Search in sources :

Example 1 with ClasspathMetaInfTldSource

use of freemarker.ext.jsp.TaglibFactory.ClasspathMetaInfTldSource in project freemarker by apache.

the class FreemarkerServlet method createTaglibFactory.

/**
 * Called to create the {@link TaglibFactory} once per servlet context.
 * The default implementation configures it based on the servlet-init parameters and various other environmental
 * settings, so if you override this method, you should call super, then adjust the result.
 *
 * @since 2.3.22
 */
protected TaglibFactory createTaglibFactory(ObjectWrapper objectWrapper, ServletContext servletContext) throws TemplateModelException {
    TaglibFactory taglibFactory = new TaglibFactory(servletContext);
    taglibFactory.setObjectWrapper(objectWrapper);
    {
        List /*<MetaInfTldSource>*/
        mergedMetaInfTldSources = new ArrayList();
        if (metaInfTldSources != null) {
            mergedMetaInfTldSources.addAll(metaInfTldSources);
        }
        String sysPropVal = SecurityUtilities.getSystemProperty(SYSTEM_PROPERTY_META_INF_TLD_SOURCES, null);
        if (sysPropVal != null) {
            try {
                List metaInfTldSourcesSysProp = parseAsMetaInfTldLocations(sysPropVal);
                if (metaInfTldSourcesSysProp != null) {
                    mergedMetaInfTldSources.addAll(metaInfTldSourcesSysProp);
                }
            } catch (ParseException e) {
                throw new TemplateModelException("Failed to parse system property \"" + SYSTEM_PROPERTY_META_INF_TLD_SOURCES + "\"", e);
            }
        }
        List /*<Pattern>*/
        jettyTaglibJarPatterns = null;
        try {
            final String attrVal = (String) servletContext.getAttribute(ATTR_JETTY_CP_TAGLIB_JAR_PATTERNS);
            jettyTaglibJarPatterns = attrVal != null ? InitParamParser.parseCommaSeparatedPatterns(attrVal) : null;
        } catch (Exception e) {
            LOG.error("Failed to parse application context attribute \"" + ATTR_JETTY_CP_TAGLIB_JAR_PATTERNS + "\" - it will be ignored", e);
        }
        if (jettyTaglibJarPatterns != null) {
            for (Iterator /*<Pattern>*/
            it = jettyTaglibJarPatterns.iterator(); it.hasNext(); ) {
                Pattern pattern = (Pattern) it.next();
                mergedMetaInfTldSources.add(new ClasspathMetaInfTldSource(pattern));
            }
        }
        taglibFactory.setMetaInfTldSources(mergedMetaInfTldSources);
    }
    {
        List /*<String>*/
        mergedClassPathTlds = new ArrayList();
        if (classpathTlds != null) {
            mergedClassPathTlds.addAll(classpathTlds);
        }
        String sysPropVal = SecurityUtilities.getSystemProperty(SYSTEM_PROPERTY_CLASSPATH_TLDS, null);
        if (sysPropVal != null) {
            try {
                List /*<String>*/
                classpathTldsSysProp = InitParamParser.parseCommaSeparatedList(sysPropVal);
                if (classpathTldsSysProp != null) {
                    mergedClassPathTlds.addAll(classpathTldsSysProp);
                }
            } catch (ParseException e) {
                throw new TemplateModelException("Failed to parse system property \"" + SYSTEM_PROPERTY_CLASSPATH_TLDS + "\"", e);
            }
        }
        taglibFactory.setClasspathTlds(mergedClassPathTlds);
    }
    return taglibFactory;
}
Also used : TemplateModelException(freemarker.template.TemplateModelException) Pattern(java.util.regex.Pattern) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) TaglibFactory(freemarker.ext.jsp.TaglibFactory) ArrayList(java.util.ArrayList) List(java.util.List) ParseException(java.text.ParseException) ServletException(javax.servlet.ServletException) TemplateModelException(freemarker.template.TemplateModelException) TemplateException(freemarker.template.TemplateException) TemplateNotFoundException(freemarker.template.TemplateNotFoundException) ParseException(java.text.ParseException) IOException(java.io.IOException) ClasspathMetaInfTldSource(freemarker.ext.jsp.TaglibFactory.ClasspathMetaInfTldSource)

Example 2 with ClasspathMetaInfTldSource

use of freemarker.ext.jsp.TaglibFactory.ClasspathMetaInfTldSource in project freemarker by apache.

the class FreemarkerServlet method parseAsMetaInfTldLocations.

private List parseAsMetaInfTldLocations(String value) throws ParseException {
    List /*<MetaInfTldSource>*/
    metaInfTldSources = null;
    List /*<String>*/
    values = InitParamParser.parseCommaSeparatedList(value);
    for (Iterator it = values.iterator(); it.hasNext(); ) {
        final String itemStr = (String) it.next();
        final MetaInfTldSource metaInfTldSource;
        if (itemStr.equals(META_INF_TLD_LOCATION_WEB_INF_PER_LIB_JARS)) {
            metaInfTldSource = WebInfPerLibJarMetaInfTldSource.INSTANCE;
        } else if (itemStr.startsWith(META_INF_TLD_LOCATION_CLASSPATH)) {
            String itemRightSide = itemStr.substring(META_INF_TLD_LOCATION_CLASSPATH.length()).trim();
            if (itemRightSide.length() == 0) {
                metaInfTldSource = new ClasspathMetaInfTldSource(Pattern.compile(".*", Pattern.DOTALL));
            } else if (itemRightSide.startsWith(":")) {
                final String regexpStr = itemRightSide.substring(1).trim();
                if (regexpStr.length() == 0) {
                    throw new ParseException("Empty regular expression after \"" + META_INF_TLD_LOCATION_CLASSPATH + ":\"", -1);
                }
                metaInfTldSource = new ClasspathMetaInfTldSource(Pattern.compile(regexpStr));
            } else {
                throw new ParseException("Invalid \"" + META_INF_TLD_LOCATION_CLASSPATH + "\" value syntax: " + value, -1);
            }
        } else if (itemStr.startsWith(META_INF_TLD_LOCATION_CLEAR)) {
            metaInfTldSource = ClearMetaInfTldSource.INSTANCE;
        } else {
            throw new ParseException("Item has no recognized source type prefix: " + itemStr, -1);
        }
        if (metaInfTldSources == null) {
            metaInfTldSources = new ArrayList();
        }
        metaInfTldSources.add(metaInfTldSource);
    }
    return metaInfTldSources;
}
Also used : ClearMetaInfTldSource(freemarker.ext.jsp.TaglibFactory.ClearMetaInfTldSource) ClasspathMetaInfTldSource(freemarker.ext.jsp.TaglibFactory.ClasspathMetaInfTldSource) WebInfPerLibJarMetaInfTldSource(freemarker.ext.jsp.TaglibFactory.WebInfPerLibJarMetaInfTldSource) MetaInfTldSource(freemarker.ext.jsp.TaglibFactory.MetaInfTldSource) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ParseException(java.text.ParseException) ClasspathMetaInfTldSource(freemarker.ext.jsp.TaglibFactory.ClasspathMetaInfTldSource)

Aggregations

ClasspathMetaInfTldSource (freemarker.ext.jsp.TaglibFactory.ClasspathMetaInfTldSource)2 ParseException (java.text.ParseException)2 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 List (java.util.List)2 TaglibFactory (freemarker.ext.jsp.TaglibFactory)1 ClearMetaInfTldSource (freemarker.ext.jsp.TaglibFactory.ClearMetaInfTldSource)1 MetaInfTldSource (freemarker.ext.jsp.TaglibFactory.MetaInfTldSource)1 WebInfPerLibJarMetaInfTldSource (freemarker.ext.jsp.TaglibFactory.WebInfPerLibJarMetaInfTldSource)1 TemplateException (freemarker.template.TemplateException)1 TemplateModelException (freemarker.template.TemplateModelException)1 TemplateNotFoundException (freemarker.template.TemplateNotFoundException)1 IOException (java.io.IOException)1 Pattern (java.util.regex.Pattern)1 ServletException (javax.servlet.ServletException)1