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


Java Validate类代码示例

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


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

示例1: inSelectScope

import org.jsoup.helper.Validate; //导入依赖的package包/类
boolean inSelectScope(String targetName) {
    for (int pos = stack.size() -1; pos >= 0; pos--) {
        Element el = stack.get(pos);
        String elName = el.nodeName();
        if (elName.equals(targetName))
            return true;
        if (!StringUtil.in(elName, TagSearchSelectScope)) // all elements except
            return false;
    }
    Validate.fail("Should not be reachable");
    return false;
}
 
开发者ID:cpusoft,项目名称:common,代码行数:13,代码来源:HtmlTreeBuilder.java

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

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

示例4: process

import org.jsoup.helper.Validate; //导入依赖的package包/类
@Override
protected boolean process(Token token) {
    // start tag, end tag, doctype, comment, character, eof
    switch (token.type) {
        case StartTag:
            insert(token.asStartTag());
            break;
        case EndTag:
            popStackToClose(token.asEndTag());
            break;
        case Comment:
            insert(token.asComment());
            break;
        case Character:
            insert(token.asCharacter());
            break;
        case Doctype:
            insert(token.asDoctype());
            break;
        case EOF: // could put some normalisation here if desired
            break;
        default:
            Validate.fail("Unexpected token type: " + token.type);
    }
    return true;
}
 
开发者ID:cpusoft,项目名称:common,代码行数:27,代码来源:XmlTreeBuilder.java

示例5: emit

import org.jsoup.helper.Validate; //导入依赖的package包/类
void emit(Token token) {
    Validate.isFalse(isEmitPending, "There is an unread token pending!");

    emitPending = token;
    isEmitPending = true;

    if (token.type == Token.TokenType.StartTag) {
        Token.StartTag startTag = (Token.StartTag) token;
        lastStartTag = startTag.tagName;
        if (startTag.selfClosing)
            selfClosingFlagAcknowledged = false;
    } else if (token.type == Token.TokenType.EndTag) {
        Token.EndTag endTag = (Token.EndTag) token;
        if (endTag.attributes != null)
            error("Attributes incorrectly present on end tag");
    }
}
 
开发者ID:cpusoft,项目名称:common,代码行数:18,代码来源:Tokeniser.java

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

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

示例8: process

import org.jsoup.helper.Validate; //导入依赖的package包/类
protected boolean process(Token token) {
    switch (token.type) {
        case StartTag:
            insert(token.asStartTag());
            break;
        case EndTag:
            popStackToClose(token.asEndTag());
            break;
        case Comment:
            insert(token.asComment());
            break;
        case Character:
            insert(token.asCharacter());
            break;
        case Doctype:
            insert(token.asDoctype());
            break;
        case EOF: // could put some normalisation here if desired
            break;
        default:
            Validate.fail("Unexpected token type: " + token.type);
    }

    return true;
}
 
开发者ID:abola,项目名称:CrawlerPack,代码行数:26,代码来源:PrefixXmlTreeBuilder.java

示例9: parse

import org.jsoup.helper.Validate; //导入依赖的package包/类
public XPathEvaluator parse() {

        while (!tq.isEmpty()) {
            Validate.isFalse(noEvalAllow, "XPath error! No operator allowed after attribute or function!" + tq);
            if (tq.matchChomp(OR_COMBINATOR)) {
                tq.consumeWhitespace();
                return combineXPathEvaluator(tq.remainder());
            } else if (tq.matchesAny(HIERARCHY_COMBINATORS)) {
                combinator(tq.consumeAny(HIERARCHY_COMBINATORS));
            } else {
                findElements();
            }
            tq.consumeWhitespace();
        }
        return collectXPathEvaluator();
    }
 
开发者ID:zongtui,项目名称:zongtui-webcrawler,代码行数:17,代码来源:XPathParser.java

示例10: 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

示例11: 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

示例12: createChat

import org.jsoup.helper.Validate; //导入依赖的package包/类
public static ChatImpl createChat(SkypeImpl client, String identity) throws ConnectionException, ChatNotFoundException {
    Validate.notNull(client, "Client must not be null");
    Validate.notEmpty(identity, "Identity must not be null/empty");

    ChatImpl result = null;

    if (identity.startsWith("19:")) {
        if (identity.endsWith("@thread.skype")) {
            result = new ChatGroup(client, identity);
        } else if (identity.endsWith("@p2p.thread.skype")) {
            result = new ChatP2P(client, identity);
        }
    } else if (identity.startsWith("8:")) {
        result = new ChatIndividual(client, identity);
    } else if (identity.startsWith("28:")) {
        result = new ChatBot(client, identity);
    }

    if (result != null) {
        result.load();
        return result;
    }

    throw new IllegalArgumentException(String.format("Unknown chat type with identity %s", identity));
}
 
开发者ID:samczsun,项目名称:Skype4J,代码行数:26,代码来源:Factory.java

示例13: createParticipant

import org.jsoup.helper.Validate; //导入依赖的package包/类
public static ParticipantImpl createParticipant(SkypeImpl client, ChatImpl chat, String id) throws ConnectionException {
    Validate.notNull(client, "Client must not be null");
    Validate.notNull(chat, "Chat must not be null");
    Validate.notEmpty(id, "Identity must not be null/empty");

    ParticipantImpl result = null;

    if (id.startsWith("8:")) {
        result = new UserImpl(client, chat, id);
    } else if (id.startsWith("28:")) {
        result = new BotImpl(client, chat, id);
    }

    if (result != null) {
        return result;
    }

    throw new IllegalArgumentException(String.format("Unknown participant type with id %s", id));
}
 
开发者ID:samczsun,项目名称:Skype4J,代码行数:20,代码来源:Factory.java

示例14: byTag

import org.jsoup.helper.Validate; //导入依赖的package包/类
private void byTag() {
    String tagName = tq.consumeElementSelector();
    Validate.notEmpty(tagName);

    // namespaces: if element name is "abc:def", selector must be "abc|def", so flip:
    if (tagName.contains("|"))
        tagName = tagName.replace("|", ":");

    evals.add(new Evaluator.Tag(tagName.trim().toLowerCase()));
}
 
开发者ID:virjar,项目名称:sipsoup,代码行数:11,代码来源:CacheCSSFunction.java

示例15: byAttribute

import org.jsoup.helper.Validate; //导入依赖的package包/类
private void byAttribute() {
    TokenQueue cq = new TokenQueue(tq.chompBalanced('[', ']')); // content queue
    String key = cq.consumeToAny(AttributeEvals); // eq, not, start, end, contain, match, (no val)
    Validate.notEmpty(key);
    cq.consumeWhitespace();

    if (cq.isEmpty()) {
        if (key.startsWith("^"))
            evals.add(new Evaluator.AttributeStarting(key.substring(1)));
        else
            evals.add(new Evaluator.Attribute(key));
    } else {
        if (cq.matchChomp("="))
            evals.add(new Evaluator.AttributeWithValue(key, cq.remainder()));

        else if (cq.matchChomp("!="))
            evals.add(new Evaluator.AttributeWithValueNot(key, cq.remainder()));

        else if (cq.matchChomp("^="))
            evals.add(new Evaluator.AttributeWithValueStarting(key, cq.remainder()));

        else if (cq.matchChomp("$="))
            evals.add(new Evaluator.AttributeWithValueEnding(key, cq.remainder()));

        else if (cq.matchChomp("*="))
            evals.add(new Evaluator.AttributeWithValueContaining(key, cq.remainder()));

        else if (cq.matchChomp("~="))
            evals.add(new Evaluator.AttributeWithValueMatching(key, Pattern.compile(cq.remainder())));
        else
            throw new Selector.SelectorParseException(
                    "Could not parse attribute query '%s': unexpected token at '%s'", query, cq.remainder());
    }
}
 
开发者ID:virjar,项目名称:sipsoup,代码行数:35,代码来源:CacheCSSFunction.java


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