Search in sources :

Example 71 with AttributesImpl

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

the class MockCacheExtensionXmlGenerator method generate.

@Override
public void generate(CacheXmlGenerator cacheXmlGenerator) throws SAXException {
    final ContentHandler handler = cacheXmlGenerator.getContentHandler();
    try {
        handler.startPrefixMapping(PREFIX, NAMESPACE);
        final AttributesImpl atts = new AttributesImpl();
        addAttribute(atts, ATTRIBUTE_VALUE, extension.getValue());
        emptyElement(handler, PREFIX, ELEMENT_CACHE, atts);
    } finally {
        handler.endPrefixMapping("mock");
    }
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) ContentHandler(org.xml.sax.ContentHandler)

Example 72 with AttributesImpl

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

the class XmlGeneratorUtilsJUnitTest method testAddAttributeAttributesImplStringObject.

/**
   * Test method for {@link XmlGeneratorUtils#addAttribute(AttributesImpl, String, Object)}.
   */
@Test
public void testAddAttributeAttributesImplStringObject() {
    final AttributesImpl attributes = new AttributesImpl();
    assertEquals(0, attributes.getLength());
    XmlGeneratorUtils.addAttribute(attributes, "localname", null);
    assertEquals(0, attributes.getLength());
    XmlGeneratorUtils.addAttribute(attributes, "localname", "value");
    assertEquals(1, attributes.getLength());
    assertEquals("localname", attributes.getLocalName(0));
    assertEquals("localname", attributes.getQName(0));
    assertEquals(XMLConstants.NULL_NS_URI, attributes.getURI(0));
    assertEquals("value", attributes.getValue(0));
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 73 with AttributesImpl

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

the class SerializingContentHandler method startElement.

/**
     * Ensure all namespace declarations are present as <code>xmlns:</code> attributes
     * and add those needed before calling superclass. This is a workaround for a Xalan bug
     * (at least in version 2.0.1) : <code>org.apache.xalan.serialize.SerializerToXML</code>
     * ignores <code>start/endPrefixMapping()</code>.
     */
public void startElement(String eltUri, String eltLocalName, String eltQName, Attributes attrs) throws SAXException {
    // JCR-1767: Generate extra prefix mapping calls where needed
    addedPrefixMappings.add(null);
    checkPrefixMapping(eltUri, eltQName);
    for (int i = 0; i < attrs.getLength(); i++) {
        checkPrefixMapping(attrs.getURI(i), attrs.getQName(i));
    }
    // try to restore the qName. The map already contains the colon
    if (null != eltUri && eltUri.length() != 0 && this.uriToPrefixMap.containsKey(eltUri)) {
        eltQName = this.uriToPrefixMap.get(eltUri) + eltLocalName;
    }
    if (this.hasMappings) {
        // Add xmlns* attributes where needed
        // New Attributes if we have to add some.
        AttributesImpl newAttrs = null;
        int mappingCount = this.prefixList.size();
        int attrCount = attrs.getLength();
        for (int mapping = 0; mapping < mappingCount; mapping++) {
            // Build infos for this namespace
            String uri = (String) this.uriList.get(mapping);
            String prefix = (String) this.prefixList.get(mapping);
            String qName = prefix.equals("") ? "xmlns" : ("xmlns:" + prefix);
            // Search for the corresponding xmlns* attribute
            boolean found = false;
            for (int attr = 0; attr < attrCount; attr++) {
                if (qName.equals(attrs.getQName(attr))) {
                    // Check if mapping and attribute URI match
                    if (!uri.equals(attrs.getValue(attr))) {
                        throw new SAXException("URI in prefix mapping and attribute do not match");
                    }
                    found = true;
                    break;
                }
            }
            if (!found) {
                // Need to add this namespace
                if (newAttrs == null) {
                    // Well know SAX bug which I spent 3 hours to remind of :-(
                    if (attrCount == 0) {
                        newAttrs = new AttributesImpl();
                    } else {
                        newAttrs = new AttributesImpl(attrs);
                    }
                }
                if (prefix.equals("")) {
                    newAttrs.addAttribute(XML, qName, qName, "CDATA", uri);
                } else {
                    newAttrs.addAttribute(XML, prefix, qName, "CDATA", uri);
                }
            }
        }
        // end for mapping
        // Cleanup for the next element
        clearMappings();
        // Start element with new attributes, if any
        super.startElement(eltUri, eltLocalName, eltQName, newAttrs == null ? attrs : newAttrs);
    } else {
        // Normal job
        super.startElement(eltUri, eltLocalName, eltQName, attrs);
    }
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) SAXException(org.xml.sax.SAXException)

Example 74 with AttributesImpl

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

the class JspDocumentParser method startElement.

/*
     * Receives notification of the start of an element.
     *
     * This method assigns the given tag attributes to one of 3 buckets:
     *
     * - "xmlns" attributes that represent (standard or custom) tag libraries.
     * - "xmlns" attributes that do not represent tag libraries.
     * - all remaining attributes.
     *
     * For each "xmlns" attribute that represents a custom tag library, the
     * corresponding TagLibraryInfo object is added to the set of custom
     * tag libraries.
     */
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    AttributesImpl taglibAttrs = null;
    AttributesImpl nonTaglibAttrs = null;
    AttributesImpl nonTaglibXmlnsAttrs = null;
    processChars();
    checkPrefixes(uri, qName, attrs);
    if (directivesOnly && !(JSP_URI.equals(uri) && localName.startsWith(DIRECTIVE_ACTION))) {
        return;
    }
    // jsp:text must not have any subelements
    if (JSP_URI.equals(uri) && TEXT_ACTION.equals(current.getLocalName())) {
        throw new SAXParseException(Localizer.getMessage("jsp.error.text.has_subelement"), locator);
    }
    startMark = new Mark(ctxt, path, locator.getLineNumber(), locator.getColumnNumber());
    if (attrs != null) {
        /*
             * Notice that due to a bug in the underlying SAX parser, the
             * attributes must be enumerated in descending order.
             */
        boolean isTaglib = false;
        for (int i = attrs.getLength() - 1; i >= 0; i--) {
            isTaglib = false;
            String attrQName = attrs.getQName(i);
            if (!attrQName.startsWith("xmlns")) {
                if (nonTaglibAttrs == null) {
                    nonTaglibAttrs = new AttributesImpl();
                }
                nonTaglibAttrs.addAttribute(attrs.getURI(i), attrs.getLocalName(i), attrs.getQName(i), attrs.getType(i), attrs.getValue(i));
            } else {
                if (attrQName.startsWith("xmlns:jsp")) {
                    isTaglib = true;
                } else {
                    String attrUri = attrs.getValue(i);
                    // TaglibInfo for this uri already established in
                    // startPrefixMapping
                    isTaglib = pageInfo.hasTaglib(attrUri);
                }
                if (isTaglib) {
                    if (taglibAttrs == null) {
                        taglibAttrs = new AttributesImpl();
                    }
                    taglibAttrs.addAttribute(attrs.getURI(i), attrs.getLocalName(i), attrs.getQName(i), attrs.getType(i), attrs.getValue(i));
                } else {
                    if (nonTaglibXmlnsAttrs == null) {
                        nonTaglibXmlnsAttrs = new AttributesImpl();
                    }
                    nonTaglibXmlnsAttrs.addAttribute(attrs.getURI(i), attrs.getLocalName(i), attrs.getQName(i), attrs.getType(i), attrs.getValue(i));
                }
            }
        }
    }
    Node node = null;
    if (tagDependentPending && JSP_URI.equals(uri) && localName.equals(BODY_ACTION)) {
        tagDependentPending = false;
        tagDependentNesting++;
        current = parseStandardAction(qName, localName, nonTaglibAttrs, nonTaglibXmlnsAttrs, taglibAttrs, startMark, current);
        return;
    }
    if (tagDependentPending && JSP_URI.equals(uri) && localName.equals(ATTRIBUTE_ACTION)) {
        current = parseStandardAction(qName, localName, nonTaglibAttrs, nonTaglibXmlnsAttrs, taglibAttrs, startMark, current);
        return;
    }
    if (tagDependentPending) {
        tagDependentPending = false;
        tagDependentNesting++;
    }
    if (tagDependentNesting > 0) {
        node = new Node.UninterpretedTag(qName, localName, nonTaglibAttrs, nonTaglibXmlnsAttrs, taglibAttrs, startMark, current);
    } else if (JSP_URI.equals(uri)) {
        node = parseStandardAction(qName, localName, nonTaglibAttrs, nonTaglibXmlnsAttrs, taglibAttrs, startMark, current);
    } else {
        node = parseCustomAction(qName, localName, uri, nonTaglibAttrs, nonTaglibXmlnsAttrs, taglibAttrs, startMark, current);
        if (node == null) {
            node = new Node.UninterpretedTag(qName, localName, nonTaglibAttrs, nonTaglibXmlnsAttrs, taglibAttrs, startMark, current);
        } else {
            // custom action
            String bodyType = getBodyType((Node.CustomTag) node);
            if (scriptlessBodyNode == null && bodyType.equalsIgnoreCase(TagInfo.BODY_CONTENT_SCRIPTLESS)) {
                scriptlessBodyNode = node;
            } else if (TagInfo.BODY_CONTENT_TAG_DEPENDENT.equalsIgnoreCase(bodyType)) {
                tagDependentPending = true;
            }
        }
    }
    current = node;
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) SAXParseException(org.xml.sax.SAXParseException)

Example 75 with AttributesImpl

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

the class ManagedEntityConfigXmlGenerator method generateSSL.

/**
   * Generates XML for the SSL configuration of the distributed system.
   */
private void generateSSL() throws SAXException {
    DistributedSystemConfig config = this.system.getConfig();
    boolean sslEnabled = config.isSSLEnabled();
    if (!sslEnabled) {
        return;
    }
    AttributesImpl atts = new AttributesImpl();
    atts.addAttribute("", "", AUTHENTICATION_REQUIRED, "", String.valueOf(config.isSSLAuthenticationRequired()));
    handler.startElement("", SSL, SSL, atts);
    String protocols = config.getSSLProtocols();
    if (protocols != null) {
        handler.startElement("", PROTOCOLS, PROTOCOLS, EMPTY);
        handler.characters(protocols.toCharArray(), 0, protocols.length());
        handler.endElement("", PROTOCOLS, PROTOCOLS);
    }
    String ciphers = config.getSSLCiphers();
    if (ciphers != null) {
        handler.startElement("", CIPHERS, CIPHERS, EMPTY);
        handler.characters(ciphers.toCharArray(), 0, ciphers.length());
        handler.endElement("", CIPHERS, CIPHERS);
    }
    Properties sslProps = config.getSSLProperties();
    for (Iterator iter = sslProps.entrySet().iterator(); iter.hasNext(); ) {
        Map.Entry entry = (Map.Entry) iter.next();
        String key = (String) entry.getKey();
        String value = (String) entry.getValue();
        handler.startElement("", PROPERTY, PROPERTY, EMPTY);
        handler.startElement("", KEY, KEY, EMPTY);
        handler.characters(key.toCharArray(), 0, key.length());
        handler.endElement("", KEY, KEY);
        handler.startElement("", VALUE, VALUE, EMPTY);
        handler.characters(value.toCharArray(), 0, value.length());
        handler.endElement("", VALUE, VALUE);
        handler.endElement("", PROPERTY, PROPERTY);
    }
    handler.endElement("", SSL, SSL);
}
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