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.olat.ims.qti.editor.beecom.objects.ChoiceQuestion.java
License:Apache License
/** * Adds condition to resprocessing with ident * /*w w w . ja v a 2s . c o m*/ * @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); }
From source file:org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion.java
License:Apache License
/** * Build fail resprocessing: Adjust score to 0 (if multiple correct mode) and set hints, solutions and fail feedback * /* www.ja v a2s. c o m*/ * @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 QTIEditHelper.addFeedbackFail(respcondition_fail); QTIEditHelper.addFeedbackHint(respcondition_fail); QTIEditHelper.addFeedbackSolution(respcondition_fail); // remove whole respcondition if empty if (or.element("varequal") == null) { resprocessingXML.remove(respcondition_fail); } }
From source file:org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion.java
License:Apache License
/** * 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) * //from w w w . ja v a2 s . c o m * @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()); QTIEditHelper.addFeedbackOlatResp(respcondition, tmpChoice.getIdent()); } }
From source file:org.olat.ims.qti.editor.beecom.objects.FIBQuestion.java
License:Apache License
/** * Build fail resprocessing: Adjust score to 0 (if single correct mode) and set hints, solutions and fail feedback when any blank is answered wrong * // w w w . j a v a 2 s . co m * @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 FIBResponse tmpResponse = (FIBResponse) i.next(); if (!tmpResponse.getType().equals(FIBResponse.TYPE_BLANK)) { continue; } final Element not = or.addElement("not"); final Element varequal = not.addElement("varequal"); varequal.addAttribute("respident", tmpResponse.getIdent()); varequal.addAttribute("case", tmpResponse.getCaseSensitive()); varequal.setText(tmpResponse.getCorrectBlank()); } // 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 QTIEditHelper.addFeedbackFail(respcondition_fail); QTIEditHelper.addFeedbackHint(respcondition_fail); QTIEditHelper.addFeedbackSolution(respcondition_fail); // remove whole respcondition if empty if (or.element("varequal") == null) { resprocessingXML.remove(respcondition_fail); } }
From source file:org.olat.ims.qti.editor.beecom.objects.SelectionOrdering.java
License:Apache License
@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)); }/*from ww w. j a va 2s. c o m*/ final Element order = selection_ordering.addElement("order"); order.addAttribute(ORDER_TYPE, orderType); }
From source file:org.olat.ims.qti.render.ResultsBuilder.java
License:Apache License
/** * Method getResDoc.// w w w . jav a2s. c o m * * @param ai The assessment instance * @param locale The users locale * @param identity * @return Document The XML document */ public Document getResDoc(final AssessmentInstance ai, final Locale locale, final Identity identity) { final AssessmentContext ac = ai.getAssessmentContext(); final DocumentFactory df = DocumentFactory.getInstance(); final Document res_doc = df.createDocument(); final Element root = df.createElement("qti_result_report"); res_doc.setRootElement(root); final Element result = root.addElement("result"); final Element extension_result = result.addElement("extension_result"); // add items (not qti standard, but nice to display original questions -> // put it into extensions) // extension_result. final int sectioncnt = ac.getSectionContextCount(); for (int i = 0; i < sectioncnt; i++) { final SectionContext sc = ac.getSectionContext(i); final int itemcnt = sc.getItemContextCount(); for (int j = 0; j < itemcnt; j++) { final ItemContext it = sc.getItemContext(j); final Element el_item = it.getEl_item(); extension_result.add(el_item); } } // add ims cp id for any media references addStaticsPath(extension_result, ai); // add assessment_result // Add User information final Element context = result.addElement("context"); final User user = identity.getUser(); final String name = user.getProperty(UserConstants.LASTNAME, locale) + " " + user.getProperty(UserConstants.FIRSTNAME, locale) + " (" + identity.getName() + ")"; String instId = user.getProperty(UserConstants.INSTITUTIONALUSERIDENTIFIER, locale); final String instName = user.getProperty(UserConstants.INSTITUTIONALNAME, locale); if (instId == null) { instId = "N/A"; } context.addElement("name").addText(name); String institution; if (instName == null) { institution = "N/A"; } else { institution = instName; } if (institution == null) { institution = "N/A"; } // Add institutional identifier (e.g. Matrikelnummer) final Element generic_identifier = context.addElement("generic_identifier"); generic_identifier.addElement("type_label").addText(institution); generic_identifier.addElement("identifier_string").addText(instId); // Add start and stop date formatted as datetime final Element beginDate = context.addElement("date"); beginDate.addElement("type_label").addText("Start"); beginDate.addElement("datetime").addText(Formatter.formatDatetime(new Date(ac.getTimeOfStart()))); final Element stopDate = context.addElement("date"); stopDate.addElement("type_label").addText("Stop"); stopDate.addElement("datetime").addText(Formatter.formatDatetime(new Date(ac.getTimeOfStop()))); final Element ares = result.addElement("assessment_result"); ares.addAttribute("ident_ref", ac.getIdent()); if (ac.getTitle() != null) { ares.addAttribute("asi_title", ac.getTitle()); } // process assessment score final Element a_score = ares.addElement("outcomes").addElement("score"); a_score.addAttribute("varname", "SCORE"); String strVal = StringHelper.formatFloat(ac.getScore(), 2); a_score.addElement("score_value").addText(strVal); strVal = ac.getMaxScore() == -1.0f ? "N/A" : StringHelper.formatFloat(ac.getMaxScore(), 2); a_score.addElement("score_max").addText(strVal); strVal = ac.getCutvalue() == -1.0f ? "N/A" : StringHelper.formatFloat(ac.getCutvalue(), 2); a_score.addElement("score_cut").addText(strVal); addElementText(ares, "duration", QTIHelper.getISODuration(ac.getDuration())); addElementText(ares, "num_sections", "" + ac.getSectionContextCount()); addElementText(ares, "num_sections_presented", "0"); addElementText(ares, "num_items", "" + ac.getItemContextCount()); addElementText(ares, "num_items_presented", "" + ac.getItemsPresentedCount()); addElementText(ares, "num_items_attempted", "" + ac.getItemsAttemptedCount()); // add section_result final int secnt = ac.getSectionContextCount(); for (int i = 0; i < secnt; i++) { final SectionContext secc = ac.getSectionContext(i); final Element secres = ares.addElement("section_result"); secres.addAttribute("ident_ref", secc.getIdent()); if (secc.getTitle() != null) { secres.addAttribute("asi_title", secc.getTitle()); } addElementText(secres, "duration", QTIHelper.getISODuration(secc.getDuration())); addElementText(secres, "num_items", "" + secc.getItemContextCount()); addElementText(secres, "num_items_presented", "" + secc.getItemsPresentedCount()); addElementText(secres, "num_items_attempted", "" + secc.getItemsAttemptedCount()); // process section score final Element sec_score = secres.addElement("outcomes").addElement("score"); sec_score.addAttribute("varname", "SCORE"); strVal = secc.getScore() == -1.0f ? "N/A" : "" + StringHelper.formatFloat(secc.getScore(), 2); sec_score.addElement("score_value").addText(strVal); strVal = secc.getMaxScore() == -1.0f ? "N/A" : "" + StringHelper.formatFloat(secc.getMaxScore(), 2); sec_score.addElement("score_max").addText(strVal); strVal = secc.getCutValue() == -1 ? "N/A" : "" + secc.getCutValue(); sec_score.addElement("score_cut").addText(strVal); // iterate over all items in this section context final List itemsc = secc.getSectionItemContexts(); for (final Iterator it_it = itemsc.iterator(); it_it.hasNext();) { final ItemContext itemc = (ItemContext) it_it.next(); final Element itres = secres.addElement("item_result"); itres.addAttribute("ident_ref", itemc.getIdent()); itres.addAttribute("asi_title", itemc.getEl_item().attributeValue("title")); final Element it_duration = itres.addElement("duration"); it_duration.addText(QTIHelper.getISODuration(itemc.getTimeSpent())); // process item score final DecimalVariable scoreVar = (DecimalVariable) (itemc.getVariables().getSCOREVariable()); final Element it_score = itres.addElement("outcomes").addElement("score"); it_score.addAttribute("varname", "SCORE"); it_score.addElement("score_value") .addText(StringHelper.formatFloat(scoreVar.getTruncatedValue(), 2)); strVal = scoreVar.hasMinValue() ? "" + scoreVar.getMinValue() : "0.0"; it_score.addElement("score_min").addText(strVal); strVal = scoreVar.hasMaxValue() ? "" + scoreVar.getMaxValue() : "N/A"; it_score.addElement("score_max").addText(strVal); strVal = scoreVar.hasCutValue() ? "" + scoreVar.getCutValue() : "N/A"; it_score.addElement("score_cut").addText(strVal); final Element el_item = itemc.getEl_item(); final Map res_responsehash = new HashMap(3); // iterate over all responses of this item final List resps = el_item.selectNodes( ".//response_lid|.//response_xy|.//response_str|.//response_num|.//response_grp"); for (final Iterator it_resp = resps.iterator(); it_resp.hasNext();) { final Element resp = (Element) it_resp.next(); final String ident = resp.attributeValue("ident"); final String rcardinality = resp.attributeValue("rcardinality"); final String rtiming = resp.attributeValue("rtiming"); // add new response final Element res_response = itres.addElement("response"); res_response.addAttribute("ident_ref", ident); res_responsehash.put(ident, res_response); // enable lookup of // @identref of <response> // (needed with <varequal> // elements // add new response_form // <response_lid ident="MR01" rcardinality="Multiple" rtiming="No"> final Element res_responseform = res_response.addElement("response_form"); res_responseform.addAttribute("cardinality", rcardinality); res_responseform.addAttribute("timing", rtiming); final String respName = resp.getName(); final String type = respName.substring(respName.indexOf("_") + 1); res_responseform.addAttribute("response_type", type); // add user answer final ItemInput itemInp = itemc.getItemInput(); final Translator trans = Util.createPackageTranslator(QTIModule.class, locale); if (itemInp == null) { // user did not answer this question at all res_response.addElement("response_value").addText(trans.translate("ResBuilder.NoAnswer")); } else { final List userAnswer = itemInp.getAsList(ident); if (userAnswer == null) { // user did not answer this question at // all res_response.addElement("response_value") .addText(trans.translate("ResBuilder.NoAnswer")); } else { // the user chose at least one option of an answer (did not // simply click send) for (final Iterator it_ans = userAnswer.iterator(); it_ans.hasNext();) { res_response.addElement("response_value").addText((String) it_ans.next()); } } } } /* * The simple element correct_response can only list correct elements, that is, no "or" or "and" elements may be in the conditionvar. Pragmatic solution: * if condition has ors or ands, then put whole conditionvar into <extension_response> (proprietary), and for easier cases (just "varequal" "not" * elements) use correct_response. */ final Map corr_answers = new HashMap(); // keys: respIdents, values: HashSet // of correct answers for this // respIdent final List respconds = el_item.selectNodes(".//respcondition"); for (final Iterator it_respc = respconds.iterator(); it_respc.hasNext();) { final Element el_respc = (Element) it_respc.next(); // check for add/set in setvar elements (check for single instance // only -> spec allows for multiple instances) final Element el_setvar = (Element) el_respc.selectSingleNode(".//setvar"); if (el_setvar == null) { continue; } if (el_setvar.attributeValue("action").equals("Add") || el_setvar.attributeValue("action").equals("Set")) { // This resrocessing gives points -> assume correct answer float numPoints = 0; try { numPoints = Float.parseFloat(el_setvar.getTextTrim()); } catch (final NumberFormatException nfe) { // } if (numPoints <= 0) { continue; } Element conditionvar = (Element) el_respc.selectSingleNode(".//conditionvar"); // there is an evaluation defined (a "resprocessing" element exists) // if (xpath(count(.//varequal) + count(.//not) = count(.//*)) is // true, then there are only "not" and "varequal" elements final XPath xCanHandle = DocumentHelper .createXPath("count(.//varequal) + count(.//not) = count(.//*)"); boolean canHandle = xCanHandle.matches(conditionvar); if (!canHandle) { // maybe we have <condvar> <and> <...>, try again final Element el_and = (Element) conditionvar.selectSingleNode("and"); if (el_and != null) { canHandle = xCanHandle.matches(el_and); if (canHandle) { // simultate the el_and to be the conditionvar conditionvar = el_and; } } else { // and finally, maybe we have an <or> element .. final Element el_or = (Element) conditionvar.selectSingleNode("or"); if (el_or != null) { canHandle = xCanHandle.matches(el_or); if (canHandle) { // simultate the el_and to be the conditionvar conditionvar = el_or; } } } } if (!canHandle) { // qti res 1.2.1 can't handle it final Element condcopy = conditionvar.createCopy(); itres.addElement("extension_item_result").add(condcopy); } else { /* * easy case: get all varequal directly under the conditionvar element and assume the "not" elements do not contain "not" elements again... * <!ELEMENT response (qti_comment? , response_form? , num_attempts? , response_value* , extension_response?)> <!ELEMENT response_form * (correct_response* , extension_responseform?)> <!ELEMENT correct_response (#PCDATA)> */ final List vareqs = conditionvar.selectNodes("./varequal"); for (final Iterator it_vareq = vareqs.iterator(); it_vareq.hasNext();) { /* * get the identifier of the response, so that we can attach the <correct_response> to the right <response> element quote: ims qti asi xml * binding :3.6.23.1 <varequal> Element: respident (required). The identifier of the corresponding <response_lid>, <response_xy>, etc. * element (this was assigned using its ident attribute). */ final Element vareq = (Element) it_vareq.next(); final String respIdent = vareq.attributeValue("respident"); Set respIdent_corr_answers = (Set) corr_answers.get(respIdent); if (respIdent_corr_answers == null) { respIdent_corr_answers = new HashSet(3); } respIdent_corr_answers.add(vareq.getText()); corr_answers.put(respIdent, respIdent_corr_answers); } // for varequal } // else varequal } // add/set setvar } // for resprocessing final Set resp_ids = corr_answers.keySet(); for (final Iterator idents = resp_ids.iterator(); idents.hasNext();) { final String respIdent = (String) idents.next(); final Set respIdent_corr_answers = (Set) corr_answers.get(respIdent); final Element res_response = (Element) res_responsehash.get(respIdent); final Element res_respform = res_response.element("response_form"); for (final Iterator iter = respIdent_corr_answers.iterator(); iter.hasNext();) { final String answer = (String) iter.next(); res_respform.addElement("correct_response").addText(answer); } } } // for response_xy } return res_doc; }
From source file:org.openadaptor.auxil.convertor.xml.OrderedMapToXmlConvertor.java
License:Open Source License
/** * Add a child Element to a parent. If the element is an array, then Add each of them as a separate Element. * /*from www . j a v a2 s .c o m*/ * @param parent * Element to add the child(ren) to. * @param name * Child(ren)'s element name * @param value * value(s) to add */ private void addElement(Element parent, String name, Object value) { // Need to create multiple elements. The joys of recursion. if (value instanceof Object[]) { Object[] values = (Object[]) value; for (int i = 0; i < values.length; i++) addElement(parent, name, values[i]); } // Only one element to add else { Element child = parent.addElement(generateElementName(name)); if (value instanceof IOrderedMap) { IOrderedMap map = (IOrderedMap) value; Iterator it = map.keys().iterator(); while (it.hasNext()) { Object keyObject = it.next(); String key = keyObject == null ? NULL_KEY_ELEMENT_TAG : keyObject.toString(); addElement(child, key, map.get(key)); } } else { if (value == null) child.addText(""); else child.addText(value.toString()); } } }
From source file:org.opencms.configuration.CmsParameterConfiguration.java
License:Open Source License
/** * Serializes this parameter configuration for the OpenCms XML configuration.<p> * //w w w . j av a 2 s .c om * For each parameter, a XML node like this<br> * <code> * <param name="theName">theValue</param> * </code><br> * is generated and appended to the provided parent node.<p> * * @param parentNode the parent node where the parameter nodes are appended to * @param parametersToIgnore if not <code>null</code>, * all parameters in this list are not written to the XML * * @return the parent node */ public Element appendToXml(Element parentNode, List<String> parametersToIgnore) { for (Map.Entry<String, Object> entry : m_configurationObjects.entrySet()) { String name = entry.getKey(); // check if the parameter should be ignored if ((parametersToIgnore == null) || !parametersToIgnore.contains(name)) { // now serialize the parameter name and value Object value = entry.getValue(); if (value instanceof List) { @SuppressWarnings("unchecked") List<String> values = (List<String>) value; for (String strValue : values) { // use the original String as value Element paramNode = parentNode.addElement(I_CmsXmlConfiguration.N_PARAM); // set the name attribute paramNode.addAttribute(I_CmsXmlConfiguration.A_NAME, name); // set the text of <param> node paramNode.addText(strValue); } } else { // use the original String as value String strValue = get(name); Element paramNode = parentNode.addElement(I_CmsXmlConfiguration.N_PARAM); // set the name attribute paramNode.addAttribute(I_CmsXmlConfiguration.A_NAME, name); // set the text of <param> node paramNode.addText(strValue); } } } return parentNode; }
From source file:org.opencms.module.CmsModuleXmlHandler.java
License:Open Source License
/** * Generates a detached XML element for a module.<p> * //from w w w. j ava 2 s . co m * @param module the module to generate the XML element for * * @return the detached XML element for the module */ public static Element generateXml(CmsModule module) { Document doc = DocumentHelper.createDocument(); Element moduleElement = doc.addElement(N_MODULE); moduleElement.addElement(N_NAME).setText(module.getName()); if (!module.getName().equals(module.getNiceName())) { moduleElement.addElement(N_NICENAME).addCDATA(module.getNiceName()); } else { moduleElement.addElement(N_NICENAME); } if (CmsStringUtil.isNotEmpty(module.getGroup())) { moduleElement.addElement(N_GROUP).setText(module.getGroup()); } if (CmsStringUtil.isNotEmpty(module.getActionClass())) { moduleElement.addElement(N_CLASS).setText(module.getActionClass()); } else { moduleElement.addElement(N_CLASS); } if (CmsStringUtil.isNotEmpty(module.getDescription())) { moduleElement.addElement(N_DESCRIPTION).addCDATA(module.getDescription()); } else { moduleElement.addElement(N_DESCRIPTION); } moduleElement.addElement(N_VERSION).setText(module.getVersion().toString()); if (CmsStringUtil.isNotEmpty(module.getAuthorName())) { moduleElement.addElement(N_AUTHORNAME).addCDATA(module.getAuthorName()); } else { moduleElement.addElement(N_AUTHORNAME); } if (CmsStringUtil.isNotEmpty(module.getAuthorEmail())) { moduleElement.addElement(N_AUTHOREMAIL).addCDATA(module.getAuthorEmail()); } else { moduleElement.addElement(N_AUTHOREMAIL); } if (module.getDateCreated() != CmsModule.DEFAULT_DATE) { moduleElement.addElement(N_DATECREATED).setText(CmsDateUtil.getHeaderDate(module.getDateCreated())); } else { moduleElement.addElement(N_DATECREATED); } if (CmsStringUtil.isNotEmpty(module.getUserInstalled())) { moduleElement.addElement(N_USERINSTALLED).setText(module.getUserInstalled()); } else { moduleElement.addElement(N_USERINSTALLED); } if (module.getDateInstalled() != CmsModule.DEFAULT_DATE) { moduleElement.addElement(N_DATEINSTALLED).setText(CmsDateUtil.getHeaderDate(module.getDateInstalled())); } else { moduleElement.addElement(N_DATEINSTALLED); } Element dependenciesElement = moduleElement.addElement(N_DEPENDENCIES); for (int i = 0; i < module.getDependencies().size(); i++) { CmsModuleDependency dependency = module.getDependencies().get(i); dependenciesElement.addElement(N_DEPENDENCY) .addAttribute(I_CmsXmlConfiguration.A_NAME, dependency.getName()) .addAttribute(A_VERSION, dependency.getVersion().toString()); } Element exportpointsElement = moduleElement.addElement(I_CmsXmlConfiguration.N_EXPORTPOINTS); for (int i = 0; i < module.getExportPoints().size(); i++) { CmsExportPoint point = module.getExportPoints().get(i); exportpointsElement.addElement(I_CmsXmlConfiguration.N_EXPORTPOINT) .addAttribute(I_CmsXmlConfiguration.A_URI, point.getUri()) .addAttribute(I_CmsXmlConfiguration.A_DESTINATION, point.getConfiguredDestination()); } Element resourcesElement = moduleElement.addElement(N_RESOURCES); for (int i = 0; i < module.getResources().size(); i++) { String resource = module.getResources().get(i); resourcesElement.addElement(I_CmsXmlConfiguration.N_RESOURCE).addAttribute(I_CmsXmlConfiguration.A_URI, resource); } Element parametersElement = moduleElement.addElement(N_PARAMETERS); SortedMap<String, String> parameters = module.getParameters(); if (parameters != null) { List<String> names = new ArrayList<String>(parameters.keySet()); Collections.sort(names); for (String name : names) { String value = parameters.get(name).toString(); Element paramNode = parametersElement.addElement(I_CmsXmlConfiguration.N_PARAM); paramNode.addAttribute(I_CmsXmlConfiguration.A_NAME, name); paramNode.addText(value); } } // add resource types List<I_CmsResourceType> resourceTypes = module.getResourceTypes(); if (resourceTypes.size() > 0) { Element resourcetypesElement = moduleElement.addElement(CmsVfsConfiguration.N_RESOURCETYPES); CmsVfsConfiguration.generateResourceTypeXml(resourcetypesElement, resourceTypes, true); } List<CmsExplorerTypeSettings> explorerTypes = module.getExplorerTypes(); if (explorerTypes.size() > 0) { Element explorerTypesElement = moduleElement.addElement(CmsWorkplaceConfiguration.N_EXPLORERTYPES); CmsWorkplaceConfiguration.generateExplorerTypesXml(explorerTypesElement, explorerTypes, true); } // return the modules node moduleElement.detach(); return moduleElement; }
From source file:org.opencms.relations.CmsLinkUpdateUtil.java
License:Open Source License
/** * Updates the given xml node with the given value.<p> * // w w w.ja v a 2 s.com * @param parent the parent node * @param nodeName the node to update * @param value the value to use to update the given node, can be <code>null</code> * @param cdata if the value should be in a CDATA section or not */ private static void updateNode(Element parent, String nodeName, String value, boolean cdata) { // get current node element Element nodeElement = parent.element(nodeName); if (value != null) { if (nodeElement == null) { // element wasn't there before, add element and set value nodeElement = parent.addElement(nodeName); } // element is there, update element value nodeElement.clearContent(); if (cdata) { nodeElement.addCDATA(value); } else { nodeElement.addText(value); } } else { // remove only if element exists if (nodeElement != null) { // remove element parent.remove(nodeElement); } } }