List of usage examples for org.dom4j Element getTextTrim
String getTextTrim();
From source file:org.alfresco.module.vti.web.ws.AbstractListEndpoint.java
License:Open Source License
/** * Deletes document workspace/*from ww w . ja v a2 s.c o m*/ * * @param soapRequest Vti soap request ({@link VtiSoapRequest}) * @param soapResponse Vti soap response ({@link VtiSoapResponse}) */ public void execute(VtiSoapRequest soapRequest, VtiSoapResponse soapResponse) throws Exception { if (logger.isDebugEnabled()) { logger.debug("SOAP method with name " + getName() + " is started."); } // mapping xml namespace to prefix SimpleNamespaceContext nc = new SimpleNamespaceContext(); nc.addNamespace(soapUriPrefix, soapUri); nc.addNamespace(prefix, namespace); // Grab the site name String dws = getDwsFromUri(soapRequest); // Fetch the root of the document Element requestElement = soapRequest.getDocument().getRootElement(); // Get the listName parameter from the request XPath listNameXPath = new Dom4jXPath(buildXPath(prefix, "/" + getName() + "/listName")); listNameXPath.setNamespaceContext(nc); Element listNameE = (Element) listNameXPath.selectSingleNode(requestElement); String listName = null; if (listNameE != null) { listName = listNameE.getTextTrim(); } // Have any further details fetched as needed executeListActionDetails(soapRequest, soapResponse, dws, listName, requestElement, nc); // All done if (logger.isDebugEnabled()) { logger.debug("SOAP method with name " + getName() + " is finished."); } }
From source file:org.alfresco.module.vti.web.ws.AbstractListEndpoint.java
License:Open Source License
protected void executeListActionDetails(VtiSoapRequest soapRequest, VtiSoapResponse soapResponse, String siteName, String listName, Element requestElement, SimpleNamespaceContext nc) throws Exception { // Get the description parameter from the request XPath descriptionXPath = new Dom4jXPath(buildXPath(prefix, "/" + getName() + "/description")); descriptionXPath.setNamespaceContext(nc); Element descriptionE = (Element) descriptionXPath .selectSingleNode(soapRequest.getDocument().getRootElement()); String description = null;/*from w ww . jav a 2 s .co m*/ if (descriptionE != null) { description = descriptionE.getTextTrim(); } // Get the template ID parameter from the request XPath templateXPath = new Dom4jXPath(buildXPath(prefix, "/" + getName() + "/templateID")); templateXPath.setNamespaceContext(nc); Element templateE = (Element) templateXPath.selectSingleNode(soapRequest.getDocument().getRootElement()); int templateID = -1; if (templateE != null) { templateID = Integer.parseInt(templateE.getTextTrim()); } // Have the List Added / Fetched ListInfoBean list = executeListAction(soapRequest, siteName, listName, description, templateID); // Have it rendered renderList(soapRequest, soapResponse, siteName, list); }
From source file:org.alfresco.module.vti.web.ws.AbstractListItemsEndpoint.java
License:Open Source License
/** * Returns information about items in the list based on the specified query *///from w w w.j a va 2s .c o m @Override protected void executeListActionDetails(VtiSoapRequest soapRequest, VtiSoapResponse soapResponse, String siteName, String listName, Element requestElement, SimpleNamespaceContext nc) throws Exception { // Have the List Fetched ListInfoBean list = null; try { list = handler.getList(listName, siteName); } catch (SiteDoesNotExistException se) { // The specification defines the exact code that must be // returned in case of a file not being found long code = VtiError.V_LIST_NOT_FOUND.getErrorCode(); String message = "Site not found: " + se.getMessage(); throw new VtiSoapException(message, code, se); } catch (FileNotFoundException fnfe) { // The specification defines the exact code that must be // returned in case of a file not being found long code = VtiError.V_LIST_NOT_FOUND.getErrorCode(); String message = "List not found: " + fnfe.getMessage(); throw new VtiSoapException(message, code, fnfe); } // Get the folder parameter for listing XPath listFolderPath = new Dom4jXPath( buildXPath(prefix, "/" + getName() + "/queryOptions/QueryOptions/Folder")); listFolderPath.setNamespaceContext(nc); Element listFolder = (Element) listFolderPath.selectSingleNode(soapRequest.getDocument().getRootElement()); // There are two ways to get changes since a date, explicit date or token (also date) Date changesSince = null; // Get the "Changes Since" date for the listing XPath changesSinceXPath = new Dom4jXPath(buildXPath(prefix, "/" + getName() + "/since")); changesSinceXPath.setNamespaceContext(nc); Element changesSinceE = (Element) changesSinceXPath.selectSingleNode(requestElement); if (changesSinceE != null) { changesSince = ISO8601DateFormat.parse(changesSinceE.getTextTrim()); } // Alternative is "Changes Since Token", which is also a date XPath changesSinceTokenXPath = new Dom4jXPath(buildXPath(prefix, "/" + getName() + "/changeToken")); changesSinceTokenXPath.setNamespaceContext(nc); Element changesSinceTokenE = (Element) changesSinceTokenXPath.selectSingleNode(requestElement); if (changesSinceTokenE != null) { changesSince = ISO8601DateFormat.parse(changesSinceTokenE.getTextTrim()); } // TODO Implement the correct error handling and error codes String timeNow = ISO8601DateFormat.format(new Date()); DocsMetaInfo result = null; if (!siteName.equals("")) { String initialUrl = pathHelper.resolveListName(listName); if (listFolder != null) { initialUrl = URLDecoder.decode(listFolder.getTextTrim(), "UTF-8"); } result = getListInfo(siteName, list, initialUrl, changesSince); } // creating soap response Element responseElement = soapResponse.getDocument().addElement("GetListItemsResponse", namespace); Element resultElement = responseElement.addElement("GetListItemsResult"); Element itemsElement = resultElement.addElement("listitems"); itemsElement.addNamespace("rs", "urn:schemas-microsoft-com:rowset"); itemsElement.addNamespace("z", "#RowsetSchema"); Element dataElement = itemsElement.addElement("rs:data"); // Change tracking information itemsElement.addAttribute("TimeStamp", timeNow); if ("GetListItemChangesSinceToken".equals(getName())) { Element changes = itemsElement.addElement("Changes"); changes.addAttribute("LastChangeToken", timeNow); } int itemCount = 0; if (result != null) { int id = 1; for (DocMetaInfo file : result.getFileMetaInfoList()) { buildRow(dataElement, file, id++, soapRequest); } for (DocMetaInfo folder : result.getFolderMetaInfoList()) { buildRow(dataElement, folder, id++, soapRequest); } itemCount = result.getFileMetaInfoList().size() + result.getFolderMetaInfoList().size(); } dataElement.addAttribute("ItemCount", Integer.toString(itemCount)); if (logger.isDebugEnabled()) { logger.debug("Soap Method with name " + getName() + " is finished."); } }
From source file:org.alfresco.module.vti.web.ws.AddUserCollectionToRoleEndpoint.java
License:Open Source License
/** * Adds new user to the site with given role * //from w w w . ja va 2s .c om * @param soapRequest Vti soap request ({@link VtiSoapRequest}) * @param soapResponse Vti soap response ({@link VtiSoapResponse}) */ @SuppressWarnings("unchecked") public void execute(VtiSoapRequest soapRequest, VtiSoapResponse soapResponse) throws Exception { if (logger.isDebugEnabled()) logger.debug("Soap Method with name " + getName() + " is started."); // mapping xml namespace to prefix SimpleNamespaceContext nc = new SimpleNamespaceContext(); nc.addNamespace(prefix, namespace); nc.addNamespace(soapUriPrefix, soapUri); Element requestElement = soapRequest.getDocument().getRootElement(); // getting document parameter from request if (logger.isDebugEnabled()) logger.debug("Getting role from request."); XPath roleNamePath = new Dom4jXPath(buildXPath(prefix, "/AddUserCollectionToRole/roleName")); roleNamePath.setNamespaceContext(nc); Element roleName = (Element) roleNamePath.selectSingleNode(requestElement); // getting document parameter from request if (logger.isDebugEnabled()) logger.debug("Getting users from request."); XPath usersPath = new Dom4jXPath(buildXPath(prefix, "/AddUserCollectionToRole/usersInfoXml/Users/User")); usersPath.setNamespaceContext(nc); List<Element> usersElementList = (List<Element>) usersPath.selectNodes(requestElement); List<UserBean> usersList = new ArrayList<UserBean>(); for (Element userElement : usersElementList) { usersList.add(new UserBean(userElement.attributeValue("Name"), userElement.attributeValue("LoginName"), userElement.attributeValue("Email"), userElement.attributeValue("Notes"))); } String role = roleName.getTextTrim(); if (role != null) { String dws = getDwsFromUri(soapRequest); if (logger.isDebugEnabled()) { String users = ""; for (UserBean userBean : usersList) { users += userBean.getDisplayName() + ", "; } logger.debug("Adding users [ " + users + "] with role '" + role + "' to the site '" + dws + "'"); } handler.addUserCollectionToRole(dws, role, usersList); // creating soap response soapResponse.getDocument().addElement("AddUserCollectionToRoleResponse", namespace); } if (logger.isDebugEnabled()) logger.debug("Soap Method with name " + getName() + " is finished."); }
From source file:org.alfresco.module.vti.web.ws.CanCreateDwsUrlEndpoint.java
License:Open Source License
/** * Creates new document workspace with given title * * @param soapRequest Vti soap request ({@link VtiSoapRequest}) * @param soapResponse Vti soap response ({@link VtiSoapResponse}) *///ww w . j a v a2 s . com public void execute(VtiSoapRequest soapRequest, VtiSoapResponse soapResponse) throws Exception { if (logger.isDebugEnabled()) { logger.debug("SOAP method with name " + getName() + " is started."); } // mapping xml namespace to prefix SimpleNamespaceContext nc = new SimpleNamespaceContext(); nc.addNamespace(prefix, namespace); nc.addNamespace(soapUriPrefix, soapUri); // getting title parameter from request XPath urlPath = new Dom4jXPath(buildXPath(prefix, "/CanCreateDwsUrl/url")); urlPath.setNamespaceContext(nc); Element url = (Element) urlPath.selectSingleNode(soapRequest.getDocument().getRootElement()); String urlText = ""; if (url != null) { urlText = url.getTextTrim(); if (urlText.equals("")) { // [MS-DWSS] return a generated/unique name urlText = GUID.generate(); } } if (false == handler.canCreateDwsUrl(urlText)) { throw new VtiHandlerException(VtiError.NO_PERMISSIONS); } // creating soap response Element resultElement = buildResultTag(soapResponse); resultElement.setText(processTag("Result", urlText).toString()); if (logger.isDebugEnabled()) { logger.debug("SOAP method with name " + getName() + " is finished."); } }
From source file:org.alfresco.module.vti.web.ws.CheckInFileEndpoint.java
License:Open Source License
/** * Check in file/*from w ww. ja va2 s . c o m*/ * * @param soapRequest Vti soap request ({@link VtiSoapRequest}) * @param soapResponse Vti soap response ({@link VtiSoapResponse}) */ public void execute(VtiSoapRequest soapRequest, VtiSoapResponse soapResponse) throws Exception { if (logger.isDebugEnabled()) logger.debug("Soap Method with name " + getName() + " is started."); // mapping xml namespace to prefix SimpleNamespaceContext nc = new SimpleNamespaceContext(); nc.addNamespace(prefix, namespace); nc.addNamespace(soapUriPrefix, soapUri); // getting pageUrl parameter from request XPath xpath = new Dom4jXPath(buildXPath(prefix, "/CheckInFile/pageUrl")); xpath.setNamespaceContext(nc); Element docE = (Element) xpath.selectSingleNode(soapRequest.getDocument().getRootElement()); if (docE == null || docE.getTextTrim().length() == 0) { throw new VtiSoapException("pageUrl must be supplied", 0x82000001l); } String docPath = URLDecoder.decode(docE.getTextTrim()); String context = soapRequest.getAlfrescoContextName(); docPath = URIUtil.getPath(docPath).substring(context.length()); // Get the comment xpath = new Dom4jXPath(buildXPath(prefix, "/CheckInFile/comment")); xpath.setNamespaceContext(nc); String comment = ((Element) xpath.selectSingleNode(soapRequest.getDocument().getRootElement())) .getTextTrim(); // Get the checkin type xpath = new Dom4jXPath(buildXPath(prefix, "/CheckInFile/CheckinType")); xpath.setNamespaceContext(nc); Element typeE = (Element) xpath.selectSingleNode(soapRequest.getDocument().getRootElement()); VersionType type = VersionType.MAJOR; if (typeE != null && typeE.getTextTrim().length() > 0) { String typeS = typeE.getTextTrim(); if ("0".equals(typeS)) { type = VersionType.MINOR; } else if ("1".equals(typeS)) { type = VersionType.MAJOR; } else if ("2".equals(typeS)) { type = VersionType.MAJOR; } else { throw new VtiSoapException("Invalid Checkin Type '" + typeS + "' received", -1); } } // Good to go if (logger.isDebugEnabled()) { logger.debug("item parameter for this request: " + docPath); } NodeRef originalNode; boolean lockAfterSucess = true; // Do not lock original node if we work with Office 2008/2011 for Mac if (VtiUtils.isMacClientRequest(soapRequest)) { lockAfterSucess = false; } try { originalNode = handler.checkInDocument(docPath, type, comment, lockAfterSucess); } catch (FileNotFoundException fnfe) { throw new VtiSoapException("File not found", -1, fnfe); } // creating soap response Element responseElement = soapResponse.getDocument().addElement("CheckInFileResponse", namespace); Element result = responseElement.addElement("CheckInFileResult"); result.setText(originalNode != null ? "true" : "false"); soapResponse.setContentType("text/xml"); if (logger.isDebugEnabled()) { logger.debug("Soap Method with name " + getName() + " is finished."); } }
From source file:org.alfresco.module.vti.web.ws.CheckOutFileEndpoint.java
License:Open Source License
/** * Check out file//from w w w .j a v a 2s. c o m * * @param soapRequest Vti soap request ({@link VtiSoapRequest}) * @param soapResponse Vti soap response ({@link VtiSoapResponse}) */ public void execute(VtiSoapRequest soapRequest, VtiSoapResponse soapResponse) throws Exception { if (logger.isDebugEnabled()) logger.debug("Soap Method with name " + getName() + " is started."); // mapping xml namespace to prefix SimpleNamespaceContext nc = new SimpleNamespaceContext(); nc.addNamespace(prefix, namespace); nc.addNamespace(soapUriPrefix, soapUri); // Get the pageUrl parameter from the request XPath xpath = new Dom4jXPath(buildXPath(prefix, "/CheckOutFile/pageUrl")); xpath.setNamespaceContext(nc); Element docE = (Element) xpath.selectSingleNode(soapRequest.getDocument().getRootElement()); if (docE == null || docE.getTextTrim().length() == 0) { throw new VtiSoapException("pageUrl must be supplied", 0x82000001l); } String docPath = URLDecoder.decode(docE.getTextTrim(), "UTF-8"); String context = soapRequest.getAlfrescoContextName(); docPath = URIUtil.getPath(docPath).substring(context.length()); // Did they want to work on it locally? xpath = new Dom4jXPath(buildXPath(prefix, "/CheckOutFile/checkoutToLocal")); xpath.setNamespaceContext(nc); Element localE = (Element) xpath.selectSingleNode(soapRequest.getDocument().getRootElement()); if (localE != null) { // If given, must be one of True or False String local = localE.getTextTrim().toLowerCase(); if ("true".equals(local) || "false".equals(local)) { // Good } else { throw new VtiSoapException("Invalid CheckOutToLocal Parameter", -1); } } // Report what we're about to do if (logger.isDebugEnabled()) { logger.debug("About to check out " + docPath); } NodeRef workingCopy; boolean lockAfterSucess = true; // Do not lock working copy node if we work with Office 2008/2011 for Mac // this clients don't send UNLOCK method after SOAP CheckOutFile request, so no need to lock working copy if (VtiUtils.isMacClientRequest(soapRequest)) { lockAfterSucess = false; } try { workingCopy = handler.checkOutDocument(docPath, lockAfterSucess); // creating soap response Element responseElement = soapResponse.getDocument().addElement("CheckOutFileResponse", namespace); Element result = responseElement.addElement("CheckOutFileResult"); result.setText(workingCopy != null ? "true" : "false"); soapResponse.setContentType("text/xml"); if (logger.isDebugEnabled()) { logger.debug("Soap Method with name " + getName() + " is finished."); } } catch (AccessDeniedException e) { soapResponse.setStatus(HttpServletResponse.SC_UNAUTHORIZED); } catch (FileNotFoundException fnfe) { throw new VtiSoapException("File not found", -1, fnfe); } }
From source file:org.alfresco.module.vti.web.ws.CreateDwsEndpoint.java
License:Open Source License
protected String getParameter(Element rootElement, String path, SimpleNamespaceContext nc) throws JaxenException { XPath xPath = new Dom4jXPath(buildXPath(prefix, path)); xPath.setNamespaceContext(nc);/*from w w w .ja v a 2 s. c o m*/ Element titleEl = (Element) xPath.selectSingleNode(rootElement); return titleEl.getTextTrim(); }
From source file:org.alfresco.module.vti.web.ws.GetDwsDataEndpoint.java
License:Open Source License
/** * Retrieves information about document workspace * /*from w ww. j a v a 2s .c om*/ * @param soapRequest Vti soap request ({@link VtiSoapRequest}) * @param soapResponse Vti soap response ({@link VtiSoapResponse}) */ public void execute(VtiSoapRequest soapRequest, VtiSoapResponse soapResponse) throws Exception { if (logger.isDebugEnabled()) { logger.debug("SOAP method with name " + getName() + " is started."); } // mapping xml namespace to prefix SimpleNamespaceContext nc = new SimpleNamespaceContext(); nc.addNamespace(prefix, namespace); nc.addNamespace(soapUriPrefix, soapUri); // getting document parameter from request XPath docPath = new Dom4jXPath(buildXPath(prefix, "/GetDwsData/document")); docPath.setNamespaceContext(nc); String doc = ((Element) docPath.selectSingleNode(soapRequest.getDocument().getRootElement())).getText(); // getting lastUpdate parameter from request XPath lastUpdatePath = new Dom4jXPath(buildXPath(prefix, "/GetDwsData/lastUpdate")); lastUpdatePath.setNamespaceContext(nc); Element lastUpdate = (Element) lastUpdatePath.selectSingleNode(soapRequest.getDocument().getRootElement()); DwsData dwsData; try { dwsData = handler.getDwsData(URLDecoder.decode(doc, "UTF-8"), lastUpdate.getTextTrim()); } catch (SiteDoesNotExistException e) { throw new VtiHandlerException(VtiError.V_URL_NOT_FOUND); } // creating soap response Element root = soapResponse.getDocument().addElement("GetDwsDataResponse", namespace); Element getDwsDataResult = root.addElement("GetDwsDataResult"); getDwsDataResult.setText(generateXml(dwsData)); if (logger.isDebugEnabled()) { logger.debug("SOAP method with name " + getName() + " is finished."); } }
From source file:org.alfresco.module.vti.web.ws.GetWebEndpoint.java
License:Open Source License
/** * Returns info on a site/*from ww w .j a v a 2 s. c om*/ * * @param soapRequest Vti soap request ({@link VtiSoapRequest}) * @param soapResponse Vti soap response ({@link VtiSoapResponse}) */ public void execute(VtiSoapRequest soapRequest, VtiSoapResponse soapResponse) throws Exception { if (logger.isDebugEnabled()) { logger.debug("SOAP method with name " + getName() + " is started."); } // mapping xml namespace to prefix SimpleNamespaceContext nc = new SimpleNamespaceContext(); nc.addNamespace(prefix, namespace); nc.addNamespace(soapUriPrefix, soapUri); // Get the web url parameter from request XPath urlPath = new Dom4jXPath(buildXPath(prefix, "/GetWeb/webUrl")); urlPath.setNamespaceContext(nc); Element urlE = (Element) urlPath.selectSingleNode(soapRequest.getDocument().getRootElement()); // Turn that into a URL in our required format String url = null; if (urlE != null) { url = URLDecoder.decode(urlE.getTextTrim(), "UTF-8"); } if (url != null && (url.equals(".") || url.equals(""))) { String dws = getDwsFromUri(soapRequest); String context = getContext(soapRequest); String host = getHost(soapRequest); url = host + context + dws; } // Fetch the details for the site DwsData dws; try { dws = handler.getDwsData(url, null); } catch (SiteDoesNotExistException e) { // The specification defines the exact code that must be // returned in case of a site not being found long code = 0x82000001l; String message = "No Site was found with the given URL"; throw new VtiSoapException(message, code, e); } catch (VtiHandlerException vti) { // Something was wrong with the request given, likely // the URL wasn't in a valid format long code = 0x82000001l; String message = "Invalid request - " + vti.getMessage(); throw new VtiSoapException(message, code, vti); } // creating soap response Element root = soapResponse.getDocument().addElement("GetWebResponse", namespace); Element result = root.addElement("GetWebResult"); Element web = result.addElement("Web"); web.addAttribute("Title", dws.getTitle()); web.addAttribute("Url", dws.getDocLibUrl()); String description = dws.getDescription(); if (description != null && description.length() > 0) { web.addAttribute("Description", dws.getDescription()); } // We don't do FSS-HTTP (yet!) web.addAttribute("CellStorageWebServiceEnabled", "False"); // We don't support offline editing web.addAttribute("ExcludeFromOfflineClient", "False"); // Completed if (logger.isDebugEnabled()) { logger.debug("SOAP method with name " + getName() + " is finished."); } }