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:org.alfresco.module.vti.web.ws.IsClaimsModeEndpoint.java
License:Open Source License
/** * Informs the client that we don't do claims mode * * @param soapRequest Vti soap request ({@link VtiSoapRequest}) * @param soapResponse Vti soap response ({@link VtiSoapResponse}) *//*from ww w.jav a 2 s. c o m*/ public void execute(VtiSoapRequest soapRequest, VtiSoapResponse soapResponse) throws Exception { if (logger.isDebugEnabled()) { logger.debug("SOAP method with name " + getName() + " is started."); } // creating soap response Element root = soapResponse.getDocument().addElement("IsClaimsModeResponse", namespace); Element result = root.addElement("IsClaimsModeResult"); // We don't support it result.addText("False"); // Completed if (logger.isDebugEnabled()) { logger.debug("SOAP method with name " + getName() + " is finished."); } }
From source file:org.alfresco.module.vti.web.ws.UpdateDwsDataEndpoint.java
License:Open Source License
/** * Update dws data for site/* w w w. j ava2s . c o m*/ * * @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); XPath updatesPath = new Dom4jXPath(buildXPath(prefix, "/UpdateDwsData/updates")); updatesPath.setNamespaceContext(nc); Element updates = (Element) updatesPath.selectSingleNode(soapRequest.getDocument().getRootElement()); Document updatesDocument = DocumentHelper.parseText(updates.getText()); XPath setVarPath = new Dom4jXPath("/Batch/Method/SetVar"); List<Element> list = setVarPath.selectNodes(updatesDocument); LinkBean link = createLink(list); XPath methodPath = new Dom4jXPath("/Batch/Method"); CAMLMethod method = CAMLMethod .value(((Element) methodPath.selectSingleNode(updatesDocument)).attributeValue("ID")); Element root = soapResponse.getDocument().addElement("UpdateDwsDataResponse", namespace); Element updateDwsDataResult = root.addElement("UpdateDwsDataResult"); Element results = updateDwsDataResult.addElement("Results"); Element result = results.addElement("Result"); result.addAttribute("ID", method.toString()); result.addAttribute("Code", "0"); try { link = handler.updateDwsData(link, method, VtiPathHelper.removeSlashes(getDwsFromUri(soapRequest))); } catch (VtiHandlerException e) { if (e.getMessage().equals(VtiHandlerException.ITEM_NOT_FOUND)) { result.addElement("Error").addAttribute("ID", "5"); return; } else if (e.getMessage().equals(VtiHandlerException.LIST_NOT_FOUND)) { result.addElement("Error").addAttribute("ID", "7"); return; } else { throw e; } } if (method.toString().equals("New")) { result.addText(generateXml(link)); } else { result.addAttribute("List", ""); result.addAttribute("Version", "0"); } if (logger.isDebugEnabled()) { logger.debug("SOAP method with name " + getName() + " is finished."); } }
From source file:org.apache.maven.archetype.common.DefaultPomManager.java
License:Apache License
public void addModule(File pom, String artifactId) throws IOException, XmlPullParserException, DocumentException, InvalidPackaging { boolean found = false; StringWriter writer = new StringWriter(); Reader fileReader = null;/*ww w . j a va 2 s. c o m*/ try { fileReader = ReaderFactory.newXmlReader(pom); SAXReader reader = new SAXReader(); Document document = reader.read(fileReader); Element project = document.getRootElement(); String packaging = null; Element packagingElement = project.element("packaging"); if (packagingElement != null) { packaging = packagingElement.getStringValue(); } if (!"pom".equals(packaging)) { throw new InvalidPackaging( "Unable to add module to the current project as it is not of packaging type 'pom'"); } Element modules = project.element("modules"); if (modules == null) { modules = project.addText(" ").addElement("modules"); modules.setText("\n "); project.addText("\n"); } // TODO: change to while loop for (@SuppressWarnings("unchecked") Iterator<Element> i = modules.elementIterator("module"); i.hasNext() && !found;) { Element module = i.next(); if (module.getText().equals(artifactId)) { found = true; } } if (!found) { Node lastTextNode = null; for (@SuppressWarnings("unchecked") Iterator<Node> i = modules.nodeIterator(); i.hasNext();) { Node node = i.next(); if (node.getNodeType() == Node.ELEMENT_NODE) { lastTextNode = null; } else if (node.getNodeType() == Node.TEXT_NODE) { lastTextNode = node; } } if (lastTextNode != null) { modules.remove(lastTextNode); } modules.addText("\n "); modules.addElement("module").setText(artifactId); modules.addText("\n "); XMLWriter xmlWriter = new XMLWriter(writer); xmlWriter.write(document); FileUtils.fileWrite(pom.getAbsolutePath(), writer.toString()); } // end if } finally { IOUtil.close(fileReader); } }
From source file:org.apache.maven.archetype.old.DefaultOldArchetype.java
License:Apache License
static boolean addModuleToParentPom(String artifactId, Reader fileReader, Writer fileWriter) throws DocumentException, IOException, ArchetypeTemplateProcessingException { SAXReader reader = new SAXReader(); Document document = reader.read(fileReader); Element project = document.getRootElement(); String packaging = null;/*from w ww.j av a2s . c o m*/ Element packagingElement = project.element("packaging"); if (packagingElement != null) { packaging = packagingElement.getStringValue(); } if (!"pom".equals(packaging)) { throw new ArchetypeTemplateProcessingException( "Unable to add module to the current project as it is not of packaging type 'pom'"); } Element modules = project.element("modules"); if (modules == null) { modules = project.addText(" ").addElement("modules"); modules.setText("\n "); project.addText("\n"); } boolean found = false; for (Iterator<?> i = modules.elementIterator("module"); i.hasNext() && !found;) { Element module = (Element) i.next(); if (module.getText().equals(artifactId)) { found = true; } } if (!found) { Node lastTextNode = null; for (Iterator<?> i = modules.nodeIterator(); i.hasNext();) { Node node = (Node) i.next(); if (node.getNodeType() == Node.ELEMENT_NODE) { lastTextNode = null; } else if (node.getNodeType() == Node.TEXT_NODE) { lastTextNode = node; } } if (lastTextNode != null) { modules.remove(lastTextNode); } modules.addText("\n "); modules.addElement("module").setText(artifactId); modules.addText("\n "); XMLWriter writer = new XMLWriter(fileWriter); writer.write(document); } return !found; }
From source file:org.apache.openmeetings.servlet.outputhandler.LangExport.java
License:Apache License
public Document createDocument(List<Fieldlanguagesvalues> flvList, List<Fieldlanguagesvalues> untranslatedList) throws Exception { Document document = createDocument(); Element root = createRoot(document); for (Fieldlanguagesvalues flv : flvList) { Element eTemp = root.addElement("string") .addAttribute("id", flv.getFieldvalues().getFieldvalues_id().toString()) .addAttribute("name", flv.getFieldvalues().getName()); Element value = eTemp.addElement("value"); value.addText(flv.getValue()); }//from ww w. j av a 2 s. c o m //untranslated if (untranslatedList.size() > 0) { root.addComment("Untranslated strings"); for (Fieldlanguagesvalues flv : untranslatedList) { Element eTemp = root.addElement("string") .addAttribute("id", flv.getFieldvalues().getFieldvalues_id().toString()) .addAttribute("name", flv.getFieldvalues().getName()); Element value = eTemp.addElement("value"); value.addText(flv.getValue()); } } return document; }
From source file:org.apache.openmeetings.web.admin.labels.LangPanel.java
License:Apache License
public static Document createDocument(List<Fieldlanguagesvalues> flvList, List<Fieldlanguagesvalues> untranslatedList) throws Exception { Document document = LangExport.createDocument(); Element root = LangExport.createRoot(document); for (Fieldlanguagesvalues flv : flvList) { Element eTemp = root.addElement("string") .addAttribute("id", flv.getFieldvalues().getFieldvalues_id().toString()) .addAttribute("name", flv.getFieldvalues().getName()); Element value = eTemp.addElement("value"); value.addText(flv.getValue()); }// w w w . ja va2s . c om //untranslated if (untranslatedList.size() > 0) { root.addComment("Untranslated strings"); for (Fieldlanguagesvalues flv : untranslatedList) { Element eTemp = root.addElement("string") .addAttribute("id", flv.getFieldvalues().getFieldvalues_id().toString()) .addAttribute("name", flv.getFieldvalues().getName()); Element value = eTemp.addElement("value"); value.addText(flv.getValue()); } } return document; }
From source file:org.apache.poi.openxml4j.opc.internal.marshallers.PackagePropertiesMarshaller.java
License:Apache License
/** * Add category property element if needed. *//*w w w . jav a2s . c o m*/ private void addCategory() { if (!propsPart.getCategoryProperty().hasValue()) return; Element elem = xmlDoc.getRootElement().element(new QName(KEYWORD_CATEGORY, namespaceCoreProperties)); if (elem == null) { // Missing, we add it elem = xmlDoc.getRootElement().addElement(new QName(KEYWORD_CATEGORY, namespaceCoreProperties)); } else { elem.clearContent();// clear the old value } elem.addText(propsPart.getCategoryProperty().getValue()); }
From source file:org.apache.poi.openxml4j.opc.internal.marshallers.PackagePropertiesMarshaller.java
License:Apache License
/** * Add content status property element if needed. *//*ww w . ja v a 2 s . c o m*/ private void addContentStatus() { if (!propsPart.getContentStatusProperty().hasValue()) return; Element elem = xmlDoc.getRootElement().element(new QName(KEYWORD_CONTENT_STATUS, namespaceCoreProperties)); if (elem == null) { // Missing, we add it elem = xmlDoc.getRootElement().addElement(new QName(KEYWORD_CONTENT_STATUS, namespaceCoreProperties)); } else { elem.clearContent();// clear the old value } elem.addText(propsPart.getContentStatusProperty().getValue()); }
From source file:org.apache.poi.openxml4j.opc.internal.marshallers.PackagePropertiesMarshaller.java
License:Apache License
/** * Add content type property element if needed. *//*from w ww .jav a2 s. co m*/ private void addContentType() { if (!propsPart.getContentTypeProperty().hasValue()) return; Element elem = xmlDoc.getRootElement().element(new QName(KEYWORD_CONTENT_TYPE, namespaceCoreProperties)); if (elem == null) { // Missing, we add it elem = xmlDoc.getRootElement().addElement(new QName(KEYWORD_CONTENT_TYPE, namespaceCoreProperties)); } else { elem.clearContent();// clear the old value } elem.addText(propsPart.getContentTypeProperty().getValue()); }
From source file:org.apache.poi.openxml4j.opc.internal.marshallers.PackagePropertiesMarshaller.java
License:Apache License
/** * Add created property element if needed. */// www . ja v a 2 s.c o m private void addCreated() { if (!propsPart.getCreatedProperty().hasValue()) return; Element elem = xmlDoc.getRootElement().element(new QName(KEYWORD_CREATED, namespaceDcTerms)); if (elem == null) { // missing, we add it elem = xmlDoc.getRootElement().addElement(new QName(KEYWORD_CREATED, namespaceDcTerms)); } else { elem.clearContent();// clear the old value } elem.addAttribute(new QName("type", namespaceXSI), "dcterms:W3CDTF"); elem.addText(propsPart.getCreatedPropertyString()); }