Search in sources :

Example 86 with Attribute

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

the class AbstractSunburstGUI method processAttributes.

/**
 * Process attributes for string representation.
 *
 * @param pBuilder
 *          the builder instance to use
 */
public void processAttributes(final StringBuilder pBuilder) {
    checkNotNull(pBuilder);
    for (final Attribute att : mHitItem.getAttributes()) {
        if ("name".equals(att.getName().getLocalPart())) {
            pBuilder.append(" Attribute: ");
            appendString(pBuilder, att.getValue());
            break;
        }
    }
}
Also used : Attribute(javax.xml.stream.events.Attribute)

Example 87 with Attribute

use of javax.xml.stream.events.Attribute in project iaf by ibissource.

the class SchemaUtils method mergeXsdsGroupedByNamespaceToSchemasWithoutIncludes.

/**
 * @return XSD's when xmlStreamWriter is null, otherwise write to
 *		 xmlStreamWriter
 */
public static Set<XSD> mergeXsdsGroupedByNamespaceToSchemasWithoutIncludes(ClassLoader classLoader, Map<String, Set<XSD>> xsdsGroupedByNamespace, XMLStreamWriter xmlStreamWriter) throws XMLStreamException, IOException, ConfigurationException {
    Set<XSD> resultXsds = new HashSet<XSD>();
    for (String namespace : xsdsGroupedByNamespace.keySet()) {
        Set<XSD> xsds = xsdsGroupedByNamespace.get(namespace);
        // Get attributes of root elements and get import elements from all XSD's
        List<Attribute> rootAttributes = new ArrayList<Attribute>();
        List<Attribute> rootNamespaceAttributes = new ArrayList<Attribute>();
        List<XMLEvent> imports = new ArrayList<XMLEvent>();
        for (XSD xsd : xsds) {
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            XMLStreamWriter w = XmlUtils.REPAIR_NAMESPACES_OUTPUT_FACTORY.createXMLStreamWriter(byteArrayOutputStream, XmlUtils.STREAM_FACTORY_ENCODING);
            xsdToXmlStreamWriter(xsd, w, false, true, false, false, rootAttributes, rootNamespaceAttributes, imports, true);
        }
        // Write XSD's with merged root element
        XSD resultXsd = null;
        XMLStreamWriter w;
        if (xmlStreamWriter == null) {
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            resultXsd = new XSD();
            resultXsd.setClassLoader(classLoader);
            resultXsd.setNamespace(namespace);
            resultXsd.setByteArrayOutputStream(byteArrayOutputStream);
            resultXsd.setSourceXsds(xsds);
            w = XmlUtils.REPAIR_NAMESPACES_OUTPUT_FACTORY.createXMLStreamWriter(byteArrayOutputStream, XmlUtils.STREAM_FACTORY_ENCODING);
        } else {
            w = xmlStreamWriter;
        }
        int i = 0;
        for (XSD xsd : xsds) {
            i++;
            boolean skipFirstElement = true;
            boolean skipLastElement = true;
            if (xsds.size() == 1) {
                skipFirstElement = false;
                skipLastElement = false;
            } else {
                if (i == 1) {
                    skipFirstElement = false;
                } else if (i == xsds.size()) {
                    skipLastElement = false;
                }
            }
            xsdToXmlStreamWriter(xsd, w, false, true, skipFirstElement, skipLastElement, rootAttributes, rootNamespaceAttributes, imports, false);
        }
        if (resultXsd != null) {
            XSD firstXsd = xsds.iterator().next();
            resultXsd.setImportedSchemaLocationsToIgnore(firstXsd.getImportedSchemaLocationsToIgnore());
            resultXsd.setUseBaseImportedSchemaLocationsToIgnore(firstXsd.isUseBaseImportedSchemaLocationsToIgnore());
            resultXsd.setImportedNamespacesToIgnore(firstXsd.getImportedNamespacesToIgnore());
            resultXsd.init();
            resultXsds.add(resultXsd);
        }
    }
    return resultXsds;
}
Also used : Attribute(javax.xml.stream.events.Attribute) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) XMLEvent(javax.xml.stream.events.XMLEvent) HashSet(java.util.HashSet)

Example 88 with Attribute

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

the class SchemaLocationsRewriteTestCase method getAttributeValues.

private List<String> getAttributeValues(URL url, String localPart) throws Exception {
    String document = IOUtils.toString(url.openStream());
    log.trace(document);
    List<String> values = new ArrayList<>();
    XMLInputFactory xmlif = XMLInputFactory.newInstance();
    XMLEventReader eventReader = xmlif.createXMLEventReader(new ByteArrayInputStream(document.getBytes(StandardCharsets.UTF_8)));
    while (eventReader.hasNext()) {
        XMLEvent xmlEvent = eventReader.nextEvent();
        if (xmlEvent.getEventType() == XMLStreamConstants.START_ELEMENT) {
            StartElement startElement = xmlEvent.asStartElement();
            Attribute attribute = startElement.getAttributeByName(new QName("", localPart));
            if (attribute != null) {
                values.add(attribute.getValue());
            }
        }
    }
    return values;
}
Also used : StartElement(javax.xml.stream.events.StartElement) ByteArrayInputStream(java.io.ByteArrayInputStream) Attribute(javax.xml.stream.events.Attribute) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) XMLEvent(javax.xml.stream.events.XMLEvent) XMLEventReader(javax.xml.stream.XMLEventReader) XMLInputFactory(javax.xml.stream.XMLInputFactory)

Example 89 with Attribute

use of javax.xml.stream.events.Attribute in project uPortal by Jasig.

the class FixedXMLEventStreamReader method getAttribute.

private Attribute getAttribute(int index) {
    if (!event.isStartElement()) {
        throw new IllegalStateException();
    }
    int count = 0;
    Iterator attributes = event.asStartElement().getAttributes();
    while (attributes.hasNext()) {
        Attribute attribute = (Attribute) attributes.next();
        if (count == index) {
            return attribute;
        } else {
            count++;
        }
    }
    throw new IllegalArgumentException();
}
Also used : Attribute(javax.xml.stream.events.Attribute) Iterator(java.util.Iterator)

Example 90 with Attribute

use of javax.xml.stream.events.Attribute in project uPortal by Jasig.

the class PortletDefinitionAttributeSource method getAdditionalAttributes.

@Override
public final Iterator<Attribute> getAdditionalAttributes(HttpServletRequest request, HttpServletResponse response, StartElement event) {
    final QName eventName = event.getName();
    final String localEventName = eventName.getLocalPart();
    // Only pay attention to channel events
    if (!IUserLayoutManager.CHANNEL.equals(localEventName)) {
        return null;
    }
    final Collection<Attribute> attributes = new LinkedList<Attribute>();
    // Add the portlet's portlet name and either the webapp URL or framework flag to the list of
    // attributes.
    final Attribute fnameAttribute = event.getAttributeByName(PORTLET_FNAME_ATTR_NAME);
    if (fnameAttribute != null) {
        final String fname = fnameAttribute.getValue();
        IPortletDefinition def = portletDefinitionDao.getPortletDefinitionByFname(fname);
        if (def == null) {
            this.logger.warn("Cannot get portlet definition attributes.  No portlet definition found for fname: '" + fname + "'.");
        } else {
            IPortletDescriptorKey descriptorKey = def.getPortletDescriptorKey();
            attributes.add(xmlEventFactory.createAttribute(PORTLET_NAME_ATTRIBUTE, descriptorKey.getPortletName()));
            attributes.add(xmlEventFactory.createAttribute(PORTLET_LIFECYCLE_ATTRIBUTE, def.getLifecycleState().toString()));
            if (descriptorKey.isFrameworkPortlet()) {
                attributes.add(xmlEventFactory.createAttribute(FRAMEWORK_PORTLET_ATTRIBUTE, "true"));
            } else {
                attributes.add(xmlEventFactory.createAttribute(WEBAPP_NAME_ATTRIBUTE, descriptorKey.getWebAppName()));
            }
        }
    }
    return attributes.iterator();
}
Also used : Attribute(javax.xml.stream.events.Attribute) QName(javax.xml.namespace.QName) IPortletDescriptorKey(org.apereo.portal.portlet.om.IPortletDescriptorKey) LinkedList(java.util.LinkedList) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition)

Aggregations

Attribute (javax.xml.stream.events.Attribute)144 QName (javax.xml.namespace.QName)73 StartElement (javax.xml.stream.events.StartElement)63 XMLEvent (javax.xml.stream.events.XMLEvent)54 XMLEventReader (javax.xml.stream.XMLEventReader)30 EndElement (javax.xml.stream.events.EndElement)26 Namespace (javax.xml.stream.events.Namespace)26 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)6 QNm (org.brackit.xquery.atomic.QNm)5