Search in sources :

Example 1 with Attributes

use of net.htmlparser.jericho.Attributes 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 2 with Attributes

use of net.htmlparser.jericho.Attributes 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 3 with Attributes

use of net.htmlparser.jericho.Attributes 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)

Example 4 with Attributes

use of net.htmlparser.jericho.Attributes 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

Attribute (net.htmlparser.jericho.Attribute)4 Attributes (net.htmlparser.jericho.Attributes)4 Element (net.htmlparser.jericho.Element)2 OutputDocument (net.htmlparser.jericho.OutputDocument)2 Source (net.htmlparser.jericho.Source)2 Prop (com.axellience.vuegwt.core.annotations.component.Prop)1 TemplateParserContext (com.axellience.vuegwt.processors.component.template.parser.context.TemplateParserContext)1 LocalComponent (com.axellience.vuegwt.processors.component.template.parser.context.localcomponents.LocalComponent)1 LocalComponentProp (com.axellience.vuegwt.processors.component.template.parser.context.localcomponents.LocalComponentProp)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 GeneratorsUtil.stringTypeToTypeName (com.axellience.vuegwt.processors.utils.GeneratorsUtil.stringTypeToTypeName)1 JavaParser (com.github.javaparser.JavaParser)1 ParseProblemException (com.github.javaparser.ParseProblemException)1 BinaryExpr (com.github.javaparser.ast.expr.BinaryExpr)1 CastExpr (com.github.javaparser.ast.expr.CastExpr)1