Java Code Examples for javax.xml.stream.XMLStreamReader#END_ELEMENT

The following examples show how to use javax.xml.stream.XMLStreamReader#END_ELEMENT . 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: DatabaseIO.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Reads table elements from the XML stream reader and adds them to the given
 * database model.
 * 
 * @param xmlReader The reader
 * @param model     The database model to add the table objects to
 */
private void readTableElements(XMLStreamReader xmlReader, Database model) throws XMLStreamException, IOException
{
    int eventType = XMLStreamReader.START_ELEMENT;

    while (eventType != XMLStreamReader.END_ELEMENT)
    {
        eventType = xmlReader.next();
        if (eventType == XMLStreamReader.START_ELEMENT)
        {
            if (isSameAs(xmlReader.getName(), QNAME_ELEMENT_TABLE)) {
                model.addTable(readTableElement(xmlReader));
            }
            else {
                readOverElement(xmlReader);
            }
        }
    }
}
 
Example 2
Source File: XMLStreamReaderTest.java    From FHIR with Apache License 2.0 6 votes vote down vote up
private static void parseResource(XMLStreamReader reader) throws XMLStreamException {
    while (reader.hasNext()) {
        debug(reader);
        switch (reader.getEventType()) {
        case XMLStreamReader.START_ELEMENT:
            java.lang.String localName = reader.getLocalName();
            System.out.println("localName: " + localName);
            switch (localName) {
            case "Patient":
                parsePatient("Patient", reader);
                break;
            }
            break;
        case XMLStreamReader.END_ELEMENT:
            return;
        }
    }
}
 
Example 3
Source File: MavenSettings.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static void skip(XMLStreamReader parser) throws XMLStreamException, IOException {
    if (parser.getEventType() != XMLStreamReader.START_ELEMENT) {
        throw new IllegalStateException();
    }
    int depth = 1;
    while (depth != 0) {
        switch (parser.next()) {
            case XMLStreamReader.END_ELEMENT:
                depth--;
                break;
            case XMLStreamReader.START_ELEMENT:
                depth++;
                break;
        }
    }
}
 
Example 4
Source File: IfcXmlDeserializer.java    From IfcPlugins with GNU Affero General Public License v3.0 6 votes vote down vote up
private void parseIso_10303_28(XMLStreamReader reader) throws DeserializeException {
	try {
		while (reader.hasNext()) {
			reader.next();
			if (reader.getEventType() == XMLStreamReader.START_ELEMENT) {
				if (reader.getLocalName().equalsIgnoreCase("uos")) {
					parseUos(reader);
				}
			} else if (reader.getEventType() == XMLStreamReader.END_ELEMENT) {
				if (reader.getLocalName().equals("iso_10303_28")) {
					return;
				}
			}
		}
	} catch (XMLStreamException e) {
		throw new DeserializeException(e);
	}
}
 
Example 5
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 6
Source File: XMLStreamReaderTest.java    From FHIR with Apache License 2.0 6 votes vote down vote up
private static void parseNarrative(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();
            switch (localName) {
            case "status":
                parseString("status", reader);
                break;
            case "div":
                java.lang.String div = XMLSupport.parseDiv(reader);
                System.out.println("    div: " + div);
                break;
            }
            break;
        case XMLStreamReader.END_ELEMENT:
            if (reader.getLocalName().equals(elementName)) {
                return;
            }
            break;
        }
    }        
}
 
Example 7
Source File: XlsxSheetContentParser.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Skips all rows before the selected starting row.
 *
 * @throws XMLStreamException
 *             If there is an error processing the underlying XML source.
 */
private void skipToStartRow() throws XMLStreamException {
	int rowIndexBeforeFirstRow = sheetMetaData.getFirstRowIndex() - 1;
	boolean skipRows = currentRowIndex < rowIndexBeforeFirstRow;
	while (skipRows && reader.hasNext()) {
		int nextEvent = reader.next();
		if (nextEvent == XMLStreamReader.START_ELEMENT) {
			// If a row was found..
			if (reader.getLocalName().equals(XlsxUtilities.TAG_ROW)) {
				// ... parse the row index (subtract 1 as XLSX indices start with 1)
				parsedRowIndex = Integer
						.parseInt(XlsxUtilities.getAttributes(reader).getValue(XlsxUtilities.TAG_ROW_INDEX)) - 1;

				// Check whether the parsed index is already
				// behind the desired end index (which means that all rows before were
				// empty)
				if (parsedRowIndex > rowIndexBeforeFirstRow) {
					currentRowIndex = rowIndexBeforeFirstRow;
					skipRows = false;
				} else {
					// Update the current row index if parsed index is still
					// before first row to read
					currentRowIndex = parsedRowIndex;
				}
			}
		} else if (nextEvent == XMLStreamReader.END_ELEMENT && reader.getLocalName().equals(XlsxUtilities.TAG_ROW)) {
			// parse until end of row if we haven't parsed too far yet
			skipRows = currentRowIndex < rowIndexBeforeFirstRow;
		}
	}
}
 
Example 8
Source File: HandlerChainsModel.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void skipInitParamElement(XMLStreamReader reader) {
    int state;
    do {
        state = XMLStreamReaderUtil.nextContent(reader);
    } while (state != XMLStreamReader.END_ELEMENT ||
            !reader.getName().equals(QNAME_HANDLER_PARAM));
    XMLStreamReaderUtil.nextElementContent(reader);
}
 
Example 9
Source File: StaxConfigTokenizer.java    From cache2k with Apache License 2.0 5 votes vote down vote up
@Override
public Item next() throws Exception {
  while (input.hasNext()) {
    int type = input.next();
    switch (type) {
      case XMLStreamReader.START_ELEMENT :
        if (startName != null) {
          hierarchy.push(startName);
          startName = input.getLocalName();
          return returnNest(hierarchy.element());
        }
        startName = input.getLocalName(); break;
      case XMLStreamReader.CHARACTERS :
        value = input.getText(); break;
      case XMLStreamReader.END_ELEMENT :
        String name = input.getLocalName();
        if (startName != null && startName.equals(name)) {
          startName = null;
          return returnProperty(name, value);
        }
        if (name.equals(hierarchy.element())) {
          hierarchy.pop();
          return returnUnnest();
        }
        break;
    }
  }
  return null;
}
 
Example 10
Source File: XMLReaderComposite.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public int getEventType() {
    switch (state) {
    case StartTag: return XMLStreamReader.START_ELEMENT;
    case EndTag: return XMLStreamReader.END_ELEMENT;
    case Payload:
    default:
        return payloadReader.getEventType();
    }
}
 
Example 11
Source File: ConfigUtil.java    From aion with MIT License 5 votes vote down vote up
public static String readValue(final XMLStreamReader sr) throws XMLStreamException {
    StringBuilder str = new StringBuilder();
    readLoop:
    while (sr.hasNext()) {
        int eventType = sr.next();
        switch (eventType) {
            case XMLStreamReader.CHARACTERS:
                str.append(sr.getText());
                break;
            case XMLStreamReader.END_ELEMENT:
                break readLoop;
        }
    }
    return str.toString();
}
 
Example 12
Source File: XMLReaderComposite.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public int getEventType() {
    switch (state) {
    case StartTag: return XMLStreamReader.START_ELEMENT;
    case EndTag: return XMLStreamReader.END_ELEMENT;
    case Payload:
    default:
        return payloadReader.getEventType();
    }
}
 
Example 13
Source File: HandlerChainsModel.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private static void skipInitParamElement(XMLStreamReader reader) {
    int state;
    do {
        state = XMLStreamReaderUtil.nextContent(reader);
    } while (state != XMLStreamReader.END_ELEMENT ||
            !reader.getName().equals(QNAME_HANDLER_PARAM));
    XMLStreamReaderUtil.nextElementContent(reader);
}
 
Example 14
Source File: VespaXMLUpdateReader.java    From vespa with Apache License 2.0 5 votes vote down vote up
FieldUpdate readAlter(DocumentUpdate update) throws XMLStreamException {
    Field f = null;
    for (int i = 0; i < reader.getAttributeCount(); i++) {
        if ("field".equals(reader.getAttributeName(i).toString())) {
            f = update.getDocumentType().getField(reader.getAttributeValue(i));
        }
    }

    if (f == null) {
        throw newDeserializeException("Alter update without \"field\" attribute");
    }

    FieldUpdate fu = FieldUpdate.create(f);

    while (reader.hasNext()) {
        int type = reader.next();
        if (type == XMLStreamReader.START_ELEMENT) {
            if ("increment".equals(reader.getName().toString()) ||
                "decrement".equals(reader.getName().toString()) ||
                "multiply".equals(reader.getName().toString()) ||
                "divide".equals(reader.getName().toString())) {
                update.addFieldUpdate(readArithmetic(update, reader.getName().toString(), f, fu));
                skipToEnd(reader.getName().toString());
            } else {
                throw newDeserializeException("Element \"" + reader.getName() + "\" not appropriate within alter element");
            }
        } else if (type == XMLStreamReader.END_ELEMENT) {
            break;
        }
    }

    return fu;
}
 
Example 15
Source File: CfgNetP2p.java    From aion with MIT License 4 votes vote down vote up
public void fromXML(final XMLStreamReader sr) throws XMLStreamException {
    loop:
    while (sr.hasNext()) {
        int eventType = sr.next();
        switch (eventType) {
            case XMLStreamReader.START_ELEMENT:
                String elelmentName = sr.getLocalName().toLowerCase();
                switch (elelmentName) {
                    case "ip":
                        this.ip = ConfigUtil.readValue(sr);
                        break;
                    case "port":
                        this.port = Integer.parseInt(ConfigUtil.readValue(sr));
                        break;
                    case "discover":
                        this.discover = Boolean.parseBoolean(ConfigUtil.readValue(sr));
                        break;
                    case "cluster-node-mode":
                        this.clusterNodeMode = Boolean.parseBoolean(ConfigUtil.readValue(sr));
                        break;
                    case "bootlist-sync-only":
                        this.bootlistSyncOnly = Boolean.parseBoolean(ConfigUtil.readValue(sr));
                        break;
                    case "sync-only-mode":
                        this.syncOnlyMode = Boolean.parseBoolean(ConfigUtil.readValue(sr));
                        break;
                    case "max-temp-nodes":
                        this.maxTempNodes = Integer.parseInt(ConfigUtil.readValue(sr));
                        break;
                    case "max-active-nodes":
                        this.maxActiveNodes = Integer.parseInt(ConfigUtil.readValue(sr));
                        break;
                    case "err-tolerance":
                        this.errorTolerance = Integer.parseInt(ConfigUtil.readValue(sr));
                        break;
                    default:
                        // ConfigUtil.skipElement(sr);
                        break;
                }
                break;
            case XMLStreamReader.END_ELEMENT:
                break loop;
        }
    }
}
 
Example 16
Source File: StreamReaderBufferCreator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
private void storeElementAndChildrenNoEx(XMLStreamReader reader) throws XMLStreamException {
    int depth = 1;
    if (_storeInScopeNamespacesOnElementFragment) {
        storeElementWithInScopeNamespaces(reader);
    } else {
        storeElement(reader);
    }

    while(depth > 0) {
        _eventType = reader.next();
        switch (_eventType) {
            case XMLStreamReader.START_ELEMENT:
                depth++;
                storeElement(reader);
                break;
            case XMLStreamReader.END_ELEMENT:
                depth--;
                storeStructure(T_END);
                break;
            case XMLStreamReader.NAMESPACE:
                storeNamespaceAttributes(reader);
                break;
            case XMLStreamReader.ATTRIBUTE:
                storeAttributes(reader);
                break;
            case XMLStreamReader.SPACE:
            case XMLStreamReader.CHARACTERS:
            case XMLStreamReader.CDATA: {
                storeContentCharacters(T_TEXT_AS_CHAR_ARRAY,
                        reader.getTextCharacters(), reader.getTextStart(),
                        reader.getTextLength());
                break;
            }
            case XMLStreamReader.COMMENT:
                storeComment(reader);
                break;
            case XMLStreamReader.PROCESSING_INSTRUCTION:
                storeProcessingInstruction(reader);
                break;
        }
    }

    /*
     * Move to next item after the end of the element
     * that has been stored
     */
    _eventType = reader.next();
}
 
Example 17
Source File: StreamReaderBufferCreator.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private void storeElementAndChildrenEx(XMLStreamReaderEx reader) throws XMLStreamException {
    int depth = 1;
    if (_storeInScopeNamespacesOnElementFragment) {
        storeElementWithInScopeNamespaces(reader);
    } else {
        storeElement(reader);
    }

    while(depth > 0) {
        _eventType = reader.next();
        switch (_eventType) {
            case XMLStreamReader.START_ELEMENT:
                depth++;
                storeElement(reader);
                break;
            case XMLStreamReader.END_ELEMENT:
                depth--;
                storeStructure(T_END);
                break;
            case XMLStreamReader.NAMESPACE:
                storeNamespaceAttributes(reader);
                break;
            case XMLStreamReader.ATTRIBUTE:
                storeAttributes(reader);
                break;
            case XMLStreamReader.SPACE:
            case XMLStreamReader.CHARACTERS:
            case XMLStreamReader.CDATA: {
                CharSequence c = reader.getPCDATA();
                if (c instanceof Base64Data) {
                    storeStructure(T_TEXT_AS_OBJECT);
                    //Instead of clone the Base64Data, the original Base64Data instance is used here to preserve the DataHandler
                    storeContentObject(c);
                } else {
                    storeContentCharacters(T_TEXT_AS_CHAR_ARRAY,
                            reader.getTextCharacters(), reader.getTextStart(),
                            reader.getTextLength());
                }
                break;
            }
            case XMLStreamReader.COMMENT:
                storeComment(reader);
                break;
            case XMLStreamReader.PROCESSING_INSTRUCTION:
                storeProcessingInstruction(reader);
                break;
        }
    }

    /*
     * Move to next item after the end of the element
     * that has been stored
     */
    _eventType = reader.next();
}
 
Example 18
Source File: StreamReaderBufferCreator.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private void storeElementAndChildrenEx(XMLStreamReaderEx reader) throws XMLStreamException {
    int depth = 1;
    if (_storeInScopeNamespacesOnElementFragment) {
        storeElementWithInScopeNamespaces(reader);
    } else {
        storeElement(reader);
    }

    while(depth > 0) {
        _eventType = reader.next();
        switch (_eventType) {
            case XMLStreamReader.START_ELEMENT:
                depth++;
                storeElement(reader);
                break;
            case XMLStreamReader.END_ELEMENT:
                depth--;
                storeStructure(T_END);
                break;
            case XMLStreamReader.NAMESPACE:
                storeNamespaceAttributes(reader);
                break;
            case XMLStreamReader.ATTRIBUTE:
                storeAttributes(reader);
                break;
            case XMLStreamReader.SPACE:
            case XMLStreamReader.CHARACTERS:
            case XMLStreamReader.CDATA: {
                CharSequence c = reader.getPCDATA();
                if (c instanceof Base64Data) {
                    storeStructure(T_TEXT_AS_OBJECT);
                    //Instead of clone the Base64Data, the original Base64Data instance is used here to preserve the DataHandler
                    storeContentObject(c);
                } else {
                    storeContentCharacters(T_TEXT_AS_CHAR_ARRAY,
                            reader.getTextCharacters(), reader.getTextStart(),
                            reader.getTextLength());
                }
                break;
            }
            case XMLStreamReader.COMMENT:
                storeComment(reader);
                break;
            case XMLStreamReader.PROCESSING_INSTRUCTION:
                storeProcessingInstruction(reader);
                break;
        }
    }

    /*
     * Move to next item after the end of the element
     * that has been stored
     */
    _eventType = reader.next();
}
 
Example 19
Source File: VespaXMLUpdateReader.java    From vespa with Apache License 2.0 4 votes vote down vote up
public void read(DocumentUpdate update) {
   try {
       // First fetch attributes.
       DocumentType doctype = null;

       for (int i = 0; i < reader.getAttributeCount(); i++) {
           final String attributeName = reader.getAttributeName(i).toString();
           final String attributeValue = reader.getAttributeValue(i);

           if ("documentid".equals(attributeName) || "id".equals(attributeName)) {
               update.setId(new DocumentId(attributeValue));
           } else if ("documenttype".equals(attributeName) || "type".equals(attributeName)) {
               doctype = docTypeManager.getDocumentType(attributeValue);
               update.setDocumentType(doctype);
           } else if ("create-if-non-existent".equals(attributeName)) {
               if ("true".equals(attributeValue)) {
                   update.setCreateIfNonExistent(true);
               } else if ("false".equals(attributeValue)) {
                   update.setCreateIfNonExistent(false);
               } else {
                   throw newDeserializeException("'create-if-non-existent' must be either 'true' or 'false', was '" + attributeValue +"'");
               }
           } else if ("condition".equals(attributeName)) {
               condition = Optional.of(attributeValue);
           }
       }

       if (doctype == null) {
           throw newDeserializeException("Must specify document type. " + reader.getLocation());
       }

       // Then fetch fields
       while (reader.hasNext()) {
           int type = reader.next();

           if (type == XMLStreamReader.START_ELEMENT) {
               final String currentName = reader.getName().toString();
               if (hasFieldPath()) {
                   if ("assign".equals(currentName)) {
                       update.addFieldPathUpdate(new AssignFieldPathUpdate(doctype, this));
                       skipToEnd("assign");
                   } else if ("add".equals(currentName)) {
                       update.addFieldPathUpdate(new AddFieldPathUpdate(doctype, this));
                       skipToEnd("add");
                   } else if ("remove".equals(currentName)) {
                       update.addFieldPathUpdate(new RemoveFieldPathUpdate(doctype, this));
                       skipToEnd("remove");
                   } else {
                       throw newDeserializeException("Unknown field path update operation " + reader.getName());
                   }
               } else {
                   if ("assign".equals(currentName)) {
                       update.addFieldUpdate(readAssign(update));
                       skipToEnd("assign");
                   } else if ("add".equals(currentName)) {
                       update.addFieldUpdate(readAdd(update));
                       skipToEnd("add");
                   } else if ("remove".equals(currentName)) {
                       update.addFieldUpdate(readRemove(update));
                       skipToEnd("remove");
                   } else if ("alter".equals(currentName)) {
                       update.addFieldUpdate(readAlter(update));
                       skipToEnd("alter");
                   } else if ("increment".equals(currentName) ||
                           "decrement".equals(currentName) ||
                           "multiply".equals(currentName) ||
                           "divide".equals(currentName)) {
                       update.addFieldUpdate(readArithmeticField(update, currentName));
                       skipToEnd(currentName);
                   } else {
                       throw newDeserializeException("Unknown update operation " + reader.getName());
                   }
               }
           } else if (type == XMLStreamReader.END_ELEMENT) {
               return;
           }
       }
   } catch (XMLStreamException e) {
       throw newException(e);
   }
}
 
Example 20
Source File: CfgTx.java    From aion with MIT License 4 votes vote down vote up
public void fromXML(final XMLStreamReader sr) throws XMLStreamException {
    loop:
    while (sr.hasNext()) {
        int eventType = sr.next();
        switch (eventType) {
            case XMLStreamReader.START_ELEMENT:
                String elementName = sr.getLocalName().toLowerCase();
                switch (elementName) {
                    case "cachemax":
                        this.cacheMax = Integer.parseInt(ConfigUtil.readValue(sr));
                        if (this.cacheMax < 128) {
                            this.cacheMax = 128;
                        } else if (this.cacheMax > 16384) { // 16GB
                            this.cacheMax = 16384;
                        }
                        break;
                    case "pooldump":
                        this.poolDump = Boolean.parseBoolean(ConfigUtil.readValue(sr));
                        break;
                    case "poolbackup":
                        this.poolBackup = Boolean.parseBoolean(ConfigUtil.readValue(sr));
                        break;
                    case "pendingtxtimeout":
                        this.pendingTransactionTimeout = Integer.parseInt(ConfigUtil.readValue(sr));
                        if (this.pendingTransactionTimeout < 60) { // 1 min
                            this.pendingTransactionTimeout = 60;
                        }
                        break;
                    case "seedmode":
                        this.seedMode = Boolean.parseBoolean(ConfigUtil.readValue(sr));
                        break;
                    default:
                        ConfigUtil.skipElement(sr);
                        break;
                }
                break;
            case XMLStreamReader.END_ELEMENT:
                break loop;
        }
    }
}