@Test public void testSafeElementName() throws Exception { assertEquals("default", safeElementName("", "default")); assertEquals("hello", safeElementName("hello", "default")); assertEquals("_0hello", safeElementName("0hello", "default")); assertEquals("_0hel_lo", safeElementName("_0hel&lo", "default")); assertEquals("__hello", safeElementName("?hello", "default")); }
public static String safeElementName(String input, String defaultIfBlank) { String name = defaultIfBlank(input, "").trim(); name = name.replaceAll(ILLEGAL_XML, ""); if (isBlank(name)) { name = defaultIfBlank; } else { if (!XMLChar.isNameStart(name.charAt(0))) { name = ELEM_REPL_VALUE + name; } for (String invalid : INVALID_ELEMENT_CHARS) { name = name.replaceAll(invalid, ELEM_REPL_VALUE); } } return name; }
XmlHelper { public static String safeElementName(String input, String defaultIfBlank) { String name = defaultIfBlank(input, "").trim(); name = name.replaceAll(ILLEGAL_XML, ""); if (isBlank(name)) { name = defaultIfBlank; } else { if (!XMLChar.isNameStart(name.charAt(0))) { name = ELEM_REPL_VALUE + name; } for (String invalid : INVALID_ELEMENT_CHARS) { name = name.replaceAll(invalid, ELEM_REPL_VALUE); } } return name; } }
XmlHelper { public static String safeElementName(String input, String defaultIfBlank) { String name = defaultIfBlank(input, "").trim(); name = name.replaceAll(ILLEGAL_XML, ""); if (isBlank(name)) { name = defaultIfBlank; } else { if (!XMLChar.isNameStart(name.charAt(0))) { name = ELEM_REPL_VALUE + name; } for (String invalid : INVALID_ELEMENT_CHARS) { name = name.replaceAll(invalid, ELEM_REPL_VALUE); } } return name; }  }
XmlHelper { public static String safeElementName(String input, String defaultIfBlank) { String name = defaultIfBlank(input, "").trim(); name = name.replaceAll(ILLEGAL_XML, ""); if (isBlank(name)) { name = defaultIfBlank; } else { if (!XMLChar.isNameStart(name.charAt(0))) { name = ELEM_REPL_VALUE + name; } for (String invalid : INVALID_ELEMENT_CHARS) { name = name.replaceAll(invalid, ELEM_REPL_VALUE); } } return name; }  @Deprecated static XmlUtils createXmlUtils(AdaptrisMessage msg); @Deprecated static XmlUtils createXmlUtils(AdaptrisMessage msg, NamespaceContext ctx); static XmlUtils createXmlUtils(AdaptrisMessage msg, NamespaceContext ctx, DocumentBuilderFactoryBuilder builder); @Deprecated static Document createDocument(AdaptrisMessage msg); @Deprecated static Document createDocument(AdaptrisMessage msg, boolean namespaceAware); static Document createDocument(AdaptrisMessage msg, DocumentBuilderFactoryBuilder builder); static Document createDocument(AdaptrisMessage msg, DocumentBuilderFactoryBuilder builder, boolean newDocOnFailure); @Deprecated static Document createDocument(AdaptrisMessage msg, NamespaceContext namespaceContext); @Deprecated static Document createDocument(String s); @Deprecated static Document createDocument(String s, NamespaceContext namespaceContext); @Deprecated static Document createDocument(String s, boolean namespaceAware); static Document createDocument(String s, DocumentBuilderFactoryBuilder builder); static Document createDocument(String s, DocumentBuilderFactoryBuilder builder, boolean newDocOnFailure); static Document createDocument(InputStream in, DocumentBuilderFactoryBuilder builder); static Document createDocument(InputStream in, DocumentBuilderFactoryBuilder builder, boolean newDocOnFailure); static String safeElementName(String input, String defaultIfBlank); static String stripIllegalXmlCharacters(String input); static void writeXmlDocument(Document doc, AdaptrisMessage msg, String encoding); static void writeXmlDocument(Document doc, AdaptrisMessage msg, String encoding, Transformer serializer); static String getXmlEncoding(AdaptrisMessage msg, String enc); }
XmlHelper { public static String safeElementName(String input, String defaultIfBlank) { String name = defaultIfBlank(input, "").trim(); name = name.replaceAll(ILLEGAL_XML, ""); if (isBlank(name)) { name = defaultIfBlank; } else { if (!XMLChar.isNameStart(name.charAt(0))) { name = ELEM_REPL_VALUE + name; } for (String invalid : INVALID_ELEMENT_CHARS) { name = name.replaceAll(invalid, ELEM_REPL_VALUE); } } return name; }  @Deprecated static XmlUtils createXmlUtils(AdaptrisMessage msg); @Deprecated static XmlUtils createXmlUtils(AdaptrisMessage msg, NamespaceContext ctx); static XmlUtils createXmlUtils(AdaptrisMessage msg, NamespaceContext ctx, DocumentBuilderFactoryBuilder builder); @Deprecated static Document createDocument(AdaptrisMessage msg); @Deprecated static Document createDocument(AdaptrisMessage msg, boolean namespaceAware); static Document createDocument(AdaptrisMessage msg, DocumentBuilderFactoryBuilder builder); static Document createDocument(AdaptrisMessage msg, DocumentBuilderFactoryBuilder builder, boolean newDocOnFailure); @Deprecated static Document createDocument(AdaptrisMessage msg, NamespaceContext namespaceContext); @Deprecated static Document createDocument(String s); @Deprecated static Document createDocument(String s, NamespaceContext namespaceContext); @Deprecated static Document createDocument(String s, boolean namespaceAware); static Document createDocument(String s, DocumentBuilderFactoryBuilder builder); static Document createDocument(String s, DocumentBuilderFactoryBuilder builder, boolean newDocOnFailure); static Document createDocument(InputStream in, DocumentBuilderFactoryBuilder builder); static Document createDocument(InputStream in, DocumentBuilderFactoryBuilder builder, boolean newDocOnFailure); static String safeElementName(String input, String defaultIfBlank); static String stripIllegalXmlCharacters(String input); static void writeXmlDocument(Document doc, AdaptrisMessage msg, String encoding); static void writeXmlDocument(Document doc, AdaptrisMessage msg, String encoding, Transformer serializer); static String getXmlEncoding(AdaptrisMessage msg, String enc); static final String FALLBACK_TRANSFORMER_FACTORY_IMPL; }