Search in sources :

Example 36 with Attribute

use of javax.xml.stream.events.Attribute in project teiid by teiid.

the class XMLEventStreamReader method initAttributes.

private void initAttributes() {
    if (!event.isStartElement()) {
        throw new IllegalStateException();
    }
    if (event != attributesEvent) {
        attributesEvent = event;
        attributesList = new ArrayList<>();
        Iterator attributes = event.asStartElement().getAttributes();
        while (attributes.hasNext()) {
            Attribute attribute = (Attribute) attributes.next();
            attributesList.add(attribute);
        }
    }
}
Also used : Attribute(javax.xml.stream.events.Attribute) Iterator(java.util.Iterator)

Example 37 with Attribute

use of javax.xml.stream.events.Attribute in project santuario-java by apache.

the class XMLSignatureOutputProcessor method processEvent.

@Override
public void processEvent(XMLSecEvent xmlSecEvent, OutputProcessorChain outputProcessorChain) throws XMLStreamException, XMLSecurityException {
    if (xmlSecEvent.getEventType() == XMLStreamConstants.START_ELEMENT) {
        XMLSecStartElement xmlSecStartElement = xmlSecEvent.asStartElement();
        // avoid double signature when child elements matches too
        if (getActiveInternalSignatureOutputProcessor() == null) {
            SecurePart securePart = securePartMatches(xmlSecStartElement, outputProcessorChain, XMLSecurityConstants.SIGNATURE_PARTS);
            if (securePart != null) {
                LOG.debug("Matched securePart for signature");
                InternalSignatureOutputProcessor internalSignatureOutputProcessor = null;
                SignaturePartDef signaturePartDef = new SignaturePartDef();
                signaturePartDef.setSecurePart(securePart);
                signaturePartDef.setTransforms(securePart.getTransforms());
                if (signaturePartDef.getTransforms() == null) {
                    signaturePartDef.setTransforms(new String[] { XMLSecurityConstants.NS_C14N_EXCL_OMIT_COMMENTS });
                }
                signaturePartDef.setExcludeVisibleC14Nprefixes(true);
                signaturePartDef.setDigestAlgo(securePart.getDigestMethod());
                if (signaturePartDef.getDigestAlgo() == null) {
                    signaturePartDef.setDigestAlgo(getSecurityProperties().getSignatureDigestAlgorithm());
                }
                if (securityProperties.isSignatureGenerateIds()) {
                    if (securePart.getIdToSign() == null) {
                        signaturePartDef.setGenerateXPointer(securePart.isGenerateXPointer());
                        signaturePartDef.setSigRefId(IDGenerator.generateID(null));
                        Attribute attribute = xmlSecStartElement.getAttributeByName(securityProperties.getIdAttributeNS());
                        if (attribute != null) {
                            signaturePartDef.setSigRefId(attribute.getValue());
                        } else {
                            List<XMLSecAttribute> attributeList = new ArrayList<>(1);
                            attributeList.add(createAttribute(securityProperties.getIdAttributeNS(), signaturePartDef.getSigRefId()));
                            xmlSecEvent = addAttributes(xmlSecStartElement, attributeList);
                        }
                    } else {
                        signaturePartDef.setSigRefId(securePart.getIdToSign());
                    }
                }
                getSignaturePartDefList().add(signaturePartDef);
                internalSignatureOutputProcessor = new InternalSignatureOutputProcessor(signaturePartDef, xmlSecStartElement);
                internalSignatureOutputProcessor.setXMLSecurityProperties(getSecurityProperties());
                internalSignatureOutputProcessor.setAction(getAction());
                internalSignatureOutputProcessor.addAfterProcessor(XMLSignatureOutputProcessor.class.getName());
                internalSignatureOutputProcessor.addBeforeProcessor(XMLSignatureEndingOutputProcessor.class.getName());
                internalSignatureOutputProcessor.init(outputProcessorChain);
                setActiveInternalSignatureOutputProcessor(internalSignatureOutputProcessor);
            }
        }
    }
    outputProcessorChain.processEvent(xmlSecEvent);
}
Also used : SecurePart(org.apache.xml.security.stax.ext.SecurePart) XMLSecStartElement(org.apache.xml.security.stax.ext.stax.XMLSecStartElement) SignaturePartDef(org.apache.xml.security.stax.impl.SignaturePartDef) XMLSecAttribute(org.apache.xml.security.stax.ext.stax.XMLSecAttribute) Attribute(javax.xml.stream.events.Attribute) ArrayList(java.util.ArrayList) XMLSecAttribute(org.apache.xml.security.stax.ext.stax.XMLSecAttribute)

Example 38 with Attribute

use of javax.xml.stream.events.Attribute in project santuario-java by apache.

the class XMLSecurityStreamReader method getAttributeValue.

@Override
public String getAttributeValue(String namespaceURI, String localName) {
    XMLSecEvent xmlSecEvent = getCurrentEvent();
    if (xmlSecEvent.getEventType() != START_ELEMENT) {
        throw new IllegalStateException(ERR_STATE_NOT_STELEM);
    }
    Attribute attribute = xmlSecEvent.asStartElement().getAttributeByName(new QName(namespaceURI, localName));
    if (attribute != null) {
        return attribute.getValue();
    }
    return null;
}
Also used : Attribute(javax.xml.stream.events.Attribute) QName(javax.xml.namespace.QName) XMLSecEvent(org.apache.xml.security.stax.ext.stax.XMLSecEvent)

Example 39 with Attribute

use of javax.xml.stream.events.Attribute in project contribution by checkstyle.

the class CheckstyleConfigurationsParser method processModuleTag.

/**
 * Parses single "module" tag.
 *
 * @param reader
 *        StAX parser interface.
 * @param startElement
 *        start element of the tag.
 * @param parent
 *        parent module instance.
 * @throws XMLStreamException
 *         on internal StAX failure.
 */
private static void processModuleTag(XMLEventReader reader, StartElement startElement, ConfigurationModule parent) throws XMLStreamException {
    String childModuleName = null;
    final Iterator<Attribute> attributes = startElement.getAttributes();
    while (attributes.hasNext()) {
        final Attribute attribute = attributes.next();
        if (attribute.getName().toString().equals(NAME_ATTR)) {
            childModuleName = attribute.getValue();
        }
    }
    final ConfigurationModule childModule = new ConfigurationModule(childModuleName);
    parseModule(reader, childModule);
    parent.addChild(childModule);
}
Also used : Attribute(javax.xml.stream.events.Attribute) MergedConfigurationModule(com.github.checkstyle.data.MergedConfigurationModule)

Example 40 with Attribute

use of javax.xml.stream.events.Attribute in project contribution by checkstyle.

the class CheckstyleConfigurationsParser method processMessageTag.

/**
 * Parses single "message" tag.
 *
 * @param startElement
 *        start element of the tag.
 * @param parent
 *        parent module instance.
 */
private static void processMessageTag(StartElement startElement, ConfigurationModule parent) {
    String propertyName = null;
    String propertyValue = null;
    final Iterator<Attribute> attributes = startElement.getAttributes();
    while (attributes.hasNext()) {
        final Attribute attribute = attributes.next();
        final String attributeName = attribute.getName().toString();
        if (attributeName.equals(KEY_ATTR)) {
            propertyName = attribute.getValue();
        } else if (attributeName.equals(VALUE_ATTR)) {
            propertyValue = attribute.getValue();
        }
    }
    parent.addProperty(propertyName, propertyValue);
}
Also used : Attribute(javax.xml.stream.events.Attribute)

Aggregations

Attribute (javax.xml.stream.events.Attribute)140 QName (javax.xml.namespace.QName)71 StartElement (javax.xml.stream.events.StartElement)62 XMLEvent (javax.xml.stream.events.XMLEvent)52 XMLEventReader (javax.xml.stream.XMLEventReader)30 Namespace (javax.xml.stream.events.Namespace)26 EndElement (javax.xml.stream.events.EndElement)25 ArrayList (java.util.ArrayList)23 XMLStreamException (javax.xml.stream.XMLStreamException)20 XMLInputFactory (javax.xml.stream.XMLInputFactory)18 InputStream (java.io.InputStream)14 IOException (java.io.IOException)12 Iterator (java.util.Iterator)11 ByteArrayInputStream (java.io.ByteArrayInputStream)7 FileInputStream (java.io.FileInputStream)7 HashMap (java.util.HashMap)7 Test (org.junit.Test)7 HashSet (java.util.HashSet)6 Characters (javax.xml.stream.events.Characters)5 QNm (org.brackit.xquery.atomic.QNm)5