Search in sources :

Example 11 with AttributesImpl

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");
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl)

Example 12 with AttributesImpl

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");
    }
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) IOException(java.io.IOException) XAttr(org.apache.hadoop.fs.XAttr) SAXException(org.xml.sax.SAXException)

Example 13 with AttributesImpl

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);
    }
}
Also used : Transformer(javax.xml.transform.Transformer) AttributesImpl(org.xml.sax.helpers.AttributesImpl) StreamResult(javax.xml.transform.stream.StreamResult) SAXTransformerFactory(javax.xml.transform.sax.SAXTransformerFactory) Resource(org.springframework.core.io.Resource) Map(java.util.Map)

Example 14 with AttributesImpl

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;
}
Also used : SAXTransformerFactory(javax.xml.transform.sax.SAXTransformerFactory) TransformerFactory(javax.xml.transform.TransformerFactory) ZipEntry(java.util.zip.ZipEntry) ZipOutputStream(java.util.zip.ZipOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) SAXTransformerFactory(javax.xml.transform.sax.SAXTransformerFactory) Templates(javax.xml.transform.Templates) ContentHandler(org.xml.sax.ContentHandler) ZipInputStream(java.util.zip.ZipInputStream) AttributesImpl(org.xml.sax.helpers.AttributesImpl) ZipOutputStream(java.util.zip.ZipOutputStream) OutputStreamWriter(java.io.OutputStreamWriter)

Example 15 with AttributesImpl

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);
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl)

Aggregations

AttributesImpl (org.xml.sax.helpers.AttributesImpl)310 SAXException (org.xml.sax.SAXException)53 Test (org.junit.Test)34 DiskWriteAttributesImpl (org.apache.geode.internal.cache.DiskWriteAttributesImpl)23 PartitionAttributesImpl (org.apache.geode.internal.cache.PartitionAttributesImpl)23 ContentHandler (org.xml.sax.ContentHandler)21 Attributes (org.xml.sax.Attributes)17 PreparedStatement (java.sql.PreparedStatement)16 ResultSet (java.sql.ResultSet)16 Map (java.util.Map)16 PackOut (org.adempiere.pipo.PackOut)16 IOException (java.io.IOException)15 POSaveFailedException (org.adempiere.pipo.exception.POSaveFailedException)12 Iterator (java.util.Iterator)11 TransformerHandler (javax.xml.transform.sax.TransformerHandler)11 StreamResult (javax.xml.transform.stream.StreamResult)11 Metadata (org.apache.tika.metadata.Metadata)11 File (java.io.File)9 SAXTransformerFactory (javax.xml.transform.sax.SAXTransformerFactory)9 DatabaseAccessException (org.adempiere.pipo.exception.DatabaseAccessException)9