struts-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "zhouyanming (JIRA)" <j...@apache.org>
Subject [jira] Commented: (WW-3079) Allow for wiring global macro Freemarker library's within FreemarkerManager
Date Thu, 02 Jul 2009 11:09:59 GMT

    [ https://issues.apache.org/struts/browse/WW-3079?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=46456#action_46456
] 

zhouyanming commented on WW-3079:
---------------------------------

package test;
import javax.servlet.ServletContext;

import freemarker.template.TemplateException;

public class MyFreemarkerManager extends
		org.apache.struts2.views.freemarker.FreemarkerManager {
	protected freemarker.template.Configuration createConfiguration(
			ServletContext servletContext) throws TemplateException {
		freemarker.template.Configuration configuration = super
				.createConfiguration(servletContext);
		// add auto import and include
		return configuration;
	}
}

<bean type="org.apache.struts2.views.freemarker.FreemarkerManagery"  class="test.MyFreemarkerManager"
/>


> Allow for wiring global macro Freemarker library's within FreemarkerManager
> ---------------------------------------------------------------------------
>
>                 Key: WW-3079
>                 URL: https://issues.apache.org/struts/browse/WW-3079
>             Project: Struts 2
>          Issue Type: Improvement
>          Components: Integration
>    Affects Versions: 2.1.8
>            Reporter: Matthew Payne
>             Fix For: 2.1.8
>
>
> Something similar can can be setup via for velocity Macro's .  We should be able to set
certain macro libs as global without needing to import them directly in our freemarker templates.

> Such a setting is currently not available in the current FreemarkerManager
> example of setting this up in another project(not struts based). 
> reference --> http://svn.riotfamily.org/svn/riotfamily/trunk/website/META-INF/riot/website-servlet.xml
> ---> notice macro lib property
> <bean id="freemarkerConfig" class="org.riotfamily.website.freemarker.WebsiteFreeMarkerConfigurer">
> 		<description>
> 			FreeMarker configuration.
> 		</description>
> 		<property name="defaultEncoding" value="UTF-8" />
> 		<property name="templateLoaderPaths">
> 		    <list>
> 		        <value>/WEB-INF/view</value>
> 		    </list>
> 		</property>
> 		<property name="freemarkerSettings" value="${website-servlet.freemarker.*}" />
> 		<property name="useTemplateCache" value="${website-servlet.useTemplateCache=true}"
/>
> 		<property name="macroLibraries">
> 			<props>
> 				<prop key="c">classpath:org/riotfamily/website/view/common.ftl</prop>
> 				<prop key="form">classpath:org/riotfamily/website/form/form.ftl</prop>
> 				<prop key="template">classpath:org/riotfamily/website/template/template.ftl</prop>
> 				<prop key="txt2img">classpath:org/riotfamily/website/txt2img/txt2img.ftl</prop>
> 			</props>
> 		</property>
> 		<property name="whitespaceStripping" value="true" />
> 	</bean>
> http://www.java2s.com/Open-Source/Java-Document/Content-Management-System/riotfamily/org/riotfamily/common/web/view/freemarker/RiotFreeMarkerConfigurer.java.htm
>   protected void importMacroLibraries(Configuration config) {
> 192:                if (macroLibraries != null) {
> 193:                    Enumeration names = macroLibraries.propertyNames();
> 194:                    while (names.hasMoreElements()) {
> 195:                        String namespace = (String) names.nextElement();
> 196:                        String lib = macroLibraries.getProperty(namespace);
> 197:                        log
> 198:                                .info(lib + " imported under namespace "
> 199:                                        + namespace);
> 200:                        config.addAutoImport(namespace, lib);
> 201:                    }
> 202:                }
> 203:            }
>      /**
> 074:             * Sets the macro libraries to be auto-imported, keyed by their namespace.
> 075:             */
> 076:            public void setMacroLibraries(Properties macroLibraries) {
> 077:                this .macroLibraries = macroLibraries;
> 078:            }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message