List of usage examples for org.jdom2 Element Element
public Element(final String name)
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 www . j a v a 2 s .c om 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:arquivo.ArquivoFilme.java
public ArquivoFilme() { super(new File("filmes.xml")); if (!arquivo.exists()) { try {/*from w w w . j a v a 2s .c o m*/ Document doc = new Document(); Element root = new Element("list"); doc.setRootElement(root); XMLOutputter xout = new XMLOutputter(); xout.output(doc, new FileOutputStream(arquivo)); System.out.println("Documento criado com sucesso!"); } catch (Exception e) { // TODO: handle exception } } }
From source file:arquivo.ArquivoFilme.java
public String add(String nome, String faixa, String tipo) { if (0 != busca(nome, true, "filme").size()) return "erro nome ja cadastrado"; SAXBuilder builder = new SAXBuilder(); try {// www .j a v a 2 s.c o m Document doc = builder.build(arquivo); Element root = (Element) doc.getRootElement(); Element filmeE = new Element("filme"); Attribute nomeE = new Attribute("nome", nome); filmeE.setAttribute(nomeE); Attribute tipoE = new Attribute("tipo", tipo); filmeE.setAttribute(tipoE); Attribute faixaE = new Attribute("faixa", faixa); filmeE.setAttribute(faixaE); root.addContent(filmeE); 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) { e.printStackTrace(); } return "erro cadastral"; }
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"; }/* w w w. jav a 2s .c o m*/ 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 ww . ja v a2s . c om*/ 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);//w ww . j a v a 2 s .com 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);//from w w w. j a v a2s.co 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 . ja v a 2s. c o m*/ // 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 w w. j av a 2s . c o 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.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; }/*from w ww.j av a2 s . co m*/ span.setAttribute("class", cssClass); if (base.isEmpty() == false) { for (FormulaElement e : base) { span.addContent(e.render(null, null)); } } return span; }