Example usage for org.jdom2 Element clone

List of usage examples for org.jdom2 Element clone

Introduction

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

Prototype

@Override
public Element clone() 

Source Link

Document

This returns a deep clone of this element.

Usage

From source file:org.yawlfoundation.yawl.util.SaxonUtil.java

License:Open Source License

/**
 * Evaluates an XQuery against a data document
 * @param query the XQuery to evaluate/*from   www. j  a va 2s  .c o  m*/
 * @param dataElem a JDOM Element containing the data tree
 * @return a List containing the Element(s) resulting from the evaluation
 * @throws SaxonApiException if there's a problem with the XQuery or Element
 */
public static List<Content> evaluateListQuery(String query, Element dataElem) throws SaxonApiException {

    // put the element in a jdom document
    Document dataDoc = new Document(dataElem.clone());
    String result = evaluateQuery(query, dataDoc);

    // use the string result to create a doc to get it expressed as an element list
    Document resultDoc = JDOMUtil.stringToDocument(StringUtil.wrap(result, "root"));
    return resultDoc.getRootElement().cloneContent();
}

From source file:org.yawlfoundation.yawl.util.YPredicateParser.java

License:Open Source License

/**
 * Evaluates an XQuery/*from  w  ww  .  j av  a 2s.c o  m*/
 * @param s the query expression
 * @param data XML'd data that may be referenced by the expression. May be null if
 * the expression doesn't reference any data
 * @return the result of the evaluation, or "__evaluation_error__" if there's a
 * problem evaluating the expression
 */
protected String evaluateXQuery(String s, Element data) {
    return evaluateXQuery(s, new Document(data.clone()));

}

From source file:org.yawlfoundation.yawl.worklet.exception.ExceptionService.java

License:Open Source License

private Element blendInCaseData(WorkItemRecord wir, Element itemData) {
    if (itemData == null)
        return null;
    Element caseData = getCaseData(wir.getRootCaseID());
    if (caseData != null) {
        Iterator<Element> itr = caseData.getChildren().iterator(); // avoid ConModEx
        while (itr.hasNext()) {
            Element child = itr.next();
            String name = child.getName();

            // assumption: if itemData contains an element of the same name as
            // caseData, then the itemData element's value is the same as, or newer
            // than, the caseData element's value. Therefore, only missing elements
            // should be added
            if (itemData.getChild(name) == null) {
                itemData.addContent(child.clone());
            }/*w w  w. j a  v  a2  s . c om*/
        }
    }
    return itemData;
}

From source file:org.yawlfoundation.yawl.worklet.exception.HandlerRunner.java

License:Open Source License

/**
* writes the node id's for the nodes returned from the rdr search
* and the data for the current workitem, to a file for later
* input into the 'add rule' process, if required
*///from www  .  j  a va2s  .  c  o m
public void saveSearchResults() {

    // create the required components for the output file
    Document doc = new Document(new Element("searchResult"));
    Element eLastNode = new Element("lastNode");
    Element eSatisfied = new Element("satisfied");
    Element eTested = new Element("tested");
    Element eId = new Element("id");
    Element eSpecid = new Element("specid");
    Element eSpecVersion = new Element("specversion");
    Element eSpecURI = new Element("specuri");
    Element eTaskid = new Element("taskid");
    Element eCaseid = new Element("caseid");
    Element eCaseData = new Element("casedata");
    Element eReason = new Element("extype");
    Element eWorklets = new Element("worklets");

    try {
        // transfer the workitem's data items to the file
        for (Element e : getDatalist().getChildren()) {
            eCaseData.addContent(e.clone());
        }

        // set values for case identifiers
        eSpecid.setText(_parentMonitor.getSpecID().getIdentifier());
        eSpecVersion.setText(_parentMonitor.getSpecID().getVersionAsString());
        eSpecURI.setText(_parentMonitor.getSpecID().getUri());
        eCaseid.setText(_parentMonitor.getCaseID());

        if (_wir != null) {
            // set values for the workitem identifiers (item-level exception)
            eId.setText(_wir.getID());
            eTaskid.setText(Library.getTaskNameFromId(_wir.getTaskID()));
        }

        // add the worklet names and case ids
        for (String wName : _runners.getAllWorkletNames()) {
            Element eWorkletName = new Element("workletName");
            Element eRunningCaseId = new Element("runningcaseid");
            Element eWorklet = new Element("worklet");
            eWorkletName.setText(wName);
            eRunningCaseId.setText(_runners.getCaseID(wName));
            eWorklet.addContent(eWorkletName);
            eWorklet.addContent(eRunningCaseId);
            eWorklets.addContent(eWorklet);
        }

        eReason.setText(String.valueOf(_reasonType));

        // add the nodeids to the relevent elements
        eSatisfied.setText(_searchPair.getLastTrueNode().getNodeIdAsString());
        eTested.setText(_searchPair.getLastEvaluatedNode().getNodeIdAsString());
        eLastNode.addContent(eSatisfied);
        eLastNode.addContent(eTested);

        // add the elements to the document
        Element root = doc.getRootElement();
        root.addContent(eId);
        root.addContent(eSpecid);
        root.addContent(eSpecVersion);
        root.addContent(eSpecURI);
        root.addContent(eTaskid);
        root.addContent(eCaseid);
        root.addContent(eWorklets);
        root.addContent(eReason);
        root.addContent(eLastNode);
        root.addContent(eCaseData);

        // create the output file
        saveDocument(createFileName(), doc);
    } catch (IllegalAddException iae) {
        _log.error("Exception when adding content", iae);
    }
}

From source file:org.yawlfoundation.yawl.worklet.support.ConditionEvaluator.java

License:Open Source License

/**
 *  PARSING METHODS/*from  w  ww.j  a v a2 s .  c o  m*/
 */

private String evaluateXQuery(String expr, Element data) throws RdrConditionException {
    try {
        if (expr.startsWith("{"))
            expr = deQuote(expr); // remove braces
        String query = String.format("boolean(%s)", expr);
        return SaxonUtil.evaluateQuery(query, new Document(data.clone()));
    } catch (SaxonApiException sae) {
        throw new RdrConditionException("Invalid XPath expression (" + expr + ").");
    }
}

From source file:org.yawlfoundation.yawl.worklet.support.WorkletRecord.java

License:Open Source License

/**
 * writes the node id's for the nodes returned from the rdr search
 * and the data for the current workitem, to a file for later
 * input into the 'add rule' process, if required
 *//*from   w  w w .  j a  v  a 2  s .c o  m*/
public void saveSearchResults() {

    // create the required components for the output file
    Document doc = new Document(new Element("searchResult"));
    Element eLastNode = new Element("lastNode");
    Element eSatisfied = new Element("satisfied");
    Element eTested = new Element("tested");
    Element eId = new Element("id");
    Element eSpecid = new Element("specid");
    Element eSpecVersion = new Element("specversion");
    Element eSpecURI = new Element("specuri");
    Element eTaskid = new Element("taskid");
    Element eCaseid = new Element("caseid");
    Element eCaseData = new Element("casedata");
    Element eReason = new Element("extype");
    Element eWorklets = new Element("worklets");

    try {
        // transfer the workitem's data items to the file
        for (Element dataItem : _datalist.getChildren()) {
            eCaseData.addContent(dataItem.clone());
        }

        //set values for the workitem identifiers
        eId.setText(_wir.getID());
        eSpecid.setText(_wir.getSpecIdentifier());
        eSpecVersion.setText(_wir.getSpecVersion());
        eSpecURI.setText(_wir.getSpecURI());
        eTaskid.setText(_wir.getTaskName());
        eCaseid.setText(_wir.getCaseID());
        eReason.setText(String.valueOf(_reasonType));

        // add the worklet names and case ids
        for (String wName : _runners.getAllWorkletNames()) {
            Element eWorkletName = new Element("workletName");
            Element eRunningCaseId = new Element("runningcaseid");
            Element eWorklet = new Element("worklet");
            eWorkletName.setText(wName);
            eRunningCaseId.setText(_runners.getCaseID(wName));
            eWorklet.addContent(eWorkletName);
            eWorklet.addContent(eRunningCaseId);
            eWorklets.addContent(eWorklet);
        }

        // add the nodeids to the relevent elements
        eSatisfied.setText(_searchPair.getLastTrueNode().getNodeIdAsString());
        eTested.setText(_searchPair.getLastEvaluatedNode().getNodeIdAsString());
        eLastNode.addContent(eSatisfied);
        eLastNode.addContent(eTested);

        // add the elements to the document
        Element root = doc.getRootElement();
        root.addContent(eId);
        root.addContent(eSpecid);
        root.addContent(eSpecVersion);
        root.addContent(eSpecURI);
        root.addContent(eTaskid);
        root.addContent(eCaseid);
        root.addContent(eWorklets);
        root.addContent(eReason);
        root.addContent(eLastNode);
        root.addContent(eCaseData);

        // create the output file
        saveDocument(createFileName(), doc);
    } catch (IllegalAddException iae) {
        WorkletRecord._log.error("Exception when adding content", iae);
    }
}

From source file:org.yawlfoundation.yawl.worklet.WorkletService.java

License:Open Source License

/**
 * updates the input datalist with the changed data in the output datalist
 *
 * @param in  - the JDOM Element containing the input params
 * @param out - the JDOM Element containing the output params
 * @return a JDOM Element with the data updated
 *///  ww w . j  av  a2s.com
public Element updateDataList(Element in, Element out) {

    // get a copy of the 'in' list      
    Element result = in.clone();

    // for each child in 'out' list, get its value and copy to 'in' list
    for (Element e : out.getChildren()) {

        // if there's a matching 'in' data item, update its value
        Element resData = result.getChild(e.getName());
        if (resData != null) {
            if (resData.getContentSize() > 0)
                resData.setContent(e.cloneContent());
            else
                resData.setText(e.getText());
        } else {
            // if the item is not in the 'in' list, add it.
            result.getChildren().add(e.clone());
        }
    }

    return result;
}

From source file:org.yawlfoundation.yawl.wsif.WSIFController.java

License:Open Source License

/**
 * Implements InterfaceBWebsideController.  It receives messages from the engine
 * notifying an enabled task and acts accordingly.  In this case it takes the message,
 * tries to check out the work item, and if successful it begins to start up a web service
 * invocation./* w w w.  j ava2s.  c o  m*/
 * @param enabledWorkItem
 */
public void handleEnabledWorkItemEvent(WorkItemRecord enabledWorkItem) {
    try {
        if (!checkConnection(_sessionHandle)) {
            _sessionHandle = connect(engineLogonName, engineLogonPassword);
        }
        if (successful(_sessionHandle)) {
            List<WorkItemRecord> executingChildren = checkOutAllInstancesOfThisTask(enabledWorkItem,
                    _sessionHandle);
            for (WorkItemRecord itemRecord : executingChildren) {
                Element inputData = itemRecord.getDataList();
                String wsdlLocation = inputData.getChildText(WSDL_LOCATION_PARAMNAME);
                String portName = inputData.getChildText(WSDL_PORTNAME_PARAMNAME);
                String operationName = inputData.getChildText(WSDL_OPERATIONNAME_PARAMNAME);

                Element webServiceArgsData = inputData.clone();
                webServiceArgsData.removeChild(WSDL_LOCATION_PARAMNAME);
                webServiceArgsData.removeChild(WSDL_PORTNAME_PARAMNAME);
                webServiceArgsData.removeChild(WSDL_OPERATIONNAME_PARAMNAME);

                Map replyFromWebServiceBeingInvoked = WSIFInvoker.invokeMethod(wsdlLocation, portName,
                        operationName, webServiceArgsData, getAuthenticationConfig());

                _log.warn("\n\nReply from Web service being invoked is : {}", replyFromWebServiceBeingInvoked);

                Element caseDataBoundForEngine = prepareReplyRootElement(enabledWorkItem, _sessionHandle);
                Map<String, String> outputDataTypes = getOutputDataTypes(enabledWorkItem);

                for (Object o : replyFromWebServiceBeingInvoked.keySet()) {
                    String varName = (String) o;
                    Object replyMsg = replyFromWebServiceBeingInvoked.get(varName);
                    System.out.println("replyMsg class = " + replyMsg.getClass().getName());
                    String varVal = replyMsg.toString();
                    String varType = outputDataTypes.get(varName);
                    if ((varType != null) && (!varType.endsWith("string"))) {
                        varVal = validateValue(varType, varVal);
                    }
                    Element content = new Element(varName);
                    content.setText(varVal);
                    caseDataBoundForEngine.addContent(content);
                }

                _logger.debug("\nResult of item [" + itemRecord.getID() + "] checkin is : " + checkInWorkItem(
                        itemRecord.getID(), inputData, caseDataBoundForEngine, null, _sessionHandle));
            }
        }

    } catch (Throwable e) {
        _logger.error(e.getMessage(), e);
    }
}

From source file:se.miun.itm.input.export.LaTeXFileExporter.java

License:Open Source License

private String getNumericalRange(Element original) throws InPUTException {
    Element clone = original.clone();
    new Element("something").addContent(clone);
    NParam element = new NParam(clone, "something", null);
    element.addMaxDependency(element);/*ww  w  .j a  v a 2 s  . c o m*/
    element.addMinDependency(element);
    element.initRanges();

    return "$" + element.toString() + "$";
}

From source file:se.miun.itm.input.model.param.ParamStore.java

License:Open Source License

private void initElementByType(String referentType, Element referent, Element type) {
    Element newChoice = type.clone();
    String localId = referent.getAttributeValue(Q.ID_ATTR);
    addAlias(referent, type);//from ww  w.  jav  a  2 s.com
    newChoice.setAttribute(Q.ID_ATTR, localId);
    newChoice.setName(referentType);
    overrideSubElementsIfExist(referent, newChoice);
    Element parent = referent.getParentElement();
    parent.removeContent(referent);
    parent.addContent(newChoice);
}