Java Code Examples for javax.xml.stream.XMLStreamReader#hasNext()

The following examples show how to use javax.xml.stream.XMLStreamReader#hasNext() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StreamReaderBufferCreator.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private void store(XMLStreamReader reader) throws XMLStreamException {
    if (!reader.hasNext()) {
        return;
    }

    _eventType = reader.getEventType();
    switch (_eventType) {
        case XMLStreamReader.START_DOCUMENT:
            storeDocumentAndChildren(reader);
            break;
        case XMLStreamReader.START_ELEMENT:
            storeElementAndChildren(reader);
            break;
        default:
            throw new XMLStreamException("XMLStreamReader not positioned at a document or element");
    }

    increaseTreeCount();
}
 
Example 2
Source File: XMLStreamReaderTest.java    From FHIR with Apache License 2.0 6 votes vote down vote up
private static void parseMeta(java.lang.String elementName, XMLStreamReader reader) throws XMLStreamException {
    while (reader.hasNext()) {
        int eventType = reader.next();
        debug(reader);

        switch (eventType) {
        case XMLStreamReader.START_ELEMENT:
            java.lang.String localName = reader.getLocalName();
            System.out.println("localName: " + localName);
            switch (localName) {
            case "versionId":
                parseString("versionId", reader);
                break;
            case "lastUpdated":
                parseInstant("lastUpdated", reader);
                break;
            }
            break;
        case XMLStreamReader.END_ELEMENT:
            if (reader.getLocalName().equals(elementName)) {
                return;
            }
            break;
        }
    }
}
 
Example 3
Source File: XMLStreamReaderTest.java    From FHIR with Apache License 2.0 6 votes vote down vote up
private static void parseString(java.lang.String elementName, XMLStreamReader reader) throws XMLStreamException {
    java.lang.String value = reader.getAttributeValue(null, "value");
    System.out.println("    value: " + value);
    
    while (reader.hasNext()) {
        int eventType = reader.next();
        debug(reader);

        switch (eventType) {
        case XMLStreamReader.START_ELEMENT:
            java.lang.String localName = reader.getLocalName();
            System.out.println("localName: " + localName);
            switch (localName) {
                //
            }
            break;
        case XMLStreamReader.END_ELEMENT:
            if (reader.getLocalName().equals(elementName)) {
                return;
            }
            break;
        }
    }        
}
 
Example 4
Source File: EdmParser.java    From cloud-odata-java with Apache License 2.0 6 votes vote down vote up
private ReferentialConstraint readReferentialConstraint(final XMLStreamReader reader) throws XMLStreamException, EntityProviderException {
  reader.require(XMLStreamConstants.START_ELEMENT, Edm.NAMESPACE_EDM_2008_09, EdmParserConstants.EDM_ASSOCIATION_CONSTRAINT);
  ReferentialConstraint refConstraint = new ReferentialConstraint();
  List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();
  refConstraint.setAnnotationAttributes(readAnnotationAttribute(reader));
  while (reader.hasNext() && !(reader.isEndElement() && Edm.NAMESPACE_EDM_2008_09.equals(reader.getNamespaceURI()) && EdmParserConstants.EDM_ASSOCIATION_CONSTRAINT.equals(reader.getLocalName()))) {
    reader.next();
    if (reader.isStartElement()) {
      extractNamespaces(reader);
      currentHandledStartTagName = reader.getLocalName();
      if (EdmParserConstants.EDM_ASSOCIATION_PRINCIPAL.equals(currentHandledStartTagName)) {
        reader.require(XMLStreamConstants.START_ELEMENT, Edm.NAMESPACE_EDM_2008_09, EdmParserConstants.EDM_ASSOCIATION_PRINCIPAL);
        refConstraint.setPrincipal(readReferentialConstraintRole(reader));
      } else if (EdmParserConstants.EDM_ASSOCIATION_DEPENDENT.equals(currentHandledStartTagName)) {
        reader.require(XMLStreamConstants.START_ELEMENT, Edm.NAMESPACE_EDM_2008_09, EdmParserConstants.EDM_ASSOCIATION_DEPENDENT);
        refConstraint.setDependent(readReferentialConstraintRole(reader));
      } else {
        annotationElements.add(readAnnotationElement(reader));
      }
    }
  }
  refConstraint.setAnnotationElements(annotationElements);
  return refConstraint;
}
 
Example 5
Source File: XmiReader.java    From secure-data-service with Apache License 2.0 5 votes vote down vote up
protected static final List<EnumLiteral> readEnumerationLiteralGroup(final XMLStreamReader reader)
        throws XMLStreamException {
    assertName(XmiElementName.ENUMERATION_LITERAL_GROUP, reader);
    final List<EnumLiteral> literals = new LinkedList<EnumLiteral>();
    while (reader.hasNext()) {
        reader.next();
        switch (reader.getEventType()) {
            case XMLStreamConstants.START_ELEMENT: {
                if (match(XmiElementName.ENUMERATION_LITERAL, reader)) {
                    literals.add(assertNotNull(readEnumerationLiteral(reader)));
                } else {
                    skipElement(reader, true);
                }
                break;
            }
            case XMLStreamConstants.END_ELEMENT: {
                assertName(XmiElementName.ENUMERATION_LITERAL_GROUP, reader);
                return literals;
            }
            case XMLStreamConstants.CHARACTERS: {
                // Ignore.
                break;
            }
            default: {
                throw new AssertionError(reader.getEventType());
            }
        }
    }
    throw new AssertionError();
}
 
Example 6
Source File: CR6708840Test.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * refer to http://forums.java.net/jive/thread.jspa?threadID=41626&tstart=0
 */
@Test
public final void testStAX() {
    try {
        XMLInputFactory xmlif = XMLInputFactory.newInstance();

        // XMLStreamReader staxReader =
        // xmlif.createXMLStreamReader((Source)new
        // StreamSource(getClass().getResource("Forum31576.xml").getFile()));
        XMLStreamReader staxReader = xmlif.createXMLStreamReader(this.getClass().getResourceAsStream("gMonths.xml"));

        SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        Schema schemaGrammar = schemaFactory.newSchema(new File(getClass().getResource("gMonths.xsd").getFile()));

        Validator schemaValidator = schemaGrammar.newValidator();

        Source staxSrc = new StAXSource(staxReader);
        schemaValidator.validate(staxSrc);

        while (staxReader.hasNext()) {
            int eventType = staxReader.next();
            System.out.println("Event of type: " + eventType);
        }
    } catch (NullPointerException ne) {
        Assert.fail("NullPointerException when result is not specified.");
    } catch (Exception e) {
        Assert.fail(e.getMessage());
        e.printStackTrace();
    }
}
 
Example 7
Source File: XmiReader.java    From secure-data-service with Apache License 2.0 5 votes vote down vote up
protected static final Range readMultiplicityRange(final XMLStreamReader reader) throws XMLStreamException {
    assertName(XmiElementName.MULTIPLICITY_RANGE, reader);
    final Identifier id = getId(reader);
    final Occurs lowerBound = getOccurs(reader, XmiAttributeName.LOWER);
    final Occurs upperBound = getOccurs(reader, XmiAttributeName.UPPER);
    while (reader.hasNext()) {
        reader.next();
        switch (reader.getEventType()) {
            case XMLStreamConstants.START_ELEMENT: {
                skipElement(reader, false);
                break;
            }
            case XMLStreamConstants.END_ELEMENT: {
                assertName(XmiElementName.MULTIPLICITY_RANGE, reader);
                return new Range(id, lowerBound, upperBound, EMPTY_TAGGED_VALUE_LIST);
            }
            case XMLStreamConstants.CHARACTERS: {
                // Ignore.
                break;
            }
            default: {
                throw new AssertionError(reader.getEventType());
            }
        }
    }
    throw new AssertionError();
}
 
Example 8
Source File: SurrogatesTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private void readXML(byte[] xmlData, String expectedContent)
        throws Exception {
    InputStream stream = new ByteArrayInputStream(xmlData);
    XMLInputFactory factory = XMLInputFactory.newInstance();
    XMLStreamReader xmlReader
            = factory.createXMLStreamReader(stream);
    boolean inTestElement = false;
    StringBuilder sb = new StringBuilder();
    while (xmlReader.hasNext()) {
        String ename;
        switch (xmlReader.getEventType()) {
            case XMLStreamConstants.START_ELEMENT:
                ename = xmlReader.getLocalName();
                if (ename.equals("writeCharactersWithString")
                        || ename.equals("writeCharactersWithArray")) {
                    inTestElement = true;
                }
                break;
            case XMLStreamConstants.END_ELEMENT:
                ename = xmlReader.getLocalName();
                if (ename.equals("writeCharactersWithString")
                        || ename.equals("writeCharactersWithArray")) {
                    inTestElement = false;
                    String content = sb.toString();
                    System.out.println(ename + " text:'" + content + "' expected:'" + expectedContent+"'");
                    Assert.assertEquals(content, expectedContent);
                    sb.setLength(0);
                }
                break;
            case XMLStreamConstants.CHARACTERS:
                if (inTestElement) {
                    sb.append(xmlReader.getText());
                }
                break;
        }
        xmlReader.next();
    }
}
 
Example 9
Source File: StaEDIXMLStreamReaderTest.java    From staedi with Apache License 2.0 5 votes vote down vote up
@Test
void testReadXml_WithOptionalInterchangeServiceRequests_TransactionOnly() throws Exception {
    EDIInputFactory ediFactory = EDIInputFactory.newFactory();
    XMLInputFactory xmlFactory = XMLInputFactory.newInstance();
    InputStream stream = getClass().getResourceAsStream("/x12/optionalInterchangeServices.edi");
    ediFactory.setProperty(EDIInputFactory.XML_DECLARE_TRANSACTION_XMLNS, Boolean.TRUE);
    EDIStreamReader reader = ediFactory.createEDIStreamReader(stream);
    EDIStreamReader filtered = ediFactory.createFilteredReader(reader, r -> true);
    XMLStreamReader xmlReader = ediFactory.createXMLStreamReader(filtered);
    xmlReader.next(); // Per StAXSource JavaDoc, put in START_DOCUMENT state
    XMLStreamReader xmlCursor = xmlFactory.createFilteredReader(xmlReader, r -> {
        boolean startTx = (r.getEventType() == XMLStreamConstants.START_ELEMENT && r.getName().getLocalPart().equals("TRANSACTION"));

        if (!startTx) {
            Logger.getGlobal().info("Skipping event: " + r.getEventType() + "; "
                    + (r.getEventType() == XMLStreamConstants.START_ELEMENT || r.getEventType() == XMLStreamConstants.END_ELEMENT
                            ? r.getName()
                            : ""));
        }

        return startTx;
    });

    xmlCursor.hasNext();

    TransformerFactory factory = TransformerFactory.newInstance();
    Transformer transformer = factory.newTransformer();
    transformer.setOutputProperty(OutputKeys.INDENT, "yes");
    transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
    StringWriter result = new StringWriter();
    transformer.transform(new StAXSource(xmlReader), new StreamResult(result));
    String resultString = result.toString();
    System.out.println(resultString);
    Diff d = DiffBuilder.compare(Input.fromFile("src/test/resources/x12/optionalInterchangeServices_transactionOnly.xml"))
                        .withTest(resultString).build();
    assertTrue(!d.hasDifferences(), () -> "XML unexpectedly different:\n" + d.toString(new DefaultComparisonFormatter()));
}
 
Example 10
Source File: JBossDeploymentStructureParser12.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static void parseExcludeSubsystem(final XMLStreamReader reader, final ModuleStructureSpec specBuilder) throws XMLStreamException {
    final Set<String> subsystems = new HashSet<String>();
    specBuilder.setExcludedSubsystems(subsystems);

    // xsd:choice
    while (reader.hasNext()) {
        switch (reader.nextTag()) {
            case XMLStreamConstants.END_ELEMENT: {
                return;
            }
            case XMLStreamConstants.START_ELEMENT: {
                switch (Element.of(reader.getName())) {
                    case SUBSYSTEM:
                        parseSubsystem(reader, subsystems);
                        break;
                    default:
                        throw unexpectedContent(reader);
                }
                break;
            }
            default: {
                throw unexpectedContent(reader);
            }
        }
    }
    throw endOfDocument(reader.getLocation());
}
 
Example 11
Source File: XmlMetadataConsumer.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private NavigationProperty readNavigationProperty(final XMLStreamReader reader) throws XMLStreamException,
    EntityProviderException {
  reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, XmlMetadataConstants.EDM_NAVIGATION_PROPERTY);

  NavigationProperty navProperty = new NavigationProperty();
  List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();
  navProperty.setName(reader.getAttributeValue(null, XmlMetadataConstants.EDM_NAME));
  String relationship = reader.getAttributeValue(null, XmlMetadataConstants.EDM_NAVIGATION_RELATIONSHIP);
  if (relationship != null) {
    FullQualifiedName fqName = extractFQName(relationship);
    navProperty.setRelationship(fqName);

  } else {
    throw new EntityProviderException(EntityProviderException.MISSING_ATTRIBUTE
        .addContent(XmlMetadataConstants.EDM_NAVIGATION_RELATIONSHIP).addContent(
            XmlMetadataConstants.EDM_NAVIGATION_PROPERTY));
  }

  navProperty.setFromRole(reader.getAttributeValue(null, XmlMetadataConstants.EDM_NAVIGATION_FROM_ROLE));
  navProperty.setToRole(reader.getAttributeValue(null, XmlMetadataConstants.EDM_NAVIGATION_TO_ROLE));
  navProperty.setAnnotationAttributes(readAnnotationAttribute(reader));
  while (reader.hasNext() && !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI())
      && XmlMetadataConstants.EDM_NAVIGATION_PROPERTY.equals(reader.getLocalName()))) {
    reader.next();
    if (reader.isStartElement()) {
      extractNamespaces(reader);
      annotationElements.add(readAnnotationElement(reader));
    }
  }
  if (!annotationElements.isEmpty()) {
    navProperty.setAnnotationElements(annotationElements);
  }
  navProperties.add(navProperty);
  return navProperty;
}
 
Example 12
Source File: ResourceExtension.java    From java-client-api with Apache License 2.0 5 votes vote down vote up
public boolean isCorrect(String word, String... uris) {
  try {
    RequestParameters params = new RequestParameters();
    params.add("service", "is-correct");
    params.add("word",    word);
    params.add("uris",    uris);

    XMLStreamReaderHandle readHandle = new XMLStreamReaderHandle();

    // call the service
    getServices().get(params, readHandle);

    QName correctName = new QName(XMLConstants.DEFAULT_NS_PREFIX, "correct");

    XMLStreamReader streamReader = readHandle.get();
    while (streamReader.hasNext()) {
      int current = streamReader.next();
      if (current == XMLStreamReader.START_ELEMENT) {
        if (correctName.equals(streamReader.getName())) {
          return "true".equals(streamReader.getElementText());
        }
      }
    }

    return false;
  } catch(XMLStreamException ex) {
    throw new RuntimeException(ex);
  }
}
 
Example 13
Source File: ExtensionElementsParser.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public void parse(XMLStreamReader xtr, List<SubProcess> activeSubProcessList, Process activeProcess, BpmnModel model) throws Exception {
    BaseElement parentElement = null;
    if (!activeSubProcessList.isEmpty()) {
        parentElement = activeSubProcessList.get(activeSubProcessList.size() - 1);

    } else {
        parentElement = activeProcess;
    }

    boolean readyWithChildElements = false;
    while (!readyWithChildElements && xtr.hasNext()) {
        xtr.next();
        if (xtr.isStartElement()) {
            if (ELEMENT_EXECUTION_LISTENER.equals(xtr.getLocalName())) {
                new ExecutionListenerParser().parseChildElement(xtr, parentElement, model);
            } else if (ELEMENT_EVENT_LISTENER.equals(xtr.getLocalName())) {
                new FlowableEventListenerParser().parseChildElement(xtr, parentElement, model);
            } else if (ELEMENT_POTENTIAL_STARTER.equals(xtr.getLocalName())) {
                new PotentialStarterParser().parse(xtr, activeProcess);
            } else {
                ExtensionElement extensionElement = BpmnXMLUtil.parseExtensionElement(xtr);
                parentElement.addExtensionElement(extensionElement);
            }

        } else if (xtr.isEndElement()) {
            if (ELEMENT_EXTENSIONS.equals(xtr.getLocalName())) {
                readyWithChildElements = true;
            }
        }
    }
}
 
Example 14
Source File: BaseBpmnXMLConverter.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
protected ExtensionElement parseExtensionElement(XMLStreamReader xtr) throws Exception {
  ExtensionElement extensionElement = new ExtensionElement();
  extensionElement.setName(xtr.getLocalName());
  if (StringUtils.isNotEmpty(xtr.getNamespaceURI())) {
    extensionElement.setNamespace(xtr.getNamespaceURI());
  }
  if (StringUtils.isNotEmpty(xtr.getPrefix())) {
    extensionElement.setNamespacePrefix(xtr.getPrefix());
  }

  BpmnXMLUtil.addCustomAttributes(xtr, extensionElement, defaultElementAttributes);

  boolean readyWithExtensionElement = false;
  while (readyWithExtensionElement == false && xtr.hasNext()) {
    xtr.next();
    if (xtr.isCharacters() || XMLStreamReader.CDATA == xtr.getEventType()) {
      if (StringUtils.isNotEmpty(xtr.getText().trim())) {
        extensionElement.setElementText(xtr.getText().trim());
      }
    } else if (xtr.isStartElement()) {
      ExtensionElement childExtensionElement = parseExtensionElement(xtr);
      extensionElement.addChildElement(childExtensionElement);
    } else if (xtr.isEndElement() && extensionElement.getName().equalsIgnoreCase(xtr.getLocalName())) {
      readyWithExtensionElement = true;
    }
  }
  return extensionElement;
}
 
Example 15
Source File: DsParser.java    From ironjacamar with Eclipse Public License 1.0 4 votes vote down vote up
/**
 *
 * parse credential tag
 *
 * @param reader reader
 * @return the parse Object
 * @throws XMLStreamException in case of error
 * @throws ParserException in case of error
 * @throws ValidateException in case of error
 */
@Override
protected Credential parseCredential(XMLStreamReader reader) throws XMLStreamException, ParserException,
   ValidateException
{

   String userName = null;
   String password = null;
   String securityDomain = null;

   Map<String, String> expressions = new HashMap<String, String>();

   while (reader.hasNext())
   {
      switch (reader.nextTag())
      {
         case END_ELEMENT : {
            switch (reader.getLocalName())
            {
               case XML.ELEMENT_SECURITY :
               case XML.ELEMENT_RECOVERY_CREDENTIAL :
                  return new CredentialImpl(userName, password, securityDomain,
                          !expressions.isEmpty() ? expressions : null);
               case XML.ELEMENT_USER_NAME :
               case XML.ELEMENT_PASSWORD :
               case XML.ELEMENT_SECURITY_DOMAIN :
                  break;
               default :
                  throw new ParserException(bundle.unexpectedEndTag(reader.getLocalName()));
            }
         }
         case START_ELEMENT : {
            switch (reader.getLocalName())
            {
               case XML.ELEMENT_USER_NAME : {
                  userName = elementAsString(reader, XML.ELEMENT_USER_NAME, expressions);
                  break;
               }
               case XML.ELEMENT_PASSWORD : {
                  password = elementAsString(reader, XML.ELEMENT_PASSWORD, expressions);
                  break;
               }
               case XML.ELEMENT_SECURITY_DOMAIN : {
                  securityDomain = elementAsString(reader, XML.ELEMENT_SECURITY_DOMAIN, expressions);
                  break;
               }
               default :
                  throw new ParserException(bundle.unexpectedElement(reader.getLocalName()));
            }
            break;
         }
      }
   }
   throw new ParserException(bundle.unexpectedEndOfDocument());
}
 
Example 16
Source File: JBossDeploymentStructureParser11.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private static void parseSystemDependency(final XMLStreamReader reader, final ModuleStructureSpec specBuilder) throws XMLStreamException {
    boolean export = false;
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
        final Attribute attribute = Attribute.of(reader.getAttributeName(i));
        switch (attribute) {
            case EXPORT:
                export = Boolean.parseBoolean(reader.getAttributeValue(i));
                break;
            default:
                throw unexpectedContent(reader);
        }
    }
    Set<String> paths = Collections.emptySet();
    final MultiplePathFilterBuilder exportBuilder = PathFilters.multiplePathFilterBuilder(export);
    while (reader.hasNext()) {
        switch (reader.nextTag()) {
            case END_ELEMENT: {
                if (export) {
                    // If re-exported, add META-INF/** -> false at the end of the list (require explicit override)
                    exportBuilder.addFilter(PathFilters.getMetaInfSubdirectoriesFilter(), false);
                    exportBuilder.addFilter(PathFilters.getMetaInfFilter(), false);
                }
                final PathFilter exportFilter = exportBuilder.create();
                specBuilder.addSystemDependency(DependencySpec.createSystemDependencySpec(PathFilters.getDefaultImportFilter(), exportFilter, paths));
                return;
            }
            case START_ELEMENT: {
                switch (Element.of(reader.getName())) {
                    case PATHS: {
                        paths = parseSet(reader);
                        break;
                    }
                    case EXPORTS: {
                        parseFilterList(reader, exportBuilder);
                        break;
                    }
                    default: {
                        throw unexpectedContent(reader);
                    }
                }
            }
        }
    }
}
 
Example 17
Source File: XmlParserStream.java    From yangtools with Eclipse Public License 1.0 4 votes vote down vote up
private static boolean isNextEndDocument(final XMLStreamReader in) throws XMLStreamException {
    return !in.hasNext() || in.next() == XMLStreamConstants.END_DOCUMENT;
}
 
Example 18
Source File: XmiReader.java    From secure-data-service with Apache License 2.0 4 votes vote down vote up
protected static final ClassType readClassType(final QName elementName, final XMLStreamReader reader)
        throws XMLStreamException {
    assertName(elementName, reader);
    boolean isAbstract = false;
    final List<Attribute> attributes = new LinkedList<Attribute>();
    final List<TaggedValue> taggedValues = new LinkedList<TaggedValue>();
    final Identifier id = getId(reader);
    final String name = getName(reader, null, XmiAttributeName.NAME);
    XmiAssociationConnection connection = null;
    while (reader.hasNext()) {
        reader.next();
        switch (reader.getEventType()) {
            case XMLStreamConstants.START_ELEMENT: {
                if (match(XmiElementName.MODEL_ELEMENT_DOT_TAGGED_VALUE, reader)) {
                    taggedValues.addAll(readTaggedValueGroup(reader));
                } else if (match(XmiElementName.CLASSIFIER_DOT_FEATURE, reader)) {
                    try {
                        attributes.addAll(readClassifierDotFeature(reader));
                    } catch (final AssertionError e) {
                        throw new XmiBadModelElementException(name.toString(), e);
                    }
                } else if ("GeneralizableElement.generalization".equals(reader.getLocalName())) {
                    skipElement(reader, false);
                } else if ("ModelElement.comment".equals(reader.getLocalName())) {
                    skipElement(reader, false);
                } else if ("ModelElement.clientDependency".equals(reader.getLocalName())) {
                    skipElement(reader, false);
                } else if ("Namespace.ownedElement".equals(reader.getLocalName())) {
                    skipElement(reader, false);
                } else if (match(XmiElementName.ASSOCIATION_DOT_CONNECTION, reader)) {
                    connection = assertNotNull(readAssociationConnection(reader));
                } else {
                    skipElement(reader, true);
                }
                break;
            }
            case XMLStreamConstants.END_ELEMENT: {
                assertName(elementName, reader);
                if (match(XmiElementName.CLASS, elementName)) {
                    return new ClassType(id, name, isAbstract, attributes, taggedValues);
                } else if (match(XmiElementName.ASSOCIATION_CLASS, elementName)) {
                    return new ClassType(id, name, isAbstract, attributes, connection.getLHS(),
                            connection.getRHS(), taggedValues);
                } else if (match(XmiElementName.ASSOCIATION, elementName)) {
                    return new ClassType(id, name, connection.getLHS(), connection.getRHS(), taggedValues);
                } else {
                    throw new AssertionError(elementName);
                }
            }
            case XMLStreamConstants.CHARACTERS: {
                // Ignore.
                break;
            }
            default: {
                throw new AssertionError(reader.getEventType());
            }
        }
    }
    throw new AssertionError();
}
 
Example 19
Source File: EWSMethod.java    From davmail with GNU General Public License v2.0 4 votes vote down vote up
protected void addExtendedPropertyValue(XMLStreamReader reader, Item item) throws XMLStreamException {
    String propertyTag = null;
    String propertyValue = null;
    while (reader.hasNext() && !(XMLStreamUtil.isEndTag(reader, "ExtendedProperty"))) {
        reader.next();
        if (XMLStreamUtil.isStartTag(reader)) {
            String tagLocalName = reader.getLocalName();
            if ("ExtendedFieldURI".equals(tagLocalName)) {
                propertyTag = getAttributeValue(reader, "PropertyTag");
                // property name is in PropertyId or PropertyName with DistinguishedPropertySetId
                if (propertyTag == null) {
                    propertyTag = getAttributeValue(reader, "PropertyId");
                }
                if (propertyTag == null) {
                    propertyTag = getAttributeValue(reader, "PropertyName");
                }
            } else if ("Value".equals(tagLocalName)) {
                propertyValue = XMLStreamUtil.getElementText(reader);
            } else if ("Values".equals(tagLocalName)) {
                StringBuilder buffer = new StringBuilder();
                while (reader.hasNext() && !(XMLStreamUtil.isEndTag(reader, "Values"))) {
                    reader.next();
                    if (XMLStreamUtil.isStartTag(reader)) {

                        if (buffer.length() > 0) {
                            buffer.append(',');
                        }
                        String singleValue = XMLStreamUtil.getElementText(reader);
                        if (singleValue != null) {
                            buffer.append(singleValue);
                        }
                    }
                }
                propertyValue = buffer.toString();
            }
        }
    }
    if ((propertyTag != null) && (propertyValue != null)) {
        item.put(propertyTag, propertyValue);
    }
}
 
Example 20
Source File: ApplicationPolicyParser.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public List<ApplicationPolicy> parse(XMLStreamReader reader) throws XMLStreamException
{
   List<ApplicationPolicy> policies = null;
   while (reader.hasNext() && reader.nextTag() != END_ELEMENT)
   {
      final Element element = Element.forName(reader.getLocalName());
      if (element.equals(Element.APPLICATION_POLICY) || element.equals(Element.SECURITY_DOMAIN))
      {
         final int count = reader.getAttributeCount();
         if (count == 0)
            throw StaxParserUtil.missingRequired(reader, Collections.singleton(org.jboss.security.config.Attribute.NAME));
         String name = null;
         String extendsName = null;
         for (int i = 0; i < count; i++)
         {
            final String value = reader.getAttributeValue(i);
            final org.jboss.security.config.Attribute attribute = org.jboss.security.config.Attribute.forName(reader.getAttributeLocalName(i));
            switch (attribute)
            {
               case NAME : {
                  name = value;
                  break;
               }
               case EXTENDS : {
                  extendsName = value;
                  break;
               }
               default :
                  throw StaxParserUtil.unexpectedAttribute(reader, i);
            }
         }
         if (name == null)
            throw StaxParserUtil.missingRequired(reader, Collections.singleton(org.jboss.security.config.Attribute.NAME));
         final ApplicationPolicy applicationPolicy = new ApplicationPolicy(name);
         if (extendsName != null)
            applicationPolicy.setBaseApplicationPolicyName(extendsName);
         route(reader, applicationPolicy);
         if (policies == null)
            policies = new ArrayList<ApplicationPolicy>();
         policies.add(applicationPolicy);

      }
      else
         throw StaxParserUtil.unexpectedElement(reader);
   }
   return policies;
}