List of usage examples for org.jsoup.nodes Element html
public Element html(String html)
From source file:com.semfapp.adamdilger.semf.NonConformanceActivity.java
public void createPdf() { Document document = Pdf.getTemplate(getApplicationContext(), data.getJobNumber()); try {/*from w ww . jav a 2s . c o m*/ Document body = Jsoup.parse(getAssets().open("nonConformance.html"), "utf-8", "http://www.example.com"); Element site = body.getElementById("site"); Element siteLocation = body.getElementById("site_location"); Element recipient = body.getElementById("recipient"); Element recipientEmail = body.getElementById("recipient_email"); Element description = body.getElementById("description_list"); Element actions = body.getElementById("actions_list"); String[] descriptionArray, actionsArray; descriptionArray = data.getDescription().split(System.lineSeparator()); actionsArray = data.getActions().split(System.lineSeparator()); site.text(data.getSite()); siteLocation.text(data.getLocation()); recipient.html("<p>" + data.getRecipient() + "</p>"); recipientEmail.html("<p>" + data.getRecipientEmail() + "</p>"); //add each bullet from arrays as a <p> for (int x = 0; x < descriptionArray.length; x++) { String f = ""; for (String bullet : descriptionArray) { f += "<p>" + bullet + "</p>"; } description.html(f); } for (int x = 0; x < actionsArray.length; x++) { String f = ""; for (String bullet : actionsArray) { f += "<p>" + bullet + "</p>"; } actions.html(f); } document.getElementById("main").html(body.html()); } catch (Exception e) { System.out.println("ERROR: " + e.toString()); } String filePath = MainActivity.pdf.createFilePath(this, "Non Conformance"); MainActivity.pdf.createPdfToFile(this, document.html(), filePath, null); pdfAttatchment = new File(filePath); }
From source file:com.semfapp.adamdilger.semf.SiteInstructionActivity.java
public void createPdf() { Document documentTemplate = Pdf.getTemplate(getApplicationContext(), data.getJobNumber()); try {//from w ww .j a v a 2 s . c o m Document body = Jsoup.parse(getAssets().open("siteInstruction.html"), "utf-8", "http://www.example.com"); Element site = body.getElementById("site"); Element siteLocation = body.getElementById("site_location"); Element recipient = body.getElementById("recipient"); Element recipientEmail = body.getElementById("recipient_email"); Element description = body.getElementById("description_list"); String[] descriptionArray; descriptionArray = data.getDescription().split(System.lineSeparator()); site.text(data.getSite()); siteLocation.text(data.getLocation()); recipient.html("<p>" + data.getRecipient() + "</p>"); recipientEmail.html("<p>" + data.getRecipientEmail() + "</p>"); //add each bullet from arrays as a <p> for (int x = 0; x < descriptionArray.length; x++) { String f = ""; for (String bullet : descriptionArray) { f += "<p>" + bullet + "</p>"; } description.html(f); } documentTemplate.getElementById("main").html(body.html()); } catch (Exception e) { System.out.println("ERROR: " + e.toString()); } name = Emailer.getSubject(Emailer.SITE_INSTRUCTION_CODE, data.getJobNumber()); String filePath = MainActivity.pdf.createFilePath(this, name); MainActivity.pdf.createPdfToFile(this, documentTemplate.html(), filePath, data.getImageArray()); pdfAttatchment = new File(filePath); }
From source file:org.apdplat.superword.tools.PrefixSuffixOptimizer.java
/** * ?????//w ww . ja va 2 s. co m * * @param element */ public static void replace(Element element) { String oldText = element.text(); StringBuilder newText = new StringBuilder(); System.out.println("oldText: " + oldText); String[] items = oldText.trim().replace(".", ",").split(","); for (String item : items) { item = item.trim(); if (!StringUtils.isAlpha(item)) { newText.append(item).append(", "); continue; } if (StringUtils.isAllUpperCase(item)) { newText.append("<strong><a target=\"_blank\" href=\"http://www.iciba.com/").append(item) .append("\">").append(item).append("</a></strong>").append(", "); } else { newText.append("<a target=\"_blank\" href=\"http://www.iciba.com/").append(item).append("\">") .append(item).append("</a>").append(", "); } WORDS.add(item.toLowerCase()); } if (newText.length() > 2) { String text = newText.substring(0, newText.length() - 2); System.out.println("newText: " + text); element.html(text); } }
From source file:org.eclipse.mylyn.docs.examples.GenerateEPUB.java
public static void main(String[] args) { // clean up from last run try {//from w w w. ja va2 s.c om Files.delete(Paths.get("loremipsum.html")); Files.delete(Paths.get("loremipsum.epub")); } catch (IOException e1) { /* no worries */ } try ( // read MarkDown FileReader fr = new FileReader("loremipsum.md"); // and output HTML Writer fw = Files.newBufferedWriter(Paths.get("loremipsum.html"), StandardOpenOption.CREATE)) { // generate HTML from markdown MarkupParser parser = new MarkupParser(); parser.setMarkupLanguage(new MarkdownLanguage()); HtmlDocumentBuilder builder = new HtmlDocumentBuilder(fw); parser.setBuilder(builder); parser.parse(fr, true); // convert any inline equations in the HTML into MathML String html = new String(Files.readAllBytes(Paths.get("loremipsum.html"))); StringBuffer sb = new StringBuffer(); Matcher m = EQUATION.matcher(html); // for each equation while (m.find()) { // replace the LaTeX code with MathML m.appendReplacement(sb, laTeX2MathMl(m.group())); } m.appendTail(sb); // EPUB 2.0 can only handle embedded SVG so we find all referenced // SVG files and replace the reference with the actual SVG code Document parse = Jsoup.parse(sb.toString(), "UTF-8", Parser.xmlParser()); Elements select = parse.select("img"); for (Element element : select) { String attr = element.attr("src"); if (attr.endsWith(".svg")) { byte[] svg = Files.readAllBytes(Paths.get(attr)); element.html(new String(svg)); } } // write back the modified HTML-file Files.write(Paths.get("loremipsum.html"), sb.toString().getBytes(), StandardOpenOption.WRITE); // instantiate a new EPUB version 2 publication Publication pub = Publication.getVersion2Instance(); // include referenced resources (default is false) pub.setIncludeReferencedResources(true); // title and subject is required pub.addTitle("EclipseCon Demo"); pub.addSubject("EclipseCon Demo"); // generate table of contents (default is true) pub.setGenerateToc(true); epub.add(pub); // add one chapter pub.addItem(Paths.get("loremipsum.html").toFile()); // create the EPUB epub.pack(new File("loremipsum.epub")); } catch (Exception e) { e.printStackTrace(); } }