javax.xml.stream.XMLStreamReader#getAttributeValue ( )源码实例Demo

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

源代码1 项目: onos   文件: NetconfRpcParserUtil.java
/**
  * Parse first rpc-reply contained in the input.
  *
  * @param xsr input
  * @return {@link NetconfRpcReply} or null on error
  */
public static NetconfRpcReply parseRpcReply(XMLStreamReader xsr) {
    try {
        for ( ; xsr.hasNext(); xsr.next()) {
            if (xsr.isStartElement() &&
                xsr.getName().getLocalPart().equals("rpc-reply")) {

                NetconfRpcReply.Builder builder = NetconfRpcReply.builder();
                String msgId = xsr.getAttributeValue(null, "message-id");
                builder.withMessageId(msgId);
                xsr.nextTag();

                return parseRpcReplyBody(builder, xsr);
            }
        }
    } catch (XMLStreamException e) {
        log.error("Exception thrown parsing rpc-reply", e);
    }
    return null;
}
 
源代码2 项目: activiti6-boot2   文件: ItemDefinitionParser.java
public void parse(XMLStreamReader xtr, BpmnModel model) throws Exception {
  if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_ID))) {
    String itemDefinitionId = model.getTargetNamespace() + ":" + xtr.getAttributeValue(null, ATTRIBUTE_ID);
    String structureRef = xtr.getAttributeValue(null, ATTRIBUTE_STRUCTURE_REF);
    if (StringUtils.isNotEmpty(structureRef)) {
      ItemDefinition item = new ItemDefinition();
      item.setId(itemDefinitionId);
      BpmnXMLUtil.addXMLLocation(item, xtr);

      int indexOfP = structureRef.indexOf(':');
      if (indexOfP != -1) {
        String prefix = structureRef.substring(0, indexOfP);
        String resolvedNamespace = model.getNamespace(prefix);
        structureRef = resolvedNamespace + ":" + structureRef.substring(indexOfP + 1);
      } else {
        structureRef = model.getTargetNamespace() + ":" + structureRef;
      }

      item.setStructureRef(structureRef);
      item.setItemKind(xtr.getAttributeValue(null, ATTRIBUTE_ITEM_KIND));
      BpmnXMLUtil.parseChildElements(ELEMENT_ITEM_DEFINITION, item, xtr, model);
      model.addItemDefinition(itemDefinitionId, item);
    }
  }
}
 
private static void parsePathName(final XMLStreamReader reader, final Set<String> set) throws XMLStreamException {
    String name = null;
    final Set<Attribute> required = EnumSet.of(Attribute.NAME);
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
        final Attribute attribute = Attribute.of(reader.getAttributeName(i));
        required.remove(attribute);
        switch (attribute) {
            case NAME:
                name = reader.getAttributeValue(i);
                break;
            default:
                throw unexpectedContent(reader);
        }
    }
    if (!required.isEmpty()) {
        throw missingAttributes(reader.getLocation(), required);
    }
    set.add(name);

    // consume remainder of element
    parseNoContent(reader);
}
 
private static void parsePathName(final XMLStreamReader reader, final Set<String> set) throws XMLStreamException {
    String name = null;
    final Set<Attribute> required = EnumSet.of(Attribute.NAME);
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
        final Attribute attribute = Attribute.of(reader.getAttributeName(i));
        required.remove(attribute);
        switch (attribute) {
            case NAME:
                name = reader.getAttributeValue(i);
                break;
            default:
                throw unexpectedContent(reader);
        }
    }
    if (!required.isEmpty()) {
        throw missingAttributes(reader.getLocation(), required);
    }
    set.add(name);

    // consume remainder of element
    parseNoContent(reader);
}
 
源代码5 项目: openjdk-8   文件: XMLStreamReaderUtil.java
public AttributesImpl(XMLStreamReader reader) {
    if (reader == null) {

        // this is the case when we call getAttributes() on the
        // reader when it is not on a start tag
        atInfos = new AttributeInfo[0];
    } else {

        // this is the normal case
        int index = 0;
        int namespaceCount = reader.getNamespaceCount();
        int attributeCount = reader.getAttributeCount();
        atInfos = new AttributeInfo[namespaceCount + attributeCount];
        for (int i=0; i<namespaceCount; i++) {
            String namespacePrefix = reader.getNamespacePrefix(i);

            // will be null if default prefix. QName can't take null
            if (namespacePrefix == null) {
                namespacePrefix = "";
            }
            atInfos[index++] = new AttributeInfo(
                new QName(XMLNS_NAMESPACE_URI,
                    namespacePrefix,
                    "xmlns"),
                reader.getNamespaceURI(i));
        }
        for (int i=0; i<attributeCount; i++) {
            atInfos[index++] = new AttributeInfo(
                reader.getAttributeName(i),
                reader.getAttributeValue(i));
        }
    }
}
 
源代码6 项目: openjdk-8   文件: WSDLParserExtensionFacade.java
/**
 *
 * @param reader
 * @return If the element has wsdl:required attribute set to true
 */

private boolean isRequiredExtension(XMLStreamReader reader) {
    String required = reader.getAttributeValue(WSDLConstants.NS_WSDL, "required");
    if(required != null)
        return Boolean.parseBoolean(required);
    return false;
}
 
private static void parseSubsystem(final XMLStreamReader reader, final Set<String> subsystems) throws XMLStreamException {
    String name = null;
    final Set<Attribute> required = EnumSet.of(Attribute.NAME);
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
        final Attribute attribute = Attribute.of(reader.getAttributeName(i));
        required.remove(attribute);
        switch (attribute) {
            case NAME:
                name = reader.getAttributeValue(i);
                break;
            default:
                throw unexpectedContent(reader);
        }
    }
    if (!required.isEmpty()) {
        throw missingAttributes(reader.getLocation(), required);
    }
    subsystems.add(name);
    if (reader.hasNext()) {
        switch (reader.nextTag()) {
            case XMLStreamConstants.END_ELEMENT:
                return;
            default:
                throw unexpectedContent(reader);
        }
    }
}
 
源代码8 项目: activiti6-boot2   文件: MessageParser.java
public void parse(XMLStreamReader xtr, BpmnModel model) throws Exception {
  if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_ID))) {
    String messageId = xtr.getAttributeValue(null, ATTRIBUTE_ID);
    String messageName = xtr.getAttributeValue(null, ATTRIBUTE_NAME);
    String itemRef = parseItemRef(xtr.getAttributeValue(null, ATTRIBUTE_ITEM_REF), model);
    Message message = new Message(messageId, messageName, itemRef);
    BpmnXMLUtil.addXMLLocation(message, xtr);
    BpmnXMLUtil.parseChildElements(ELEMENT_MESSAGE, message, xtr, model);
    model.addMessage(message);
  }
}
 
源代码9 项目: powsybl-core   文件: TsoDisconnectedGenerator.java
public static TsoDisconnectedGenerator fromXml(String contingencyId, XMLStreamReader xmlsr) throws XMLStreamException {
    String text = null;
    Map<String, Float> disconnectedGenerators = new HashMap<>();
    String id = null;
    while (xmlsr.hasNext()) {
        int eventType = xmlsr.next();
        switch (eventType) {
            case XMLEvent.CHARACTERS:
                text = xmlsr.getText();
                break;

            case XMLEvent.START_ELEMENT:
                if (Objects.equals(ELEM_GENERATOR, xmlsr.getLocalName())) {
                    id = xmlsr.getAttributeValue(null, "id");
                }
                break;

            case XMLEvent.END_ELEMENT:
                switch (xmlsr.getLocalName()) {
                    case ELEM_GENERATOR:
                        if (id == null) {
                            throw new AssertionError();
                        }
                        float p = Float.parseFloat(text);
                        disconnectedGenerators.put(id, p);
                        id = null;
                        break;
                    case "index":
                        return new TsoDisconnectedGenerator(contingencyId, disconnectedGenerators);
                    default:
                        throw new AssertionError("Unexpected element: " + xmlsr.getLocalName());
                }
                break;

            default:
                break;
        }
    }
    throw new AssertionError("Should not happen");
}
 
源代码10 项目: openjdk-8-source   文件: EPRHeader.java
@Nullable
public String getAttribute(@NotNull String nsUri, @NotNull String localName) {
    try {
        XMLStreamReader sr = epr.read("EndpointReference"/*doesn't matter*/);
        while(sr.getEventType()!= XMLStreamConstants.START_ELEMENT)
            sr.next();

        return sr.getAttributeValue(nsUri,localName);
    } catch (XMLStreamException e) {
        // since we are reading from buffer, this can't happen.
        throw new AssertionError(e);
    }
}
 
源代码11 项目: secure-data-service   文件: XmiReader.java
protected static final boolean getBoolean(final XmiAttributeName name, final boolean defaultValue,
        final XMLStreamReader reader) {
    final String value = reader.getAttributeValue(GLOBAL_NAMESPACE, name.getLocalName());
    if (value != null) {
        return Boolean.valueOf(value);
    } else {
        return defaultValue;
    }
}
 
源代码12 项目: secure-data-service   文件: WadlReader.java
private static final String getHRef(final XMLStreamReader reader, final String defaultName) {
    final String name = reader.getAttributeValue(GLOBAL_NAMESPACE, WadlAttributeName.HREF.getLocalName());
    if (name != null) {
        return name;
    } else {
        return defaultName;
    }
}
 
/**
 * Reads policy reference URIs from PolicyURIs attribute and returns them
 * as a String array returns null if there is no such attribute. This method
 * will attempt to check for the attribute in every supported policy namespace.
 * Resulting array of URIs is concatenation of URIs defined in all found
 * PolicyURIs attribute version.
 */
private String[] getPolicyURIsFromAttr(final XMLStreamReader reader) {
    final StringBuilder policyUriBuffer = new StringBuilder();
    for (NamespaceVersion version : NamespaceVersion.values()) {
        final String value = reader.getAttributeValue(version.toString(), XmlToken.PolicyUris.toString());
        if (value != null) {
            policyUriBuffer.append(value).append(" ");
        }
    }
    return (policyUriBuffer.length() > 0) ? policyUriBuffer.toString().split("[\\n ]+") : null;
}
 
源代码14 项目: rich-test-results   文件: AntXmlParser.java
private void parseProperties(XMLStreamReader xmlStreamReader, TestSuite.Builder suiteBuilder)
    throws XMLStreamException {
  String tagName = null;
  do {
    xmlStreamReader.next();
    if (!xmlStreamReader.hasName()) {
      continue;
    }
    tagName = xmlStreamReader.getName().toString();
    if (xmlStreamReader.isStartElement()) {
      switch (tagName) {
        case "property":
          Builder builder = suiteBuilder.addPropertyBuilder();
          for (int i = 0; i < xmlStreamReader.getAttributeCount(); i++) {
            String attributeValue = xmlStreamReader.getAttributeValue(i);
            switch (xmlStreamReader.getAttributeName(i).toString()) {
              case "name":
                builder.setName(attributeValue);
                break;
              case "value":
                builder.setValue(attributeValue);
                break;
            }
          }
          break;
      }
    } else if (xmlStreamReader.isEndElement() && "properties".equals(tagName)) {
      break;
    }
  } while (!xmlStreamReader.isEndElement() || !"properties".equals(tagName));
}
 
源代码15 项目: atlas   文件: OSMParser.java
private Map<String, Object> extractProperties(XMLStreamReader parser ) {
    LinkedHashMap<String, Object> properties = new LinkedHashMap<String, Object>();
    for ( int i = 0; i < parser.getAttributeCount(); i++ )
    {
        String prop = parser.getAttributeLocalName( i );
        Object value = parser.getAttributeValue( i );
        properties.put( prop, value );
    }
    return properties;
}
 
源代码16 项目: openjdk-jdk8u   文件: PolicyWSDLParserExtension.java
/**
 * Reads policy reference URIs from PolicyURIs attribute and returns them
 * as a String array returns null if there is no such attribute. This method
 * will attempt to check for the attribute in every supported policy namespace.
 * Resulting array of URIs is concatenation of URIs defined in all found
 * PolicyURIs attribute version.
 */
private String[] getPolicyURIsFromAttr(final XMLStreamReader reader) {
    final StringBuilder policyUriBuffer = new StringBuilder();
    for (NamespaceVersion version : NamespaceVersion.values()) {
        final String value = reader.getAttributeValue(version.toString(), XmlToken.PolicyUris.toString());
        if (value != null) {
            policyUriBuffer.append(value).append(" ");
        }
    }
    return (policyUriBuffer.length() > 0) ? policyUriBuffer.toString().split("[\\n ]+") : null;
}
 
@Override
protected BaseElement convertXMLToElement(XMLStreamReader xtr, BpmnModel model) throws Exception {
  BusinessRuleTask businessRuleTask = new BusinessRuleTask();
  BpmnXMLUtil.addXMLLocation(businessRuleTask, xtr);
  businessRuleTask.setInputVariables(parseDelimitedList(xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, ATTRIBUTE_TASK_RULE_VARIABLES_INPUT)));
  businessRuleTask.setRuleNames(parseDelimitedList(xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, ATTRIBUTE_TASK_RULE_RULES)));
  businessRuleTask.setResultVariableName(xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, ATTRIBUTE_TASK_RULE_RESULT_VARIABLE));
  businessRuleTask.setClassName(xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, ATTRIBUTE_TASK_RULE_CLASS));
  String exclude = xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, ATTRIBUTE_TASK_RULE_EXCLUDE);
  if (ATTRIBUTE_VALUE_TRUE.equalsIgnoreCase(exclude)) {
    businessRuleTask.setExclude(true);
  }
  parseChildElements(getXMLElementName(), businessRuleTask, model, xtr);
  return businessRuleTask;
}
 
源代码18 项目: jdk8u60   文件: ParserUtil.java
public static String getAttribute(XMLStreamReader reader, String name) {
    return reader.getAttributeValue(null, name);
}
 
源代码19 项目: olingo-odata2   文件: XmlMetadataConsumer.java
private Facets readFacets(final XMLStreamReader reader) throws XMLStreamException {
  String isNullable = reader.getAttributeValue(null, XmlMetadataConstants.EDM_PROPERTY_NULLABLE);
  String maxLength = reader.getAttributeValue(null, XmlMetadataConstants.EDM_PROPERTY_MAX_LENGTH);
  String precision = reader.getAttributeValue(null, XmlMetadataConstants.EDM_PROPERTY_PRECISION);
  String scale = reader.getAttributeValue(null, XmlMetadataConstants.EDM_PROPERTY_SCALE);
  String isFixedLength = reader.getAttributeValue(null, XmlMetadataConstants.EDM_PROPERTY_FIXED_LENGTH);
  String isUnicode = reader.getAttributeValue(null, XmlMetadataConstants.EDM_PROPERTY_UNICODE);
  String concurrencyMode = reader.getAttributeValue(null, XmlMetadataConstants.EDM_PROPERTY_CONCURRENCY_MODE);
  String defaultValue = reader.getAttributeValue(null, XmlMetadataConstants.EDM_PROPERTY_DEFAULT_VALUE);
  String collation = reader.getAttributeValue(null, XmlMetadataConstants.EDM_PROPERTY_COLLATION);
  if (isNullable != null || maxLength != null || precision != null || scale != null || isFixedLength != null
      || isUnicode != null || concurrencyMode != null || defaultValue != null || collation != null) {
    Facets facets = new Facets();
    if (isNullable != null) {
      facets.setNullable("true".equalsIgnoreCase(isNullable));
    }
    if (maxLength != null) {
      if (XmlMetadataConstants.EDM_PROPERTY_MAX_LENGTH_MAX_VALUE_FIRST_UPPERCASE.equals(maxLength)
          || XmlMetadataConstants.EDM_PROPERTY_MAX_LENGTH_MAX_VALUE_LOWERCASE.equals(maxLength)) {
        facets.setMaxLength(Integer.MAX_VALUE);
      } else {
        facets.setMaxLength(Integer.parseInt(maxLength));
      }
    }
    if (precision != null) {
      facets.setPrecision(Integer.parseInt(precision));
    }
    if (scale != null) {
      facets.setScale(Integer.parseInt(scale));
    }
    if (isFixedLength != null) {
      facets.setFixedLength("true".equalsIgnoreCase(isFixedLength));
    }
    if (isUnicode != null) {
      facets.setUnicode("true".equalsIgnoreCase(isUnicode));
    }
    for (int i = 0; i < EdmConcurrencyMode.values().length; i++) {
      if (EdmConcurrencyMode.values()[i].name().equalsIgnoreCase(concurrencyMode)) {
        facets.setConcurrencyMode(EdmConcurrencyMode.values()[i]);
      }
    }
    facets.setDefaultValue(defaultValue);
    facets.setCollation(collation);
    return facets;
  } else {
    return null;
  }
}
 
源代码20 项目: gate-core   文件: DocumentStaxUtils.java
/**
 * Processes the TextWithNodes element from this XMLStreamReader,
 * returning the text content of the document. The supplied map is
 * updated with the offset of each Node element encountered. The
 * reader must be positioned on the starting TextWithNodes tag and
 * will be returned positioned on the corresponding closing tag.
 * 
 * @param xsr
 * @param nodeIdToOffsetMap
 * @return the text content of the document
 */
public static String readTextWithNodes(XMLStreamReader xsr,
        Map<Integer, Long> nodeIdToOffsetMap) throws XMLStreamException {
  StringBuffer textBuf = new StringBuffer(20480);
  int eventType;
  while((eventType = xsr.next()) != XMLStreamConstants.END_ELEMENT) {
    switch(eventType) {
      case XMLStreamConstants.CHARACTERS:
      case XMLStreamConstants.CDATA:
        textBuf.append(xsr.getTextCharacters(), xsr.getTextStart(), xsr
                .getTextLength());
        break;

      case XMLStreamConstants.START_ELEMENT:
        // only Node elements allowed
        xsr.require(XMLStreamConstants.START_ELEMENT, null, "Node");
        String idString = xsr.getAttributeValue(null, "id");
        if(idString == null) {
          throw new XMLStreamException("Node element has no id", xsr
                  .getLocation());
        }
        try {
          Integer id = Integer.valueOf(idString);
          Long offset = Long.valueOf(textBuf.length());
          nodeIdToOffsetMap.put(id, offset);
        }
        catch(NumberFormatException nfe) {
          throw new XMLStreamException("Node element must have "
                  + "integer id", xsr.getLocation());
        }

        // Node element must be empty
        if(xsr.next() != XMLStreamConstants.END_ELEMENT) {
          throw new XMLStreamException("Node element within TextWithNodes "
                  + "must be empty.", xsr.getLocation());
        }
        break;

      default:
        // do nothing - ignore comments, PIs...
    }
  }
  return textBuf.toString();
}