Example usage for org.dom4j DocumentHelper createDocument

List of usage examples for org.dom4j DocumentHelper createDocument

Introduction

In this page you can find the example usage for org.dom4j DocumentHelper createDocument.

Prototype

public static Document createDocument() 

Source Link

Usage

From source file:itensil.workflow.activities.web.ActivityServlet.java

License:Open Source License

/**
 *  /processList//from w  ww .j  a v  a 2s .  c  o m
 *
 * Get a list of process and include their icons
 *
 * Parameters:
 *  uri - processes folder uri
 *
 */
@ContentType("text/xml")
public void webProcessList(HttpServletRequest request, HttpServletResponse response) throws Exception {

    RepositoryHelper.beginTransaction();
    RepositoryHelper.useReadOnly();
    String uri = request.getParameter("uri");
    Document doc = DocumentHelper.createDocument();
    Element root = doc.addElement("list");
    if (!(Check.isEmpty(uri) || uri.length() < 2)) {
        uri = RepositoryHelper.resolveUri(uri);
        MutableRepositoryNode node = RepositoryHelper.getNode(uri, false);
        if (!node.isCollection()) {
            node = (MutableRepositoryNode) node.getParent();
        }
        String pUri = node.getUri();
        root.addAttribute("uri", pUri);
        for (RepositoryNode kid : node.getChildren()) {
            if (kid.isCollection()) {
                MutableRepositoryNode mkid = (MutableRepositoryNode) kid;
                String kName = UriHelper.localizeUri(pUri, kid.getUri());
                Element rnElem = root.addElement("node");
                rnElem.addAttribute("uri", kName);
                rnElem.addAttribute("owner", kid.getOwner().getUserId());
                String style = mkid.getPropertyValue(PropertyHelper.itensilQName("style"));
                rnElem.addAttribute("style", Check.isEmpty(style) ? "icon:def" : style);
                String val;

                val = mkid.getPropertyValue(PropertyHelper.itensilQName("description"));
                rnElem.addAttribute("description", val == null ? "" : val);

                val = mkid.getPropertyValue(PropertyHelper.defaultQName("getlastmodified"));
                rnElem.addAttribute("lastmodified", val == null ? "" : val);
            }
        }

    }
    RepositoryHelper.commitTransaction();
    ServletUtil.cacheTimeout(response, 37);
    doc.write(response.getWriter());
}

From source file:itensil.workflow.activities.web.ActivityServlet.java

License:Open Source License

/**
 *  /activeProcesses/*from ww  w .j av  a 2 s  . c  o  m*/
 *
 * Get a list of active process and include their icons
 *
 *
 */
@ContentType("text/xml")
public void webActiveProcesses(HttpServletRequest request, HttpServletResponse response) throws Exception {

    RepositoryHelper.beginTransaction();
    RepositoryHelper.useReadOnly();
    Document doc = DocumentHelper.createDocument();
    Element root = doc.addElement("list");
    User user = (User) request.getUserPrincipal();
    UserActivities uActivities = new UserActivities(user, HibernateUtil.getSession());

    root.addAttribute("uri",
            UriHelper.absoluteUri(RepositoryHelper.getPrimaryRepository().getMount(), "process"));

    for (RepositoryNode kid : uActivities.getActiveFlows(22)) {
        if (kid.isCollection()) {
            String kName = UriHelper.name(kid.getUri());
            Element rnElem = root.addElement("node");
            rnElem.addAttribute("uri", kName);
            rnElem.addAttribute("owner", kid.getOwner().getUserId());
            String style = ((MutableRepositoryNode) kid).getPropertyValue(PropertyHelper.itensilQName("style"));
            rnElem.addAttribute("style", Check.isEmpty(style) ? "icon:def" : style);
        }
    }

    RepositoryHelper.commitTransaction();
    ServletUtil.cacheTimeout(response, 13);
    doc.write(response.getWriter());
}

From source file:itensil.workflow.activities.web.ActivityServlet.java

License:Open Source License

/**
 *  /modifiedProcesses// ww w. j av a 2s . com
 *
 * Get a list of active process and include their icons
 *
 *
 */
@ContentType("text/xml")
public void webModifiedProcesses(HttpServletRequest request, HttpServletResponse response) throws Exception {
    RepositoryHelper.beginTransaction();
    RepositoryHelper.useReadOnly();
    Document doc = DocumentHelper.createDocument();
    Element root = doc.addElement("list");

    NodePermission creatPerm = DefaultNodePermission.createPermission(request.getUserPrincipal());
    Repository repo = RepositoryHelper.getPrimaryRepository();
    String procUri = UriHelper.absoluteUri(repo.getMount(), "process");
    root.addAttribute("uri", procUri);
    RepositoryNode procFold = repo.getNodeByUri(procUri, false);
    int count = 0;
    for (MutableRepositoryNode kid : repo.getRecentlyModified(
            UriHelper.absoluteUri(repo.getMount(), "process/%/chart.flow"), 22 * 2, creatPerm)) {

        RepositoryNode fold = kid.getParent();
        if (fold.getParentNodeId().endsWith(procFold.getNodeId())) {
            String kName = UriHelper.name(fold.getUri());
            Element rnElem = root.addElement("node");
            rnElem.addAttribute("uri", kName);
            rnElem.addAttribute("owner", fold.getOwner().getUserId());
            String style = ((MutableRepositoryNode) fold)
                    .getPropertyValue(PropertyHelper.itensilQName("style"));
            rnElem.addAttribute("style", Check.isEmpty(style) ? "icon:def" : style);
            count++;
            if (count >= 22)
                break;
        }
    }

    RepositoryHelper.commitTransaction();
    ServletUtil.cacheTimeout(response, 13);
    doc.write(response.getWriter());
}

From source file:itensil.workflow.activities.web.ActivityServlet.java

License:Open Source License

/**
 *  /modifiedCourses//  w  ww. j  av a2 s  . c o  m
 *
 * Get a list of active process and include their icons
 *
 *
 */
@ContentType("text/xml")
public void webModifiedCourses(HttpServletRequest request, HttpServletResponse response) throws Exception {
    RepositoryHelper.beginTransaction();
    RepositoryHelper.useReadOnly();
    Document doc = DocumentHelper.createDocument();
    Element root = doc.addElement("list");

    NodePermission creatPerm = DefaultNodePermission.createPermission(request.getUserPrincipal());
    Repository repo = RepositoryHelper.getPrimaryRepository();
    String procUri = UriHelper.absoluteUri(repo.getMount(), "course");
    root.addAttribute("uri", procUri);
    RepositoryNode procFold = repo.getNodeByUri(procUri, false);
    int count = 0;
    for (MutableRepositoryNode kid : repo.getRecentlyModified(
            UriHelper.absoluteUri(repo.getMount(), "course/%/chart.flow"), 22 * 2, creatPerm)) {

        RepositoryNode fold = kid.getParent();
        if (fold.getParentNodeId().endsWith(procFold.getNodeId())) {
            String kName = UriHelper.name(fold.getUri());
            Element rnElem = root.addElement("node");
            rnElem.addAttribute("uri", kName);
            rnElem.addAttribute("owner", fold.getOwner().getUserId());
            String style = ((MutableRepositoryNode) fold)
                    .getPropertyValue(PropertyHelper.itensilQName("style"));
            rnElem.addAttribute("style", Check.isEmpty(style) ? "icon:def" : style);
            count++;
            if (count >= 22)
                break;
        }
    }

    RepositoryHelper.commitTransaction();
    ServletUtil.cacheTimeout(response, 13);
    doc.write(response.getWriter());
}

From source file:itensil.workflow.activities.web.ActivityServlet.java

License:Open Source License

@SuppressWarnings("unchecked")
@ContentType("text/xml")
public void webGanttSchedule(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String activityId = request.getParameter("activity");
    String stepId = request.getParameter("step");
    String startStr = request.getParameter("startDate");
    String dueStr = request.getParameter("dueDate");
    if (!Check.isEmpty(activityId)) {
        Date startDate = ActivityXML.parseDate(startStr);
        Date dueDate = ActivityXML.parseDate(dueStr);
        // TODO schedule call back

        Document doc = DocumentHelper.createDocument();
        Element root = doc.addElement("step-dates");
        root.addAttribute("activity", activityId);
        root.addAttribute("forStep", stepId);
        // add Step sub-elements

        ServletUtil.setExpired(response);

        doc.write(response.getWriter());

    } else {/*from  w  w  w.  j a v a 2  s .  c  o  m*/
        throw new NotFoundException("[blank]");
    }
}

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

License:Open Source License

/**
 *  /simStatus/*from w  w  w  .  j av  a  2 s  . c  om*/
 *
 *  Send simulator status
 *
 *  Output:
 *      Status XML
 */
@SuppressWarnings("unchecked")
@ContentType("text/xml")
public void webSimStatus(HttpServletRequest request, HttpServletResponse response) throws Exception {

    HttpSession session = request.getSession();
    SimulatorStateStore<Token, String> store = (SimulatorStateStore<Token, String>) session
            .getAttribute("simModel");

    TrackingXML<Token> track = new TrackingXML<Token>(store, store);
    Document doc = DocumentHelper.createDocument();
    track.appendAllActiveSteps(doc);

    ServletUtil.setExpired(response);
    doc.write(response.getWriter());
}

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

License:Open Source License

/**
 * Output://from   ww  w  .  j  av  a2  s . co  m
 *      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());
}

From source file:itslearning.platform.restapi.sdk.learningtoolapp.LearningObjectServicetRestClient.java

private String serializeLearningObjectInstanceUserReportToXML(LearningObjectInstanceUserReport userReport) {
    Document document = DocumentHelper.createDocument();

    Element root = document.addElement("LearningObjectInstanceUserReport");
    root.setQName(new QName("LearningObjectInstanceUserReport",
            new Namespace("", EntityConstants.NAMESPACE_ENTITIES)));
    root.add(new Namespace("i", "http://www.w3.org/2001/XMLSchema-instance"));

    fillLearningObjectInstanceUserReportXmlElement(root, userReport);

    return root.asXML();
}

From source file:itslearning.platform.restapi.sdk.learningtoolapp.LearningObjectServicetRestClient.java

private String serializeLearningObjectInstanceUserReportCommentOnCommentToXML(
        LearningObjectInstanceUserReportCommentOnComment reportComment) {
    Document document = DocumentHelper.createDocument();

    Element root = document.addElement("LearningObjectInstanceUserReportCommentOnComment");
    root.setQName(new QName("LearningObjectInstanceUserReportCommentOnComment",
            new Namespace("", EntityConstants.NAMESPACE_ENTITIES)));
    root.add(new Namespace("i", "http://www.w3.org/2001/XMLSchema-instance"));

    if (reportComment.getUserId() != null) {
        root.addElement("UserId").addText(reportComment.getUserId().toString());
    }//from   w  ww . ja  va2  s. c  o  m
    if (reportComment.getCommentText() != null) {
        root.addElement("CommentText").addText(reportComment.getCommentText());
    }
    if (reportComment.getCommentSyncKey() != null) {
        root.addElement("CommentSyncKey").addText(reportComment.getCommentSyncKey());
    }
    if (reportComment.getModifiedUtc() != null) {
        root.addElement("ModifiedUtc").addText(sdf.format(reportComment.getModifiedUtc()));
    }
    return root.asXML();
}

From source file:itslearning.platform.restapi.sdk.learningtoolapp.LearningObjectServicetRestClient.java

private String serializeNotificationToWrappedXML(Notification notification) {
    Document document = DocumentHelper.createDocument();

    Element root = document.addElement("notification");
    root.add(new Namespace("i", "http://www.w3.org/2001/XMLSchema-instance"));
    root.add(new Namespace("a", EntityConstants.NAMESPACE_ENTITIES));

    if (notification.getLaunchParameter() != null) {
        root.addElement("a:LaunchParameter").addText(notification.getLaunchParameter().toString());
    }/* w  w w. j a  v a 2  s.c  om*/
    if (notification.getLocalizedMessages() != null) {
        Element n = root.addElement("a:LocalizedMessages");
        n.add(new Namespace("b", EntityConstants.NAMESPACE_ARRAYS));

        HashMap<String, String> messages = notification.getLocalizedMessages();
        for (String lang : messages.keySet()) {
            Element messageKeyValuePair = n.addElement("b:KeyValueOfstringstring");
            messageKeyValuePair.addElement("b:Key").addText(lang);
            messageKeyValuePair.addElement("b:Value").addText(messages.get(lang));
        }
    }
    if (notification.getMessage() != null) {
        root.addElement("a:Message").addText(notification.getMessage());
    }
    if (notification.getReciverPermission() != null) {
        root.addElement("a:ReciverPermission").addText(notification.getReciverPermission().toString());
    }

    return root.asXML();
}