本文整理汇总了Java中org.jsoup.helper.Validate.notNull方法的典型用法代码示例。如果您正苦于以下问题:Java Validate.notNull方法的具体用法?Java Validate.notNull怎么用?Java Validate.notNull使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jsoup.helper.Validate
的用法示例。
在下文中一共展示了Validate.notNull方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: insertInFosterParent
import org.jsoup.helper.Validate; //导入方法依赖的package包/类
void insertInFosterParent(Node in) {
Element fosterParent;
Element lastTable = getFromStack("table");
boolean isLastTableParent = false;
if (lastTable != null) {
if (lastTable.parent() != null) {
fosterParent = lastTable.parent();
isLastTableParent = true;
} else
fosterParent = aboveOnStack(lastTable);
} else { // no table == frag
fosterParent = stack.get(0);
}
if (isLastTableParent) {
Validate.notNull(lastTable); // last table cannot be null by this point.
lastTable.before(in);
}
else
fosterParent.appendChild(in);
}
示例2: valueOf
import org.jsoup.helper.Validate; //导入方法依赖的package包/类
/**
* 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". Case insensitive.
* @return The tag, either defined or new generic.
*/
public static Tag valueOf(String tagName) {
Validate.notNull(tagName);
Tag tag = tags.get(tagName);
if (tag == null) {
tagName = tagName.trim().toLowerCase();
Validate.notEmpty(tagName);
tag = tags.get(tagName);
if (tag == null) {
// not defined: create default; go anywhere, do anything! (incl be inside a <p>)
tag = new Tag(tagName);
tag.isBlock = false;
tag.canContainBlock = true;
}
}
return tag;
}
示例3: select
import org.jsoup.helper.Validate; //导入方法依赖的package包/类
/**
* Find elements matching selector.
*
* @param query CSS selector
* @param roots root elements to descend into
* @return matching elements, empty if none
*/
public static Elements select(String query, Iterable<Element> roots) {
Validate.notEmpty(query);
Validate.notNull(roots);
Evaluator evaluator = QueryParser.parse(query);
ArrayList<Element> elements = new ArrayList<Element>();
IdentityHashMap<Element, Boolean> seenElements = new IdentityHashMap<Element, Boolean>();
// dedupe elements by identity, not equality
for (Element root : roots) {
final Elements found = select(evaluator, root);
for (Element el : found) {
if (!seenElements.containsKey(el)) {
elements.add(el);
seenElements.put(el, Boolean.TRUE);
}
}
}
return new Elements(elements);
}
示例4: this
import org.jsoup.helper.Validate; //导入方法依赖的package包/类
/**
Remove a list of allowed elements from a whitelist. (If a tag is not allowed, it will be removed from the HTML.)
@param tags tag names to disallow
@return this (for chaining)
*/
public Whitelist removeTags(String... tags) {
Validate.notNull(tags);
for(String tag: tags) {
Validate.notEmpty(tag);
TagName tagName = TagName.valueOf(tag);
if(tagNames.remove(tagName)) { // Only look in sub-maps if tag was allowed
attributes.remove(tagName);
enforcedAttributes.remove(tagName);
protocols.remove(tagName);
}
}
return this;
}
示例5: traverse
import org.jsoup.helper.Validate; //导入方法依赖的package包/类
/**
* Perform a depth-first traversal through this node and its descendants.
* @param nodeVisitor the visitor callbacks to perform on each node
* @return this node, for chaining
*/
public Node traverse(NodeVisitor nodeVisitor) {
Validate.notNull(nodeVisitor);
NodeTraversor traversor = new NodeTraversor(nodeVisitor);
traversor.traverse(this);
return this;
}
示例6: addClass
import org.jsoup.helper.Validate; //导入方法依赖的package包/类
/**
Add a class name to this element's {@code class} attribute.
@param className class name to add
@return this element
*/
public Element addClass(String className) {
Validate.notNull(className);
Set<String> classes = classNames();
classes.add(className);
classNames(classes);
return this;
}
示例7: XmlDeclaration
import org.jsoup.helper.Validate; //导入方法依赖的package包/类
/**
Create a new XML declaration
@param name of declaration
@param baseUri base uri
@param isProcessingInstruction is processing instruction
*/
public XmlDeclaration(String name, String baseUri, boolean isProcessingInstruction) {
super(baseUri);
Validate.notNull(name);
this.name = name;
this.isProcessingInstruction = isProcessingInstruction;
}
示例8: anchor
import org.jsoup.helper.Validate; //导入方法依赖的package包/类
/**
Add allowed URL protocols for an element's URL attribute. This restricts the possible values of the attribute to
URLs with the defined protocol.
<p>
E.g.: <code>addProtocols("a", "href", "ftp", "http", "https")</code>
</p>
<p>
To allow a link to an in-page URL anchor (i.e. <code><a href="#anchor"></code>, add a <code>#</code>:<br>
E.g.: <code>addProtocols("a", "href", "#")</code>
</p>
@param tag Tag the URL protocol is for
@param key Attribute key
@param protocols List of valid protocols
@return this, for chaining
*/
public Whitelist addProtocols(String tag, String key, String... protocols) {
Validate.notEmpty(tag);
Validate.notEmpty(key);
Validate.notNull(protocols);
TagName tagName = TagName.valueOf(tag);
AttributeKey attrKey = AttributeKey.valueOf(key);
Map<AttributeKey, Set<Protocol>> attrMap;
Set<Protocol> protSet;
if (this.protocols.containsKey(tagName)) {
attrMap = this.protocols.get(tagName);
} else {
attrMap = new HashMap<AttributeKey, Set<Protocol>>();
this.protocols.put(tagName, attrMap);
}
if (attrMap.containsKey(attrKey)) {
protSet = attrMap.get(attrKey);
} else {
protSet = new HashSet<Protocol>();
attrMap.put(attrKey, protSet);
}
for (String protocol : protocols) {
Validate.notEmpty(protocol);
Protocol prot = Protocol.valueOf(protocol);
protSet.add(prot);
}
return this;
}
示例9: removeProtocols
import org.jsoup.helper.Validate; //导入方法依赖的package包/类
/**
Remove allowed URL protocols for an element's URL attribute.
<p>
E.g.: <code>removeProtocols("a", "href", "ftp")</code>
</p>
@param tag Tag the URL protocol is for
@param key Attribute key
@param protocols List of invalid protocols
@return this, for chaining
*/
public Whitelist removeProtocols(String tag, String key, String... protocols) {
Validate.notEmpty(tag);
Validate.notEmpty(key);
Validate.notNull(protocols);
TagName tagName = TagName.valueOf(tag);
AttributeKey attrKey = AttributeKey.valueOf(key);
if(this.protocols.containsKey(tagName)) {
Map<AttributeKey, Set<Protocol>> attrMap = this.protocols.get(tagName);
if(attrMap.containsKey(attrKey)) {
Set<Protocol> protSet = attrMap.get(attrKey);
for (String protocol : protocols) {
Validate.notEmpty(protocol);
Protocol prot = Protocol.valueOf(protocol);
protSet.remove(prot);
}
if(protSet.isEmpty()) { // Remove protocol set if empty
attrMap.remove(attrKey);
if(attrMap.isEmpty()) // Remove entry for tag if empty
this.protocols.remove(tagName);
}
}
}
return this;
}
示例10: nextElementSibling
import org.jsoup.helper.Validate; //导入方法依赖的package包/类
/**
* Gets the next sibling element of this element. E.g., if a {@code div} contains two {@code p}s,
* the {@code nextElementSibling} of the first {@code p} is the second {@code p}.
* <p>
* This is similar to {@link #nextSibling()}, but specifically finds only Elements
* </p>
* @return the next element, or null if there is no next element
* @see #previousElementSibling()
*/
public Element nextElementSibling() {
if (parentNode == null) return null;
List<Element> siblings = parent().children();
Integer index = indexInList(this, siblings);
Validate.notNull(index);
if (siblings.size() > index+1)
return siblings.get(index+1);
else
return null;
}
示例11: previousElementSibling
import org.jsoup.helper.Validate; //导入方法依赖的package包/类
/**
* Gets the previous element sibling of this element.
* @return the previous element, or null if there is no previous element
* @see #nextElementSibling()
*/
public Element previousElementSibling() {
if (parentNode == null) return null;
List<Element> siblings = parent().children();
Integer index = indexInList(this, siblings);
Validate.notNull(index);
if (index > 0)
return siblings.get(index-1);
else
return null;
}
示例12: reconstructFormattingElements
import org.jsoup.helper.Validate; //导入方法依赖的package包/类
void reconstructFormattingElements() {
Element last = lastFormattingElement();
if (last == null || onStack(last))
return;
Element entry = last;
int size = formattingElements.size();
int pos = size - 1;
boolean skip = false;
while (true) {
if (pos == 0) { // step 4. if none before, skip to 8
skip = true;
break;
}
entry = formattingElements.get(--pos); // step 5. one earlier than entry
if (entry == null || onStack(entry)) // step 6 - neither marker nor on stack
break; // jump to 8, else continue back to 4
}
while(true) {
if (!skip) // step 7: on later than entry
entry = formattingElements.get(++pos);
Validate.notNull(entry); // should not occur, as we break at last element
// 8. create new element from element, 9 insert into current node, onto stack
skip = false; // can only skip increment from 4.
Element newEl = insertStartTag(entry.nodeName()); // todo: avoid fostering here?
// newEl.namespace(entry.namespace()); // todo: namespaces
newEl.attributes().addAll(entry.attributes());
// 10. replace entry with new entry
formattingElements.set(pos, newEl);
// 11
if (pos == size-1) // if not last entry in list, jump to 7
break;
}
}
示例13: replaceChild
import org.jsoup.helper.Validate; //导入方法依赖的package包/类
protected void replaceChild(Node out, Node in) {
Validate.isTrue(out.parentNode == this);
Validate.notNull(in);
if (in.parentNode != null)
in.parentNode.removeChild(in);
final int index = out.siblingIndex;
childNodes.set(index, in);
in.parentNode = this;
in.setSiblingIndex(index);
out.parentNode = null;
}
示例14: before
import org.jsoup.helper.Validate; //导入方法依赖的package包/类
/**
* Insert the specified node into the DOM before this node (i.e. as a preceding sibling).
* @param node to add before this node
* @return this node, for chaining
* @see #after(Node)
*/
public Node before(Node node) {
Validate.notNull(node);
Validate.notNull(parentNode);
parentNode.addChildren(siblingIndex, node);
return this;
}
示例15: setValue
import org.jsoup.helper.Validate; //导入方法依赖的package包/类
/**
Set the attribute value.
@param value the new attribute value; must not be null
*/
public String setValue(String value) {
Validate.notNull(value);
String old = this.value;
this.value = value;
return old;
}