Example usage for javax.xml.stream XMLStreamReader isStartElement

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

Introduction

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

Prototype

public boolean isStartElement();

Source Link

Document

Returns true if the cursor points to a start tag (otherwise false)

Usage

From source file:org.activiti.designer.eclipse.bpmn.BpmnParser.java

private ReceiveTask parseReceiveTask(XMLStreamReader xtr) {
    ReceiveTask receiveTask = new ReceiveTask();
    boolean readyWithTask = false;
    try {/*from   w  w  w  .  j  a v a 2 s  . c  om*/
        while (readyWithTask == false && xtr.hasNext()) {
            xtr.next();
            if (xtr.isStartElement() && "extensionElements".equalsIgnoreCase(xtr.getLocalName())) {
                receiveTask.getExecutionListeners().addAll(parseListeners(xtr));

            } else if (xtr.isStartElement()
                    && "multiInstanceLoopCharacteristics".equalsIgnoreCase(xtr.getLocalName())) {
                receiveTask.setLoopCharacteristics(parseMultiInstanceDef(xtr));

            } else if (xtr.isEndElement() && "receiveTask".equalsIgnoreCase(xtr.getLocalName())) {
                readyWithTask = true;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return receiveTask;
}

From source file:org.activiti.designer.eclipse.bpmn.BpmnParser.java

private BusinessRuleTask parseBusinessRuleTask(XMLStreamReader xtr) {
    BusinessRuleTask businessRuleTask = new BusinessRuleTask();
    if (xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, "rules") != null) {
        String ruleNames = xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, "rules");
        if (ruleNames != null && ruleNames.length() > 0) {
            businessRuleTask.getRuleNames().clear();
            if (ruleNames.contains(",") == false) {
                businessRuleTask.getRuleNames().add(ruleNames);
            } else {
                String[] ruleNameList = ruleNames.split(",");
                for (String rule : ruleNameList) {
                    businessRuleTask.getRuleNames().add(rule);
                }// w w w  .j a va2s  .  co m
            }
        }
    }
    if (xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, "ruleVariablesInput") != null) {
        String inputNames = xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, "ruleVariablesInput");
        if (inputNames != null && inputNames.length() > 0) {
            businessRuleTask.getInputVariables().clear();
            if (inputNames.contains(",") == false) {
                businessRuleTask.getInputVariables().add(inputNames);
            } else {
                String[] inputNamesList = inputNames.split(",");
                for (String input : inputNamesList) {
                    businessRuleTask.getInputVariables().add(input);
                }
            }
        }
    }
    if (xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, "exclude") != null) {
        businessRuleTask
                .setExclude(Boolean.valueOf(xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, "exclude")));
    }
    if (xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, "resultVariableName") != null) {
        businessRuleTask.setResultVariableName(
                xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, "resultVariableName"));
    }

    boolean readyWithTask = false;
    try {
        while (readyWithTask == false && xtr.hasNext()) {
            xtr.next();
            if (xtr.isStartElement() && "extensionElements".equalsIgnoreCase(xtr.getLocalName())) {
                businessRuleTask.getExecutionListeners().addAll(parseListeners(xtr));

            } else if (xtr.isStartElement()
                    && "multiInstanceLoopCharacteristics".equalsIgnoreCase(xtr.getLocalName())) {
                businessRuleTask.setLoopCharacteristics(parseMultiInstanceDef(xtr));

            } else if (xtr.isEndElement() && "businessRuleTask".equalsIgnoreCase(xtr.getLocalName())) {
                readyWithTask = true;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return businessRuleTask;
}

From source file:org.activiti.designer.eclipse.bpmn.BpmnParser.java

private BoundaryEventModel parseBoundaryEvent(XMLStreamReader xtr) {
    BoundaryEvent boundaryEvent = new BoundaryEvent();
    boundaryEvent.setName(xtr.getAttributeValue(null, "name"));

    if (xtr.getAttributeValue(null, "cancelActivity") != null) {
        String cancelActivity = xtr.getAttributeValue(null, "cancelActivity");
        if ("true".equalsIgnoreCase(cancelActivity)) {
            boundaryEvent.setCancelActivity(true);
        } else {// w w w. jav a 2s  .c o  m
            boundaryEvent.setCancelActivity(false);
        }
    }

    BoundaryEventModel model = new BoundaryEventModel();
    model.boundaryEvent = boundaryEvent;
    model.attachedRef = xtr.getAttributeValue(null, "attachedToRef");
    try {
        while (xtr.hasNext()) {
            xtr.next();
            if (xtr.isStartElement() && "timerEventDefinition".equalsIgnoreCase(xtr.getLocalName())) {
                model.type = BoundaryEventModel.TIMEEVENT;
                boundaryEvent.getEventDefinitions().add(parseTimerEventDefinition(xtr));
                break;

            } else if (xtr.isStartElement() && "errorEventDefinition".equalsIgnoreCase(xtr.getLocalName())) {
                model.type = BoundaryEventModel.ERROREVENT;
                boundaryEvent.getEventDefinitions().add(parseErrorEventDefinition(xtr));
                break;

            } else if (xtr.isStartElement() && "signalEventDefinition".equalsIgnoreCase(xtr.getLocalName())) {
                model.type = BoundaryEventModel.SIGNALEVENT;
                boundaryEvent.getEventDefinitions().add(parseSignalEventDefinition(xtr));
                break;

            } else if (xtr.isEndElement() && "boundaryEvent".equalsIgnoreCase(xtr.getLocalName())) {
                break;
            }
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
    return model;
}

From source file:org.activiti.designer.eclipse.bpmn.BpmnParser.java

private IntermediateCatchEvent parseIntermediateCatchEvent(XMLStreamReader xtr) {
    IntermediateCatchEvent catchEvent = new IntermediateCatchEvent();

    try {/*  w w w .  j a  v  a  2s . co m*/
        while (xtr.hasNext()) {
            xtr.next();
            if (xtr.isStartElement() && "timerEventDefinition".equalsIgnoreCase(xtr.getLocalName())) {
                catchEvent.getEventDefinitions().add(parseTimerEventDefinition(xtr));
                break;

            } else if (xtr.isStartElement() && "signalEventDefinition".equalsIgnoreCase(xtr.getLocalName())) {
                catchEvent.getEventDefinitions().add(parseSignalEventDefinition(xtr));
                break;

            } else if (xtr.isEndElement() && "intermediateCatchEvent".equalsIgnoreCase(xtr.getLocalName())) {
                break;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return catchEvent;
}

From source file:org.activiti.designer.eclipse.bpmn.BpmnParser.java

private ThrowEvent parseIntermediateThrowEvent(XMLStreamReader xtr) {
    ThrowEvent throwEvent = new ThrowEvent();
    try {/* w  w w .j a  v  a  2  s .c o  m*/
        while (xtr.hasNext()) {
            xtr.next();
            if (xtr.isStartElement() && "signalEventDefinition".equalsIgnoreCase(xtr.getLocalName())) {
                throwEvent.getEventDefinitions().add(parseSignalEventDefinition(xtr));
                break;

            } else if (xtr.isEndElement() && "intermediateThrowEvent".equalsIgnoreCase(xtr.getLocalName())) {
                break;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return throwEvent;
}

From source file:org.activiti.designer.eclipse.bpmn.BpmnParser.java

private TimerEventDefinition parseTimerEventDefinition(XMLStreamReader xtr) {
    TimerEventDefinition eventDefinition = new TimerEventDefinition();
    try {// w  ww . j  av a2 s.  co  m
        while (xtr.hasNext()) {
            xtr.next();
            if (xtr.isStartElement() && "timeDuration".equalsIgnoreCase(xtr.getLocalName())) {
                eventDefinition.setTimeDuration(xtr.getElementText());
                break;

            } else if (xtr.isStartElement() && "timeDate".equalsIgnoreCase(xtr.getLocalName())) {
                eventDefinition.setTimeDate(xtr.getElementText());
                break;

            } else if (xtr.isStartElement() && "timeCycle".equalsIgnoreCase(xtr.getLocalName())) {
                eventDefinition.setTimeCycle(xtr.getElementText());
                break;

            } else if (xtr.isEndElement() && "timerEventDefinition".equalsIgnoreCase(xtr.getLocalName())) {
                break;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return eventDefinition;
}

From source file:org.activiti.dmn.converter.util.DmnXMLUtil.java

public static void parseChildElements(String elementName, DmnElement parentElement, XMLStreamReader xtr,
        Map<String, BaseChildElementParser> childParsers, DmnDefinition model) throws Exception {

    Map<String, BaseChildElementParser> localParserMap = new HashMap<String, BaseChildElementParser>(
            genericChildParserMap);/*from  www .java  2  s .  c  o m*/
    if (childParsers != null) {
        localParserMap.putAll(childParsers);
    }

    boolean inExtensionElements = false;
    boolean readyWithChildElements = false;
    while (readyWithChildElements == false && xtr.hasNext()) {
        xtr.next();

        if (xtr.isStartElement()) {

            if (ELEMENT_EXTENSIONS.equals(xtr.getLocalName())) {
                inExtensionElements = true;
            } else if (localParserMap.containsKey(xtr.getLocalName())) {
                BaseChildElementParser childParser = localParserMap.get(xtr.getLocalName());
                //if we're into an extension element but the current element is not accepted by this parentElement then is read as a custom extension element
                if (inExtensionElements && !childParser.accepts(parentElement)) {
                    DmnExtensionElement extensionElement = parseExtensionElement(xtr);
                    parentElement.addExtensionElement(extensionElement);
                    continue;
                }
                localParserMap.get(xtr.getLocalName()).parseChildElement(xtr, parentElement, model);
            } else if (inExtensionElements) {
                DmnExtensionElement extensionElement = parseExtensionElement(xtr);
                parentElement.addExtensionElement(extensionElement);
            }

        } else if (xtr.isEndElement()) {
            if (ELEMENT_EXTENSIONS.equals(xtr.getLocalName())) {
                inExtensionElements = false;
            } else if (elementName.equalsIgnoreCase(xtr.getLocalName())) {
                readyWithChildElements = true;
            }
        }
    }
}

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());
    }/*  ww  w .ja v  a2s  . co  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.activiti.dmn.xml.converter.DmnXMLConverter.java

public DmnDefinition convertToDmnModel(XMLStreamReader xtr) {
    DmnDefinition model = new DmnDefinition();
    DmnElement parentElement = null;/*from w w  w  .  ja  v a  2  s.c  o m*/

    try {
        while (xtr.hasNext()) {
            try {
                xtr.next();
            } catch (Exception e) {
                LOGGER.debug("Error reading XML document", e);
                throw new DmnXMLException("Error reading XML", e);
            }

            if (xtr.isStartElement() == false) {
                continue;
            }

            if (ELEMENT_DEFINITIONS.equals(xtr.getLocalName())) {
                model.setId(xtr.getAttributeValue(null, ATTRIBUTE_ID));
                model.setName(xtr.getAttributeValue(null, ATTRIBUTE_NAME));
                model.setNamespace(MODEL_NAMESPACE);
                parentElement = model;
            } else if (ELEMENT_DECISION.equals(xtr.getLocalName())) {
                Decision decision = new Decision();
                model.addDrgElement(decision);
                decision.setId(xtr.getAttributeValue(null, ATTRIBUTE_ID));
                decision.setName(xtr.getAttributeValue(null, ATTRIBUTE_NAME));
                parentElement = decision;
            } else if (ELEMENT_DECISION_TABLE.equals(xtr.getLocalName())) {
                DecisionTable currentDecisionTable = new DecisionTable();
                currentDecisionTable.setId(xtr.getAttributeValue(null, ATTRIBUTE_ID));

                if (xtr.getAttributeValue(null, ATTRIBUTE_HIT_POLICY) != null) {
                    currentDecisionTable
                            .setHitPolicy(HitPolicy.valueOf(xtr.getAttributeValue(null, ATTRIBUTE_HIT_POLICY)));
                } else {
                    currentDecisionTable.setHitPolicy(HitPolicy.FIRST);
                }

                model.getDrgElements().get(model.getDrgElements().size() - 1)
                        .setDecisionTable(currentDecisionTable);
                model.setCurrentDecisionTable(currentDecisionTable);
                parentElement = currentDecisionTable;
            } else if (ELEMENT_OUTPUT_CLAUSE.equals(xtr.getLocalName())) {
                OutputClause outputClause = new OutputClause();
                model.getCurrentDecisionTable().addOutput(outputClause);
                outputClause.setId(xtr.getAttributeValue(null, ATTRIBUTE_ID));
                outputClause.setLabel(xtr.getAttributeValue(null, ATTRIBUTE_LABEL));
                outputClause.setName(xtr.getAttributeValue(null, ATTRIBUTE_NAME));
                outputClause.setTypeRef(xtr.getAttributeValue(null, ATTRIBUTE_TYPE_REF));
                parentElement = outputClause;
            } else if (ELEMENT_DESCRIPTION.equals(xtr.getLocalName())) {
                parentElement.setDescription(xtr.getElementText());
            } else if (ELEMENT_EXTENSIONS.equals(xtr.getLocalName())) {
                while (xtr.hasNext()) {
                    xtr.next();
                    if (xtr.isStartElement()) {
                        DmnExtensionElement extensionElement = DmnXMLUtil.parseExtensionElement(xtr);
                        parentElement.addExtensionElement(extensionElement);
                    } else if (xtr.isEndElement()) {
                        if (ELEMENT_EXTENSIONS.equals(xtr.getLocalName())) {
                            break;
                        }
                    }
                }

            } else if (convertersToDmnMap.containsKey(xtr.getLocalName())) {
                BaseDmnXMLConverter converter = convertersToDmnMap.get(xtr.getLocalName());
                converter.convertToDmnModel(xtr, model);
            }
        }

        processDmnElements(model.getCurrentDecisionTable());

    } catch (DmnXMLException e) {
        throw e;

    } catch (Exception e) {
        LOGGER.error("Error processing DMN document", e);
        throw new DmnXMLException("Error processing DMN document", e);
    }
    return model;
}

From source file:org.apache.axiom.util.stax.XMLStreamReaderUtilsTest.java

private void testGetDataHandlerFromElementWithZeroLength(boolean useDHR) throws Exception {
    XMLStreamReader reader = StAXUtils.createXMLStreamReader(new StringReader("<test/>"));
    if (useDHR) {
        // To have an XMLStreamReader that uses the DataHandlerReader extension, we wrap
        // the parser using an XOPDecodingStreamReader (even if the document doesn't contain
        // any xop:Include).
        reader = new XOPDecodingStreamReader(reader, null);
    }/*from  w w w .java 2s .  c om*/
    try {
        reader.next();

        // Check precondition
        assertTrue(reader.isStartElement());

        DataHandler dh = XMLStreamReaderUtils.getDataHandlerFromElement(reader);

        // Check postcondition
        assertTrue(reader.isEndElement());
        assertEquals(-1, dh.getInputStream().read());
    } finally {
        reader.close();
    }
}