List of usage examples for javax.xml.stream XMLStreamReader isCharacters
public boolean isCharacters();
From source file:Main.java
/** * Skip new lines after the end elements. * This function should be called when the cursor is pointing to CHARACTER and leaves the cursor * at END_ELEMENT OR START_ELEMENT/* w ww . j a v a 2 s. co m*/ * @param xmlStreamReader */ public static void skipNewLines(XMLStreamReader xmlStreamReader) throws XMLStreamException { if (xmlStreamReader.isCharacters()) { while (xmlStreamReader.isCharacters() && xmlStreamReader.hasNext()) xmlStreamReader.next(); } }
From source file:com.predic8.membrane.core.config.AbstractXmlElement.java
/** * Needed to resolve interceptor IDs into interceptor beans *//* w w w. j a va2s .c om*/ public XMLElement parse(XMLStreamReader token) throws Exception { move2RootElementIfNeeded(token); log.debug("<" + token.getLocalName() + ">"); parseAttributes(token); while (token.hasNext()) { token.next(); if (token.isStartElement()) { parseChildren(token, token.getName().getLocalPart()); } else if (token.isCharacters()) { parseCharacters(token); } else if (token.isEndElement()) { log.debug("</" + token.getLocalName() + ">"); break; } } doAfterParsing(); return this; }
From source file:com.predic8.membrane.core.http.xml.Response.java
@Override protected void parseChildren(XMLStreamReader token, String child) throws Exception { if (Headers.ELEMENT_NAME.equals(child)) { headers = (Headers) new Headers().parse(token); } else if ("status".equals(child)) { statusCode = Integer//from ww w.jav a2 s .c o m .parseInt(StringUtils.defaultIfBlank(token.getAttributeValue("", "status-code"), "0")); statusMessage = ""; while (token.hasNext()) { token.next(); if (token.isStartElement()) { parseChildren(token, token.getName().getLocalPart()); } else if (token.isCharacters()) { statusMessage += token.getText(); } else if (token.isEndElement()) { break; } } } }
From source file:org.activiti.bpmn.converter.BaseBpmnXMLConverter.java
@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()); }/* w ww . java 2 s. co m*/ 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()) { 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; }
From source file:org.activiti.dmn.converter.util.DmnXMLUtil.java
public static DmnExtensionElement parseExtensionElement(XMLStreamReader xtr) throws Exception { DmnExtensionElement extensionElement = new DmnExtensionElement(); extensionElement.setName(xtr.getLocalName()); if (StringUtils.isNotEmpty(xtr.getNamespaceURI())) { extensionElement.setNamespace(xtr.getNamespaceURI()); }//from ww w . j a v a 2s . c o m if (StringUtils.isNotEmpty(xtr.getPrefix())) { extensionElement.setNamespacePrefix(xtr.getPrefix()); } for (int i = 0; i < xtr.getAttributeCount(); i++) { DmnExtensionAttribute extensionAttribute = new DmnExtensionAttribute(); extensionAttribute.setName(xtr.getAttributeLocalName(i)); extensionAttribute.setValue(xtr.getAttributeValue(i)); if (StringUtils.isNotEmpty(xtr.getAttributeNamespace(i))) { extensionAttribute.setNamespace(xtr.getAttributeNamespace(i)); } if (StringUtils.isNotEmpty(xtr.getAttributePrefix(i))) { extensionAttribute.setNamespacePrefix(xtr.getAttributePrefix(i)); } extensionElement.addAttribute(extensionAttribute); } 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()) { DmnExtensionElement childExtensionElement = parseExtensionElement(xtr); extensionElement.addChildElement(childExtensionElement); } else if (xtr.isEndElement() && extensionElement.getName().equalsIgnoreCase(xtr.getLocalName())) { readyWithExtensionElement = true; } } return extensionElement; }
From source file:org.erdc.cobie.shared.COBieUtility.java
static public Map<String, String> elementMapFromXMLObject(XmlObject xml) { Map<String, String> elementMap = new HashMap<String, String>(); XMLStreamReader rdr = xml.newXMLStreamReader(); String keyName = ""; String keyVal = ""; boolean lastWasStartElement = false; int attCount = 0; try {//from ww w . ja v a 2 s. c om while (rdr.hasNext()) { try { attCount = rdr.getAttributeCount(); } catch (Exception ex) { attCount = 0; } if (attCount > 0) { for (int i = 0; i < attCount; i++) { keyName = rdr.getAttributeLocalName(i); keyVal = rdr.getAttributeValue(i); if (!elementMap.containsKey(keyName)) { elementMap.put(keyName, escape(keyVal)); } lastWasStartElement = false; } } if (rdr.isStartElement()) { keyName = rdr.getLocalName(); lastWasStartElement = true; } else if (rdr.isCharacters() && lastWasStartElement) { if (isElementADateTime(xml, keyName)) { keyVal = COBieUtility.stringFromXmlDateTime(xml, keyName); } else { keyVal = rdr.getText(); } if (!elementMap.containsKey(keyName)) { elementMap.put(keyName, escape(keyVal)); } lastWasStartElement = false; } else { lastWasStartElement = false; } rdr.next(); } } catch (XMLStreamException e) { LOGGER.error("", e); } return elementMap; }
From source file:org.flowable.bpmn.converter.BaseBpmnXMLConverter.java
@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()); }//from w w w . j a va 2s . c o m 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; }
From source file:org.flowable.cmmn.converter.CmmnXmlConverter.java
public CmmnModel convertToCmmnModel(XMLStreamReader xtr) { ConversionHelper conversionHelper = new ConversionHelper(); conversionHelper.setCmmnModel(new CmmnModel()); try {/*from w ww . ja v a 2 s . co m*/ String currentXmlElement = null; while (xtr.hasNext()) { try { xtr.next(); } catch (Exception e) { LOGGER.debug("Error reading CMMN XML document", e); throw new CmmnXMLException("Error reading XML", e); } if (xtr.isStartElement()) { currentXmlElement = xtr.getLocalName(); if (elementConverters.containsKey(currentXmlElement)) { elementConverters.get(currentXmlElement).convertToCmmnModel(xtr, conversionHelper); } } else if (xtr.isEndElement()) { currentXmlElement = null; if (elementConverters.containsKey(xtr.getLocalName())) { elementConverters.get(xtr.getLocalName()).elementEnd(xtr, conversionHelper); } } else if (xtr.isCharacters() && currentXmlElement != null) { if (textConverters.containsKey(currentXmlElement)) { textConverters.get(currentXmlElement).convertToCmmnModel(xtr, conversionHelper); } } } } catch (CmmnXMLException e) { throw e; } catch (Exception e) { LOGGER.error("Error processing CMMN XML document", e); throw new CmmnXMLException("Error processing CMMN XML document", e); } // Post process all elements: add instances where a reference is used processCmmnElements(conversionHelper); return conversionHelper.getCmmnModel(); }
From source file:org.flowable.cmmn.converter.ExtensionElementsXMLConverter.java
protected void readCompletionNeutralRule(XMLStreamReader xtr, ConversionHelper conversionHelper) { if (conversionHelper.getCurrentCmmnElement() instanceof PlanItemControl) { CompletionNeutralRule completionNeutralRule = new CompletionNeutralRule(); completionNeutralRule.setName(xtr.getAttributeValue(null, CmmnXmlConstants.ATTRIBUTE_NAME)); PlanItemControl planItemControl = (PlanItemControl) conversionHelper.getCurrentCmmnElement(); planItemControl.setCompletionNeutralRule(completionNeutralRule); readCommonXmlInfo(completionNeutralRule, xtr); boolean readyWithChildElements = false; try {//from w ww . ja va 2 s . com while (!readyWithChildElements && xtr.hasNext()) { xtr.next(); if (xtr.isStartElement()) { if (CmmnXmlConstants.ELEMENT_CONDITION.equals(xtr.getLocalName())) { xtr.next(); if (xtr.isCharacters()) { completionNeutralRule.setCondition(xtr.getText()); } break; } } else if (xtr.isEndElement()) { if (CmmnXmlConstants.ELEMENT_COMPLETION_NEUTRAL_RULE.equalsIgnoreCase(xtr.getLocalName())) { readyWithChildElements = true; } } } } catch (Exception ex) { LOGGER.error("Error processing CMMN document", ex); throw new XMLException("Error processing CMMN document", ex); } } }
From source file:org.osaf.cosmo.xml.DomReader.java
private static Node readNode(Document d, XMLStreamReader reader) throws XMLStreamException { Node root = null;/*from www. ja v a2s .co m*/ Node current = null; while (reader.hasNext()) { reader.next(); if (reader.isEndElement()) { //log.debug("Finished reading " + current.getNodeName()); if (current.getParentNode() == null) break; //log.debug("Setting current to " + //current.getParentNode().getNodeName()); current = current.getParentNode(); } if (reader.isStartElement()) { Element e = readElement(d, reader); if (root == null) { //log.debug("Setting root to " + e.getNodeName()); root = e; } if (current != null) { //log.debug("Appending child " + e.getNodeName() + " to " + //current.getNodeName()); current.appendChild(e); } //log.debug("Setting current to " + e.getNodeName()); current = e; continue; } if (reader.isCharacters()) { CharacterData cd = d.createTextNode(reader.getText()); if (root == null) return cd; if (current == null) return cd; //log.debug("Appending text '" + cd.getData() + "' to " + //current.getNodeName()); current.appendChild(cd); continue; } } return root; }