List of usage examples for org.jdom2 Element addContent
@Override public Element addContent(final Collection<? extends Content> newContent)
From source file:arquivo.ArquivoFilme.java
public String addSesao(String nome, int numeroSala, int horaI, int mimI, int horaF, int mimF) { String retorno = "erro"; if (!nome.equals("")) { if (this.confirnaSesao(numeroSala, horaI, mimI, horaF, mimF)) { SAXBuilder builder = new SAXBuilder(); try { Document doc = builder.build(arquivo); Element root = (Element) doc.getRootElement(); List<Element> filme = super.buscaInterna(root, true, nome, "filme"); if (filme.size() == 0) { return "erro filme n registrado"; }//from ww w . j a va 2s . c om List<Element> salas = filme.get(0).getChildren("sala"); Element secao = new Element("secao"); secao.setAttribute(new Attribute("horaI", "" + horaI)); secao.setAttribute(new Attribute("mimI", "" + mimI)); secao.setAttribute(new Attribute("horaF", "" + horaF)); secao.setAttribute(new Attribute("mimF", "" + mimF)); boolean confirna = false; for (int i = 0; i < salas.size(); i++) { if (salas.get(i).getAttributeValue("numeroSala").equals("" + numeroSala)) { confirna = true; salas.get(i).addContent(secao); break; } } if (!confirna) { Element sala = new Element("sala"); sala.addContent(secao); filme.get(0).addContent(sala); } XMLOutputter xout = new XMLOutputter(); OutputStream out = new FileOutputStream(arquivo); xout.output(doc, out); System.out.println("Documento alterado com sucesso!"); retorno = "cadastrado com suceso"; } catch (Exception e) { } } else retorno = "nesse horario a sala estara ocupada"; } return retorno; }
From source file:at.ac.tuwien.ims.latex2mobiformulaconv.converter.mathml2html.DOMFormulaConverter.java
License:Open Source License
@Override public Formula parse(int id, String latexFormula) { Formula formula = super.parseToMathML(id, latexFormula); // Generate output Element div = new Element("div"); Element html = new Element("div"); html.setAttribute("class", "math"); if (formula.isInvalid() == false) { SAXBuilder builder = new SAXBuilder(); try {/*from w w w .j ava 2 s.c o m*/ Document mathml = builder.build(new StringReader(formula.getMathMl())); Element root = mathml.getRootElement(); if (root.getChildren().isEmpty()) { return null; } Iterator<Element> it = root.getChildren().iterator(); while (it.hasNext()) { Element cur = it.next(); FormulaElement formulaElement = renderElement(cur); if (formulaElement != null) { Element resultHtml = formulaElement.render(null, null); if (resultHtml != null) { html.addContent(resultHtml); } else { logger.debug("HTML is NULL: " + cur.getName()); } } } } catch (JDOMException e) { logger.error("Error parsing generated MathML:"); logger.error(formula.getMathMl()); logger.error(e.getMessage(), e); } catch (IOException e) { logger.error("Error reading generated MathML:"); logger.error(formula.getMathMl()); logger.error(e.getMessage(), e); } } else { html.addContent(renderInvalidFormulaSource(formula)); } div.addContent(html); formula.setHtml(div); return formula; }
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);/*from www .j a v a 2s .co m*/ fencedSpan.addContent(openFenceSpan); // Content 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.Mfrac.java
License:Open Source License
@Override public Element render(FormulaElement parent, List<FormulaElement> siblings) { Element fraction = new Element("span"); fraction.setAttribute("class", "mfrac"); Element numeratorSpan = new Element("span"); numeratorSpan.setAttribute("class", "numerator"); List<FormulaElement> siblingsList = new ArrayList<>(); siblingsList.add(numerator);/*w w w . ja v a 2s .c o m*/ siblingsList.add(denominator); numeratorSpan.addContent(numerator.render(this, siblingsList)); Element denominatorSpan = new Element("span"); denominatorSpan.setAttribute("class", "denominator"); // style for linethickness // medium (same as 1), thin (thinner than 1, otherwise up to the renderer), or thick (thicker than 1, otherwise up to the renderer). switch (linethickness) { case "medium": linethickness = "1"; break; case "thin": linethickness = "0.75"; break; case "thick": linethickness = "2"; break; default: try { Double.valueOf(linethickness); } catch (NumberFormatException e) { linethickness = "1"; } } denominatorSpan.setAttribute("style", "border-top: " + linethickness + "px solid black;"); denominatorSpan.addContent(this.denominator.render(this, siblingsList)); fraction.addContent(numeratorSpan); fraction.addContent(denominatorSpan); return fraction; }
From source file:at.ac.tuwien.ims.latex2mobiformulaconv.converter.mathml2html.elements.layout.Mroot.java
License:Open Source License
@Override public Element render(FormulaElement parent, List<FormulaElement> siblings) { Element mrootSpan = new Element("span"); mrootSpan.setAttribute("class", "mroot"); if (degree != null) { Element indexSpan = new Element("span"); indexSpan.setAttribute("class", "mroot-degree"); indexSpan.addContent(degree.render(null, null)); mrootSpan.addContent(indexSpan); }// w w w. j a v a2s . c om // Root symbol Element mrootSymbol = new Element("span"); mrootSymbol.setAttribute("class", "mroot-symbol"); Mtext sqrtSymbol = new Mtext(); sqrtSymbol.setValue(ROOT_SYMBOL); mrootSymbol.addContent(sqrtSymbol.render(null, null)); mrootSpan.addContent(mrootSymbol); Element mrootTopbar = new Element("span"); mrootTopbar.setAttribute("class", "mroot-topbar"); // base Element baseSpan = new Element("span"); baseSpan.setAttribute("class", "mroot-base"); baseSpan.addContent(base.render(null, null)); mrootTopbar.addContent(baseSpan); mrootSpan.addContent(mrootTopbar); return mrootSpan; }
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 ww . ja va2 s . c om*/ 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.layout.Mstyle.java
License:Open Source License
@Override public Element render(FormulaElement parent, List<FormulaElement> siblings) { Element span = new Element("span"); // set style classes String cssClass = "mstyle"; if (style != null && style.isEmpty() == false) { cssClass += " mathvariant-" + style; }//w ww .j a v a 2s . co m span.setAttribute("class", cssClass); if (base.isEmpty() == false) { for (FormulaElement e : base) { span.addContent(e.render(null, null)); } } return span; }
From source file:at.ac.tuwien.ims.latex2mobiformulaconv.converter.mathml2html.elements.scriptlimit.Mover.java
License:Open Source License
@Override public Element render(FormulaElement parent, List<FormulaElement> siblings) { Element mainDiv = new Element("div"); mainDiv.setAttribute("class", "mover"); // Siblings/* w w w. j a v a 2 s . c om*/ List<FormulaElement> content = new ArrayList<>(); content.add(base); content.add(overscript); Element baseDiv = new Element("div"); baseDiv.addContent(base.render(this, content)); baseDiv.setAttribute("class", "base"); Element overscriptDiv = new Element("div"); overscriptDiv.setAttribute("class", "overscript"); overscriptDiv.addContent(overscript.render(this, content)); mainDiv.addContent(overscriptDiv); mainDiv.addContent(baseDiv); return mainDiv; }
From source file:at.ac.tuwien.ims.latex2mobiformulaconv.converter.mathml2html.elements.scriptlimit.Msub.java
License:Open Source License
@Override public Element render(FormulaElement parent, List<FormulaElement> siblings) { Element msubSpan = new Element("span"); msubSpan.setAttribute("class", "msub"); // Add base content msubSpan.addContent(base.render(null, null)); // Add subscript content Element sub = new Element("sub"); sub.addContent(subscript.render(null, null)); msubSpan.addContent(sub);/*from w ww.j a v a 2s. com*/ return msubSpan; }
From source file:at.ac.tuwien.ims.latex2mobiformulaconv.converter.mathml2html.elements.scriptlimit.Msubsup.java
License:Open Source License
@Override public Element render(FormulaElement parent, List<FormulaElement> siblings) { Element msubsupSpan = new Element("span"); msubsupSpan.setAttribute("class", "msubsup"); // Add base content msubsupSpan.addContent(base.render(null, null)); // Add subscript content Element sup = new Element("sup"); sup.addContent(superscript.render(null, null)); msubsupSpan.addContent(sup);/* w w w.j a v a 2 s . co m*/ // Add superscript content Element sub = new Element("sub"); sub.addContent(subscript.render(null, null)); msubsupSpan.addContent(sub); return msubsupSpan; }