List of usage examples for org.jsoup.nodes Element appendElement
public Element appendElement(String tagName)
From source file:com.aliyun.openservices.odps.console.commands.DescribeResourceCommand.java
@Override public String runHtml(Document dom) throws ODPSConsoleException, OdpsException { Odps odps = getCurrentOdps();//from w ww .j av a 2 s . c o m if (!(odps.resources().exists(projectName, resourceName))) { throw new ODPSConsoleException("Resource not found : " + resourceName); } Resource r = odps.resources().get(projectName, resourceName); Element element = dom.body().appendElement("div").appendElement("dl"); element.appendElement("dt").text("Name"); element.appendElement("dd").text(r.getName()); element.appendElement("dt").text("Owner"); element.appendElement("dd").text(r.getOwner()); element.appendElement("dt").text("Type"); element.appendElement("dd").text(String.valueOf(r.getType())); if (r.getType() == Resource.Type.TABLE) { TableResource tr = (TableResource) r; String tableSource = tr.getSourceTable().getProject() + "." + tr.getSourceTable().getName(); if (tr.getSourceTablePartition() != null) { tableSource += " partition(" + tr.getSourceTablePartition().toString() + ")"; } element.appendElement("dt").text("SourceTableName"); element.appendElement("dd").text(tableSource); } element.appendElement("dt").text("Comment"); element.appendElement("dd").text(r.getComment()); element.appendElement("dt").text("CreatedTime"); element.appendElement("dd").text(DATE_FORMAT.format(r.getCreatedTime())); element.appendElement("dt").text("LastModifiedTime"); element.appendElement("dd").text(DATE_FORMAT.format(r.getLastModifiedTime())); return dom.toString(); }
From source file:com.blackducksoftware.tools.nrt.generator.NRTReportGenerator.java
private void addNewScriptElementWithJson(Element jsonCompListElement, String jsonText) { Element scriptElement = jsonCompListElement.appendElement("script"); DataNode jsonNode = new DataNode(jsonText, ""); scriptElement.appendChild(jsonNode); }
From source file:poe.trade.assist.SearchForm.java
private String removeAllExceptSearchForm(String html) { String htmlDirectory = htmlDirectory(); Document doc = Jsoup.parse(html); // Remove stuff outside of id="main" // doc.body().children().stream().filter(e -> !"main".equalsIgnoreCase(e.id())).forEach(e -> e.remove()); Element head = doc.head(); // Replace everthing in the <head> head.children().stream().forEach(e -> e.remove()); head.appendElement("meta").attr("charset", "utf-8"); head.appendElement("meta").attr("name", "viewport").attr("content", "width=device-width"); head.appendElement("title").text("poe.trade.assist"); head.appendElement("script").attr("type", "text/javascript").attr("src", htmlDirectory + "packed.js"); head.appendElement("link").attr("rel", "stylesheet").attr("href", htmlDirectory + "packed_dark.css"); // Show search form Optional.ofNullable(doc.getElementById("search-form")).ifPresent(e -> e.attr("style", "")); Optional.ofNullable(doc.getElementById("search")) .ifPresent(e -> e.attr("action", "http://poe.trade/search")); // /*from w ww . j av a2 s . c om*/ // Element mainElement = doc.getElementById("main"); // Element topDivContainer = mainElement.child(0); // // // Remove everthing that is not id="content" or h2 // topDivContainer.children().stream() // .filter(e -> !"content".equalsIgnoreCase(e.id())) // .filter(e -> !e.tag().getName().equalsIgnoreCase("h2")) // .forEach(e -> e.remove()); // // // Clean up stuff inside id="content" // // // Remove "Show search form", "search/import" // Optional<Element> searchFormElem = doc.getElementsByTag("a").stream().filter(e -> e.hasClass("button") && e.hasClass("secondary") && e.hasClass("expand")).findFirst(); // searchFormElem.ifPresent(e -> e.remove()); // // Optional<Element> searchOrImportDiv = doc.getElementsByTag("div").stream().filter(e -> e.hasClass("row") && e.hasClass("form-choose-action")).findFirst(); // searchOrImportDiv.ifPresent(e -> e.remove()); // // // Remove search results Elements searchResultBlocks = doc.getElementsByClass("search-results-block"); if (searchResultBlocks.size() > 0) { searchResultBlocks.get(0).remove(); } // append assist as the last element in body // doc.body().appendElement("script").attr("type", "text/javascript").attr("src", htmlDirectory + "assist.js"); String cleanHtml = doc.toString(); return cleanHtml; }
From source file:poe.trade.assist.SearchView.java
private String addHeadElements(String html) { String htmlDirectory = htmlDirectory(); Document doc = Jsoup.parse(html); Element head = doc.head(); // Replace everthing in the <head> head.children().stream().forEach(e -> e.remove()); head.appendElement("meta").attr("charset", "utf-8"); head.appendElement("meta").attr("name", "viewport").attr("content", "width=device-width"); head.appendElement("title").text("poe.trade.assist"); head.appendElement("script").attr("type", "text/javascript").attr("src", htmlDirectory + "packed.js"); head.appendElement("link").attr("rel", "stylesheet").attr("href", htmlDirectory + "packed_dark.css"); doc.body().appendElement("script").attr("type", "text/javascript").attr("src", htmlDirectory + "assist.js"); String cleanHTML = doc.toString(); // try { // FileUtils.writeStringToFile(new File("test"), cleanHTML); // } catch (IOException e1) { // // TODO Auto-generated catch block // e1.printStackTrace(); // }/*w ww .ja v a2 s. c om*/ return cleanHTML; }