Search in sources :

Example 31 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
 *
 * @param element
 *            The element to process
 * @param msgcode
 *            The message code to check for
 * @return true if the msgcode is disabled for the given element.
 */
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(CF.COMMENT)) {
            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 32 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 CFLintScanException {
    Element commentElement = null;
    for (final Element elem : elements) {
        if (elem.getName().equals(CF.COMMENT)) {
            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)

Example 33 with Element

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

the class CFLint method process.

public void process(final String src, final String filename) throws CFLintScanException {
    try {
        fireStartedProcessing(filename);
        lineOffsets = null;
        if (src == null || src.trim().length() == 0) {
            final Context context = new Context(filename, null, null, false, handler, configuration);
            reportRule(null, null, context, null, new ContextMessage(AVOID_EMPTY_FILES, null));
        } else {
            lineOffsets = getLineOffsets(src.split("\n"));
            final CFMLSource cfmlSource = new CFMLSource(src.contains("<!---") ? CommentReformatting.wrap(src) : src);
            final ParserTag firstTag = getFirstTagQuietly(cfmlSource);
            final List<Element> elements = new ArrayList<>();
            if (firstTag != null) {
                elements.addAll(cfmlSource.getChildElements());
            }
            if (isComponentOrInterfaceScript(src, elements)) {
                // Check if pure cfscript
                final CFScriptStatement scriptStatement = cfmlParser.parseScript(src);
                final Context context = new Context(filename, null, null, false, handler, scriptStatement == null ? null : scriptStatement.getTokens(), configuration);
                process(scriptStatement, context);
            } else {
                processStack(elements, " ", filename, null);
            }
        }
        fireFinishedProcessing(filename);
    } catch (final Exception e) {
        throw new CFLintScanException(e);
    }
}
Also used : Context(com.cflint.plugins.Context) ContextMessage(com.cflint.plugins.Context.ContextMessage) CFMLSource(cfml.parsing.CFMLSource) CFScriptStatement(cfml.parsing.cfscript.script.CFScriptStatement) CFLintScanException(com.cflint.exception.CFLintScanException) ParserTag(cfml.parsing.ParserTag) Element(net.htmlparser.jericho.Element) ArrayList(java.util.ArrayList) ParseException(cfml.parsing.reporting.ParseException) IOException(java.io.IOException) CFLintScanException(com.cflint.exception.CFLintScanException)

Example 34 with Element

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

the class QueryParamChecker method determineIgnoreLines.

/**
 * Determine the line numbers of the <!--- @CFLintIgnore CFQUERYPARAM_REQ ---> tags
 * Both the current and the next line are included.
 *
 * @param element   the element object
 * @return          the line numbers of any @@CFLintIgnore annotations.
 */
private List<Integer> determineIgnoreLines(final Element element) {
    final List<Integer> ignoreLines = new ArrayList<>();
    for (Element comment : element.getChildElements()) {
        if ("!---".equals(comment.getName()) && comment.toString().contains("@CFLintIgnore") && comment.toString().contains("CFQUERYPARAM_REQ")) {
            int ignoreLine = comment.getSource().getRow(comment.getEnd());
            ignoreLines.add(ignoreLine);
            ignoreLines.add(ignoreLine + 1);
            ignoreLines.add(comment.getSource().getRow(comment.getBegin()));
        } else {
            ignoreLines.addAll(determineIgnoreLines(comment));
        }
    }
    return ignoreLines;
}
Also used : Element(net.htmlparser.jericho.Element) ArrayList(java.util.ArrayList)

Example 35 with Element

use of net.htmlparser.jericho.Element in project vue-gwt by Axellience.

the class TemplateParser method processElement.

/**
 * Recursive method that will process the whole template DOM tree.
 * @param element Current element being processed
 */
private void processElement(Element element) {
    context.setCurrentSegment(element);
    currentProp = null;
    currentAttribute = null;
    Attributes attributes = element.getAttributes();
    Attribute vForAttribute = attributes != null ? attributes.get("v-for") : null;
    if (vForAttribute != null) {
        // Add a context layer for our v-for
        context.addContextLayer();
        // Process the v-for expression, and update our attribute
        String processedVForValue = processVForValue(vForAttribute.getValue());
        outputDocument.replace(vForAttribute.getValueSegment(), processedVForValue);
    }
    // Process the element
    if (attributes != null)
        processElementAttributes(element);
    // Process text segments
    StreamSupport.stream(((Iterable<Segment>) element::getNodeIterator).spliterator(), false).filter(segment -> !(segment instanceof Tag) && !(segment instanceof CharacterReference)).filter(segment -> {
        for (Element child : element.getChildElements()) if (child.encloses(segment))
            return false;
        return true;
    }).forEach(this::processTextNode);
    // Recurse downwards
    element.getChildElements().forEach(this::processElement);
    // After downward recursion, pop the context layer
    if (vForAttribute != null)
        context.popContextLayer();
}
Also used : Attributes(net.htmlparser.jericho.Attributes) TemplateExpression(com.axellience.vuegwt.processors.component.template.parser.result.TemplateExpression) CastExpr(com.github.javaparser.ast.expr.CastExpr) Any(jsinterop.base.Any) OutputDocument(net.htmlparser.jericho.OutputDocument) HashSet(java.util.HashSet) Matcher(java.util.regex.Matcher) Type(com.github.javaparser.ast.type.Type) GeneratorsUtil.stringTypeToTypeName(com.axellience.vuegwt.processors.utils.GeneratorsUtil.stringTypeToTypeName) Prop(com.axellience.vuegwt.core.annotations.component.Prop) VariableInfo(com.axellience.vuegwt.processors.component.template.parser.variable.VariableInfo) CharacterReference(net.htmlparser.jericho.CharacterReference) Expression(com.github.javaparser.ast.expr.Expression) StreamSupport(java.util.stream.StreamSupport) BinaryExpr(com.github.javaparser.ast.expr.BinaryExpr) Source(net.htmlparser.jericho.Source) LinkedList(java.util.LinkedList) Messager(javax.annotation.processing.Messager) NodeWithType(com.github.javaparser.ast.nodeTypes.NodeWithType) Element(net.htmlparser.jericho.Element) GeneratorsNameUtil.propNameToAttributeName(com.axellience.vuegwt.processors.utils.GeneratorsNameUtil.propNameToAttributeName) TemplateParserLoggerProvider(com.axellience.vuegwt.processors.component.template.parser.jericho.TemplateParserLoggerProvider) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr) TemplateParserResult(com.axellience.vuegwt.processors.component.template.parser.result.TemplateParserResult) Set(java.util.Set) NameExpr(com.github.javaparser.ast.expr.NameExpr) LocalComponent(com.axellience.vuegwt.processors.component.template.parser.context.localcomponents.LocalComponent) Config(net.htmlparser.jericho.Config) Collectors(java.util.stream.Collectors) LocalVariableInfo(com.axellience.vuegwt.processors.component.template.parser.variable.LocalVariableInfo) Attribute(net.htmlparser.jericho.Attribute) List(java.util.List) ParseProblemException(com.github.javaparser.ParseProblemException) Tag(net.htmlparser.jericho.Tag) TypeName(com.squareup.javapoet.TypeName) Optional(java.util.Optional) LocalComponentProp(com.axellience.vuegwt.processors.component.template.parser.context.localcomponents.LocalComponentProp) Pattern(java.util.regex.Pattern) TemplateParserContext(com.axellience.vuegwt.processors.component.template.parser.context.TemplateParserContext) Segment(net.htmlparser.jericho.Segment) JavaParser(com.github.javaparser.JavaParser) Attribute(net.htmlparser.jericho.Attribute) Element(net.htmlparser.jericho.Element) Attributes(net.htmlparser.jericho.Attributes) CharacterReference(net.htmlparser.jericho.CharacterReference) Tag(net.htmlparser.jericho.Tag)

Aggregations

Element (net.htmlparser.jericho.Element)70 Source (net.htmlparser.jericho.Source)17 DownloadService (delta.games.lotro.utils.DownloadService)11 ArrayList (java.util.ArrayList)11 Segment (net.htmlparser.jericho.Segment)6 InputSource (org.xml.sax.InputSource)6 Context (com.cflint.plugins.Context)4 Matcher (java.util.regex.Matcher)4 StartTag (net.htmlparser.jericho.StartTag)4 BasicStatsSet (delta.games.lotro.character.stats.BasicStatsSet)3 Item (delta.games.lotro.lore.items.Item)3 List (java.util.List)3 Attribute (net.htmlparser.jericho.Attribute)3 CFScriptStatement (cfml.parsing.cfscript.script.CFScriptStatement)2 ParseException (cfml.parsing.reporting.ParseException)2 CFLintScanException (com.cflint.exception.CFLintScanException)2 ContextMessage (com.cflint.plugins.Context.ContextMessage)2 Money (delta.games.lotro.common.Money)2 CraftingResult (delta.games.lotro.lore.crafting.recipes.CraftingResult)2 Ingredient (delta.games.lotro.lore.crafting.recipes.Ingredient)2