List of usage examples for org.jdom2 Element setText
public Element setText(final String text)
From source file:app.simulation.Exporter.java
License:MIT License
public void exportXML() throws Exception { Element root = new Element("simulation"); Document document = new Document(root); if (configuration != null) { Element tagConfiguration = new Element("configuration"); Element delay = new Element("delay"); delay.setText(String.format("%s", configuration.getDelay())); Element iterations = new Element("iterations"); iterations.setText(String.format("%s", configuration.getIterations())); Element agents = new Element("agents"); agents.setText(String.format("%s", configuration.getAgents())); Element latticeSize = new Element("latticeSize"); latticeSize.setText(String.format("%s", configuration.getLatticeSize())); Element description = new Element("description"); description.setText(String.format("%s", configuration.getDescription())); tagConfiguration.addContent(delay); tagConfiguration.addContent(iterations); tagConfiguration.addContent(agents); tagConfiguration.addContent(latticeSize); tagConfiguration.addContent(description); root.addContent(tagConfiguration); }//from w ww . ja v a 2 s . c o m if (initialCell != null) { Element tagInitialCell = new Element("initialCell"); Element x = new Element("x"); x.setText(String.format("%s", initialCell.getX())); Element y = new Element("y"); y.setText(String.format("%s", initialCell.getY())); Element z = new Element("z"); z.setText(String.format("%s", initialCell.getZ())); Element state = new Element("state"); state.setText(String.format("%s", initialCell.getState())); Element color = new Element("color"); Element r = new Element("r"); r.setText(String.format("%s", initialCell.getColor().getRed())); Element g = new Element("g"); g.setText(String.format("%s", initialCell.getColor().getGreen())); Element b = new Element("b"); b.setText(String.format("%s", initialCell.getColor().getBlue())); color.addContent(r); color.addContent(g); color.addContent(b); tagInitialCell.addContent(x); tagInitialCell.addContent(y); tagInitialCell.addContent(z); tagInitialCell.addContent(state); tagInitialCell.addContent(color); root.addContent(tagInitialCell); } if (rules != null) { Element tagRules = new Element("rules"); for (Rule rule : rules) { Element tagRule = new Element("rule"); Element neighbourhood = new Element("neighbourhood"); neighbourhood.setText(rule.getNeighbourhood()); Element state = new Element("state"); state.setText(String.format("%s", rule.getState())); Element color = new Element("color"); Element r = new Element("r"); r.setText(String.format("%s", rule.getColor().getRed())); Element g = new Element("g"); g.setText(String.format("%s", rule.getColor().getGreen())); Element b = new Element("b"); b.setText(String.format("%s", rule.getColor().getBlue())); color.addContent(r); color.addContent(g); color.addContent(b); tagRule.addContent(neighbourhood); tagRule.addContent(state); tagRule.addContent(color); tagRules.addContent(tagRule); } root.addContent(tagRules); } XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); outputter.output(document, new FileWriter(path)); }
From source file:arquivo.ArquivoF.java
public String add(String confSenha, String loing, String senha, String nome) { if (confSenha.equals(senha) && !loing.equals("") && !nome.equals("") && !senha.equals("")) { if (0 != busca(nome, true, "funcinario").size() && buscaLong(loing).size() != 0) return "erro nome ja cadastrado"; SAXBuilder builder = new SAXBuilder(); try {//from w w w. j a va2 s .c o m Document doc = builder.build(arquivo); Element root = (Element) doc.getRootElement(); Element funcionario = new Element("funcinario"); Attribute nomeE = new Attribute("nome", nome); funcionario.setAttribute(nomeE); Element loingE = new Element("loing"); loingE.setText(loing); funcionario.addContent(loingE); Element senhaE = new Element("senha"); senhaE.setText(senha); funcionario.addContent(senhaE); root.addContent(funcionario); XMLOutputter xout = new XMLOutputter(); OutputStream out = new FileOutputStream(arquivo); xout.output(doc, out); System.out.println("Documento alterado com sucesso!"); return "cadastrado com suceso"; } catch (Exception e) { } } else return "preemcha os compos corretamente"; return "erro cadastral"; }
From source file:at.ac.tuwien.ims.latex2mobiformulaconv.converter.mathml2html.elements.layout.Mfenced.java
License:Open Source License
@Override public Element render(FormulaElement parent, List<FormulaElement> siblings) { Element fencedSpan = new Element("span"); fencedSpan.setAttribute("class", "mfenced"); // Opening fence Element openFenceSpan = new Element("span"); openFenceSpan.setAttribute("class", "mfenced-open"); openFenceSpan.setText(opened); fencedSpan.addContent(openFenceSpan); // Content/*from www. j a va 2 s . co m*/ if (content.isEmpty() == false) { // if this is a fenced table or matrix, just render the content element // pass information about the fence via parent reference if (content.size() == 1 && content.get(0) instanceof Mtable) { Mtable fencedTableOrMatrix = (Mtable) content.get(0); return fencedTableOrMatrix.render(this, null); } String tempSeparators = separators.replaceAll(" ", ""); for (int i = 0; i < content.size(); i++) { FormulaElement element = content.get(i); Element contentSpan = new Element("span"); contentSpan.setAttribute("class", "mfenced-content"); contentSpan.addContent(element.render(null, null)); fencedSpan.addContent(contentSpan); // Separators if (content.size() > 1) { Mo separatorElement = new Mo(); separatorElement.setSeparator(true); String separator = SEPARATOR; if (tempSeparators.length() == 1) { separator = tempSeparators; } else if (i < tempSeparators.length()) { separator = Character.toString(tempSeparators.charAt(i)); // Entity lookup if (separator.length() > 1) { String entityName = separator.substring(1, separator.length() - 1); if (MathmlCharacterDictionary.entityMapByName.containsKey(entityName)) { separator = MathmlCharacterDictionary.entityMapByName.get(entityName); } } } separatorElement.setValue(separator); Element mo = separatorElement.render(this, null); mo.setAttribute("class", mo.getAttributeValue("class") + " mfenced-separator"); fencedSpan.addContent(mo); } } } // Closing fence Element closeFenceSpan = new Element("span"); closeFenceSpan.setAttribute("class", "mfenced-close"); closeFenceSpan.setText(closed); fencedSpan.addContent(closeFenceSpan); return fencedSpan; }
From source file:at.ac.tuwien.ims.latex2mobiformulaconv.converter.mathml2html.elements.layout.Mrow.java
License:Open Source License
@Override public Element render(FormulaElement parent, List<FormulaElement> siblings) { if (list.isEmpty()) { Element nothing = new Element("span"); nothing.setAttribute("class", "nothing"); nothing.setText(" "); return nothing; }/*from w w w .j a va2 s.co m*/ if (list.size() == 1) { // MathML2 3.3.1.2.1 mrow of one argument // http://www.w3.org/TR/MathML2/chapter3.html#presm.mrow // MathML renderers are required to treat an mrow element containing exactly one argument as equivalent // in all ways to the single argument occurring alone, // provided there are no attributes on the mrow element's start tag. return list.get(0).render(parent, siblings); } Element span = new Element("span"); span.setAttribute("class", "mrow"); Iterator<FormulaElement> iterator = list.iterator(); while (iterator.hasNext()) { FormulaElement cur = iterator.next(); Element html = cur.render(this, list); if (html != null) { span.addContent(html); } else { logger.debug("HTML is NULL: " + cur.getClass().toString()); } } return span; }
From source file:at.ac.tuwien.ims.latex2mobiformulaconv.converter.mathml2html.elements.token.Mspace.java
License:Open Source License
@Override public Element render(FormulaElement parent, List<FormulaElement> siblings) { Element span = new Element("span"); span.setAttribute("class", "mspace"); String style = "width: " + width.toString() + "; height: " + height.toString() + ";"; span.setAttribute("style", style); span.setText(" "); return span;//from www.j a v a 2 s.c om }
From source file:at.ac.tuwien.ims.latex2mobiformulaconv.converter.mathml2html.elements.token.Mtext.java
License:Open Source License
@Override public Element render(FormulaElement parent, List<FormulaElement> siblings) { Element span = new Element("span"); span.setAttribute("class", "mtext"); span.setText(value.trim()); return span;/*from w w w . j ava 2s. c o m*/ }
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 w ww .jav a2 s .c om*/ 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:at.ac.tuwien.ims.latex2mobiformulaconv.converter.mathml2html.FormulaConverter.java
License:Open Source License
public Element renderInvalidFormulaSource(Formula formula) { // Render invalid LaTeX code Element invalidFormulaPre = new Element("pre"); invalidFormulaPre.setText("Formula #" + formula.getId() + " is invalid!\n\n" + formula.getLatexCode()); return invalidFormulaPre; }
From source file:at.newmedialab.lmf.search.services.cores.SolrCoreServiceImpl.java
License:Apache License
/** * Create/update the solrconfig.xml file for the given core according to the core configuration. * * @param engine the solr core configuration *//*from w ww. j a v a2 s .c o m*/ private void createSolrConfigXml(SolrCoreConfiguration engine) throws MarmottaException { File configTemplate = new File(getCoreDirectory(engine.getName()), "conf" + File.separator + "solrconfig-template.xml"); File configFile = new File(getCoreDirectory(engine.getName()), "conf" + File.separator + "solrconfig.xml"); try { SAXBuilder parser = new SAXBuilder(XMLReaders.NONVALIDATING); Document solrConfig = parser.build(configTemplate); FileOutputStream out = new FileOutputStream(configFile); // Configure suggestion service: add fields to suggestion handler Program<Value> program = engine.getProgram(); for (Element handler : solrConfig.getRootElement().getChildren("requestHandler")) { if (handler.getAttribute("class").getValue().equals(SuggestionRequestHandler.class.getName())) { for (Element lst : handler.getChildren("lst")) { if (lst.getAttribute("name").getValue().equals("defaults")) { //set suggestion fields for (FieldMapping<?, Value> fieldMapping : program.getFields()) { String fieldName = fieldMapping.getFieldName(); final Map<String, String> fieldConfig = fieldMapping.getFieldConfig(); if (fieldConfig != null && fieldConfig.keySet().contains(SOLR_SUGGESTION_FIELD_OPTION)) { String suggestionType = fieldConfig.get(SOLR_SUGGESTION_FIELD_OPTION); if (suggestionType.equals("facet")) { Element field_elem = new Element("str"); field_elem.setAttribute("name", SuggestionRequestParams.SUGGESTION_FIELD); field_elem.setText(fieldName); lst.addContent(field_elem); } else { log.error("suggestionType " + suggestionType + " not supported"); } } } } } } } XMLOutputter xo = new XMLOutputter(Format.getPrettyFormat().setIndent(" ")); xo.output(solrConfig, out); out.close(); } catch (JDOMException e) { throw new MarmottaException("parse error while parsing SOLR schema template file " + configTemplate, e); } catch (IOException e) { throw new MarmottaException("I/O error while parsing SOLR schema template file " + configTemplate, e); } }
From source file:ataraxis.passwordmanager.XMLHandler.java
License:Open Source License
/** * Create a new account-Element//from w w w . java 2 s . c om * * @param entry the AccountEntry * @throws JDOMException by Errors with JDOM * @throws EntryDoesNotExistException */ private void createAccountElement(AccountEntry entry) throws JDOMException, EntryDoesNotExistException { // create Element sub-structure Element newAccountElement = new Element("account"); newAccountElement.setAttribute("id", entry.getId()); Element newName = new Element("name"); newName.setText(entry.getName()); Element newPass = new Element("password"); newPass.setText(entry.getPassword()); Element newLink = new Element("link"); newLink.setText(entry.getLink()); Element newComment = new Element("comment"); newComment.setText(entry.getComment()); // put newPWElement together newAccountElement.addContent(newName); newAccountElement.addContent(newPass); newAccountElement.addContent(newLink); newAccountElement.addContent(newComment); // add parent if (entry.getParentEntry() == null) { s_rootElement.addContent(newAccountElement); } else { try { Element parrent = getElement(entry.getParentEntry().getId()); parrent.addContent(newAccountElement); } catch (JDOMException e) { logger.fatal(e); throw new EntryDoesNotExistException("No such parent"); } } }