NameValidator extends DefaultValidator { protected static String getPrintableName(String s) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (c >= ' ' && c < 127) { sb.append(c); } else if (c == '\b') { sb.append("\\b"); } else if (c == '\f') { sb.append("\\f"); } else if (c == '\n') { sb.append("\\n"); } else if (c == '\r') { sb.append("\\r"); } else if (c == '\t') { sb.append("\\t"); } else { sb.append(String.format("\\u%04x", (int) c)); } } return sb.toString(); } NameValidator(NodeState namespaces, boolean initPhase); @Override void propertyAdded(PropertyState after); @Override void propertyChanged(PropertyState before, PropertyState after); @Override void propertyDeleted(PropertyState before); @Override Validator childNodeAdded(String name, NodeState after); @Override Validator childNodeChanged(
            String name, NodeState before, NodeState after); @Override Validator childNodeDeleted(String name, NodeState before);  }
@Test public void testEscaping() { assertEquals("abc", NameValidator.getPrintableName("abc")); assertEquals("\\t\\r\\n\\b\\f", NameValidator.getPrintableName("\t\r\n\b\f")); assertEquals("\\u00e0", NameValidator.getPrintableName("\u00e0")); }