Java Code Examples for org.dom4j.Element#addText()

The following examples show how to use org.dom4j.Element#addText() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
@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 Project: olat   File: ChoiceQuestion.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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 3
Source Project: ats-framework   File: XmlText.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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 4
Source Project: olat   File: ChoiceQuestion.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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 5
Source Project: cuba   File: UserSetHelper.java    License: Apache License 2.0 6 votes vote down vote up
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 Project: olat   File: ChoiceQuestion.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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 7
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 8
Source Project: Decca   File: ConflictRiskAna.java    License: MIT License 5 votes vote down vote up
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 9
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 10
Source Project: olat   File: ChoiceQuestion.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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 11
Source Project: olat   File: SelectionOrdering.java    License: Apache License 2.0 5 votes vote down vote up
@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 12
Source Project: java-client-api   File: DOM4JHandleTest.java    License: Apache License 2.0 5 votes vote down vote up
@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 13
Source Project: EasyML   File: EndNodeDef.java    License: Apache License 2.0 5 votes vote down vote up
@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 14
Source Project: EasyML   File: WFGraph.java    License: Apache License 2.0 5 votes vote down vote up
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 15
Source Project: Openfire   File: UpdateManager.java    License: Apache License 2.0 5 votes vote down vote up
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 16
Source Project: olat   File: SelectionOrdering.java    License: Apache License 2.0 5 votes vote down vote up
@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 17
@Override
public void marshal(Element element) {
	element.addText(String.valueOf(getValue()));
}
 
Example 18
@Override
public void marshal(Element element) {
	element.addText(String.valueOf(getValue()));
}
 
Example 19
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 20
Source Project: olat   File: ChoiceQuestion.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 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);
        }
    }

}