javax.xml.stream.events.StartElement#getAttributes ( )源码实例Demo

下面列出了javax.xml.stream.events.StartElement#getAttributes ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: openjdk-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;
}
 
源代码2 项目: openjdk-jdk8u   文件: 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));
    }
}
 
源代码3 项目: TencentKona-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));
    }
}
 
/**
 * 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);
}
 
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));
		}
	}
}
 
源代码6 项目: testgrid   文件: TestNgResultsParser.java
/**
 * Read the name attribute from the classElement input.
 *
 * @param classElement the class element
 * @return the name attribute
 */
private String getClassName(StartElement classElement) {
    String classNameStr = "unknown";
    final Iterator attributes = classElement.getAttributes();
    while (attributes.hasNext()) {
        Attribute att = (Attribute) attributes.next();
        if (att.getName().getLocalPart().equals("classname")) {
            String[] split = att.getValue().split("\\.");
            //get the class name from fully qualified class name
            classNameStr = split[split.length - 1];
        }
        if (att.getName().getLocalPart().equals("name")) {
            classNameStr = StringUtil
                    .concatStrings(classNameStr, "#", att.getValue());
        }
    }
    return classNameStr;
}
 
源代码7 项目: netbeans   文件: RestXMLResponseParser.java
private HashMap<String, String> getMapEntry(StartElement entry) {
    HashMap<String, String> entryMap = new HashMap<>();
    Iterator iter = entry.getAttributes();
    while (iter.hasNext()) {
        Attribute att = (Attribute) iter.next();
        entryMap.put(att.getName().getLocalPart(), att.getValue());
    }
    return entryMap;
}
 
源代码8 项目: knox   文件: XmlFilterReader.java
private void bufferAttributes( StartElement event, Element element ) {
  Iterator attributes = event.getAttributes();
  while( attributes.hasNext() ) {
    Attribute attribute = (Attribute)attributes.next();
    bufferAttribute( element, attribute );
  }
}
 
private void parseAssertionData(NamespaceVersion nsVersion, String value, ModelNode childNode, final StartElement childElement) throws IllegalArgumentException, PolicyException {
    // finish assertion node processing: create and set assertion data...
    final Map<QName, String> attributeMap = new HashMap<QName, String>();
    boolean optional = false;
    boolean ignorable = false;

    final Iterator iterator = childElement.getAttributes();
    while (iterator.hasNext()) {
        final Attribute nextAttribute = (Attribute) iterator.next();
        final QName name = nextAttribute.getName();
        if (attributeMap.containsKey(name)) {
            throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0059_MULTIPLE_ATTRS_WITH_SAME_NAME_DETECTED_FOR_ASSERTION(nextAttribute.getName(), childElement.getName())));
        } else {
            if (nsVersion.asQName(XmlToken.Optional).equals(name)) {
                optional = parseBooleanValue(nextAttribute.getValue());
            } else if (nsVersion.asQName(XmlToken.Ignorable).equals(name)) {
                ignorable = parseBooleanValue(nextAttribute.getValue());
            } else {
                attributeMap.put(name, nextAttribute.getValue());
            }
        }
    }
    final AssertionData nodeData = new AssertionData(childElement.getName(), value, attributeMap, childNode.getType(), optional, ignorable);

    // check visibility value syntax if present...
    if (nodeData.containsAttribute(PolicyConstants.VISIBILITY_ATTRIBUTE)) {
        final String visibilityValue = nodeData.getAttributeValue(PolicyConstants.VISIBILITY_ATTRIBUTE);
        if (!PolicyConstants.VISIBILITY_VALUE_PRIVATE.equals(visibilityValue)) {
            throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0004_UNEXPECTED_VISIBILITY_ATTR_VALUE(visibilityValue)));
        }
    }

    childNode.setOrReplaceNodeData(nodeData);
}
 
源代码10 项目: TencentKona-8   文件: StAXEventConnector.java
/**
 * Get the attributes associated with the given START_ELEMENT StAXevent.
 *
 * @return the StAX attributes converted to an org.xml.sax.Attributes
 */
private Attributes getAttributes(StartElement event) {
    attrs.clear();

    // in SAX, namespace declarations are not part of attributes by default.
    // (there's a property to control that, but as far as we are concerned
    // we don't use it.) So don't add xmlns:* to attributes.

    // gather non-namespace attrs
    for (Iterator i = event.getAttributes(); i.hasNext();) {
        Attribute staxAttr = (Attribute)i.next();

        QName name = staxAttr.getName();
        String uri = fixNull(name.getNamespaceURI());
        String localName = name.getLocalPart();
        String prefix = name.getPrefix();
        String qName;
        if (prefix == null || prefix.length() == 0)
            qName = localName;
        else
            qName = prefix + ':' + localName;
        String type = staxAttr.getDTDType();
        String value = staxAttr.getValue();

        attrs.addAttribute(uri, localName, qName, type, value);
    }

    return attrs;
}
 
源代码11 项目: hottub   文件: StAXSchemaParser.java
private void fillXMLAttributes(StartElement event) {
    fAttributes.removeAllAttributes();
    final Iterator attrs = event.getAttributes();
    while (attrs.hasNext()) {
        Attribute attr = (Attribute) attrs.next();
        fillQName(fAttributeQName, attr.getName());
        String type = attr.getDTDType();
        int idx = fAttributes.getLength();
        fAttributes.addAttributeNS(fAttributeQName,
                (type != null) ? type : XMLSymbols.fCDATASymbol, attr.getValue());
        fAttributes.setSpecified(idx, attr.isSpecified());
    }
}
 
源代码12 项目: openjdk-8   文件: StAXSchemaParser.java
private void fillXMLAttributes(StartElement event) {
    fAttributes.removeAllAttributes();
    final Iterator attrs = event.getAttributes();
    while (attrs.hasNext()) {
        Attribute attr = (Attribute) attrs.next();
        fillQName(fAttributeQName, attr.getName());
        String type = attr.getDTDType();
        int idx = fAttributes.getLength();
        fAttributes.addAttributeNS(fAttributeQName,
                (type != null) ? type : XMLSymbols.fCDATASymbol, attr.getValue());
        fAttributes.setSpecified(idx, attr.isSpecified());
    }
}
 
源代码13 项目: lams   文件: AuditConfigParser.java
@SuppressWarnings("unchecked")
private AuditProviderEntry getEntry(XMLEventReader xmlEventReader) throws XMLStreamException
{
   XMLEvent xmlEvent = xmlEventReader.nextEvent(); 
   Map<String, Object> options = new HashMap<String,Object>();
   
   
   String codeName = null; 
   
   //We got the login-module element
   StartElement policyModuleElement = (StartElement) xmlEvent;
   //We got the login-module element
   Iterator<Attribute> attrs = policyModuleElement.getAttributes();
   while(attrs.hasNext())
   {
      Attribute attribute = attrs.next();
      
      QName attQName = attribute.getName();
      String attributeValue = StaxParserUtil.getAttributeValue(attribute);
      if("code".equals(attQName.getLocalPart()))
      {
         codeName = attributeValue; 
      } 
   } 
   //See if there are options
   ModuleOptionParser moParser = new ModuleOptionParser();
   options.putAll(moParser.parse(xmlEventReader));
   
   AuditProviderEntry entry =  new AuditProviderEntry(codeName, options);  
   return entry;
}
 
源代码14 项目: openjdk-8-source   文件: StAXEvent2SAX.java
/**
 * Get the attributes associated with the given START_ELEMENT StAXevent.
 *
 * @return the StAX attributes converted to an org.xml.sax.Attributes
 */
private Attributes getAttributes(StartElement event) {
    AttributesImpl attrs = new AttributesImpl();

    if ( !event.isStartElement() ) {
        throw new InternalError(
            "getAttributes() attempting to process: " + event);
    }

    // in SAX, namespace declarations are not part of attributes by default.
    // (there's a property to control that, but as far as we are concerned
    // we don't use it.) So don't add xmlns:* to attributes.

    // gather non-namespace attrs
    for (Iterator i = event.getAttributes(); i.hasNext();) {
        Attribute staxAttr = (javax.xml.stream.events.Attribute)i.next();

        String uri = staxAttr.getName().getNamespaceURI();
        if (uri == null) {
            uri = "";
        }
        String localName = staxAttr.getName().getLocalPart();
        String prefix = staxAttr.getName().getPrefix();
        String qName;
        if (prefix == null || prefix.length() == 0) {
            qName = localName;
        } else {
            qName = prefix + ':' + localName;
        }
        String type = staxAttr.getDTDType();
        String value = staxAttr.getValue();

        attrs.addAttribute(uri, localName, qName, type, value);
    }

    return attrs;
}
 
源代码15 项目: lams   文件: IdentityTrustConfigParser.java
@SuppressWarnings("unchecked")
private IdentityTrustModuleEntry getEntry(XMLEventReader xmlEventReader) throws XMLStreamException
{
   XMLEvent xmlEvent = xmlEventReader.nextEvent(); 
   Map<String, Object> options = new HashMap<String,Object>(); 
   
   String codeName = null; 
   ControlFlag flag = null;
   
   //We got the login-module element
   StartElement policyModuleElement = (StartElement) xmlEvent;
   //We got the login-module element
   Iterator<Attribute> attrs = policyModuleElement.getAttributes();
   while(attrs.hasNext())
   {
      Attribute attribute = attrs.next();
      
      QName attQName = attribute.getName();
      String attributeValue = StaxParserUtil.getAttributeValue(attribute);
      
      if("code".equals(attQName.getLocalPart()))
      {
         codeName = attributeValue; 
      }
      if ("flag".equals(attQName.getLocalPart()))
      {
         flag = ControlFlag.valueOf(attributeValue);
      }
   } 
   //See if there are options
   ModuleOptionParser moParser = new ModuleOptionParser();
   options.putAll(moParser.parse(xmlEventReader));
   
   IdentityTrustModuleEntry entry =  new IdentityTrustModuleEntry(codeName, options);  
   entry.setControlFlag(flag);
   return entry;
}
 
源代码16 项目: lams   文件: AuthenticationJASPIConfigParser.java
@SuppressWarnings("unchecked")
private AppConfigurationEntry getJAASEntry(XMLEventReader xmlEventReader) throws XMLStreamException
{
   XMLEvent xmlEvent = xmlEventReader.nextEvent();
   Map<String, Object> options = new HashMap<String, Object>();

   String codeName = null;
   LoginModuleControlFlag controlFlag = LoginModuleControlFlag.REQUIRED;

   //We got the login-module element
   StartElement loginModuleElement = (StartElement) xmlEvent;
   //We got the login-module element
   Iterator<Attribute> attrs = loginModuleElement.getAttributes();
   while (attrs.hasNext())
   {
      Attribute attribute = attrs.next();
      QName attQName = attribute.getName();
      String attributeValue = StaxParserUtil.getAttributeValue(attribute);

      if ("code".equals(attQName.getLocalPart()))
      {
         codeName = attributeValue;
      }
      else if ("flag".equals(attQName.getLocalPart()))
      {
         controlFlag = getControlFlag(attributeValue);
      }
   }
   //See if there are options
   ModuleOptionParser moParser = new ModuleOptionParser();
   options.putAll(moParser.parse(xmlEventReader));

   return new AppConfigurationEntry(codeName, controlFlag, options);
}
 
源代码17 项目: openjdk-8   文件: StAXEventConnector.java
/**
 * Get the attributes associated with the given START_ELEMENT StAXevent.
 *
 * @return the StAX attributes converted to an org.xml.sax.Attributes
 */
private Attributes getAttributes(StartElement event) {
    attrs.clear();

    // in SAX, namespace declarations are not part of attributes by default.
    // (there's a property to control that, but as far as we are concerned
    // we don't use it.) So don't add xmlns:* to attributes.

    // gather non-namespace attrs
    for (Iterator i = event.getAttributes(); i.hasNext();) {
        Attribute staxAttr = (Attribute)i.next();

        QName name = staxAttr.getName();
        String uri = fixNull(name.getNamespaceURI());
        String localName = name.getLocalPart();
        String prefix = name.getPrefix();
        String qName;
        if (prefix == null || prefix.length() == 0)
            qName = localName;
        else
            qName = prefix + ':' + localName;
        String type = staxAttr.getDTDType();
        String value = staxAttr.getValue();

        attrs.addAttribute(uri, localName, qName, type, value);
    }

    return attrs;
}
 
源代码18 项目: JDKSourceCode1.8   文件: StAXSchemaParser.java
private void fillXMLAttributes(StartElement event) {
    fAttributes.removeAllAttributes();
    final Iterator attrs = event.getAttributes();
    while (attrs.hasNext()) {
        Attribute attr = (Attribute) attrs.next();
        fillQName(fAttributeQName, attr.getName());
        String type = attr.getDTDType();
        int idx = fAttributes.getLength();
        fAttributes.addAttributeNS(fAttributeQName,
                (type != null) ? type : XMLSymbols.fCDATASymbol, attr.getValue());
        fAttributes.setSpecified(idx, attr.isSpecified());
    }
}
 
源代码19 项目: openjdk-jdk8u   文件: XmlPolicyModelUnmarshaller.java
private void parseAssertionData(NamespaceVersion nsVersion, String value, ModelNode childNode, final StartElement childElement) throws IllegalArgumentException, PolicyException {
    // finish assertion node processing: create and set assertion data...
    final Map<QName, String> attributeMap = new HashMap<QName, String>();
    boolean optional = false;
    boolean ignorable = false;

    final Iterator iterator = childElement.getAttributes();
    while (iterator.hasNext()) {
        final Attribute nextAttribute = (Attribute) iterator.next();
        final QName name = nextAttribute.getName();
        if (attributeMap.containsKey(name)) {
            throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0059_MULTIPLE_ATTRS_WITH_SAME_NAME_DETECTED_FOR_ASSERTION(nextAttribute.getName(), childElement.getName())));
        } else {
            if (nsVersion.asQName(XmlToken.Optional).equals(name)) {
                optional = parseBooleanValue(nextAttribute.getValue());
            } else if (nsVersion.asQName(XmlToken.Ignorable).equals(name)) {
                ignorable = parseBooleanValue(nextAttribute.getValue());
            } else {
                attributeMap.put(name, nextAttribute.getValue());
            }
        }
    }
    final AssertionData nodeData = new AssertionData(childElement.getName(), value, attributeMap, childNode.getType(), optional, ignorable);

    // check visibility value syntax if present...
    if (nodeData.containsAttribute(PolicyConstants.VISIBILITY_ATTRIBUTE)) {
        final String visibilityValue = nodeData.getAttributeValue(PolicyConstants.VISIBILITY_ATTRIBUTE);
        if (!PolicyConstants.VISIBILITY_VALUE_PRIVATE.equals(visibilityValue)) {
            throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0004_UNEXPECTED_VISIBILITY_ATTR_VALUE(visibilityValue)));
        }
    }

    childNode.setOrReplaceNodeData(nodeData);
}
 
源代码20 项目: contribution   文件: CheckstyleReportsParser.java
/**
 * Parses portion of the XML report.
 *
 * @param diffReport
 *        container for parsed data.
 * @param reader
 *        StAX parser interface.
 * @param numOfFilenames
 *        number of "file" tags to parse.
 * @param index
 *        internal index of the parsed file.
 * @throws XMLStreamException
 *         on internal parser error.
 */
private static void parseXmlPortion(DiffReport diffReport,
        XMLEventReader reader, int numOfFilenames, int index)
                throws XMLStreamException {
    int counter = numOfFilenames;
    String filename = null;
    List<CheckstyleRecord> records = null;
    while (reader.hasNext()) {
        final XMLEvent event = reader.nextEvent();
        if (event.isStartElement()) {
            final StartElement startElement = event.asStartElement();
            final String startElementName = startElement.getName()
                    .getLocalPart();
            // file tag encounter
            if (startElementName.equals(FILE_TAG)) {
                counter--;
                diffReport.getStatistics().incrementFileCount(index);
                final Iterator<Attribute> attributes = startElement
                        .getAttributes();
                while (attributes.hasNext()) {
                    final Attribute attribute = attributes.next();
                    if (attribute.getName().toString()
                            .equals(FILENAME_ATTR)) {
                        filename = attribute.getValue();
                    }
                }
                records = new ArrayList<>();
            }
            // error tag encounter
            else if (startElementName.equals(ERROR_TAG)) {
                records.add(parseErrorTag(startElement, diffReport.getStatistics(), index,
                        filename));
            }
        }
        if (event.isEndElement()) {
            final EndElement endElement = event.asEndElement();
            if (endElement.getName().getLocalPart().equals(FILE_TAG)) {
                diffReport.addRecords(records, filename);
                if (counter == 0) {
                    break;
                }
            }
        }
    }
}