Search in sources :

Example 11 with Element

use of net.htmlparser.jericho.Element in project CFLint by cflint.

the class CFLint method checkForDisabled.

/*
     * Check for <!--- CFLINT-DISABLE ---> in the tag hierarchy
     */
protected boolean checkForDisabled(final Element element, final String msgcode) {
    Element elem = element;
    while (elem != null) {
        final Element prevSibling = getPreviousSibling(elem);
        if (prevSibling != null && prevSibling.getName().equals("!---")) {
            final Pattern p = Pattern.compile(".*---\\s*CFLINT-DISABLE\\s+(.*)\\s*---.*");
            final Matcher m = p.matcher(prevSibling.toString().toUpperCase().trim());
            if (m.matches()) {
                // No message codes in CFLINT-DISABLE
                if (m.group(1).trim().length() == 0) {
                    if (verbose) {
                        System.out.println("Skipping disabled " + msgcode);
                    }
                    return true;
                }
                // check for matching message codes in CFLINT-DISABLE
                for (String skipcode : m.group(1).split(",")) {
                    skipcode = skipcode.trim();
                    if (msgcode.equals(skipcode)) {
                        if (verbose) {
                            System.out.println("Skipping disabled " + msgcode);
                        }
                        return true;
                    }
                }
            }
        }
        elem = elem.getParentElement();
    }
    return false;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) Element(net.htmlparser.jericho.Element)

Example 12 with Element

use of net.htmlparser.jericho.Element in project CFLint by cflint.

the class CFLint method processStack.

public void processStack(final List<Element> elements, final String space, final Context context) throws ParseException, IOException {
    Element commentElement = null;
    for (final Element elem : elements) {
        if (elem.getName().equals("!---")) {
            commentElement = elem;
        } else {
            final Context subContext = context.subContext(elem);
            if (commentElement != null) {
                applyRuleOverrides(subContext, commentElement);
                commentElement = null;
            }
            process(elem, space, subContext);
        }
    }
}
Also used : Context(com.cflint.plugins.Context) Element(net.htmlparser.jericho.Element)

Aggregations

Element (net.htmlparser.jericho.Element)12 Context (com.cflint.plugins.Context)4 ArrayList (java.util.ArrayList)3 Matcher (java.util.regex.Matcher)3 Source (net.htmlparser.jericho.Source)3 CFScriptStatement (cfml.parsing.cfscript.script.CFScriptStatement)2 Attribute (net.htmlparser.jericho.Attribute)2 CFMLSource (cfml.parsing.CFMLSource)1 ParserTag (cfml.parsing.ParserTag)1 CFExpression (cfml.parsing.cfscript.CFExpression)1 CFIdentifier (cfml.parsing.cfscript.CFIdentifier)1 CFCase (cfml.parsing.cfscript.script.CFCase)1 CFCatchStatement (cfml.parsing.cfscript.script.CFCatchStatement)1 CFCompDeclStatement (cfml.parsing.cfscript.script.CFCompDeclStatement)1 CFCompoundStatement (cfml.parsing.cfscript.script.CFCompoundStatement)1 CFExpressionStatement (cfml.parsing.cfscript.script.CFExpressionStatement)1 CFForInStatement (cfml.parsing.cfscript.script.CFForInStatement)1 CFForStatement (cfml.parsing.cfscript.script.CFForStatement)1 CFFuncDeclStatement (cfml.parsing.cfscript.script.CFFuncDeclStatement)1 CFFunctionParameter (cfml.parsing.cfscript.script.CFFunctionParameter)1