Example usage for org.jdom2 Element getContent

List of usage examples for org.jdom2 Element getContent

Introduction

In this page you can find the example usage for org.jdom2 Element getContent.

Prototype

@Override
public List<Content> getContent() 

Source Link

Document

This returns the full content of the element as a List which may contain objects of type Text, Element, Comment, ProcessingInstruction, CDATA, and EntityRef.

Usage

From source file:org.yawlfoundation.yawl.elements.YTask.java

License:Open Source License

public synchronized boolean t_complete(YPersistenceManager pmgr, YIdentifier childID,
        Document decompositionOutputData)
        throws YDataStateException, YStateException, YQueryException, YPersistenceException {
    if (t_isBusy()) {
        YSpecification spec = _net.getSpecification();
        YDataValidator validator = spec.getDataValidator();
        validateOutputs(validator, decompositionOutputData);

        for (String query : getQueriesForTaskCompletion()) {
            if (ExternalDBGatewayFactory.isExternalDBMappingExpression(query)) {
                AbstractExternalDBGateway gateway = ExternalDBGatewayFactory.getInstance(query);
                updateExternalFromTaskCompletion(gateway, query, decompositionOutputData);
                continue;
            }//w  w  w  .  j  ava2  s  .  c o  m

            String localVarThatQueryResultGetsAppliedTo = getMIOutputAssignmentVar(query);
            Element queryResultElement = evaluateTreeQuery(query, decompositionOutputData);

            //debugging method call
            generateCompletingReport1(query, decompositionOutputData, queryResultElement);

            if (queryResultElement == null) {
                throw new YDataQueryException(query, queryResultElement, null,
                        "The result of the output query (" + query + ") is null");
            }

            // handle empty complex type flag elements
            if (queryResultElement.getContentSize() == 0) {
                handleEmptyComplexTypeFlagOutput(decompositionOutputData, queryResultElement, query,
                        localVarThatQueryResultGetsAppliedTo);
            }

            if (query.equals(getPreJoiningMIQuery())) {
                _groupedMultiInstanceOutputData.getRootElement().addContent(queryResultElement.clone());
            } else {
                _localVariableNameToReplaceableOutputData.put(localVarThatQueryResultGetsAppliedTo,
                        queryResultElement);
            }

            //Now we check that the resulting transformation produced data according
            //to the net variable's type.
            if (spec.getSchemaVersion().isSchemaValidating() && (!query.equals(getPreJoiningMIQuery()))) {
                YVariable var = _net.getLocalOrInputVariable(localVarThatQueryResultGetsAppliedTo);
                try {
                    Element tempRoot = new Element(_decompositionPrototype.getID());
                    tempRoot.addContent(queryResultElement.clone());
                    /**
                     * MF: Skip schema checking if we have an empty XQuery result to allow us to effectively blank-out
                     * a net variable.
                     */
                    if ((queryResultElement.getChildren().size() != 0
                            || (queryResultElement.getContent().size() != 0))) {
                        validator.validate(var, tempRoot, getID());
                    }
                } catch (YDataValidationException e) {
                    YDataStateException f = new YDataStateException(query,
                            decompositionOutputData.getRootElement(), validator.getSchema(), queryResultElement,
                            e.getErrors(), getID(),
                            "BAD PROCESS DEFINITION. Data extraction failed schema validation at task completion.");
                    f.setStackTrace(e.getStackTrace());
                    throw f;
                }
                generateCompletingReport2(queryResultElement, localVarThatQueryResultGetsAppliedTo, query,
                        decompositionOutputData);
            }
        }
        _mi_executing.removeOne(pmgr, childID);
        _mi_complete.add(pmgr, childID);
        if (t_isExitEnabled()) {
            t_exit(pmgr);
            return true;
        }
        return false;
    } else {
        throw new RuntimeException("This task [" + (getName() != null ? getName() : getID())
                + "] is not active, and therefore cannot be completed.");
    }
}

From source file:recparser.idmef.IdmefParser.java

License:Open Source License

public void listChildren(Element current, Object o, Element parent) {

    if (o != null) {
        Object object;/*from   w  ww.  ja  v  a 2  s.co m*/
        String contentName = current.getName();
        Address address = null;
        //Si es Address generamos una nueva instancia
        if (contentName.equals("Address")) {
            address = new Address();
            object = address;
        } else {
            object = o;
        }
        //get the attributes of the current element and add them to the corresponding object of idmefModel package
        List attribute_list = current.getAttributes();
        Iterator it_attribute = attribute_list.iterator();
        while (it_attribute.hasNext()) {
            Attribute attribute = (Attribute) it_attribute.next();
            addAttribute(current, attribute, object);
        }
        //get the contents of the current element and add them to the corresponding object of idmefModel package
        List contents = current.getContent();
        Iterator it_contents = contents.iterator();

        while (it_contents.hasNext()) {
            Object child = it_contents.next();
            if (child instanceof Text) {
                Text t = (Text) child;
                String contentValue = t.getTextTrim();

                if (!("".equals(contentValue))) {
                    addContent(parent, contentName, contentValue, object);
                }
            }
        }
        if (contentName.equals("Address")) {
            if (o instanceof IntrusionTarget) {
                IntrusionTarget target = (IntrusionTarget) o;
                target.setNode(address);
            } else if (o instanceof IntrusionSource) {
                IntrusionSource source = (IntrusionSource) o;
                source.setNode(address);
            }
        }

        //get the children of the current element and call the method recursively.
        List children = current.getChildren();
        Iterator iterator = children.iterator();

        while (iterator.hasNext()) {
            Element child = (Element) iterator.next();
            ;
            listChildren(child, object, current);
        }
    }
}

From source file:univ.mlv.GraphBuilder.CompleteTheGraph.java

/**
 * Parser le SVg pour rcuprer les lments <g>
 *
 * @param rootElement racine du SVG// w ww.  j  a v a  2  s . c  o m
 */
private static void process(Element rootElement) {
    //Une fois qu'on a trouv le G => Graph on rcupre ses enfants et on arrete, sinon on parse de manire rcursive
    if (rootElement.getName().equals("g")) {
        list_g.add(rootElement);
        list_g.addAll(rootElement.getChildren());
    } else {
        List content = rootElement.getContent();
        Iterator iterator = content.iterator();
        while (iterator.hasNext()) {
            Object o = iterator.next();
            if (o instanceof Element) {
                Element child = (Element) o;
                process(child);
            }
        }
    }
}

From source file:univ.mlv.GraphBuilder.GraphConstructor.java

private static void process(Element rootElement) {
    //        Element root2=rootElement;
    //        //rcuprer l'id
    //        String nodeID_prop = rootElement.getAttributeValue("nodeID", rdfNamespace);
    //        if (nodeID_prop == null) {
    //            nodeID_prop = rootElement.getAttributeValue("about", rdfNamespace);
    //        }/*from  ww  w . ja  va2 s . co m*/
    //        if (nodeID_prop == null) {
    //            nodeID_prop = rootElement.getAttributeValue("resource", rdfNamespace);
    //        }
    //        if(nodeID_prop != null && nodeID_prop.contains(".com/")){
    //            nodeID_prop= nodeID_prop.split(".com/")[1].replaceAll("/", "_");
    //        }
    if (!rootElement.getName().equals("RDF") && !rootElement.getName().equals("graph")
            && !rootElement.getName().equals("Text")) {
        String name = rootElement.getName();
        boolean isConcept = false, isProperty = false;
        if (Character.isUpperCase(name.charAt(0))) {
            isConcept = true;
        } else {
            isProperty = true;
        }
        String id = getId(rootElement);
        if (id == null) {
            //c'est une property, si il n'a pas d'enfant alors c'est une proprit object
            //il faut rcuprer son parent et sa valeur
            if (isProperty && rootElement.getChildren().isEmpty()) {
                //c'est une datatype, l'ajouter  la liste des datatype
                if (dataProperty.keySet().contains(getId(rootElement.getParentElement()))) {
                    dataProperty.get(getId(rootElement.getParentElement())).add(rootElement);
                } else {
                    List<Element> newList = new ArrayList<Element>();
                    newList.add(rootElement);
                    dataProperty.put(getId(rootElement.getParentElement()), newList);
                }
            } else if (isProperty) {
                //Si il y a des enfants, c'est que c'est une proprit object, le range n'est pas en id mais est l'enfant qui suit
                if (null != rootElement.getParentElement() && null != getId(rootElement.getParentElement())
                        && objProperty.keySet().contains(getId(rootElement.getParentElement()))) {
                    objProperty.get(getId(rootElement.getParentElement())).add(rootElement);
                } else {
                    List<Element> newList = new ArrayList<Element>();
                    newList.add(rootElement);
                    if (null == getId(rootElement.getParentElement())) {
                        objProperty.put(rootElement.getParentElement().getName(), newList);
                    } else {
                        objProperty.put(getId(rootElement.getParentElement()), newList);
                    }
                }
            }
        } else {
            //Si l'id est prsent mais qu'il n'y a pas d'enfent, alors c'est une proprit objet avec un rdf about dcrit
            if (rootElement.getChildren().isEmpty() && isProperty) {
                if (objProperty.keySet().contains(getId(rootElement.getParentElement()))) {
                    objProperty.get(getId(rootElement.getParentElement())).add(rootElement);
                } else if (isProperty) {
                    List<Element> newList = new ArrayList<Element>();
                    newList.add(rootElement);
                    objProperty.put(getId(rootElement.getParentElement()), newList);
                }
            } else if (isConcept) {
                if (conceptMap.keySet().contains(id)) {
                    //                    conceptMap.get(id).add(rootElement);
                } else {
                    conceptMap.put(id, rootElement);
                    concept.add(rootElement);
                }
            }
        }

    }
    List content = rootElement.getContent();
    Iterator iterator = content.iterator();
    while (iterator.hasNext()) {
        Object o = iterator.next();
        if (o instanceof Element) {
            Element child = (Element) o;
            process(child);
        }
    }
}

From source file:xml.JDOMConverter.java

License:Apache License

/**.
 * Filters the object to convert it//  ww w .ja v  a 2 s  .com
 * @param o : Object
 * @thows JSONException
 * @see JSONConverter#tree
 * @see JSONConverter#readJsonStream(InputStream)
 */
public final void filter(final Object o) throws JSONException {
    if (o instanceof Element) {
        Element element = (Element) o;
        String elemName = element.getName();
        List children = element.getContent();
        List attribute = element.getAttributes();
        Iterator ita = attribute.iterator();
        Iterator itc = children.iterator();

        current++;
        tree.add(current, new JSONObject());

        // Attributes
        while (ita.hasNext()) {
            Object child = ita.next();
            filter(child);
        }
        // Children
        while (itc.hasNext()) {
            Object child = itc.next();
            filter(child);
        }
        handleArray(elemName);
        tree.remove(current);
        current--;
    } else if (o instanceof Attribute) {
        handleAttribute((Attribute) o);
    } else if (o instanceof Text) {
        handleText((Text) o);
    }
}