Example usage for javax.xml.stream XMLStreamReader hasNext

List of usage examples for javax.xml.stream XMLStreamReader hasNext

Introduction

In this page you can find the example usage for javax.xml.stream XMLStreamReader hasNext.

Prototype

public boolean hasNext() throws XMLStreamException;

Source Link

Document

Returns true if there are more parsing events and false if there are no more events.

Usage

From source file:org.flowable.cmmn.converter.ExtensionElementsXMLConverter.java

@Override
protected CmmnElement convert(XMLStreamReader xtr, ConversionHelper conversionHelper) {

    boolean readyWithChildElements = false;
    try {//w w w  .j  a  va2  s.  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 w w w  . j a  v a2s . c  o 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 {/*from w ww  .  j a  va  2  s. c  om*/
        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 . ja  v  a2s  . 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;// w w w.j a va2s.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.gephi.statistics.StatisticsModelImpl.java

public void readXML(XMLStreamReader reader) throws XMLStreamException {
    Collection<? extends StatisticsUI> uis = Lookup.getDefault().lookupAll(StatisticsUI.class);
    Collection<? extends StatisticsBuilder> builders = Lookup.getDefault().lookupAll(StatisticsBuilder.class);

    boolean end = false;
    while (reader.hasNext() && !end) {
        int type = reader.next();

        switch (type) {
        case XMLStreamReader.START_ELEMENT:
            String name = reader.getLocalName();
            if ("report".equalsIgnoreCase(name)) {
                String classStr = reader.getAttributeValue(null, "class");
                Class reportClass = null;
                for (StatisticsBuilder builder : builders) {
                    if (builder.getStatisticsClass().getName().equals(classStr)) {
                        reportClass = builder.getStatisticsClass();
                    }/*www.  j a  v  a2s  .c om*/
                }
                if (reportClass != null) {
                    String report = reader.getAttributeValue(null, "value");
                    report = unembedImages(report);
                    reportMap.put(reportClass, report);
                }
            }
            break;
        case XMLStreamReader.END_ELEMENT:
            if ("statisticsmodel".equalsIgnoreCase(reader.getLocalName())) {
                end = true;
            }
            break;
        }
    }
}

From source file:org.graphipedia.wikipedia.parser.SimpleStaxParser.java

/**
 * Parses the elements in the XML file./*w  w  w.ja  va  2s.  com*/
 * @param reader The XML stream.
 * @throws XMLStreamException when something goes wrong while parsing the XML file.
 */
private void parseElements(XMLStreamReader reader) throws XMLStreamException {
    LinkedList<String> elementStack = new LinkedList<String>();
    StringBuilder textBuffer = new StringBuilder();
    List<String> attributeValues = new ArrayList<String>();

    while (reader.hasNext()) {
        switch (reader.next()) {
        case XMLEvent.START_ELEMENT:
            String startElement = reader.getName().getLocalPart();
            elementStack.push(startElement);
            attributeValues = new ArrayList<String>();
            if (isInterestingWithAttributes(startElement)) {
                int noAttributes = reader.getAttributeCount();
                for (int i = 0; i < noAttributes; i += 1)
                    attributeValues.add(reader.getAttributeValue(i));
            }
            textBuffer.setLength(0);
            break;
        case XMLEvent.END_ELEMENT:
            String element = elementStack.pop();
            if (isInterestingWithAttributes(element)) {
                if (!handleElement(element, textBuffer.toString().trim(), attributeValues))
                    return;
            } else if (isInteresting(element)) {
                if (!handleElement(element, textBuffer.toString().trim()))
                    return;
            }
            break;
        case XMLEvent.CHARACTERS:
            if (isInteresting(elementStack.peek())) {
                textBuffer.append(reader.getText());
            }
            break;
        }
    }
}

From source file:org.jbpm.designer.web.profile.impl.JbpmProfileImpl.java

private void initializeLocalPlugins(ServletContext context) {
    Map<String, IDiagramPlugin> registry = PluginServiceImpl.getLocalPluginsRegistry(context);
    FileInputStream fileStream = null;
    try {//from w  w w  . j  a va 2  s .co  m
        try {
            fileStream = new FileInputStream(new StringBuilder(context.getRealPath("/")).append("/")
                    .append(ConfigurationProvider.getInstance().getDesignerContext()).append("profiles")
                    .append("/").append("jbpm.xml").toString());
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
        XMLInputFactory factory = XMLInputFactory.newInstance();
        XMLStreamReader reader = factory.createXMLStreamReader(fileStream, "UTF-8");
        while (reader.hasNext()) {
            if (reader.next() == XMLStreamReader.START_ELEMENT) {
                if ("profile".equals(reader.getLocalName())) {
                    for (int i = 0; i < reader.getAttributeCount(); i++) {
                        if ("stencilset".equals(reader.getAttributeLocalName(i))) {
                            _stencilSet = reader.getAttributeValue(i);
                        }
                    }
                } else if ("plugin".equals(reader.getLocalName())) {
                    String name = null;
                    for (int i = 0; i < reader.getAttributeCount(); i++) {
                        if ("name".equals(reader.getAttributeLocalName(i))) {
                            name = reader.getAttributeValue(i);
                        }
                    }
                    _plugins.put(name, registry.get(name));
                } else if ("localhistory".equals(reader.getLocalName())) {
                    for (int i = 0; i < reader.getAttributeCount(); i++) {
                        if ("enabled".equals(reader.getAttributeLocalName(i))) {
                            String localhistoryenabled = reader.getAttributeValue(i);
                            if (!isEmpty(localhistoryenabled)) {
                                _localHistoryEnabled = localhistoryenabled;
                            } else {
                                _logger.info("Invalid local history enabled");
                            }
                        }
                        if ("timeout".equals(reader.getAttributeLocalName(i))) {
                            String localhistorytimeout = reader.getAttributeValue(i);
                            if (!isEmpty(localhistorytimeout)) {
                                _localHistoryTimeout = localhistorytimeout;
                            } else {
                                _logger.info("Invalid local history timeout");
                            }
                        }
                    }
                } else if ("storesvgonsave".equals(reader.getLocalName())) {
                    for (int i = 0; i < reader.getAttributeCount(); i++) {
                        if ("enabled".equals(reader.getAttributeLocalName(i))) {
                            String storesvgonsaveenabled = reader.getAttributeValue(i);
                            if (!isEmpty(storesvgonsaveenabled)) {
                                _storeSVGonSaveOption = storesvgonsaveenabled;
                            } else {
                                _logger.info("Invalid store svg on save enabled");
                            }
                        }
                    }
                }
            }
        }
    } catch (XMLStreamException e) {
        _logger.error(e.getMessage(), e);
        throw new RuntimeException(e); // stop initialization
    } finally {
        if (fileStream != null) {
            try {
                fileStream.close();
            } catch (IOException e) {
            }
        }
        ;
    }
}

From source file:org.jbpm.designer.web.server.ProcessDiffServiceServlet.java

private List<String> getAssetVersions(String packageName, String assetName, String uuid,
        IDiagramProfile profile) {//from  w w  w .  j ava 2 s  .c o m
    try {
        String assetVersionURL = RepositoryInfo.getRepositoryProtocol(profile) + "://"
                + RepositoryInfo.getRepositoryHost(profile) + "/"
                + RepositoryInfo.getRepositorySubdomain(profile).substring(0,
                        RepositoryInfo.getRepositorySubdomain(profile).indexOf("/"))
                + "/rest/packages/" + URLEncoder.encode(packageName, "UTF-8") + "/assets/" + assetName
                + "/versions/";
        List<String> versionList = new ArrayList<String>();

        XMLInputFactory factory = XMLInputFactory.newInstance();
        XMLStreamReader reader = factory.createXMLStreamReader(
                ServletUtil.getInputStreamForURL(assetVersionURL, "GET", profile), "UTF-8");
        boolean isFirstTitle = true;
        String title = "";
        while (reader.hasNext()) {
            int next = reader.next();
            if (next == XMLStreamReader.START_ELEMENT) {
                if ("title".equals(reader.getLocalName())) {
                    if (isFirstTitle) {
                        isFirstTitle = false;
                    } else {
                        versionList.add(reader.getElementText());
                    }
                }
            }
        }
        return versionList;
    } catch (Exception e) {
        _logger.error(e.getMessage());
        return null;
    }
}

From source file:org.jwebsocket.config.xml.JWebSocketConfigHandler.java

/**
 * {@inheritDoc}//from w  w w.j  a  v a 2  s.  co  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();
}