下面列出了org.jsoup.nodes.Comment#org.jsoup.nodes.DataNode 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void head(Node source, int depth) {
if (source instanceof Element) {
Element sourceEl = (Element) source;
if (whitelist.isSafeTag(sourceEl.tagName())) { // safe, clone and copy safe attrs
ElementMeta meta = createSafeElement(sourceEl);
Element destChild = meta.el;
destination.appendChild(destChild);
numDiscarded += meta.numAttribsDiscarded;
destination = destChild;
} else if (source != root) { // not a safe tag, so don't add. don't count root against discarded.
numDiscarded++;
}
} else if (source instanceof TextNode) {
TextNode sourceText = (TextNode) source;
TextNode destText = new TextNode(sourceText.getWholeText());
destination.appendChild(destText);
} else if (source instanceof DataNode && whitelist.isSafeTag(source.parent().nodeName())) {
DataNode sourceData = (DataNode) source;
DataNode destData = new DataNode(sourceData.getWholeData());
destination.appendChild(destData);
} else { // else, we don't care about comments, xml proc instructions, etc
numDiscarded++;
}
}
public void head(Node source, int depth) {
if (source instanceof Element) {
Element sourceEl = (Element) source;
if (whitelist.isSafeTag(sourceEl.tagName())) { // safe, clone and copy safe attrs
ElementMeta meta = createSafeElement(sourceEl);
Element destChild = meta.el;
destination.appendChild(destChild);
numDiscarded += meta.numAttribsDiscarded;
destination = destChild;
} else if (source != root) { // not a safe tag, so don't add. don't count root against discarded.
numDiscarded++;
}
} else if (source instanceof TextNode) {
TextNode sourceText = (TextNode) source;
TextNode destText = new TextNode(sourceText.getWholeText());
destination.appendChild(destText);
} else if (source instanceof DataNode && whitelist.isSafeTag(source.parent().nodeName())) {
DataNode sourceData = (DataNode) source;
DataNode destData = new DataNode(sourceData.getWholeData());
destination.appendChild(destData);
} else { // else, we don't care about comments, xml proc instructions, etc
numDiscarded++;
}
}
@JavascriptInterface
public void showSource(String html) {
Log.d("HTML", html);
Element body = Jsoup.parse(html).body();
Elements elements = body.getElementsByAttribute("src");
for(Element e: elements){
if(e.tagName().equals("video")){
for(DataNode node : e.dataNodes()){
if(node.nodeName().equals("src")){
Log.d("JSInterface",node.getWholeData());
}
}
}
Log.d("JSInterface",e.toString());
}
/*Elements elements = body.getElementsByTag("body");
if(elements != null && !elements.isEmpty()){
elements = elements.get(0).getElementsByTag("video");
if(elements != null && !elements.isEmpty()){
Log.d("JSInterface",elements.get(0).toString());
elements = elements.get(0).getElementsByAttribute("src");
if(elements != null && !elements.isEmpty()){
Log.d("JSInterface",elements.get(0).toString());
}
}
}else {
Log.d("JSInterface","没有Video");
}*/
FileUtils.saveFile("video.html",html);
}
private void addInitialFlow(JsonObject initialJson, Document indexDocument,
VaadinSession session) {
String csrfToken = session.getCsrfToken();
if (csrfToken != null) {
initialJson.put(CSRF_TOKEN, csrfToken);
}
Element elm = new Element("script");
elm.attr("initial", "");
elm.appendChild(new DataNode(
"window.Vaadin = {TypeScript: " + JsonUtil.stringify(initialJson) + "};"
));
indexDocument.head().insertChildren(0, elm);
}
private static Element createElement(String tag, String content,
String... attrs) {
Element elm = new Element(Tag.valueOf(tag), "");
if (content != null && !content.isEmpty()) {
elm.appendChild(new DataNode(content));
}
for (int i = 0; i < attrs.length - 1; i += 2) {
elm.attr(attrs[i], attrs[i + 1]);
}
return elm;
}
private Element createInlineJavaScriptElement(
String javaScriptContents) {
// defer makes no sense without src:
// https://developer.mozilla.org/en/docs/Web/HTML/Element/script
Element wrapper = createJavaScriptElement(null, false);
wrapper.appendChild(
new DataNode(javaScriptContents));
return wrapper;
}
private Element createDependencyElement(BootstrapUriResolver resolver,
LoadMode loadMode, JsonObject dependency,
Dependency.Type type) {
boolean inlineElement = loadMode == LoadMode.INLINE;
String url = dependency.hasKey(Dependency.KEY_URL)
? resolver.resolveVaadinUri(
dependency.getString(Dependency.KEY_URL))
: null;
final Element dependencyElement;
switch (type) {
case STYLESHEET:
dependencyElement = createStylesheetElement(url);
break;
case JAVASCRIPT:
dependencyElement = createJavaScriptElement(url,
!inlineElement);
break;
case JS_MODULE:
dependencyElement = createJavaScriptElement(url, false,
"module");
break;
default:
throw new IllegalStateException(
"Unsupported dependency type: " + type);
}
if (inlineElement) {
dependencyElement.appendChild(new DataNode(
dependency.getString(Dependency.KEY_CONTENTS)));
}
return dependencyElement;
}
/**
* Replace link tags with style tags in order to keep the same inclusion
* order
*
* @param doc
* the html document
* @param cssContents
* the list of external css files with their content
*/
private static void internStyles(Document doc, List<ExternalCss> cssContents) {
Elements els = doc.select(CSS_LINKS_SELECTOR);
for (Element e : els) {
if (isInlineModeAllowed(e, InlineModes.STYLE_ATTR)) {
String path = e.attr(HREF_ATTR);
ExternalCss css = getCss(cssContents, path);
if (css != null) {
Element style = new Element(Tag.valueOf(STYLE_TAG), "");
style.appendChild(new DataNode(getCssContent(css)));
e.replaceWith(style);
}
}
}
}