Search in sources :

Example 61 with AttributesImpl

use of org.xml.sax.helpers.AttributesImpl in project jackrabbit by apache.

the class XmlnsContentHandler method startElement.

/**
     * Adds the recorded namespace mappings (if any) as "xmlns" attributes
     * before passing the call on to the proxied content handler.
     */
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
    if (!namespaces.isEmpty()) {
        AttributesImpl attributes = new AttributesImpl(atts);
        Iterator iterator = namespaces.entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry entry = (Map.Entry) iterator.next();
            String prefix = (String) entry.getKey();
            String uri = (String) entry.getValue();
            if (prefix.length() == 0) {
                attributes.addAttribute(XMLNS_NAMESPACE, "xmlns", "xmlns", "CDATA", uri);
            } else {
                attributes.addAttribute(XMLNS_NAMESPACE, prefix, "xmlns:" + prefix, "CDATA", uri);
            }
        }
        atts = attributes;
        namespaces.clear();
    }
    super.startElement(namespaceURI, localName, qName, atts);
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) Iterator(java.util.Iterator) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 62 with AttributesImpl

use of org.xml.sax.helpers.AttributesImpl in project jackrabbit by apache.

the class ToXmlContentHandlerTest method testProcessingInstruction.

public void testProcessingInstruction() throws SAXException {
    ContentHandler handler = new ToXmlContentHandler();
    handler.startDocument();
    handler.processingInstruction("foo", "abc=\"xyz\"");
    handler.startElement("", "test", "test", new AttributesImpl());
    handler.processingInstruction("bar", null);
    handler.endElement("", "test", "test");
    handler.endDocument();
    assertEquals("<?xml version=\"1.0\"?>" + "<?foo abc=\"xyz\"?><test><?bar?></test>", handler.toString());
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) ContentHandler(org.xml.sax.ContentHandler)

Example 63 with AttributesImpl

use of org.xml.sax.helpers.AttributesImpl in project jackrabbit by apache.

the class SerializingContentHandlerTest method testSerializingContentHandler.

public void testSerializingContentHandler() throws Exception {
    StringWriter writer = new StringWriter();
    ContentHandler handler = SerializingContentHandler.getSerializer(writer);
    handler.startDocument();
    handler.startPrefixMapping("p", "uri");
    handler.startElement("uri", "a", "p:a", new AttributesImpl());
    AttributesImpl attributes = new AttributesImpl();
    attributes.addAttribute("uri", "foo", "p:foo", "CDATA", "bar");
    handler.startElement(null, "b", "b", attributes);
    handler.characters("abc".toCharArray(), 0, 3);
    handler.endElement(null, "b", "b");
    handler.startElement(null, "c", "c", new AttributesImpl());
    handler.endElement(null, "c", "c");
    handler.characters("xyz".toCharArray(), 0, 3);
    handler.endElement("uri", "a", "p:a");
    handler.endPrefixMapping("p");
    handler.endDocument();
    String xml = writer.toString();
    assertContains(xml, "<p:a");
    assertContains(xml, "xmlns:p");
    assertContains(xml, "=");
    assertContains(xml, "uri");
    assertContains(xml, ">");
    assertContains(xml, "<b");
    assertContains(xml, "p:foo");
    assertContains(xml, "bar");
    assertContains(xml, "abc");
    assertContains(xml, "</b>");
    assertContains(xml, "<c/>");
    assertContains(xml, "xyz");
    assertContains(xml, "</p:a>");
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) StringWriter(java.io.StringWriter) ContentHandler(org.xml.sax.ContentHandler)

Example 64 with AttributesImpl

use of org.xml.sax.helpers.AttributesImpl in project jackrabbit by apache.

the class ToXmlContentHandlerTest method testChildElements.

public void testChildElements() throws SAXException {
    ContentHandler handler = new ToXmlContentHandler();
    handler.startDocument();
    handler.startElement("", "test", "test", new AttributesImpl());
    handler.startElement("", "foo", "foo", new AttributesImpl());
    handler.endElement("", "foo", "foo");
    handler.startElement("", "bar", "bar", new AttributesImpl());
    handler.endElement("", "bar", "bar");
    handler.endElement("", "test", "test");
    handler.endDocument();
    assertEquals("<?xml version=\"1.0\"?><test><foo/><bar/></test>", handler.toString());
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) ContentHandler(org.xml.sax.ContentHandler)

Example 65 with AttributesImpl

use of org.xml.sax.helpers.AttributesImpl in project jackrabbit by apache.

the class ToXmlContentHandlerTest method testIgnorableWhitespace.

public void testIgnorableWhitespace() throws SAXException {
    ContentHandler handler = new ToXmlContentHandler();
    handler.startDocument();
    handler.ignorableWhitespace("\n".toCharArray(), 0, 1);
    handler.startElement("", "test", "test", new AttributesImpl());
    handler.ignorableWhitespace("\n".toCharArray(), 0, 1);
    handler.endElement("", "test", "test");
    handler.ignorableWhitespace("\n".toCharArray(), 0, 1);
    handler.endDocument();
    assertEquals("<?xml version=\"1.0\"?>\n<test>\n</test>\n", handler.toString());
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) ContentHandler(org.xml.sax.ContentHandler)

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