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.flowable.bpmn.converter.parser.SubProcessParser.java

public void parse(XMLStreamReader xtr, List<SubProcess> activeSubProcessList, Process activeProcess) {
    SubProcess subProcess = null;/*from ww w .j  a va 2s.  c  o  m*/
    if (ELEMENT_TRANSACTION.equalsIgnoreCase(xtr.getLocalName())) {
        subProcess = new Transaction();

    } else if (ELEMENT_ADHOC_SUBPROCESS.equalsIgnoreCase(xtr.getLocalName())) {
        AdhocSubProcess adhocSubProcess = new AdhocSubProcess();
        String orderingAttributeValue = xtr.getAttributeValue(null, ATTRIBUTE_ORDERING);
        if (StringUtils.isNotEmpty(orderingAttributeValue)) {
            adhocSubProcess.setOrdering(orderingAttributeValue);
        }

        if (ATTRIBUTE_VALUE_FALSE
                .equalsIgnoreCase(xtr.getAttributeValue(null, ATTRIBUTE_CANCEL_REMAINING_INSTANCES))) {
            adhocSubProcess.setCancelRemainingInstances(false);
        }

        subProcess = adhocSubProcess;

    } else if (ATTRIBUTE_VALUE_TRUE.equalsIgnoreCase(xtr.getAttributeValue(null, ATTRIBUTE_TRIGGERED_BY))) {
        subProcess = new EventSubProcess();

    } else {
        subProcess = new SubProcess();
    }

    BpmnXMLUtil.addXMLLocation(subProcess, xtr);
    activeSubProcessList.add(subProcess);

    subProcess.setId(xtr.getAttributeValue(null, ATTRIBUTE_ID));
    subProcess.setName(xtr.getAttributeValue(null, ATTRIBUTE_NAME));

    boolean async = false;
    String asyncString = BpmnXMLUtil.getAttributeValue(ATTRIBUTE_ACTIVITY_ASYNCHRONOUS, xtr);
    if (ATTRIBUTE_VALUE_TRUE.equalsIgnoreCase(asyncString)) {
        async = true;
    }

    boolean notExclusive = false;
    String exclusiveString = BpmnXMLUtil.getAttributeValue(ATTRIBUTE_ACTIVITY_EXCLUSIVE, xtr);
    if (ATTRIBUTE_VALUE_FALSE.equalsIgnoreCase(exclusiveString)) {
        notExclusive = true;
    }

    boolean forCompensation = false;
    String compensationString = xtr.getAttributeValue(null, ATTRIBUTE_ACTIVITY_ISFORCOMPENSATION);
    if (ATTRIBUTE_VALUE_TRUE.equalsIgnoreCase(compensationString)) {
        forCompensation = true;
    }

    subProcess.setAsynchronous(async);
    subProcess.setNotExclusive(notExclusive);
    subProcess.setForCompensation(forCompensation);
    if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_DEFAULT))) {
        subProcess.setDefaultFlow(xtr.getAttributeValue(null, ATTRIBUTE_DEFAULT));
    }

    if (activeSubProcessList.size() > 1) {
        SubProcess parentSubProcess = activeSubProcessList.get(activeSubProcessList.size() - 2);
        parentSubProcess.addFlowElement(subProcess);

    } else {
        activeProcess.addFlowElement(subProcess);
    }
}

From source file:org.flowable.bpmn.converter.ScriptTaskXMLConverter.java

@Override
protected BaseElement convertXMLToElement(XMLStreamReader xtr, BpmnModel model) throws Exception {
    ScriptTask scriptTask = new ScriptTask();
    BpmnXMLUtil.addXMLLocation(scriptTask, xtr);
    scriptTask.setScriptFormat(xtr.getAttributeValue(null, ATTRIBUTE_TASK_SCRIPT_FORMAT));
    scriptTask.setResultVariable(BpmnXMLUtil.getAttributeValue(ATTRIBUTE_TASK_SCRIPT_RESULTVARIABLE, xtr));
    if (StringUtils.isEmpty(scriptTask.getResultVariable())) {
        scriptTask.setResultVariable(BpmnXMLUtil.getAttributeValue(ATTRIBUTE_TASK_SERVICE_RESULTVARIABLE, xtr));
    }//  www .ja  va2  s. c  om
    String autoStoreVariables = BpmnXMLUtil.getAttributeValue(ATTRIBUTE_TASK_SCRIPT_AUTO_STORE_VARIABLE, xtr);
    if (StringUtils.isNotEmpty(autoStoreVariables)) {
        scriptTask.setAutoStoreVariables(Boolean.valueOf(autoStoreVariables));
    }
    parseChildElements(getXMLElementName(), scriptTask, childParserMap, model, xtr);
    return scriptTask;
}

From source file:org.flowable.bpmn.converter.SendTaskXMLConverter.java

@Override
protected BaseElement convertXMLToElement(XMLStreamReader xtr, BpmnModel model) throws Exception {
    SendTask sendTask = new SendTask();
    BpmnXMLUtil.addXMLLocation(sendTask, xtr);
    sendTask.setType(BpmnXMLUtil.getAttributeValue(ATTRIBUTE_TYPE, xtr));

    if ("##WebService".equals(xtr.getAttributeValue(null, ATTRIBUTE_TASK_IMPLEMENTATION))) {
        sendTask.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_WEBSERVICE);
        sendTask.setOperationRef(//from  w  ww  .  java 2  s.  co m
                parseOperationRef(xtr.getAttributeValue(null, ATTRIBUTE_TASK_OPERATION_REF), model));
    }

    parseChildElements(getXMLElementName(), sendTask, model, xtr);

    return sendTask;
}

From source file:org.flowable.bpmn.converter.SequenceFlowXMLConverter.java

@Override
protected BaseElement convertXMLToElement(XMLStreamReader xtr, BpmnModel model) throws Exception {
    SequenceFlow sequenceFlow = new SequenceFlow();
    BpmnXMLUtil.addXMLLocation(sequenceFlow, xtr);
    sequenceFlow.setSourceRef(xtr.getAttributeValue(null, ATTRIBUTE_FLOW_SOURCE_REF));
    sequenceFlow.setTargetRef(xtr.getAttributeValue(null, ATTRIBUTE_FLOW_TARGET_REF));
    sequenceFlow.setName(xtr.getAttributeValue(null, ATTRIBUTE_NAME));
    sequenceFlow.setSkipExpression(xtr.getAttributeValue(null, ATTRIBUTE_FLOW_SKIP_EXPRESSION));

    parseChildElements(getXMLElementName(), sequenceFlow, model, xtr);

    return sequenceFlow;
}

From source file:org.flowable.bpmn.converter.ServiceTaskXMLConverter.java

@Override
protected BaseElement convertXMLToElement(XMLStreamReader xtr, BpmnModel model) throws Exception {
    ServiceTask serviceTask = new ServiceTask();
    BpmnXMLUtil.addXMLLocation(serviceTask, xtr);
    if (StringUtils.isNotEmpty(BpmnXMLUtil.getAttributeValue(ATTRIBUTE_TASK_SERVICE_CLASS, xtr))) {
        serviceTask.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_CLASS);
        serviceTask.setImplementation(BpmnXMLUtil.getAttributeValue(ATTRIBUTE_TASK_SERVICE_CLASS, xtr));

    } else if (StringUtils.isNotEmpty(BpmnXMLUtil.getAttributeValue(ATTRIBUTE_TASK_SERVICE_EXPRESSION, xtr))) {
        serviceTask.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_EXPRESSION);
        serviceTask.setImplementation(BpmnXMLUtil.getAttributeValue(ATTRIBUTE_TASK_SERVICE_EXPRESSION, xtr));

    } else if (StringUtils
            .isNotEmpty(BpmnXMLUtil.getAttributeValue(ATTRIBUTE_TASK_SERVICE_DELEGATEEXPRESSION, xtr))) {
        serviceTask.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION);
        serviceTask.setImplementation(// w w  w.j a va  2 s  .com
                BpmnXMLUtil.getAttributeValue(ATTRIBUTE_TASK_SERVICE_DELEGATEEXPRESSION, xtr));

    } else if ("##WebService".equals(xtr.getAttributeValue(null, ATTRIBUTE_TASK_IMPLEMENTATION))) {
        serviceTask.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_WEBSERVICE);
        serviceTask.setOperationRef(
                parseOperationRef(xtr.getAttributeValue(null, ATTRIBUTE_TASK_OPERATION_REF), model));
    }

    serviceTask
            .setResultVariableName(BpmnXMLUtil.getAttributeValue(ATTRIBUTE_TASK_SERVICE_RESULTVARIABLE, xtr));
    if (StringUtils.isEmpty(serviceTask.getResultVariableName())) {
        serviceTask.setResultVariableName(BpmnXMLUtil.getAttributeValue("resultVariable", xtr));
    }

    serviceTask.setType(BpmnXMLUtil.getAttributeValue(ATTRIBUTE_TYPE, xtr));
    serviceTask.setExtensionId(BpmnXMLUtil.getAttributeValue(ATTRIBUTE_TASK_SERVICE_EXTENSIONID, xtr));

    if (StringUtils.isNotEmpty(BpmnXMLUtil.getAttributeValue(ATTRIBUTE_TASK_SERVICE_SKIP_EXPRESSION, xtr))) {
        serviceTask
                .setSkipExpression(BpmnXMLUtil.getAttributeValue(ATTRIBUTE_TASK_SERVICE_SKIP_EXPRESSION, xtr));
    }
    parseChildElements(getXMLElementName(), serviceTask, model, xtr);

    return serviceTask;
}

From source file:org.flowable.bpmn.converter.StartEventXMLConverter.java

@Override
protected BaseElement convertXMLToElement(XMLStreamReader xtr, BpmnModel model) throws Exception {
    String formKey = BpmnXMLUtil.getAttributeValue(ATTRIBUTE_FORM_FORMKEY, xtr);
    StartEvent startEvent = null;//from www  . ja va 2 s  . co  m
    if (StringUtils.isNotEmpty(formKey)) {
        if (model.getStartEventFormTypes() != null && model.getStartEventFormTypes().contains(formKey)) {
            startEvent = new AlfrescoStartEvent();
        }
    }
    if (startEvent == null) {
        startEvent = new StartEvent();
    }

    BpmnXMLUtil.addXMLLocation(startEvent, xtr);
    startEvent.setInitiator(BpmnXMLUtil.getAttributeValue(ATTRIBUTE_EVENT_START_INITIATOR, xtr));
    boolean interrupting = true;
    String interruptingAttribute = xtr.getAttributeValue(null, ATTRIBUTE_EVENT_START_INTERRUPTING);
    if (ATTRIBUTE_VALUE_FALSE.equalsIgnoreCase(interruptingAttribute)) {
        interrupting = false;
    }

    startEvent.setInterrupting(interrupting);
    startEvent.setFormKey(formKey);

    parseChildElements(getXMLElementName(), startEvent, model, xtr);

    return startEvent;
}

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

protected void setImplementation(XMLStreamReader xtr, AbstractFlowableHttpHandler handler) {
    if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_CLASS))) {
        handler.setImplementation(xtr.getAttributeValue(null, ATTRIBUTE_CLASS));
        handler.setImplementationType(IMPLEMENTATION_TYPE_CLASS);

    } else if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_DELEGATE_EXPRESSION))) {
        handler.setImplementation(xtr.getAttributeValue(null, ATTRIBUTE_DELEGATE_EXPRESSION));
        handler.setImplementationType(IMPLEMENTATION_TYPE_DELEGATEEXPRESSION);
    }/*  w ww .  ja  v  a 2 s  .c  o  m*/
}

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

@Override
protected CmmnElement convert(XMLStreamReader xtr, ConversionHelper conversionHelper) {
    Case caze = new Case();
    caze.setName(xtr.getAttributeValue(null, CmmnXmlConstants.ATTRIBUTE_NAME));
    caze.setInitiatorVariableName(xtr.getAttributeValue(CmmnXmlConstants.FLOWABLE_EXTENSIONS_NAMESPACE,
            CmmnXmlConstants.ATTRIBUTE_INITIATOR_VARIABLE_NAME));

    String candidateUsersString = CmmnXmlUtil.getAttributeValue(CmmnXmlConstants.ATTRIBUTE_CASE_CANDIDATE_USERS,
            xtr);/*from w w  w  .  jav a2s .com*/
    if (StringUtils.isNotEmpty(candidateUsersString)) {
        List<String> candidateUsers = CmmnXmlUtil.parseDelimitedList(candidateUsersString);
        caze.setCandidateStarterUsers(candidateUsers);
    }

    String candidateGroupsString = CmmnXmlUtil
            .getAttributeValue(CmmnXmlConstants.ATTRIBUTE_CASE_CANDIDATE_GROUPS, xtr);
    if (StringUtils.isNotEmpty(candidateGroupsString)) {
        List<String> candidateGroups = CmmnXmlUtil.parseDelimitedList(candidateGroupsString);
        caze.setCandidateStarterGroups(candidateGroups);
    }

    conversionHelper.getCmmnModel().addCase(caze);
    conversionHelper.setCurrentCase(caze);
    return caze;
}

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

@Override
protected CmmnElement convert(XMLStreamReader xtr, ConversionHelper conversionHelper) {
    CmmnModel model = conversionHelper.getCmmnModel();
    model.setId(xtr.getAttributeValue(null, CmmnXmlConstants.ATTRIBUTE_ID));
    model.setName(xtr.getAttributeValue(null, CmmnXmlConstants.ATTRIBUTE_NAME));
    model.setExpressionLanguage(xtr.getAttributeValue(null, CmmnXmlConstants.ATTRIBUTE_EXPRESSION_LANGUAGE));
    model.setExporter(xtr.getAttributeValue(null, CmmnXmlConstants.ATTRIBUTE_EXPORTER));
    model.setExporterVersion(xtr.getAttributeValue(null, CmmnXmlConstants.ATTRIBUTE_EXPORTER_VERSION));
    model.setAuthor(xtr.getAttributeValue(null, CmmnXmlConstants.ATTRIBUTE_AUTHOR));
    model.setTargetNamespace(xtr.getAttributeValue(null, CmmnXmlConstants.ATTRIBUTE_TARGET_NAMESPACE));

    String creationDateString = xtr.getAttributeValue(null, CmmnXmlConstants.ATTRIBUTE_CREATION_DATE);
    if (StringUtils.isNotEmpty(creationDateString)) {
        try {//  www  .j  av  a  2s. c o m
            Date creationDate = new SimpleDateFormat(XSD_DATETIME_FORMAT).parse(creationDateString);
            model.setCreationDate(creationDate);
        } catch (ParseException e) {
            LOGGER.warn("Ignoring creationDate attribute: invalid date format", e);
        }
    }

    return null;
}

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

@Override
protected CmmnElement convert(XMLStreamReader xtr, ConversionHelper conversionHelper) {
    try {/*from   w ww  .j a v  a 2s. com*/
        String textFormat = xtr.getAttributeValue(null, CmmnXmlConstants.ATTRIBUTE_TEXT_FORMAT);
        if (StringUtils.isEmpty(textFormat)) {
            textFormat = "text/plain";
        }

        String documentation = xtr.getElementText();
        if (StringUtils.isNotEmpty(documentation)) {
            conversionHelper.getCurrentCmmnElement().setDocumentation(documentation);
            conversionHelper.getCurrentCmmnElement().setDocumentationTextFormat(textFormat);
        }

        return null;

    } catch (Exception e) {
        throw new CmmnXMLException("Error reading documentation element", e);
    }
}