FormsUtil.java 869 Bytes
/*
 * Decompiled with CFR 0_118.
 */
package com.day.cq.wcm.foundation.forms.impl;

public class FormsUtil {
    private FormsUtil() {
    }

    public static String filterElementName(String nodeName) {
        StringBuilder sb = new StringBuilder();
        int lastAdded = 0;
        for (int i = 0; i < nodeName.length(); ++i) {
            char c = nodeName.charAt(i);
            int toAdd = c;
            if ("abcdefghijklmnopqrstuvwxyz0123456789_ABCDEFGHIJKLMNOPQRSTUVWXYZ./:-".indexOf(c) < 0) {
                if (lastAdded == 95) continue;
                toAdd = 95;
            } else if (i == 0 && Character.isDigit(c)) {
                sb.append('_');
            }
            sb.append((char)toAdd);
            lastAdded = toAdd;
        }
        if (sb.length() == 0) {
            sb.append('_');
        }
        return sb.toString();
    }
}