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.activiti.designer.eclipse.bpmn.BpmnParser.java

private StartEvent parseStartEvent(XMLStreamReader xtr) {
    StartEvent startEvent = null;/*from w  w  w . j a v a2 s .  co  m*/
    if (StringUtils.isNotEmpty(xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, "formKey"))) {
        String[] formTypes = PreferencesUtil.getStringArray(Preferences.ALFRESCO_FORMTYPES_STARTEVENT);
        for (String form : formTypes) {
            if (form.equals(xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, "formKey"))) {
                startEvent = new AlfrescoStartEvent();
            }
        }
    }
    if (startEvent == null) {
        startEvent = new StartEvent();
    }

    if (StringUtils.isNotEmpty(xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, "initiator"))) {
        startEvent.setInitiator(xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, "initiator"));
    }

    if (StringUtils.isNotEmpty(xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, "formKey"))) {
        startEvent.setFormKey(xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, "formKey"));
    }
    boolean readyWithStartEvent = false;
    try {
        while (readyWithStartEvent == false && xtr.hasNext()) {
            xtr.next();
            if (xtr.isStartElement() && "formProperty".equalsIgnoreCase(xtr.getLocalName())) {
                FormProperty property = new FormProperty();
                startEvent.getFormProperties().add(property);
                parseFormProperty(property, xtr);

            } else if (xtr.isStartElement() && "errorEventDefinition".equalsIgnoreCase(xtr.getLocalName())) {
                startEvent.getEventDefinitions().add(parseErrorEventDefinition(xtr));

            } else if (xtr.isStartElement() && "timerEventDefinition".equalsIgnoreCase(xtr.getLocalName())) {
                startEvent.getEventDefinitions().add(parseTimerEventDefinition(xtr));

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

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

private void parseFormProperty(FormProperty property, XMLStreamReader xtr) {
    if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, "id"))) {
        property.setId(xtr.getAttributeValue(null, "id"));
    }/*from w ww . java 2  s.com*/
    if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, "name"))) {
        property.setName(xtr.getAttributeValue(null, "name"));
    }
    if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, "type"))) {
        property.setType(xtr.getAttributeValue(null, "type"));
    }
    if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, "value"))) {
        property.setValue(xtr.getAttributeValue(null, "value"));
    }
    if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, "variable"))) {
        property.setVariable(xtr.getAttributeValue(null, "variable"));
    }
    if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, "expression"))) {
        property.setExpression(xtr.getAttributeValue(null, "expression"));
    }
    if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, "default"))) {
        property.setDefaultExpression(xtr.getAttributeValue(null, "default"));
    }
    if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, "datePattern"))) {
        property.setDatePattern(xtr.getAttributeValue(null, "datePattern"));
    }
    if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, "required"))) {
        property.setRequired(Boolean.valueOf(xtr.getAttributeValue(null, "required")));
    }
    if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, "readable"))) {
        property.setReadable(Boolean.valueOf(xtr.getAttributeValue(null, "readable")));
    }
    if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, "writable"))) {
        property.setWriteable(Boolean.valueOf(xtr.getAttributeValue(null, "writable")));
    }

    boolean readyWithFormProperty = false;
    try {
        while (readyWithFormProperty == false && xtr.hasNext()) {
            xtr.next();
            if (xtr.isStartElement() && "value".equalsIgnoreCase(xtr.getLocalName())) {
                FormValue value = new FormValue();
                value.setId(xtr.getAttributeValue(null, "id"));
                value.setName(xtr.getAttributeValue(null, "name"));
                property.getFormValues().add(value);

            } else if (xtr.isEndElement() && "formProperty".equalsIgnoreCase(xtr.getLocalName())) {
                readyWithFormProperty = true;
            }
        }
    } catch (Exception e) {
    }
}

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

private MultiInstanceLoopCharacteristics parseMultiInstanceDef(XMLStreamReader xtr) {
    MultiInstanceLoopCharacteristics multiInstanceDef = new MultiInstanceLoopCharacteristics();

    if (xtr.getAttributeValue(null, "isSequential") != null) {
        multiInstanceDef.setSequential(Boolean.valueOf(xtr.getAttributeValue(null, "isSequential")));
    }// w w w . ja  v a 2s  .c  o  m

    if (xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, "collection") != null) {
        multiInstanceDef.setInputDataItem(xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, "collection"));
    }
    if (xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, "elementVariable") != null) {
        multiInstanceDef
                .setElementVariable(xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, "elementVariable"));
    }

    boolean readyWithMultiInstance = false;
    try {
        while (readyWithMultiInstance == false && xtr.hasNext()) {
            xtr.next();
            if (xtr.isStartElement() && "loopCardinality".equalsIgnoreCase(xtr.getLocalName())) {
                multiInstanceDef.setLoopCardinality(xtr.getElementText());

            } else if (xtr.isStartElement() && "loopDataInputRef".equalsIgnoreCase(xtr.getLocalName())) {
                multiInstanceDef.setInputDataItem(xtr.getElementText());

            } else if (xtr.isStartElement() && "inputDataItem".equalsIgnoreCase(xtr.getLocalName())) {
                if (xtr.getAttributeValue(null, "name") != null) {
                    multiInstanceDef.setElementVariable(xtr.getAttributeValue(null, "name"));
                }

            } else if (xtr.isStartElement() && "completionCondition".equalsIgnoreCase(xtr.getLocalName())) {
                multiInstanceDef.setCompletionCondition(xtr.getElementText());

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

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

private EndEvent parseEndEvent(XMLStreamReader xtr) {
    EndEvent endEvent = new EndEvent();

    boolean readyWithEndEvent = false;
    try {/*from w  w w .ja  v a2s  .  co m*/
        while (readyWithEndEvent == false && xtr.hasNext()) {
            xtr.next();
            if (xtr.isStartElement() && "errorEventDefinition".equalsIgnoreCase(xtr.getLocalName())) {
                endEvent.getEventDefinitions().add(parseErrorEventDefinition(xtr));

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

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

private TextAnnotation parseTextAnnotation(XMLStreamReader xtr) throws XMLStreamException {
    final TextAnnotation ta = new TextAnnotation();
    ta.setId(xtr.getAttributeValue(null, "id"));
    ta.setTextFormat(xtr.getAttributeValue(null, "textFormat"));
    while (xtr.hasNext()) {
        xtr.next();//from   w  ww  .  j a  v  a 2 s.co  m
        if (xtr.isStartElement() && "text".equalsIgnoreCase(xtr.getLocalName())) {
            ta.setText(xtr.getElementText());
            break;
        }
    }
    return ta;
}

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

private static String parseSequenceFlowCondition(XMLStreamReader xtr, SequenceFlowModel sequenceFlow) {
    String condition = null;//from ww w .j av a 2s . c  om
    if (xtr.getAttributeValue(null, "name") != null && xtr.getAttributeValue(null, "name").contains("${")) {
        condition = xtr.getAttributeValue(null, "name");
    }
    boolean readyWithSequenceFlow = false;
    try {
        while (readyWithSequenceFlow == false && xtr.hasNext()) {
            xtr.next();
            if (xtr.isStartElement() && "conditionExpression".equalsIgnoreCase(xtr.getLocalName())) {
                condition = xtr.getElementText();

            } else if (xtr.isStartElement() && "extensionElements".equalsIgnoreCase(xtr.getLocalName())) {
                sequenceFlow.listenerList.addAll(parseListeners(xtr));

            } else if (xtr.isEndElement() && "sequenceFlow".equalsIgnoreCase(xtr.getLocalName())) {
                readyWithSequenceFlow = true;
            }
        }
    } catch (Exception e) {
    }
    return condition;
}

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

private UserTask parseUserTask(XMLStreamReader xtr) {
    UserTask userTask = null;/*from   www.ja  v a 2  s  .c o m*/
    if (xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, "formKey") != null) {
        String[] formTypes = PreferencesUtil.getStringArray(Preferences.ALFRESCO_FORMTYPES_USERTASK);
        for (String form : formTypes) {
            if (form.equals(xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, "formKey"))) {
                userTask = new AlfrescoUserTask();
            }
        }
    }
    if (userTask == null) {
        userTask = new UserTask();
    }

    if (StringUtils.isNotEmpty(xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, "dueDate"))) {
        userTask.setDueDate(xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, "dueDate"));
    }

    if (StringUtils.isNotEmpty(xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, "assignee"))) {
        String assignee = xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, "assignee");
        userTask.setAssignee(assignee);

    }

    if (StringUtils.isNotEmpty(xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, "candidateUsers"))) {
        String expression = xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, "candidateUsers");
        String[] expressionList = null;
        if (expression.contains(";")) {
            expressionList = expression.split(";");
        } else {
            expressionList = new String[] { expression };
        }
        for (String user : expressionList) {
            userTask.getCandidateUsers().add(user);
        }

    }

    if (StringUtils.isNotEmpty(xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, "candidateGroups"))) {
        String expression = xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, "candidateGroups");
        String[] expressionList = null;
        if (expression.contains(";")) {
            expressionList = expression.split(";");
        } else {
            expressionList = new String[] { expression };
        }
        for (String group : expressionList) {
            userTask.getCandidateGroups().add(group);
        }
    }

    if (StringUtils.isNotEmpty(xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, "formKey"))) {
        userTask.setFormKey(xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, "formKey"));
    }

    if (StringUtils.isNotEmpty(xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, "priority"))) {
        Integer priorityValue = null;
        try {
            priorityValue = Integer.valueOf(xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, "priority"));
        } catch (Exception e) {
        }
        userTask.setPriority(priorityValue);
    }

    boolean readyWithUserTask = false;
    try {
        String assignmentType = null;
        ActivitiListener listener = null;
        while (readyWithUserTask == false && xtr.hasNext()) {
            xtr.next();
            if (xtr.isStartElement() && "humanPerformer".equalsIgnoreCase(xtr.getLocalName())) {
                assignmentType = "humanPerformer";

            } else if (xtr.isStartElement() && "potentialOwner".equalsIgnoreCase(xtr.getLocalName())) {
                assignmentType = "potentialOwner";

            } else if (xtr.isStartElement() && "formalExpression".equalsIgnoreCase(xtr.getLocalName())) {
                if ("potentialOwner".equals(assignmentType)) {
                    List<String> assignmentList = new ArrayList<String>();
                    String assignmentText = xtr.getElementText();
                    if (assignmentText.contains(",")) {
                        String[] assignmentArray = assignmentText.split(",");
                        assignmentList = Arrays.asList(assignmentArray);
                    } else {
                        assignmentList.add(assignmentText);
                    }
                    for (String assignmentValue : assignmentList) {
                        if (assignmentValue == null)
                            continue;
                        assignmentValue = assignmentValue.trim();
                        if (assignmentValue.length() == 0)
                            continue;

                        if (assignmentValue.trim().startsWith("user(")) {
                            userTask.getCandidateUsers().add(assignmentValue);

                        } else {
                            userTask.getCandidateGroups().add(assignmentValue);
                        }
                    }

                } else {
                    userTask.setAssignee(xtr.getElementText());
                }

            } else if (xtr.isStartElement() && ("taskListener".equalsIgnoreCase(xtr.getLocalName()))) {

                if (xtr.getAttributeValue(null, "class") != null
                        && "org.alfresco.repo.workflow.activiti.listener.ScriptExecutionListener"
                                .equals(xtr.getAttributeValue(null, "class"))
                        || "org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener"
                                .equals(xtr.getAttributeValue(null, "class"))) {

                    listener = new ActivitiListener();
                    listener.setEvent(xtr.getAttributeValue(null, "event"));
                    listener.setImplementationType(ALFRESCO_TYPE);
                    boolean readyWithAlfrescoType = false;
                    while (readyWithAlfrescoType == false && xtr.hasNext()) {
                        xtr.next();
                        if (xtr.isStartElement() && "field".equalsIgnoreCase(xtr.getLocalName())) {
                            String script = getFieldExtensionValue(xtr);
                            if (script != null && script.length() > 0) {
                                listener.setImplementation(script);
                            }
                            readyWithAlfrescoType = true;
                        } else if (xtr.isEndElement()
                                && "extensionElements".equalsIgnoreCase(xtr.getLocalName())) {
                            readyWithAlfrescoType = true;
                            readyWithUserTask = true;
                        }
                    }
                } else {
                    listener = parseListener(xtr);
                }
                userTask.getTaskListeners().add(listener);

            } else if (xtr.isStartElement() && "field".equalsIgnoreCase(xtr.getLocalName())) {
                listener.getFieldExtensions().add(parseFieldExtension(xtr));

            } else if (xtr.isStartElement() && "formProperty".equalsIgnoreCase(xtr.getLocalName())) {
                FormProperty property = new FormProperty();
                userTask.getFormProperties().add(property);
                parseFormProperty(property, xtr);

            } else if (xtr.isStartElement() && "documentation".equalsIgnoreCase(xtr.getLocalName())) {

                String docText = xtr.getElementText();
                if (StringUtils.isEmpty(docText) == false) {
                    userTask.setDocumentation(docText);
                }

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

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

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

private ScriptTask parseScriptTask(XMLStreamReader xtr) {
    ScriptTask scriptTask = new ScriptTask();
    scriptTask.setScriptFormat(xtr.getAttributeValue(null, "scriptFormat"));
    boolean readyWithScriptTask = false;
    try {/* w  w w  .  java 2s . c  o m*/
        while (readyWithScriptTask == false && xtr.hasNext()) {
            xtr.next();
            if (xtr.isStartElement() && "script".equalsIgnoreCase(xtr.getLocalName())) {
                scriptTask.setScript(xtr.getElementText());

            } else if (xtr.isStartElement() && "extensionElements".equalsIgnoreCase(xtr.getLocalName())) {
                scriptTask.getExecutionListeners().addAll(parseListeners(xtr));

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

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

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

private MailTask parseMailTask(XMLStreamReader xtr, String taskType) {
    MailTask mailTask = new MailTask();
    boolean readyWithMailTask = false;
    try {//from   w  w  w  .j  a  va  2  s. com
        while (readyWithMailTask == false && xtr.hasNext()) {
            xtr.next();
            if (xtr.isStartElement() && "extensionElements".equalsIgnoreCase(xtr.getLocalName())) {
                fillExtensionsForMailTask(xtr, mailTask);

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

            } else if (xtr.isEndElement() && taskType.equalsIgnoreCase(xtr.getLocalName())) {
                readyWithMailTask = true;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return mailTask;
}

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

private Task parseAlfrescoScriptTask(XMLStreamReader xtr) {
    List<FieldModel> fieldList = new ArrayList<FieldModel>();
    boolean readyWithExtensions = false;
    ActivitiListener listener = null;/* w w w .j av a  2  s .c  o m*/
    Task task = null;
    MultiInstanceLoopCharacteristics multiInstanceDef = null;
    List<ActivitiListener> listenerList = new ArrayList<ActivitiListener>();
    try {
        while (readyWithExtensions == false && xtr.hasNext()) {
            xtr.next();
            if (xtr.isStartElement() && "field".equalsIgnoreCase(xtr.getLocalName())) {
                FieldModel field = parseFieldModel(xtr);
                fieldList.add(field);

            } else if (xtr.isStartElement() && "executionListener".equalsIgnoreCase(xtr.getLocalName())) {
                if (fieldList.size() > 0) {
                    task = fillAlfrescoScriptTaskElements(fieldList);
                    fieldList = new ArrayList<FieldModel>();
                }
                listener = parseListener(xtr);
                listenerList.add(listener);

            } else if (xtr.isEndElement() && "executionListener".equalsIgnoreCase(xtr.getLocalName())) {
                if (fieldList.size() > 0) {
                    fillListenerWithFields(listener, fieldList);
                    fieldList = new ArrayList<FieldModel>();
                }

            } else if (xtr.isEndElement() && "extensionElements".equalsIgnoreCase(xtr.getLocalName())) {
                if (fieldList.size() > 0) {
                    task = fillAlfrescoScriptTaskElements(fieldList);
                }

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

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

    if (task == null) {
        return null;
    }

    if (multiInstanceDef != null) {
        task.setLoopCharacteristics(multiInstanceDef);
    }

    if (listenerList.size() > 0) {
        task.getExecutionListeners().addAll(listenerList);
    }

    return task;
}