List of usage examples for org.dom4j DocumentHelper createDocument
public static Document createDocument(Element rootElement)
From source file:itensil.workflow.activities.web.ActivityServlet.java
License:Open Source License
/** * /launch//from w w w.j av a 2 s. c o m * * Inject a new activity into a flow. * * Request XML: * * <launch> * * <flow>/path/xxx.flow</flow> * <master-flow>/optional/master-path/xxx.flow</master-flow> * <name>text</name> * <description>text</description> * <start>date</start> * <end>date</end> * <priority>number</priority> * <parent>activity.id</parent> * <parentStep>step.id</parentStep> * <project>id</project> * <meet>0</meet> * * <!-- maybe this for more file inputs? --> * <file name="...">uri</file> ... * </launch> * */ @SuppressWarnings("unchecked") @ContentType("text/xml") public void webLaunch(HttpServletRequest request, HttpServletResponse response) throws Exception { Document doc = XMLDocument.readStream(request.getInputStream()); Element root = doc.getRootElement(); if ("launch".equals(root.getName())) { HibernateUtil.beginTransaction(); User user = (User) request.getUserPrincipal(); User subUser = null; String submitId = root.elementTextTrim("submitId"); if (!Check.isEmpty(submitId) && UserUtil.isAdmin((AuthenticatedUser) user)) { user = user.getUserSpace().resolve(new DefaultUser(submitId)); subUser = user; } UserActivities uActivities = new UserActivities(user, HibernateUtil.getSession()); boolean isMeet = "1".equals(root.elementTextTrim("meet")); String name = root.elementTextTrim("name"); if (Check.isEmpty(name)) throw new NotFoundException("[blank activity]"); // resolve the flow String flowUri = root.elementTextTrim("flow"); String path = root.elementTextTrim("path"); if (!Check.isEmpty(flowUri)) { if (!flowUri.startsWith("/")) flowUri = UriHelper.absoluteUri(Check.isEmpty(path) ? "/home/process" : path, flowUri); flowUri = RepositoryHelper.resolveUri(flowUri); } else { flowUri = UriHelper.absoluteUri( RepositoryHelper.getPrimaryRepository().getMount() + (isMeet ? "/meeting" : "/process"), UriHelper.filterName(name)); // auto meeting folder if (isMeet) { String meetFolder = RepositoryHelper.getPrimaryRepository().getMount() + "/meeting"; try { RepositoryHelper.getNode(meetFolder, false); } catch (NotFoundException nfe) { RepositoryHelper.createCollection(meetFolder); } } flowUri = RepositoryHelper.getAvailableUri(flowUri); } HashMap<String, String> roles = new HashMap<String, String>(); // Pre-assign some roles for (Element rolEl : (List<Element>) root.elements("role")) { String role = rolEl.attributeValue("role"); String assignId = rolEl.attributeValue("assignId"); if (role != null) role = role.trim(); if (!Check.isEmpty(role) && !Check.isEmpty(assignId)) { roles.put(role, assignId); } } String parentId = root.elementTextTrim("parent"); String parentStep = root.elementTextTrim("parentStep"); // Launch it! Activity activityEnt = uActivities.launch(name, root.elementTextTrim("description"), flowUri, RepositoryHelper.resolveUri(root.elementTextTrim("master-flow")), parentId, root.elementTextTrim("project"), root.elementTextTrim("contextGroup"), ActivityXML.parseDate(root.elementTextTrim("dueDate")), roles); // is the submit user different than the thread user? if (subUser != null) { ((MutableRepositoryNode) activityEnt.getNode()) .grantPermission(new DefaultNodePermission(subUser, DefaultNodePermission.WRITE, true)); } // Connect the parent step... this probably shouldn't be in the servlet if (!Check.isEmpty(parentStep) && !Check.isEmpty(parentId)) { Activity parAct = uActivities.getActivity(parentId); ActivityStepState aStat = parAct.getStates().get(parentStep); if (aStat != null) { aStat.setSubActivityId(activityEnt.getId()); HibernateUtil.getSession().update(aStat); } } if (isMeet) { // flag repo node MutableRepositoryNode actRepoNode = (MutableRepositoryNode) activityEnt.getNode(); HashMap<QName, String> propMap = new HashMap<QName, String>(1); propMap.put(PropertyHelper.itensilQName("meet-setup"), "1"); PropertyHelper.setNodeValues(actRepoNode, propMap); // throw out initial end state ActivityStepState endState = null; for (ActivityStepState actState : activityEnt.getStates().values()) { if (actState.getSubState() == SubState.ENTER_END) { endState = actState; break; } } if (endState != null) { activityEnt.getStates().remove(endState.getStepId()); HibernateUtil.getSession().delete(endState); } } // return activity's status Document retDoc = DocumentHelper.createDocument(ActivityXML.display(activityEnt)); HibernateUtil.commitTransaction(); retDoc.write(response.getWriter()); } }
From source file:itensil.workflow.activities.web.ActivityServlet.java
License:Open Source License
/** * /submit/*from w w w.j a v a 2 s . c om*/ * * Submit an Activity for flow routing * * Request XML: * <submit> * <activity>activity.id</activity> * <step>step.id</step> * <expr>expression</expr> * * <!-- maybe this for more wiki inputs? --> * <data name="...">value</data> ... * </submit> */ @SuppressWarnings("unchecked") @ContentType("text/xml") public void webSubmit(HttpServletRequest request, HttpServletResponse response) throws Exception { Document doc = XMLDocument.readStream(request.getInputStream()); Element root = doc.getRootElement(); if ("submit".equals(root.getName())) { User user = (User) request.getUserPrincipal(); HibernateUtil.beginTransaction(); Session session = HibernateUtil.getSession(); UserActivities uActivities = new UserActivities(user, session); // resolve the activity String activityId = root.elementTextTrim("activity"); Activity activityEnt = uActivities.getActivity(activityId); if (activityEnt == null) { throw new NotFoundException(activityId); } String step = root.elementTextTrim("step"); if (Check.isEmpty(step)) { throw new NotFoundException("[empty step]"); } HashMap<String, String> submitValues = null; Element data = root.element("rule-data"); if (data != null) { List<Element> kids = data.elements(); if (!kids.isEmpty()) { submitValues = new HashMap<String, String>(); for (Element attrElem : kids) { submitValues.put(attrElem.getName(), attrElem.getText()); } } } Element swPath = root.element("switch-path"); String resTx; if (swPath != null && swPath.hasContent()) { resTx = uActivities.exitSwitch(activityEnt, step, swPath.getTextTrim()); } else { resTx = uActivities.submit(activityEnt, step, submitValues, root.elementTextTrim("expr")); } // return activity's status Element actElem = ActivityXML.display(activityEnt); actElem.addAttribute("resTx", resTx); Document retDoc = DocumentHelper.createDocument(actElem); HibernateUtil.commitTransaction(); retDoc.write(response.getWriter()); } }
From source file:itensil.workflow.activities.web.ActivityServlet.java
License:Open Source License
/** * /undo// w w w. j a va 2s .c o m * * Undo last activity event * * Parameters: * activity - id * */ @ContentType("text/xml") public void webUndo(HttpServletRequest request, HttpServletResponse response) throws Exception { HibernateUtil.beginTransaction(); User user = (User) request.getUserPrincipal(); UserActivities uActivities = new UserActivities(user, HibernateUtil.getSession()); String id = request.getParameter("id"); String txId = request.getParameter("txId"); if (Check.isEmpty(txId)) { throw new NotFoundException("[Transaction not found]"); } Activity activityEnt = uActivities.getActivity(id); if (activityEnt == null) { throw new NotFoundException(id); } uActivities.undo(activityEnt, txId); Element iElem = ActivityXML.display(activityEnt); HibernateUtil.commitTransaction(); Document doc = DocumentHelper.createDocument(iElem); ServletUtil.setExpired(response); doc.write(response.getWriter()); }
From source file:itensil.workflow.activities.web.ActivityServlet.java
License:Open Source License
/** * /sendToFlow//from w w w.j a v a 2 s . c o m * * Move activity to the begining of a different process * * Parameters: * activity - id * flow * master-flow */ @ContentType("text/xml") public void webSendToFlow(HttpServletRequest request, HttpServletResponse response) throws Exception { Map<String, String> params = RequestUtil.readParameters(request, new String[] { "activity", "flow", "master-flow" }); HibernateUtil.beginTransaction(); User user = (User) request.getUserPrincipal(); UserActivities uActivities = new UserActivities(user, HibernateUtil.getSession()); String id = params.get("activity"); Activity activityEnt = uActivities.getActivity(id); activityEnt = uActivities.sendToFlow(activityEnt, RepositoryHelper.resolveUri(params.get("flow")), RepositoryHelper.resolveUri(params.get("master-flow"))); Element iElem = ActivityXML.display(activityEnt); HibernateUtil.commitTransaction(); Document doc = DocumentHelper.createDocument(iElem); ServletUtil.setExpired(response); doc.write(response.getWriter()); }
From source file:itensil.workflow.activities.web.ActivityServlet.java
License:Open Source License
/** * /rebuildFolder//from ww w . ja v a2 s . c o m * * Rebuild an activity's folder * * Parameters: * activity - id * */ @ContentType("text/xml") public void webRebuildFolder(HttpServletRequest request, HttpServletResponse response) throws Exception { HibernateUtil.beginTransaction(); User user = (User) request.getUserPrincipal(); UserActivities uActivities = new UserActivities(user, HibernateUtil.getSession()); String id = request.getParameter("id"); Activity activity = uActivities.getActivity(id); if (activity == null) { throw new NotFoundException(id); } try { activity = uActivities.rebuildActivityFolder(activity); } catch (NotFoundException nfe) { response.getWriter().print("<missing-flow/>\n"); } Element iElem = ActivityXML.display(activity); try { iElem.addAttribute("uri", activity.getNode().getUri()); } catch (NotFoundException nfe) { throw new ActivityInvalidException("Missing repository node", nfe); } HibernateUtil.commitTransaction(); Document doc = DocumentHelper.createDocument(iElem); ServletUtil.setExpired(response); doc.write(response.getWriter()); }
From source file:itensil.workflow.activities.web.ActivityServlet.java
License:Open Source License
/** * /actvitiyInfo// w w w .j av a 2s. co m * * Get actvitiy info * * Parameters: * activity - id * */ @ContentType("text/xml") public void webActivityInfo(HttpServletRequest request, HttpServletResponse response) throws Exception { HibernateUtil.beginTransaction(); HibernateUtil.readOnlySession(); User user = (User) request.getUserPrincipal(); UserActivities uActivities = new UserActivities(user, HibernateUtil.getSession()); String id = request.getParameter("id"); Activity activity = uActivities.getActivity(id); if (activity == null) { throw new NotFoundException(id); } Element iElem = ActivityXML.display(activity); try { iElem.addAttribute("uri", activity.getNode().getUri()); } catch (NotFoundException nfe) { throw new ActivityInvalidException("Missing repository node", nfe); } if (activity.getDescription() == null) { iElem.addAttribute("description", ""); } if (activity.getContextGroupId() == null) { iElem.addAttribute("contextGroup", ""); } HibernateUtil.commitTransaction(); Document doc = DocumentHelper.createDocument(iElem); ServletUtil.setExpired(response); doc.write(response.getWriter()); }
From source file:itensil.workflow.activities.web.ActivityServlet.java
License:Open Source License
/** * /getLogsAndPlans//from w w w . ja v a2 s . co m * * Get actvitiy info * * Parameters: * activity - id * */ @ContentType("text/xml") public void webGetLogsAndPlans(HttpServletRequest request, HttpServletResponse response) throws Exception { HibernateUtil.beginTransaction(); User user = (User) request.getUserPrincipal(); UserActivities uActivities = new UserActivities(user, HibernateUtil.getSession()); String id = request.getParameter("id"); Activity activity = uActivities.getActivity(id); if (activity == null) { throw new NotFoundException(id); } Element iElem = ActivityXML.display(activity); try { iElem.addAttribute("uri", activity.getNode().getUri()); } catch (NotFoundException nfe) { throw new ActivityInvalidException("Missing repository node", nfe); } Pair<Date, Date> minMaxDates = new Pair<Date, Date>(activity.getStartDate(), activity.getDueDate()); iElem.add(ActivityXML.logs(activity, minMaxDates)); iElem.add(ActivityXML.plans(activity, minMaxDates)); HibernateUtil.commitTransaction(); if (minMaxDates.first == null) minMaxDates.first = new Date(); if (minMaxDates.second == null) minMaxDates.second = new Date(); if (minMaxDates.first.after(minMaxDates.second)) { Date hd = minMaxDates.first; minMaxDates.first = minMaxDates.second; minMaxDates.second = hd; } iElem.addAttribute("minDate", ActivityXML.dateFmtZ.format(minMaxDates.first)); iElem.addAttribute("maxDate", ActivityXML.dateFmtZ.format(minMaxDates.second)); Document doc = DocumentHelper.createDocument(iElem); ServletUtil.setExpired(response); doc.write(response.getWriter()); }
From source file:mesquite.chromaseq.lib.ChromaseqInfoFile.java
License:Open Source License
public ChromaseqInfoFile() { rootElement = DocumentHelper.createElement("mesquite"); chromaseqElement = rootElement.addElement("chromaseq"); doc = DocumentHelper.createDocument(rootElement); chromaseqElement.addAttribute("version", "" + infoFileVersion); processedFolderElement = chromaseqElement.addElement("processedFolder"); }
From source file:mesquite.chromaseq.lib.SequenceProfile.java
License:Open Source License
public String getXML() { Element mesquiteElement = DocumentHelper.createElement("mesquite"); Document doc = DocumentHelper.createDocument(mesquiteElement); Element sequenceProfileElement = DocumentHelper.createElement("sequenceProfile"); mesquiteElement.add(sequenceProfileElement); XMLUtil.addFilledElement(sequenceProfileElement, "version", "1"); Element boundedByTokensElement = DocumentHelper.createElement("boundedByTokens"); sequenceProfileElement.add(boundedByTokensElement); XMLUtil.addFilledElement(boundedByTokensElement, "name", name); XMLUtil.addFilledElement(boundedByTokensElement, "description", DocumentHelper.createCDATA(description)); XMLUtil.addFilledElement(boundedByTokensElement, "location", DocumentHelper.createCDATA(location)); XMLUtil.addFilledElement(boundedByTokensElement, "moltype", DocumentHelper.createCDATA(moltype)); XMLUtil.addFilledElement(boundedByTokensElement, "productName", DocumentHelper.createCDATA(productName)); XMLUtil.addFilledElement(boundedByTokensElement, "seqIDSuffix", DocumentHelper.createCDATA(seqIDSuffix)); XMLUtil.addFilledElement(boundedByTokensElement, "gcode", DocumentHelper.createCDATA("" + gcode)); XMLUtil.addFilledElement(boundedByTokensElement, "note", DocumentHelper.createCDATA("" + note)); // XMLUtil.addFilledElement(boundedByTokensElement, "CDS",DocumentHelper.createCDATA(MesquiteBoolean.toTrueFalseString(CDS))); return XMLUtil.getDocumentAsXMLString(doc); }
From source file:mesquite.chromaseq.SampleAndPrimerFileNameParser.ChromFileNameParsing.java
License:Open Source License
public String getXML() { Element mesquiteElement = DocumentHelper.createElement("mesquite"); Document doc = DocumentHelper.createDocument(mesquiteElement); Element nameRules = DocumentHelper.createElement("chromFileNameParsingRules"); mesquiteElement.add(nameRules);//from w w w .j a v a2s.c om XMLUtil.addFilledElement(nameRules, "version", "1"); Element boundedByTokensElement = DocumentHelper.createElement("boundedByTokens"); nameRules.add(boundedByTokensElement); XMLUtil.addFilledElement(boundedByTokensElement, "name", name); XMLUtil.addFilledElement(boundedByTokensElement, "sampleCodeFirst", MesquiteBoolean.toTrueFalseString(sampleCodeFirst)); XMLUtil.addFilledElement(boundedByTokensElement, "dnaCodeStartToken", DocumentHelper.createCDATA(dnaCodeStartToken)); XMLUtil.addFilledElement(boundedByTokensElement, "dnaCodeEndToken", DocumentHelper.createCDATA(dnaCodeEndToken)); XMLUtil.addFilledElement(boundedByTokensElement, "dnaCodeSuffixToken", DocumentHelper.createCDATA(dnaCodeSuffixToken)); XMLUtil.addFilledElement(boundedByTokensElement, "dnaCodeRemovalToken", DocumentHelper.createCDATA(dnaCodeRemovalToken)); XMLUtil.addFilledElement(boundedByTokensElement, "primerStartToken", DocumentHelper.createCDATA(primerStartToken)); XMLUtil.addFilledElement(boundedByTokensElement, "primerEndToken", DocumentHelper.createCDATA(primerEndToken)); return XMLUtil.getDocumentAsXMLString(doc); }