use of org.xml.sax.helpers.AttributesImpl in project hadoop by apache.
the class FSEditLogOp method blockToXml.
public static void blockToXml(ContentHandler contentHandler, Block block) throws SAXException {
contentHandler.startElement("", "", "BLOCK", new AttributesImpl());
XMLUtils.addSaxString(contentHandler, "BLOCK_ID", Long.toString(block.getBlockId()));
XMLUtils.addSaxString(contentHandler, "NUM_BYTES", Long.toString(block.getNumBytes()));
XMLUtils.addSaxString(contentHandler, "GENSTAMP", Long.toString(block.getGenerationStamp()));
contentHandler.endElement("", "", "BLOCK");
}
use of org.xml.sax.helpers.AttributesImpl in project hadoop by apache.
the class FSEditLogOp method appendXAttrsToXml.
private static void appendXAttrsToXml(ContentHandler contentHandler, List<XAttr> xAttrs) throws SAXException {
for (XAttr xAttr : xAttrs) {
contentHandler.startElement("", "", "XATTR", new AttributesImpl());
XMLUtils.addSaxString(contentHandler, "NAMESPACE", xAttr.getNameSpace().toString());
XMLUtils.addSaxString(contentHandler, "NAME", xAttr.getName());
if (xAttr.getValue() != null) {
try {
XMLUtils.addSaxString(contentHandler, "VALUE", XAttrCodec.encodeValue(xAttr.getValue(), XAttrCodec.HEX));
} catch (IOException e) {
throw new SAXException(e);
}
}
contentHandler.endElement("", "", "XATTR");
}
}
use of org.xml.sax.helpers.AttributesImpl in project opennms by OpenNMS.
the class XmlSystemReportFormatter method write.
@Override
public void write(final SystemReportPlugin plugin) {
if (!hasDisplayable(plugin))
return;
if (m_handler == null) {
try {
StreamResult streamResult = new StreamResult(getOutputStream());
SAXTransformerFactory tf = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
m_handler = tf.newTransformerHandler();
Transformer serializer = m_handler.getTransformer();
serializer.setOutputProperty(OutputKeys.CDATA_SECTION_ELEMENTS, "entry");
m_handler.setResult(streamResult);
} catch (final Exception e) {
LOG.error("Unable to create XML stream writer.", e);
m_handler = null;
}
try {
m_handler.startDocument();
m_handler.startElement("", "", "systemReportPlugins", null);
} catch (final Exception e) {
LOG.warn("Unable to start document.", e);
m_handler = null;
}
}
if (m_handler == null) {
LOG.warn("Unable to write, no handler defined!");
return;
}
try {
AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "name", "CDATA", plugin.getName());
atts.addAttribute("", "", "description", "CDATA", plugin.getDescription());
m_handler.startElement("", "", "plugin", atts);
for (final Map.Entry<String, Resource> entry : plugin.getEntries().entrySet()) {
final boolean displayable = isDisplayable(entry.getValue());
atts = new AttributesImpl();
atts.addAttribute("", "", "key", "CDATA", entry.getKey());
if (!displayable) {
atts.addAttribute("", "", "skipped", "CDATA", "true");
}
m_handler.startElement("", "", "entry", atts);
if (displayable) {
final String value = getResourceText(entry.getValue());
if (value != null) {
m_handler.startCDATA();
m_handler.characters(value.toCharArray(), 0, value.length());
m_handler.endCDATA();
}
}
m_handler.endElement("", "", "entry");
}
m_handler.endElement("", "", "plugin");
} catch (final Exception e) {
LOG.warn("An error occurred while attempting to write XML data.", e);
}
}
use of org.xml.sax.helpers.AttributesImpl in project enclojure by EricThorsen.
the class Processor method process.
public int process() throws TransformerException, IOException, SAXException {
ZipInputStream zis = new ZipInputStream(input);
final ZipOutputStream zos = new ZipOutputStream(output);
final OutputStreamWriter osw = new OutputStreamWriter(zos);
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
TransformerFactory tf = TransformerFactory.newInstance();
if (!tf.getFeature(SAXSource.FEATURE) || !tf.getFeature(SAXResult.FEATURE)) {
return 0;
}
SAXTransformerFactory saxtf = (SAXTransformerFactory) tf;
Templates templates = null;
if (xslt != null) {
templates = saxtf.newTemplates(xslt);
}
// configuring outHandlerFactory
// ///////////////////////////////////////////////////////
EntryElement entryElement = getEntryElement(zos);
ContentHandler outDocHandler = null;
switch(outRepresentation) {
case BYTECODE:
outDocHandler = new OutputSlicingHandler(new ASMContentHandlerFactory(zos, computeMax), entryElement, false);
break;
case MULTI_XML:
outDocHandler = new OutputSlicingHandler(new SAXWriterFactory(osw, true), entryElement, true);
break;
case SINGLE_XML:
ZipEntry outputEntry = new ZipEntry(SINGLE_XML_NAME);
zos.putNextEntry(outputEntry);
outDocHandler = new SAXWriter(osw, false);
break;
}
// configuring inputDocHandlerFactory
// /////////////////////////////////////////////////
ContentHandler inDocHandler;
if (templates == null) {
inDocHandler = outDocHandler;
} else {
inDocHandler = new InputSlicingHandler("class", outDocHandler, new TransformerHandlerFactory(saxtf, templates, outDocHandler));
}
ContentHandlerFactory inDocHandlerFactory = new SubdocumentHandlerFactory(inDocHandler);
if (inDocHandler != null && inRepresentation != SINGLE_XML) {
inDocHandler.startDocument();
inDocHandler.startElement("", "classes", "classes", new AttributesImpl());
}
int i = 0;
ZipEntry ze;
while ((ze = zis.getNextEntry()) != null) {
update(ze.getName(), n++);
if (isClassEntry(ze)) {
processEntry(zis, ze, inDocHandlerFactory);
} else {
OutputStream os = entryElement.openEntry(getName(ze));
copyEntry(zis, os);
entryElement.closeEntry();
}
i++;
}
if (inDocHandler != null && inRepresentation != SINGLE_XML) {
inDocHandler.endElement("", "classes", "classes");
inDocHandler.endDocument();
}
if (outRepresentation == SINGLE_XML) {
zos.closeEntry();
}
zos.flush();
zos.close();
return i;
}
use of org.xml.sax.helpers.AttributesImpl in project enclojure by EricThorsen.
the class SAXAnnotationAdapter method addValueElement.
private void addValueElement(final String element, final String name, final String desc, final String value) {
AttributesImpl att = new AttributesImpl();
if (name != null) {
att.addAttribute("", "name", "name", "", name);
}
if (desc != null) {
att.addAttribute("", "desc", "desc", "", desc);
}
if (value != null) {
att.addAttribute("", "value", "value", "", SAXClassAdapter.encode(value));
}
addElement(element, att);
}
Aggregations