@Test public void testFilter() { generator.activate(DEFAULT_CONFIG); String filtered = generator.filter("A*dsf--dsfas__sdf_"); assertNotNull(filtered); assertEquals("a-dsf--dsfas__sdf_", filtered); filtered = generator.filter("A*dsf--dsfas&&sdf*"); assertNotNull(filtered); assertEquals("a-dsf--dsfas-sdf-", filtered); filtered = generator.filter("*A*dsf--dsfa s&&sdf*"); assertNotNull(filtered); assertEquals("-a-dsf--dsfa-s-sdf-", filtered); filtered = generator.filter(""); assertNotNull(filtered); assertEquals("-", filtered); try { filtered = generator.filter(null); fail(); } catch (NullPointerException e) { } }
@Override public String filter(String nodeName) { final StringBuilder sb = new StringBuilder(); char lastAdded = 0; nodeName = nodeName.toLowerCase(); for (int i = 0; i < nodeName.length(); i++) { final char c = nodeName.charAt(i); char toAdd = c; if (allowedChars.indexOf(c) < 0) { if (lastAdded == replacementChar) { continue; } toAdd = replacementChar; } else if (i == 0 && Character.isDigit(c)) { sb.append(replacementChar); } sb.append(toAdd); lastAdded = toAdd; } if (sb.length() == 0) { sb.append(replacementChar); } return sb.toString(); }
PropertyHintNodeNameGenerator implements NodeNameGenerator, NameFilter { @Override public String filter(String nodeName) { final StringBuilder sb = new StringBuilder(); char lastAdded = 0; nodeName = nodeName.toLowerCase(); for (int i = 0; i < nodeName.length(); i++) { final char c = nodeName.charAt(i); char toAdd = c; if (allowedChars.indexOf(c) < 0) { if (lastAdded == replacementChar) { continue; } toAdd = replacementChar; } else if (i == 0 && Character.isDigit(c)) { sb.append(replacementChar); } sb.append(toAdd); lastAdded = toAdd; } if (sb.length() == 0) { sb.append(replacementChar); } return sb.toString(); } }
PropertyHintNodeNameGenerator implements NodeNameGenerator, NameFilter { @Override public String filter(String nodeName) { final StringBuilder sb = new StringBuilder(); char lastAdded = 0; nodeName = nodeName.toLowerCase(); for (int i = 0; i < nodeName.length(); i++) { final char c = nodeName.charAt(i); char toAdd = c; if (allowedChars.indexOf(c) < 0) { if (lastAdded == replacementChar) { continue; } toAdd = replacementChar; } else if (i == 0 && Character.isDigit(c)) { sb.append(replacementChar); } sb.append(toAdd); lastAdded = toAdd; } if (sb.length() == 0) { sb.append(replacementChar); } return sb.toString(); }  }
PropertyHintNodeNameGenerator implements NodeNameGenerator, NameFilter { @Override public String filter(String nodeName) { final StringBuilder sb = new StringBuilder(); char lastAdded = 0; nodeName = nodeName.toLowerCase(); for (int i = 0; i < nodeName.length(); i++) { final char c = nodeName.charAt(i); char toAdd = c; if (allowedChars.indexOf(c) < 0) { if (lastAdded == replacementChar) { continue; } toAdd = replacementChar; } else if (i == 0 && Character.isDigit(c)) { sb.append(replacementChar); } sb.append(toAdd); lastAdded = toAdd; } if (sb.length() == 0) { sb.append(replacementChar); } return sb.toString(); }  @Activate @Modified void activate(Config config); @Override String filter(String nodeName); @Override String getNodeName(SlingHttpServletRequest request, String parentPath, boolean requirePrefix,
            NodeNameGenerator defaultNodeNameGenerator); }
PropertyHintNodeNameGenerator implements NodeNameGenerator, NameFilter { @Override public String filter(String nodeName) { final StringBuilder sb = new StringBuilder(); char lastAdded = 0; nodeName = nodeName.toLowerCase(); for (int i = 0; i < nodeName.length(); i++) { final char c = nodeName.charAt(i); char toAdd = c; if (allowedChars.indexOf(c) < 0) { if (lastAdded == replacementChar) { continue; } toAdd = replacementChar; } else if (i == 0 && Character.isDigit(c)) { sb.append(replacementChar); } sb.append(toAdd); lastAdded = toAdd; } if (sb.length() == 0) { sb.append(replacementChar); } return sb.toString(); }  @Activate @Modified void activate(Config config); @Override String filter(String nodeName); @Override String getNodeName(SlingHttpServletRequest request, String parentPath, boolean requirePrefix,
            NodeNameGenerator defaultNodeNameGenerator); static final String RP_NODE_NAME_PARAM; }