List of usage examples for org.dom4j Element add
void add(Namespace namespace);
Namespace
to this element. From source file:io.mashin.oep.model.node.action.extended.CustomActionNode.java
License:Open Source License
@Override public void write(Element parentNode) { super.write(parentNode); Element element = (Element) hpdlModel.get(); String xmlContent = xml.getStringValue(); if (xmlContent.isEmpty()) { xmlContent = "<EMPTY_CUSTOM_NODE xmlns=\"uri:oozie:EMPTY_CUSTOM_NODE:0.1\"/>"; }//w ww .j a v a2 s .c om try { element.add(DocumentHelper.parseText(xmlContent).getRootElement()); } catch (Throwable t) { element.setText(xmlContent); } writeConnections(element); }
From source file:itensil.kb.web.KbServlet.java
License:Open Source License
/** * /listByRef/*w w w. j a v a 2s . com*/ * * Output: * article header list * */ @SuppressWarnings("unchecked") @ContentType("text/xml") public void webListByRef(HttpServletRequest request, HttpServletResponse response) throws Exception { String uri = request.getParameter("uri"); String refId = request.getParameter("refId"); if (!Check.isEmpty(uri) && !Check.isEmpty(refId)) { RepositoryHelper.beginTransaction(); RepositoryHelper.useReadOnly(); uri = RepositoryHelper.resolveUri(uri); Document doc = XMLDocument.readStream(RepositoryHelper.loadContent(uri)); Document resDoc = DocumentHelper.createDocument(); Element resRoot = resDoc.addElement("articles"); for (Element elem : (List<Element>) doc.getRootElement().elements("article")) { if (refId.equals(elem.attributeValue("refId"))) { // just the node, no content elem.setText(""); resRoot.add(elem.createCopy()); } } RepositoryHelper.commitTransaction(); if (resRoot.hasContent()) ServletUtil.cacheTimeout(response, 27); else ServletUtil.noCache(response); resDoc.write(response.getWriter()); } else { throw new NotFoundException("[blank]"); } }
From source file:itensil.repository.web.ShellServlet.java
License:Open Source License
/** * /getProps/*w w w .ja v a 2 s . 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.workflow.activities.web.ActivityServlet.java
License:Open Source License
/** * /assignedList//from www . j ava 2 s .c om * * 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// ww w .j av a 2 s. c o m * * 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/*from ww w. jav 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//from ww w.ja v 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
/** * /getLogsAndPlans/*from w w w . j av a 2 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: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()); }// www . jav a 2s .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(); }