本文整理了Java中org.jsoup.parser.Tag.valueOf()
方法的一些代码示例,展示了Tag.valueOf()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Tag.valueOf()
方法的具体详情如下:
包路径:org.jsoup.parser.Tag
类名称:Tag
方法名:valueOf
[英]Get a Tag by name. If not previously defined (unknown), returns a new generic tag, that can do anything.
Pre-defined tags (P, DIV etc) will be ==, but unknown tags are not registered and will only .equals().
[中]按名称获取标签。如果之前未定义(未知),则返回一个新的通用标记,该标记可以执行任何操作。
预定义的标签(P、DIV等)将为==,但未知的标签不会被注册,只会被删除。等于()。
代码示例来源:origin: org.jsoup/jsoup
/**
* Get a Tag by name. If not previously defined (unknown), returns a new generic tag, that can do anything.
* <p>
* Pre-defined tags (P, DIV etc) will be ==, but unknown tags are not registered and will only .equals().
* </p>
*
* @param tagName Name of tag, e.g. "p". <b>Case sensitive</b>.
* @return The tag, either defined or new generic.
*/
public static Tag valueOf(String tagName) {
return valueOf(tagName, ParseSettings.preserveCase);
}
代码示例来源:origin: org.jsoup/jsoup
/**
Create a new, empty Document.
@param baseUri base URI of document
@see org.jsoup.Jsoup#parse
@see #createShell
*/
public Document(String baseUri) {
super(Tag.valueOf("#root", ParseSettings.htmlDefault), baseUri);
this.location = baseUri;
}
代码示例来源:origin: org.jsoup/jsoup
/**
* Create a new, standalone element.
* @param tag tag name
*/
public Element(String tag) {
this(Tag.valueOf(tag), "", new Attributes());
}
代码示例来源:origin: org.jsoup/jsoup
/**
* Change the tag of this element. For example, convert a {@code <span>} to a {@code <div>} with
* {@code el.tagName("div");}.
*
* @param tagName new tag name for this element
* @return this element, for chaining
*/
public Element tagName(String tagName) {
Validate.notEmpty(tagName, "Tag name must not be empty.");
tag = Tag.valueOf(tagName, ParseSettings.preserveCase); // preserve the requested tag case
return this;
}
代码示例来源:origin: org.jsoup/jsoup
/**
Create a new Element, with this document's base uri. Does not make the new element a child of this document.
@param tagName element tag name (e.g. {@code a})
@return new element
*/
public Element createElement(String tagName) {
return new Element(Tag.valueOf(tagName, ParseSettings.preserveCase), this.baseUri());
}
代码示例来源:origin: org.jsoup/jsoup
Element insertStartTag(String startTagName) {
Element el = new Element(Tag.valueOf(startTagName, settings), baseUri);
insert(el);
return el;
}
代码示例来源:origin: jooby-project/jooby
/**
* Read a svg file and return the svg element (original) and a new symbol element (created from
* original).
*
* @param file Svg file.
* @param id ID to use.
* @return Svg element (original) and a symbol element (converted).
* @throws IOException If something goes wrong.
*/
private Tuple<Element, Element> symbol(final Path file, final String id) throws IOException {
Element svg = Jsoup.parse(file.toFile(), "UTF-8").select("svg").first();
Element symbol = new Element(Tag.valueOf("symbol"), "")
.attr("id", id)
.attr("viewBox", svg.attr("viewBox"));
new ArrayList<>(svg.childNodes()).forEach(symbol::appendChild);
return new Tuple(svg, symbol);
}
代码示例来源:origin: org.jsoup/jsoup
FormElement insertForm(Token.StartTag startTag, boolean onStack) {
Tag tag = Tag.valueOf(startTag.name(), settings);
FormElement el = new FormElement(tag, baseUri, startTag.attributes);
setFormElement(el);
insertNode(el);
if (onStack)
stack.add(el);
return el;
}
代码示例来源:origin: org.jsoup/jsoup
/**
* Create a new element by tag name, and add it as the first child.
*
* @param tagName the name of the tag (e.g. {@code div}).
* @return the new element, to allow you to add content to it, e.g.:
* {@code parent.prependElement("h1").attr("id", "header").text("Welcome");}
*/
public Element prependElement(String tagName) {
Element child = new Element(Tag.valueOf(tagName), baseUri());
prependChild(child);
return child;
}
代码示例来源:origin: org.jsoup/jsoup
/**
* Create a new element by tag name, and add it as the last child.
*
* @param tagName the name of the tag (e.g. {@code div}).
* @return the new element, to allow you to add content to it, e.g.:
* {@code parent.appendElement("h1").attr("id", "header").text("Welcome");}
*/
public Element appendElement(String tagName) {
Element child = new Element(Tag.valueOf(tagName), baseUri());
appendChild(child);
return child;
}
代码示例来源:origin: jooby-project/jooby
@Override
public void run(final Config conf) throws Exception {
String input = get("input");
if (input == null) {
throw new IllegalArgumentException("Required option 'svg-symbol.input' not present");
}
Path basedir = Paths.get(get("basedir").toString());
Path dir = basedir.resolve(input);
List<CharSequence> cssout = new ArrayList<>();
Element svg = new Element(Tag.valueOf("svg"), "");
attrs("svg", "output").forEach((n, v) -> svg.attr(n, v.toString()));
files(dir, file -> {
log.debug("{}", file);
String id = get("id.prefix") + file.getFileName().toString().replace(".svg", "")
+ get("id.suffix");
Tuple<Element, Element> rewrite = symbol(file, id);
svg.appendChild(rewrite._2);
cssout.add(css(id, rewrite._1));
});
write(basedir.resolve(svgPath()), ImmutableList.of(svg.outerHtml()));
write(basedir.resolve(cssPath()), cssout);
}
代码示例来源:origin: org.jsoup/jsoup
Element insert(Token.StartTag startTag) {
Tag tag = Tag.valueOf(startTag.name(), settings);
// todo: wonder if for xml parsing, should treat all tags as unknown? because it's not html.
Element el = new Element(tag, baseUri, settings.normalizeAttributes(startTag.attributes));
insertNode(el);
if (startTag.isSelfClosing()) {
if (!tag.isKnownTag()) // unknown tag, remember this is self closing for output. see above.
tag.setSelfClosing();
} else {
stack.add(el);
}
return el;
}
代码示例来源:origin: org.jsoup/jsoup
@Override
public boolean matches(Element root, Element element) {
if (element instanceof PseudoTextElement)
return true;
List<TextNode> textNodes = element.textNodes();
for (TextNode textNode : textNodes) {
PseudoTextElement pel = new PseudoTextElement(
org.jsoup.parser.Tag.valueOf(element.tagName()), element.baseUri(), element.attributes());
textNode.replaceWith(pel);
pel.appendChild(textNode);
}
return false;
}
代码示例来源:origin: org.jsoup/jsoup
Element insert(Token.StartTag startTag) {
// handle empty unknown tags
// when the spec expects an empty tag, will directly hit insertEmpty, so won't generate this fake end tag.
if (startTag.isSelfClosing()) {
Element el = insertEmpty(startTag);
stack.add(el);
tokeniser.transition(TokeniserState.Data); // handles <script />, otherwise needs breakout steps from script data
tokeniser.emit(emptyEnd.reset().name(el.tagName())); // ensure we get out of whatever state we are in. emitted for yielded processing
return el;
}
Element el = new Element(Tag.valueOf(startTag.name(), settings), baseUri, settings.normalizeAttributes(startTag.attributes));
insert(el);
return el;
}
代码示例来源:origin: org.jsoup/jsoup
Element insertEmpty(Token.StartTag startTag) {
Tag tag = Tag.valueOf(startTag.name(), settings);
Element el = new Element(tag, baseUri, startTag.attributes);
insertNode(el);
if (startTag.isSelfClosing()) {
if (tag.isKnownTag()) {
if (!tag.isEmpty())
tokeniser.error("Tag cannot be self closing; not a void tag");
}
else // unknown tag, remember this is self closing for output
tag.setSelfClosing();
}
return el;
}
代码示例来源:origin: org.jsoup/jsoup
private ElementMeta createSafeElement(Element sourceEl) {
String sourceTag = sourceEl.tagName();
Attributes destAttrs = new Attributes();
Element dest = new Element(Tag.valueOf(sourceTag), sourceEl.baseUri(), destAttrs);
int numDiscarded = 0;
Attributes sourceAttrs = sourceEl.attributes();
for (Attribute sourceAttr : sourceAttrs) {
if (whitelist.isSafeAttribute(sourceTag, sourceEl, sourceAttr))
destAttrs.put(sourceAttr);
else
numDiscarded++;
}
Attributes enforcedAttrs = whitelist.getEnforcedAttributes(sourceTag);
destAttrs.addAll(enforcedAttrs);
return new ElementMeta(dest, numDiscarded);
}
代码示例来源:origin: org.jsoup/jsoup
root = new Element(Tag.valueOf("html", settings), baseUri);
doc.appendChild(root);
stack.add(root);
代码示例来源:origin: k9mail/k-9
public void head(Node source, int depth) {
if (elementToSkip != null) {
return;
}
if (source instanceof Element) {
Element sourceElement = (Element) source;
if (isSafeTag(sourceElement)) {
String sourceTag = sourceElement.tagName();
Attributes destinationAttributes = sourceElement.attributes().clone();
Element destinationChild = new Element(Tag.valueOf(sourceTag), sourceElement.baseUri(), destinationAttributes);
destination.appendChild(destinationChild);
destination = destinationChild;
} else if (source != root) {
elementToSkip = sourceElement;
}
} else if (source instanceof TextNode) {
TextNode sourceText = (TextNode) source;
TextNode destinationText = new TextNode(sourceText.getWholeText(), source.baseUri());
destination.appendChild(destinationText);
} else if (source instanceof DataNode && isSafeTag(source.parent())) {
DataNode sourceData = (DataNode) source;
DataNode destinationData = new DataNode(sourceData.getWholeData(), source.baseUri());
destination.appendChild(destinationData);
}
}
代码示例来源:origin: org.jsoup/jsoup
break;
Element replacement = new Element(Tag.valueOf(node.nodeName(), ParseSettings.preserveCase), tb.getBaseUri());
代码示例来源:origin: com.vaadin/vaadin-server
@Override
public void writeDesign(Element design, DesignContext designContext) {
super.writeDesign(design, designContext);
Element popupContent = new Element(Tag.valueOf("popup-content"), "");
popupContent.appendChild(
designContext.createElement(content.getPopupComponent()));
String minimizedHTML = content.getMinimizedValueAsHTML();
if (minimizedHTML != null && !minimizedHTML.isEmpty()) {
design.append(minimizedHTML);
}
design.appendChild(popupContent);
}
内容来源于网络,如有侵权,请联系作者删除!