List of usage examples for javax.xml.stream XMLStreamReader isEndElement
public boolean isEndElement();
From source file:org.flowable.cmmn.converter.CmmnXmlConverter.java
public CmmnModel convertToCmmnModel(XMLStreamReader xtr) { ConversionHelper conversionHelper = new ConversionHelper(); conversionHelper.setCmmnModel(new CmmnModel()); try {// w ww .j a v a 2s. c o 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
@Override protected CmmnElement convert(XMLStreamReader xtr, ConversionHelper conversionHelper) { boolean readyWithChildElements = false; try {// www .j a v a 2s.c o m while (!readyWithChildElements && xtr.hasNext()) { xtr.next(); if (xtr.isStartElement()) { if (CmmnXmlConstants.ELEMENT_COMPLETION_NEUTRAL_RULE.equals(xtr.getLocalName())) { readCompletionNeutralRule(xtr, conversionHelper); } else if (CmmnXmlConstants.ELEMENT_FIELD.equals(xtr.getLocalName())) { readFieldExtension(xtr, conversionHelper); } else if (CmmnXmlConstants.ELEMENT_HTTP_REQUEST_HANDLER.equals(xtr.getLocalName())) { readHttpRequestHandler(xtr, conversionHelper); } else if (CmmnXmlConstants.ELEMENT_HTTP_RESPONSE_HANDLER.equals(xtr.getLocalName())) { readHttpResponseHandler(xtr, conversionHelper); } else if (CmmnXmlConstants.ELEMENT_PROCESS_TASK_IN_PARAMETERS.equals(xtr.getLocalName())) { readIOParameter(xtr, true, conversionHelper); } else if (CmmnXmlConstants.ELEMENT_PROCESS_TASK_OUT_PARAMETERS.equals(xtr.getLocalName())) { readIOParameter(xtr, false, conversionHelper); } else if (CmmnXmlConstants.ELEMENT_TASK_LISTENER.equals(xtr.getLocalName())) { readTaskListener(xtr, conversionHelper); } else if (CmmnXmlConstants.ELEMENT_PLAN_ITEM_LIFECYCLE_LISTENER.equals(xtr.getLocalName())) { readLifecycleListener(xtr, conversionHelper); } else { ExtensionElement extensionElement = CmmnXmlUtil.parseExtensionElement(xtr); conversionHelper.getCurrentCmmnElement().addExtensionElement(extensionElement); } } else if (xtr.isEndElement()) { if (CmmnXmlConstants.ELEMENT_TASK_LISTENER.equalsIgnoreCase(xtr.getLocalName()) || CmmnXmlConstants.ELEMENT_PLAN_ITEM_LIFECYCLE_LISTENER .equalsIgnoreCase(xtr.getLocalName())) { conversionHelper.removeCurrentCmmnElement(); } else if (CmmnXmlConstants.ELEMENT_EXTENSION_ELEMENTS.equalsIgnoreCase(xtr.getLocalName())) { readyWithChildElements = true; } } } } catch (Exception ex) { LOGGER.error("Error processing CMMN document", ex); throw new XMLException("Error processing CMMN document", ex); } return null; }
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 ww w . java 2 s .c om 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.flowable.cmmn.converter.ExtensionElementsXMLConverter.java
protected void readFieldExtension(XMLStreamReader xtr, ConversionHelper conversionHelper) { BaseElement cmmnElement = conversionHelper.getCurrentCmmnElement(); FieldExtension extension = new FieldExtension(); extension.setFieldName(xtr.getAttributeValue(null, CmmnXmlConstants.ATTRIBUTE_NAME)); String stringValueAttribute = xtr.getAttributeValue(null, CmmnXmlConstants.ATTRIBUTE_FIELD_STRING); String expressionAttribute = xtr.getAttributeValue(null, CmmnXmlConstants.ATTRIBUTE_FIELD_EXPRESSION); if (StringUtils.isNotEmpty(stringValueAttribute)) { extension.setStringValue(stringValueAttribute); } else if (StringUtils.isNotEmpty(expressionAttribute)) { extension.setExpression(expressionAttribute); } else {// ww w. j ava 2 s . co m boolean readyWithFieldExtension = false; try { while (!readyWithFieldExtension && xtr.hasNext()) { xtr.next(); if (xtr.isStartElement() && CmmnXmlConstants.ELEMENT_FIELD_STRING.equalsIgnoreCase(xtr.getLocalName())) { extension.setStringValue(xtr.getElementText().trim()); } else if (xtr.isStartElement() && CmmnXmlConstants.ELEMENT_FIELD_EXPRESSION.equalsIgnoreCase(xtr.getLocalName())) { extension.setExpression(xtr.getElementText().trim()); } else if (xtr.isEndElement() && CmmnXmlConstants.ELEMENT_FIELD.equalsIgnoreCase(xtr.getLocalName())) { readyWithFieldExtension = true; } } } catch (Exception e) { LOGGER.warn("Error parsing field extension child elements", e); } } CmmnElement currentCmmnElement = conversionHelper.getCurrentCmmnElement(); if (currentCmmnElement instanceof ServiceTask) { ((ServiceTask) currentCmmnElement).getFieldExtensions().add(extension); } else if (currentCmmnElement instanceof DecisionTask) { ((DecisionTask) currentCmmnElement).getFieldExtensions().add(extension); } else if (currentCmmnElement instanceof FlowableListener) { ((FlowableListener) currentCmmnElement).getFieldExtensions().add(extension); } else { throw new FlowableException("Programmatic error: field added to unkown element " + currentCmmnElement); } }
From source file:org.flowable.cmmn.converter.FieldExtensionXmlConverter.java
@Override protected CmmnElement convert(XMLStreamReader xtr, ConversionHelper conversionHelper) { CmmnElement cmmnElement = conversionHelper.getCurrentCmmnElement(); if (!(cmmnElement instanceof ServiceTask || cmmnElement instanceof DecisionTask)) { return null; }/*from w w w. j av a2s . com*/ TaskWithFieldExtensions serviceTask = (TaskWithFieldExtensions) cmmnElement; FieldExtension extension = new FieldExtension(); extension.setFieldName(xtr.getAttributeValue(null, CmmnXmlConstants.ATTRIBUTE_NAME)); String stringValueAttribute = xtr.getAttributeValue(null, CmmnXmlConstants.ATTRIBUTE_FIELD_STRING); String expressionAttribute = xtr.getAttributeValue(null, CmmnXmlConstants.ATTRIBUTE_FIELD_EXPRESSION); if (StringUtils.isNotEmpty(stringValueAttribute)) { extension.setStringValue(stringValueAttribute); } else if (StringUtils.isNotEmpty(expressionAttribute)) { extension.setExpression(expressionAttribute); } else { boolean readyWithFieldExtension = false; try { while (!readyWithFieldExtension && xtr.hasNext()) { xtr.next(); if (xtr.isStartElement() && CmmnXmlConstants.ELEMENT_FIELD_STRING.equalsIgnoreCase(xtr.getLocalName())) { extension.setStringValue(xtr.getElementText().trim()); } else if (xtr.isStartElement() && CmmnXmlConstants.ELEMENT_FIELD_EXPRESSION.equalsIgnoreCase(xtr.getLocalName())) { extension.setExpression(xtr.getElementText().trim()); } else if (xtr.isEndElement() && getXMLElementName().equalsIgnoreCase(xtr.getLocalName())) { readyWithFieldExtension = true; } } } catch (Exception e) { LOGGER.warn("Error parsing field extension child elements", e); } } serviceTask.getFieldExtensions().add(extension); return null; }
From source file:org.flowable.dmn.converter.child.OutputValuesParser.java
@Override public void parseChildElement(XMLStreamReader xtr, DmnElement parentElement, DecisionTable decisionTable) throws Exception { if (!(parentElement instanceof OutputClause)) return;/*from w w w. jav a 2s. c o m*/ OutputClause clause = (OutputClause) parentElement; UnaryTests outputValues = new UnaryTests(); boolean readyWithOutputValues = false; try { while (!readyWithOutputValues && xtr.hasNext()) { xtr.next(); if (xtr.isStartElement() && ELEMENT_TEXT.equalsIgnoreCase(xtr.getLocalName())) { String outputValuesText = xtr.getElementText(); if (StringUtils.isNotEmpty(outputValuesText)) { String[] outputValuesSplit = outputValuesText.replaceAll("^\"", "") .split("\"?(,|$)(?=(([^\"]*\"){2})*[^\"]*$) *\"?"); outputValues.setTextValues(new ArrayList<Object>(Arrays.asList(outputValuesSplit))); } } else if (xtr.isEndElement() && getElementName().equalsIgnoreCase(xtr.getLocalName())) { readyWithOutputValues = true; } } } catch (Exception e) { LOGGER.warn("Error parsing output values", e); } clause.setOutputValues(outputValues); }
From source file:org.jwebsocket.config.xml.JWebSocketConfigHandler.java
/** * {@inheritDoc}//from w w w .ja v a 2 s .c o m */ @Override public Config processConfig(XMLStreamReader aStreamReader) { JWebSocketConfig.Builder lConfigBuilder = new JWebSocketConfig.Builder(); try { while (aStreamReader.hasNext()) { aStreamReader.next(); if (aStreamReader.isStartElement()) { String lElementName = aStreamReader.getLocalName(); if (lElementName.equals(ELEMENT_PROTOCOL)) { aStreamReader.next(); lConfigBuilder.setProtocol(aStreamReader.getText()); } else if (lElementName.equals(ELEMENT_NODE_ID)) { aStreamReader.next(); lConfigBuilder.setNodeId(aStreamReader.getText()); } else if (lElementName.equals(ELEMENT_LIBRARY_FOLDER)) { aStreamReader.next(); lConfigBuilder.setLibraryFolder(aStreamReader.getText()); } else if (lElementName.equals(ELEMENT_LIBRARIES)) { List<LibraryConfig> lLibraries = handleLibraries(aStreamReader); lConfigBuilder = lConfigBuilder.setLibraries(lLibraries); } else if (lElementName.equals(ELEMENT_ENGINES)) { List<EngineConfig> lEngines = handleEngines(aStreamReader); lConfigBuilder = lConfigBuilder.setEngines(lEngines); } else if (lElementName.equals(ELEMENT_SERVERS)) { List<ServerConfig> lServers = handleServers(aStreamReader); lConfigBuilder = lConfigBuilder.setServers(lServers); } else if (lElementName.equals(ELEMENT_PLUGINS)) { List<PluginConfig> lPlugins = handlePlugins(aStreamReader); lConfigBuilder = lConfigBuilder.setPlugins(lPlugins); } else if (lElementName.equals(ELEMENT_FILTERS)) { List<FilterConfig> lFilters = handleFilters(aStreamReader); lConfigBuilder = lConfigBuilder.setFilters(lFilters); } else if (lElementName.equals(ELEMENT_LOGGING)) { List<LoggingConfig> loggingConfigs = handleLoggingConfigs(aStreamReader); lConfigBuilder = lConfigBuilder.setLoggingConfig(loggingConfigs); } else if (lElementName.equals(ELEMENT_RIGHTS)) { List<RightConfig> lGlobalRights = handleRights(aStreamReader); lConfigBuilder = lConfigBuilder.setGlobalRights(lGlobalRights); } else if (lElementName.equals(ELEMENT_ROLES)) { List<RoleConfig> lRoles = handleRoles(aStreamReader); lConfigBuilder = lConfigBuilder.setGlobalRoles(lRoles); } else if (lElementName.equals(ELEMENT_USERS)) { List<UserConfig> lUsers = handleUsers(aStreamReader); lConfigBuilder = lConfigBuilder.setUsers(lUsers); } else { // ignore } } if (aStreamReader.isEndElement()) { String lElementName = aStreamReader.getLocalName(); if (lElementName.equals(JWEBSOCKET)) { break; } } } } catch (XMLStreamException lEx) { throw new WebSocketRuntimeException("Error parsing jWebSocket.xml configuration file", lEx); } // if no filters where given in the .xml file // initialize empty filter list here if (lConfigBuilder.getFilters() == null) { lConfigBuilder.setFilters(new FastList<FilterConfig>()); } // now return the config object, this is the only one config object that // should exists // in the system return lConfigBuilder.buildConfig(); }
From source file:org.jwebsocket.config.xml.JWebSocketConfigHandler.java
/** * private method to handle the user config. * * @param aStreamReader// w w w . jav a2s . co m * the stream reader object * @return the list of user config * @throws XMLStreamException * if there's any exception reading configuration */ private List<UserConfig> handleUsers(XMLStreamReader aStreamReader) throws XMLStreamException { List<UserConfig> lUsers = new FastList<UserConfig>(); while (aStreamReader.hasNext()) { aStreamReader.next(); if (aStreamReader.isStartElement()) { String lElementName = aStreamReader.getLocalName(); if (lElementName.equals(ELEMENT_USER)) { UserConfig lUser = (UserConfig) handlerContext.get(lElementName).processConfig(aStreamReader); lUsers.add(lUser); } } if (aStreamReader.isEndElement()) { String lElementName = aStreamReader.getLocalName(); if (lElementName.equals(ELEMENT_USERS)) { break; } } } return lUsers; }
From source file:org.jwebsocket.config.xml.JWebSocketConfigHandler.java
/** * method that reads the roles configuration * * @param aStreamReader/*from w ww. ja va 2 s .c om*/ * the stream reader object * @return the list of roles config * @throws XMLStreamException * if there's any exception reading configuration */ private List<RoleConfig> handleRoles(XMLStreamReader aStreamReader) throws XMLStreamException { List<RoleConfig> lRoles = new FastList<RoleConfig>(); while (aStreamReader.hasNext()) { aStreamReader.next(); if (aStreamReader.isStartElement()) { String lElementName = aStreamReader.getLocalName(); if (lElementName.equals(ELEMENT_ROLE)) { RoleConfig lRole = (RoleConfig) handlerContext.get(lElementName).processConfig(aStreamReader); lRoles.add(lRole); } } if (aStreamReader.isEndElement()) { String lElementName = aStreamReader.getLocalName(); if (lElementName.equals(ELEMENT_ROLES)) { break; } } } return lRoles; }
From source file:org.jwebsocket.config.xml.JWebSocketConfigHandler.java
/** * private method to read the list of rights configuration * * @param aStreamReader//from w ww. j a v a2 s. com * the stream reader object * @return the list of rights configuration * @throws XMLStreamException * if there's any exception reading configuration */ private List<RightConfig> handleRights(XMLStreamReader aStreamReader) throws XMLStreamException { List<RightConfig> lRights = new FastList<RightConfig>(); while (aStreamReader.hasNext()) { aStreamReader.next(); if (aStreamReader.isStartElement()) { String lElementName = aStreamReader.getLocalName(); if (lElementName.equals(ELEMENT_RIGHT)) { RightConfig lRight = (RightConfig) handlerContext.get(lElementName) .processConfig(aStreamReader); lRights.add(lRight); } } if (aStreamReader.isEndElement()) { String lElementName = aStreamReader.getLocalName(); if (lElementName.equals(ELEMENT_RIGHTS)) { break; } } } return lRights; }