Example usage for javax.xml.stream XMLStreamReader isEndElement

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

Introduction

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

Prototype

public boolean isEndElement();

Source Link

Document

Returns true if the cursor points to an end tag (otherwise false)

Usage

From source file:org.deegree.style.se.parser.GraphicSymbologyParser.java

private Pair<Mark, Continuation<Mark>> parseMark(XMLStreamReader in) throws XMLStreamException {
    in.require(START_ELEMENT, null, "Mark");

    Mark base = new Mark();
    Continuation<Mark> contn = null;

    in.nextTag();//from  w ww  .ja va 2 s  .c  om

    while (!(in.isEndElement() && in.getLocalName().equals("Mark"))) {
        if (in.isEndElement()) {
            in.nextTag();
        }

        if (in.getLocalName().equals("WellKnownName")) {
            String wkn = in.getElementText();
            try {
                base.wellKnown = SimpleMark.valueOf(wkn.toUpperCase());
            } catch (IllegalArgumentException e) {
                LOG.warn("Specified unsupported WellKnownName of '{}', using square instead.", wkn);
                base.wellKnown = SimpleMark.SQUARE;
            }
        } else
            sym: if (in.getLocalName().equals("OnlineResource") || in.getLocalName().equals("InlineContent")) {
                LOG.debug("Loading mark from external file.");
                Triple<InputStream, String, Continuation<StringBuffer>> pair = getOnlineResourceOrInlineContent(
                        in);
                if (pair == null) {
                    in.nextTag();
                    break sym;
                }
                InputStream is = pair.first;
                in.nextTag();

                in.require(START_ELEMENT, null, "Format");
                String format = in.getElementText();
                in.require(END_ELEMENT, null, "Format");

                in.nextTag();
                if (in.getLocalName().equals("MarkIndex")) {
                    base.markIndex = Integer.parseInt(in.getElementText());
                }

                if (is != null) {
                    try {
                        java.awt.Font font = null;
                        if (format.equalsIgnoreCase("ttf")) {
                            font = createFont(TRUETYPE_FONT, is);
                        }
                        if (format.equalsIgnoreCase("type1")) {
                            font = createFont(TYPE1_FONT, is);
                        }

                        if (format.equalsIgnoreCase("svg")) {
                            base.shape = ShapeHelper.getShapeFromSvg(is, pair.second);
                        }

                        if (font == null && base.shape == null) {
                            LOG.warn("Mark was not loaded, because the format '{}' is not supported.", format);
                            break sym;
                        }

                        if (font != null && base.markIndex >= font.getNumGlyphs() - 1) {
                            LOG.warn("The font only contains {} glyphs, but the index given was {}.",
                                    font.getNumGlyphs(), base.markIndex);
                            break sym;
                        }

                        base.font = font;
                    } catch (FontFormatException e) {
                        LOG.debug("Stack trace:", e);
                        LOG.warn("The file was not a valid '{}' file: '{}'", format, e.getLocalizedMessage());
                    } catch (IOException e) {
                        LOG.debug("Stack trace:", e);
                        LOG.warn("The file could not be read: '{}'.", e.getLocalizedMessage());
                    } finally {
                        closeQuietly(is);
                    }
                }
            } else if (in.getLocalName().equals("Fill")) {
                final Pair<Fill, Continuation<Fill>> fill = context.fillParser.parseFill(in);
                base.fill = fill.first;
                if (fill.second != null) {
                    contn = new Continuation<Mark>(contn) {
                        @Override
                        public void updateStep(Mark base, Feature f, XPathEvaluator<Feature> evaluator) {
                            fill.second.evaluate(base.fill, f, evaluator);
                        }
                    };
                }
            } else if (in.getLocalName().equals("Stroke")) {
                final Pair<Stroke, Continuation<Stroke>> stroke = context.strokeParser.parseStroke(in);
                base.stroke = stroke.first;
                if (stroke.second != null) {
                    contn = new Continuation<Mark>(contn) {
                        @Override
                        public void updateStep(Mark base, Feature f, XPathEvaluator<Feature> evaluator) {
                            stroke.second.evaluate(base.stroke, f, evaluator);
                        }
                    };
                }
            } else if (in.isStartElement()) {
                Location loc = in.getLocation();
                LOG.error("Found unknown element '{}' at line {}, column {}, skipping.",
                        new Object[] { in.getLocalName(), loc.getLineNumber(), loc.getColumnNumber() });
                skipElement(in);
            }
    }

    in.require(END_ELEMENT, null, "Mark");

    return new Pair<Mark, Continuation<Mark>>(base, contn);
}

From source file:org.deegree.style.se.parser.GraphicSymbologyParser.java

private Triple<BufferedImage, String, Continuation<List<BufferedImage>>> parseExternalGraphic(
        final XMLStreamReader in) throws IOException, XMLStreamException {
    // TODO color replacement

    in.require(START_ELEMENT, null, "ExternalGraphic");

    String format = null;/*  w  w w. j a  v a2 s  . c  o  m*/
    BufferedImage img = null;
    String url = null;
    Triple<InputStream, String, Continuation<StringBuffer>> pair = null;
    Continuation<List<BufferedImage>> contn = null; // needs to be list to be updateable by reference...

    while (!(in.isEndElement() && in.getLocalName().equals("ExternalGraphic"))) {
        in.nextTag();

        if (in.getLocalName().equals("Format")) {
            format = in.getElementText();
        } else if (in.getLocalName().equals("OnlineResource") || in.getLocalName().equals("InlineContent")) {
            pair = getOnlineResourceOrInlineContent(in);
        } else if (in.isStartElement()) {
            Location loc = in.getLocation();
            LOG.error("Found unknown element '{}' at line {}, column {}, skipping.",
                    new Object[] { in.getLocalName(), loc.getLineNumber(), loc.getColumnNumber() });
            skipElement(in);
        }
    }

    try {
        if (pair != null) {
            if (pair.first != null && format != null && (format.toLowerCase().indexOf("svg") == -1)) {
                img = ImageIO.read(pair.first);
            }
            url = pair.second;

            final Continuation<StringBuffer> sbcontn = pair.third;

            if (pair.third != null) {
                final LinkedHashMap<String, BufferedImage> cache = new LinkedHashMap<String, BufferedImage>(
                        256) {
                    private static final long serialVersionUID = -6847956873232942891L;

                    @Override
                    protected boolean removeEldestEntry(Map.Entry<String, BufferedImage> eldest) {
                        return size() > 256; // yeah, hardcoded max size... TODO
                    }
                };
                contn = new Continuation<List<BufferedImage>>() {
                    @Override
                    public void updateStep(List<BufferedImage> base, Feature f,
                            XPathEvaluator<Feature> evaluator) {
                        StringBuffer sb = new StringBuffer();
                        sbcontn.evaluate(sb, f, evaluator);
                        String file = sb.toString();
                        if (cache.containsKey(file)) {
                            base.add(cache.get(file));
                            return;
                        }
                        try {
                            BufferedImage i;
                            if (context.location != null) {
                                i = ImageIO.read(context.location.resolve(file));
                            } else {
                                i = ImageIO.read(resolve(file, in));
                            }
                            base.add(i);
                            cache.put(file, i);
                        } catch (MalformedURLException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                    }
                };
            }
        }
    } finally {
        if (pair != null) {
            try {
                pair.first.close();
            } catch (Exception e) {
                LOG.trace("Stack trace when closing input stream:", e);
            }
        }
    }

    return new Triple<BufferedImage, String, Continuation<List<BufferedImage>>>(img, url, contn);
}

From source file:org.eclipse.smila.connectivity.framework.agent.jobfile.JobFileReader.java

/**
 * /*from  w w w. ja v a 2s.c  om*/
 * @param staxReader
 *          source XML stream
 * @param tagName
 *          tag name
 * @return true if we are currently at a end tag with the specified name
 */
private boolean isEndTag(final XMLStreamReader staxReader, final String tagName) {
    return staxReader.isEndElement() && tagName.equals(staxReader.getLocalName());
}

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

@SuppressWarnings("unchecked")
protected ExtensionElement parseExtensionElement(XMLStreamReader xtr) throws Exception {
    ExtensionElement extensionElement = new ExtensionElement();
    extensionElement.setName(xtr.getLocalName());
    if (StringUtils.isNotEmpty(xtr.getNamespaceURI())) {
        extensionElement.setNamespace(xtr.getNamespaceURI());
    }// w  w  w . j  a v a  2  s  .c om
    if (StringUtils.isNotEmpty(xtr.getPrefix())) {
        extensionElement.setNamespacePrefix(xtr.getPrefix());
    }

    BpmnXMLUtil.addCustomAttributes(xtr, extensionElement, defaultElementAttributes);

    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()) {
            ExtensionElement childExtensionElement = parseExtensionElement(xtr);
            extensionElement.addChildElement(childExtensionElement);
        } else if (xtr.isEndElement() && extensionElement.getName().equalsIgnoreCase(xtr.getLocalName())) {
            readyWithExtensionElement = true;
        }
    }
    return extensionElement;
}

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

public BpmnModel convertToBpmnModel(XMLStreamReader xtr) {
    BpmnModel model = new BpmnModel();
    model.setStartEventFormTypes(startEventFormTypes);
    model.setUserTaskFormTypes(userTaskFormTypes);
    try {/*from w  w w . java  2  s . co  m*/
        Process activeProcess = null;
        List<SubProcess> activeSubProcessList = new ArrayList<SubProcess>();
        while (xtr.hasNext()) {
            try {
                xtr.next();
            } catch (Exception e) {
                LOGGER.debug("Error reading XML document", e);
                throw new XMLException("Error reading XML", e);
            }

            if (xtr.isEndElement() && (ELEMENT_SUBPROCESS.equals(xtr.getLocalName())
                    || ELEMENT_TRANSACTION.equals(xtr.getLocalName())
                    || ELEMENT_ADHOC_SUBPROCESS.equals(xtr.getLocalName()))) {

                activeSubProcessList.remove(activeSubProcessList.size() - 1);
            }

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

            if (ELEMENT_DEFINITIONS.equals(xtr.getLocalName())) {
                definitionsParser.parse(xtr, model);

            } else if (ELEMENT_RESOURCE.equals(xtr.getLocalName())) {
                resourceParser.parse(xtr, model);

            } else if (ELEMENT_SIGNAL.equals(xtr.getLocalName())) {
                signalParser.parse(xtr, model);

            } else if (ELEMENT_MESSAGE.equals(xtr.getLocalName())) {
                messageParser.parse(xtr, model);

            } else if (ELEMENT_ERROR.equals(xtr.getLocalName())) {

                if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_ID))) {
                    model.addError(xtr.getAttributeValue(null, ATTRIBUTE_ID),
                            xtr.getAttributeValue(null, ATTRIBUTE_ERROR_CODE));
                }

            } else if (ELEMENT_IMPORT.equals(xtr.getLocalName())) {
                importParser.parse(xtr, model);

            } else if (ELEMENT_ITEM_DEFINITION.equals(xtr.getLocalName())) {
                itemDefinitionParser.parse(xtr, model);

            } else if (ELEMENT_DATA_STORE.equals(xtr.getLocalName())) {
                dataStoreParser.parse(xtr, model);

            } else if (ELEMENT_INTERFACE.equals(xtr.getLocalName())) {
                interfaceParser.parse(xtr, model);

            } else if (ELEMENT_IOSPECIFICATION.equals(xtr.getLocalName())) {
                ioSpecificationParser.parseChildElement(xtr, activeProcess, model);

            } else if (ELEMENT_PARTICIPANT.equals(xtr.getLocalName())) {
                participantParser.parse(xtr, model);

            } else if (ELEMENT_MESSAGE_FLOW.equals(xtr.getLocalName())) {
                messageFlowParser.parse(xtr, model);

            } else if (ELEMENT_PROCESS.equals(xtr.getLocalName())) {

                Process process = processParser.parse(xtr, model);
                if (process != null) {
                    activeProcess = process;
                }

            } else if (ELEMENT_POTENTIAL_STARTER.equals(xtr.getLocalName())) {
                potentialStarterParser.parse(xtr, activeProcess);

            } else if (ELEMENT_LANE.equals(xtr.getLocalName())) {
                laneParser.parse(xtr, activeProcess, model);

            } else if (ELEMENT_DOCUMENTATION.equals(xtr.getLocalName())) {

                BaseElement parentElement = null;
                if (!activeSubProcessList.isEmpty()) {
                    parentElement = activeSubProcessList.get(activeSubProcessList.size() - 1);
                } else if (activeProcess != null) {
                    parentElement = activeProcess;
                }
                documentationParser.parseChildElement(xtr, parentElement, model);

            } else if (activeProcess == null && ELEMENT_TEXT_ANNOTATION.equals(xtr.getLocalName())) {
                String elementId = xtr.getAttributeValue(null, ATTRIBUTE_ID);
                TextAnnotation textAnnotation = (TextAnnotation) new TextAnnotationXMLConverter()
                        .convertXMLToElement(xtr, model);
                textAnnotation.setId(elementId);
                model.getGlobalArtifacts().add(textAnnotation);

            } else if (activeProcess == null && ELEMENT_ASSOCIATION.equals(xtr.getLocalName())) {
                String elementId = xtr.getAttributeValue(null, ATTRIBUTE_ID);
                Association association = (Association) new AssociationXMLConverter().convertXMLToElement(xtr,
                        model);
                association.setId(elementId);
                model.getGlobalArtifacts().add(association);

            } else if (ELEMENT_EXTENSIONS.equals(xtr.getLocalName())) {
                extensionElementsParser.parse(xtr, activeSubProcessList, activeProcess, model);

            } else if (ELEMENT_SUBPROCESS.equals(xtr.getLocalName())
                    || ELEMENT_TRANSACTION.equals(xtr.getLocalName())
                    || ELEMENT_ADHOC_SUBPROCESS.equals(xtr.getLocalName())) {
                subProcessParser.parse(xtr, activeSubProcessList, activeProcess);

            } else if (ELEMENT_COMPLETION_CONDITION.equals(xtr.getLocalName())) {
                if (!activeSubProcessList.isEmpty()) {
                    SubProcess subProcess = activeSubProcessList.get(activeSubProcessList.size() - 1);
                    if (subProcess instanceof AdhocSubProcess) {
                        AdhocSubProcess adhocSubProcess = (AdhocSubProcess) subProcess;
                        adhocSubProcess.setCompletionCondition(xtr.getElementText());
                    }
                }

            } else if (ELEMENT_DI_SHAPE.equals(xtr.getLocalName())) {
                bpmnShapeParser.parse(xtr, model);

            } else if (ELEMENT_DI_EDGE.equals(xtr.getLocalName())) {
                bpmnEdgeParser.parse(xtr, model);

            } else {

                if (!activeSubProcessList.isEmpty()
                        && ELEMENT_MULTIINSTANCE.equalsIgnoreCase(xtr.getLocalName())) {

                    multiInstanceParser.parseChildElement(xtr,
                            activeSubProcessList.get(activeSubProcessList.size() - 1), model);

                } else if (convertersToBpmnMap.containsKey(xtr.getLocalName())) {
                    if (activeProcess != null) {
                        BaseBpmnXMLConverter converter = convertersToBpmnMap.get(xtr.getLocalName());
                        converter.convertToBpmnModel(xtr, model, activeProcess, activeSubProcessList);
                    }
                }
            }
        }

        for (Process process : model.getProcesses()) {
            for (Pool pool : model.getPools()) {
                if (process.getId().equals(pool.getProcessRef())) {
                    pool.setExecutable(process.isExecutable());
                }
            }
            processFlowElements(process.getFlowElements(), process);
        }

    } catch (XMLException e) {
        throw e;

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

From source file:org.flowable.bpmn.converter.child.DataAssociationParser.java

public static void parseDataAssociation(DataAssociation dataAssociation, String elementName,
        XMLStreamReader xtr) {
    boolean readyWithDataAssociation = false;
    Assignment assignment = null;// www  .j  a  v  a2s  . co  m
    try {

        dataAssociation.setId(xtr.getAttributeValue(null, "id"));

        while (readyWithDataAssociation == false && xtr.hasNext()) {
            xtr.next();
            if (xtr.isStartElement() && ELEMENT_SOURCE_REF.equals(xtr.getLocalName())) {
                String sourceRef = xtr.getElementText();
                if (StringUtils.isNotEmpty(sourceRef)) {
                    dataAssociation.setSourceRef(sourceRef.trim());
                }

            } else if (xtr.isStartElement() && ELEMENT_TARGET_REF.equals(xtr.getLocalName())) {
                String targetRef = xtr.getElementText();
                if (StringUtils.isNotEmpty(targetRef)) {
                    dataAssociation.setTargetRef(targetRef.trim());
                }

            } else if (xtr.isStartElement() && ELEMENT_TRANSFORMATION.equals(xtr.getLocalName())) {
                String transformation = xtr.getElementText();
                if (StringUtils.isNotEmpty(transformation)) {
                    dataAssociation.setTransformation(transformation.trim());
                }

            } else if (xtr.isStartElement() && ELEMENT_ASSIGNMENT.equals(xtr.getLocalName())) {
                assignment = new Assignment();
                BpmnXMLUtil.addXMLLocation(assignment, xtr);

            } else if (xtr.isStartElement() && ELEMENT_FROM.equals(xtr.getLocalName())) {
                String from = xtr.getElementText();
                if (assignment != null && StringUtils.isNotEmpty(from)) {
                    assignment.setFrom(from.trim());
                }

            } else if (xtr.isStartElement() && ELEMENT_TO.equals(xtr.getLocalName())) {
                String to = xtr.getElementText();
                if (assignment != null && StringUtils.isNotEmpty(to)) {
                    assignment.setTo(to.trim());
                }

            } else if (xtr.isEndElement() && ELEMENT_ASSIGNMENT.equals(xtr.getLocalName())) {
                if (StringUtils.isNotEmpty(assignment.getFrom())
                        && StringUtils.isNotEmpty(assignment.getTo())) {
                    dataAssociation.getAssignments().add(assignment);
                }

            } else if (xtr.isEndElement() && elementName.equals(xtr.getLocalName())) {
                readyWithDataAssociation = true;
            }
        }
    } catch (Exception e) {
        LOGGER.warn("Error parsing data association child elements", e);
    }
}

From source file:org.flowable.bpmn.converter.child.FieldExtensionParser.java

public void parseChildElement(XMLStreamReader xtr, BaseElement parentElement, BpmnModel model)
        throws Exception {

    if (!accepts(parentElement))
        return;//from   w  ww  . j av  a 2s .  co  m

    FieldExtension extension = new FieldExtension();
    BpmnXMLUtil.addXMLLocation(extension, xtr);
    extension.setFieldName(xtr.getAttributeValue(null, ATTRIBUTE_FIELD_NAME));

    if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_FIELD_STRING))) {
        extension.setStringValue(xtr.getAttributeValue(null, ATTRIBUTE_FIELD_STRING));

    } else if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_FIELD_EXPRESSION))) {
        extension.setExpression(xtr.getAttributeValue(null, ATTRIBUTE_FIELD_EXPRESSION));

    } else {
        boolean readyWithFieldExtension = false;
        try {
            while (readyWithFieldExtension == false && xtr.hasNext()) {
                xtr.next();
                if (xtr.isStartElement() && ELEMENT_FIELD_STRING.equalsIgnoreCase(xtr.getLocalName())) {
                    extension.setStringValue(xtr.getElementText().trim());

                } else if (xtr.isStartElement()
                        && ATTRIBUTE_FIELD_EXPRESSION.equalsIgnoreCase(xtr.getLocalName())) {
                    extension.setExpression(xtr.getElementText().trim());

                } else if (xtr.isEndElement() && getElementName().equalsIgnoreCase(xtr.getLocalName())) {
                    readyWithFieldExtension = true;
                }
            }
        } catch (Exception e) {
            LOGGER.warn("Error parsing field extension child elements", e);
        }
    }

    if (parentElement instanceof FlowableListener) {
        ((FlowableListener) parentElement).getFieldExtensions().add(extension);
    } else if (parentElement instanceof ServiceTask) {
        ((ServiceTask) parentElement).getFieldExtensions().add(extension);
    } else {
        ((SendTask) parentElement).getFieldExtensions().add(extension);
    }
}

From source file:org.flowable.bpmn.converter.child.FlowableCollectionParser.java

@Override
public void parseChildElement(XMLStreamReader xtr, BaseElement parentElement, BpmnModel model)
        throws Exception {
    if (!(parentElement instanceof MultiInstanceLoopCharacteristics)) {
        return;// w  w  w.j  a  v a 2s.c  o  m
    }

    MultiInstanceLoopCharacteristics multiInstanceLoopCharacteristics = (MultiInstanceLoopCharacteristics) parentElement;

    CollectionHandler collectionHandler = null;

    if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_MULTIINSTANCE_COLLECTION_CLASS))) {
        collectionHandler = new CollectionHandler();
        collectionHandler
                .setImplementation(xtr.getAttributeValue(null, ATTRIBUTE_MULTIINSTANCE_COLLECTION_CLASS));
        collectionHandler.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_CLASS);

    } else if (StringUtils
            .isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_MULTIINSTANCE_COLLECTION_DELEGATEEXPRESSION))) {
        collectionHandler = new CollectionHandler();
        collectionHandler.setImplementation(
                xtr.getAttributeValue(null, ATTRIBUTE_MULTIINSTANCE_COLLECTION_DELEGATEEXPRESSION));
        collectionHandler.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION);
    }

    if (collectionHandler != null) {
        BpmnXMLUtil.addXMLLocation(collectionHandler, xtr);
        multiInstanceLoopCharacteristics.setHandler(collectionHandler);
    }

    boolean readyWithCollection = false;
    try {
        while (!readyWithCollection && xtr.hasNext()) {
            xtr.next();
            if (xtr.isStartElement()
                    && ELEMENT_MULTIINSTANCE_COLLECTION_STRING.equalsIgnoreCase(xtr.getLocalName())) {
                // it is a string value
                multiInstanceLoopCharacteristics.setCollectionString(xtr.getElementText());

            } else if (xtr.isStartElement()
                    && ELEMENT_MULTIINSTANCE_COLLECTION_EXPRESSION.equalsIgnoreCase(xtr.getLocalName())) {
                // it is an expression
                multiInstanceLoopCharacteristics.setInputDataItem(xtr.getElementText());

            } else if (xtr.isEndElement() && getElementName().equalsIgnoreCase(xtr.getLocalName())) {
                readyWithCollection = true;
            }
        }
    } catch (Exception e) {
        LOGGER.warn("Error parsing collection child elements", e);
    }
}

From source file:org.flowable.bpmn.converter.child.FormPropertyParser.java

public void parseChildElement(XMLStreamReader xtr, BaseElement parentElement, BpmnModel model)
        throws Exception {

    if (!accepts(parentElement))
        return;/*from w  w  w .  ja  va 2 s. c om*/

    FormProperty property = new FormProperty();
    BpmnXMLUtil.addXMLLocation(property, xtr);
    property.setId(xtr.getAttributeValue(null, ATTRIBUTE_FORM_ID));
    property.setName(xtr.getAttributeValue(null, ATTRIBUTE_FORM_NAME));
    property.setType(xtr.getAttributeValue(null, ATTRIBUTE_FORM_TYPE));
    property.setVariable(xtr.getAttributeValue(null, ATTRIBUTE_FORM_VARIABLE));
    property.setExpression(xtr.getAttributeValue(null, ATTRIBUTE_FORM_EXPRESSION));
    property.setDefaultExpression(xtr.getAttributeValue(null, ATTRIBUTE_FORM_DEFAULT));
    property.setDatePattern(xtr.getAttributeValue(null, ATTRIBUTE_FORM_DATEPATTERN));
    if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_FORM_REQUIRED))) {
        property.setRequired(Boolean.valueOf(xtr.getAttributeValue(null, ATTRIBUTE_FORM_REQUIRED)));
    }
    if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_FORM_READABLE))) {
        property.setReadable(Boolean.valueOf(xtr.getAttributeValue(null, ATTRIBUTE_FORM_READABLE)));
    }
    if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_FORM_WRITABLE))) {
        property.setWriteable(Boolean.valueOf(xtr.getAttributeValue(null, ATTRIBUTE_FORM_WRITABLE)));
    }

    boolean readyWithFormProperty = false;
    try {
        while (readyWithFormProperty == false && xtr.hasNext()) {
            xtr.next();
            if (xtr.isStartElement() && ELEMENT_VALUE.equalsIgnoreCase(xtr.getLocalName())) {
                FormValue value = new FormValue();
                BpmnXMLUtil.addXMLLocation(value, xtr);
                value.setId(xtr.getAttributeValue(null, ATTRIBUTE_ID));
                value.setName(xtr.getAttributeValue(null, ATTRIBUTE_NAME));
                property.getFormValues().add(value);

            } else if (xtr.isEndElement() && getElementName().equalsIgnoreCase(xtr.getLocalName())) {
                readyWithFormProperty = true;
            }
        }
    } catch (Exception e) {
        LOGGER.warn("Error parsing form properties child elements", e);
    }

    if (parentElement instanceof UserTask) {
        ((UserTask) parentElement).getFormProperties().add(property);
    } else {
        ((StartEvent) parentElement).getFormProperties().add(property);
    }
}

From source file:org.flowable.bpmn.converter.child.IOSpecificationParser.java

public void parseChildElement(XMLStreamReader xtr, BaseElement parentElement, BpmnModel model)
        throws Exception {

    if (parentElement instanceof Activity == false && parentElement instanceof Process == false)
        return;//from  w w  w  .jav a  2s  . co m

    IOSpecification ioSpecification = new IOSpecification();
    BpmnXMLUtil.addXMLLocation(ioSpecification, xtr);
    boolean readyWithIOSpecification = false;
    try {
        while (readyWithIOSpecification == false && xtr.hasNext()) {
            xtr.next();
            if (xtr.isStartElement() && ELEMENT_DATA_INPUT.equalsIgnoreCase(xtr.getLocalName())) {
                DataSpec dataSpec = new DataSpec();
                BpmnXMLUtil.addXMLLocation(dataSpec, xtr);
                dataSpec.setId(xtr.getAttributeValue(null, ATTRIBUTE_ID));
                dataSpec.setName(xtr.getAttributeValue(null, ATTRIBUTE_NAME));
                dataSpec.setItemSubjectRef(
                        parseItemSubjectRef(xtr.getAttributeValue(null, ATTRIBUTE_ITEM_SUBJECT_REF), model));
                ioSpecification.getDataInputs().add(dataSpec);

            } else if (xtr.isStartElement() && ELEMENT_DATA_OUTPUT.equalsIgnoreCase(xtr.getLocalName())) {
                DataSpec dataSpec = new DataSpec();
                BpmnXMLUtil.addXMLLocation(dataSpec, xtr);
                dataSpec.setId(xtr.getAttributeValue(null, ATTRIBUTE_ID));
                dataSpec.setName(xtr.getAttributeValue(null, ATTRIBUTE_NAME));
                dataSpec.setItemSubjectRef(
                        parseItemSubjectRef(xtr.getAttributeValue(null, ATTRIBUTE_ITEM_SUBJECT_REF), model));
                ioSpecification.getDataOutputs().add(dataSpec);

            } else if (xtr.isStartElement() && ELEMENT_DATA_INPUT_REFS.equalsIgnoreCase(xtr.getLocalName())) {
                String dataInputRefs = xtr.getElementText();
                if (StringUtils.isNotEmpty(dataInputRefs)) {
                    ioSpecification.getDataInputRefs().add(dataInputRefs.trim());
                }

            } else if (xtr.isStartElement() && ELEMENT_DATA_OUTPUT_REFS.equalsIgnoreCase(xtr.getLocalName())) {
                String dataOutputRefs = xtr.getElementText();
                if (StringUtils.isNotEmpty(dataOutputRefs)) {
                    ioSpecification.getDataOutputRefs().add(dataOutputRefs.trim());
                }

            } else if (xtr.isEndElement() && getElementName().equalsIgnoreCase(xtr.getLocalName())) {
                readyWithIOSpecification = true;
            }
        }
    } catch (Exception e) {
        LOGGER.warn("Error parsing ioSpecification child elements", e);
    }

    if (parentElement instanceof Process) {
        ((Process) parentElement).setIoSpecification(ioSpecification);
    } else {
        ((Activity) parentElement).setIoSpecification(ioSpecification);
    }
}