Example usage for org.dom4j Element addText

List of usage examples for org.dom4j Element addText

Introduction

In this page you can find the example usage for org.dom4j Element addText.

Prototype

Element addText(String text);

Source Link

Document

Adds a new Text node with the given text to this element.

Usage

From source file:gr.abiss.calipso.util.ItemUtils.java

License:Open Source License

public static Document getAsXml(Item item) {
    Document d = XmlUtils.getNewDocument("space");
    Element root = d.getRootElement();
    //        root.addAttribute("refId", item.getRefId());
    root.addAttribute("refId", item.getUniqueRefId());
    if (item.getRelatedItems() != null && item.getRelatedItems().size() > 0) {
        Element relatedItems = root.addElement("relatedItems");
        for (ItemItem itemItem : item.getRelatedItems()) {
            Element relatedItem = relatedItems.addElement("relatedItem");
            //                relatedItem.addAttribute("refId", itemItem.getItem().getRefId());
            relatedItem.addAttribute("refId", itemItem.getItem().getUniqueRefId());
        }/*from ww  w  .  ja v a 2  s  .  co  m*/
    }
    if (item.getRelatingItems() != null && item.getRelatingItems().size() > 0) {
        Element relatingItems = root.addElement("relatingItems");
        for (ItemItem itemItem : item.getRelatingItems()) {
            Element relatingItem = relatingItems.addElement("relatingItem");
            //                relatingItem.addAttribute("refId", itemItem.getItem().getRefId());
            relatingItem.addAttribute("refId", itemItem.getItem().getUniqueRefId());
        }
    }
    if (item.getSummary() != null) {
        root.addElement("summary").addText(item.getSummary());
    }
    if (item.getDetail() != null) {
        root.addElement("detail").addText(item.getDetail());
    }
    Element loggedBy = root.addElement("loggedBy");
    loggedBy.addAttribute("userId", item.getLoggedBy().getId() + "");
    loggedBy.addText(item.getLoggedBy().getName());
    if (item.getAssignedTo() != null) {
        Element assignedTo = root.addElement("assignedTo");
        assignedTo.addAttribute("userId", item.getAssignedTo().getId() + "");
        assignedTo.addText(item.getAssignedTo().getName());
    }
    return d;
}

From source file:hebbNet.HebbNet.java

License:Open Source License

/** Method used for saving the properties of this component */
public void exportToXmlElement(Element element) {
    Element nn = element.addElement("hebbnet");
    // TODO//from w  w w  .  ja  va  2s.  co  m
    nn.addAttribute("UniqueName", getHash());
    nn.addAttribute("learningrate", String.valueOf(learningrate));
    nn.addAttribute("input_nodes", String.valueOf(this.input_nodes));
    nn.addAttribute("output_nodes", String.valueOf(this.output_nodes));
    nn.addAttribute("nodes", String.valueOf(this.nodes));
    nn.addAttribute("weight_range", String.valueOf(this.weight_range));
    nn.addAttribute("bias_range", String.valueOf(this.bias_range));

    Element dnodes = nn.addElement("nodes");

    for (int i = 0; i < this.nodes; i++) {
        Element node;
        if (i < input_nodes) {
            node = dnodes.addElement("node");
            node.addAttribute("nr", String.valueOf(i));
            node.addAttribute("type", "inputNode");
        } else {
            node = dnodes.addElement("node");
            node.addAttribute("nr", String.valueOf(i));
            node.addAttribute("type", "node");
            Element bias = node.addElement("bias");
            bias.addText(String.valueOf(this.bias[i]));

            Element weights = node.addElement("weights");
            for (int j = 0; j < this.nodes; j++) {
                Element weight = weights.addElement("weight");
                weight.addAttribute("from", String.valueOf(j));
                weight.addText(String.valueOf(this.weight[j][i]));
                weight.addAttribute("plasticity", String.valueOf(plasticity[j][i]));
            }
        }
    }
}

From source file:hudson.model.Api.java

License:Open Source License

/**
 * Exposes the bean as XML./*from www . ja  v a2  s. c  o  m*/
 */
public void doXml(StaplerRequest req, StaplerResponse rsp, @QueryParameter String xpath,
        @QueryParameter String wrapper, @QueryParameter String tree, @QueryParameter int depth)
        throws IOException, ServletException {
    setHeaders(rsp);

    String[] excludes = req.getParameterValues("exclude");

    if (xpath == null && excludes == null) {
        // serve the whole thing
        rsp.serveExposedBean(req, bean, Flavor.XML);
        return;
    }

    StringWriter sw = new StringWriter();

    // first write to String
    Model p = MODEL_BUILDER.get(bean.getClass());
    TreePruner pruner = (tree != null) ? new NamedPathPruner(tree) : new ByDepth(1 - depth);
    p.writeTo(bean, pruner, Flavor.XML.createDataWriter(bean, sw));

    // apply XPath
    FilteredFunctionContext functionContext = new FilteredFunctionContext();
    Object result;
    try {
        Document dom = new SAXReader().read(new StringReader(sw.toString()));
        // apply exclusions
        if (excludes != null) {
            for (String exclude : excludes) {
                XPath xExclude = dom.createXPath(exclude);
                xExclude.setFunctionContext(functionContext);
                List<org.dom4j.Node> list = (List<org.dom4j.Node>) xExclude.selectNodes(dom);
                for (org.dom4j.Node n : list) {
                    Element parent = n.getParent();
                    if (parent != null)
                        parent.remove(n);
                }
            }
        }

        if (xpath == null) {
            result = dom;
        } else {
            XPath comp = dom.createXPath(xpath);
            comp.setFunctionContext(functionContext);
            List list = comp.selectNodes(dom);
            if (wrapper != null) {
                Element root = DocumentFactory.getInstance().createElement(wrapper);
                for (Object o : list) {
                    if (o instanceof String) {
                        root.addText(o.toString());
                    } else {
                        root.add(((org.dom4j.Node) o).detach());
                    }
                }
                result = root;
            } else if (list.isEmpty()) {
                rsp.setStatus(HttpServletResponse.SC_NOT_FOUND);
                rsp.getWriter().print(Messages.Api_NoXPathMatch(xpath));
                return;
            } else if (list.size() > 1) {
                rsp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                rsp.getWriter().print(Messages.Api_MultipleMatch(xpath, list.size()));
                return;
            } else {
                result = list.get(0);
            }
        }

    } catch (DocumentException e) {
        LOGGER.log(Level.FINER, "Failed to do XPath/wrapper handling. XML is as follows:" + sw, e);
        throw new IOException("Failed to do XPath/wrapper handling. Turn on FINER logging to view XML.", e);
    }

    if (isSimpleOutput(result) && !permit(req)) {
        // simple output prohibited
        rsp.sendError(HttpURLConnection.HTTP_FORBIDDEN,
                "primitive XPath result sets forbidden; implement jenkins.security.SecureRequester");
        return;
    }

    // switch to gzipped output
    OutputStream o = rsp.getCompressedOutputStream(req);
    try {
        if (isSimpleOutput(result)) {
            // simple output allowed
            rsp.setContentType("text/plain;charset=UTF-8");
            String text = result instanceof CharacterData ? ((CharacterData) result).getText()
                    : result.toString();
            o.write(text.getBytes("UTF-8"));
            return;
        }

        // otherwise XML
        rsp.setContentType("application/xml;charset=UTF-8");
        new XMLWriter(o).write(result);
    } finally {
        o.close();
    }
}

From source file:info.jtrac.domain.Field.java

License:Apache License

private void copyTo(Element e) {
    // appending empty strings to create new objects for "clone" support
    e.addAttribute(NAME, name + "");
    e.addAttribute(LABEL, label + "");
    if (optional) {
        e.addAttribute(OPTIONAL, TRUE);/*w  w  w  . j  av a2  s .c  o  m*/
    }
    if (options == null) {
        return;
    }
    for (Map.Entry<String, String> entry : options.entrySet()) {
        Element option = e.addElement(OPTION);
        option.addAttribute(VALUE, entry.getKey() + "");
        option.addText((String) entry.getValue() + "");
    }
}

From source file:info.jtrac.domain.Item.java

License:Apache License

public Element getAsXml() {
    // root//from  w  ww.  j  ava2 s .com
    Element root = XmlUtils.getNewElement("item");
    root.addAttribute("refId", this.getRefId());
    // related items
    if (this.getRelatedItems() != null && this.getRelatedItems().size() > 0) {
        Element relatedItems = root.addElement("relatedItems");
        for (ItemItem itemItem : this.getRelatedItems()) {
            Element relatedItem = relatedItems.addElement("relatedItem");
            relatedItem.addAttribute("refId", itemItem.getItem().getRefId());
            relatedItem.addAttribute("linkType", itemItem.getRelationText());
        }
    }
    // relating items
    if (this.getRelatingItems() != null && this.getRelatingItems().size() > 0) {
        Element relatingItems = root.addElement("relatingItems");
        for (ItemItem itemItem : this.getRelatingItems()) {
            Element relatingItem = relatingItems.addElement("relatingItem");
            relatingItem.addAttribute("refId", itemItem.getItem().getRefId());
            relatingItem.addAttribute("linkType", itemItem.getRelationText());
        }
    }
    // summary
    if (this.getSummary() != null) {
        root.addElement("summary").addText(this.getSummary());
    }
    // detail
    if (this.getDetail() != null) {
        root.addElement("detail").addText(this.getDetail());
    }
    // logged by
    Element loggedBy = root.addElement("loggedBy");
    // loggedBy.addAttribute("userId", item.getLoggedBy().getId() + "");
    loggedBy.addText(this.getLoggedBy().getName());
    // assigned to
    if (this.getAssignedTo() != null) {
        Element assignedTo = root.addElement("assignedTo");
        // assignedTo.addAttribute("userId", item.getAssignedTo().getId() + "");
        assignedTo.addText(this.getAssignedTo().getName());
    }
    // status
    Element status = root.addElement("status");
    status.addAttribute("statusId", this.getStatus() + "");
    status.addText(this.getStatusValue());
    // custom fields
    Map<Field.Name, Field> fields = this.getSpace().getMetadata().getFields();
    for (Field.Name fieldName : this.getSpace().getMetadata().getFieldOrder()) {
        Object value = this.getValue(fieldName);
        if (value != null) {
            Field field = fields.get(fieldName);
            Element customField = root.addElement(fieldName.getText());
            customField.addAttribute("label", field.getLabel());
            if (field.isDropDownType()) {
                customField.addAttribute("optionId", value + "");
            }
            customField.addText(this.getCustomValue(fieldName));
        }
    }
    // timestamp
    Element timestamp = root.addElement("timestamp");
    timestamp.addText(DateUtils.formatTimeStamp(this.getTimeStamp()));
    // history
    if (this.getHistory() != null) {
        Element historyRoot = root.addElement("history");
        for (History history : this.getHistory()) {
            Element event = historyRoot.addElement("event");
            // index
            event.addAttribute("eventId", (history.getIndex() + 1) + "");
            // logged by
            Element historyLoggedBy = event.addElement("loggedBy");
            // historyLoggedBy.addAttribute("userId", history.getLoggedBy().getId() + "");
            historyLoggedBy.addText(history.getLoggedBy().getName());
            // status
            if (history.getStatus() != null) {
                Element historyStatus = event.addElement("status");
                historyStatus.addAttribute("statusId", history.getStatus() + "");
                historyStatus.addText(history.getStatusValue());
            }
            // assigned to
            if (history.getAssignedTo() != null) {
                Element historyAssignedTo = event.addElement("assignedTo");
                // historyAssignedTo.addAttribute("userId", history.getAssignedTo().getId() + "");
                historyAssignedTo.addText(history.getAssignedTo().getName());
            }
            // attachment
            if (history.getAttachment() != null) {
                Element historyAttachment = event.addElement("attachment");
                historyAttachment.addAttribute("attachmentId", history.getAttachment().getId() + "");
                historyAttachment.addText(history.getAttachment().getFileName());
            }
            // comment
            if (history.getComment() != null) {
                Element historyComment = event.addElement("comment");
                historyComment.addText(history.getComment());
            }
            // timestamp
            Element historyTimestamp = event.addElement("timestamp");
            historyTimestamp.addText(DateUtils.formatTimeStamp(history.getTimeStamp()));
            // custom fields
            List<Field> editable = this.getSpace().getMetadata().getEditableFields();
            for (Field field : editable) {
                Object value = history.getValue(field.getName());
                if (value != null) {
                    Element historyCustomField = event.addElement(field.getName().getText());
                    historyCustomField.addAttribute("label", field.getLabel());
                    if (field.isDropDownType()) {
                        historyCustomField.addAttribute("optionId", value + "");
                    }
                    historyCustomField.addText(history.getCustomValue(field.getName()));
                }
            }
        }
    }
    return root;
}

From source file:info.jtrac.util.ItemUtils.java

License:Apache License

public static Element getAsXml(Item item) {
    // root//from  w  w w  .ja va  2s.  com
    Element root = XmlUtils.getNewElement("item");
    root.addAttribute("refId", item.getRefId());
    // related items
    if (item.getRelatedItems() != null && item.getRelatedItems().size() > 0) {
        Element relatedItems = root.addElement("relatedItems");
        for (ItemItem itemItem : item.getRelatedItems()) {
            Element relatedItem = relatedItems.addElement("relatedItem");
            relatedItem.addAttribute("refId", itemItem.getItem().getRefId());
            relatedItem.addAttribute("linkType", itemItem.getRelationText());
        }
    }
    // relating items
    if (item.getRelatingItems() != null && item.getRelatingItems().size() > 0) {
        Element relatingItems = root.addElement("relatingItems");
        for (ItemItem itemItem : item.getRelatingItems()) {
            Element relatingItem = relatingItems.addElement("relatingItem");
            relatingItem.addAttribute("refId", itemItem.getItem().getRefId());
            relatingItem.addAttribute("linkType", itemItem.getRelationText());
        }
    }
    // summary
    if (item.getSummary() != null) {
        root.addElement("summary").addText(item.getSummary());
    }
    // detail
    if (item.getDetail() != null) {
        root.addElement("detail").addText(item.getDetail());
    }
    // logged by
    Element loggedBy = root.addElement("loggedBy");
    // loggedBy.addAttribute("userId", item.getLoggedBy().getId() + "");
    loggedBy.addText(item.getLoggedBy().getName());
    // assigned to
    if (item.getAssignedTo() != null) {
        Element assignedTo = root.addElement("assignedTo");
        // assignedTo.addAttribute("userId", item.getAssignedTo().getId() + "");
        assignedTo.addText(item.getAssignedTo().getName());
    }
    // status
    Element status = root.addElement("status");
    status.addAttribute("statusId", item.getStatus() + "");
    status.addText(item.getStatusValue());
    // custom fields
    Map<Field.Name, Field> fields = item.getSpace().getMetadata().getFields();
    for (Field.Name fieldName : item.getSpace().getMetadata().getFieldOrder()) {
        Object value = item.getValue(fieldName);
        if (value != null) {
            Field field = fields.get(fieldName);
            Element customField = root.addElement(fieldName.getText());
            customField.addAttribute("label", field.getLabel());
            if (field.isDropDownType()) {
                customField.addAttribute("optionId", value + "");
            }
            customField.addText(item.getCustomValue(fieldName));
        }
    }
    // timestamp
    Element timestamp = root.addElement("timestamp");
    timestamp.addText(DateUtils.formatTimeStamp(item.getTimeStamp()));
    // history
    if (item.getHistory() != null) {
        Element historyRoot = root.addElement("history");
        for (History history : item.getHistory()) {
            Element event = historyRoot.addElement("event");
            // index
            event.addAttribute("eventId", (history.getIndex() + 1) + "");
            // logged by
            Element historyLoggedBy = event.addElement("loggedBy");
            // historyLoggedBy.addAttribute("userId", history.getLoggedBy().getId() + "");
            historyLoggedBy.addText(history.getLoggedBy().getName());
            // status
            if (history.getStatus() != null) {
                Element historyStatus = event.addElement("status");
                historyStatus.addAttribute("statusId", history.getStatus() + "");
                historyStatus.addText(history.getStatusValue());
            }
            // assigned to
            if (history.getAssignedTo() != null) {
                Element historyAssignedTo = event.addElement("assignedTo");
                // historyAssignedTo.addAttribute("userId", history.getAssignedTo().getId() + "");
                historyAssignedTo.addText(history.getAssignedTo().getName());
            }
            // attachment
            if (history.getAttachment() != null) {
                Element historyAttachment = event.addElement("attachment");
                historyAttachment.addAttribute("attachmentId", history.getAttachment().getId() + "");
                historyAttachment.addText(history.getAttachment().getFileName());
            }
            // comment
            if (history.getComment() != null) {
                Element historyComment = event.addElement("comment");
                historyComment.addText(history.getComment());
            }
            // timestamp
            Element historyTimestamp = event.addElement("timestamp");
            historyTimestamp.addText(DateUtils.formatTimeStamp(history.getTimeStamp()));
            // custom fields
            List<Field> editable = item.getSpace().getMetadata().getEditableFields();
            for (Field field : editable) {
                Object value = history.getValue(field.getName());
                if (value != null) {
                    Element historyCustomField = event.addElement(field.getName().getText());
                    historyCustomField.addAttribute("label", field.getLabel());
                    if (field.isDropDownType()) {
                        historyCustomField.addAttribute("optionId", value + "");
                    }
                    historyCustomField.addText(history.getCustomValue(field.getName()));
                }
            }
        }
    }
    return root;
}

From source file:itensil.kb.web.KbServlet.java

License:Open Source License

/**
 *  /save//from  w ww  . ja  v  a 2  s .  c  o m
 *
 *  Output:
 *      Wiki save XML
 *
 */
@SuppressWarnings("unchecked")
@ContentType("text/xml")
public void webSave(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String uri = request.getParameter("uri");
    if (!Check.isEmpty(uri)) {
        Document doc = XMLDocument.readStream(request.getInputStream());
        Element reqRoot = doc.getRootElement();

        if ("kb-save".equals(reqRoot.getName())) {
            List<Element> arts;
            boolean hasMods = false;

            RepositoryHelper.beginTransaction();
            uri = RepositoryHelper.resolveUri(uri);
            MutableRepositoryNode node = (MutableRepositoryNode) RepositoryHelper.getNode(uri, true);
            String verStr = request.getParameter("version");
            NodeVersion version = Check.isEmpty(verStr) ? new DefaultNodeVersion()
                    : new DefaultNodeVersion(verStr, false);
            NodeContent content = node.getContent(version);

            Document kbDoc = XMLDocument.readStream(content.getStream());
            Element kbRoot = kbDoc.getRootElement();

            // creates
            arts = reqRoot.elements("create");
            for (Element reqArt : arts) {
                Element kbArt = kbRoot.addElement("article");
                kbArt.addAttribute("id", reqArt.attributeValue("id"));
                kbArt.addAttribute("refId", reqArt.attributeValue("refId"));
                kbArt.addAttribute("categories", reqArt.attributeValue("categories"));
                kbArt.addAttribute("createTime", reqArt.attributeValue("createTime"));
                kbArt.addAttribute("createBy", reqArt.attributeValue("createBy"));
                kbArt.addAttribute("modifyTime", reqArt.attributeValue("modifyTime"));
                kbArt.addAttribute("modifyBy", reqArt.attributeValue("modifyBy"));
                kbArt.addAttribute("layout", reqArt.attributeValue("layout"));
                kbArt.addText(reqArt.getText());
            }

            // modifies
            arts = reqRoot.elements("modify");
            hasMods = arts.size() > 0;
            for (Element reqArt : arts) {
                Element kbArt = getElementById(kbRoot, "article", reqArt.attributeValue("origId"));
                if (kbArt == null) { // try to recover client-proclaimed failed creates
                    kbArt = kbRoot.addElement("article");
                    kbArt.addAttribute("createTime", reqArt.attributeValue("createTime"));
                    kbArt.addAttribute("createBy", reqArt.attributeValue("createBy"));
                }
                kbArt.addAttribute("id", reqArt.attributeValue("id"));
                kbArt.addAttribute("refId", reqArt.attributeValue("refId"));
                kbArt.addAttribute("categories", reqArt.attributeValue("categories"));
                kbArt.addAttribute("modifyTime", reqArt.attributeValue("modifyTime"));
                kbArt.addAttribute("modifyBy", reqArt.attributeValue("modifyBy"));
                kbArt.addAttribute("layout", reqArt.attributeValue("layout"));
                kbArt.setText(reqArt.getText());
            }

            // deletes
            arts = reqRoot.elements("delete");
            hasMods = hasMods || arts.size() > 0;
            for (Element reqArt : arts) {
                Element kbArt = getElementById(kbRoot, "article", reqArt.attributeValue("id"));
                if (kbArt != null) {
                    kbRoot.remove(kbArt);
                }
            }

            NodeProperties props = node.getProperties(version);
            byte buf[] = kbDoc.asXML().getBytes("UTF-8");
            if (hasMods) { // no version on creates
                if (props != null)
                    version = props.getVersion();
                version = RepositoryHelper.nextVersion(node, version, version.isDefault());
            }
            if (props != null) {
                if (hasMods) {
                    props = new DefaultNodeProperties(version, props.getPropertyMap());
                } else {
                    version = props.getVersion();
                }
                String modDate = PropertyHelper.dateString(new Date());
                props.setValue("getlastmodified", modDate);
                props.setValue("getcontentlength", String.valueOf(buf.length));
                props.setValue(PropertyHelper.itensilQName("modifier"),
                        ((User) request.getUserPrincipal()).getUserId());
                props.setValue("getetag",
                        PropertyHelper.makeEtag(node.getUri(), version.getNumber(), modDate, buf.length));
                node.setProperties(props);
            }
            NodeContent modContent = new DefaultNodeContent(buf, version);
            node.setContent(modContent);
            RepositoryHelper.commitTransaction();
        }

    } else {
        throw new NotFoundException("[blank]");
    }
    response.getWriter().print("<ok/>");
}

From source file:itensil.repository.web.ShellServlet.java

License:Open Source License

/**
 *  /getProps//from   w  ww  . j  a va 2s. c  o m
 *
 * Get node properties
 *
 */
@ContentType("text/xml")
public void webGetProps(HttpServletRequest request, HttpServletResponse response) throws Exception {

    String uri = request.getParameter("uri");
    if (!(Check.isEmpty(uri) || uri.length() < 2)) {

        RepositoryHelper.beginTransaction();
        RepositoryHelper.useReadOnly();
        uri = RepositoryHelper.resolveUri(uri);
        MutableRepositoryNode node = getNode(uri);
        NodeProperties props = node.getProperties(new DefaultNodeVersion());
        Document doc = DocumentHelper.createDocument();
        Element root = doc.addElement("properties");
        Namespace davNs = DocumentHelper.createNamespace(PropertyHelper.DEFAULT_PREFIX,
                PropertyHelper.DEFAULT_QNAMESPACE);
        root.add(davNs);
        root.add(DocumentHelper.createNamespace(PropertyHelper.ITENSIL_PREFIX,
                PropertyHelper.ITENSIL_QNAMESPACE));
        root.add(DocumentHelper.createNamespace(PropertyHelper.ITENSIL_ENTITY_PREFIX,
                PropertyHelper.ITENSIL_ENTITY_QNAMESPACE));
        root.addAttribute("uri", node.getUri());
        root.addElement(new org.dom4j.QName("displayname", davNs)).addText(UriHelper.name(uri));
        if (node.isCollection()) {
            root.addElement(new org.dom4j.QName("collection", davNs));
        }
        int nsCount = 0;
        if (props != null) {
            for (Map.Entry<QName, String> prop : props.getPropertyMap().entrySet()) {
                Namespace ns = root.getNamespaceForURI(prop.getKey().getNamespaceURI());
                if (ns == null) {
                    nsCount++;
                    root.addNamespace(prop.getKey().getNamespaceURI(), "ns" + nsCount);
                }
                Element pElem = root.addElement(new org.dom4j.QName(prop.getKey().getLocalPart(), ns));
                String val = prop.getValue();
                if (val != null)
                    pElem.addText(val);
            }
        }
        RepositoryHelper.commitTransaction();
        ServletUtil.setExpired(response);
        doc.write(response.getWriter());
    } else {
        throw new NotFoundException("[blank]");
    }
}

From source file:itensil.web.MethodServlet.java

License:Open Source License

protected void errorXML(HttpServletRequest request, HttpServletResponse response, Throwable th)
        throws IOException {

    Document doc = DocumentHelper.createDocument();
    Element error = doc.addElement("error");
    error.addAttribute("exception", th.getClass().getName());
    Element message = error.addElement("message");
    String msg = th.getMessage();
    message.addText(msg == null ? th.toString() : msg);
    if (logger.isInfoEnabled()) {
        Element details = error.addElement("details");
        StringWriter sw = new StringWriter();
        th.printStackTrace(new PrintWriter(sw));
        details.addCDATA(sw.toString());
    }/*from   w  ww  .  j a  v  a  2s  .  c  o  m*/
    if (th.getCause() != null) {
        error.addAttribute("cause", th.getCause().getClass().getName());
    }
    ServletUtil.noCache(response);
    doc.write(response.getWriter());
}

From source file:itensil.workflow.track.TrackingServlet.java

License:Open Source License

/**
 * Output://w  w  w  .  j  a v  a2  s .  c om
 *      Token Status XML + any conditional options
 */
protected void sendTokenState(Token tok, TrackingXML<Token> track, TrackingManualEval<Token, String> condEval,
        HttpServletResponse response) throws Exception {

    Document doc = DocumentHelper.createDocument();
    Element root = doc.addElement("track");
    track.appendActiveSteps(tok, root);

    // send condinition options
    //   currently limited to single-state tokens, and switch mode=XOR
    Collection<Condition> conds = condEval.getPendingConditions(tok);
    if (conds != null) {
        Element tokElem = root.addElement("token-conditions");
        tokElem.addAttribute("id", tok.getId());
        for (Condition cond : conds) {
            Element ce = tokElem.addElement("condition");
            ce.addAttribute("returnId", cond.getReturnId());
            String str = cond.getInnerText();
            if (str != null)
                ce.addText(cond.getInnerText());
        }
    }

    ServletUtil.setExpired(response);
    //response.setContentType("text/xml");
    doc.write(response.getWriter());
}