Example usage for org.jdom2 Element getChildText

List of usage examples for org.jdom2 Element getChildText

Introduction

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

Prototype

public String getChildText(final String cname, final Namespace ns) 

Source Link

Document

Returns the textual content of the named child element, or null if there's no such child.

Usage

From source file:org.yawlfoundation.yawl.unmarshal.YDecompositionParser.java

License:Open Source License

private List<FlowStruct> parsePostset(Element netElementElem) {
    List<FlowStruct> postsetFlowStructs = new ArrayList<FlowStruct>();
    for (Element flowsIntoElem : netElementElem.getChildren("flowsInto", _yawlNS)) {
        String nextElementRef = flowsIntoElem.getChild("nextElementRef", _yawlNS).getAttributeValue("id");
        FlowStruct flowStruct = new FlowStruct(nextElementRef, flowsIntoElem.getChildText("predicate", _yawlNS),
                flowsIntoElem.getChildText("documentation", _yawlNS));
        String predicateString = flowsIntoElem.getChildText("predicate", _yawlNS);
        if (predicateString != null) {
            flowStruct._flowPredicate = predicateString;
            String predicateOrderingStr = flowsIntoElem.getChild("predicate", _yawlNS)
                    .getAttributeValue("ordering");
            if (predicateOrderingStr != null) {
                flowStruct._predicateOrdering = new Integer(predicateOrderingStr);
            }//from  ww w  .  j a  v  a 2s .  c  o  m
        }
        Element isDefaultFlow = flowsIntoElem.getChild("isDefaultFlow", _yawlNS);
        if (isDefaultFlow != null) {
            flowStruct._isDefaultFlow = true;
        }
        postsetFlowStructs.add(flowStruct);
    }
    return postsetFlowStructs;
}

From source file:org.yawlfoundation.yawl.unmarshal.YDecompositionParser.java

License:Open Source License

private YNet parseNet(YNet net, Element netElem) {
    if (!isBeta2Version()) {
        String isRootNet = netElem.getAttributeValue("isRootNet");
        if ("true".equals(isRootNet)) {
            _specificationParser.getSpecification().setRootNet(net);

            // set external data gateway (since 2.1)
            String gateway = netElem.getChildText("externalDataGateway", _yawlNS);
            if (gateway != null)
                net.setExternalDataGateway(gateway);
        }/*from  w  w w  .  jav a2s.co m*/
    }
    for (Element localVariableElem : netElem.getChildren("localVariable", _yawlNS)) {
        YVariable localVar = new YVariable(_decomposition);
        parseLocalVariable(localVariableElem, localVar, _yawlNS, isBeta2Version());
        net.setLocalVariable(localVar);
    }
    parseProcessControlElements(net, netElem.getChild("processControlElements", _yawlNS));
    return net;
}

From source file:org.yawlfoundation.yawl.unmarshal.YDecompositionParser.java

License:Open Source License

/**
 * Adds variable specific information to the YParameter argument (in &amp; out var).
 * @param localVariableElem/*from   w w w .j a  v a 2 s.  com*/
 * @param variable
 */
public static void parseLocalVariable(Element localVariableElem, YVariable variable, Namespace ns,
        boolean version2) {
    //parse & set the initial value
    variable.setInitialValue(JDOMUtil.decodeEscapes(localVariableElem.getChildText("initialValue", ns)));

    String name;
    String dataType;
    String namespace = null;

    //if version is beta 2 vars are stored in different format
    if (version2) {
        name = localVariableElem.getAttributeValue("name");
        dataType = localVariableElem.getChildText("type", ns);
        if (null != dataType) {
            namespace = dataType.startsWith("xs") ? "http://www.w3.org/2001/XMLSchema" : null;

            //if data type is of QName form eliminate the first bit as it is useless for
            //version 2 anyway
            if (dataType.indexOf(':') != -1) {
                dataType = dataType.substring(dataType.indexOf(':') + 1);
            }
        }
        if (null == namespace)
            variable.setUntyped(true);
    } else { //must be version 3 or greater
        name = localVariableElem.getChildText("name", ns);
        dataType = localVariableElem.getChildText("type", ns);
        namespace = localVariableElem.getChildText("namespace", ns);

        //check to see if the variable is untyped
        variable.setUntyped(localVariableElem.getChild("isUntyped", ns) != null);

        // set mandatory (default is false)
        variable.setMandatory(localVariableElem.getChild("mandatory", ns) != null);

        //set the element name if it uses one
        String elementName;
        elementName = localVariableElem.getChildText("element", ns);
        variable.setElementName(elementName);

        // set ordering (if schema 2.1 or later)
        String orderingStr = localVariableElem.getChildText("index", ns);
        if (StringUtil.isIntegerString(orderingStr)) {
            variable.setOrdering(new Integer(orderingStr));
        }

        variable.getAttributes().fromJDOM(localVariableElem.getAttributes());
        variable.getAttributes().transformDynamicValues(variable);
    }
    //the variable either is data typed xor linked to an element declaration
    variable.setDataTypeAndName(dataType, name, namespace);
}

From source file:org.yawlfoundation.yawl.unmarshal.YDecompositionParser.java

License:Open Source License

private void parseExternalInteraction(YDecomposition decomposition, Element decompElem) {
    String interactionStr = decompElem.getChildText("externalInteraction", _yawlNS);
    if (interactionStr != null)
        decomposition.setExternalInteraction(interactionStr.equalsIgnoreCase("manual"));
}

From source file:org.yawlfoundation.yawl.unmarshal.YDecompositionParser.java

License:Open Source License

private void parseCodelet(YDecomposition decomposition, Element decompElem) {
    String codelet = decompElem.getChildText("codelet", _yawlNS);
    if (codelet != null)
        decomposition.setCodelet(codelet);
}

From source file:org.yawlfoundation.yawl.unmarshal.YSpecificationParser.java

License:Open Source License

private void parseSpecification(Element specificationElem, YSchemaVersion version) throws YSyntaxException {
    List<Element> decompositionElems = specificationElem.getChildren("decomposition", _yawlNS);
    for (Element decompositionElem : decompositionElems) {
        Namespace xsiNameSpc = decompositionElem.getNamespace("xsi");
        String decompID = decompositionElem.getAttributeValue("id");
        Attribute type = decompositionElem.getAttribute("type", xsiNameSpc);
        if (type != null) {
            String decompType = type.getValue();
            _decompAndTypeMap.put(decompID, decompType);
        }//w  w  w  .j  a v a 2  s  .  c om
    }
    String uriString = specificationElem.getAttributeValue("uri");
    _specification = new YSpecification(uriString);
    _specification.setVersion(version);
    _specification.setMetaData(parseMetaData(specificationElem));
    String name = specificationElem.getChildText("name", _yawlNS);
    String documentation = specificationElem.getChildText("documentation", _yawlNS);

    // if name and doco fields missing from spec, see if they are in metadata
    if (name == null)
        name = _specification.getMetaData().getTitle();
    if (documentation == null)
        documentation = _specification.getMetaData().getDescription();
    _specification.setName(name);
    _specification.setDocumentation(documentation);

    Namespace schema4SchemaNS = Namespace.getNamespace(_schema4SchemaURI);
    Element schemaElem = specificationElem.getChild("schema", schema4SchemaNS);
    if (null != schemaElem) {
        extractEmptyComplexTypeFlagTypeNames(schemaElem);
        _specification.setSchema(JDOMUtil.elementToString(schemaElem));
    } else {

        // if the spec has no schema definition insert a default one so that a
        // DataValidator gets created
        _specification.setSchema(_defaultSchema);
    }

    //If is version beta2 we loop through in a slightly different way.
    if (isBeta2Version()) {
        _decompositionParser = new YDecompositionParser[decompositionElems.size() + 1];
        Element rootNetElem = specificationElem.getChild("rootNet", _yawlNS);
        _decompositionParser[0] = new YDecompositionParser(rootNetElem, this,
                _specification.getSchemaVersion());
        YNet rootNet = (YNet) _decompositionParser[0].getDecomposition();
        _specification.setRootNet(rootNet);

        for (int i = 1; i <= decompositionElems.size(); i++) {
            Element decompositionElem = decompositionElems.get(i - 1);
            _decompositionParser[i] = new YDecompositionParser(decompositionElem, this,
                    _specification.getSchemaVersion());
            YDecomposition decomposition = _decompositionParser[i].getDecomposition();
            _specification.addDecomposition(decomposition);
        }
    } else {//must be beta3 or greater
        _decompositionParser = new YDecompositionParser[decompositionElems.size()];
        for (int i = 0; i < decompositionElems.size(); i++) {
            Element decompositionElem = decompositionElems.get(i);
            _decompositionParser[i] = new YDecompositionParser(decompositionElem, this,
                    _specification.getSchemaVersion());
            YDecomposition decomposition = _decompositionParser[i].getDecomposition();
            _specification.addDecomposition(decomposition);
        }
    }
    addSchema(specificationElem);
}

From source file:org.yawlfoundation.yawl.unmarshal.YSpecificationParser.java

License:Open Source License

YMetaData parseMetaData(Element specificationElem) {
    Element metaDataElem = specificationElem.getChild("metaData", _yawlNS);
    YMetaData metaData = new YMetaData();

    metaData.setTitle(metaDataElem.getChildText("title", _yawlNS));

    for (Element creatorElem : metaDataElem.getChildren("creator", _yawlNS)) {
        metaData.addCreator(creatorElem.getText());
    }// w  w  w.  java 2 s.co m

    for (Element subjectElem : metaDataElem.getChildren("subject", _yawlNS)) {
        metaData.addSubject(subjectElem.getText());
    }

    metaData.setDescription(metaDataElem.getChildText("description", _yawlNS));

    for (Element contributor : metaDataElem.getChildren("contributor", _yawlNS)) {
        metaData.addContributor(contributor.getText());
    }

    metaData.setCoverage(metaDataElem.getChildText("coverage", _yawlNS));

    String validFrom = metaDataElem.getChildText("validFrom", _yawlNS);
    if (validFrom != null) {
        try {
            metaData.setValidFrom(YMetaData.dateFormat.parse(validFrom));
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }
    String validUntil = metaDataElem.getChildText("validUntil", _yawlNS);
    if (validUntil != null) {
        try {
            metaData.setValidUntil(YMetaData.dateFormat.parse(validUntil));
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }
    String created = metaDataElem.getChildText("created", _yawlNS);
    if (created != null) {
        try {
            metaData.setCreated(YMetaData.dateFormat.parse(created));
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

    String version = metaDataElem.getChildText("version", _yawlNS);
    if (version != null && version.trim().length() > 0) {
        metaData.setVersion(new YSpecVersion(version.trim()));
    } else
        metaData.setVersion(new YSpecVersion(INITIAL_VERSION));

    metaData.setStatus(metaDataElem.getChildText("status", _yawlNS));
    /**
     * AJH: Add in support for the persistent property. This is simply a property which indicates if
     *      a custom service processing workitems from this specification needs to perform any
     *      "persistence" activities.
     */
    {
        String persistentText = metaDataElem.getChildText("persistent", _yawlNS);
        if (persistentText == null) {
            metaData.setPersistent(false);
        } else {
            metaData.setPersistent(persistentText.trim().equalsIgnoreCase("TRUE"));
        }
    }

    String uniqueID = metaDataElem.getChildText("identifier", _yawlNS);
    if (uniqueID != null)
        metaData.setUniqueID(uniqueID);

    return metaData;
}

From source file:uk.co.platosys.boox.core.Boox.java

License:Open Source License

/**
 * This is one of a group of setup/configuration methods.
 * @param enterprise/*from  w w  w .  j a  v  a 2 s.c om*/
 * @param clerk
 * @param tasksElement
 */
public static void createTasks(Enterprise enterprise, Clerk clerk, Element tasksElement)
        throws PermissionsException {
    List<Element> taskElements = tasksElement.getChildren(TASK_ELEMENT_NAME, ns);
    Map<Ledger, Permission> permissions = new HashMap<Ledger, Permission>();
    for (Element taskElement : taskElements) {
        String name = "";
        String description = "";
        String frequency = "";
        String rolename = "";
        String formClassName = "";

        try {
            name = taskElement.getAttributeValue(Task.NAME_ATTNAME);
            description = taskElement.getChildText(Task.TASKDESCRIPTION_ELNAME, ns);
            frequency = taskElement.getAttributeValue(Task.FREQ_ATTNAME);
            rolename = taskElement.getAttributeValue(Task.ROLE_ATTNAME);
            formClassName = taskElement.getAttributeValue(Task.FORM_ATTNAME);
        } catch (Throwable t) {

        }
        String sysname = ShortHash.hash(Task.SYSNAME_PREFIX + name + description);

        int frint = 20;

        switch (frequency) {
        case "once":
            frint = Task.ONCE;
            break;
        case "daily":
            frint = Task.DAILY;
            break;
        case "weekly":
            frint = Task.WEEKLY;
            break;
        case "fortnightly":
            frint = Task.FORTNIGHTLY;
            break;
        case "fourweekly":
            frint = Task.FOURWEEKLY;
            break;
        case "monthly":
            frint = Task.MONTHLY;
            break;
        case "periodend":
            frint = Task.PERIOD_END;
            break;
        case "quarterly":
            frint = Task.QUARTERLY;
            break;
        case "annual":
            frint = Task.ANNUAL;
            break;
        case "irregular":
            frint = Task.IRREGULAR;
            break;
        default:
            frint = Task.IRREGULAR;
        }
        Role role = Role.getRole(rolename);

        List<Element> ledgerElements = taskElement.getChildren(Boox.LEDGER_ELEMENT_NAME, ns);

        for (Element ledgerElement : ledgerElements) {
            String permissionName = "";
            String ledgerName = "";
            boolean cascades = false;
            try {
                ledgerName = ledgerElement.getAttributeValue(NAME_ATTRIBUTE_NAME);
                permissionName = ledgerElement.getAttributeValue(PERMISSION_ATTRIBUTE_NAME);
                cascades = (ledgerElement.getAttributeValue(CASCADES_ATTRIBUTE_NAME).equals("true"));
            } catch (Throwable t) {

            }
            Ledger ledger = Ledger.getLedger(enterprise, ledgerName);
            Permission permission;
            if (cascades) {
                permission = CascadingPermission.getPermission(permissionName);
            } else {
                permission = Permission.getPermission(permissionName);
            }
            if (clerk.hasPermission(enterprise, ledger, permission)) {
                permissions.put(ledger, permission);
            } else {
                String error = "BX: creating task - permissions error: owning clerk " + clerk.getName()
                        + " does not have " + permission.getName() + " permission on ledger "
                        + ledger.getFullName();
                logger.log(error);
                throw new PermissionsException(error);
            }
        }
        Task.createTask(enterprise, clerk, name, description, frint, role, formClassName, permissions);
    }
}

From source file:utils.ParserXML.java

License:Apache License

/**
 * search recursuvely the element and returns the contents
 * @param root/* w w w .  ja va 2 s .co  m*/
 * @param element name of element
 * @param namespace
 * @return value of element, null if element don't exist
 */
public static String getElementContentInStructure(Element root, String element, Namespace namespace) {

    String value = root.getChildText(element, namespace);
    Element result;
    if (value == null) {
        result = ParserXML.searchElementStatic(root.getChildren(), element, namespace);
        if (result != null) {
            value = result.getText();
        }
    }

    return value;
}

From source file:XMLReader.ReadCoursesXML.java

License:Open Source License

public static List<Course> ReadCourses(String idUser, String xmlSource) {
    List<Course> curso = new ArrayList<Course>();

    try {/*w w w  .  j  a  va 2s  .com*/
        Element rootNode = builder.build(xmlSource).getRootElement();
        List<Element> lista = rootNode.getChildren("curso", ns);

        for (Element e : lista)
            if (e.getChildText("idProfesor", ns).equals(idUser)) {
                Course t = new Course(e, ns);
                curso.add(t);
            }
    } catch (IOException io) {
        System.out.println(io.getMessage());
    } catch (JDOMException jdomex) {
        System.out.println(jdomex.getMessage());
    }

    Collections.sort(curso, new OrdenaCurso());
    return curso;
}