Java Code Examples for org.dom4j.Element#addText()
The following examples show how to use
org.dom4j.Element#addText() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LocationListFlag.java From HeavySpleef with GNU General Public License v3.0 | 6 votes |
@Override public void marshalListItem(Element element, Location item) { Element worldElement = element.addElement("world"); Element xElement = element.addElement("x"); Element yElement = element.addElement("y"); Element zElement = element.addElement("z"); worldElement.addText(item.getWorld().getName()); xElement.addText(String.valueOf(item.getX())); yElement.addText(String.valueOf(item.getY())); zElement.addText(String.valueOf(item.getZ())); if (item.getYaw() != 0f) { element.addElement("yaw").addText(String.valueOf(item.getYaw())); } if (item.getPitch() != 0f) { element.addElement("pitch").addText(String.valueOf(item.getPitch())); } }
Example 2
Source File: ExtensionLobbyWall.java From HeavySpleef with GNU General Public License v3.0 | 6 votes |
public void marshal(Element element) { Element startElement = element.addElement("start"); Element xStartElement = startElement.addElement("x"); Element yStartElement = startElement.addElement("y"); Element zStartElement = startElement.addElement("z"); Element worldStartElement = startElement.addElement("world"); Element endElement = element.addElement("end"); Element xEndElement = endElement.addElement("x"); Element yEndElement = endElement.addElement("y"); Element zEndElement = endElement.addElement("z"); worldStartElement.addText(world.getName()); xStartElement.addText(String.valueOf(start.getBlockX())); yStartElement.addText(String.valueOf(start.getBlockY())); zStartElement.addText(String.valueOf(start.getBlockZ())); xEndElement.addText(String.valueOf(end.getBlockX())); yEndElement.addText(String.valueOf(end.getBlockY())); zEndElement.addText(String.valueOf(end.getBlockZ())); }
Example 3
Source File: ChoiceQuestion.java From olat with Apache License 2.0 | 6 votes |
/** * Feedback, solution and hints in case of failure * * @param resprocessingXML */ private void buildRespconditionKprim_fail(final Element resprocessingXML) { final Element respcondition_fail = resprocessingXML.addElement("respcondition"); respcondition_fail.addAttribute("title", "Fail"); respcondition_fail.addAttribute("continue", "Yes"); final Element conditionvar = respcondition_fail.addElement("conditionvar"); final Element not = conditionvar.addElement("not"); final Element and = not.addElement("and"); for (final Iterator i = getResponses().iterator(); i.hasNext();) { final ChoiceResponse choice = (ChoiceResponse) i.next(); Element varequal; varequal = and.addElement("varequal"); varequal.addAttribute("respident", getIdent()); varequal.addAttribute("case", "Yes"); if (choice.isCorrect()) { varequal.addText(choice.getIdent() + ":correct"); } else { // incorrect answers varequal.addText(choice.getIdent() + ":wrong"); } } QTIEditHelperEBL.addFeedbackFail(respcondition_fail); QTIEditHelperEBL.addFeedbackHint(respcondition_fail); QTIEditHelperEBL.addFeedbackSolution(respcondition_fail); }
Example 4
Source File: ChoiceQuestion.java From olat with Apache License 2.0 | 6 votes |
/** * Build resprocessing for olat response feedbacks (uses naming conventions: respcondition:title is set to _olat_resp_feedback to signal a feedback that it belongs * directly to the response with the same response ident as the current feedback) * * @param resprocessingXML */ private void buildRespconditionOlatFeedback(final Element resprocessingXML) { for (final Iterator i = getResponses().iterator(); i.hasNext();) { final Element respcondition = resprocessingXML.addElement("respcondition"); respcondition.addAttribute("title", "_olat_resp_feedback"); respcondition.addAttribute("continue", "Yes"); final Element conditionvar = respcondition.addElement("conditionvar"); final ChoiceResponse tmpChoice = (ChoiceResponse) i.next(); final Element varequal = conditionvar.addElement("varequal"); varequal.addAttribute("respident", getIdent()); varequal.addAttribute("case", "Yes"); varequal.addText(tmpChoice.getIdent()); QTIEditHelperEBL.addFeedbackOlatResp(respcondition, tmpChoice.getIdent()); } }
Example 5
Source File: UserSetHelper.java From cuba with Apache License 2.0 | 6 votes |
public static String generateSetFilter(Set ids, String entityClass, String componentId, String entityAlias) { Document document = DocumentHelper.createDocument(); Element root = DocumentHelper.createElement("filter"); Element or = root.addElement("and"); Element condition = or.addElement("c"); condition.addAttribute("name", "set"); condition.addAttribute("inExpr", "true"); condition.addAttribute("hidden", "true"); condition.addAttribute("locCaption", "Set filter"); condition.addAttribute("entityAlias", entityAlias); condition.addAttribute("class", entityClass); condition.addAttribute("type", ConditionType.CUSTOM.name()); String listOfId = createIdsString(ids); String randomName = RandomStringUtils.randomAlphabetic(10); condition.addText(entityAlias + ".id in :component$" + componentId + "." + randomName); Element param = condition.addElement("param"); param.addAttribute("name", "component$" + componentId + "." + randomName); param.addAttribute("isFoldersFilterEntitiesSet", "true"); param.addText(listOfId); document.add(root); return Dom4j.writeDocument(document, true); }
Example 6
Source File: XmlText.java From ats-framework with Apache License 2.0 | 6 votes |
/** * Append text to a XML element. * * @param xpath XPath , pointing to a XML element * @param text the text , which will be appended to a XML element * @return this instance * @throws XMLException */ @PublicAtsApi public XmlText appendText( String xpath, String text ) throws XMLException { if (StringUtils.isNullOrEmpty(xpath)) { throw new XMLException("Null/empty xpath is not allowed."); } if (StringUtils.isNullOrEmpty(text)) { throw new XMLException("Null/empty text is not allowed."); } Element element = findElement(xpath); if (element == null) { throw new XMLException("'" + xpath + "' is not a valid path"); } element.addText(text); return this; }
Example 7
Source File: ChoiceQuestion.java From olat with Apache License 2.0 | 6 votes |
/** * Adds condition to resprocessing with ident * * @param resprocessingXML * @param ident * @param mastery * @param points */ private void addRespcondition(final Element resprocessingXML, final String ident, final boolean mastery, final String points) { final Element respcondition = resprocessingXML.addElement("respcondition"); respcondition.addAttribute("continue", "Yes"); if (mastery) { respcondition.addAttribute("title", "Mastery"); } else { respcondition.addAttribute("title", "Fail"); } Element condition = respcondition.addElement("conditionvar"); if (!mastery) { condition = condition.addElement("not"); } final Element varequal = condition.addElement("varequal"); varequal.addAttribute("respident", getIdent()); varequal.addAttribute("case", "Yes"); varequal.addText(ident); final Element setvar = respcondition.addElement("setvar"); setvar.addAttribute("varname", "SCORE"); setvar.addAttribute("action", "Add"); setvar.addText(points); }
Example 8
Source File: EndNodeDef.java From EasyML with Apache License 2.0 | 5 votes |
@Override public void append2XML(Element root) { Element kill = root.addElement("kill"); Element msg = kill.addElement("message"); msg.addText("Map/Reduce failed, error message[${wf:errorMessage(wf:lastErrorNode())}]"); kill.addAttribute("name", "fail"); Element end = root.addElement("end"); end.addAttribute("name", getName()); }
Example 9
Source File: SelectionOrdering.java From olat with Apache License 2.0 | 5 votes |
@Override public void addToElement(final Element root) { final Element selection_ordering = root.addElement("selection_ordering"); final Element selection = selection_ordering.addElement("selection"); if (selectionNumber > 0) { final Element selection_number = selection.addElement("selection_number"); selection_number.addText(String.valueOf(selectionNumber)); } final Element order = selection_ordering.addElement("order"); order.addAttribute(ORDER_TYPE, orderType); }
Example 10
Source File: UpdateManager.java From Openfire with Apache License 2.0 | 5 votes |
private String getAvailablePluginsUpdateRequest() { Element xmlRequest = docFactory.createDocument().addElement("available"); // Add locale so we can get current name and description of plugins Element locale = xmlRequest.addElement("locale"); locale.addText(JiveGlobals.getLocale().toString()); return xmlRequest.asXML(); }
Example 11
Source File: WFGraph.java From EasyML with Apache License 2.0 | 5 votes |
public static void main(String args[]){ Namespace rootNs = new Namespace("", "uri:oozie:workflow:0.4"); // root namespace uri QName rootQName = QName.get("workflow-app", rootNs); // your root element's name Element workflow = DocumentHelper.createElement(rootQName); Document doc = DocumentHelper.createDocument(workflow); workflow.addAttribute("name", "test"); Element test = workflow.addElement("test"); test.addText("hello"); OutputFormat outputFormat = OutputFormat.createPrettyPrint(); outputFormat.setEncoding("UTF-8"); outputFormat.setIndent(true); outputFormat.setIndent(" "); outputFormat.setNewlines(true); try { StringWriter stringWriter = new StringWriter(); XMLWriter xmlWriter = new XMLWriter(stringWriter); xmlWriter.write(doc); xmlWriter.close(); System.out.println( doc.asXML() ); System.out.println( stringWriter.toString().trim()); } catch (Exception ex) { ex.printStackTrace(); } }
Example 12
Source File: ConflictRiskAna.java From Decca with MIT License | 5 votes |
public Element getConflictElement() { Element conflictEle = new DefaultElement("conflictJar"); conflictEle.addAttribute("groupId-artifactId", nodeConflict.getGroupId() + ":" + nodeConflict.getArtifactId()); StringBuilder versions = new StringBuilder(); for (String version : nodeConflict.getVersions()) { versions.append(version); } conflictEle.addAttribute("versions", versions.toString()); int riskLevel = getRiskLevel(); conflictEle.addAttribute("riskLevel", "" + riskLevel); Element versionsEle = conflictEle.addElement("versions"); for (DepJar depJar : nodeConflict.getDepJars()) { versionsEle.add(depJar.geJarConflictEle()); } Element risksEle = conflictEle.addElement("RiskMethods"); risksEle.addAttribute("tip", "methods would be referenced but not be loaded"); if (riskLevel == 3 || riskLevel == 4) { int cnt = 0; for (String rchedMthd : getPrintRisk()) { if(cnt==10) break; if (!nodeConflict.getUsedDepJar().containsMthd(rchedMthd)) { Element riskEle = risksEle.addElement("RiskMthd"); riskEle.addText(rchedMthd.replace('<', ' ').replace('>', ' ')); cnt++; } } } else { } return conflictEle; }
Example 13
Source File: DOM4JHandleTest.java From java-client-api with Apache License 2.0 | 5 votes |
@Test public void testReadWrite() throws SAXException, IOException { // create an identifier for the database document String docId = "/example/jdom-test.xml"; // create a manager for XML database documents XMLDocumentManager docMgr = Common.client.newXMLDocumentManager(); DocumentFactory factory = new DocumentFactory(); // create a dom4j document Document writeDocument = factory.createDocument(); Element root = factory.createElement("root"); root.attributeValue("foo", "bar"); root.add(factory.createElement("child")); root.addText("mixed"); writeDocument.setRootElement(root); // create a handle for the dom4j document DOM4JHandle writeHandle = new DOM4JHandle(writeDocument); // write the document to the database docMgr.write(docId, writeHandle); // create a handle to receive the database content as a dom4j document DOM4JHandle readHandle = new DOM4JHandle(); // read the document content from the database as a dom4j document docMgr.read(docId, readHandle); // access the document content Document readDocument = readHandle.get(); assertNotNull("Wrote null dom4j document", readDocument); assertXMLEqual("dom4j document not equal", writeDocument.asXML(), readDocument.asXML()); // delete the document docMgr.delete(docId); }
Example 14
Source File: SelectionOrdering.java From olat with Apache License 2.0 | 5 votes |
@Override public void addToElement(final Element root) { final Element selection_ordering = root.addElement("selection_ordering"); final Element selection = selection_ordering.addElement("selection"); if (selectionNumber > 0) { final Element selection_number = selection.addElement("selection_number"); selection_number.addText(String.valueOf(selectionNumber)); } final Element order = selection_ordering.addElement("order"); order.addAttribute(ORDER_TYPE, orderType); }
Example 15
Source File: ChoiceQuestion.java From olat with Apache License 2.0 | 5 votes |
/** * Build fail resprocessing: Adjust score to 0 (if multiple correct mode) and set hints, solutions and fail feedback * * @param resprocessingXML * @param isSingleCorrect */ private void buildRespcondition_fail(final Element resprocessingXML, final boolean isSingleCorrect) { // build final Element respcondition_fail = resprocessingXML.addElement("respcondition"); respcondition_fail.addAttribute("title", "Fail"); respcondition_fail.addAttribute("continue", "Yes"); final Element conditionvar = respcondition_fail.addElement("conditionvar"); final Element or = conditionvar.addElement("or"); for (final Iterator i = getResponses().iterator(); i.hasNext();) { final ChoiceResponse tmpChoice = (ChoiceResponse) i.next(); Element varequal; // Add this response to the fail case // if single correct type and not correct // or multi correct and points negative or 0 if ((isSingleCorrect && !tmpChoice.isCorrect()) || (!isSingleCorrect && tmpChoice.getPoints() <= 0)) { varequal = or.addElement("varequal"); varequal.addAttribute("respident", getIdent()); varequal.addAttribute("case", "Yes"); varequal.addText(tmpChoice.getIdent()); } } // for loop if (isSingleCorrect) { final Element setvar = respcondition_fail.addElement("setvar"); setvar.addAttribute("varname", "SCORE"); setvar.addAttribute("action", "Set"); setvar.addText("0"); } // Use fail feedback, hints and solutions QTIEditHelperEBL.addFeedbackFail(respcondition_fail); QTIEditHelperEBL.addFeedbackHint(respcondition_fail); QTIEditHelperEBL.addFeedbackSolution(respcondition_fail); // remove whole respcondition if empty if (or.element("varequal") == null) { resprocessingXML.remove(respcondition_fail); } }
Example 16
Source File: PersistenceXmlWriter.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
private static void write(Argument arg) throws Exception { try { Document document = DocumentHelper.createDocument(); Element persistence = document.addElement("persistence", "http://java.sun.com/xml/ns/persistence"); persistence.addAttribute(QName.get("schemaLocation", "xsi", "http://www.w3.org/2001/XMLSchema-instance"), "http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"); persistence.addAttribute("version", "2.0"); for (Class<?> cls : scanContainerEntity(arg.getProject())) { Element unit = persistence.addElement("persistence-unit"); unit.addAttribute("name", cls.getCanonicalName()); unit.addAttribute("transaction-type", "RESOURCE_LOCAL"); Element provider = unit.addElement("provider"); provider.addText(PersistenceProviderImpl.class.getCanonicalName()); for (Class<?> o : scanMappedSuperclass(cls)) { Element mapped_element = unit.addElement("class"); mapped_element.addText(o.getCanonicalName()); } Element slice_unit_properties = unit.addElement("properties"); Map<String, String> properties = new LinkedHashMap<String, String>(); for (Entry<String, String> entry : properties.entrySet()) { Element property = slice_unit_properties.addElement("property"); property.addAttribute("name", entry.getKey()); property.addAttribute("value", entry.getValue()); } } OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding("UTF-8"); File file = new File(arg.getPath()); XMLWriter writer = new XMLWriter(new FileWriter(file), format); writer.write(document); writer.close(); System.out.println("create persistence.xml at path:" + arg.getPath()); } catch (Exception e) { e.printStackTrace(); } }
Example 17
Source File: CamelDesignerCoreService.java From tesb-studio-se with Apache License 2.0 | 4 votes |
private void addSpringContent(Item item, Element jobElement) { Element routeSpringElement = jobElement.addElement("RouteSpring"); routeSpringElement.addAttribute(QName.get("space", Namespace.XML_NAMESPACE), "preserve"); String springContent = ((CamelProcessItem) item).getSpringContent(); routeSpringElement.addText(springContent); }
Example 18
Source File: BooleanFlag.java From HeavySpleef with GNU General Public License v3.0 | 4 votes |
@Override public void marshal(Element element) { element.addText(String.valueOf(getValue())); }
Example 19
Source File: IntegerFlag.java From HeavySpleef with GNU General Public License v3.0 | 4 votes |
@Override public void marshal(Element element) { element.addText(String.valueOf(getValue())); }
Example 20
Source File: ChoiceQuestion.java From olat with Apache License 2.0 | 4 votes |
/** * Build resprocessing for multiple choice item with a single correct answer. Set score to correct value and use mastery feedback. * * @param resprocessingXML */ private void buildRespconditionMCSingle_mastery(final Element resprocessingXML) { final Element respcondition_correct = resprocessingXML.addElement("respcondition"); respcondition_correct.addAttribute("title", "Mastery"); respcondition_correct.addAttribute("continue", "Yes"); final Element conditionvar = respcondition_correct.addElement("conditionvar"); final Element and = conditionvar.addElement("and"); final Element not = conditionvar.addElement("not"); final Element or = not.addElement("or"); for (final Iterator i = getResponses().iterator(); i.hasNext();) { final ChoiceResponse tmpChoice = (ChoiceResponse) i.next(); Element varequal; if (tmpChoice.isCorrect()) { // correct answers varequal = and.addElement("varequal"); } else { // incorrect answers varequal = or.addElement("varequal"); } varequal.addAttribute("respident", getIdent()); varequal.addAttribute("case", "Yes"); varequal.addText(tmpChoice.getIdent()); } // for loop final Element setvar = respcondition_correct.addElement("setvar"); setvar.addAttribute("varname", "SCORE"); setvar.addAttribute("action", "Set"); setvar.addText("" + getSingleCorrectScore()); // Use mastery feedback QTIEditHelperEBL.addFeedbackMastery(respcondition_correct); // remove whole respcondition if empty if (or.element("varequal") == null && and.element("varequal") == null) { resprocessingXML.remove(respcondition_correct); } else { // remove any unset <and> and <not> nodes if (and.element("varequal") == null) { conditionvar.remove(and); } if (or.element("varequal") == null) { conditionvar.remove(not); } } }