List of usage examples for org.dom4j Document addElement
Element addElement(String name);
Element
node with the given name to this branch and returns a reference to the new node. From source file:itensil.workflow.activities.rules.XPathConditionEval.java
License:Open Source License
public static Document getDefaultData(Activity activity, FlowModel model) throws EvalException { Document ddoc = activity.getDataCache(); if (ddoc == null) { Collection<AppElement> elems = model.matchAppElements(ITENSIL_WF_NS, "data"); if (elems.isEmpty()) { // throw new EvalException("Missing default data source"); // supply an empty doc ddoc = DocumentHelper.createDocument(); ddoc.addElement("data"); } else {/* w w w . java 2 s . c om*/ AppElement datElem = elems.iterator().next(); try { String dataUri = UriHelper.absoluteUri(activity.getNode().getUri(), datElem.getAttribute("src")); ddoc = XMLDocument.readStream(RepositoryHelper.loadContent(dataUri)); } catch (Exception e) { throw new EvalException("Data source error", e); } } activity.setDataCache(ddoc); } return ddoc; }
From source file:itensil.workflow.activities.web.ActivityServlet.java
License:Open Source License
/** * /assignedList/*from ww w .ja va2 s . co m*/ * * List Assign Activities * */ @SuppressWarnings("unchecked") @ContentType("text/xml") public void webAssignedList(HttpServletRequest request, HttpServletResponse response) throws Exception { String flow = request.getParameter("flow"); HibernateUtil.beginTransaction(); HibernateUtil.readOnlySession(); User user = (User) request.getUserPrincipal(); String userId = request.getParameter("userId"); boolean includeEnds = "1".equals(request.getParameter("ends")); if (!Check.isEmpty(userId) && UserUtil.isAdmin((AuthenticatedUser) user)) { user = user.getUserSpace().resolve(new DefaultUser(userId)); } Session session = HibernateUtil.getSession(); UserActivities uActivities = new UserActivities(user, session); uActivities.setPageSize(100); Document doc = DocumentHelper.createDocument(); Element root = doc.addElement("list"); List<Activity> aActivities; if (Check.isEmpty(flow)) { aActivities = uActivities.getAssignActivities(0, includeEnds); } else { // resolve flow FlowState fState = (FlowState) session.get(FlowState.class, RepositoryHelper.getNode(flow, false).getParentNodeId()); aActivities = fState == null ? null : uActivities.getFlowAssignActivities(fState, 0, includeEnds); } if (aActivities != null) { for (Activity act : aActivities) { root.add(ActivityXML.display(act)); } } HibernateUtil.commitTransaction(); ServletUtil.setExpired(response); doc.write(response.getWriter()); }
From source file:itensil.workflow.activities.web.ActivityServlet.java
License:Open Source License
/** * /submittedList//from w w w.j ava2 s . com * * List Submit Activities * */ @SuppressWarnings("unchecked") @ContentType("text/xml") public void webSubmittedList(HttpServletRequest request, HttpServletResponse response) throws Exception { String flow = request.getParameter("flow"); HibernateUtil.beginTransaction(); HibernateUtil.readOnlySession(); User user = (User) request.getUserPrincipal(); String userId = request.getParameter("userId"); boolean includeEnds = "1".equals(request.getParameter("ends")); if (!Check.isEmpty(userId) && UserUtil.isAdmin((AuthenticatedUser) user)) { user = user.getUserSpace().resolve(new DefaultUser(userId)); } Session session = HibernateUtil.getSession(); UserActivities uActivities = new UserActivities(user, session); uActivities.setPageSize(100); Document doc = DocumentHelper.createDocument(); Element root = doc.addElement("list"); List<Activity> aActivities; if (Check.isEmpty(flow)) { aActivities = uActivities.getSubmitActivities(0, includeEnds); } else { flow = RepositoryHelper.resolveUri(flow); // resolve flow FlowState fState = (FlowState) session.get(FlowState.class, RepositoryHelper.getNode(flow, false).getParentNodeId()); aActivities = fState == null ? null : uActivities.getFlowSubmitActivities(fState, 0, includeEnds); } if (aActivities != null) { for (Activity act : aActivities) { root.add(ActivityXML.display(act)); } } HibernateUtil.commitTransaction(); ServletUtil.setExpired(response); doc.write(response.getWriter()); }
From source file:itensil.workflow.activities.web.ActivityServlet.java
License:Open Source License
/** * /kidList/* w w w. j a v a2s. c o m*/ * * List Activity Kids * */ @ContentType("text/xml") public void webKidList(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); Document doc = DocumentHelper.createDocument(); Element root = doc.addElement("list"); for (Activity kid : activity.getActiveChildren()) { root.add(ActivityXML.display(kid)); } HibernateUtil.commitTransaction(); ServletUtil.setExpired(response); doc.write(response.getWriter()); }
From source file:itensil.workflow.activities.web.ActivityServlet.java
License:Open Source License
/** * /setList// w w w .j av a 2s . c o m * * Get actvitiy info * * Parameters: * activity - id[] * */ @ContentType("text/xml") public void webSetList(HttpServletRequest request, HttpServletResponse response) throws Exception { HibernateUtil.beginTransaction(); HibernateUtil.readOnlySession(); User user = (User) request.getUserPrincipal(); UserActivities uActivities = new UserActivities(user, HibernateUtil.getSession()); String ids[] = request.getParameterValues("id"); Document resDoc = DocumentHelper.createDocument(); Element resRoot = resDoc.addElement("activities"); for (String id : ids) { Activity activity = uActivities.getActivity(id); if (activity != null) { resRoot.add(ActivityXML.display(activity)); } } HibernateUtil.commitTransaction(); ServletUtil.setExpired(response); resDoc.write(response.getWriter()); }
From source file:itensil.workflow.activities.web.ActivityServlet.java
License:Open Source License
/** * /getPlan// w ww. j a v a 2 s . c o m * * Get activity plan * * Parameters: * activity - id * step - step * */ @ContentType("text/xml") public void webGetPlan(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"); String step = request.getParameter("step"); if (Check.isEmpty(step)) throw new NotFoundException("[blank step]"); Activity activity = uActivities.getActivity(id); ActivityPlan plan = activity.getPlans().get(step); Document doc = DocumentHelper.createDocument(); Element root = doc.addElement("plan"); root.addAttribute("stepId", step); root.addAttribute("activity", activity.getId()); if (plan != null) { root.addAttribute("skip", plan.isSkip() ? "1" : "0"); if (plan.getDueDate() != null) root.addAttribute("dueDate", ActivityXML.dateFmtZ.format(plan.getDueDate())); if (plan.getAssignId() != null) root.addAttribute("assignId", plan.getAssignId()); } HibernateUtil.commitTransaction(); ServletUtil.setExpired(response); doc.write(response.getWriter()); }
From source file:itensil.workflow.activities.web.ActivityServlet.java
License:Open Source License
/** * /flowInfo/*from w w w . j a v a 2 s .co m*/ * * Get flow info * * Parameters: * flow - uri * masterFlow - optional uri * */ @ContentType("text/xml") public void webFlowInfo(HttpServletRequest request, HttpServletResponse response) throws Exception { // resolve the flow String flowUri = request.getParameter("flow"); if (Check.isEmpty(flowUri)) throw new NotFoundException("[blank]"); MutableRepositoryNode flowNode; FlowState flowState = null; FlowModel flowMod = new FlowModel(); HibernateUtil.beginTransaction(); HibernateUtil.readOnlySession(); flowUri = RepositoryHelper.resolveUri(flowUri); String icon = null; try { flowNode = RepositoryHelper.getNode(flowUri, false); flowState = (FlowState) HibernateUtil.getSession().get(FlowState.class, flowNode.getNodeId()); String style = flowNode.getPropertyValue(PropertyHelper.itensilQName("style")); if (Check.isEmpty(style)) { FlowSAXHandler hand = new FlowSAXHandler(flowMod); hand.parse(RepositoryHelper.loadContent(UriHelper.absoluteUri(flowUri, "chart.flow"))); } else { if (style.startsWith("icon:")) icon = style.substring(5); } } catch (NotFoundException nfe) { // not-found, check for master-flow String mastUri = request.getParameter("masterFlow"); if (Check.isEmpty(mastUri)) throw nfe; MutableRepositoryNode mastNode = RepositoryHelper.getNode(mastUri, false); String style = mastNode.getPropertyValue(PropertyHelper.itensilQName("style")); if (Check.isEmpty(style)) { FlowSAXHandler hand = new FlowSAXHandler(flowMod); hand.parse(RepositoryHelper.loadContent(UriHelper.absoluteUri(mastUri, "chart.flow"))); } else { if (style.startsWith("icon:")) icon = style.substring(5); } } if (icon == null) { AppElement activityType = flowMod.matchAppElements("http://itensil.com/workflow", "type").iterator() .next(); if (activityType != null) { icon = activityType.getAttribute("icon"); } } Document doc = DocumentHelper.createDocument(); Element root = doc.addElement("flow-info"); // get icon root.addAttribute("icon", Check.isEmpty(icon) ? "def" : icon); root.addAttribute("active", (flowState != null && flowState.isActive()) ? "1" : "0"); HibernateUtil.commitTransaction(); ServletUtil.cacheTimeout(response, 37); // send info doc.write(response.getWriter()); }
From source file:itensil.workflow.activities.web.ActivityServlet.java
License:Open Source License
/** * /roleList/* w ww . j a v a 2 s . co m*/ * * Get roles * * Parameters: * flowUri * */ @ContentType("text/xml") public void webRoleList(HttpServletRequest request, HttpServletResponse response) throws Exception { HibernateUtil.beginTransaction(); HibernateUtil.readOnlySession(); String activityId = request.getParameter("activity"); Document doc = DocumentHelper.createDocument(); Element root = doc.addElement("role-list"); if (Check.isEmpty(activityId)) { FlowState fState = getFlowState(request.getParameter("flowUri")); for (FlowRole role : fState.getRoles().values()) { Element elem = root.addElement("role"); elem.addAttribute("role", role.getRole()); elem.addAttribute("assignId", role.getAssignId()); } } else { User user = (User) request.getUserPrincipal(); UserActivities uActivities = new UserActivities(user, HibernateUtil.getSession()); Activity activity = uActivities.getActivity(activityId); for (ActivityRole role : activity.getRoles().values()) { Element elem = root.addElement("role"); elem.addAttribute("role", role.getRole()); elem.addAttribute("assignId", role.getAssignId()); } } HibernateUtil.commitTransaction(); ServletUtil.setExpired(response); doc.write(response.getWriter()); }
From source file:itensil.workflow.activities.web.ActivityServlet.java
License:Open Source License
/** * /getTimer/* w w w .j a v a 2 s . co m*/ * * Get an Activity Timer * * Parameters: * activity * tiemrId * */ @ContentType("text/xml") public void webGetTimer(HttpServletRequest request, HttpServletResponse response) throws Exception { String activityId = request.getParameter("activity"); String timerId = request.getParameter("timer"); if (!Check.isEmpty(activityId) && !Check.isEmpty(timerId)) { HibernateUtil.beginTransaction(); HibernateUtil.readOnlySession(); User user = (User) request.getUserPrincipal(); UserActivities uActivities = new UserActivities(user, HibernateUtil.getSession()); Activity activity = uActivities.getActivity(activityId); ActivityTimer att = uActivities.getActivityTimer(activity, timerId); Document doc = DocumentHelper.createDocument(); Element elem = doc.addElement("activity-timer"); elem.addAttribute("activity", activityId); elem.addAttribute("timerId", timerId); if (att != null) { elem.addAttribute("conditional", att.isConditional() ? "1" : "0"); if (att.getAtTime() != null) elem.addAttribute("atTime", ActivityXML.dateFmtZ.format(att.getAtTime())); } else { elem.addAttribute("conditional", "0"); elem.addAttribute("atTime", ""); } HibernateUtil.commitTransaction(); ServletUtil.setExpired(response); doc.write(response.getWriter()); } else { throw new NotFoundException("[blank activity or timer]"); } }
From source file:itensil.workflow.activities.web.ActivityServlet.java
License:Open Source License
/** * /processList/*from w w w . j a va 2 s .co 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()); }