Search in sources :

Example 1 with Attribute

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

the class TemplateParser method processElementAttributes.

/**
 * Process an {@link Element} and check for vue attributes.
 * @param element Current element being processed
 */
private void processElementAttributes(Element element) {
    Optional<LocalComponent> localComponent = getLocalComponentForElement(element);
    // Iterate on element attributes
    Set<LocalComponentProp> foundProps = new HashSet<>();
    for (Attribute attribute : element.getAttributes()) {
        if ("v-for".equals(attribute.getKey()) || "v-model".equals(attribute.getKey()))
            continue;
        Optional<LocalComponentProp> optionalProp = localComponent.flatMap(lc -> lc.getPropForAttribute(attribute.getName()));
        optionalProp.ifPresent(foundProps::add);
        if (!VUE_ATTR_PATTERN.matcher(attribute.getKey()).matches()) {
            optionalProp.ifPresent(this::validateStringPropBinding);
            continue;
        }
        context.setCurrentSegment(attribute);
        currentAttribute = attribute;
        currentProp = optionalProp.orElse(null);
        currentExpressionReturnType = getExpressionReturnTypeForAttribute(attribute);
        String processedExpression = processExpression(attribute.getValue());
        if (attribute.getValueSegment() != null)
            outputDocument.replace(attribute.getValueSegment(), processedExpression);
    }
    localComponent.ifPresent(lc -> validateRequiredProps(lc, foundProps));
}
Also used : LocalComponentProp(com.axellience.vuegwt.processors.component.template.parser.context.localcomponents.LocalComponentProp) Attribute(net.htmlparser.jericho.Attribute) LocalComponent(com.axellience.vuegwt.processors.component.template.parser.context.localcomponents.LocalComponent) HashSet(java.util.HashSet)

Example 2 with Attribute

use of net.htmlparser.jericho.Attribute in project zaproxy by zaproxy.

the class HtmlContextAnalyser method getHtmlContexts.

public List<HtmlContext> getHtmlContexts(String target, HtmlContext targetContext, int ignoreFlags) {
    List<HtmlContext> contexts = new ArrayList<>();
    int offset = 0;
    while ((offset = htmlPage.indexOf(target, offset)) >= 0) {
        HtmlContext context = new HtmlContext(this.msg, target, offset, offset + target.length());
        offset += target.length();
        // Is it in quotes?
        char leftQuote = 0;
        for (int i = context.getStart() - 1; i > 0; i--) {
            char chr = htmlPage.charAt(i);
            if (isQuote(chr)) {
                leftQuote = chr;
                break;
            } else if (chr == '>') {
                // end of another tag
                break;
            }
        }
        if (leftQuote != 0) {
            for (int i = context.getEnd(); i < htmlPage.length(); i++) {
                char chr = htmlPage.charAt(i);
                if (leftQuote == chr) {
                    // matching quote
                    context.setSurroundingQuote("" + leftQuote);
                    break;
                } else if (isQuote(chr)) {
                    // Another non matching quote
                    break;
                } else if (chr == '<') {
                    // start of another tag
                    break;
                }
            }
        }
        // is it in an HTML comment?
        String prefix = htmlPage.substring(0, context.getStart());
        if (prefix.lastIndexOf("<!--") > prefix.lastIndexOf(">")) {
            // Also check closing comment?
            context.setHtmlComment(true);
        }
        // Work out the location in the DOM
        Element element = src.getEnclosingElement(context.getStart());
        if (element != null) {
            // See if its in an attribute
            boolean isInputTag = element.getName().equalsIgnoreCase(// Special case for input src attributes
            "input");
            boolean isImageInputTag = false;
            Iterator<Attribute> iter = element.getAttributes().iterator();
            while (iter.hasNext()) {
                Attribute att = iter.next();
                if (att.getValue() != null && att.getValue().toLowerCase().indexOf(target.toLowerCase()) >= 0) {
                    // Found the injected value
                    context.setTagAttribute(att.getName());
                    context.setInUrlAttribute(this.isUrlAttribute(att.getName()));
                    context.setInScriptAttribute(this.isScriptAttribute(att.getName()));
                }
                if (isInputTag && att.getName().equalsIgnoreCase("type") && "image".equalsIgnoreCase(att.getValue())) {
                    isImageInputTag = true;
                }
            }
            // record the tag hierarchy
            context.addParentTag(element.getName());
            if (!isInputTag || isImageInputTag) {
                // Input tags only use the src attribute if the type is 'image'
                context.setInTagWithSrc(this.isInTagWithSrcAttribute(element.getName()));
            }
            while ((element = element.getParentElement()) != null) {
                context.addParentTag(element.getName());
            }
        }
        if (targetContext == null) {
            // Always add
            contexts.add(context);
        } else if (targetContext.matches(context, ignoreFlags)) {
            // Matches the supplied context
            contexts.add(context);
        }
    }
    return contexts;
}
Also used : Attribute(net.htmlparser.jericho.Attribute) Element(net.htmlparser.jericho.Element) ArrayList(java.util.ArrayList)

Example 3 with Attribute

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

the class CFDebugAttributeChecker method element.

@Override
public void element(final Element element, final Context context, final BugList bugs) {
    final Attributes attributes = element.getAttributes();
    if (attributes == null) {
        return;
    }
    final Attribute debugAttr = attributes.get(CF.DEBUG);
    if (debugAttr != null) {
        if (!debugAttr.hasValue() || (!debugAttr.getValue().equalsIgnoreCase("no") && !debugAttr.getValue().equalsIgnoreCase("false")))
            context.addMessage("AVOID_USING_DEBUG_ATTR", null);
    }
    if (element.getName().equalsIgnoreCase(CF.CFSETTING)) {
        final Attribute showDebugOutputAttr = element.getAttributes().get("showDebugOutput");
        if (showDebugOutputAttr != null) {
            if ("Yes".equalsIgnoreCase(showDebugOutputAttr.getValue()) || "true".equalsIgnoreCase(showDebugOutputAttr.getValue())) {
                context.addMessage("AVOID_USING_CFSETTING_DEBUG", null);
            }
        }
    }
}
Also used : Attribute(net.htmlparser.jericho.Attribute) Attributes(net.htmlparser.jericho.Attributes)

Example 4 with Attribute

use of net.htmlparser.jericho.Attribute in project liferay-ide by liferay.

the class AdminUtil method getKBArticleDiff.

public static String getKBArticleDiff(long resourcePrimKey, int sourceVersion, int targetVersion, String param) throws Exception {
    if (sourceVersion < KBArticleConstants.DEFAULT_VERSION) {
        sourceVersion = KBArticleConstants.DEFAULT_VERSION;
    }
    if (sourceVersion == targetVersion) {
        KBArticle kbArticle = KBArticleLocalServiceUtil.getKBArticle(resourcePrimKey, targetVersion);
        return BeanPropertiesUtil.getString(kbArticle, param);
    }
    KBArticle sourceKBArticle = KBArticleLocalServiceUtil.getKBArticle(resourcePrimKey, sourceVersion);
    KBArticle targetKBArticle = KBArticleLocalServiceUtil.getKBArticle(resourcePrimKey, targetVersion);
    String sourceHtml = BeanPropertiesUtil.getString(sourceKBArticle, param);
    String targetHtml = BeanPropertiesUtil.getString(targetKBArticle, param);
    String diff = DiffHtmlUtil.diff(new UnsyncStringReader(sourceHtml), new UnsyncStringReader(targetHtml));
    Source source = new Source(diff);
    OutputDocument outputDocument = new OutputDocument(source);
    for (Element element : source.getAllElements()) {
        StringBundler sb = new StringBundler(4);
        Attributes attributes = element.getAttributes();
        if (attributes == null) {
            continue;
        }
        Attribute changeTypeAttribute = attributes.get("changeType");
        if (changeTypeAttribute != null) {
            String changeTypeValue = changeTypeAttribute.getValue();
            if (changeTypeValue.contains("diff-added-image")) {
                sb.append("border: 10px solid #CFC; ");
            } else if (changeTypeValue.contains("diff-changed-image")) {
                sb.append("border: 10px solid #C6C6FD; ");
            } else if (changeTypeValue.contains("diff-removed-image")) {
                sb.append("border: 10px solid #FDC6C6; ");
            }
        }
        Attribute classAttribute = attributes.get("class");
        if (classAttribute != null) {
            String classValue = classAttribute.getValue();
            if (classValue.contains("diff-html-added")) {
                sb.append("background-color: #CFC; ");
            } else if (classValue.contains("diff-html-changed")) {
                sb.append("background-color: #C6C6FD; ");
            } else if (classValue.contains("diff-html-removed")) {
                sb.append("background-color: #FDC6C6; ");
                sb.append("text-decoration: line-through; ");
            }
        }
        if (Validator.isNull(sb.toString())) {
            continue;
        }
        Attribute styleAttribute = attributes.get("style");
        if (styleAttribute != null) {
            sb.append(GetterUtil.getString(styleAttribute.getValue()));
        }
        Map<String, String> map = outputDocument.replace(attributes, false);
        map.put("style", sb.toString());
    }
    return outputDocument.toString();
}
Also used : KBArticle(com.liferay.knowledgebase.model.KBArticle) Attribute(net.htmlparser.jericho.Attribute) UnsyncStringReader(com.liferay.portal.kernel.io.unsync.UnsyncStringReader) OutputDocument(net.htmlparser.jericho.OutputDocument) Element(net.htmlparser.jericho.Element) Attributes(net.htmlparser.jericho.Attributes) Source(net.htmlparser.jericho.Source) StringBundler(com.liferay.portal.kernel.util.StringBundler)

Example 5 with Attribute

use of net.htmlparser.jericho.Attribute in project knox by apache.

the class HtmlFilterReaderBase method processStartTag.

private void processStartTag(StartTag tag) {
    if ("<".equals(tag.getTagType().getStartDelimiter())) {
        Element e = document.createElement(tag.getNameSegment().toString());
        stack.push(new Level(tag));
        writer.write("<");
        writer.write(tag.getNameSegment().toString());
        Attributes attributes = tag.getAttributes();
        if (!attributes.isEmpty()) {
            for (Attribute attribute : attributes) {
                processAttribute(attribute);
            }
        }
        if (tag.toString().trim().endsWith("/>") || tag.isEmptyElementTag()) {
            stack.pop();
            writer.write("/>");
        } else {
            writer.write(">");
        }
    } else {
        writer.write(tag.toString());
    }
}
Also used : Attribute(net.htmlparser.jericho.Attribute) Element(org.w3c.dom.Element) Attributes(net.htmlparser.jericho.Attributes)

Aggregations

Attribute (net.htmlparser.jericho.Attribute)9 Attributes (net.htmlparser.jericho.Attributes)4 Element (net.htmlparser.jericho.Element)4 Source (net.htmlparser.jericho.Source)3 LocalComponent (com.axellience.vuegwt.processors.component.template.parser.context.localcomponents.LocalComponent)2 LocalComponentProp (com.axellience.vuegwt.processors.component.template.parser.context.localcomponents.LocalComponentProp)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 OutputDocument (net.htmlparser.jericho.OutputDocument)2 CFExpression (cfml.parsing.cfscript.CFExpression)1 ArrayErrorListener (cfml.parsing.reporting.ArrayErrorListener)1 ParseException (cfml.parsing.reporting.ParseException)1 Prop (com.axellience.vuegwt.core.annotations.component.Prop)1 TemplateParserContext (com.axellience.vuegwt.processors.component.template.parser.context.TemplateParserContext)1 TemplateParserLoggerProvider (com.axellience.vuegwt.processors.component.template.parser.jericho.TemplateParserLoggerProvider)1 TemplateExpression (com.axellience.vuegwt.processors.component.template.parser.result.TemplateExpression)1 TemplateParserResult (com.axellience.vuegwt.processors.component.template.parser.result.TemplateParserResult)1 LocalVariableInfo (com.axellience.vuegwt.processors.component.template.parser.variable.LocalVariableInfo)1 VariableInfo (com.axellience.vuegwt.processors.component.template.parser.variable.VariableInfo)1 GeneratorsNameUtil.propNameToAttributeName (com.axellience.vuegwt.processors.utils.GeneratorsNameUtil.propNameToAttributeName)1