Example usage for javax.xml.stream XMLStreamReader getAttributeValue

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

Introduction

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

Prototype

public String getAttributeValue(String namespaceURI, String localName);

Source Link

Document

Returns the normalized attribute value of the attribute with the namespace and localName If the namespaceURI is null the namespace is not checked for equality

Usage

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

private SequenceFlowModel parseSequenceFlow(XMLStreamReader xtr) {
    SequenceFlowModel sequenceFlow = new SequenceFlowModel();
    sequenceFlow.sourceRef = xtr.getAttributeValue(null, "sourceRef");
    sequenceFlow.targetRef = xtr.getAttributeValue(null, "targetRef");
    sequenceFlow.id = xtr.getAttributeValue(null, "id");
    sequenceFlow.name = xtr.getAttributeValue(null, "name");
    sequenceFlow.conditionExpression = parseSequenceFlowCondition(xtr, sequenceFlow);
    return sequenceFlow;
}

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

private AssociationModel parseAssociation(XMLStreamReader xtr) {

    final AssociationModel association = new AssociationModel();
    association.id = xtr.getAttributeValue(null, "id");
    association.sourceRef = xtr.getAttributeValue(null, "sourceRef");
    association.targetRef = xtr.getAttributeValue(null, "targetRef");

    final String direction = xtr.getAttributeValue(null, "associationDirection");
    for (final AssociationDirection oneDir : AssociationDirection.values()) {
        if (oneDir.getValue().equalsIgnoreCase(direction)) {
            association.associationDirection = oneDir;
        }//www  .  j  a  va2  s.  co m
    }

    return association;
}

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();/*w w  w . j  a v a  2s .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   w  ww  .  j  a  va2s  . 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   ww w . j av  a2s .  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 {//from   w  w  w. j  a  v a 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 static FieldModel parseFieldModel(XMLStreamReader xtr) {
    FieldModel field = new FieldModel();
    field.name = xtr.getAttributeValue(null, "name");
    field.value = getFieldExtensionValue(xtr);
    return field;
}

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

private ServiceTask parseServiceTask(XMLStreamReader xtr) {
    ServiceTask serviceTask = new ServiceTask();
    if (xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, "class") != null) {
        serviceTask.setImplementationType(CLASS_TYPE);
        serviceTask.setImplementation(xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, "class"));

    } else if (xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, "expression") != null) {
        serviceTask.setImplementationType(EXPRESSION_TYPE);
        serviceTask.setImplementation(xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, "expression"));
    } else if (xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, "delegateExpression") != null) {
        serviceTask.setImplementationType(DELEGATE_EXPRESSION_TYPE);
        serviceTask/*from  w w w  . j  av a  2 s  .  c  o  m*/
                .setImplementation(xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, "delegateExpression"));
    }

    if (xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, "resultVariableName") != null) {
        serviceTask.setResultVariableName(
                xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, "resultVariableName"));
    }

    boolean readyWithServiceTask = false;
    try {
        while (readyWithServiceTask == false && xtr.hasNext()) {
            xtr.next();
            if (xtr.isStartElement() && "extensionElements".equalsIgnoreCase(xtr.getLocalName())) {
                fillExtensionsForServiceTask(xtr, serviceTask);

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

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

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

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

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

private static void fillExtensionsForMailTask(XMLStreamReader xtr, MailTask mailTask) {
    List<FieldExtension> extensionList = new ArrayList<FieldExtension>();
    boolean readyWithExtensions = false;
    try {/* w w w.  j  av a 2s  . c om*/
        ActivitiListener listener = null;
        while (readyWithExtensions == false && xtr.hasNext()) {
            xtr.next();
            if (xtr.isStartElement() && "field".equalsIgnoreCase(xtr.getLocalName())) {
                String name = xtr.getAttributeValue(null, "name");
                if ("to".equalsIgnoreCase(name)) {
                    mailTask.setTo(getFieldExtensionValue(xtr));
                } else if ("from".equalsIgnoreCase(name)) {
                    mailTask.setFrom(getFieldExtensionValue(xtr));
                } else if ("cc".equalsIgnoreCase(name)) {
                    mailTask.setCc(getFieldExtensionValue(xtr));
                } else if ("bcc".equalsIgnoreCase(name)) {
                    mailTask.setBcc(getFieldExtensionValue(xtr));
                } else if ("charset".equalsIgnoreCase(name)) {
                    mailTask.setCharset(getFieldExtensionValue(xtr));
                } else if ("subject".equalsIgnoreCase(name)) {
                    mailTask.setSubject(getFieldExtensionValue(xtr));
                } else if ("html".equalsIgnoreCase(name)) {
                    mailTask.setHtml(getFieldExtensionValue(xtr));
                } else if ("text".equalsIgnoreCase(name)) {
                    mailTask.setText(getFieldExtensionValue(xtr));
                }
            } else if (xtr.isStartElement() && "field".equalsIgnoreCase(xtr.getLocalName())) {
                FieldExtension extension = parseFieldExtension(xtr);
                extensionList.add(extension);

            } else if (xtr.isStartElement() && "executionListener".equalsIgnoreCase(xtr.getLocalName())) {
                listener = parseListener(xtr);
                mailTask.getExecutionListeners().add(listener);

            } else if (xtr.isEndElement() && "executionListener".equalsIgnoreCase(xtr.getLocalName())) {
                if (extensionList.size() > 0) {
                    listener.getFieldExtensions().addAll(extensionList);
                    extensionList = new ArrayList<FieldExtension>();
                }
            } else if (xtr.isEndElement() && "extensionElements".equalsIgnoreCase(xtr.getLocalName())) {
                readyWithExtensions = true;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

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

private static void fillExtensionsForCallActivity(XMLStreamReader xtr, CallActivity callActivity) {
    List<FieldExtension> extensionList = new ArrayList<FieldExtension>();
    boolean readyWithExtensions = false;
    try {//from  w w  w .  ja  v  a2 s  . co  m
        ActivitiListener listener = null;
        while (readyWithExtensions == false && xtr.hasNext()) {
            xtr.next();
            if (xtr.isStartElement() && "field".equalsIgnoreCase(xtr.getLocalName())) {
                FieldExtension extension = parseFieldExtension(xtr);
                extensionList.add(extension);

            } else if (xtr.isStartElement() && "executionListener".equalsIgnoreCase(xtr.getLocalName())) {
                listener = parseListener(xtr);
                callActivity.getExecutionListeners().add(listener);

            } else if (xtr.isEndElement() && "executionListener".equalsIgnoreCase(xtr.getLocalName())) {
                if (extensionList.size() > 0) {
                    listener.getFieldExtensions().addAll(extensionList);
                    extensionList = new ArrayList<FieldExtension>();
                }

            } else if (xtr.isStartElement() && "in".equalsIgnoreCase(xtr.getLocalName())) {
                String source = xtr.getAttributeValue(null, "source");
                String sourceExpression = xtr.getAttributeValue(null, "sourceExpression");
                String target = xtr.getAttributeValue(null, "target");
                String targetExpression = xtr.getAttributeValue(null, "targetExpression");
                if ((StringUtils.isNotEmpty(source) || StringUtils.isNotEmpty(sourceExpression))
                        && (StringUtils.isNotEmpty(target) || StringUtils.isNotEmpty(targetExpression))) {

                    IOParameter parameter = new IOParameter();
                    if (StringUtils.isNotEmpty(sourceExpression)) {
                        parameter.setSourceExpression(sourceExpression);
                    } else {
                        parameter.setSource(source);
                    }

                    if (StringUtils.isNotEmpty(targetExpression)) {
                        parameter.setTargetExpression(targetExpression);
                    } else {
                        parameter.setTarget(target);
                    }
                    callActivity.getInParameters().add(parameter);
                }

            } else if (xtr.isStartElement() && "out".equalsIgnoreCase(xtr.getLocalName())) {
                String source = xtr.getAttributeValue(null, "source");
                String sourceExpression = xtr.getAttributeValue(null, "sourceExpression");
                String target = xtr.getAttributeValue(null, "target");
                String targetExpression = xtr.getAttributeValue(null, "targetExpression");
                if ((StringUtils.isNotEmpty(source) || StringUtils.isNotEmpty(sourceExpression))
                        && (StringUtils.isNotEmpty(target) || StringUtils.isNotEmpty(targetExpression))) {

                    IOParameter parameter = new IOParameter();
                    if (StringUtils.isNotEmpty(sourceExpression)) {
                        parameter.setSourceExpression(sourceExpression);
                    } else {
                        parameter.setSource(source);
                    }

                    if (StringUtils.isNotEmpty(targetExpression)) {
                        parameter.setTargetExpression(targetExpression);
                    } else {
                        parameter.setTarget(target);
                    }
                    callActivity.getOutParameters().add(parameter);
                }

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