public static void notify(Notifying n,
ContentHandler ch,
String mimetype) throws SAXException {
final String PREFIX = Constants.ERROR_NAMESPACE_PREFIX;
final String URI = Constants.ERROR_NAMESPACE_URI;
// Start the document
ch.startDocument();
ch.startPrefixMapping(PREFIX, URI);
// Root element.
AttributesImpl atts = new AttributesImpl();
atts.addAttribute(URI, "type", PREFIX + ":type", "CDATA", n.getType());
atts.addAttribute(URI, "sender", PREFIX + ":sender", "CDATA", n.getSender());
ch.startElement(URI, "notify", PREFIX + ":notify", atts);
ch.startElement(URI, "title", PREFIX + ":title", new AttributesImpl());
ch.characters(n.getTitle().toCharArray(), 0, n.getTitle().length());
ch.endElement(URI, "title", PREFIX + ":title");
ch.startElement(URI, "source", PREFIX + ":source", new AttributesImpl());
ch.characters(n.getSource().toCharArray(), 0, n.getSource().length());
ch.endElement(URI, "source", PREFIX + ":source");
ch.startElement(URI, "message", PREFIX + ":message", new AttributesImpl());
if (n.getMessage() != null) {
ch.characters(n.getMessage().toCharArray(), 0, n.getMessage().length());
}
ch.endElement(URI, "message", PREFIX + ":message");
ch.startElement(URI, "description", PREFIX + ":description", XMLUtils.EMPTY_ATTRIBUTES);
ch.characters(n.getDescription().toCharArray(), 0, n.getDescription().length());
ch.endElement(URI, "description", PREFIX + ":description");
Map extraDescriptions = n.getExtraDescriptions();
for (Iterator i = extraDescriptions.entrySet().iterator(); i.hasNext(); ) {
final Map.Entry me = (Map.Entry) i.next();
String key = (String) me.getKey();
String value = String.valueOf(me.getValue());
atts = new AttributesImpl();
atts.addAttribute(URI, "description", PREFIX + ":description", "CDATA", key);
ch.startElement(URI, "extra", PREFIX + ":extra", atts);
ch.characters(value.toCharArray(), 0, value.length());
ch.endElement(URI, "extra", PREFIX + ":extra");
}
// End root element.
ch.endElement(URI, "notify", PREFIX + ":notify");
// End the document.
ch.endPrefixMapping(PREFIX);
ch.endDocument();
}
Generate notification information in XML format. |