Java 类javax.xml.stream.events.Attribute 实例源码

项目:InComb    文件:AtomParser.java   
/**
 * Basic setter
 */
protected void setLink(final RssElement element) {
    if (!actualElement.isEmpty() && actualElement.lastElement().equals(TAG_ENTRY)) {
        final Attribute relAttr = element.attributes.get(ATTR_REL);
        final Attribute hrefAttr = element.attributes.get(ATTR_HREF);
        if(relAttr != null && hrefAttr != null) {
            switch (relAttr.getValue()) {
                case REL_ALTERNATE:
                    parsingElement.getLastItem().setLink(hrefAttr.getValue());
                    break;

                // TODO get image
            }
        }
    }
}
项目:powsybl-core    文件:CimAnonymizer.java   
private Attribute anonymizeAttribute(Attribute attribute) {
    if (attribute.getName().equals(RDF_ID)) {
        return xmlStaxContext.eventFactory.createAttribute(attribute.getName(), dictionary.anonymize(attribute.getValue()));
    } else if (attribute.getName().equals(RDF_RESOURCE) || attribute.getName().equals(RDF_ABOUT)) {
        // skip outside graph rdf:ID references
        AttributeValue value  = AttributeValue.parseValue(attribute);
        if ((value.getNsUri() == null || !value.getNsUri().matches(CIM_URI_PATTERN)) &&
                (rdfIdValues == null || rdfIdValues.contains(value.get()))) {
            return xmlStaxContext.eventFactory.createAttribute(attribute.getName(), value.toString(dictionary));
        } else {
            skipped.add(attribute.getValue());
            return null;
        }
    } else {
        throw new AssertionError("Unknown attribute " + attribute.getName());
    }
}
项目:powsybl-core    文件:CimAnonymizer.java   
private XMLEvent anonymizeStartElement(StartElement startElement) {
    if (startElement.getName().getLocalPart().equals("IdentifiedObject.name")) {
        identifiedObjectName = true;
    } else if (startElement.getName().getLocalPart().equals("IdentifiedObject.description")) {
        identifiedObjectDescription = true;
    } else {
        Iterator it = startElement.getAttributes();
        if (it.hasNext()) {
            List<Attribute> newAttributes = new ArrayList<>();
            while (it.hasNext()) {
                Attribute attribute = (Attribute) it.next();
                Attribute newAttribute = anonymizeAttribute(attribute);
                newAttributes.add(newAttribute != null ? newAttribute : attribute);
            }
            return xmlStaxContext.eventFactory.createStartElement(startElement.getName(),
                                                                  newAttributes.iterator(),
                                                                  startElement.getNamespaces());
        }
    }
    return null;
}
项目:powsybl-core    文件:CimAnonymizer.java   
private void addRdfIdValues(InputStream is, Set<String> rdfIdValues) throws XMLStreamException {
    // memoize RDF ID values of the document
    XMLEventReader eventReader = xmlStaxContext.inputFactory.createXMLEventReader(is);
    while (eventReader.hasNext()) {
        XMLEvent event = eventReader.nextEvent();
        if (event.isStartElement()) {
            StartElement startElement = event.asStartElement();
            Iterator it = startElement.getAttributes();
            while (it.hasNext()) {
                Attribute attribute = (Attribute) it.next();
                QName name = attribute.getName();
                if (RDF_ID.equals(name)) {
                    rdfIdValues.add(attribute.getValue());
                }
            }
        }
    }
    eventReader.close();
}
项目:OpenJSharp    文件:XmlPolicyModelUnmarshaller.java   
private PolicySourceModel initializeNewModel(final StartElement element) throws PolicyException, XMLStreamException {
    PolicySourceModel model;

    final NamespaceVersion nsVersion = NamespaceVersion.resolveVersion(element.getName().getNamespaceURI());

    final Attribute policyName = getAttributeByName(element, nsVersion.asQName(XmlToken.Name));
    final Attribute xmlId = getAttributeByName(element, PolicyConstants.XML_ID);
    Attribute policyId = getAttributeByName(element, PolicyConstants.WSU_ID);

    if (policyId == null) {
        policyId = xmlId;
    } else if (xmlId != null) {
        throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0058_MULTIPLE_POLICY_IDS_NOT_ALLOWED()));
    }

    model = createSourceModel(nsVersion,
            (policyId == null) ? null : policyId.getValue(),
            (policyName == null) ? null : policyName.getValue());

    return model;
}
项目:OpenJSharp    文件:XmlPolicyModelUnmarshaller.java   
private Attribute getAttributeByName(final StartElement element,
        final QName attributeName) {
    // call standard API method to retrieve the attribute by name
    Attribute attribute = element.getAttributeByName(attributeName);

    // try to find the attribute without a prefix.
    if (attribute == null) {
        final String localAttributeName = attributeName.getLocalPart();
        final Iterator iterator = element.getAttributes();
        while (iterator.hasNext()) {
            final Attribute nextAttribute = (Attribute) iterator.next();
            final QName aName = nextAttribute.getName();
            final boolean attributeFoundByWorkaround = aName.equals(attributeName) || (aName.getLocalPart().equals(localAttributeName) && (aName.getPrefix() == null || "".equals(aName.getPrefix())));
            if (attributeFoundByWorkaround) {
                attribute = nextAttribute;
                break;
            }

        }
    }

    return attribute;
}
项目:OpenJSharp    文件:TubelineFeatureReader.java   
public TubelineFeature parse(XMLEventReader reader) throws WebServiceException {
    try {
        final StartElement element = reader.nextEvent().asStartElement();
        boolean attributeEnabled = true;
        final Iterator iterator = element.getAttributes();
        while (iterator.hasNext()) {
            final Attribute nextAttribute = (Attribute) iterator.next();
            final QName attributeName = nextAttribute.getName();
            if (ENABLED_ATTRIBUTE_NAME.equals(attributeName)) {
                attributeEnabled = ParserUtil.parseBooleanValue(nextAttribute.getValue());
            } else if (NAME_ATTRIBUTE_NAME.equals(attributeName)) {
                // TODO use name attribute
            } else {
                // TODO logging message
                throw LOGGER.logSevereException(new WebServiceException("Unexpected attribute"));
            }
        }
        return parseFactories(attributeEnabled, element, reader);
    } catch (XMLStreamException e) {
        throw LOGGER.logSevereException(new WebServiceException("Failed to unmarshal XML document", e));
    }
}
项目:aws-sdk-java-v2    文件:StaxUnmarshallerContext.java   
/**
 * Returns the text contents of the current element being parsed.
 *
 * @return The text contents of the current element being parsed.
 */
public String readText() throws XMLStreamException {
    if (isInsideResponseHeader()) {
        return getHeader(currentHeader);
    }
    if (currentEvent.isAttribute()) {
        Attribute attribute = (Attribute) currentEvent;
        return attribute.getValue();
    }

    StringBuilder sb = new StringBuilder();
    while (true) {
        XMLEvent event = eventReader.peek();
        if (event.getEventType() == XMLStreamConstants.CHARACTERS) {
            eventReader.nextEvent();
            sb.append(event.asCharacters().getData());
        } else if (event.getEventType() == XMLStreamConstants.END_ELEMENT) {
            return sb.toString();
        } else {
            throw new RuntimeException("Encountered unexpected event: " + event.toString());
        }
    }
}
项目:ibm-cos-sdk-java    文件:StaxUnmarshallerContext.java   
/**
 * Returns the text contents of the current element being parsed.
 *
 * @return The text contents of the current element being parsed.
 * @throws XMLStreamException
 */
public String readText() throws XMLStreamException {
    if (isInsideResponseHeader()) {
        return getHeader(currentHeader);
    }
    if (currentEvent.isAttribute()) {
        Attribute attribute = (Attribute)currentEvent;
        return attribute.getValue();
    }

    StringBuilder sb = new StringBuilder();
    while (true) {
        XMLEvent event = eventReader.peek();
        if (event.getEventType() == XMLStreamConstants.CHARACTERS) {
            eventReader.nextEvent();
            sb.append(event.asCharacters().getData());
        } else if (event.getEventType() == XMLStreamConstants.END_ELEMENT) {
            return sb.toString();
        } else {
            throw new RuntimeException("Encountered unexpected event: " + event.toString());
        }
    }
}
项目:openjdk-jdk10    文件:XmlPolicyModelUnmarshaller.java   
private PolicySourceModel initializeNewModel(final StartElement element) throws PolicyException, XMLStreamException {
    PolicySourceModel model;

    final NamespaceVersion nsVersion = NamespaceVersion.resolveVersion(element.getName().getNamespaceURI());

    final Attribute policyName = getAttributeByName(element, nsVersion.asQName(XmlToken.Name));
    final Attribute xmlId = getAttributeByName(element, PolicyConstants.XML_ID);
    Attribute policyId = getAttributeByName(element, PolicyConstants.WSU_ID);

    if (policyId == null) {
        policyId = xmlId;
    } else if (xmlId != null) {
        throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0058_MULTIPLE_POLICY_IDS_NOT_ALLOWED()));
    }

    model = createSourceModel(nsVersion,
            (policyId == null) ? null : policyId.getValue(),
            (policyName == null) ? null : policyName.getValue());

    return model;
}
项目:openjdk-jdk10    文件:XmlPolicyModelUnmarshaller.java   
private Attribute getAttributeByName(final StartElement element,
        final QName attributeName) {
    // call standard API method to retrieve the attribute by name
    Attribute attribute = element.getAttributeByName(attributeName);

    // try to find the attribute without a prefix.
    if (attribute == null) {
        final String localAttributeName = attributeName.getLocalPart();
        final Iterator iterator = element.getAttributes();
        while (iterator.hasNext()) {
            final Attribute nextAttribute = (Attribute) iterator.next();
            final QName aName = nextAttribute.getName();
            final boolean attributeFoundByWorkaround = aName.equals(attributeName) || (aName.getLocalPart().equals(localAttributeName) && (aName.getPrefix() == null || "".equals(aName.getPrefix())));
            if (attributeFoundByWorkaround) {
                attribute = nextAttribute;
                break;
            }

        }
    }

    return attribute;
}
项目:openjdk-jdk10    文件:TubelineFeatureReader.java   
public TubelineFeature parse(XMLEventReader reader) throws WebServiceException {
    try {
        final StartElement element = reader.nextEvent().asStartElement();
        boolean attributeEnabled = true;
        final Iterator iterator = element.getAttributes();
        while (iterator.hasNext()) {
            final Attribute nextAttribute = (Attribute) iterator.next();
            final QName attributeName = nextAttribute.getName();
            if (ENABLED_ATTRIBUTE_NAME.equals(attributeName)) {
                attributeEnabled = ParserUtil.parseBooleanValue(nextAttribute.getValue());
            } else if (NAME_ATTRIBUTE_NAME.equals(attributeName)) {
                // TODO use name attribute
            } else {
                // TODO logging message
                throw LOGGER.logSevereException(new WebServiceException("Unexpected attribute"));
            }
        }
        return parseFactories(attributeEnabled, element, reader);
    } catch (XMLStreamException e) {
        throw LOGGER.logSevereException(new WebServiceException("Failed to unmarshal XML document", e));
    }
}
项目:openjdk9    文件:XmlPolicyModelUnmarshaller.java   
private PolicySourceModel initializeNewModel(final StartElement element) throws PolicyException, XMLStreamException {
    PolicySourceModel model;

    final NamespaceVersion nsVersion = NamespaceVersion.resolveVersion(element.getName().getNamespaceURI());

    final Attribute policyName = getAttributeByName(element, nsVersion.asQName(XmlToken.Name));
    final Attribute xmlId = getAttributeByName(element, PolicyConstants.XML_ID);
    Attribute policyId = getAttributeByName(element, PolicyConstants.WSU_ID);

    if (policyId == null) {
        policyId = xmlId;
    } else if (xmlId != null) {
        throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0058_MULTIPLE_POLICY_IDS_NOT_ALLOWED()));
    }

    model = createSourceModel(nsVersion,
            (policyId == null) ? null : policyId.getValue(),
            (policyName == null) ? null : policyName.getValue());

    return model;
}
项目:openjdk9    文件:XmlPolicyModelUnmarshaller.java   
private Attribute getAttributeByName(final StartElement element,
        final QName attributeName) {
    // call standard API method to retrieve the attribute by name
    Attribute attribute = element.getAttributeByName(attributeName);

    // try to find the attribute without a prefix.
    if (attribute == null) {
        final String localAttributeName = attributeName.getLocalPart();
        final Iterator iterator = element.getAttributes();
        while (iterator.hasNext()) {
            final Attribute nextAttribute = (Attribute) iterator.next();
            final QName aName = nextAttribute.getName();
            final boolean attributeFoundByWorkaround = aName.equals(attributeName) || (aName.getLocalPart().equals(localAttributeName) && (aName.getPrefix() == null || "".equals(aName.getPrefix())));
            if (attributeFoundByWorkaround) {
                attribute = nextAttribute;
                break;
            }

        }
    }

    return attribute;
}
项目:openjdk9    文件:TubelineFeatureReader.java   
public TubelineFeature parse(XMLEventReader reader) throws WebServiceException {
    try {
        final StartElement element = reader.nextEvent().asStartElement();
        boolean attributeEnabled = true;
        final Iterator iterator = element.getAttributes();
        while (iterator.hasNext()) {
            final Attribute nextAttribute = (Attribute) iterator.next();
            final QName attributeName = nextAttribute.getName();
            if (ENABLED_ATTRIBUTE_NAME.equals(attributeName)) {
                attributeEnabled = ParserUtil.parseBooleanValue(nextAttribute.getValue());
            } else if (NAME_ATTRIBUTE_NAME.equals(attributeName)) {
                // TODO use name attribute
            } else {
                // TODO logging message
                throw LOGGER.logSevereException(new WebServiceException("Unexpected attribute"));
            }
        }
        return parseFactories(attributeEnabled, element, reader);
    } catch (XMLStreamException e) {
        throw LOGGER.logSevereException(new WebServiceException("Failed to unmarshal XML document", e));
    }
}
项目:spring4-understanding    文件:StaxEventXMLReader.java   
private void handleStartElement(StartElement startElement) throws SAXException {
    if (getContentHandler() != null) {
        QName qName = startElement.getName();
        if (hasNamespacesFeature()) {
            for (Iterator i = startElement.getNamespaces(); i.hasNext();) {
                Namespace namespace = (Namespace) i.next();
                startPrefixMapping(namespace.getPrefix(), namespace.getNamespaceURI());
            }
            for (Iterator i = startElement.getAttributes(); i.hasNext();){
                Attribute attribute = (Attribute) i.next();
                QName attributeName = attribute.getName();
                startPrefixMapping(attributeName.getPrefix(), attributeName.getNamespaceURI());
            }

            getContentHandler().startElement(qName.getNamespaceURI(), qName.getLocalPart(), toQualifiedName(qName),
                    getAttributes(startElement));
        }
        else {
            getContentHandler().startElement("", "", toQualifiedName(qName), getAttributes(startElement));
        }
    }
}
项目:spring4-understanding    文件:XMLEventStreamReader.java   
@SuppressWarnings("rawtypes")
private Attribute getAttribute(int index) {
    if (!this.event.isStartElement()) {
        throw new IllegalStateException();
    }
    int count = 0;
    Iterator attributes = this.event.asStartElement().getAttributes();
    while (attributes.hasNext()) {
        Attribute attribute = (Attribute) attributes.next();
        if (count == index) {
            return attribute;
        }
        else {
            count++;
        }
    }
    throw new IllegalArgumentException();
}
项目:svg-stockpile    文件:StartElementProcessor.java   
/**
 * Modifies a {@link StartElement}, removing attributes that do not have a {@link QName#getNamespaceURI()} that
 * equals {@link SvgDocument#NAMESPACE_URI}.
 * @param element The {@link StartElement} to remove attributes from.
 * @return The modified {@link StartElement}.
 */
@SuppressWarnings("unchecked")
private static XMLEvent removeNonSvgAttributes(StartElement element) {
    Iterator<Attribute> original = element.getAttributes();
    Collection<Attribute> modified = new ArrayList<>();

    while (original.hasNext()) {
        Attribute attribute = original.next();
        QName qName = attribute.getName();
        String namespaceUri = qName.getNamespaceURI();

        if (namespaceUri.isEmpty() || namespaceUri.equals(SvgDocument.NAMESPACE_URI)) {
            modified.add(attribute);
        }
    }

    return events.createStartElement(element.getName(), modified.iterator(), element.getNamespaces());
}
项目:xmlsec-gost    文件:ResolverXPointer.java   
public boolean matches(XMLSecStartElement xmlSecStartElement, QName idAttributeNS) {
    //when id is null we have #xpointer(/) and then we just return true for the first start-element
    if (id == null) {
        if (!rootNodeOccured) {
            rootNodeOccured = true;
            return true;
        }
        return false;
    }
    //case #xpointer(id('ID')):
    Attribute attribute = xmlSecStartElement.getAttributeByName(idAttributeNS);
    if (attribute != null && attribute.getValue().equals(id)) {
        return true;
    }
    return false;
}
项目:ts-reaktive    文件:TagWriteProtocol.java   
/**
 * @param name The qualified name of the tag to write, or none() to have the last item of [getters] deliver a {@link QName}.
 * @param getters Getter function for each sub-protocol to write (and additional first element delivering a QName, if name == none())
 * @param protocols Protocols to use to write each of the getter elements
 */
public TagWriteProtocol(Option<QName> name, Vector<? extends WriteProtocol<XMLEvent,?>> protocols, Vector<Function1<T, ?>> g) {
    if (name.isDefined() && (protocols.size() != g.size()) ||
        name.isEmpty() && (protocols.size() != g.size() - 1)) {
        throw new IllegalArgumentException ("Number of protocols and getters does not match");
    }
    this.name = name;
    this.getName = t -> name.getOrElse(() -> (QName) g.head().apply(t));

    Vector<Function1<T, ?>> getters = (name.isEmpty()) ? g.drop(1) : g;

    Tuple2<Vector<Tuple2<WriteProtocol<XMLEvent,?>, Function1<T, ?>>>, Vector<Tuple2<WriteProtocol<XMLEvent,?>, Function1<T, ?>>>> partition =
        ((Vector<WriteProtocol<XMLEvent,?>>)protocols).zip(getters)
        .partition(t -> Attribute.class.isAssignableFrom(t._1.getEventType()));

    this.attrProtocols = partition._1().map(t -> t._1());
    this.attrGetters = partition._1().map(t -> t._2());
    this.otherProtocols = partition._2().map(t -> t._1());
    this.otherGetters = partition._2().map(t -> t._2());
}
项目:lookaside_java-1.8.0-openjdk    文件:XmlPolicyModelUnmarshaller.java   
private PolicySourceModel initializeNewModel(final StartElement element) throws PolicyException, XMLStreamException {
    PolicySourceModel model;

    final NamespaceVersion nsVersion = NamespaceVersion.resolveVersion(element.getName().getNamespaceURI());

    final Attribute policyName = getAttributeByName(element, nsVersion.asQName(XmlToken.Name));
    final Attribute xmlId = getAttributeByName(element, PolicyConstants.XML_ID);
    Attribute policyId = getAttributeByName(element, PolicyConstants.WSU_ID);

    if (policyId == null) {
        policyId = xmlId;
    } else if (xmlId != null) {
        throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0058_MULTIPLE_POLICY_IDS_NOT_ALLOWED()));
    }

    model = createSourceModel(nsVersion,
            (policyId == null) ? null : policyId.getValue(),
            (policyName == null) ? null : policyName.getValue());

    return model;
}
项目:lookaside_java-1.8.0-openjdk    文件:XmlPolicyModelUnmarshaller.java   
private Attribute getAttributeByName(final StartElement element,
        final QName attributeName) {
    // call standard API method to retrieve the attribute by name
    Attribute attribute = element.getAttributeByName(attributeName);

    // try to find the attribute without a prefix.
    if (attribute == null) {
        final String localAttributeName = attributeName.getLocalPart();
        final Iterator iterator = element.getAttributes();
        while (iterator.hasNext()) {
            final Attribute nextAttribute = (Attribute) iterator.next();
            final QName aName = nextAttribute.getName();
            final boolean attributeFoundByWorkaround = aName.equals(attributeName) || (aName.getLocalPart().equals(localAttributeName) && (aName.getPrefix() == null || "".equals(aName.getPrefix())));
            if (attributeFoundByWorkaround) {
                attribute = nextAttribute;
                break;
            }

        }
    }

    return attribute;
}
项目:lookaside_java-1.8.0-openjdk    文件:TubelineFeatureReader.java   
public TubelineFeature parse(XMLEventReader reader) throws WebServiceException {
    try {
        final StartElement element = reader.nextEvent().asStartElement();
        boolean attributeEnabled = true;
        final Iterator iterator = element.getAttributes();
        while (iterator.hasNext()) {
            final Attribute nextAttribute = (Attribute) iterator.next();
            final QName attributeName = nextAttribute.getName();
            if (ENABLED_ATTRIBUTE_NAME.equals(attributeName)) {
                attributeEnabled = ParserUtil.parseBooleanValue(nextAttribute.getValue());
            } else if (NAME_ATTRIBUTE_NAME.equals(attributeName)) {
                // TODO use name attribute
            } else {
                // TODO logging message
                throw LOGGER.logSevereException(new WebServiceException("Unexpected attribute"));
            }
        }
        return parseFactories(attributeEnabled, element, reader);
    } catch (XMLStreamException e) {
        throw LOGGER.logSevereException(new WebServiceException("Failed to unmarshal XML document", e));
    }
}
项目:ZombieLib2    文件:Fb2FileParser.java   
private String getImageCoverage(XMLEventReader reader) throws XMLStreamException {
    while (reader.hasNext()) {
        XMLEvent event = reader.nextEvent();
        if (event.isStartElement()) {
            StartElement element = event.asStartElement();
            String localPart = element.getName().getLocalPart();
            if ("image".equals(localPart)) {
                QName hrefQName = new QName("http://www.w3.org/1999/xlink", "href");
                Attribute href = element.getAttributeByName(hrefQName);
                return href.getValue();
            }
        }
        if (event.isEndElement() && "coverage".equals(event.asEndElement().getName().getLocalPart())) {
            return null;
        }
    }
    return null;
}
项目:spring    文件:StaxEventXMLReader.java   
private void handleStartElement(StartElement startElement) throws SAXException {
    if (getContentHandler() != null) {
        QName qName = startElement.getName();
        if (hasNamespacesFeature()) {
            for (Iterator i = startElement.getNamespaces(); i.hasNext();) {
                Namespace namespace = (Namespace) i.next();
                startPrefixMapping(namespace.getPrefix(), namespace.getNamespaceURI());
            }
            for (Iterator i = startElement.getAttributes(); i.hasNext();){
                Attribute attribute = (Attribute) i.next();
                QName attributeName = attribute.getName();
                startPrefixMapping(attributeName.getPrefix(), attributeName.getNamespaceURI());
            }

            getContentHandler().startElement(qName.getNamespaceURI(), qName.getLocalPart(), toQualifiedName(qName),
                    getAttributes(startElement));
        }
        else {
            getContentHandler().startElement("", "", toQualifiedName(qName), getAttributes(startElement));
        }
    }
}
项目:spring    文件:XMLEventStreamReader.java   
@SuppressWarnings("rawtypes")
private Attribute getAttribute(int index) {
    if (!this.event.isStartElement()) {
        throw new IllegalStateException();
    }
    int count = 0;
    Iterator attributes = this.event.asStartElement().getAttributes();
    while (attributes.hasNext()) {
        Attribute attribute = (Attribute) attributes.next();
        if (count == index) {
            return attribute;
        }
        else {
            count++;
        }
    }
    throw new IllegalArgumentException();
}
项目:KeePassJava2    文件:KdbxInputTransformer.java   
public XMLEvent transform (XMLEvent event) {
    switch (event.getEventType()) {
        case START_ELEMENT: {
            Attribute attribute = event.asStartElement().getAttributeByName(new QName("Protected"));
            if (attribute != null) {
                decryptContent = Helpers.toBoolean(attribute.getValue());
            }
            break;
        }
        case END_ELEMENT: {
            decryptContent = false;
            break;
        }
        case CHARACTERS: {
            if (decryptContent) {
                String text = event.asCharacters().getData();
                text = new String(streamEncryptor.decrypt(Helpers.decodeBase64Content(text.getBytes(), false)));
                event = xmlEventFactory.createCharacters(text);
            }
            break;
        }
    }
    return event;
}
项目:techytax-zk    文件:StaxUtils.java   
private static void writeAttributeEvent(XMLEvent event, XMLStreamWriter writer) 
    throws XMLStreamException {

    Attribute attr = (Attribute)event;
    QName name = attr.getName();
    String nsURI = name.getNamespaceURI();
    String localName = name.getLocalPart();
    String prefix = name.getPrefix();
    String value = attr.getValue();

    if (prefix != null) {
        writer.writeAttribute(prefix, nsURI, localName, value);
    } else if (nsURI != null) {
        writer.writeAttribute(nsURI, localName, value);
    } else {
        writer.writeAttribute(localName, value);
    }
}
项目:contribution    文件:CheckstyleConfigurationsParser.java   
/**
 * 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);
}
项目:contribution    文件:CheckstyleConfigurationsParser.java   
/**
 * Parses single "property" tag.
 *
 * @param startElement
 *        start element of the tag.
 * @param parent
 *        parent module instance.
 */
private static void processPropertyTag(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(NAME_ATTR)) {
            propertyName = attribute.getValue();
        }
        else if (attributeName.equals(VALUE_ATTR)) {
            propertyValue = attribute.getValue();
        }
    }
    parent.addProperty(propertyName, propertyValue);
}
项目:contribution    文件:CheckstyleConfigurationsParser.java   
/**
 * 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);
}
项目:infobip-open-jdk-8    文件:XmlPolicyModelUnmarshaller.java   
private PolicySourceModel initializeNewModel(final StartElement element) throws PolicyException, XMLStreamException {
    PolicySourceModel model;

    final NamespaceVersion nsVersion = NamespaceVersion.resolveVersion(element.getName().getNamespaceURI());

    final Attribute policyName = getAttributeByName(element, nsVersion.asQName(XmlToken.Name));
    final Attribute xmlId = getAttributeByName(element, PolicyConstants.XML_ID);
    Attribute policyId = getAttributeByName(element, PolicyConstants.WSU_ID);

    if (policyId == null) {
        policyId = xmlId;
    } else if (xmlId != null) {
        throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0058_MULTIPLE_POLICY_IDS_NOT_ALLOWED()));
    }

    model = createSourceModel(nsVersion,
            (policyId == null) ? null : policyId.getValue(),
            (policyName == null) ? null : policyName.getValue());

    return model;
}
项目:infobip-open-jdk-8    文件:XmlPolicyModelUnmarshaller.java   
private Attribute getAttributeByName(final StartElement element,
        final QName attributeName) {
    // call standard API method to retrieve the attribute by name
    Attribute attribute = element.getAttributeByName(attributeName);

    // try to find the attribute without a prefix.
    if (attribute == null) {
        final String localAttributeName = attributeName.getLocalPart();
        final Iterator iterator = element.getAttributes();
        while (iterator.hasNext()) {
            final Attribute nextAttribute = (Attribute) iterator.next();
            final QName aName = nextAttribute.getName();
            final boolean attributeFoundByWorkaround = aName.equals(attributeName) || (aName.getLocalPart().equals(localAttributeName) && (aName.getPrefix() == null || "".equals(aName.getPrefix())));
            if (attributeFoundByWorkaround) {
                attribute = nextAttribute;
                break;
            }

        }
    }

    return attribute;
}
项目:infobip-open-jdk-8    文件:TubelineFeatureReader.java   
public TubelineFeature parse(XMLEventReader reader) throws WebServiceException {
    try {
        final StartElement element = reader.nextEvent().asStartElement();
        boolean attributeEnabled = true;
        final Iterator iterator = element.getAttributes();
        while (iterator.hasNext()) {
            final Attribute nextAttribute = (Attribute) iterator.next();
            final QName attributeName = nextAttribute.getName();
            if (ENABLED_ATTRIBUTE_NAME.equals(attributeName)) {
                attributeEnabled = ParserUtil.parseBooleanValue(nextAttribute.getValue());
            } else if (NAME_ATTRIBUTE_NAME.equals(attributeName)) {
                // TODO use name attribute
            } else {
                // TODO logging message
                throw LOGGER.logSevereException(new WebServiceException("Unexpected attribute"));
            }
        }
        return parseFactories(attributeEnabled, element, reader);
    } catch (XMLStreamException e) {
        throw LOGGER.logSevereException(new WebServiceException("Failed to unmarshal XML document", e));
    }
}
项目:teiid    文件:XMLEventStreamReader.java   
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();
}
项目:datacollector    文件:ElementMatcherImpl.java   
@Override
public boolean checkStartElement(StartElement startElement) {
  if (wildcardElement || isQualifiedMatch(startElement.getName())) {
    numElementsSeen++;
    if (byIndex) {
      return numElementsSeen == index;
    } else if (byAttribute) {
      final Iterator<?> attrIter = startElement.getAttributes();
      while (attrIter.hasNext()) {
        Attribute attrib = (Attribute) attrIter.next();
        if (attrib.getName().getLocalPart().equals(attributeName) &&
            (Constants.WILDCARD.equals(attributeValue)) || attrib.getValue().equals(attributeValue)) {
          return true;
        }
      }
      return false;
    } else {
      return true;
    }
  } else {
    return false;
  }
}
项目:travelingsales    文件:ODRVisualizationDataReader.java   
/**
 * reads a key/value pair for a certain way type.
 *
 * @param element way definition element
 */
private void readWayDefinition(final StartElement element) {
    currentElementType = ElementType.WAY_DEFINITION;

    currentKey = null;
    currentValue = null;

    for (Iterator<?> attributes = element.getAttributes(); attributes.hasNext();) {
        Attribute attribute = (Attribute) attributes.next();
        if (attribute.getName().toString().equals("key")) {
           currentKey = attribute.getValue();
        } else if (attribute.getName().toString().equals("value")) {
            currentValue = attribute.getValue();
        }
    }
}
项目:OLD-OpenJDK8    文件:XmlPolicyModelUnmarshaller.java   
private PolicySourceModel initializeNewModel(final StartElement element) throws PolicyException, XMLStreamException {
    PolicySourceModel model;

    final NamespaceVersion nsVersion = NamespaceVersion.resolveVersion(element.getName().getNamespaceURI());

    final Attribute policyName = getAttributeByName(element, nsVersion.asQName(XmlToken.Name));
    final Attribute xmlId = getAttributeByName(element, PolicyConstants.XML_ID);
    Attribute policyId = getAttributeByName(element, PolicyConstants.WSU_ID);

    if (policyId == null) {
        policyId = xmlId;
    } else if (xmlId != null) {
        throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0058_MULTIPLE_POLICY_IDS_NOT_ALLOWED()));
    }

    model = createSourceModel(nsVersion,
            (policyId == null) ? null : policyId.getValue(),
            (policyName == null) ? null : policyName.getValue());

    return model;
}
项目:OLD-OpenJDK8    文件:XmlPolicyModelUnmarshaller.java   
private Attribute getAttributeByName(final StartElement element,
        final QName attributeName) {
    // call standard API method to retrieve the attribute by name
    Attribute attribute = element.getAttributeByName(attributeName);

    // try to find the attribute without a prefix.
    if (attribute == null) {
        final String localAttributeName = attributeName.getLocalPart();
        final Iterator iterator = element.getAttributes();
        while (iterator.hasNext()) {
            final Attribute nextAttribute = (Attribute) iterator.next();
            final QName aName = nextAttribute.getName();
            final boolean attributeFoundByWorkaround = aName.equals(attributeName) || (aName.getLocalPart().equals(localAttributeName) && (aName.getPrefix() == null || "".equals(aName.getPrefix())));
            if (attributeFoundByWorkaround) {
                attribute = nextAttribute;
                break;
            }

        }
    }

    return attribute;
}
项目:OLD-OpenJDK8    文件:TubelineFeatureReader.java   
public TubelineFeature parse(XMLEventReader reader) throws WebServiceException {
    try {
        final StartElement element = reader.nextEvent().asStartElement();
        boolean attributeEnabled = true;
        final Iterator iterator = element.getAttributes();
        while (iterator.hasNext()) {
            final Attribute nextAttribute = (Attribute) iterator.next();
            final QName attributeName = nextAttribute.getName();
            if (ENABLED_ATTRIBUTE_NAME.equals(attributeName)) {
                attributeEnabled = ParserUtil.parseBooleanValue(nextAttribute.getValue());
            } else if (NAME_ATTRIBUTE_NAME.equals(attributeName)) {
                // TODO use name attribute
            } else {
                // TODO logging message
                throw LOGGER.logSevereException(new WebServiceException("Unexpected attribute"));
            }
        }
        return parseFactories(attributeEnabled, element, reader);
    } catch (XMLStreamException e) {
        throw LOGGER.logSevereException(new WebServiceException("Failed to unmarshal XML document", e));
    }
}