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);
}
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());
}
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>");
}
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());
}
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());
}
Aggregations