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;
}
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;
}
Aggregations