Ejemplo n.º 1
0
 @Test
 public void testToXml() throws Exception {
   String xml = properties.toXml();
   for (String fragment : sampleXmlFragments) {
     assertTrue(fragment, xml.contains(fragment));
   }
 }
Ejemplo n.º 2
0
  public Element makeRootElement(Document document) {
    Element root = document.createElement("properties");
    List<String> keys = new ArrayList<>(keySet());
    Collections.sort(keys);

    for (String key : keys) {
      WikiPageProperty childProperty = getProperty(key);
      toXml(childProperty, key, document, root);
    }

    return root;
  }
Ejemplo n.º 3
0
  private void toXml(WikiPageProperty context, String key, Document document, Element parent) {
    Element element = document.createElement(key);

    String value = context.getValue();
    if (context.hasChildren()) {
      if (value != null) element.setAttribute("value", value);

      Set<?> childKeys = context.keySet();
      for (Object childKey : childKeys) {
        String childKeyAsString = (String) childKey;
        WikiPageProperty child = context.getProperty(childKeyAsString);
        if (child == null) {
          LOG.warning(
              "Property key \"" + childKeyAsString + "\" has null value for {" + context + "}");
        } else {
          toXml(child, childKeyAsString, document, element);
        }
      }
    } else if (value != null) element.appendChild(document.createTextNode(value));

    parent.appendChild(element);
  }