List of usage examples for org.w3c.dom Attr getValue
public String getValue();
From source file:org.dita.dost.module.BranchFilterModule.java
/** Rewrite href or copy-to if duplicates exist. */ private void rewriteDuplicates(final Element root) { // collect href and copy-to final Map<URI, Map<Set<URI>, List<Attr>>> refs = new HashMap<>(); for (final Element e : getTopicrefs(root)) { Attr attr = e.getAttributeNode(BRANCH_COPY_TO); if (attr == null) { attr = e.getAttributeNode(ATTRIBUTE_NAME_COPY_TO); if (attr == null) { attr = e.getAttributeNode(ATTRIBUTE_NAME_HREF); }/*from w w w.j a v a 2 s. co m*/ } if (attr != null) { final URI h = stripFragment(map.resolve(attr.getValue())); Map<Set<URI>, List<Attr>> attrsMap = refs.computeIfAbsent(h, k -> new HashMap<>()); final Set<URI> currentFilter = getBranchFilters(e); List<Attr> attrs = attrsMap.computeIfAbsent(currentFilter, k -> new ArrayList<>()); attrs.add(attr); } } // check and rewrite for (final Map.Entry<URI, Map<Set<URI>, List<Attr>>> ref : refs.entrySet()) { final Map<Set<URI>, List<Attr>> attrsMaps = ref.getValue(); if (attrsMaps.size() > 1) { if (attrsMaps.containsKey(Collections.EMPTY_LIST)) { attrsMaps.remove(Collections.EMPTY_LIST); } else { Set<URI> first = attrsMaps.keySet().iterator().next(); attrsMaps.remove(first); } int i = 1; for (final Map.Entry<Set<URI>, List<Attr>> attrsMap : attrsMaps.entrySet()) { final String suffix = "-" + i; final List<Attr> attrs = attrsMap.getValue(); for (final Attr attr : attrs) { final String gen = addSuffix(attr.getValue(), suffix); logger.info(MessageUtils.getMessage("DOTJ065I", attr.getValue(), gen) .setLocation(attr.getOwnerElement()).toString()); if (attr.getName().equals(BRANCH_COPY_TO)) { attr.setValue(gen); } else { attr.getOwnerElement().setAttribute(BRANCH_COPY_TO, gen); } final URI dstUri = map.resolve(gen); if (dstUri != null) { final FileInfo hrefFileInfo = job.getFileInfo(currentFile.resolve(attr.getValue())); if (hrefFileInfo != null) { final URI newResult = addSuffix(hrefFileInfo.result, suffix); final FileInfo.Builder dstBuilder = new FileInfo.Builder(hrefFileInfo).uri(dstUri) .result(newResult); if (hrefFileInfo.format == null) { dstBuilder.format(ATTR_FORMAT_VALUE_DITA); } final FileInfo dstFileInfo = dstBuilder.build(); job.add(dstFileInfo); } } } i++; } } } }
From source file:org.dita.dost.reader.ChunkMapReader.java
public static String getValue(final Element elem, final String attrName) { final Attr attr = elem.getAttributeNode(attrName); if (attr != null && !attr.getValue().isEmpty()) { return attr.getValue(); }//from w w w . j av a 2 s . co m return null; }
From source file:org.dita.dost.reader.ChunkMapReader.java
public static String getCascadeValue(final Element elem, final String attrName) { Element current = elem;//from w ww . j av a 2s . c o m while (current != null) { final Attr attr = current.getAttributeNode(attrName); if (attr != null) { return attr.getValue(); } final Node parent = current.getParentNode(); if (parent != null && parent.getNodeType() == Node.ELEMENT_NODE) { current = (Element) parent; } else { break; } } return null; }
From source file:org.dita.dost.util.DitaUtil.java
private static String getFileNameFromMap(String ditaMapPath) { StringBuffer fileName = new StringBuffer(); try {/*from ww w . ja va2 s . c o m*/ FileInputStream ditaMapStream; ditaMapStream = new FileInputStream(ditaMapPath); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); factory.setValidating(false); factory.setFeature("http://xml.org/sax/features/namespaces", false); factory.setFeature("http://xml.org/sax/features/validation", false); factory.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false); factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); DocumentBuilder builder; Document doc = null; XPathExpression expr = null; builder = factory.newDocumentBuilder(); doc = builder.parse(new InputSource(ditaMapStream)); XPathFactory xFactory = XPathFactory.newInstance(); XPath xpath = xFactory.newXPath(); expr = xpath.compile("//bookmap/bookmeta/prodinfo/prodname"); Node prodNameNode = (Node) expr.evaluate(doc, XPathConstants.NODE); if (prodNameNode != null) { fileName.append(prodNameNode.getTextContent()); expr = xpath.compile("//bookmap/bookmeta/prodinfo/vrmlist"); Element vrmlistNode = (Element) expr.evaluate(doc, XPathConstants.NODE); if (vrmlistNode != null) { NodeList versions = vrmlistNode.getElementsByTagName("vrm"); if (versions.getLength() > 0) { NamedNodeMap versionAttributes = versions.item(0).getAttributes(); Attr releaseAttr = (Attr) versionAttributes.getNamedItem("release"); if (releaseAttr != null) { fileName.append(String.format("_%s", releaseAttr.getValue())); } Attr versionAttr = (Attr) versionAttributes.getNamedItem("version"); if (versionAttr != null) { fileName.append(String.format("_%s", versionAttr.getValue())); } } } } else { expr = xpath.compile("/bookmap"); prodNameNode = (Node) expr.evaluate(doc, XPathConstants.NODE); if (prodNameNode != null) { Node node = prodNameNode.getAttributes().getNamedItem("id"); if (node != null) { fileName.append(node.getTextContent()); } } else { expr = xpath.compile("/map"); prodNameNode = (Node) expr.evaluate(doc, XPathConstants.NODE); if (prodNameNode != null) { Node node = prodNameNode.getAttributes().getNamedItem("title"); if (node != null) { fileName.append(node.getTextContent()); } } } } } catch (FileNotFoundException e) { } catch (ParserConfigurationException e) { } catch (SAXException e) { } catch (IOException e) { } catch (XPathExpressionException e) { } return fileName.toString(); }
From source file:org.dita.dost.util.XMLUtils.java
/** * Add or set attribute. Convenience method for {@link #addOrSetAttribute(AttributesImpl, String, String, String, String, String)}. * /*from w ww.j a v a 2 s .c o m*/ * @param atts attributes * @param att attribute node */ public static void addOrSetAttribute(final AttributesImpl atts, final Node att) { if (att.getNodeType() != Node.ATTRIBUTE_NODE) { throw new IllegalArgumentException(); } final Attr a = (Attr) att; String localName = a.getLocalName(); if (localName == null) { localName = a.getName(); final int i = localName.indexOf(':'); if (i != -1) { localName = localName.substring(i + 1); } } addOrSetAttribute(atts, a.getNamespaceURI() != null ? a.getNamespaceURI() : NULL_NS_URI, localName, a.getName() != null ? a.getName() : localName, a.isId() ? "ID" : "CDATA", a.getValue()); }
From source file:org.docx4j.XmlUtils.java
/** * Copy a node from one DOM document to another. Used * to avoid relying on an underlying implementation which might * not support importNode //from w ww . ja va 2 s . c o m * (eg Xalan's org.apache.xml.dtm.ref.DTMNodeProxy). * * WARNING: doesn't fully support namespaces! * * @param sourceNode * @param destParent */ public static void treeCopy(Node sourceNode, Node destParent) { // http://osdir.com/ml/text.xml.xerces-j.devel/2004-04/msg00066.html // suggests the problem has been fixed? // source node maybe org.apache.xml.dtm.ref.DTMNodeProxy // (if its xslt output we are copying) // or com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl // (if its marshalled JAXB) log.debug("node type" + sourceNode.getNodeType()); switch (sourceNode.getNodeType()) { case Node.DOCUMENT_NODE: // type 9 case Node.DOCUMENT_FRAGMENT_NODE: // type 11 // log.debug("DOCUMENT:" + w3CDomNodeToString(sourceNode) ); // if (sourceNode.getChildNodes().getLength()==0) { // log.debug("..no children!"); // } // recurse on each child NodeList nodes = sourceNode.getChildNodes(); if (nodes != null) { for (int i = 0; i < nodes.getLength(); i++) { log.debug("child " + i + "of DOCUMENT_NODE"); //treeCopy((DTMNodeProxy)nodes.item(i), destParent); treeCopy((Node) nodes.item(i), destParent); } } break; case Node.ELEMENT_NODE: // Copy of the node itself log.debug("copying: " + sourceNode.getNodeName()); Node newChild; if (destParent instanceof Document) { newChild = ((Document) destParent).createElementNS(sourceNode.getNamespaceURI(), sourceNode.getLocalName()); } else if (sourceNode.getNamespaceURI() != null) { newChild = destParent.getOwnerDocument().createElementNS(sourceNode.getNamespaceURI(), sourceNode.getLocalName()); } else { newChild = destParent.getOwnerDocument().createElement(sourceNode.getNodeName()); } destParent.appendChild(newChild); // .. its attributes NamedNodeMap atts = sourceNode.getAttributes(); for (int i = 0; i < atts.getLength(); i++) { Attr attr = (Attr) atts.item(i); // log.debug("attr.getNodeName(): " + attr.getNodeName()); // log.debug("attr.getNamespaceURI(): " + attr.getNamespaceURI()); // log.debug("attr.getLocalName(): " + attr.getLocalName()); // log.debug("attr.getPrefix(): " + attr.getPrefix()); if (attr.getNodeName().startsWith("xmlns:")) { /* A document created from a dom4j document using dom4j 1.6.1's io.domWriter does this ?! attr.getNodeName(): xmlns:w attr.getNamespaceURI(): null attr.getLocalName(): null attr.getPrefix(): null unless i'm doing something wrong, this is another reason to remove use of dom4j from docx4j */ ; // this is a namespace declaration. not our problem } else if (attr.getNamespaceURI() == null) { //log.debug("attr.getLocalName(): " + attr.getLocalName() + "=" + attr.getValue()); ((org.w3c.dom.Element) newChild).setAttribute(attr.getName(), attr.getValue()); } else if (attr.getNamespaceURI().equals("http://www.w3.org/2000/xmlns/")) { ; // this is a namespace declaration. not our problem } else if (attr.getNodeName() != null) { // && attr.getNodeName().equals("xml:space")) { // restrict this fix to xml:space only, if necessary // Necessary when invoked from BindingTraverserXSLT, // com.sun.org.apache.xerces.internal.dom.AttrNSImpl // otherwise it was becoming w:space="preserve"! /* eg xml:space * attr.getNodeName(): xml:space attr.getNamespaceURI(): http://www.w3.org/XML/1998/namespace attr.getLocalName(): space attr.getPrefix(): xml */ ((org.w3c.dom.Element) newChild).setAttributeNS(attr.getNamespaceURI(), attr.getNodeName(), attr.getValue()); } else { ((org.w3c.dom.Element) newChild).setAttributeNS(attr.getNamespaceURI(), attr.getLocalName(), attr.getValue()); } } // recurse on each child NodeList children = sourceNode.getChildNodes(); if (children != null) { for (int i = 0; i < children.getLength(); i++) { //treeCopy( (DTMNodeProxy)children.item(i), newChild); treeCopy((Node) children.item(i), newChild); } } break; case Node.TEXT_NODE: // Where destParent is com.sun.org.apache.xerces.internal.dom.DocumentImpl, // destParent.getOwnerDocument() returns null. // #document ; com.sun.org.apache.xerces.internal.dom.DocumentImpl // System.out.println(sourceNode.getNodeValue()); //System.out.println(destParent.getNodeName() + " ; " + destParent.getClass().getName() ); if (destParent.getOwnerDocument() == null && destParent.getNodeName().equals("#document")) { Node textNode = ((Document) destParent).createTextNode(sourceNode.getNodeValue()); destParent.appendChild(textNode); } else { Node textNode = destParent.getOwnerDocument().createTextNode(sourceNode.getNodeValue()); // Warning: If you attempt to write a single "&" character, it will be converted to & // even if it doesn't look like that with getNodeValue() or getTextContent()! // So avoid any tricks with entities! See notes in docx2xhtmlNG2.xslt Node appended = destParent.appendChild(textNode); } break; // case Node.CDATA_SECTION_NODE: // writer.write("<![CDATA[" + // node.getNodeValue() + "]]>"); // break; // // case Node.COMMENT_NODE: // writer.write(indentLevel + "<!-- " + // node.getNodeValue() + " -->"); // writer.write(lineSeparator); // break; // // case Node.PROCESSING_INSTRUCTION_NODE: // writer.write("<?" + node.getNodeName() + // " " + node.getNodeValue() + // "?>"); // writer.write(lineSeparator); // break; // // case Node.ENTITY_REFERENCE_NODE: // writer.write("&" + node.getNodeName() + ";"); // break; // // case Node.DOCUMENT_TYPE_NODE: // DocumentType docType = (DocumentType)node; // writer.write("<!DOCTYPE " + docType.getName()); // if (docType.getPublicId() != null) { // System.out.print(" PUBLIC \"" + // docType.getPublicId() + "\" "); // } else { // writer.write(" SYSTEM "); // } // writer.write("\"" + docType.getSystemId() + "\">"); // writer.write(lineSeparator); // break; } }
From source file:org.eclipse.mdht.dita.ui.util.DitaUtil.java
private static String getFileNameFromMap(String ditaMapPath) { StringBuffer fileName = new StringBuffer(); try {//from w ww. j av a2 s.co m FileInputStream ditaMapStream; ditaMapStream = new FileInputStream(ditaMapPath); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); factory.setValidating(false); factory.setFeature("http://xml.org/sax/features/namespaces", false); factory.setFeature("http://xml.org/sax/features/validation", false); factory.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false); factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); DocumentBuilder builder; Document doc = null; XPathExpression expr = null; builder = factory.newDocumentBuilder(); doc = builder.parse(new InputSource(ditaMapStream)); XPathFactory xFactory = XPathFactory.newInstance(); XPath xpath = xFactory.newXPath(); expr = xpath.compile("//bookmap/bookmeta/prodinfo/prodname"); Node prodNameNode = (Node) expr.evaluate(doc, XPathConstants.NODE); if (prodNameNode != null) { fileName.append(prodNameNode.getTextContent()); expr = xpath.compile("//bookmap/bookmeta/prodinfo/vrmlist"); Element vrmlistNode = (Element) expr.evaluate(doc, XPathConstants.NODE); if (vrmlistNode != null) { NodeList versions = vrmlistNode.getElementsByTagName("vrm"); if (versions.getLength() > 0) { NamedNodeMap versionAttributes = versions.item(0).getAttributes(); Attr releaseAttr = (Attr) versionAttributes.getNamedItem("release"); if (releaseAttr != null) { fileName.append(String.format("_%s", releaseAttr.getValue())); } Attr versionAttr = (Attr) versionAttributes.getNamedItem("version"); if (versionAttr != null) { fileName.append(String.format("_%s", versionAttr.getValue())); } } } } else { expr = xpath.compile("/bookmap"); prodNameNode = (Node) expr.evaluate(doc, XPathConstants.NODE); if (prodNameNode != null) { Node node = prodNameNode.getAttributes().getNamedItem("id"); if (node != null) { fileName.append(node.getTextContent()); } } else { expr = xpath.compile("/map"); prodNameNode = (Node) expr.evaluate(doc, XPathConstants.NODE); if (prodNameNode != null) { Node node = prodNameNode.getAttributes().getNamedItem("title"); if (node != null) { fileName.append(node.getTextContent()); } } } } } catch (Exception e) { e.printStackTrace(); System.out.println(); } return fileName.toString(); }
From source file:org.eclipse.wst.xsl.xalan.debugger.XalanVariable.java
private String buildAttributes(NamedNodeMap attributes) { String value = " "; for (int a = 0; a < attributes.getLength(); a++) { Attr attribute = (Attr) attributes.item(a); // if (attribute.getPrefix() != null) { // value = value + attribute.getPrefix() + ":"; // } value = value + attribute.getName() + "=\"" + attribute.getValue() + "\" "; }// w ww. j a va 2s . c om value = value + " "; return value; }
From source file:org.etudes.mneme.impl.ImportQtiServiceImpl.java
/** * Process the item if it is recognized as a Respondous Essay question. * /*from w ww.j av a2 s . com*/ * @param item * The QTI item from the QTI file DOM. * @param pool * The pool to add the question to. * @param pointsAverage * A running average to contribute the question's point value to for the pool. */ protected boolean processRespondousEssay(Element item, Pool pool) throws AssessmentPermissionException { try { // the attributes of a survey question String presentation = null; String feedback = null; String externalId = null; externalId = StringUtil.trimToNull(item.getAttribute("ident")); // presentation text // Respondous is using the format - presentation/material/mattext XPath presentationTextPath = new DOMXPath("presentation/material/mattext"); List presentationMaterialTexts = presentationTextPath.selectNodes(item); StringBuilder presentationTextBuilder = new StringBuilder(); for (Object presentationMaterialText : presentationMaterialTexts) { Element presentationTextElement = (Element) presentationMaterialText; XPath matTextPath = new DOMXPath("."); String matText = StringUtil.trimToNull(matTextPath.stringValueOf(presentationTextElement)); if (matText != null) presentationTextBuilder.append(matText); } presentation = presentationTextBuilder.toString(); if (presentation == null) { // QTI format - presentation/flow/material/mattext presentationTextPath = new DOMXPath("presentation/flow/material/mattext"); presentation = StringUtil.trimToNull(presentationTextPath.stringValueOf(item)); } if (presentation == null) return false; // reponse_str/response_fib XPath renderFibPath = new DOMXPath("presentation/response_str/render_fib"); Element responseFib = (Element) renderFibPath.selectSingleNode(item); if (responseFib == null) return false; Attr promptAttr = responseFib.getAttributeNode("prompt"); Attr rowsAttr = responseFib.getAttributeNode("rows"); Attr columnsAttr = responseFib.getAttributeNode("columns"); if (promptAttr == null || rowsAttr == null || columnsAttr == null) return false; if (!"Box".equalsIgnoreCase(promptAttr.getValue().trim())) return false; // create the question Question question = this.questionService.newQuestion(pool, "mneme:Essay"); EssayQuestionImpl e = (EssayQuestionImpl) (question.getTypeSpecificQuestion()); String clean = HtmlHelper.cleanAndAssureAnchorTarget(presentation, true); question.getPresentation().setText(clean); // type e.setSubmissionType(EssayQuestionImpl.SubmissionType.inline); XPath itemfeedbackPath = new DOMXPath("itemfeedback/material/mattext"); feedback = StringUtil.trimToNull(itemfeedbackPath.stringValueOf(item)); // add feedback if (StringUtil.trimToNull(feedback) != null) { question.setFeedback(HtmlHelper.cleanAndAssureAnchorTarget(feedback, true)); } // save question.getTypeSpecificQuestion().consolidate(""); this.questionService.saveQuestion(question); return true; } catch (JaxenException e) { return false; } }
From source file:org.etudes.mneme.impl.ImportQtiServiceImpl.java
/** * Process this item if it is recognized as a Respondous Fill in the blank. * //from w w w . java 2s . c o m * @param item * The QTI item from the QTI file DOM. * @param pool * The pool to add the question to. * @param pointsAverage * A running average to contribute the question's point value to for the pool. * @return true if successfully recognized and processed, false if not. */ protected boolean processRespondousFillIn(Element item, Pool pool, Average pointsAverage) throws AssessmentPermissionException { // the attributes of a Fill In the Blank question boolean caseSensitive = false; boolean mutuallyExclusive = false; String presentation = null; float points = 0.0f; String feedback = null; boolean isResponseTextual = false; String externalId = null; List<String> answers = new ArrayList<String>(); try { // identifier externalId = StringUtil.trimToNull(item.getAttribute("ident")); // presentation text // Respondous is using the format - presentation/material/mattext XPath presentationTextPath = new DOMXPath("presentation/material/mattext"); List presentationMaterialTexts = presentationTextPath.selectNodes(item); StringBuilder presentationTextBuilder = new StringBuilder(); for (Object presentationMaterialText : presentationMaterialTexts) { Element presentationTextElement = (Element) presentationMaterialText; XPath matTextPath = new DOMXPath("."); String matText = StringUtil.trimToNull(matTextPath.stringValueOf(presentationTextElement)); if (matText != null) presentationTextBuilder.append(matText); } presentation = presentationTextBuilder.toString(); if (presentation == null) { // QTI format - presentation/flow/material/mattext presentationTextPath = new DOMXPath("presentation/flow/material/mattext"); presentation = StringUtil.trimToNull(presentationTextPath.stringValueOf(item)); } if (presentation == null) return false; // reponse_str/response_fib XPath renderFibPath = new DOMXPath("presentation/response_str/render_fib"); Element responseFib = (Element) renderFibPath.selectSingleNode(item); if (responseFib == null) return false; Attr promptAttr = responseFib.getAttributeNode("prompt"); Attr rowsAttr = responseFib.getAttributeNode("rows"); Attr columnsAttr = responseFib.getAttributeNode("columns"); if (promptAttr == null || rowsAttr != null || columnsAttr != null) return false; if (!"Box".equalsIgnoreCase(promptAttr.getValue().trim())) return false; // score declaration - decvar XPath scoreDecVarPath = new DOMXPath("resprocessing/outcomes/decvar"); Element scoreDecVarElement = (Element) scoreDecVarPath.selectSingleNode(item); if (scoreDecVarElement == null) return false; String vartype = StringUtil.trimToNull(scoreDecVarElement.getAttribute("vartype")); if ((vartype != null) && !("Integer".equalsIgnoreCase(vartype) || "Decimal".equalsIgnoreCase(vartype))) return false; String maxValue = StringUtil.trimToNull(scoreDecVarElement.getAttribute("maxvalue")); String minValue = StringUtil.trimToNull(scoreDecVarElement.getAttribute("minvalue")); try { points = Float.valueOf(maxValue); } catch (NumberFormatException e) { points = Float.valueOf("1.0"); } // correct answer XPath respConditionPath = new DOMXPath("resprocessing/respcondition"); List responses = respConditionPath.selectNodes(item); if (responses == null || responses.size() == 0) return false; for (Object oResponse : responses) { Element responseElement = (Element) oResponse; XPath responsePath = new DOMXPath("conditionvar/varequal"); String responseText = StringUtil.trimToNull(responsePath.stringValueOf(responseElement)); if (responseText != null) { // score XPath setVarPath = new DOMXPath("setvar"); Element setVarElement = (Element) setVarPath.selectSingleNode(responseElement); if (setVarElement == null) continue; if ("Add".equalsIgnoreCase(setVarElement.getAttribute("action"))) { String pointsValue = StringUtil.trimToNull(setVarElement.getTextContent()); if (pointsValue == null) pointsValue = "1.0"; answers.add(responseText.trim()); // feedback optional and can be Response, Solution, Hint XPath displayFeedbackPath = new DOMXPath("displayfeedback"); Element displayFeedbackElement = (Element) displayFeedbackPath .selectSingleNode(responseElement); if (displayFeedbackElement == null) continue; String feedbackType = StringUtil .trimToNull(displayFeedbackElement.getAttribute("feedbacktype")); if (feedbackType == null || "Response".equalsIgnoreCase(feedbackType)) { String linkRefId = StringUtil .trimToNull(displayFeedbackElement.getAttribute("linkrefid")); if (linkRefId == null) continue; XPath itemfeedbackPath = new DOMXPath(".//itemfeedback[@ident='" + linkRefId + "']"); Element feedbackElement = (Element) itemfeedbackPath.selectSingleNode(item); if (feedbackElement == null) continue; XPath feedbackTextPath = new DOMXPath("material/mattext"); String feedbackText = StringUtil .trimToNull(feedbackTextPath.stringValueOf(feedbackElement)); feedback = feedbackText; } } } } if (answers.size() == 0) return false; // create the question Question question = this.questionService.newQuestion(pool, "mneme:FillBlanks"); FillBlanksQuestionImpl f = (FillBlanksQuestionImpl) (question.getTypeSpecificQuestion()); // case sensitive f.setCaseSensitive(Boolean.FALSE.toString()); // mutually exclusive f.setAnyOrder(Boolean.FALSE.toString()); StringBuffer buildAnswers = new StringBuffer(); buildAnswers.append("{"); for (String answer : answers) { if (!isResponseTextual) { try { Float.parseFloat(answer); } catch (NumberFormatException e) { isResponseTextual = true; } } buildAnswers.append(answer); buildAnswers.append("|"); } buildAnswers.replace(buildAnswers.length() - 1, buildAnswers.length(), "}"); String questionText = presentation.concat(buildAnswers.toString()); String clean = HtmlHelper.cleanAndAssureAnchorTarget(questionText, true); f.setText(clean); // text or numeric f.setResponseTextual(Boolean.toString(isResponseTextual)); // add feedback if (StringUtil.trimToNull(feedback) != null) { question.setFeedback(HtmlHelper.cleanAndAssureAnchorTarget(feedback, true)); } // save question.getTypeSpecificQuestion().consolidate(""); this.questionService.saveQuestion(question); // add to the points average pointsAverage.add(points); return true; } catch (JaxenException e) { return false; } }