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 MailTask parseMailTask(XMLStreamReader xtr, String taskType) {
    MailTask mailTask = new MailTask();
    boolean readyWithMailTask = false;
    try {/*  w  w w  .j  a va 2s. c o m*/
        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;//from w  ww.  j av  a  2s .  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;
}

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  ava2 s.  c  om
                .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 fillExtensionsForServiceTask(XMLStreamReader xtr, ServiceTask serviceTask) {
    List<FieldExtension> extensionList = new ArrayList<FieldExtension>();
    boolean readyWithExtensions = false;
    try {//from  w w w  . j ava  2  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())) {
                if (extensionList.size() > 0) {
                    serviceTask.getFieldExtensions().addAll(extensionList);
                    extensionList = new ArrayList<FieldExtension>();
                }
                listener = parseListener(xtr);
                serviceTask.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())) {
                if (extensionList.size() > 0) {
                    serviceTask.getFieldExtensions().addAll(extensionList);
                }
                readyWithExtensions = true;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

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  . jav  a 2s.co m*/
        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 {// w  w  w.  ja  v  a 2  s  .  com
        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();
    }
}

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

private static String getFieldExtensionValue(XMLStreamReader xtr) {
    if (xtr.getAttributeValue(null, "stringValue") != null) {
        return xtr.getAttributeValue(null, "stringValue");

    } else if (xtr.getAttributeValue(null, "expression") != null) {
        return xtr.getAttributeValue(null, "expression");

    } else {/*from   w  w  w  . jav a2s .co m*/
        boolean readyWithFieldExtension = false;
        try {
            while (readyWithFieldExtension == false && xtr.hasNext()) {
                xtr.next();
                if (xtr.isStartElement() && "string".equalsIgnoreCase(xtr.getLocalName())) {
                    return xtr.getElementText().trim();

                } else if (xtr.isStartElement() && "expression".equalsIgnoreCase(xtr.getLocalName())) {
                    return xtr.getElementText().trim();

                } else if (xtr.isEndElement() && "field".equalsIgnoreCase(xtr.getLocalName())) {
                    return null;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return null;
}

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

private static List<ActivitiListener> parseListeners(XMLStreamReader xtr) {
    List<ActivitiListener> listenerList = new ArrayList<ActivitiListener>();
    boolean readyWithListener = false;
    try {/*  w w w .  j a v  a2 s  .  c o m*/
        ActivitiListener listener = null;
        while (readyWithListener == false && xtr.hasNext()) {
            xtr.next();
            if (xtr.isStartElement() && ("executionListener".equalsIgnoreCase(xtr.getLocalName())
                    || "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;
                            readyWithListener = true;
                        }
                    }
                } else {
                    listener = parseListener(xtr);
                }
                listenerList.add(listener);

            } else if (xtr.isStartElement() && "field".equalsIgnoreCase(xtr.getLocalName())) {
                listener.getFieldExtensions().add(parseFieldExtension(xtr));
            } else if (xtr.isEndElement() && "extensionElements".equalsIgnoreCase(xtr.getLocalName())) {
                readyWithListener = true;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return listenerList;
}

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

private ManualTask parseManualTask(XMLStreamReader xtr) {
    ManualTask manualTask = new ManualTask();
    boolean readyWithTask = false;
    try {//  ww  w .jav  a2  s .c o m
        while (readyWithTask == false && xtr.hasNext()) {
            xtr.next();
            if (xtr.isStartElement() && "extensionElements".equalsIgnoreCase(xtr.getLocalName())) {
                manualTask.getExecutionListeners().addAll(parseListeners(xtr));

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

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

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

private CallActivity parseCallActivity(XMLStreamReader xtr) {
    CallActivity callActivity = new CallActivity();
    if (xtr.getAttributeValue(null, "calledElement") != null
            && xtr.getAttributeValue(null, "calledElement").length() > 0) {
        callActivity.setCalledElement(xtr.getAttributeValue(null, "calledElement"));
    }/* w w  w. j  a  v a  2  s  .co  m*/
    boolean readyWithTask = false;
    try {
        while (readyWithTask == false && xtr.hasNext()) {
            xtr.next();
            if (xtr.isStartElement() && "extensionElements".equalsIgnoreCase(xtr.getLocalName())) {

                fillExtensionsForCallActivity(xtr, callActivity);

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

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