List of usage examples for org.dom4j Element addText
Element addText(String text);
Text
node with the given text to this element. From source file:nl.tue.gale.ae.processor.plugin.DebugPlugin.java
License:Open Source License
public void doGet(Resource resource) throws ProcessorException { GaleContext gale = GaleContext.of(resource); try {// w ww . j ava 2 s . c o m try { gale.ebc().event("ccdm", ImmutableList.<String>of()); gale.ebc().event("ccum", ImmutableList.<String>of()); gale.ebc().event("ccae", ImmutableList.<String>of()); System.gc(); } catch (Exception e) { e.printStackTrace(); } Element result = GaleUtil.createHTMLElement("p"); result.addText("Succes!"); gale.usedStream(); resource.put("xml", result); resource.put("mime", "text/xhtml"); } catch (Exception e) { throw new ProcessorException("unable to run debug plugin: " + e.getMessage(), e); } }
From source file:nl.tue.gale.ae.processor.plugin.UpdateContentPlugin.java
License:Open Source License
public void doGet(Resource resource) throws ProcessorException { GaleContext gale = GaleContext.of(resource); try {// w ww.j ava 2 s.com String camFileName = gale.req().getParameter("cam"); Element cam = GaleUtil.parseXML(GaleUtil.generateURL(camFileName, gale.gc().getHomeDir())) .getRootElement(); ((UpdateContentManager) gale.ac().getBean("updateContentManager")).updateCAMModel(cam); Element result = GaleUtil.createHTMLElement("p"); result.addText("Succes!"); gale.usedStream(); resource.put("xml", result); resource.put("mime", "text/xhtml"); } catch (Exception e) { throw new ProcessorException("unable to run debug plugin: " + e.getMessage(), e); } }
From source file:nl.tue.gale.ae.processor.view.NextView.java
License:Open Source License
public Element getXml(Resource resource, Object... params) { GaleContext gale = GaleContext.of(resource); String expr = GaleUtil.getParam(params, "expr"); if (expr == null) expr = defaultExpr;/*w w w . ja v a 2 s .com*/ String label = GaleUtil.getParam(params, "label"); String done = GaleUtil.getParam(params, "done"); if (done == null) done = "end of course"; TreeNodes nodes = new TreeNodes(gale); TreeNode startNode = nodes.get(gale.concept().getUriString()); TreeNode currentNode = nextNode(startNode, nodes); int loop = 0; while (currentNode != null && !startNode.equals(currentNode) && loop < loopMax) { CacheSession<EntityValue> session = gale.openUmSession(); session.setBaseUri(URIs.of(currentNode.getConcept())); Boolean exprResult = (Boolean) gale.eval(session, expr); if (exprResult) break; currentNode = nextNode(currentNode, nodes); loop++; } if (loop == loopMax) return GaleUtil.createHTMLElement("span").addText(done + " (loop)"); Element span = GaleUtil.createHTMLElement("span"); if (currentNode == null || startNode.equals(currentNode)) { span.addText(done); return span; } if (label != null) span.addText(label); Element a = GaleUtil.createNSElement("a", GaleUtil.adaptns); span.add(a); a.addAttribute("href", currentNode.getConcept()); a.addText(gale.dm().get(URIs.of(currentNode.getConcept())).getTitle()); return span; }
From source file:nl.tue.gale.ae.processor.view.StaticTreeView.java
License:Open Source License
private Element createMenuItem(GaleContext gale, String conceptName) { Element result = GaleUtil.createHTMLElement("li"); Element a = GaleUtil.createNSElement("a", GaleUtil.adaptns); result.add(a);//from w ww . java 2 s . c o m Concept c = gale.dm().get(URIs.of(conceptName)); a.addText(c.getTitle()); a.addAttribute("href", c.getUriString()); return result; }
From source file:nl.tue.gale.common.GaleUtil.java
License:Open Source License
/** * Generates an html span element with the specified error text. The element * will have its 'class' attribute set to 'error'. * /* w ww.ja va 2 s .c o m*/ * @param text * the text to use in the generated element * @param doc * the <code>Document</code> that the generated element will be a * part of * @return the generated span <code>org.w3c.dom.Element</code> */ public static Element createErrorElement(String text) { Element result = DocumentFactory.getInstance().createElement( DocumentFactory.getInstance().createQName("span", "", "http://www.w3.org/1999/xhtml")); result.addText(text); result.addAttribute("style", "color:#D02020"); return result; }
From source file:nl.tue.gale.common.XPPEntityReader.java
License:Open Source License
protected Document parseDocument() throws DocumentException, IOException, XmlPullParserException { DocumentFactory df = getDocumentFactory(); Document document = df.createDocument(); Element parent = null; XmlPullParser pp = getXPPParser();//from w ww .j a va 2 s . c om pp.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true); pp.setFeature(XmlPullParser.FEATURE_PROCESS_DOCDECL, false); defineEntities(pp); while (true) { int type = pp.nextToken(); switch (type) { case XmlPullParser.PROCESSING_INSTRUCTION: { String text = pp.getText(); int loc = text.indexOf(" "); if (loc >= 0) { String target = text.substring(0, loc); String txt = text.substring(loc + 1); document.addProcessingInstruction(target, txt); } else { document.addProcessingInstruction(text, ""); } break; } case XmlPullParser.COMMENT: { if (parent != null) { parent.addComment(pp.getText()); } else { document.addComment(pp.getText()); } break; } case XmlPullParser.CDSECT: { if (parent != null) { parent.addCDATA(pp.getText()); } else { String msg = "Cannot have text content outside of the " + "root document"; throw new DocumentException(msg); } break; } case XmlPullParser.ENTITY_REF: if (parent != null) { if (pp.getName().equals("gt")) { parent.addText(">"); } else if (pp.getName().equals("lt")) { parent.addText("<"); } else if (pp.getName().equals("amp")) { parent.addText("&"); } else if (pp.getName().equals("quot")) { parent.addText("\""); } else parent.addEntity(pp.getName(), "&" + pp.getName() + ";"); } break; case XmlPullParser.END_DOCUMENT: return document; case XmlPullParser.START_TAG: { QName qname = (pp.getPrefix() == null) ? df.createQName(pp.getName(), pp.getNamespace()) : df.createQName(pp.getName(), pp.getPrefix(), pp.getNamespace()); Element newElement = df.createElement(qname); int nsStart = pp.getNamespaceCount(pp.getDepth() - 1); int nsEnd = pp.getNamespaceCount(pp.getDepth()); for (int i = nsStart; i < nsEnd; i++) { if (pp.getNamespacePrefix(i) != null) { newElement.addNamespace(pp.getNamespacePrefix(i), pp.getNamespaceUri(i)); } } for (int i = 0; i < pp.getAttributeCount(); i++) { QName qa = (pp.getAttributePrefix(i) == null) ? df.createQName(pp.getAttributeName(i)) : df.createQName(pp.getAttributeName(i), pp.getAttributePrefix(i), pp.getAttributeNamespace(i)); newElement.addAttribute(qa, pp.getAttributeValue(i)); } if (parent != null) { parent.add(newElement); } else { document.add(newElement); } parent = newElement; break; } case XmlPullParser.END_TAG: { if (parent != null) { parent = parent.getParent(); } break; } case XmlPullParser.TEXT: { String text = pp.getText(); if (parent != null) { parent.addText(text); } else { String msg = "Cannot have text content outside of the " + "root document"; throw new DocumentException(msg); } break; } default: break; } } }
From source file:org.alfresco.module.vti.web.actions.VtiSoapAction.java
License:Open Source License
/** * Creates an appropriate SOAP Fault Response, in the appropriate * of the two different formats//from w ww. j a v a 2s . co m */ private void createFaultSOAPResponse(VtiSoapRequest request, Element responseElement, Exception e, VtiEndpoint vtiEndpoint) { // Is it something like // <FooResponse><FooResult><Error ID="123"/></FooResult></FooResponse> ? if (e instanceof VtiHandlerException) { VtiHandlerException handlerException = (VtiHandlerException) e; Element endpointResponseE = responseElement.addElement(vtiEndpoint.getName() + "Response", vtiEndpoint.getNamespace()); Element endpointResultE = endpointResponseE.addElement(vtiEndpoint.getName() + "Result"); //String errorMessage = handlerException.getMessage(); String errorCode; if (handlerException.getErrorCode() > -1) { errorCode = Long.toString(handlerException.getErrorCode()); } else { errorCode = "13"; } // Return it as an ID based error, without the message endpointResultE.addElement("Error").addAttribute("ID", errorCode); } else if (e instanceof DwsException) { // <FooResponse><FooResult><Error>[ID]</Error></FooResult></FooResponse> DwsException handlerException = (DwsException) e; Element endpointResponseE = responseElement.addElement(vtiEndpoint.getResponseTagName(), vtiEndpoint.getNamespace()); Element endpointResultE = endpointResponseE.addElement(vtiEndpoint.getResultTagName()); DwsError error = handlerException.getError(); // Error value, numeric ID int errorId = error.toInt(); // Error code, e.g. "ServerFailure" String errorCode = error.toCode(); // Return it as an Coded ID based error, without the message Map<String, Object> errorAttrs = new HashMap<String, Object>(1); errorAttrs.put("ID", errorId); StringBuilder sb = startTag("Error", errorAttrs); sb.append(errorCode); sb.append(endTag("Error")); String elText = sb.toString(); endpointResultE.setText(elText); } else { // We need to return a regular SOAP Fault String errorMessage = e.getMessage(); if (errorMessage == null) { errorMessage = "Unknown error"; } // Manually generate the Soap error response Element fault = responseElement.addElement(QName.get("Fault", "s", VtiSoapResponse.NAMESPACE)); if ("1.2".equals(request.getVersion())) { // SOAP 1.2 is Code + Reason Element faultCode = fault.addElement(QName.get("Code", "s", VtiSoapResponse.NAMESPACE)); Element faultCodeText = faultCode.addElement(QName.get("Value", "s", VtiSoapResponse.NAMESPACE)); faultCodeText.addText("s:Server"); Element faultReason = fault.addElement(QName.get("Reason", "s", VtiSoapResponse.NAMESPACE)); Element faultReasonText = faultReason.addElement(QName.get("Text", "s", VtiSoapResponse.NAMESPACE)); faultReasonText.addText("Exception of type '" + e.getClass().getName() + "' was thrown."); } else { // SOAP 1.1 is Code + String Element faultCode = fault.addElement("faultcode"); faultCode.addText("s:Server"); Element faultString = fault.addElement("faultstring"); faultString.addText(e.getClass().getName()); } // Both versions get the detail Element detail = fault.addElement("detail"); Element errorstring = detail .addElement(QName.get("errorstring", "", "http://schemas.microsoft.com/sharepoint/soap/")); errorstring.addText(errorMessage); // Include the code if known if (e instanceof VtiSoapException) { VtiSoapException soapException = (VtiSoapException) e; if (soapException.getErrorCode() > 0) { Element errorcode = detail.addElement( QName.get("errorcode", "", "http://schemas.microsoft.com/sharepoint/soap/")); // Codes need to be zero padded to 8 characters, eg 0x12345678 String codeHex = Long.toHexString(soapException.getErrorCode()); while (codeHex.length() < 8) { codeHex = "0" + codeHex; } errorcode.addText("0x" + codeHex); } } } }
From source file:org.alfresco.module.vti.web.ws.CreateDwsEndpoint.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}) *///w w w . j a v a 2s .co m 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 rootElement = soapRequest.getDocument().getRootElement(); // getting title parameter from request String dwsName = getParameter(rootElement, "/CreateDws/name", nc); // getting title parameter from request String title = getParameter(rootElement, "/CreateDws/title", nc); String parentDws = getDwsForCreationFromUri(soapRequest); DwsBean dws = handler.createDws(parentDws, dwsName, null, title, null, getHost(soapRequest), getContext(soapRequest), (SessionUser) soapRequest.getSession().getAttribute(SharepointConstants.USER_SESSION_ATTRIBUTE)); // creating soap response Element resultElement = buildResultTag(soapResponse); resultElement.addText(generateXml(dws)); if (logger.isDebugEnabled()) { logger.debug("SOAP method with name " + getName() + " is finished."); } }
From source file:org.alfresco.module.vti.web.ws.GetDwsMetaDataEndpoint.java
License:Open Source License
/** * Retrieves information about document workspace * //from w w w .j av 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); Element reqElement = soapRequest.getDocument().getRootElement(); // getting document parameter from request XPath docPath = new Dom4jXPath(buildXPath(prefix, "/GetDwsMetaData/document")); docPath.setNamespaceContext(nc); String doc = ((Element) docPath.selectSingleNode(reqElement)).getText(); // getting id parameter from request XPath idPath = new Dom4jXPath(buildXPath(prefix, "/GetDwsMetaData/id")); idPath.setNamespaceContext(nc); Element id = (Element) idPath.selectSingleNode(reqElement); // getting minimal parameter from request XPath minimalPath = new Dom4jXPath(buildXPath(prefix, "/GetDwsMetaData/minimal")); minimalPath.setNamespaceContext(nc); Element minimal = (Element) minimalPath.selectSingleNode(reqElement); //getting information about document workspace DwsMetadata dwsMetadata = handler.getDWSMetaData(URLDecoder.decode(doc, "UTF-8"), id.getText(), Boolean.valueOf(minimal.getText())); // creating soap response Element root = soapResponse.getDocument().addElement("GetDwsMetaDataResponse", namespace); Element getDwsMetaDataResult = root.addElement("GetDwsMetaDataResult"); getDwsMetaDataResult.addText(generateXml(dwsMetadata)); if (logger.isDebugEnabled()) { logger.debug("SOAP method with name " + getName() + " is finished."); } }
From source file:org.alfresco.module.vti.web.ws.GetMeetingsInformationEndpoint.java
License:Open Source License
/** * Retrieve information related to meetings * /*from w ww . ja v a 2 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); Element requestElement = soapRequest.getDocument().getRootElement(); // getting requestFlags parameter from request if (logger.isDebugEnabled()) logger.debug("Getting requestFlags from request."); XPath requestFlagsPath = new Dom4jXPath(buildXPath(prefix, "/GetMeetingsInformation/requestFlags")); requestFlagsPath.setNamespaceContext(nc); Element requestFlagsE = (Element) requestFlagsPath.selectSingleNode(requestElement); int requestFlags = 0; if (requestFlagsE != null) { requestFlags = Integer.parseInt(requestFlagsE.getText()); } // Some kinds of calls need a site, some don't String siteName = getDwsFromUri(soapRequest); if (logger.isDebugEnabled()) logger.debug("Site Name is '" + siteName + "', request flags are " + requestFlags); if (siteName.length() > 0) { // Is Flag 0x8 set? 0x8 = Query the status values of one site if ((requestFlags & 8) == 8) { siteName = siteName.substring(1); } else { // There's a specific error code for this case throw new VtiSoapException("vti.meeting.error.subsites", 0x1); } } // getting lcid parameter from request if (logger.isDebugEnabled()) logger.debug("Getting lcid from request."); XPath lcidPath = new Dom4jXPath(buildXPath(prefix, "/GetMeetingsInformation/lcid")); lcidPath.setNamespaceContext(nc); Element lcidE = (Element) lcidPath.selectSingleNode(requestElement); int lcid = 0; if (lcidE != null) { lcid = Integer.parseInt(lcidE.getText()); } // Fetch the meeting details MeetingsInformation info = handler.getMeetingsInformation(siteName, requestFlags, lcid); // writing soap response Element root = soapResponse.getDocument().addElement("GetMeetingsInformationResponse", namespace); Element getMeetingsInformationResult = root.addElement("GetMeetingsInformationResult"); Element meetingsInformation = getMeetingsInformationResult.addElement("MeetingsInformation"); // allow create? Element allowCreate = meetingsInformation.addElement("AllowCreate"); allowCreate.addText(info.isAllowCreate() ? "True" : "False"); // supported languages List<Integer> templateLanguages = info.getTemplateLanguages(); if (!templateLanguages.isEmpty()) { Element listTemplateLanguages = meetingsInformation.addElement("ListTemplateLanguages"); for (Integer language : templateLanguages) { Element LCID = listTemplateLanguages.addElement("LCID"); LCID.addText(String.valueOf(language.intValue())); } } // supported templates List<MwsTemplate> templates = info.getTemplates(); if (!templates.isEmpty()) { Element listTemplates = meetingsInformation.addElement("ListTemplates"); for (MwsTemplate mwsTemplate : templates) { Element template = listTemplates.addElement("Template"); template.addAttribute("Name", mwsTemplate.getName()); template.addAttribute("Title", mwsTemplate.getTitle()); template.addAttribute("Id", String.valueOf(mwsTemplate.getId())); template.addAttribute("Description", mwsTemplate.getDescription()); template.addAttribute("ImageUrl", getHost(soapRequest) + soapRequest.getAlfrescoContextName() + "/resources/images/logo/alfresco3d.jpg"); } } MwsStatus status = info.getStatus(); if (status != null) { Element workspaceStatus = meetingsInformation.addElement("WorkspaceStatus"); workspaceStatus.addAttribute("UniquePermissions", String.valueOf(status.isUniquePermissions())); workspaceStatus.addAttribute("MeetingCount", String.valueOf(status.getMeetingCount())); workspaceStatus.addAttribute("AnonymousAccess", String.valueOf(status.isAnonymousAccess())); workspaceStatus.addAttribute("AllowAuthenticatedUsers", String.valueOf(status.isAllowAuthenticatedUsers())); } soapResponse.setContentType("text/xml"); if (logger.isDebugEnabled()) { logger.debug("SOAP method with name " + getName() + " is finished."); } }