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

info.bliki.wiki.tags.extension.ChartTag Maven / Gradle / Ivy

The newest version!
package info.bliki.wiki.tags.extension;

import info.bliki.htmlcleaner.TagNode;
import info.bliki.htmlcleaner.Utils;
import info.bliki.wiki.filter.ITextConverter;
import info.bliki.wiki.model.IWikiModel;
import info.bliki.wiki.tags.HTMLTag;
import info.bliki.wiki.tags.util.INoBodyParsingTag;

import java.io.IOException;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * Wiki tag for the Google Chart
 * API
 *
 */
public class ChartTag extends HTMLTag implements INoBodyParsingTag {
    final static public HashSet ALLOWED_ATTRIBUTES_SET = new HashSet<>(997);

    /**
     * See chart
     * parameters supported by the Google Chart API.
     */
    final static public String[] ALLOWED_ATTRIBUTES = { "alt", "chbh", "chco", "chd", "chdl", "chdlp", "chds", "chem", "chf", "chfd",
            "chg", "chl", "chld", "chls", "chm", "chma", "choe", "chof", "chp", "chs", "chst", "cht", "chtm", "chtt", "chts", "chxt",
            "chxr", "chxl", "chxp", "chxs", "chxtc" };

    static {
        for (int i = 0; i < ALLOWED_ATTRIBUTES.length; i++) {
            ALLOWED_ATTRIBUTES_SET.add(ALLOWED_ATTRIBUTES[i]);
        }
    }

    public ChartTag() {
        super("chart");
    }

    @Override
    public void renderHTML(ITextConverter converter, Appendable buf, IWikiModel model) throws IOException {

        TagNode node = this;
        StringBuilder chartUrl = new StringBuilder(100);
        Map tagAtttributes = node.getAttributes();
        Set keysSet = tagAtttributes.keySet();
        for (String str : keysSet) {
            if (str.equals("alt")) {
                continue;
            }
            Utils.appendAmpersandEscapedAttribute(chartUrl, str, tagAtttributes);
        }

        buf.append("\"");");
    }

    @Override
    public boolean isAllowedAttribute(String attName) {
        return ALLOWED_ATTRIBUTES_SET.contains(attName);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy