List of usage examples for org.jdom2 Element addContent
@Override public Element addContent(final Collection<? extends Content> newContent)
From source file:at.ac.tuwien.ims.latex2mobiformulaconv.converter.mathml2html.elements.scriptlimit.Msup.java
License:Open Source License
@Override public Element render(FormulaElement parent, List<FormulaElement> siblings) { Element msuperSpan = new Element("span"); msuperSpan.setAttribute("class", "msup"); // Add base content if (base != null) { Element baseElement = base.render(null, null); msuperSpan.addContent(baseElement); }/*from ww w . ja va 2s.c om*/ // Add superscript content Element sub = new Element("sup"); sub.addContent(superscript.render(null, null)); msuperSpan.addContent(sub); return msuperSpan; }
From source file:at.ac.tuwien.ims.latex2mobiformulaconv.converter.mathml2html.elements.scriptlimit.Munder.java
License:Open Source License
@Override public Element render(FormulaElement parent, List<FormulaElement> siblings) { Element mainDiv = new Element("div"); mainDiv.setAttribute("class", "munder"); // Siblings//from w w w . j av a 2s. co m List<FormulaElement> content = new ArrayList<>(); content.add(base); content.add(underscript); Element baseDiv = new Element("div"); baseDiv.addContent(base.render(this, content)); baseDiv.setAttribute("class", "base"); mainDiv.addContent(baseDiv); Element underscriptDiv = new Element("div"); underscriptDiv.setAttribute("class", "underscript"); underscriptDiv.addContent(underscript.render(this, content)); mainDiv.addContent(underscriptDiv); return mainDiv; }
From source file:at.ac.tuwien.ims.latex2mobiformulaconv.converter.mathml2html.elements.tablesmatrices.Mtable.java
License:Open Source License
@Override public Element render(FormulaElement parent, List<FormulaElement> siblings) { Element mtableDiv = new Element("div"); mtableDiv.setAttribute("class", "mtable"); // create Table Element table = new Element("table"); // Matrix / Table parenthesis if (parent != null && parent instanceof Mfenced) { Mfenced mfenced = (Mfenced) parent; if (mfenced.getOpened().equals("(") && mfenced.getClosed().equals(")")) { table.setAttribute("class", "pmatrix"); }// ww w . j a va2 s .c o m if (mfenced.getOpened().equals("[") && mfenced.getClosed().equals("]")) { table.setAttribute("class", "bmatrix"); } if (mfenced.getOpened().equals("{") && mfenced.getClosed().equals("}")) { table.setAttribute("class", "pmatrix"); // intentionally pmatrix for curved border corners mtableDiv.setAttribute("class", mtableDiv.getAttributeValue("class") + " mtable-Bmatrix"); } if (mfenced.getOpened().equals("|") && mfenced.getClosed().equals("|")) { table.setAttribute("class", "vmatrix"); } if (mfenced.getOpened().equals("") && mfenced.getClosed().equals("")) { table.setAttribute("class", "Vmatrix"); } } // evaluate Rows for (int i = 0; i < rows.size(); i++) { table.addContent(rows.get(i).render(null, null)); } mtableDiv.addContent(table); return mtableDiv; }
From source file:at.ac.tuwien.ims.latex2mobiformulaconv.converter.mathml2html.elements.tablesmatrices.Mtd.java
License:Open Source License
@Override public Element render(FormulaElement parent, List<FormulaElement> siblings) { Element td = new Element("td"); td.addContent(content.render(null, null)); return td;/*w w w. j av a 2 s.c om*/ }
From source file:at.ac.tuwien.ims.latex2mobiformulaconv.converter.mathml2html.elements.tablesmatrices.Mtr.java
License:Open Source License
@Override public Element render(FormulaElement parent, List<FormulaElement> siblings) { Element tr = new Element("tr"); for (int i = 0; i < tds.size(); i++) { tr.addContent(tds.get(i).render(null, null)); }/*from w w w .j a v a 2 s .c o m*/ return tr; }
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 . ja va 2s.com 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.newmedialab.lmf.search.services.cores.SolrCoreServiceImpl.java
License:Apache License
/** * Create/update the schema.xml file for the given core according to the core definition. * * @param engine the engine configuration *//*from ww w. j a va 2 s. c om*/ private void createSchemaXml(SolrCoreConfiguration engine) throws MarmottaException { log.info("generating schema.xml for search program {}", engine.getName()); SAXBuilder parser = new SAXBuilder(XMLReaders.NONVALIDATING); File schemaTemplate = new File(getCoreDirectory(engine.getName()), "conf" + File.separator + "schema-template.xml"); File schemaFile = new File(getCoreDirectory(engine.getName()), "conf" + File.separator + "schema.xml"); try { Document doc = parser.build(schemaTemplate); Element schemaNode = doc.getRootElement(); Element fieldsNode = schemaNode.getChild("fields"); if (!schemaNode.getName().equals("schema") || fieldsNode == null) throw new MarmottaException(schemaTemplate + " is an invalid SOLR schema file"); schemaNode.setAttribute("name", engine.getName()); Program<Value> program = engine.getProgram(); for (FieldMapping<?, Value> fieldMapping : program.getFields()) { String fieldName = fieldMapping.getFieldName(); String solrType = null; try { solrType = solrProgramService.getSolrFieldType(fieldMapping.getFieldType().toString()); } catch (MarmottaException e) { solrType = null; } if (solrType == null) { log.error("field {} has an invalid field type; ignoring field definition", fieldName); continue; } Element fieldElement = new Element("field"); fieldElement.setAttribute("name", fieldName); fieldElement.setAttribute("type", solrType); // Set the default properties fieldElement.setAttribute("stored", "true"); fieldElement.setAttribute("indexed", "true"); fieldElement.setAttribute("multiValued", "true"); // FIXME: Hardcoded Stuff! if (solrType.equals("location")) { fieldElement.setAttribute("indexed", "true"); fieldElement.setAttribute("multiValued", "false"); } // Handle extra field configuration final Map<String, String> fieldConfig = fieldMapping.getFieldConfig(); if (fieldConfig != null) { for (Map.Entry<String, String> attr : fieldConfig.entrySet()) { if (SOLR_FIELD_OPTIONS.contains(attr.getKey())) { fieldElement.setAttribute(attr.getKey(), attr.getValue()); } } } fieldsNode.addContent(fieldElement); if (fieldConfig != null && fieldConfig.keySet().contains(SOLR_COPY_FIELD_OPTION)) { String[] copyFields = fieldConfig.get(SOLR_COPY_FIELD_OPTION).split("\\s*,\\s*"); for (String copyField : copyFields) { if (copyField.trim().length() > 0) { // ignore 'empty' fields Element copyElement = new Element("copyField"); copyElement.setAttribute("source", fieldName); copyElement.setAttribute("dest", copyField.trim()); schemaNode.addContent(copyElement); } } } else { Element copyElement = new Element("copyField"); copyElement.setAttribute("source", fieldName); copyElement.setAttribute("dest", "lmf.text_all"); schemaNode.addContent(copyElement); } //for suggestions, copy all fields to lmf.spellcheck (used for spellcheck and querying); //only facet is a supported type at the moment if (fieldConfig != null && fieldConfig.keySet().contains(SOLR_SUGGESTION_FIELD_OPTION)) { String suggestionType = fieldConfig.get(SOLR_SUGGESTION_FIELD_OPTION); if (suggestionType.equals("facet")) { Element copyElement = new Element("copyField"); copyElement.setAttribute("source", fieldName); copyElement.setAttribute("dest", "lmf.spellcheck"); schemaNode.addContent(copyElement); } else { log.error("suggestionType " + suggestionType + " not supported"); } } } if (!schemaFile.exists() || schemaFile.canWrite()) { FileOutputStream out = new FileOutputStream(schemaFile); XMLOutputter xo = new XMLOutputter(Format.getPrettyFormat().setIndent(" ")); xo.output(doc, out); out.close(); } else { log.error("schema file {} is not writable", schemaFile); } } catch (JDOMException e) { throw new MarmottaException("parse error while parsing SOLR schema template file " + schemaTemplate, e); } catch (IOException e) { throw new MarmottaException("I/O error while parsing SOLR schema template file " + schemaTemplate, e); } }
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 ww w.j a va 2 s. co 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 .j a va 2 s. com*/ * * @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"); } } }
From source file:br.com.nfe.util.Chave.java
public void criarChave(String uf, String tpEmis, String nNfe, String cNf, String serie, String AnoMes, String cnpj) {// w w w . j av a 2 s .com this.cNf = cNf; Element gerarChave = new Element("gerarChave"); Document documento = new Document(gerarChave); Element UF = new Element("UF"); UF.setText(uf); Element NNFE = new Element("nNF"); NNFE.setText(nNfe); Element CNF = new Element("cNF"); CNF.setText(cNf); Element TPEMIS = new Element("tpEmis"); TPEMIS.setText(tpEmis); Element SERIE = new Element("serie"); SERIE.setText(serie); Element ANOMES = new Element("AAMM"); ANOMES.setText(AnoMes); Element CNPJ = new Element("CNPJ"); CNPJ.setText(cnpj); gerarChave.addContent(UF); gerarChave.addContent(TPEMIS); gerarChave.addContent(NNFE); //gerarChave.addContent(CNF); gerarChave.addContent(SERIE); gerarChave.addContent(ANOMES); gerarChave.addContent(CNPJ); XMLOutputter xout = new XMLOutputter(); try { FileWriter arquivo = new FileWriter( new File("c:/unimake/uninfe/" + pasta + "/envio/" + cNf + "-gerar-chave.xml")); xout.output(documento, arquivo); } catch (IOException e) { e.printStackTrace(); } }