Search in sources :

Example 26 with Attribute

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

the class SAMLAttributeValueParser method parse.

@Override
public Object parse(XMLEventReader xmlEventReader) throws ParsingException {
    StartElement element = StaxParserUtil.getNextStartElement(xmlEventReader);
    StaxParserUtil.validate(element, SAMLAssertionQNames.ATTRIBUTE_VALUE.getQName());
    Attribute nil = element.getAttributeByName(NIL);
    if (nil != null) {
        String nilValue = StaxParserUtil.getAttributeValue(nil);
        if (nilValue != null && (nilValue.equalsIgnoreCase("true") || nilValue.equals("1"))) {
            String elementText = StaxParserUtil.getElementText(xmlEventReader);
            if (elementText == null || elementText.isEmpty()) {
                return null;
            } else {
                throw logger.nullValueError("nil attribute is not in SAML20 format");
            }
        } else {
            throw logger.parserRequiredAttribute(JBossSAMLURIConstants.XSI_PREFIX.get() + ":nil");
        }
    }
    Attribute type = element.getAttributeByName(XSI_TYPE);
    if (type == null) {
        if (StaxParserUtil.hasTextAhead(xmlEventReader)) {
            return StaxParserUtil.getElementText(xmlEventReader);
        }
        // Else we may have Child Element
        XMLEvent xmlEvent = StaxParserUtil.peek(xmlEventReader);
        if (xmlEvent instanceof StartElement) {
            element = (StartElement) xmlEvent;
            final QName qName = element.getName();
            if (Objects.equals(qName, SAMLAssertionQNames.NAMEID.getQName())) {
                return SAMLParserUtil.parseNameIDType(xmlEventReader);
            }
        } else if (xmlEvent instanceof EndElement) {
            return "";
        }
        // when no type attribute assigned -> assume anyType
        return parseAnyTypeAsString(xmlEventReader);
    }
    // RK Added an additional type check for base64Binary type as calheers is passing this type
    String typeValue = StaxParserUtil.getAttributeValue(type);
    if (typeValue.contains(":string")) {
        return StaxParserUtil.getElementText(xmlEventReader);
    } else if (typeValue.contains(":anyType")) {
        return parseAnyTypeAsString(xmlEventReader);
    } else if (typeValue.contains(":base64Binary")) {
        return StaxParserUtil.getElementText(xmlEventReader);
    } else if (typeValue.contains(":date")) {
        return XMLTimeUtil.parse(StaxParserUtil.getElementText(xmlEventReader));
    } else if (typeValue.contains(":boolean")) {
        return StaxParserUtil.getElementText(xmlEventReader);
    }
    // KEYCLOAK-18417: Simply ignore unknown types
    logger.debug("Skipping attribute value of unsupported type " + typeValue);
    StaxParserUtil.bypassElementBlock(xmlEventReader);
    return null;
}
Also used : StartElement(javax.xml.stream.events.StartElement) Attribute(javax.xml.stream.events.Attribute) EndElement(javax.xml.stream.events.EndElement) QName(javax.xml.namespace.QName) XMLEvent(javax.xml.stream.events.XMLEvent)

Example 27 with Attribute

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

the class StaxParserUtil method getUriAttributeValue.

/**
 * Get the Attribute value
 *
 * @param startElement
 * @param tag localpart of the qname of the attribute
 *
 * @return
 */
public static URI getUriAttributeValue(StartElement startElement, HasQName attrName) {
    Attribute attr = startElement.getAttributeByName(attrName.getQName());
    String value = getAttributeValue(attr);
    return value == null ? null : URI.create(value);
}
Also used : Attribute(javax.xml.stream.events.Attribute)

Example 28 with Attribute

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

the class StaxParserUtil method getXmlTimeAttributeValue.

/**
 * Get the Attribute value
 *
 * @param startElement
 * @param tag localpart of the qname of the attribute
 *
 * @return
 */
public static XMLGregorianCalendar getXmlTimeAttributeValue(StartElement startElement, HasQName attrName) throws ParsingException {
    Attribute attr = startElement.getAttributeByName(attrName.getQName());
    String value = getAttributeValue(attr);
    return value == null ? null : XMLTimeUtil.parse(value);
}
Also used : Attribute(javax.xml.stream.events.Attribute)

Example 29 with Attribute

use of javax.xml.stream.events.Attribute in project hibernate-orm by hibernate.

the class JpaOrmXmlEventReader method wrap.

private StartElement wrap(StartElement startElement) {
    List<Attribute> newElementAttributeList = mapAttributes(startElement);
    List<Namespace> newNamespaceList = mapNamespaces(startElement);
    // Transfer the location info from the incoming event to the event factory
    // so that the event we ask it to generate for us has the same location info
    xmlEventFactory.setLocation(startElement.getLocation());
    return xmlEventFactory.createStartElement(new QName(MappingXsdSupport.INSTANCE.latestJpaDescriptor().getNamespaceUri(), startElement.getName().getLocalPart()), newElementAttributeList.iterator(), newNamespaceList.iterator());
}
Also used : Attribute(javax.xml.stream.events.Attribute) QName(javax.xml.namespace.QName) Namespace(javax.xml.stream.events.Namespace)

Example 30 with Attribute

use of javax.xml.stream.events.Attribute in project sirix by sirixdb.

the class AbstractTraverseModel method fillAttributes.

/**
 * Fill an attribute list with entries.
 *
 * @param rtx
 *          Sirix {@link NodeReadTrx}
 * @return {@link List} of {@link Attribute}s
 */
protected List<Attribute> fillAttributes(final NodeReadTrx rtx) {
    assert rtx != null;
    final XMLEventFactory eventFactory = XMLEventFactory.newInstance();
    // attributes in the axis.
    assert rtx.getKind() == Kind.ELEMENT;
    final int attNumber = rtx.getAttributeCount();
    final List<Attribute> attributes = new ArrayList<>(attNumber);
    for (int i = 0; i < attNumber; i++) {
        rtx.moveToAttribute(i);
        final QNm name = rtx.getName();
        attributes.add(eventFactory.createAttribute(new QName(name.getNamespaceURI(), name.getLocalName(), name.getPrefix()), rtx.getValue()));
        rtx.moveToParent();
    }
    return attributes;
}
Also used : QNm(org.brackit.xquery.atomic.QNm) Attribute(javax.xml.stream.events.Attribute) XMLEventFactory(javax.xml.stream.XMLEventFactory) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList)

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