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

private IntermediateCatchEvent parseIntermediateCatchEvent(XMLStreamReader xtr) {
    IntermediateCatchEvent catchEvent = new IntermediateCatchEvent();

    try {/*from www  .  jav  a  2  s .  c  o m*/
        while (xtr.hasNext()) {
            xtr.next();
            if (xtr.isStartElement() && "timerEventDefinition".equalsIgnoreCase(xtr.getLocalName())) {
                catchEvent.getEventDefinitions().add(parseTimerEventDefinition(xtr));
                break;

            } else if (xtr.isStartElement() && "signalEventDefinition".equalsIgnoreCase(xtr.getLocalName())) {
                catchEvent.getEventDefinitions().add(parseSignalEventDefinition(xtr));
                break;

            } else if (xtr.isEndElement() && "intermediateCatchEvent".equalsIgnoreCase(xtr.getLocalName())) {
                break;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return catchEvent;
}

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

private ThrowEvent parseIntermediateThrowEvent(XMLStreamReader xtr) {
    ThrowEvent throwEvent = new ThrowEvent();
    try {//  w w  w  .j av a 2s. c o m
        while (xtr.hasNext()) {
            xtr.next();
            if (xtr.isStartElement() && "signalEventDefinition".equalsIgnoreCase(xtr.getLocalName())) {
                throwEvent.getEventDefinitions().add(parseSignalEventDefinition(xtr));
                break;

            } else if (xtr.isEndElement() && "intermediateThrowEvent".equalsIgnoreCase(xtr.getLocalName())) {
                break;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return throwEvent;
}

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

private TimerEventDefinition parseTimerEventDefinition(XMLStreamReader xtr) {
    TimerEventDefinition eventDefinition = new TimerEventDefinition();
    try {// ww w .j a v  a2 s . c  o m
        while (xtr.hasNext()) {
            xtr.next();
            if (xtr.isStartElement() && "timeDuration".equalsIgnoreCase(xtr.getLocalName())) {
                eventDefinition.setTimeDuration(xtr.getElementText());
                break;

            } else if (xtr.isStartElement() && "timeDate".equalsIgnoreCase(xtr.getLocalName())) {
                eventDefinition.setTimeDate(xtr.getElementText());
                break;

            } else if (xtr.isStartElement() && "timeCycle".equalsIgnoreCase(xtr.getLocalName())) {
                eventDefinition.setTimeCycle(xtr.getElementText());
                break;

            } else if (xtr.isEndElement() && "timerEventDefinition".equalsIgnoreCase(xtr.getLocalName())) {
                break;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return eventDefinition;
}

From source file:org.activiti.dmn.converter.util.DmnXMLUtil.java

public static void parseChildElements(String elementName, DmnElement parentElement, XMLStreamReader xtr,
        Map<String, BaseChildElementParser> childParsers, DmnDefinition model) throws Exception {

    Map<String, BaseChildElementParser> localParserMap = new HashMap<String, BaseChildElementParser>(
            genericChildParserMap);// w w w.j  a v a2  s . c om
    if (childParsers != null) {
        localParserMap.putAll(childParsers);
    }

    boolean inExtensionElements = false;
    boolean readyWithChildElements = false;
    while (readyWithChildElements == false && xtr.hasNext()) {
        xtr.next();

        if (xtr.isStartElement()) {

            if (ELEMENT_EXTENSIONS.equals(xtr.getLocalName())) {
                inExtensionElements = true;
            } else if (localParserMap.containsKey(xtr.getLocalName())) {
                BaseChildElementParser childParser = localParserMap.get(xtr.getLocalName());
                //if we're into an extension element but the current element is not accepted by this parentElement then is read as a custom extension element
                if (inExtensionElements && !childParser.accepts(parentElement)) {
                    DmnExtensionElement extensionElement = parseExtensionElement(xtr);
                    parentElement.addExtensionElement(extensionElement);
                    continue;
                }
                localParserMap.get(xtr.getLocalName()).parseChildElement(xtr, parentElement, model);
            } else if (inExtensionElements) {
                DmnExtensionElement extensionElement = parseExtensionElement(xtr);
                parentElement.addExtensionElement(extensionElement);
            }

        } else if (xtr.isEndElement()) {
            if (ELEMENT_EXTENSIONS.equals(xtr.getLocalName())) {
                inExtensionElements = false;
            } else if (elementName.equalsIgnoreCase(xtr.getLocalName())) {
                readyWithChildElements = true;
            }
        }
    }
}

From source file:org.activiti.dmn.converter.util.DmnXMLUtil.java

public static DmnExtensionElement parseExtensionElement(XMLStreamReader xtr) throws Exception {
    DmnExtensionElement extensionElement = new DmnExtensionElement();
    extensionElement.setName(xtr.getLocalName());
    if (StringUtils.isNotEmpty(xtr.getNamespaceURI())) {
        extensionElement.setNamespace(xtr.getNamespaceURI());
    }//from w ww . j  a  v a 2s .co  m
    if (StringUtils.isNotEmpty(xtr.getPrefix())) {
        extensionElement.setNamespacePrefix(xtr.getPrefix());
    }

    for (int i = 0; i < xtr.getAttributeCount(); i++) {
        DmnExtensionAttribute extensionAttribute = new DmnExtensionAttribute();
        extensionAttribute.setName(xtr.getAttributeLocalName(i));
        extensionAttribute.setValue(xtr.getAttributeValue(i));
        if (StringUtils.isNotEmpty(xtr.getAttributeNamespace(i))) {
            extensionAttribute.setNamespace(xtr.getAttributeNamespace(i));
        }
        if (StringUtils.isNotEmpty(xtr.getAttributePrefix(i))) {
            extensionAttribute.setNamespacePrefix(xtr.getAttributePrefix(i));
        }
        extensionElement.addAttribute(extensionAttribute);
    }

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

From source file:org.activiti.dmn.xml.converter.DmnXMLConverter.java

public DmnDefinition convertToDmnModel(XMLStreamReader xtr) {
    DmnDefinition model = new DmnDefinition();
    DmnElement parentElement = null;//from   ww w.  j  a  v  a  2 s  .  c o m

    try {
        while (xtr.hasNext()) {
            try {
                xtr.next();
            } catch (Exception e) {
                LOGGER.debug("Error reading XML document", e);
                throw new DmnXMLException("Error reading XML", e);
            }

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

            if (ELEMENT_DEFINITIONS.equals(xtr.getLocalName())) {
                model.setId(xtr.getAttributeValue(null, ATTRIBUTE_ID));
                model.setName(xtr.getAttributeValue(null, ATTRIBUTE_NAME));
                model.setNamespace(MODEL_NAMESPACE);
                parentElement = model;
            } else if (ELEMENT_DECISION.equals(xtr.getLocalName())) {
                Decision decision = new Decision();
                model.addDrgElement(decision);
                decision.setId(xtr.getAttributeValue(null, ATTRIBUTE_ID));
                decision.setName(xtr.getAttributeValue(null, ATTRIBUTE_NAME));
                parentElement = decision;
            } else if (ELEMENT_DECISION_TABLE.equals(xtr.getLocalName())) {
                DecisionTable currentDecisionTable = new DecisionTable();
                currentDecisionTable.setId(xtr.getAttributeValue(null, ATTRIBUTE_ID));

                if (xtr.getAttributeValue(null, ATTRIBUTE_HIT_POLICY) != null) {
                    currentDecisionTable
                            .setHitPolicy(HitPolicy.valueOf(xtr.getAttributeValue(null, ATTRIBUTE_HIT_POLICY)));
                } else {
                    currentDecisionTable.setHitPolicy(HitPolicy.FIRST);
                }

                model.getDrgElements().get(model.getDrgElements().size() - 1)
                        .setDecisionTable(currentDecisionTable);
                model.setCurrentDecisionTable(currentDecisionTable);
                parentElement = currentDecisionTable;
            } else if (ELEMENT_OUTPUT_CLAUSE.equals(xtr.getLocalName())) {
                OutputClause outputClause = new OutputClause();
                model.getCurrentDecisionTable().addOutput(outputClause);
                outputClause.setId(xtr.getAttributeValue(null, ATTRIBUTE_ID));
                outputClause.setLabel(xtr.getAttributeValue(null, ATTRIBUTE_LABEL));
                outputClause.setName(xtr.getAttributeValue(null, ATTRIBUTE_NAME));
                outputClause.setTypeRef(xtr.getAttributeValue(null, ATTRIBUTE_TYPE_REF));
                parentElement = outputClause;
            } else if (ELEMENT_DESCRIPTION.equals(xtr.getLocalName())) {
                parentElement.setDescription(xtr.getElementText());
            } else if (ELEMENT_EXTENSIONS.equals(xtr.getLocalName())) {
                while (xtr.hasNext()) {
                    xtr.next();
                    if (xtr.isStartElement()) {
                        DmnExtensionElement extensionElement = DmnXMLUtil.parseExtensionElement(xtr);
                        parentElement.addExtensionElement(extensionElement);
                    } else if (xtr.isEndElement()) {
                        if (ELEMENT_EXTENSIONS.equals(xtr.getLocalName())) {
                            break;
                        }
                    }
                }

            } else if (convertersToDmnMap.containsKey(xtr.getLocalName())) {
                BaseDmnXMLConverter converter = convertersToDmnMap.get(xtr.getLocalName());
                converter.convertToDmnModel(xtr, model);
            }
        }

        processDmnElements(model.getCurrentDecisionTable());

    } catch (DmnXMLException e) {
        throw e;

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

From source file:org.apache.axiom.util.stax.XMLStreamReaderUtilsTest.java

private void testGetDataHandlerFromElementWithZeroLength(boolean useDHR) throws Exception {
    XMLStreamReader reader = StAXUtils.createXMLStreamReader(new StringReader("<test/>"));
    if (useDHR) {
        // To have an XMLStreamReader that uses the DataHandlerReader extension, we wrap
        // the parser using an XOPDecodingStreamReader (even if the document doesn't contain
        // any xop:Include).
        reader = new XOPDecodingStreamReader(reader, null);
    }/*from ww  w .j ava2s  .  c o m*/
    try {
        reader.next();

        // Check precondition
        assertTrue(reader.isStartElement());

        DataHandler dh = XMLStreamReaderUtils.getDataHandlerFromElement(reader);

        // Check postcondition
        assertTrue(reader.isEndElement());
        assertEquals(-1, dh.getInputStream().read());
    } finally {
        reader.close();
    }
}

From source file:org.apache.axiom.util.stax.XMLStreamReaderUtilsTest.java

private void testGetDataHandlerFromElementNonCoalescing(boolean useDHR) throws Exception {
    // We generate base64 that is sufficiently large to force the parser to generate
    // multiple CHARACTER events
    StringBuffer buffer = new StringBuffer("<test>");
    Base64EncodingStringBufferOutputStream out = new Base64EncodingStringBufferOutputStream(buffer);
    byte[] data = new byte[65536];
    new Random().nextBytes(data);
    out.write(data);//ww  w.  j  a  v a 2s .c  o m
    out.complete();
    buffer.append("</test>");
    XMLStreamReader reader = StAXUtils.createXMLStreamReader(StAXParserConfiguration.NON_COALESCING,
            new StringReader(buffer.toString()));
    if (useDHR) {
        reader = new XOPDecodingStreamReader(reader, null);
    }
    try {
        reader.next();

        // Check precondition
        assertTrue(reader.isStartElement());

        DataHandler dh = XMLStreamReaderUtils.getDataHandlerFromElement(reader);

        // Check postcondition
        assertTrue(reader.isEndElement());
        assertTrue(Arrays.equals(data, IOUtils.toByteArray(dh.getInputStream())));
    } finally {
        reader.close();
    }
}

From source file:org.apache.syncope.client.console.widgets.reconciliation.ReconciliationReportParser.java

public static ReconciliationReport parse(final Date run, final InputStream in) throws XMLStreamException {
    XMLStreamReader streamReader = INPUT_FACTORY.createXMLStreamReader(in);
    streamReader.nextTag(); // root
    streamReader.nextTag(); // report
    streamReader.nextTag(); // reportlet

    ReconciliationReport report = new ReconciliationReport(run);

    List<Missing> missing = new ArrayList<>();
    List<Misaligned> misaligned = new ArrayList<>();
    Set<String> onSyncope = null;
    Set<String> onResource = null;

    Any user = null;/*from  www.  jav a  2  s  .c o m*/
    Any group = null;
    Any anyObject = null;
    String lastAnyType = null;
    while (streamReader.hasNext()) {
        if (streamReader.isStartElement()) {
            switch (streamReader.getLocalName()) {
            case "users":
                Anys users = new Anys();
                users.setTotal(Integer.valueOf(streamReader.getAttributeValue("", "total")));
                report.setUsers(users);
                break;

            case "user":
                user = new Any();
                user.setType(AnyTypeKind.USER.name());
                user.setKey(streamReader.getAttributeValue("", "key"));
                user.setName(streamReader.getAttributeValue("", "username"));
                report.getUsers().getAnys().add(user);
                break;

            case "groups":
                Anys groups = new Anys();
                groups.setTotal(Integer.valueOf(streamReader.getAttributeValue("", "total")));
                report.setGroups(groups);
                break;

            case "group":
                group = new Any();
                group.setType(AnyTypeKind.GROUP.name());
                group.setKey(streamReader.getAttributeValue("", "key"));
                group.setName(streamReader.getAttributeValue("", "groupName"));
                report.getGroups().getAnys().add(group);
                break;

            case "anyObjects":
                lastAnyType = streamReader.getAttributeValue("", "type");
                Anys anyObjects = new Anys();
                anyObjects.setAnyType(lastAnyType);
                anyObjects.setTotal(Integer.valueOf(streamReader.getAttributeValue("", "total")));
                report.getAnyObjects().add(anyObjects);
                break;

            case "anyObject":
                anyObject = new Any();
                anyObject.setType(lastAnyType);
                anyObject.setKey(streamReader.getAttributeValue("", "key"));
                final String anyType = lastAnyType;
                IterableUtils.find(report.getAnyObjects(), new Predicate<Anys>() {

                    @Override
                    public boolean evaluate(final Anys anys) {
                        return anyType.equals(anys.getAnyType());
                    }
                }).getAnys().add(anyObject);
                break;

            case "missing":
                missing.add(new Missing(streamReader.getAttributeValue("", "resource"),
                        streamReader.getAttributeValue("", "connObjectKeyValue")));
                break;

            case "misaligned":
                misaligned.add(new Misaligned(streamReader.getAttributeValue("", "resource"),
                        streamReader.getAttributeValue("", "connObjectKeyValue"),
                        streamReader.getAttributeValue("", "name")));
                break;

            case "onSyncope":
                onSyncope = new HashSet<>();
                break;

            case "onResource":
                onResource = new HashSet<>();
                break;

            case "value":
                Set<String> set = onSyncope == null ? onResource : onSyncope;
                set.add(streamReader.getElementText());
                break;

            default:
            }
        } else if (streamReader.isEndElement()) {
            switch (streamReader.getLocalName()) {
            case "user":
                user.getMissing().addAll(missing);
                user.getMisaligned().addAll(misaligned);
                missing.clear();
                misaligned.clear();
                break;

            case "group":
                group.getMissing().addAll(missing);
                group.getMisaligned().addAll(misaligned);
                missing.clear();
                misaligned.clear();
                break;

            case "anyObject":
                anyObject.getMissing().addAll(missing);
                anyObject.getMisaligned().addAll(misaligned);
                missing.clear();
                misaligned.clear();
                break;

            case "onSyncope":
                misaligned.get(misaligned.size() - 1).getOnSyncope().addAll(onSyncope);
                onSyncope = null;
                break;

            case "onResource":
                misaligned.get(misaligned.size() - 1).getOnResource().addAll(onResource);
                onResource = null;
                break;

            default:
            }

        }

        streamReader.next();
    }

    return report;
}

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

Pair<Graphic, Continuation<Graphic>> parseGraphic(XMLStreamReader in) throws XMLStreamException {
    in.require(START_ELEMENT, null, "Graphic");

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

    while (!(in.isEndElement() && in.getLocalName().equals("Graphic"))) {
        in.nextTag();/*from  w  ww .j  a v a  2  s .c  o  m*/

        if (in.getLocalName().equals("Mark")) {
            final Pair<Mark, Continuation<Mark>> pair = parseMark(in);

            if (pair != null) {
                base.mark = pair.first;
                if (pair.second != null) {
                    contn = new Continuation<Graphic>(contn) {
                        @Override
                        public void updateStep(Graphic base, Feature f, XPathEvaluator<Feature> evaluator) {
                            pair.second.evaluate(base.mark, f, evaluator);
                        }
                    };
                }
            }
        } else if (in.getLocalName().equals("ExternalGraphic")) {
            try {
                final Triple<BufferedImage, String, Continuation<List<BufferedImage>>> p = parseExternalGraphic(
                        in);
                if (p.third != null) {
                    contn = new Continuation<Graphic>(contn) {
                        @Override
                        public void updateStep(Graphic base, Feature f, XPathEvaluator<Feature> evaluator) {
                            LinkedList<BufferedImage> list = new LinkedList<BufferedImage>();
                            p.third.evaluate(list, f, evaluator);
                            base.image = list.poll();
                        }
                    };
                } else {
                    base.image = p.first;
                    base.imageURL = p.second;
                }
            } catch (IOException e) {
                LOG.debug("Stack trace", e);
                LOG.warn("External graphic could not be loaded. Location: line '{}' column '{}' of file '{}'.",
                        new Object[] { in.getLocation().getLineNumber(), in.getLocation().getColumnNumber(),
                                in.getLocation().getSystemId() });
            }
        } else if (in.getLocalName().equals("Opacity")) {
            contn = context.parser.updateOrContinue(in, "Opacity", base, new Updater<Graphic>() {
                public void update(Graphic obj, String val) {
                    obj.opacity = Double.parseDouble(val);
                }
            }, contn).second;
        } else if (in.getLocalName().equals("Size")) {
            contn = context.parser.updateOrContinue(in, "Size", base, new Updater<Graphic>() {
                public void update(Graphic obj, String val) {
                    obj.size = Double.parseDouble(val);
                }
            }, contn).second;
        } else if (in.getLocalName().equals("Rotation")) {
            contn = context.parser.updateOrContinue(in, "Rotation", base, new Updater<Graphic>() {
                public void update(Graphic obj, String val) {
                    obj.rotation = Double.parseDouble(val);
                }
            }, contn).second;
        } else if (in.getLocalName().equals("AnchorPoint")) {
            while (!(in.isEndElement() && in.getLocalName().equals("AnchorPoint"))) {
                in.nextTag();

                if (in.getLocalName().equals("AnchorPointX")) {
                    contn = context.parser.updateOrContinue(in, "AnchorPointX", base, new Updater<Graphic>() {
                        public void update(Graphic obj, String val) {
                            obj.anchorPointX = Double.parseDouble(val);
                        }
                    }, contn).second;
                } else if (in.getLocalName().equals("AnchorPointY")) {
                    contn = context.parser.updateOrContinue(in, "AnchorPointY", base, new Updater<Graphic>() {
                        public void update(Graphic obj, String val) {
                            obj.anchorPointY = Double.parseDouble(val);
                        }
                    }, contn).second;
                } 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);
                }
            }
        } else if (in.getLocalName().equals("Displacement")) {
            while (!(in.isEndElement() && in.getLocalName().equals("Displacement"))) {
                in.nextTag();

                if (in.getLocalName().equals("DisplacementX")) {
                    contn = context.parser.updateOrContinue(in, "DisplacementX", base, new Updater<Graphic>() {
                        public void update(Graphic obj, String val) {
                            obj.displacementX = Double.parseDouble(val);
                        }
                    }, contn).second;
                } else if (in.getLocalName().equals("DisplacementY")) {
                    contn = context.parser.updateOrContinue(in, "DisplacementY", base, new Updater<Graphic>() {
                        public void update(Graphic obj, String val) {
                            obj.displacementY = Double.parseDouble(val);
                        }
                    }, contn).second;
                } 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);
                }
            }
        } 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, "Graphic");

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