List of usage examples for org.dom4j DocumentHelper createDocument
public static Document createDocument()
From source file:itensil.repository.web.ShellServlet.java
License:Open Source License
/** * /status/*w w w . j a v a 2 s. c o m*/ * * Node status, including locks and history * */ @ContentType("text/xml") public void webStatus(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); Document doc = DocumentHelper.createDocument(); Element root = doc.addElement("status"); root.addAttribute("uri", node.getUri()); // locks for (NodeLock lock : node.getLocks()) { Element lockElem = root.addElement("lock"); lockElem.addAttribute("ower", lock.getOwner().getUserId()); lockElem.addAttribute("exclusive", lock.isExclusive() ? "1" : "0"); } // versions for (NodeVersion ver : node.getVersions()) { Element verElem = root.addElement("version"); verElem.addAttribute("default", ver.isDefault() ? "1" : "0"); verElem.addAttribute("label", ver.getLabel() != null ? ver.getLabel() : ""); verElem.addAttribute("number", ver.getNumber()); NodeProperties props = node.getProperties(ver); if (props != null) { verElem.addAttribute("time", props.getValue("getlastmodified")); verElem.addAttribute("modifier", props.getValue(PropertyHelper.itensilQName("modifier"))); } } RepositoryHelper.commitTransaction(); ServletUtil.setExpired(response); doc.write(response.getWriter()); } else { throw new NotFoundException("[blank]"); } }
From source file:itensil.repository.web.ShellServlet.java
License:Open Source License
/** * /xslt//w w w . j av a 2s . c o m * * XSL Transform * * srcUri - input xml file * dstUri - output html/xml/text file * xslUri - style document */ @ContentType("text/xml") public void webXslt(HttpServletRequest request, HttpServletResponse response) throws Exception { Map<String, String> params = RequestUtil.readParameters(request, new String[] { "srcUri", "dstUri", "xslUri" }); String xslUri = params.get("xslUri"); String srcUri = params.get("srcUri"); String dstUri = params.get("dstUri"); if (!(Check.isEmpty(srcUri) || srcUri.length() < 2 || Check.isEmpty(dstUri) || dstUri.length() < 2 || Check.isEmpty(xslUri) || xslUri.length() < 2)) { xslUri = RepositoryHelper.resolveUri(xslUri); srcUri = RepositoryHelper.resolveUri(srcUri); dstUri = RepositoryHelper.resolveUri(dstUri); RepositoryHelper.beginTransaction(); Repository repository = RepositoryHelper.getRepository(dstUri); MutableRepositoryNode node; NodeProperties props; NodeVersion version = new DefaultNodeVersion(); try { node = repository.getNodeByUri(dstUri, true); if (node.isCollection()) throw new AccessDeniedException(dstUri, "collection"); props = node.getProperties(version); if (props != null) { version = RepositoryHelper.nextVersion(node, props.getVersion(), true); props = new DefaultNodeProperties(version, props.getPropertyMap()); } else { props = new DefaultNodeProperties(version); } } catch (NotFoundException nfe) { node = repository.createNode(dstUri, false, (User) request.getUserPrincipal()); props = new DefaultNodeProperties(version); } ByteArrayOutputStream ostream = new ByteArrayOutputStream(1024 * 16); StreamResult result = new StreamResult(ostream); ExslTransform.transformXML(result, new StreamSource(RepositoryHelper.loadContent(srcUri)), new StreamSource(RepositoryHelper.loadContent(xslUri)), UriHelper.getParent(srcUri), null); NodeContent content = new DefaultNodeContent(ostream.toByteArray(), version); // properties String mime = getServletContext().getMimeType(dstUri); if (mime == null) mime = "application/octet-stream"; PropertyHelper.setStandardProperties(props, dstUri, mime, content.getLength()); node.setProperties(props); node.setContent(content); RepositoryHelper.commitTransaction(); Document doc = DocumentHelper.createDocument(); doc.addElement("ok").addAttribute("result", node.getUri()); ServletUtil.setExpired(response); doc.write(response.getWriter()); } }
From source file:itensil.repository.web.ShellServlet.java
License:Open Source License
/** * /copy// w w w .j a v a2 s . c om * * Copy a node * */ @ContentType("text/xml") public void webCopy(HttpServletRequest request, HttpServletResponse response) throws Exception { Map<String, String> params = RequestUtil.readParameters(request, new String[] { "srcUri", "dstUri", "description" }); String description = params.get("description"); String srcUri = params.get("srcUri"); String dstUri = params.get("dstUri"); if (!(Check.isEmpty(srcUri) || srcUri.length() < 2 || Check.isEmpty(dstUri) || dstUri.length() < 2)) { dstUri = filterDestUri(dstUri); RepositoryHelper.beginTransaction(); RepositoryNode resNode = RepositoryHelper.copyAndUpdate(dstUri, srcUri, (User) request.getUserPrincipal(), description); RepositoryHelper.commitTransaction(); // expire since probably get ServletUtil.setExpired(response); Document doc = DocumentHelper.createDocument(); doc.addElement("ok").addAttribute("result", resNode.getUri()); doc.write(response.getWriter()); } else { throw new NotFoundException("[blank]"); } }
From source file:itensil.repository.web.ShellServlet.java
License:Open Source License
/** * /move//from www . j ava2 s.c om * * Mode a node * */ @ContentType("text/xml") public void webMove(HttpServletRequest request, HttpServletResponse response) throws Exception { String srcUri = request.getParameter("srcUri"); String dstUri = request.getParameter("dstUri"); if (!(Check.isEmpty(srcUri) || srcUri.length() < 2 || Check.isEmpty(dstUri) || dstUri.length() < 2)) { dstUri = filterDestUri(dstUri); RepositoryHelper.beginTransaction(); dstUri = RepositoryHelper.resolveUri(dstUri); srcUri = RepositoryHelper.resolveUri(srcUri); MutableRepositoryNode node = getNode(srcUri); node.move(dstUri); RepositoryHelper.commitTransaction(); // expire since probably get ServletUtil.setExpired(response); Document doc = DocumentHelper.createDocument(); doc.addElement("ok").addAttribute("result", node.getUri()); doc.write(response.getWriter()); } else { throw new NotFoundException("[blank]"); } }
From source file:itensil.security.web.CommunityAdmin.java
License:Open Source License
/** * /getConfigProp/*from w ww . ja v a 2s .com*/ * * */ @ContentType("text/xml") public void webGetConfigProp(HttpServletRequest request, HttpServletResponse response) throws Exception { HibernateUtil.beginTransaction(); HibernateUtil.readOnlySession(); Document doc = DocumentHelper.createDocument(); Element root = doc.addElement("config-property"); Property prop = ConfigManager.getProperty(request.getParameter("component")); root.addElement("component").setText(prop.getComponent()); root.addElement("properties").setText(prop.getProperties()); HibernateUtil.commitTransaction(); ServletUtil.noCache(response); doc.write(response.getWriter()); }
From source file:itensil.security.web.CommunityAdmin.java
License:Open Source License
/** * /getInfo//from www. j a v a2 s.co m * * Community Info * */ public void webGetInfo(HttpServletRequest request, HttpServletResponse response) throws Exception { HibernateUtil.beginTransaction(); HibernateUtil.readOnlySession(); UserEntity self = (UserEntity) request.getUserPrincipal(); Document doc = DocumentHelper.createDocument(); Element root = doc.addElement("community"); String uspaceId = request.getParameter("uspaceId"); if (SysAdmin.isSysAdmin(self) && !Check.isEmpty(uspaceId)) { UserSpaceEntity uspace = (UserSpaceEntity) HibernateUtil.getSession().get(UserSpaceEntity.class, uspaceId); if (uspace != null) { root.addElement("uspaceId").setText(uspace.getUserSpaceId()); root.addElement("name").setText(Check.emptyIfNull(uspace.getName())); root.addElement("baseUrl").setText(Check.emptyIfNull(uspace.getBaseUrl())); root.addElement("brand").setText(Check.emptyIfNull(uspace.getBrand())); root.addElement("features").setText(Check.emptyIfNull(uspace.getFeaturesStr())); } } HibernateUtil.commitTransaction(); ServletUtil.noCache(response); doc.write(response.getWriter()); }
From source file:itensil.security.web.UserSpaceServlet.java
License:Open Source License
/** * /list//from ww w . j a v a2 s. c o m * * Output: * User List XML * */ @ContentType("text/xml") public void webList(HttpServletRequest request, HttpServletResponse response) throws Exception { UserEntity self = (UserEntity) request.getUserPrincipal(); HibernateUtil.beginTransaction(); HibernateUtil.readOnlySession(); UserSpace uspace = self.getUserSpace(); HibernateUtil.getSession().refresh(uspace); Document doc = DocumentHelper.createDocument(); Element root = doc.addElement("list"); root.addAttribute("name", uspace.getName()); root.addAttribute("self", self.getUserId()); root.addAttribute("self-roles", self.getUSpaceUser().getRoleStr()); for (User user : uspace.getUsers()) { Element uElem = root.addElement("user"); uElem.addAttribute("id", user.getUserId()); // email source may change here.... uElem.addAttribute("email", user.getName()); uElem.addAttribute("name", user.getSimpleName()); } for (Group grp : uspace.getGroups()) { Element gElem = root.addElement("group"); gElem.addAttribute("id", grp.getGroupId()); gElem.addAttribute("name", grp.getSimpleName()); } // include everyone for lookup Everyone evo = new Everyone(); Element gElem = root.addElement("group"); gElem.addAttribute("id", evo.getGroupId()); gElem.addAttribute("name", evo.getSimpleName()); gElem.addAttribute("everyone", "1"); HibernateUtil.commitTransaction(); // let the list live a bit ServletUtil.cacheTimeout(response, 12); doc.write(response.getWriter()); }
From source file:itensil.security.web.UserSpaceServlet.java
License:Open Source License
/** * /userManList//from w w w . ja v a2s .co m * * Output: * User/Groups List XML * */ @ContentType("text/xml") public void webUserManList(HttpServletRequest request, HttpServletResponse response) throws Exception { AuthenticatedUser self = (AuthenticatedUser) request.getUserPrincipal(); HibernateUtil.beginTransaction(); HibernateUtil.readOnlySession(); if (!self.getRoles().contains("admin")) throw new UserSpaceException("Admin role required"); UserSpaceEntity uspace = (UserSpaceEntity) self.getUserSpace(); HibernateUtil.getSession().refresh(uspace); Document doc = DocumentHelper.createDocument(); Element root = doc.addElement("list"); root.addAttribute("name", uspace.getName()); root.addAttribute("self", self.getUserId()); for (USpaceUserEntity uus : uspace.getUserSpaceUsers().values()) { UserEntity user = uus.getUserEntity(); Element uElem = root.addElement("user"); uElem.addAttribute("id", user.getUserId()); // email source may change here.... uElem.addAttribute("email", user.getName()); uElem.addAttribute("name", user.getSimpleName()); uElem.addAttribute("roles", uus.getRoleStr()); for (Group grp : uspace.getGroupsForUser(user)) { Element gElem = uElem.addElement("group"); gElem.addAttribute("id", grp.getGroupId()); gElem.addAttribute("name", grp.getSimpleName()); } } HibernateUtil.commitTransaction(); ServletUtil.noCache(response); doc.write(response.getWriter()); }
From source file:itensil.security.web.UserSpaceServlet.java
License:Open Source License
/** * /groupManList// ww w . j a va 2s . c o m * * Output: * Group/User List XML * */ @SuppressWarnings("unchecked") @ContentType("text/xml") public void webGroupManList(HttpServletRequest request, HttpServletResponse response) throws Exception { AuthenticatedUser self = (AuthenticatedUser) request.getUserPrincipal(); HibernateUtil.beginTransaction(); HibernateUtil.readOnlySession(); if (!self.getRoles().contains("admin")) throw new UserSpaceException("Admin role required"); UserSpaceEntity uspace = (UserSpaceEntity) self.getUserSpace(); //HibernateUtil.getSession().refresh(uspace); Document doc = DocumentHelper.createDocument(); Element root = doc.addElement("list"); Query qry = HibernateUtil.getSession().getNamedQuery("USpace.groupsByType"); qry.setInteger("gtype", 0); qry.setEntity("uspace", uspace); for (GroupEntity grp : (List<GroupEntity>) qry.list()) { Element gElem = root.addElement("group"); gElem.addAttribute("id", grp.getGroupId()); gElem.addAttribute("name", grp.getSimpleName()); gElem.addAttribute("parentId", Check.emptyIfNull(grp.getParentGroupId())); for (User user : grp.getUserEntities()) { Element uElem = gElem.addElement("user"); uElem.addAttribute("id", user.getUserId()); uElem.addAttribute("name", user.getSimpleName()); uElem.addAttribute("email", user.getName()); } } HibernateUtil.commitTransaction(); ServletUtil.noCache(response); doc.write(response.getWriter()); }
From source file:itensil.security.web.UserSpaceServlet.java
License:Open Source License
/** * /orgList//from w w w .j av a 2 s. c om * * Output: * Group/User List XML * */ @SuppressWarnings("unchecked") @ContentType("text/xml") public void webOrgList(HttpServletRequest request, HttpServletResponse response) throws Exception { AuthenticatedUser self = (AuthenticatedUser) request.getUserPrincipal(); HibernateUtil.beginTransaction(); HibernateUtil.readOnlySession(); UserSpaceEntity uspace = (UserSpaceEntity) self.getUserSpace(); if (!uspace.getFeatures().contains("orgs")) throw new UserSpaceException("Org feature required"); //HibernateUtil.getSession().refresh(uspace); Document doc = DocumentHelper.createDocument(); Element root = doc.addElement("list"); Query qry = HibernateUtil.getSession().getNamedQuery("USpace.groupsByType"); qry.setInteger("gtype", 1); qry.setEntity("uspace", uspace); for (GroupEntity grp : (List<GroupEntity>) qry.list()) { Element gElem = root.addElement("group"); gElem.addAttribute("id", grp.getGroupId()); gElem.addAttribute("name", grp.getSimpleName()); gElem.addAttribute("fullName", grp.getGroupName()); gElem.addAttribute("remoteKey", grp.getRemoteKey()); gElem.addAttribute("parentId", grp.getParentGroupId()); } HibernateUtil.commitTransaction(); ServletUtil.noCache(response); doc.write(response.getWriter()); }