List of usage examples for org.jdom2 Text getText
public String getText()
Text
node as a Java String
. From source file:at.ac.tuwien.ims.latex2mobiformulaconv.converter.mathml2html.FormulaConverter.java
License:Open Source License
/** * Replaces all formulas with the html representation of the mapped formula objects * * @param doc JDOM Document where to replace the formulas * @param formulaMap Map of the indexed Formula Objects * @return JDOM Document with replaced formulas *//*from ww w . j a v a 2s. c o m*/ public Document replaceFormulas(Document doc, Map<Integer, Formula> formulaMap) { List<Element> foundFormulas = xpath.evaluate(doc); if (foundFormulas.size() > 0) { Map<String, Element> formulaMarkupMap = new HashMap<>(); // Initialize markup map for (Element element : foundFormulas) { formulaMarkupMap.put(element.getAttribute("id").getValue(), element); } // Replace all found formulas Iterator<Integer> formulaIterator = formulaMap.keySet().iterator(); while (formulaIterator.hasNext()) { Integer id = formulaIterator.next(); Element formulaMarkupRoot = formulaMarkupMap.get(FORMULA_ID_PREFIX + id); Formula formula = formulaMap.get(id); formulaMarkupRoot.removeAttribute("class"); formulaMarkupRoot.removeContent(); formulaMarkupRoot.setName("div"); Element div = (Element) formulaMarkupRoot.getParent(); div.setName("div"); div.setAttribute("class", "formula"); // Potentially there's text inside the paragraph... List<Text> texts = div.getContent(Filters.textOnly()); if (texts.isEmpty() == false) { String textString = ""; for (Text text : texts) { textString += text.getText(); } Element textSpan = new Element("span"); textSpan.setAttribute("class", "text"); textSpan.setText(textString); div.addContent(textSpan); List<Content> content = div.getContent(); content.removeAll(texts); } if (generateDebugMarkup) { div.setAttribute("style", "border: 1px solid black;"); // Header Element h4 = new Element("h4"); h4.setText("DEBUG - Formula #" + formula.getId()); div.addContent(h4); // Render LaTeX source Element latexPre = new Element("pre"); latexPre.setAttribute("class", "debug-latex"); latexPre.setText(formula.getLatexCode()); div.addContent(latexPre); // Render MathML markup Element mathmlPre = new Element("pre"); mathmlPre.setAttribute("class", "debug-mathml"); mathmlPre.setText(formula.getMathMl()); div.addContent(mathmlPre); // Render HTML Markup Element htmlPre = new Element("pre"); htmlPre.setAttribute("class", "debug-html"); XMLOutputter xmlOutputter = new XMLOutputter(); xmlOutputter.setFormat(Format.getRawFormat()); htmlPre.setText(xmlOutputter.outputString(formula.getHtml())); div.addContent(htmlPre); } // Set formula into formulaMarkupRoot.addContent(formula.getHtml()); } } return doc; }
From source file:com.c4om.autoconf.ulysses.extra.svrlmultipathinterpreter.SVRLMultipathInterpreterMain.java
License:Apache License
/** * This method gets a list of all the paths occurring in <code>//svrl:failed-assert/svrl:text</code>, as expected by SVRLMultipathInterpreterMain. * @param svrlDocument The SVRL document, as a JDOM2 {@link Document} * @return a {@link List} of {@link String}, with the paths. *///from ww w. ja v a 2 s .c o m private List<String> getPathsFromDocument(Document svrlDocument) { List<String> results = new ArrayList<>(); List<Namespace> namespaces = Arrays.asList(CommonXMLConstants.NAMESPACE_SVRL); List<Text> resultingTexts = performJAXENXPath("//svrl:failed-assert/svrl:text/text()", svrlDocument, Filters.text(), namespaces); for (Text resultingText : resultingTexts) { for (String untrimmedResult : resultingText.getText().split("[\r\n]+")) { String trimmedResult = untrimmedResult.trim(); if (!trimmedResult.equals("")) { results.add(trimmedResult); } } } return results; }
From source file:ditatools.translate.DitaTranslator.java
License:Apache License
private void handleText(Text text) { if (text.getTextTrim().length() > 0) { try {/*from w w w . j a va2s .c o m*/ Translation fromEnglish = translator.translate(text.getText(), DOC_LANGUAGE, language); // String translatedValue = fromEnglish.getTranslatedText(); // System.out.println(translatedValue); // printCharacters(translatedValue); // text.setText(translatedValue); // XXX better handling of API errors; in particular, wait // and retry when hitting a short term API rate limit. text.setText(fromEnglish.getTranslatedText()); } catch (IOException e) { e.printStackTrace(); } catch (URISyntaxException e) { e.printStackTrace(); } catch (TranslatorException e) { e.printStackTrace(); } } }
From source file:io.macgyver.plugin.ci.jenkins.decorators.GitHubDecorator.java
License:Apache License
Optional<String> getText(List<Text> list) { if (list == null || list.isEmpty()) { return Optional.absent(); }// w w w . j av a 2s. c o m Text text = list.get(0); if (text == null) { return Optional.absent(); } return Optional.fromNullable(text.getText()); }
From source file:org.apache.maven.io.util.WriterUtils.java
License:Apache License
/** * Method insertAtPreferredLocation.//from w ww. j a v a2s . c o m * * @param parent * @param counter * @param child */ public static void insertAtPreferredLocation(final Element parent, final Element child, final IndentationCounter counter) { int contentIndex = 0; int elementCounter = 0; final Iterator it = parent.getContent().iterator(); Text lastText = null; int offset = 0; while (it.hasNext() && elementCounter <= counter.getCurrentIndex()) { final Object next = it.next(); offset = offset + 1; if (next instanceof Element) { elementCounter = elementCounter + 1; contentIndex = contentIndex + offset; offset = 0; } if (next instanceof Text && it.hasNext()) { lastText = (Text) next; } } if (lastText != null && lastText.getTextTrim().length() == 0) { lastText = lastText.clone(); } else { String starter = lineSeparator; for (int i = 0; i < counter.getDepth(); i++) { starter = starter + INDENT; // TODO make settable? } lastText = factory.text(starter); } if (parent.getContentSize() == 0) { final Text finalText = lastText.clone(); finalText.setText(finalText.getText().substring(0, finalText.getText().length() - INDENT.length())); parent.addContent(contentIndex, finalText); } parent.addContent(contentIndex, child); parent.addContent(contentIndex, lastText); }
From source file:org.apache.maven.toolchain.model.io.jdom.MavenToolchainsJDOMWriter.java
License:Apache License
/** * Method insertAtPreferredLocation./*from ww w . ja va2s . c om*/ * * @param parent * @param counter * @param child */ protected void insertAtPreferredLocation(final Element parent, final Element child, final IndentationCounter counter) { int contentIndex = 0; int elementCounter = 0; final Iterator it = parent.getContent().iterator(); Text lastText = null; int offset = 0; while (it.hasNext() && elementCounter <= counter.getCurrentIndex()) { final Object next = it.next(); offset = offset + 1; if (next instanceof Element) { elementCounter = elementCounter + 1; contentIndex = contentIndex + offset; offset = 0; } if (next instanceof Text && it.hasNext()) { lastText = (Text) next; } } if (lastText != null && lastText.getTextTrim().length() == 0) { lastText = lastText.clone(); } else { String starter = lineSeparator; for (int i = 0; i < counter.getDepth(); i++) { starter = starter + INDENT; // TODO make settable? } lastText = factory.text(starter); } if (parent.getContentSize() == 0) { final Text finalText = lastText.clone(); finalText.setText(finalText.getText().substring(0, finalText.getText().length() - INDENT.length())); parent.addContent(contentIndex, finalText); } parent.addContent(contentIndex, child); parent.addContent(contentIndex, lastText); }
From source file:org.kdp.word.transformer.ListParagraphTransformer.java
License:Apache License
private void normalizeListItemText(Element el) { for (Content co : el.getContent()) { if (co.getCType() == CType.Text) { Text tco = (Text) co; String text = tco.getText().trim(); tco.setText(text + " "); }/* w w w. ja v a2 s. c om*/ } }
From source file:org.kdp.word.transformer.ListParagraphTransformer.java
License:Apache License
private boolean processItemMarker(Element liItem) { String first = ""; int cosize = liItem.getContentSize(); Content co = liItem.getContent(0);//w w w .j a v a2 s. c o m if (co.getCType() == CType.Text) { Text text = (Text) co; String value = text.getText(); int index = value.indexOf(" "); first = value.substring(0, index); value = value.substring(index + 1); text.setText(value); } else if (cosize > 1 && co.getCType() == CType.Element) { Element el = (Element) co; first = el.getText(); el.getParent().removeContent(co); } return first.endsWith("."); }
From source file:org.mycore.frontend.editor.postprocessor.MCREditorPostProcessorXSL.java
License:Open Source License
public MCRJDOMContent transform(MCRContent source) throws IOException { try {//from w w w . ja v a 2s .com Element root = source.asXML().getRootElement().clone(); for (Iterator<Text> iter = root.getDescendants(Filters.text()).iterator(); iter.hasNext();) { Text text = iter.next(); text.setText(MCRXMLFunctions.normalizeUnicode(text.getText())); } return new MCRJDOMContent(root); } catch (JDOMException ex) { throw new IOException(ex); } catch (SAXException ex) { throw new IOException(ex); } }
From source file:org.rascalmpl.library.lang.xml.DOM.java
License:Open Source License
private IString getString(boolean trim, Text text) throws Skip { if (trim) {//from w ww . j av a2 s . c o m java.lang.String s = text.getTextTrim(); if ("".equals(s)) { throw new Skip(); } return vf.string(s); } return vf.string(text.getText()); }