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

info.bliki.wiki.template.URLEncode Maven / Gradle / Ivy

The newest version!
package info.bliki.wiki.template;

import info.bliki.wiki.model.IWikiModel;

import java.io.IOException;
import java.net.URLEncoder;
import java.util.List;

import static java.nio.charset.StandardCharsets.UTF_8;

/**
 * A template parser function for {{urlencode: ... }} syntax
 *
 */
public class URLEncode extends AbstractTemplateFunction {
    public final static ITemplateFunction CONST = new URLEncode();

    @Override
    public String parseFunction(List list, IWikiModel model, char[] src, int beginIndex, int endIndex, boolean isSubst) throws IOException {
        if (list.size() > 0) {
            String result = isSubst ? list.get(0) : parseTrim(list.get(0), model);
            return URLEncoder.encode(result, UTF_8.name());
        }
        return null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy