/** * Only document can be select * See: https://github.com/code4craft/webmagic/issues/113 * * @param elementIterator elementIterator * @return element element */ private Element checkElementAndConvert(ListIterator<Element> elementIterator) { Element element = elementIterator.next(); if (!(element instanceof Document)) { Document root = new Document(element.ownerDocument().baseUri()); Element clone = element.clone(); root.appendChild(clone); elementIterator.set(root); return root; } return element; }
private void insertNode(Node node) { // if the stack hasn't been set up yet, elements (doctype, comments) go into the doc if (stack.size() == 0) doc.appendChild(node); else if (isFosterInserts()) insertInFosterParent(node); else currentElement().appendChild(node); // connect form controls to their form element if (node instanceof Element && ((Element) node).tag().isFormListed()) { if (formElement != null) formElement.addElement((Element) node); } }
doc.appendChild(root); stack.add(root); resetInsertionMode();
boolean process(Token t, HtmlTreeBuilder tb) { if (isWhitespace(t)) { return true; // ignore whitespace } else if (t.isComment()) { tb.insert(t.asComment()); } else if (t.isDoctype()) { // todo: parse error check on expected doctypes // todo: quirk state check on doctype ids Token.Doctype d = t.asDoctype(); DocumentType doctype = new DocumentType( tb.settings.normalizeTag(d.getName()), d.getPublicIdentifier(), d.getSystemIdentifier()); doctype.setPubSysKey(d.getPubSysKey()); tb.getDocument().appendChild(doctype); if (d.isForceQuirks()) tb.getDocument().quirksMode(Document.QuirksMode.quirks); tb.transition(BeforeHtml); } else { // todo: check not iframe srcdoc tb.transition(BeforeHtml); return tb.process(t); // re-process token } return true; } },
doc.appendChild(docType); Element html = doc.createElement("html"); doc.appendChild(html); html.appendChild(doc.createElement("head")); Element body = doc.createElement("body");
private void addVersionNumber(Document document) { Element versionNumber = document.createElement("div") .attr("id", "versionList") .attr("class", "process-version"); document.appendChild(versionNumber); versionNumber.append(description + " v. " + version); }
public StringBuilder build() throws Exception { final StringBuilder stringBuilder = new StringBuilder(8 * 1024); scriptBuilder.append("<script type=\"text/javascript\">"); final Document document = Jsoup.parse(""); if (!hasUserPriviledgesToViewTask()) { final Element widgetsNode = document.createElement("div") .attr("role", "alert") .attr("class", "alert alert-warning"); widgetsNode.text(i18Source.getMessage("task.noright.to.view")); document.appendChild(widgetsNode); stringBuilder.append(document.toString()); return stringBuilder; } if (showGenericButtons()) buildActionButtons(document); final Element widgetsNode = document.createElement("div") .attr("id", getVaadinWidgetsHtmlId()) .attr("class", "vaadin-widgets-view"); document.appendChild(widgetsNode); buildWidgets(document, widgetsNode); buildAdditionalData(document); stringBuilder.append(document.toString()); scriptBuilder.append("vaadinWidgetsCount = ").append(vaadinWidgetsCount).append(';'); scriptBuilder.append("</script>"); stringBuilder.append(scriptBuilder); return stringBuilder; }
/** * Only document can be select * See: https://github.com/code4craft/webmagic/issues/113 * * @param elementIterator elementIterator * @return element element */ private Element checkElementAndConvert(ListIterator<Element> elementIterator) { Element element = elementIterator.next(); if (!(element instanceof Document)) { Document root = new Document(element.ownerDocument().baseUri()); Element clone = element.clone(); root.appendChild(clone); elementIterator.set(root); return root; } return element; }
/** * Only document can be select * See: https://github.com/code4craft/webmagic/issues/113 * * @param elementIterator elementIterator * @return element element */ private Element checkElementAndConvert(ListIterator<Element> elementIterator) { Element element = elementIterator.next(); if (!(element instanceof Document)) { Document root = new Document(element.ownerDocument().baseUri()); Element clone = element.clone(); root.appendChild(clone); elementIterator.set(root); return root; } return element; }
res.appendChild( body.select( "div[id=main]" ).first() ); res.appendChild( script );
res.appendChild( body.select( "div[id=main]" ).first() ); res.appendChild( script );
public String toHtml() { Document doc = new Document(""); doc.appendChild(toElement()); RenderUtil.applyMessages(doc); RenderUtil.applyClearAction(doc, true); return doc.html(); }
/** * Add actions buttons to the output document. */ protected void buildActionButtons(final Document document) { Element actionsNode = document.createElement("div") //.attr("id", "actions-list") .attr("id", getActionsListHtmlId()) .attr("class", "actions-view") .addClass("fixed-element-action-buttons"); document.appendChild(actionsNode); Element genericActionButtons = document.createElement("div") .attr("id", getActionsGenericListHtmlId()) .attr("class", "btn-group pull-left actions-generic-view"); Element specificActionButtons = document.createElement("div") .attr("id", getActionsSpecificListHtmlId()) .attr("class", "btn-group pull-right actions-process-view"); actionsNode.appendChild(genericActionButtons); actionsNode.appendChild(specificActionButtons); document.appendElement("div").addClass("fixed-element-anchor-action-buttons"); /* Check if the viewed object is in a terminal state */ buildGenericActionButtons(genericActionButtons); if (!isViewedObjectClosed()) { buildSpecificActionButtons(specificActionButtons); } }
private void insertNode(Node node) { // if the stack hasn't been set up yet, elements (doctype, comments) go into the doc if (stack.size() == 0) doc.appendChild(node); else if (isFosterInserts()) insertInFosterParent(node); else currentElement().appendChild(node); // connect form controls to their form element if (node instanceof Element && ((Element) node).tag().isFormListed()) { if (formElement != null) formElement.addElement((Element) node); } }
DocumentType doctype = new DocumentType("html", "", "", document.baseUri()); document.appendChild(doctype); Element html = document.appendElement("html"); html.attr("lang", context.getUI().getLocale().getLanguage());
static Document postprocess(Element topNode) { Log.i("postprocess"); Document doc = new Document(""); if (topNode == null) { return doc; } removeNodesWithNegativeScores(topNode); replaceLineBreaksWithSpaces(topNode); removeUnlikelyChildNodes(topNode); removeTagsButRetainContent(topNode); removeTagsNotLikelyToBeParagraphs(topNode); removeTopLevelTagsNotLikelyToBeParagraphs(topNode); removeShortParagraphs(topNode); removeDisallowedAttributes(topNode); for (Node node : topNode.childNodes()) { doc.appendChild(node.clone()); // TODO: Don’t copy each item separately. } return doc; }
doc.appendChild(root); stack.push(root); resetInsertionMode();
boolean process(Token t, Asta4DTagSupportHtmlTreeBuilder tb) { if (isWhitespace(t)) { return true; // ignore whitespace } else if (t.isComment()) { tb.insert(t.asComment()); } else if (t.isDoctype()) { // todo: parse error check on expected doctypes // todo: quirk state check on doctype ids Token.Doctype d = t.asDoctype(); DocumentType doctype = new DocumentType(d.getName(), d.getPublicIdentifier(), d.getSystemIdentifier(), tb.getBaseUri()); tb.getDocument().appendChild(doctype); if (d.isForceQuirks()) tb.getDocument().quirksMode(Document.QuirksMode.quirks); tb.transition(BeforeHtml); } else { // todo: check not iframe srcdoc tb.transition(BeforeHtml); return tb.process(t); // re-process token } return true; } },