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.neuclear.xml.AbstractElementProxy.java
License:LGPL
/** * Adds another Element with the given name and the same Namespace as this element to this element. * * @param child// w w w. j a v a 2 s . c o m */ protected final Element addElement(final String child, final String text) { Element elem = addElement(child); elem.addText(text); return elem; }
From source file:org.neuclear.xml.xmlsec.HTMLSignature.java
License:Open Source License
private void createHTMLBadge(Element elem) { Element head = elem.element("head"); Element body = elem.element("body"); // body.addElement("hr"); Element title = body.addElement("p"); title.addAttribute("id", "dsigtitle"); title.addAttribute("style", TITLESTYLE); title.setText("This page has been digitally signed."); body.addText("\n"); }
From source file:org.nuxeo.ecm.core.io.impl.transformers.FieldMapper.java
License:Open Source License
@Override public boolean transform(ExportedDocument xdoc) throws IOException { Element root = xdoc.getDocument().getRootElement(); List<Object> schemas = root.elements("schema"); Element src = null;//from w ww . j a v a2s.co m if (schemas != null) { for (Object s : schemas) { Element schema = (Element) s; String name = schema.attribute("name").getText(); if (srcSchemaName.equalsIgnoreCase(name)) { src = schema.element(getUnprefixedName(srcField)); src.detach(); } } Element dstSchema = null; if (dstField == null || src == null) { // NOP } else { for (Object s : schemas) { Element schema = (Element) s; String name = schema.attribute("name").getText(); if (dstSchemaName.equalsIgnoreCase(name)) { dstSchema = schema; break; } } if (dstSchema == null) { dstSchema = root.addElement("schema"); dstSchema.addAttribute("name", dstSchemaName); } Element dst = dstSchema.element(getUnprefixedName(dstField)); if (dst == null) { String prefix = getPrefix(dstField); if (prefix == null || dstSchema.getNamespaceForPrefix(prefix) == null) { dst = dstSchema.addElement(getUnprefixedName(dstField)); } else { dst = dstSchema.addElement(dstField); } } for (Object sub : src.elements()) { Element e = (Element) sub; e.detach(); dst.add(e); } String txt = src.getText(); if (txt != null) { dst.addText(txt); } } } return true; }
From source file:org.nuxeo.ecm.core.io.impl.TypedExportedDocumentImpl.java
License:Apache License
/** * Here we do what super does but add the "type" attribute to the XML elements. *///w ww. j a v a 2 s . c o m @Override @SuppressWarnings("rawtypes") protected void readProperty(Element parent, Namespace targetNs, Field field, Object value, boolean inlineBlobs) throws IOException { Type type = field.getType(); QName name = QName.get(field.getName().getLocalName(), targetNs.prefix, targetNs.uri); Element element = parent.addElement(name); // extract the element content if (type.isSimpleType()) { element.addAttribute(TYPE_ATTRIBUTE, getSimpleTypeId(type)); if (value != null) { element.addText(type.encode(value)); } } else if (type.isComplexType()) { ComplexType ctype = (ComplexType) type; if (TypeConstants.isContentType(ctype)) { element.addAttribute(TYPE_ATTRIBUTE, TypeConstants.CONTENT); if (value != null) { readBlob(element, ctype, (Blob) value, inlineBlobs); } } else { element.addAttribute(TYPE_ATTRIBUTE, COMPLEX_TYPE_ID); if (value != null) { readComplex(element, ctype, (Map) value, inlineBlobs); } } } else if (type.isListType()) { String typeId; ListType listType = ((ListType) type); // Scalar list if (listType.isScalarList()) { typeId = SCALAR_LIST_TYPE_ID; } // Content list else if (TypeConstants.isContentType(listType.getFieldType())) { typeId = CONTENT_LIST_TYPE_ID; } // Complex list else { typeId = COMPLEX_LIST_TYPE_ID; } element.addAttribute(TYPE_ATTRIBUTE, typeId); if (value != null) { if (value instanceof List) { readList(element, (ListType) type, (List) value, inlineBlobs); } else if (value.getClass().getComponentType() != null) { readList(element, (ListType) type, PrimitiveArrays.toList(value), inlineBlobs); } else { throw new IllegalArgumentException( "A value of list type is neither list neither array: " + value); } } } }
From source file:org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion.java
License:Apache License
/** * Build XML tree (presentation & resprocessing) *///from ww w . j ava 2 s .co m public void addToElement(final Element root) { final Element presentationXML = root.addElement("presentation"); presentationXML.addAttribute("label", getLable()); // Question getQuestion().addToElement(presentationXML); final Element response_lid = presentationXML.addElement("response_lid"); response_lid.addAttribute("ident", getIdent()); response_lid.addAttribute("rcardinality", (getType() == TYPE_SC) ? "Single" : "Multiple"); response_lid.addAttribute("rtiming", "No"); final Element render_choice = response_lid.addElement("render_choice"); render_choice.addAttribute("shuffle", isShuffle() ? "Yes" : "No"); render_choice.addAttribute("minnumber", getType() == TYPE_SC ? "1" : "0"); render_choice.addAttribute("maxnumber", getType() == TYPE_SC ? "1" : String.valueOf(getResponses().size())); for (final Iterator i = getResponses().iterator(); i.hasNext();) { final ChoiceResponse tmpChoice = (ChoiceResponse) i.next(); final Element flow_label = render_choice.addElement("flow_label"); // Add horizontal or vertical alignment. All flow_labels get the // same value flow_label.addAttribute("class", getFlowLabelClass()); final Element response_lable = flow_label.addElement("response_label"); response_lable.addAttribute("ident", tmpChoice.getIdent()); response_lable.addAttribute("rshuffle", "Yes"); // QTI default value tmpChoice.getContent().addToElement(response_lable); } // ------------------ final Element resprocessingXML = root.addElement("resprocessing"); final Element outcomes = resprocessingXML.addElement("outcomes"); final Element decvar = outcomes.addElement("decvar"); decvar.addAttribute("varname", "SCORE"); decvar.addAttribute("vartype", "Decimal"); decvar.addAttribute("defaultval", "0"); decvar.addAttribute("minvalue", "" + getMinValue()); float maxScore = QTIEditHelper.calculateMaxScore(this); maxScore = maxScore > getMaxValue() ? getMaxValue() : maxScore; decvar.addAttribute("maxvalue", "" + maxScore); decvar.addAttribute("cutvalue", "" + maxScore); // process respcondition_correct and fail if (getType() == TYPE_SC) { buildRespconditionSC_mastery(resprocessingXML); buildRespcondition_fail(resprocessingXML, true); } else if (getType() == TYPE_MC) { if (isSingleCorrect()) { buildRespconditionMCSingle_mastery(resprocessingXML); buildRespcondition_fail(resprocessingXML, true); } else { buildRespconditionMCMulti_mastery(resprocessingXML); buildRespcondition_fail(resprocessingXML, false); } } else if (getType() == TYPE_KPRIM) { buildRespconditionKprim(resprocessingXML); buildRespconditionKprim_fail(resprocessingXML); } // hint if (getHintText() != null) { QTIEditHelper.addHintElement(root, getHintText()); } // solution if (getSolutionText() != null) { QTIEditHelper.addSolutionElement(root, getSolutionText()); } // Response feedback if (getType() != TYPE_KPRIM) { buildRespconditionOlatFeedback(resprocessingXML); // Feedback for all other cases eg. none has been selected final Element respcondition_incorrect = resprocessingXML.addElement("respcondition"); respcondition_incorrect.addAttribute("title", "Fail"); respcondition_incorrect.addAttribute("continue", "Yes"); respcondition_incorrect.addElement("conditionvar").addElement("other"); final Element setvar = respcondition_incorrect.addElement("setvar"); setvar.addAttribute("varname", "SCORE"); setvar.addAttribute("action", "Set"); setvar.addText("0"); QTIEditHelper.addFeedbackFail(respcondition_incorrect); QTIEditHelper.addFeedbackHint(respcondition_incorrect); QTIEditHelper.addFeedbackSolution(respcondition_incorrect); } }
From source file:org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion.java
License:Apache License
/** * Build resprocessing for single choice item. Set score to correct value and use mastery feedback * /*from w w w.j a va 2 s . c o m*/ * @param resprocessingXML */ private void buildRespconditionSC_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"); for (final Iterator i = getResponses().iterator(); i.hasNext();) { // fetch correct answer (there should be a single instance) final ChoiceResponse tmpChoice = (ChoiceResponse) i.next(); if (!tmpChoice.isCorrect()) { continue; } // found correct answer final Element varequal = conditionvar.addElement("varequal"); varequal.addAttribute("respident", getIdent()); varequal.addAttribute("case", "Yes"); varequal.addText(tmpChoice.getIdent()); break; } // for loop // check if conditionvar has correct value if (conditionvar.elements().size() == 0) { resprocessingXML.remove(respcondition_correct); return; } final Element setvar = respcondition_correct.addElement("setvar"); setvar.addAttribute("varname", "SCORE"); setvar.addAttribute("action", "Set"); setvar.addText("" + getSingleCorrectScore()); // Use mastery feedback QTIEditHelper.addFeedbackMastery(respcondition_correct); }
From source file:org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion.java
License:Apache License
/** * Build resprocessing for multiple choice item with a single correct answer. Set score to correct value and use mastery feedback. * //from w w w . j a v a 2 s . c o m * @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 QTIEditHelper.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); } } }
From source file:org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion.java
License:Apache License
/** * Build resprocessing for multiple choice question with multiple correct answers. Sets correct score for positive (mastery) and negative (fail) conditions and use * mastery feedback when all mastery responses have been selected. * //w ww . ja v a 2s . c o m * @param resprocessingXML */ private void buildRespconditionMCMulti_mastery(final Element resprocessingXML) { for (final Iterator i = getResponses().iterator(); i.hasNext();) { final ChoiceResponse tmpChoice = (ChoiceResponse) i.next(); final float points = tmpChoice.getPoints(); if (points == 0) { continue; } final Element respcondition_correct = resprocessingXML.addElement("respcondition"); respcondition_correct.addAttribute("continue", "Yes"); if (points > 0) { respcondition_correct.addAttribute("title", "Mastery"); } else { respcondition_correct.addAttribute("title", "Fail"); } final Element varequal = respcondition_correct.addElement("conditionvar").addElement("varequal"); varequal.addAttribute("respident", getIdent()); varequal.addAttribute("case", "Yes"); varequal.addText(tmpChoice.getIdent()); final Element setvar = respcondition_correct.addElement("setvar"); setvar.addAttribute("varname", "SCORE"); setvar.addAttribute("action", "Add"); setvar.addText("" + points); } // for loop // Resp condition for feedback mastery: // all response with points>0 must be selected 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.getPoints() > 0) { 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 // Use mastery feedback QTIEditHelper.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); } } }
From source file:org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion.java
License:Apache License
/** * Build resprocessing for Kprim question. * //from w w w . j a v a2 s . c om * @param resprocessingXML */ private void buildRespconditionKprim(final Element resprocessingXML) { for (final Iterator i = getResponses().iterator(); i.hasNext();) { final ChoiceResponse choice = (ChoiceResponse) i.next(); if (choice.isCorrect()) { addRespcondition(resprocessingXML, choice.getIdent() + ":correct", true, String.valueOf(choice.getPoints())); addRespcondition(resprocessingXML, choice.getIdent() + ":correct", false, String.valueOf(-choice.getPoints())); } else { addRespcondition(resprocessingXML, choice.getIdent() + ":wrong", true, String.valueOf(choice.getPoints())); addRespcondition(resprocessingXML, choice.getIdent() + ":wrong", false, String.valueOf(-choice.getPoints())); } } // Resp condition for feedback mastery kprim: 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"); 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 { varequal.addText(choice.getIdent() + ":wrong"); } } // Use mastery feedback QTIEditHelper.addFeedbackMastery(respcondition_correct); }
From source file:org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion.java
License:Apache License
/** * Feedback, solution and hints in case of failure * /*w ww.j av a 2 s . com*/ * @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"); } } QTIEditHelper.addFeedbackFail(respcondition_fail); QTIEditHelper.addFeedbackHint(respcondition_fail); QTIEditHelper.addFeedbackSolution(respcondition_fail); }