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;
}
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);
}
}
}
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);
}
}
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;
}
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();
}
Aggregations