List of usage examples for javax.xml.stream XMLStreamReader isStartElement
public boolean isStartElement();
From source file:org.flowable.cmmn.converter.CmmnXmlConverter.java
public CmmnModel convertToCmmnModel(XMLStreamReader xtr) { ConversionHelper conversionHelper = new ConversionHelper(); conversionHelper.setCmmnModel(new CmmnModel()); try {/*from ww w . j ava 2 s .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 {//from ww w .j a v a 2 s . co 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 w w w .j a va 2 s . co m*/ 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 {/*w w w. jav a 2s . c o 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; }/* w w w. j a va 2 s.co m*/ 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 ww w . ja va 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.geowebcache.georss.StaxGeoRSSReader.java
private void parseEntryMember(final XMLStreamReader reader, final QName memberName, final Entry entry) throws XMLStreamException { reader.require(START_ELEMENT, memberName.getNamespaceURI(), memberName.getLocalPart()); if (ATOM.id.equals(memberName)) { String id = text(reader); entry.setId(id);/*from ww w . ja va 2s .c o m*/ } else if (ATOM.link.equals(memberName)) { String uri = text(reader); URI link; try { link = new URI(uri); entry.setLink(link); } catch (URISyntaxException e) { logger.info("Feed contains illegal 'link' element content:" + uri); } } else if (ATOM.title.equals(memberName)) { String title = text(reader); entry.setTitle(title); } else if (ATOM.subtitle.equals(memberName)) { String subtitle = text(reader); entry.setSubtitle(subtitle); } else if (ATOM.updated.equals(memberName)) { String upd = text(reader); if (upd != null && upd.length() > 0) { entry.setUpdated(upd); } } else if (GEORSS.where.equals(memberName)) { QName nextTag = nextTag(reader); if (reader.isStartElement() && GML_NS_URI.equals(nextTag.getNamespaceURI())) { Geometry where = geometry(reader); if (logger.isTraceEnabled()) { logger.trace("Got geometry from feed: " + where); } entry.setWhere(where); } } consume(reader, memberName); reader.require(END_ELEMENT, memberName.getNamespaceURI(), memberName.getLocalPart()); }
From source file:org.jabref.logic.importer.fileformat.MedlineImporter.java
@Override public ParserResult importDatabase(BufferedReader reader) throws IOException { Objects.requireNonNull(reader); List<BibEntry> bibItems = new ArrayList<>(); try {/*from w w w. j a v a 2 s.com*/ JAXBContext context = JAXBContext.newInstance("org.jabref.logic.importer.fileformat.medline"); XMLInputFactory xmlInputFactory = XMLInputFactory.newFactory(); XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(reader); //go to the root element while (!xmlStreamReader.isStartElement()) { xmlStreamReader.next(); } Unmarshaller unmarshaller = context.createUnmarshaller(); Object unmarshalledObject = unmarshaller.unmarshal(xmlStreamReader); //check whether we have an article set, an article, a book article or a book article set if (unmarshalledObject instanceof PubmedArticleSet) { PubmedArticleSet articleSet = (PubmedArticleSet) unmarshalledObject; for (Object article : articleSet.getPubmedArticleOrPubmedBookArticle()) { if (article instanceof PubmedArticle) { PubmedArticle currentArticle = (PubmedArticle) article; parseArticle(currentArticle, bibItems); } if (article instanceof PubmedBookArticle) { PubmedBookArticle currentArticle = (PubmedBookArticle) article; parseBookArticle(currentArticle, bibItems); } } } else if (unmarshalledObject instanceof PubmedArticle) { PubmedArticle article = (PubmedArticle) unmarshalledObject; parseArticle(article, bibItems); } else if (unmarshalledObject instanceof PubmedBookArticle) { PubmedBookArticle currentArticle = (PubmedBookArticle) unmarshalledObject; parseBookArticle(currentArticle, bibItems); } else { PubmedBookArticleSet bookArticleSet = (PubmedBookArticleSet) unmarshalledObject; for (PubmedBookArticle bookArticle : bookArticleSet.getPubmedBookArticle()) { parseBookArticle(bookArticle, bibItems); } } } catch (JAXBException | XMLStreamException e) { LOGGER.debug("could not parse document", e); return ParserResult.fromError(e); } return new ParserResult(bibItems); }
From source file:org.jboss.rusheye.parser.Parser.java
private void parseFile(File file, boolean tmpfile) { VisualSuite visualSuite = null;/*from w w w . ja v a 2 s. c o m*/ try { XMLValidationSchemaFactory schemaFactory = XMLValidationSchemaFactory .newInstance(XMLValidationSchema.SCHEMA_ID_W3C_SCHEMA); URL schemaURL = getClass().getClassLoader().getResource("org/jboss/rusheye/visual-suite.xsd"); XMLValidationSchema schema = schemaFactory.createSchema(schemaURL); XMLInputFactory2 factory = (XMLInputFactory2) XMLInputFactory.newInstance(); StreamFilter filter = new StreamFilter() { @Override public boolean accept(XMLStreamReader reader) { return reader.isStartElement(); } }; XMLStreamReader2 reader = factory.createXMLStreamReader(file); XMLStreamReader2 filteredReader = new Stax2FilteredStreamReader(reader, filter); reader.validateAgainst(schema); // EventFilter filter = new EventFilter() { // @Override // public boolean accept(XMLEvent reader) { // return reader.isStartElement(); // } // }; // // XMLEventReader reader = factory.createXMLEventReader(file); // XMLEventReader filteredReader = factory.createFilteredReader(reader, filter); JAXBContext ctx = JAXBContext.newInstance(VisualSuite.class.getPackage().getName()); Unmarshaller um = ctx.createUnmarshaller(); UnmarshallerMultiListener listener = new UnmarshallerMultiListener(); um.setListener(listener); // skip parsing of the first element - visual-suite filteredReader.nextTag(); visualSuite = new VisualSuite(); handler.setVisualSuite(visualSuite); handler.getContext().invokeListeners().onSuiteStarted(visualSuite); listener.registerListener(new UniqueIdentityChecker(handler.getContext())); while (filteredReader.hasNext()) { try { // go on the start of the next tag filteredReader.nextTag(); Object o = um.unmarshal(reader); if (o instanceof GlobalConfiguration) { GlobalConfiguration globalConfiguration = (GlobalConfiguration) o; handler.getContext().setCurrentConfiguration(globalConfiguration); visualSuite.setGlobalConfiguration(globalConfiguration); handler.getContext().invokeListeners().onConfigurationReady(visualSuite); RetriverInjector retriverInjector = new RetriverInjector(this); for (Mask mask : globalConfiguration.getMasks()) { retriverInjector.afterUnmarshal(mask, null); } listener.registerListener(retriverInjector); } if (o instanceof Test) { Test test = (Test) o; handler.getContext().setCurrentConfiguration(test); handler.getContext().setCurrentTest(test); for (Pattern pattern : test.getPatterns()) { handler.getContext().invokeListeners().onPatternReady(test, pattern); } Test testWrapped = ConfigurationCompiler.wrap(test, visualSuite.getGlobalConfiguration()); handler.getContext().invokeListeners().onTestReady(testWrapped); } } catch (WstxParsingException e) { // intentionally blank - wrong end of document detection } } } catch (XMLStreamException e) { throw handleParsingException(e, e); } catch (JAXBException e) { throw handleParsingException(e, e.getLinkedException()); } finally { if (visualSuite != null && handler.getContext() != null) { handler.getContext().invokeListeners().onSuiteReady(visualSuite); } if (tmpfile) { FileUtils.deleteQuietly(file); } } }
From source file:org.jwebsocket.config.xml.JWebSocketConfigHandler.java
/** * {@inheritDoc}/* w w w .j av a2 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(); }