use of org.xml.sax.helpers.AttributesImpl in project groovy by apache.
the class SAXBuilder method createNode.
protected Object createNode(Object name, Map attributeMap, Object text) {
AttributesImpl attributes = new AttributesImpl();
for (Iterator iter = attributeMap.entrySet().iterator(); iter.hasNext(); ) {
Map.Entry entry = (Map.Entry) iter.next();
Object key = entry.getKey();
Object value = entry.getValue();
String uri = "";
String localName = null;
String qualifiedName = "";
String valueText = (value != null) ? value.toString() : "";
if (key instanceof QName) {
QName qname = (QName) key;
uri = qname.getNamespaceURI();
localName = qname.getLocalPart();
qualifiedName = qname.getQualifiedName();
} else {
localName = key.toString();
qualifiedName = localName;
}
attributes.addAttribute(uri, localName, qualifiedName, "CDATA", valueText);
}
doStartElement(name, attributes);
if (text != null) {
doText(text);
}
return name;
}
use of org.xml.sax.helpers.AttributesImpl in project hadoop by apache.
the class XmlEditsVisitor method start.
/**
* Start visitor (initialization)
*/
@Override
public void start(int version) throws IOException {
try {
contentHandler.startElement("", "", "EDITS_VERSION", new AttributesImpl());
StringBuilder bld = new StringBuilder();
bld.append(version);
addString(bld.toString());
contentHandler.endElement("", "", "EDITS_VERSION");
} catch (SAXException e) {
throw new IOException("SAX error: " + e.getMessage());
}
}
use of org.xml.sax.helpers.AttributesImpl in project hadoop by apache.
the class XMLUtils method addSaxString.
/**
* Add a SAX tag with a string inside.
*
* @param contentHandler the SAX content handler
* @param tag the element tag to use
* @param val the string to put inside the tag
*/
public static void addSaxString(ContentHandler contentHandler, String tag, String val) throws SAXException {
contentHandler.startElement("", "", tag, new AttributesImpl());
char[] c = mangleXmlString(val, false).toCharArray();
contentHandler.characters(c, 0, c.length);
contentHandler.endElement("", "", tag);
}
use of org.xml.sax.helpers.AttributesImpl in project hadoop by apache.
the class FSEditLogOp method permissionStatusToXml.
public static void permissionStatusToXml(ContentHandler contentHandler, PermissionStatus perm) throws SAXException {
contentHandler.startElement("", "", "PERMISSION_STATUS", new AttributesImpl());
XMLUtils.addSaxString(contentHandler, "USERNAME", perm.getUserName());
XMLUtils.addSaxString(contentHandler, "GROUPNAME", perm.getGroupName());
fsPermissionToXml(contentHandler, perm.getPermission());
contentHandler.endElement("", "", "PERMISSION_STATUS");
}
use of org.xml.sax.helpers.AttributesImpl in project hadoop by apache.
the class FSEditLogOp method delegationKeyToXml.
public static void delegationKeyToXml(ContentHandler contentHandler, DelegationKey key) throws SAXException {
contentHandler.startElement("", "", "DELEGATION_KEY", new AttributesImpl());
XMLUtils.addSaxString(contentHandler, "KEY_ID", Integer.toString(key.getKeyId()));
XMLUtils.addSaxString(contentHandler, "EXPIRY_DATE", Long.toString(key.getExpiryDate()));
if (key.getEncodedKey() != null) {
XMLUtils.addSaxString(contentHandler, "KEY", Hex.encodeHexString(key.getEncodedKey()));
}
contentHandler.endElement("", "", "DELEGATION_KEY");
}
Aggregations