Search in sources :

Example 76 with AttributesImpl

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

the class ManagedEntityConfigXmlGenerator method parse.

/**
   * Called by the transformer to parse the "input source". We ignore the input source and, instead,
   * generate SAX events to the {@link #setContentHandler ContentHandler}.
   */
public void parse(InputSource input) throws SAXException {
    Assert.assertTrue(this.handler != null);
    handler.startDocument();
    AttributesImpl atts = new AttributesImpl();
    atts.addAttribute("", "", ID, "", String.valueOf(this.system.getConfig().getSystemId()));
    handler.startElement("", DISTRIBUTED_SYSTEM, DISTRIBUTED_SYSTEM, atts);
    // Add generation methods here
    try {
        generateRemoteCommand();
        generateDiscovery();
        generateSSL();
        generateCacheServers();
    } catch (AdminException ex) {
        throw new SAXException(LocalizedStrings.ManagedEntityConfigXmlGenerator_AN_ADMINEXCEPTION_WAS_THROWN_WHILE_GENERATING_XML.toLocalizedString(), ex);
    }
    handler.endElement("", DISTRIBUTED_SYSTEM, DISTRIBUTED_SYSTEM);
    handler.endDocument();
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl)

Example 77 with AttributesImpl

use of org.xml.sax.helpers.AttributesImpl in project spring-framework by spring-projects.

the class AbstractStaxXMLReaderTestCase method mockContentHandler.

protected final ContentHandler mockContentHandler() throws Exception {
    ContentHandler contentHandler = mock(ContentHandler.class);
    willAnswer(new CopyCharsAnswer()).given(contentHandler).characters(any(char[].class), anyInt(), anyInt());
    willAnswer(new CopyCharsAnswer()).given(contentHandler).ignorableWhitespace(any(char[].class), anyInt(), anyInt());
    willAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            invocation.getArguments()[3] = new AttributesImpl((Attributes) invocation.getArguments()[3]);
            return null;
        }
    }).given(contentHandler).startElement(anyString(), anyString(), anyString(), any(Attributes.class));
    return contentHandler;
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Attributes(org.xml.sax.Attributes) ContentHandler(org.xml.sax.ContentHandler)

Example 78 with AttributesImpl

use of org.xml.sax.helpers.AttributesImpl in project spring-framework by spring-projects.

the class StaxEventXMLReader method getAttributes.

private Attributes getAttributes(StartElement event) {
    AttributesImpl attributes = new AttributesImpl();
    for (Iterator i = event.getAttributes(); i.hasNext(); ) {
        Attribute attribute = (Attribute) i.next();
        QName qName = attribute.getName();
        String namespace = qName.getNamespaceURI();
        if (namespace == null || !hasNamespacesFeature()) {
            namespace = "";
        }
        String type = attribute.getDTDType();
        if (type == null) {
            type = "CDATA";
        }
        attributes.addAttribute(namespace, qName.getLocalPart(), toQualifiedName(qName), type, attribute.getValue());
    }
    if (hasNamespacePrefixesFeature()) {
        for (Iterator i = event.getNamespaces(); i.hasNext(); ) {
            Namespace namespace = (Namespace) i.next();
            String prefix = namespace.getPrefix();
            String namespaceUri = namespace.getNamespaceURI();
            String qName;
            if (StringUtils.hasLength(prefix)) {
                qName = "xmlns:" + prefix;
            } else {
                qName = "xmlns";
            }
            attributes.addAttribute("", "", qName, "CDATA", namespaceUri);
        }
    }
    return attributes;
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) Attribute(javax.xml.stream.events.Attribute) QName(javax.xml.namespace.QName) Iterator(java.util.Iterator) Namespace(javax.xml.stream.events.Namespace)

Example 79 with AttributesImpl

use of org.xml.sax.helpers.AttributesImpl in project spring-framework by spring-projects.

the class StaxStreamXMLReader method getAttributes.

private Attributes getAttributes() {
    AttributesImpl attributes = new AttributesImpl();
    for (int i = 0; i < this.reader.getAttributeCount(); i++) {
        String namespace = this.reader.getAttributeNamespace(i);
        if (namespace == null || !hasNamespacesFeature()) {
            namespace = "";
        }
        String type = this.reader.getAttributeType(i);
        if (type == null) {
            type = "CDATA";
        }
        attributes.addAttribute(namespace, this.reader.getAttributeLocalName(i), toQualifiedName(this.reader.getAttributeName(i)), type, this.reader.getAttributeValue(i));
    }
    if (hasNamespacePrefixesFeature()) {
        for (int i = 0; i < this.reader.getNamespaceCount(); i++) {
            String prefix = this.reader.getNamespacePrefix(i);
            String namespaceUri = this.reader.getNamespaceURI(i);
            String qName;
            if (StringUtils.hasLength(prefix)) {
                qName = "xmlns:" + prefix;
            } else {
                qName = "xmlns";
            }
            attributes.addAttribute("", "", qName, "CDATA", namespaceUri);
        }
    }
    return attributes;
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl)

Example 80 with AttributesImpl

use of org.xml.sax.helpers.AttributesImpl in project robovm by robovm.

the class AttributesImplTest method testSetAttributes.

public void testSetAttributes() {
    // Ordinary cases
    AttributesImpl attrs = new AttributesImpl();
    attrs.addAttribute("http://yet.another.uri", "doe", "john:doe", "boolean", "false");
    attrs.setAttributes(empty);
    assertEquals(0, attrs.getLength());
    attrs.setAttributes(multi);
    assertEquals(multi.getLength(), attrs.getLength());
    for (int i = 0; i < multi.getLength(); i++) {
        assertEquals(multi.getURI(i), attrs.getURI(i));
        assertEquals(multi.getLocalName(i), attrs.getLocalName(i));
        assertEquals(multi.getQName(i), attrs.getQName(i));
        assertEquals(multi.getType(i), attrs.getType(i));
        assertEquals(multi.getValue(i), attrs.getValue(i));
    }
    // null case
    try {
        attrs.setAttributes(null);
        fail("NullPointerException expected");
    } catch (NullPointerException e) {
        // Expected, but must be empty now
        assertEquals(0, attrs.getLength());
    }
}
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