Java Code Examples for org.jdom2.Element#removeChild()

The following examples show how to use org.jdom2.Element#removeChild() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Marshaller.java    From yawl with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static String getMergedOutputData(Element inputData, Element outputData) {
    try {
        Element merged = inputData.clone();
        JDOMUtil.stripAttributes(merged);
        JDOMUtil.stripAttributes(outputData);

        List<Element> children = outputData.getChildren();

        // iterate through the output vars and add them to the merged doc.
        for (int i = children.size() - 1; i >= 0; i--) {
            Element child = children.get(i);

            // the input data will be removed from the merged doc and
            // the output data will be added.
            merged.removeChild(child.getName());
            merged.addContent(child.detach());
        }
        return JDOMUtil.elementToString(merged);
    }
    catch (Exception e) {
        return "";
    }
}
 
Example 2
Source File: DynFormFieldAssembler.java    From yawl with GNU Lesser General Public License v3.0 6 votes vote down vote up
private Map<String, String> getAppInfo(Element eField) {
    Namespace ns = eField.getNamespace();
    Element annotation = eField.getChild("annotation", ns);
    if (annotation != null) {
        Map<String, String> infoMap = new HashMap<>();
        Element appInfo = annotation.getChild("appinfo", ns);
        if (appInfo != null) {
            for (Element child : appInfo.getChildren()) {
                String text = child.getText();
                if (!StringUtil.isNullOrEmpty(text)) {
                    infoMap.put(child.getName(), text);
                }
            }
        }
        eField.removeChild("annotation", ns);   // done processing the annotation
        return infoMap;
    }
    return Collections.emptyMap();
}
 
Example 3
Source File: YParameter.java    From yawl with GNU Lesser General Public License v3.0 5 votes vote down vote up
public String toSummaryXML() {
    String result = "";
    Element eParam = JDOMUtil.stringToElement(toXML());
    if (eParam != null) {
        eParam.removeChild("initialValue");
        Element typeElement = eParam.getChild("type");
        Element orderingElem = new Element("ordering");
        orderingElem.setText("" + _ordering);
        int insPos = (null == typeElement) ? 0 : 1 ;
        eParam.addContent(insPos, orderingElem);
        result = JDOMUtil.elementToString(eParam);
    }
    return result ;
}
 
Example 4
Source File: YMarshal.java    From yawl with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Builds a list of specification objects from a XML string.
 * @param specStr the XML string describing the specification set
 * @param schemaValidate when true, will cause the specifications to be
 * validated against schema while being parsed
 * @return a list of YSpecification objects taken from the XML string.
 * @throws YSyntaxException if a parsed specification doesn't validate against
 * schema
 */
public static List<YSpecification> unmarshalSpecifications(String specStr,
                                                           boolean schemaValidate)
        throws YSyntaxException {
    
    List<YSpecification> result = null;

    // first check if the xml string is well formed and build a document
    Document document = JDOMUtil.stringToDocument(specStr);
    if (document != null) {
        Element specificationSetEl = document.getRootElement();
        YSchemaVersion version = getVersion(specificationSetEl);
        Namespace ns = specificationSetEl.getNamespace();

        // strip layout element, if any (the engine doesn't use it)
        specificationSetEl.removeChild("layout", ns);

        // now check the specification file against its respective schema
        if (schemaValidate) {
            SchemaHandler validator = new SchemaHandler(version.getSchemaURL());
            if (! validator.compileAndValidate(specStr)) {
                throw new YSyntaxException(
                  " The specification file failed to verify against YAWL's Schema:\n"
                        + validator.getConcatenatedMessage());
            }
        }

        // now build a set of specifications - verification has not yet occurred.
        result = buildSpecifications(specificationSetEl, ns, version);
    }
    else {
        throw new YSyntaxException("Invalid XML specification.");
    }
    return result;
}
 
Example 5
Source File: RSS094Generator.java    From rome with Apache License 2.0 5 votes vote down vote up
@Override
protected void populateItem(final Item item, final Element eItem, final int index) {
    super.populateItem(item, eItem, index);

    final Description description = item.getDescription();
    if (description != null && description.getType() != null) {
        final Element eDescription = eItem.getChild("description", getFeedNamespace());
        eDescription.setAttribute(new Attribute("type", description.getType()));
    }
    eItem.removeChild("expirationDate", getFeedNamespace());
}
 
Example 6
Source File: WSIFController.java    From yawl with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * 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.
 * @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);
    }
}