/** * 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; }
if (context.ownerDocument() != null) // quirks setup: doc.quirksMode(context.ownerDocument().quirksMode());
public Document ownerDocument() { return originElement.ownerDocument(); }
@Override public Document getOwnerDocument() { return new DocumentAdaptor(element.ownerDocument()); }
@Override public Document getOwnerDocument() { return NodeAdaptors.getDocument(element.ownerDocument()); }
@Override public Document getOwnerDocument() { return new DocumentAdaptor(element.ownerDocument()); }
@Override public Document getOwnerDocument() { return NodeAdaptors.getDocument(element.ownerDocument()); }
private final static void applySnippetResultToElement(Document doc, String snippetRefId, Element snippetElement, Element renderTarget, Renderer renderer) { apply(renderTarget, renderer); if (snippetElement.ownerDocument() == null) { // it means this snippet element is replaced by a // element completely String reSelector = SelectorUtil.attr(ExtNodeConstants.SNIPPET_NODE_TAG_SELECTOR, ExtNodeConstants.ATTR_SNIPPET_REF, snippetRefId); Elements elems = doc.select(reSelector); if (elems.size() > 0) { snippetElement = elems.get(0); } else { snippetElement = null; } } if (snippetElement != null) { snippetElement.attr(ExtNodeConstants.SNIPPET_NODE_ATTR_STATUS, ExtNodeConstants.SNIPPET_NODE_ATTR_STATUS_FINISHED); } }
private void createButton(Element parent, String actionButtonId, String buttonClass, String iconClass, String messageKey, String descriptionKey, String clickFunction) { Element buttonNode = parent.ownerDocument().createElement("button") .attr("class", buttonClass != null ? "btn btn-" + buttonClass : "btn") .attr("disabled", "true") .attr("id", actionButtonId) .attr("data-toggle", "tooltip") .attr("data-placement", "bottom") .attr("title", i18Source.getMessage(descriptionKey)); Element buttonIcon = parent.ownerDocument().createElement("span") .attr("class", iconClass != null ? "glyphicon glyphicon-" + iconClass : "glyphicon"); parent.appendChild(buttonNode); buttonNode.appendChild(buttonIcon); buttonNode.appendText(i18Source.getMessage(messageKey)); scriptBuilder.append("$('#").append(actionButtonId).append("').click(function() { ").append(clickFunction).append("('").append(getViewedObjectId()).append("'); });"); scriptBuilder.append("$('#").append(actionButtonId).append("').tooltip();"); }
public final static void removeNodesBySelector(Element target, String selector, boolean pullupChildren) { Elements removeNodes = target.select(selector); Iterator<Element> it = removeNodes.iterator(); Element rm; while (it.hasNext()) { rm = it.next(); if (target == rm) { continue; } if (rm.ownerDocument() == null) { continue; } if (pullupChildren) { pullupChildren(rm); } rm.remove(); } }
private void addClaimActionButton(Element parent) { String actionButtonId = "action-button-claim"; Element buttonNode = parent.ownerDocument().createElement("button") .attr("class", "btn btn-warning") .attr("disabled", "true") .attr("id", actionButtonId); parent.appendChild(buttonNode); Element cancelButtonIcon = parent.ownerDocument().createElement("span") .attr("class", "glyphicon glyphicon-download"); parent.appendChild(buttonNode); buttonNode.appendChild(cancelButtonIcon); buttonNode.appendText(i18Source.getMessage("button.claim")); Long processStateConfigurationId = task.getCurrentProcessStateConfiguration().getId(); scriptBuilder.append("$('#").append(actionButtonId) .append("').click(function() { claimTaskFromQueue('#action-button-claim','null', '") .append(processStateConfigurationId).append("','") .append(task.getInternalTaskId()) .append("'); });") .append("$('#").append(actionButtonId) .append("').tooltip({placement: 'bottom', title: '").append(i18Source.getMessage("button.claim.descrition")).append("'});"); }
/** * 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; }
Element buttonNode = parent.ownerDocument().createElement("button") .attr("class", btnClass) .attr("disabled", "true") Element actionButtonIcon = parent.ownerDocument().createElement("span") .attr("class", "glyphicon glyphicon-" + iconName);
if (ee.ownerDocument() == null) { continue; // it a child of something we've already killed, so it
private ItemImpl follow(Element el, MicrodataDocument doc) throws ClientException { if (el.hasAttr("itemscope")) { return new ItemImpl(el, doc); } if (el.tagName().equalsIgnoreCase("a") && el.hasAttr("href")) { String href = el.attr("href"); if (href.startsWith("#")) { Element first = el.ownerDocument().select(href).first(); return first == null ? null : follow(first, doc); } String absHref = el.attr("abs:href"); MicrodataDocument d = (MicrodataDocument) doc.client.get(absHref); try { URI uri = new URI(absHref); String fragment = uri.getRawFragment(); if (fragment != null) { Element e = d.jsoupDocument.getElementById(fragment); return e == null ? null : follow(e, d); } } catch (URISyntaxException ex) { throw new ClientException("Error parsing URI: " + absHref, ex); } ItemsImpl items = (ItemsImpl) d.items(); if (items.length() == 1) { return (ItemImpl) items.at(0); } throw new ClientException("Unable determine item: " + absHref); } return new ItemImpl(el, doc); }
Element divContentNode = parent.ownerDocument().createElement("div") .attr("id", "vertical_layout" + widget.getId()); parent.appendChild(divContentNode); Element ulNode = parent.ownerDocument().createElement("ul") .attr("id", tabId) .attr("class", "nav nav-tabs"); parent.appendChild(ulNode); Element divContentNode = parent.ownerDocument().createElement("div") .attr("id", divContentId) .attr("class", "tab-content"); Element liNode = parent.ownerDocument().createElement("li"); ulNode.appendChild(liNode); Element aNode = parent.ownerDocument().createElement("a") .attr("id", "tab_link_" + childId) .attr("href", '#' + childId) Element divTabContentNode = parent.ownerDocument().createElement("div") .attr("id", childId) .attr("class", isFirst ? "tab-pane active" : "tab-pane"); Element divContentNode = parent.ownerDocument().createElement("div") .attr("id", "vertical_layout" + widget.getId()); parent.appendChild(divContentNode); Element divContentNode = parent.ownerDocument().createElement("div")
if (context.ownerDocument() != null) // quirks setup: doc.quirksMode(context.ownerDocument().quirksMode());
/** * Handle an ignored HTMLElement. * The default method here is to either write the HTMLElement as a block if it is a block element, * or write it directly if it is not. * * @param node Node to handle * @param converter Parent converter for this object. */ public void handleIgnoredHTMLElement(Element node, DocumentConverter converter) { if(node.isBlock()) { converter.output.writeBlock(node.toString()); } else { // Note: because this is an inline element, we want to make sure it stays that way! // this means turning off prettyPrinting, so that JSoup doesn't add unecessary spacing around // the child nodes. Document doc = node.ownerDocument(); boolean oldPrettyPrint = doc.outputSettings().prettyPrint(); doc.outputSettings().prettyPrint(false); converter.output.write(node.toString()); doc.outputSettings().prettyPrint(oldPrettyPrint); } }
Element paragraph = body.ownerDocument().createElement(tag.getName());