XStreamUtils { public static String toXmlElementName(String fieldName) { if (fieldName == null) { return null; } if (fieldName.length() == 0) { return fieldName; } if (fieldName.length() == 1) { return fieldName.toLowerCase(); } if (Character.isUpperCase(fieldName.charAt(0)) && Character.isUpperCase(fieldName.charAt(1))) { return fieldName; } StringBuilder cbuff = new StringBuilder(fieldName); cbuff.setCharAt(0, Character.toLowerCase(cbuff.charAt(0))); boolean ucPrev = false; for (int i = 1; i < cbuff.length(); i++) { char ch = cbuff.charAt(i); if (Character.isUpperCase(ch)) { if (ucPrev) { continue; } ucPrev = true; cbuff.insert(i, '-'); ++i; cbuff.setCharAt(i, Character.toLowerCase(ch)); } else { ucPrev = false; } } return cbuff.toString(); }  static String toFieldName(String xmlElementName); static String toXmlElementName(String fieldName); static Collection<String> createParentFields(Class<?> clazz, String field, String separator); static boolean setContainsAnyOf(Set<String> toCheck, Collection<String> possibles); static List<String> readResource(InputStream in); static List<Class<?>> getClasses(InputStream in);  }
@Test public void testToXmlElementName() { assertNull("", XStreamUtils.toXmlElementName(null)); assertEquals("", XStreamUtils.toXmlElementName("")); assertEquals("m", XStreamUtils.toXmlElementName("m")); assertEquals("m", XStreamUtils.toXmlElementName("M")); assertEquals("MM", XStreamUtils.toXmlElementName("MM")); assertEquals("mm", XStreamUtils.toXmlElementName("Mm")); assertEquals("MMUNTOUCHEDandAbitMore", XStreamUtils.toXmlElementName("MMUNTOUCHEDandAbitMore")); assertEquals("my-class", XStreamUtils.toXmlElementName("myClass")); assertEquals("the-little-dog-saw-aCat", XStreamUtils.toXmlElementName("theLittleDogSawACat")); assertEquals("the-little-dog-saw-arat", XStreamUtils.toXmlElementName("theLittleDogSawArat")); assertEquals("java.lang.-string", XStreamUtils.toXmlElementName("java.lang.String")); assertEquals("com.adaptris.core.http.jetty.-jetty-pooling-workflow-interceptor", XStreamUtils.toXmlElementName("com.adaptris.core.http.jetty.JettyPoolingWorkflowInterceptor")); }