private void writeDataElement(XmlSerializer xml, String name, SimpleData value, int depth)
      throws IOException {
    String elemName = null;
    String text = null;

    if (value instanceof TagData) {
      elemName = TAG_ELEM;

    } else if (value instanceof DateData) {
      elemName = DATE_ELEM;
      Date d = ((DateData) value).getValue();
      if (d != null) text = XMLUtils.saveDate(d);

    } else if (value instanceof NumberData) {
      elemName = NUMBER_ELEM;
      text = numberFormat.format(((NumberData) value).getDouble());

    } else {
      elemName = STRING_ELEM;
      text = value.toString();
    }

    if (elemName != null) {
      indent(xml, depth);
      xml.startTag(null, elemName);
      xml.attribute(null, NAME_ATTR, name);
      if (text != null) xml.text(text);
      xml.endTag(null, elemName);
      xml.ignorableWhitespace(NEWLINE);
    }
  }
Esempio n. 2
0
  /**
   * Returns the specified attribute in the org.w3c.dom.Element argument. If no such attribute
   * exists, an error is logged and a XMLParseException is thrown.
   */
  private String getAttribute(Element xmlDefinition, String tag) throws IllegalArgumentException {
    String attribute = xmlDefinition.getAttribute(tag);

    if (!XMLUtils.hasValue(attribute)) {
      String message = "Missing attribute \"" + tag + "\" in preferences-pane declaration.";

      logger.log(Level.SEVERE, message);
      throw new IllegalArgumentException(message);
    }

    return attribute;
  }
 private String escXml(String s) {
   return s == null ? "" : XMLUtils.escapeAttribute(s);
 }