org.jsoup.nodes.Document.head()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(9.4k)|赞(0)|评价(0)|浏览(205)

本文整理了Java中org.jsoup.nodes.Document.head()方法的一些代码示例,展示了Document.head()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Document.head()方法的具体详情如下:
包路径:org.jsoup.nodes.Document
类名称:Document
方法名:head

Document.head介绍

[英]Accessor to the document's head element.
[中]文档头元素的访问者。

代码示例

代码示例来源:origin: k9mail/k-9

public void clean(Document dirtyDocument, Document cleanedDocument) {
  copySafeNodes(dirtyDocument.head(), cleanedDocument.head());
}

代码示例来源:origin: k9mail/k-9

private void addCustomHeadContents(Document document) {
  document.head().append("<meta name=\"viewport\" content=\"width=device-width\"/>" +
      HtmlConverter.cssStyleTheme() +
      HtmlConverter.cssStylePre());
}

代码示例来源:origin: org.jsoup/jsoup

/**
 Set the document's {@code title} element. Updates the existing element, or adds {@code title} to {@code head} if
 not present
 @param title string to set as title
 */
public void title(String title) {
  Validate.notNull(title);
  Element titleEl = getElementsByTag("title").first();
  if (titleEl == null) { // add to head
    head().appendElement("title").text(title);
  } else {
    titleEl.text(title);
  }
}

代码示例来源:origin: org.jsoup/jsoup

/**
 Determines if the input document <b>body</b>is valid, against the whitelist. It is considered valid if all the tags and attributes
 in the input HTML are allowed by the whitelist, and that there is no content in the <code>head</code>.
 <p>
 This method can be used as a validator for user input. An invalid document will still be cleaned successfully
 using the {@link #clean(Document)} document. If using as a validator, it is recommended to still clean the document
 to ensure enforced attributes are set correctly, and that the output is tidied.
 </p>
 @param dirtyDocument document to test
 @return true if no tags or attributes need to be removed; false if they do
 */
public boolean isValid(Document dirtyDocument) {
  Validate.notNull(dirtyDocument);
  Document clean = Document.createShell(dirtyDocument.baseUri());
  int numDiscarded = copySafeNodes(dirtyDocument.body(), clean.body());
  return numDiscarded == 0
    && dirtyDocument.head().childNodes().size() == 0; // because we only look at the body, but we start from a shell, make sure there's nothing in the head
}

代码示例来源:origin: org.jsoup/jsoup

/**
 Normalise the document. This happens after the parse phase so generally does not need to be called.
 Moves any text content that is not in the body element into the body.
 @return this document after normalisation
 */
public Document normalise() {
  Element htmlEl = findFirstElementByTagName("html", this);
  if (htmlEl == null)
    htmlEl = appendElement("html");
  if (head() == null)
    htmlEl.prependElement("head");
  if (body() == null)
    htmlEl.appendElement("body");
  // pull text nodes out of root, html, and head els, and push into body. non-text nodes are already taken care
  // of. do in inverse order to maintain text order.
  normaliseTextNodes(head());
  normaliseTextNodes(htmlEl);
  normaliseTextNodes(this);
  normaliseStructure("head", htmlEl);
  normaliseStructure("body", htmlEl);
  
  ensureMetaCharsetElement();
  
  return this;
}

代码示例来源:origin: org.jsoup/jsoup

metaCharset.attr("charset", charset().displayName());
} else {
  Element head = head();

代码示例来源:origin: stackoverflow.com

Document document = Jsoup.connect(url).get();
Element head = document.head();
head.append("<link rel=\"stylesheet\" href=\"http://example.com/your.css\">");

代码示例来源:origin: rakam-io/rakam

parse.head().prepend(String.format("<base href='%s'>", url));
parse.head().prepend("<link href=\"/static/components/codemirror/lib/codemirror.css\" media=\"screen\" rel=\"stylesheet\" />");
parse.head().prepend("<link href=\"/static/embed/jquery-ui-theme.css\" media=\"screen\" rel=\"stylesheet\" />");
parse.head().prepend("<link href=\"/static/components/bootstrap-colorpicker/css/colorpicker.css\" media=\"screen\" rel=\"stylesheet\" />");
parse.head().prepend("<link href=\"/static/embed/rakam-inline-editor.css\" media=\"screen\" rel=\"stylesheet\" />");
parse.head().prepend("<script src=\"/static/embed/rakam-inline-editor.js\"></script>");
parse.head().prepend("<script src=\"/static/components/bootstrap-colorpicker/js/bootstrap-colorpicker.js\"></script>");
parse.head().prepend("<script src=\"/static/components/codemirror/mode/xml/xml.js\"></script>");
parse.head().prepend("<script src=\"/static/components/codemirror/mode/javascript/javascript.js\"></script>");
parse.head().prepend("<script src=\"/static/components/codemirror/mode/css/css.js\"></script>");
parse.head().prepend("<script src=\"/static/components/codemirror/mode/vbscript/vbscript.js\"></script>");
parse.head().prepend("<script src=\"/static/components/codemirror/mode/htmlmixed/htmlmixed.js\"></script>");
parse.head().prepend("<script src=\"/static/components/codemirror/lib/codemirror.js\"></script>");
parse.head().prepend("<script src=\"/static/components/jquery-ui/jquery-ui.min.js\"></script>");
parse.head().prepend("<script src=\"/static/components/jquery/dist/jquery.min.js\"></script>");

代码示例来源:origin: org.jboss.errai/errai-bus

final Document document = Jsoup.parse(responseWrapper.toString());
String injectedScript = "<script>var " + ERRAI_CSRF_TOKEN_VAR + " = '" + CSRFTokenCheck.getToken(session) + "';</script>";
document.head().prepend(injectedScript);
output = document.html();

代码示例来源:origin: com.vaadin/vaadin-server

/**
 * Writes the package mappings (prefix -> package name) of this object to
 * the specified document.
 * <p>
 * The prefixes are stored as <meta> tags under <head> in the document.
 *
 * @param doc
 *            the Jsoup document tree where the package mappings are written
 */
public void writePackageMappings(Document doc) {
  Element head = doc.head();
  for (String prefix : getPackagePrefixes()) {
    // Only store the prefix-name mapping if it is not a default mapping
    // (such as "vaadin" -> "com.vaadin.ui")
    if (!VAADIN_PREFIX.equals(prefix) && !VAADIN7_PREFIX.equals(prefix)
        && !LEGACY_PREFIX.equals(prefix)) {
      Node newNode = doc.createElement("meta");
      newNode.attr("name", "package-mapping");
      String prefixToPackageName = prefix + ":" + getPackage(prefix);
      newNode.attr("content", prefixToPackageName);
      head.appendChild(newNode);
    }
  }
}

代码示例来源:origin: com.vaadin/vaadin-server

Element head = doc.head();
if (head == null) {
  return;

代码示例来源:origin: com.vaadin/vaadin-server

document.child(0).before(doctype);
Element head = document.head();
head.appendElement("meta").attr("http-equiv", "Content-Type").attr(
    "content", ApplicationConstants.CONTENT_TYPE_TEXT_HTML_UTF_8);

代码示例来源:origin: stackoverflow.com

Connection con2=Jsoup.connect(url);
   Document doc = con2.get();
   //or use Document doc = Jsoup.parse(html);
   Element e=doc.head().select("meta[name=header]").first();
   String url=e.attr("content");

代码示例来源:origin: stackoverflow.com

Connection con2=Jsoup.connect(url);
Document doc = con2.get();
Element e1=doc.head().select("link[href~=.*\\.(ico|png)]").first(); // example type 1 & 2 
String imageUrl1=e1.attr("href");
Element e2 = doc.head().select("meta[itemprop=image]").first(); //example type 3 
String imageUrl2=e2.attr("itemprop");

代码示例来源:origin: aint/laverna-android

/**
 * A method which adds style in the head of the document.
 * @param doc a document to add style.
 */
private void addDocStyle(Document doc) {
  Element head = doc.head();
  head.append(DOC_STYLE);
}

代码示例来源:origin: isucon/isucon5-qualify

public void hasStyleSheet(String path) {
 Elements es = document().head().getElementsByTag("link");
 if (es.stream().noneMatch(e -> e.attr("rel").equals("stylesheet") && e.attr("href").equals(path))) {
  addViolation(String.format("スタイルシートのパス %s への参照がありません", path));
 }
}

代码示例来源:origin: io.committed.krill/krill

private void process(final InputStream stream, final String charset, final ContentHandler handler,
  final Metadata metadata) throws IOException, SAXException {
 final Document document = Jsoup.parse(stream, charset, "");
 clean(document);
 document.head().select("meta").forEach(m -> {
  final String name = m.attr("name");
  final String value = m.attr("content");
  if (!Strings.isNullOrEmpty(name)) {
   metadata.add(name, value);
  }
 });
 document.traverse(new JsoupToSaxVisitor(handler));
}

代码示例来源:origin: isucon/isucon5-final

public boolean hasStyleSheet(String path) {
  Elements es = document().head().getElementsByTag("link");
  if (es.stream().noneMatch(e -> e.attr("rel").equals("stylesheet") && e.attr("href").equals(path))) {
    addViolation(String.format("スタイルシートのパス %s への参照がありません", path));
    return wrap(false);
  }
  return wrap(true);
}

代码示例来源:origin: GistLabs/mechanize

@Override
protected void loadPage() throws Exception {
  Document jsoup = Jsoup.parse(getInputStream(), getContentEncoding(response), getUri());
  setBaseUri(jsoup.head().baseUri());
  this.htmlElements = new HtmlElements(this, jsoup);
}

代码示例来源:origin: aint/laverna-android

/**
 * A method which parses html using Jsoup,
 * @param htmlText a text to parse.
 * @return a document with parsed text.
 */
private Document getParsedHtmlDocument(String htmlText) {
  Document doc = Jsoup.parseBodyFragment(htmlText);
  doc.outputSettings(new Document.OutputSettings().prettyPrint(false));
  doc.head().append(DOC_STYLE);
  doc.body().append(HIGHLIGHT_JS_SCRIPT);
  return doc;
}

相关文章