当前位置: 首页>>代码示例>>Java>>正文


Java Validate.isTrue方法代码示例

本文整理汇总了Java中org.jsoup.helper.Validate.isTrue方法的典型用法代码示例。如果您正苦于以下问题:Java Validate.isTrue方法的具体用法?Java Validate.isTrue怎么用?Java Validate.isTrue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jsoup.helper.Validate的用法示例。


在下文中一共展示了Validate.isTrue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: this

import org.jsoup.helper.Validate; //导入方法依赖的package包/类
/**
 Add a list of allowed attributes to a tag. (If an attribute is not allowed on an element, it will be removed.)
 <p>
 E.g.: <code>addAttributes("a", "href", "class")</code> allows <code>href</code> and <code>class</code> attributes
 on <code>a</code> tags.
 </p>
 <p>
 To make an attribute valid for <b>all tags</b>, use the pseudo tag <code>:all</code>, e.g.
 <code>addAttributes(":all", "class")</code>.
 </p>

 @param tag  The tag the attributes are for. The tag will be added to the allowed tag list if necessary.
 @param keys List of valid attributes for the tag
 @return this (for chaining)
 */
public Whitelist addAttributes(String tag, String... keys) {
    Validate.notEmpty(tag);
    Validate.notNull(keys);
    Validate.isTrue(keys.length > 0, "No attributes supplied.");

    TagName tagName = TagName.valueOf(tag);
    if (!tagNames.contains(tagName))
        tagNames.add(tagName);
    Set<AttributeKey> attributeSet = new HashSet<AttributeKey>();
    for (String key : keys) {
        Validate.notEmpty(key);
        attributeSet.add(AttributeKey.valueOf(key));
    }
    if (attributes.containsKey(tagName)) {
        Set<AttributeKey> currentSet = attributes.get(tagName);
        currentSet.addAll(attributeSet);
    } else {
        attributes.put(tagName, attributeSet);
    }
    return this;
}
 
开发者ID:cpusoft,项目名称:common,代码行数:37,代码来源:Whitelist.java

示例2: functionRegex

import org.jsoup.helper.Validate; //导入方法依赖的package包/类
private void functionRegex(String remainder) {
    Validate.isTrue(remainder.endsWith(")"), "Unclosed bracket for function! " + remainder);
    List<String> params = XTokenQueue.trimQuotes(XTokenQueue.parseFuncionParams(remainder.substring("regex(".length(), remainder.length() - 1)));
    if (params.size() == 1) {
        elementOperator = new ElementOperator.Regex(params.get(0));
    } else if (params.size() == 2) {
        if (params.get(0).startsWith("@")) {
            elementOperator = new ElementOperator.Regex(params.get(1), params.get(0).substring(1));
        } else {
            elementOperator = new ElementOperator.Regex(params.get(0), null, Integer.parseInt(params.get(1)));
        }
    } else if (params.size() == 3) {
        elementOperator = new ElementOperator.Regex(params.get(1), params.get(0).substring(1), Integer.parseInt(params.get(2)));
    } else {
        throw new Selector.SelectorParseException("Unknown usage for regex()" + remainder);
    }
}
 
开发者ID:zongtui,项目名称:zongtui-webcrawler,代码行数:18,代码来源:XPathParser.java

示例3: trimQuotes

import org.jsoup.helper.Validate; //导入方法依赖的package包/类
public static String trimQuotes(String str) {
    Validate.isTrue(str != null && str.length() > 0);
    String quote = str.substring(0, 1);
    if (StringUtil.in(quote, "\"", "'")) {
        Validate.isTrue(str.endsWith(quote), "Quote" + " for " + str + " is incomplete!");
        str = str.substring(1, str.length() - 1);
    }
    return str;
}
 
开发者ID:zongtui,项目名称:zongtui-webcrawler,代码行数:10,代码来源:XTokenQueue.java

示例4: insertChildren

import org.jsoup.helper.Validate; //导入方法依赖的package包/类
/**
 * Inserts the given child nodes into this element at the specified index. Current nodes will be shifted to the
 * right. The inserted nodes will be moved from their current parent. To prevent moving, copy the nodes first.
 *
 * @param index 0-based index to insert children at. Specify {@code 0} to insert at the start, {@code -1} at the
 * end
 * @param children child nodes to insert
 * @return this element, for chaining.
 */
public Element insertChildren(int index, Collection<? extends Node> children) {
    Validate.notNull(children, "Children collection to be inserted must not be null.");
    int currentSize = childNodeSize();
    if (index < 0) index += currentSize +1; // roll around
    Validate.isTrue(index >= 0 && index <= currentSize, "Insert position out of bounds.");

    ArrayList<Node> nodes = new ArrayList<Node>(children);
    Node[] nodeArray = nodes.toArray(new Node[nodes.size()]);
    addChildren(index, nodeArray);
    return this;
}
 
开发者ID:cpusoft,项目名称:common,代码行数:21,代码来源:Element.java

示例5: 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;
}
 
开发者ID:cpusoft,项目名称:common,代码行数:13,代码来源:Node.java

示例6: removeChild

import org.jsoup.helper.Validate; //导入方法依赖的package包/类
protected void removeChild(Node out) {
    Validate.isTrue(out.parentNode == this);
    final int index = out.siblingIndex;
    childNodes.remove(index);
    reindexChildren(index);
    out.parentNode = null;
}
 
开发者ID:cpusoft,项目名称:common,代码行数:8,代码来源:Node.java

示例7: splitText

import org.jsoup.helper.Validate; //导入方法依赖的package包/类
/**
 * Split this text node into two nodes at the specified string offset. After splitting, this node will contain the
 * original text up to the offset, and will have a new text node sibling containing the text after the offset.
 * @param offset string offset point to split node at.
 * @return the newly created text node containing the text after the offset.
 */
public TextNode splitText(int offset) {
    Validate.isTrue(offset >= 0, "Split offset must be not be negative");
    Validate.isTrue(offset < text.length(), "Split offset must not be greater than current text length");

    String head = getWholeText().substring(0, offset);
    String tail = getWholeText().substring(offset);
    text(head);
    TextNode tailNode = new TextNode(tail, this.baseUri());
    if (parent() != null)
        parent().addChildren(siblingIndex()+1, tailNode);

    return tailNode;
}
 
开发者ID:cpusoft,项目名称:common,代码行数:20,代码来源:TextNode.java

示例8: consumeToUnescaped

import org.jsoup.helper.Validate; //导入方法依赖的package包/类
public String consumeToUnescaped(String str) {
    String s = consumeToAny(str);
    if (s.length() > 0 && s.charAt(s.length() - 1) == '\\') {
        s += consume();
        s += consumeToUnescaped(str);
    }
    Validate.isTrue(pos < queue.length(), "Unclosed quotes! " + queue);
    return s;
}
 
开发者ID:zongtui,项目名称:zongtui-webcrawler,代码行数:10,代码来源:XTokenQueue.java

示例9: createMessage

import org.jsoup.helper.Validate; //导入方法依赖的package包/类
public static ChatMessageImpl createMessage(Chat chat, ParticipantImpl user, String id, String clientId, long time, Message message, SkypeImpl skype) throws ConnectionException {
    Validate.notNull(chat, "Chat must not be null");
    Validate.isTrue(chat instanceof ChatImpl, "Chat must be instanceof ChatImpl");
    Validate.notNull(user, "User must not be null");

    if (("8:" + chat.getClient().getUsername()).equals(user.getId())) {
        return new SentMessageImpl(chat, user, id, clientId, time, message, skype);
    } else {
        return new ReceivedMessageImpl(chat, user, id, clientId, time, message, skype);
    }
}
 
开发者ID:samczsun,项目名称:Skype4J,代码行数:12,代码来源:Factory.java

示例10: joinChat

import org.jsoup.helper.Validate; //导入方法依赖的package包/类
@Override
public GroupChat joinChat(String id) throws ConnectionException, ChatNotFoundException, NoPermissionException {
    Validate.isTrue(id.startsWith("19:") && id.endsWith("@thread.skype"), "Invalid chat id");
    JsonObject obj = new JsonObject();
    obj.add("role", "User");
    Endpoints.ADD_MEMBER_URL.open(this, id, getUsername()).on(403, (connection) -> {
        throw new NoPermissionException();
    }).on(404, (connection) -> {
        throw new ChatNotFoundException();
    }).expect(200, "While joining chat").put(obj);
    return (GroupChat) getOrLoadChat(id);
}
 
开发者ID:samczsun,项目名称:Skype4J,代码行数:13,代码来源:SkypeImpl.java

示例11: consumeIndex

import org.jsoup.helper.Validate; //导入方法依赖的package包/类
private int consumeIndex() {
    String indexS = tq.chompTo(")").trim();
    Validate.isTrue(StringUtil.isNumeric(indexS), "Index must be numeric");
    return Integer.parseInt(indexS);
}
 
开发者ID:virjar,项目名称:sipsoup,代码行数:6,代码来源:CacheCSSFunction.java

示例12: insertOnStackAfter

import org.jsoup.helper.Validate; //导入方法依赖的package包/类
void insertOnStackAfter(Element after, Element in) {
    int i = stack.lastIndexOf(after);
    Validate.isTrue(i != -1);
    stack.add(i+1, in);
}
 
开发者ID:cpusoft,项目名称:common,代码行数:6,代码来源:HtmlTreeBuilder.java

示例13: replaceInQueue

import org.jsoup.helper.Validate; //导入方法依赖的package包/类
private void replaceInQueue(ArrayList<Element> queue, Element out, Element in) {
    int i = queue.lastIndexOf(out);
    Validate.isTrue(i != -1);
    queue.set(i, in);
}
 
开发者ID:cpusoft,项目名称:common,代码行数:6,代码来源:HtmlTreeBuilder.java

示例14: call

import org.jsoup.helper.Validate; //导入方法依赖的package包/类
@Override
public Evaluator call(String... param) {
    Validate.isTrue(param.length == 2, String.format("Error argument of %s", "contains"));
    return new Evaluator.AttributeWithValueContaining(param[0], param[1]);
}
 
开发者ID:zongtui,项目名称:zongtui-webcrawler,代码行数:6,代码来源:XPathParser.java

示例15: unConsume

import org.jsoup.helper.Validate; //导入方法依赖的package包/类
public void unConsume(int length) {
    Validate.isTrue(length <= pos, "length " + length + " is larger than consumed chars " + pos);
    pos -= length;
}
 
开发者ID:zongtui,项目名称:zongtui-webcrawler,代码行数:5,代码来源:XTokenQueue.java


注:本文中的org.jsoup.helper.Validate.isTrue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。