All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.cflint.tools.CFTool Maven / Gradle / Ivy

Go to download

A static code analysis tool for ColdFusion (in the spirit of FindBugs and Lint). With CFLint, you are able to analyze your ColdFusion code base for code violations.

There is a newer version: 1.5.0
Show newest version
package com.cflint.tools;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import com.cflint.config.CFLintPluginInfo.PluginInfoRule.PluginMessage;

import cfml.parsing.cfscript.CFExpression;
import net.htmlparser.jericho.Element;

public class CFTool {

    public static Element getNamedParent(final Element elem, final String tagName) {
    	Element parentElem = elem.getParentElement();
        while (parentElem != null && !parentElem.getName().equals(tagName)) {
        	parentElem = parentElem.getParentElement();
        }
        return parentElem;
    }

    public static boolean toBoolean(final String value) {
        if (value == null) {
            return false;
        }
        return value.trim().equalsIgnoreCase("yes") || value.trim().equalsIgnoreCase("true");
    }

    public static Element getElementBefore(Element element, List elements) {
        if (element != null && elements != null && elements.indexOf(element) > 0) {
            return elements.get(elements.indexOf(element) - 1);
        }
        return null;
    }

    public static Map convertMap(final Map map) {
        final Map retval = new HashMap();
        for (Entry entry : map.entrySet()) {
            retval.put(entry.getKey().toString().toLowerCase(), entry.getValue());
        }
        return retval;
    }

    /*
     * Apply the configuration to the existing rule. Overlay it.
     */
    public static void merge(final PluginMessage cfgMsg, final PluginMessage msg) {
        if (!isEmpty(cfgMsg.getMessageText())) {
            msg.setMessageText(cfgMsg.getMessageText());
        }
        if (!isEmpty(cfgMsg.getSeverity())) {
            msg.setSeverity(cfgMsg.getSeverity());
        }
    }

    private static boolean isEmpty(final String messageText) {
        return messageText == null || messageText.trim().length() == 0;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy