当前位置: 首页>>代码示例>>Java>>正文


Java Configuration.setSharedVariable方法代码示例

本文整理汇总了Java中freemarker.template.Configuration.setSharedVariable方法的典型用法代码示例。如果您正苦于以下问题:Java Configuration.setSharedVariable方法的具体用法?Java Configuration.setSharedVariable怎么用?Java Configuration.setSharedVariable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在freemarker.template.Configuration的用法示例。


在下文中一共展示了Configuration.setSharedVariable方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: configuration

import freemarker.template.Configuration; //导入方法依赖的package包/类
@Singleton
@Provides
public static Configuration configuration(LinkHelper linkHelper, MultiTemplateLoader templateLoader) {
    try {
        freemarker.log.Logger.selectLoggerLibrary(Logger.LIBRARY_SLF4J);
        Configuration cfg = new freemarker.template.Configuration(Configuration.VERSION_2_3_25);
        cfg.setTagSyntax(freemarker.template.Configuration.SQUARE_BRACKET_TAG_SYNTAX);
        cfg.setLazyAutoImports(true);
        cfg.setLocale(Locale.GERMANY); // todo make configurable
        cfg.addAutoImport("saito", "saito.ftl");
        cfg.setSharedVariable("saitoLinkHelper", linkHelper);
        cfg.setDefaultEncoding("UTF-8");
        cfg.setLogTemplateExceptions(false);
        cfg.setTemplateLoader(templateLoader);
        return cfg;
    } catch (TemplateModelException | ClassNotFoundException e) {
        log.error("Error creating config", e);
        throw new IllegalStateException(e);
    }
}
 
开发者ID:marcobehler,项目名称:saito,代码行数:21,代码来源:FreemarkerModule.java

示例2: afterPropertiesSet

import freemarker.template.Configuration; //导入方法依赖的package包/类
@Override
public void afterPropertiesSet() throws IOException, TemplateException {
	super.afterPropertiesSet();
	Configuration cfg = this.getConfiguration();
	cfg.setSharedVariable("shiro", new ShiroTags());// shiro标签
	cfg.setNumberFormat("#");// 防止页面输出数字,变成2,000
	// 可以添加很多自己的要传输到页面的[方法、对象、值]
}
 
开发者ID:butter-fly,项目名称:belling-admin,代码行数:9,代码来源:FreeMarkerConfigExtend.java

示例3: loadTransforms

import freemarker.template.Configuration; //导入方法依赖的package包/类
/**
 * Protected helper method.
 * <p>
 * SCIPIO: TODO: delegate to FreeMarkerWorker and remove license notice
 */
protected static void loadTransforms(ClassLoader loader, Properties props, Configuration config) {
    for (Iterator<Object> i = props.keySet().iterator(); i.hasNext();) {
        String key = (String) i.next();
        String className = props.getProperty(key);
        if (Debug.verboseOn()) {
            Debug.logVerbose("Adding FTL Transform " + key + " with class " + className, module);
        }
        try {
            config.setSharedVariable(key, loader.loadClass(className).newInstance());
        } catch (Exception e) {
            Debug.logError(e, "Could not pre-initialize dynamically loaded class: " + className + ": " + e, module);
        }
    }
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:20,代码来源:CmsRenderTemplate.java

示例4: loadTransforms

import freemarker.template.Configuration; //导入方法依赖的package包/类
/**
 * Protected helper method.
 */
protected static void loadTransforms(ClassLoader loader, Properties props, Configuration config) {
    for (Iterator<Object> i = props.keySet().iterator(); i.hasNext();) {
        String key = (String) i.next();
        String className = props.getProperty(key);
        if (Debug.verboseOn()) {
            Debug.logVerbose("Adding FTL Transform " + key + " with class " + className, module);
        }
        try {
            config.setSharedVariable(key, loader.loadClass(className).newInstance());
        } catch (Exception e) {
            Debug.logError(e, "Could not pre-initialize dynamically loaded class: " + className + ": " + e, module);
        }
    }
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:18,代码来源:FreeMarkerWorker.java

示例5: loadSharedVars

import freemarker.template.Configuration; //导入方法依赖的package包/类
/**
 * SCIPIO: Loads shared vars.
 */
protected static void loadSharedVars(Properties props, Configuration config) {
    for (Iterator<Object> i = props.keySet().iterator(); i.hasNext();) {
        String key = (String) i.next();
        String value = props.getProperty(key);
        if (Debug.verboseOn()) {
            Debug.logVerbose("Adding FTL shared var " + key + " with value " + value, module);
        }
        try {
            config.setSharedVariable(key, value);
        } catch (Exception e) {
            Debug.logError(e, "Could not pre-initialize dynamically loaded shared var: " + key + ": " + e, module);
        }
    }
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:18,代码来源:FreeMarkerWorker.java

示例6: registerDirectives

import freemarker.template.Configuration; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
protected static void registerDirectives(Configuration conf, ServletContext servletContext)
    throws ServletException, IOException {
    // ---------------------------------------------------------------
    // Locate directives and add them to the freemarker conf.
    // ---------------------------------------------------------------

    ModuleLoader loader = App.get().moduleLoader();
    Class<WidgetController>[] foundClasses = (Class<WidgetController>[]) loader
        .findAllTypesAnnotatedWith(Directive.class, false);

    if (foundClasses != null && foundClasses.length > 0) {
        for (Class<WidgetController> foundClass : foundClasses) {
            try {
                Annotation declaredAnnotation = Annotations.declaredAnnotation(foundClass, Directive.class);

                if (declaredAnnotation != null) {
                    // get directive name from annotation (this is the tag
                    // name that will be used in the template)
                    String directiveName = ((Directive) declaredAnnotation).value();

                    if (Str.isEmpty(directiveName))
                        directiveName = ((Directive) declaredAnnotation).name();

                    if (!Str.isEmpty(directiveName)) {
                        // Add it to the configuration as a shared variable
                        conf.setSharedVariable(directiveName, ModuleInjector.get().getInstance(foundClass));
                    }
                }
            } catch (Throwable t) {
                RuntimeException re = new RuntimeException(t);
                re.setStackTrace(t.getStackTrace());
                throw re;
            }
        }
    }
}
 
开发者ID:geetools,项目名称:geeCommerce-Java-Shop-Software-and-PIM,代码行数:38,代码来源:FreemarkerHelper.java

示例7: render

import freemarker.template.Configuration; //导入方法依赖的package包/类
public static String render(String templateContent, Map<String, Object> params)
    throws IOException, TemplateException {
    StringWriter sw = new StringWriter();

    App app = App.get();
    ApplicationContext appCtx = app.context();
    RequestContext reqCtx = appCtx.getRequestContext();

    // TODO: replace quick hack with configured value!
    Configuration conf = new Configuration();
    conf.setDefaultEncoding("UTF-8");

    if (reqCtx != null && reqCtx.getLocale() != null)
        conf.setLocale(reqCtx.getLocale());

    conf.setSharedVariable("set", new SetDirective());
    conf.setSharedVariable("url", app.inject(URLDirective.class));
    conf.setSharedVariable("attribute", new AttributeDirective());
    conf.setSharedVariable("attribute_exists", new AttributeExistsDirective());
    conf.setSharedVariable("attribute_equals", new AttributeEqualsDirective());
    conf.setSharedVariable("attribute_has_value", new AttributeHasValueDirective());
    conf.setSharedVariable("message", new MessageDirective());
    conf.setSharedVariable("print", new PrintDirective());
    conf.setSharedVariable("json", new JsonDirective());
    conf.setSharedVariable("skin", new SkinDirective());
    conf.setSharedVariable("truncate", new TruncateDirective());

    Template t = new Template("name", new StringReader(templateContent), conf);
    t.process(params, sw);
    return sw.toString();
}
 
开发者ID:geetools,项目名称:geeCommerce-Java-Shop-Software-and-PIM,代码行数:32,代码来源:Templates.java

示例8: getInternalEngine

import freemarker.template.Configuration; //导入方法依赖的package包/类
protected Configuration getInternalEngine() throws IOException, TemplateException{
	
	try {
		BeansWrapper beansWrapper = new BeansWrapper(Configuration.VERSION_2_3_23);
		this.templateModel = beansWrapper.getStaticModels().get(String.class.getName());
	} catch (TemplateModelException e) {
		throw new IOException(e.getMessage(),e.getCause());
	}

	// 创建 Configuration 实例
	Configuration config = new Configuration(Configuration.VERSION_2_3_23);
	
	Properties props = ConfigUtils.filterWithPrefix("docx4j.freemarker.", "docx4j.freemarker.", Docx4jProperties.getProperties(), false);

	// FreeMarker will only accept known keys in its setSettings and
	// setAllSharedVariables methods.
	if (!props.isEmpty()) {
		config.setSettings(props);
	}

	if (this.freemarkerVariables != null && !this.freemarkerVariables.isEmpty()) {
		config.setAllSharedVariables(new SimpleHash(this.freemarkerVariables, config.getObjectWrapper()));
	}

	if (this.defaultEncoding != null) {
		config.setDefaultEncoding(this.defaultEncoding);
	}

	List<TemplateLoader> templateLoaders = new LinkedList<TemplateLoader>(this.templateLoaders);
	
	// Register template loaders that are supposed to kick in early.
	if (this.preTemplateLoaders != null) {
		templateLoaders.addAll(this.preTemplateLoaders);
	}
	
	postProcessTemplateLoaders(templateLoaders);
	
	// Register template loaders that are supposed to kick in late.
	if (this.postTemplateLoaders != null) {
		templateLoaders.addAll(this.postTemplateLoaders);
	}
	
	TemplateLoader loader = getAggregateTemplateLoader(templateLoaders);
	if (loader != null) {
		config.setTemplateLoader(loader);
	}
	//config.setClassLoaderForTemplateLoading(classLoader, basePackagePath);
	//config.setCustomAttribute(name, value);
	//config.setDirectoryForTemplateLoading(dir);
	//config.setServletContextForTemplateLoading(servletContext, path);
	//config.setSharedVariable(name, value);
	//config.setSharedVariable(name, tm);
	config.setSharedVariable("fmXmlEscape", new XmlEscape());
	config.setSharedVariable("fmHtmlEscape", new HtmlEscape());
	//config.setSharedVaribles(map);
	
       return config;
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:59,代码来源:WordprocessingMLFreemarkerTemplate.java

示例9: main

import freemarker.template.Configuration; //导入方法依赖的package包/类
public static void main(String[] args) {
	Configuration config = new Configuration();
	try {
		config.setClassForTemplateLoading(HelloFreeMarker.class, "");
		// 去掉int型输出时的逗号, 例如: 123,456
        // config.setNumberFormat("#");		// config.setNumberFormat("0"); 也可以
        config.setNumberFormat("#0.#####");
        config.setDateFormat("yyyy-MM-dd");
        config.setTimeFormat("HH:mm:ss");
        config.setDateTimeFormat("yyyy-MM-dd HH:mm:ss");
        config.setDateTimeFormat("yyyy-MM-dd HH");
        
		config.setSharedVariable("sharedChen", "sharedChen");
		config.setSharedVariable("name", "HelloFreeMarker----------------SharedVariable");
		
		Template myTemplate = config.getTemplate("hellofreemarker.ftl");
		
		Map<String,Object> dataModel = new HashMap<String, Object>();
		
		dataModel.put("name", "HelloFreeMarker");
		dataModel.put("date1", (new Date()).toString());
		dataModel.put("dateO", new Date());
		dataModel.put("staticUser", User.class);
		
		dataModel.put("chen","");
		 
		 User user =  User.getUser();
		 
		 dataModel.put("user",user);
		 
		 List temp = new ArrayList();
		 temp.add("1");
		 temp.add("2");
		 temp.add("322");
		 dataModel.put("list", temp);
		 
		StringWriter sw = new StringWriter();
		myTemplate.process(dataModel, sw);
		
		System.out.println(sw.toString());
		
	} catch (Exception e) {
		e.printStackTrace();
	}

}
 
开发者ID:thinking-github,项目名称:nbone,代码行数:47,代码来源:HelloFreeMarker.java

示例10: registerWidgets

import freemarker.template.Configuration; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
protected static void registerWidgets(Configuration conf, ServletContext servletContext)
    throws ServletException, IOException {
    // ---------------------------------------------------------------
    // Locate widgets, wrap them in a freemarker directive
    // and add them to the freemarker conf as a shared variable.
    // ---------------------------------------------------------------

    ModuleLoader loader = App.get().moduleLoader();
    Class<WidgetController>[] foundClasses = (Class<WidgetController>[]) loader
        .findAllTypesAnnotatedWith(Widget.class, false);

    if (foundClasses != null && foundClasses.length > 0) {
        for (Class<WidgetController> foundClass : foundClasses) {
            try {
                Annotation declaredAnnotation = Annotations.declaredAnnotation(foundClass, Widget.class);

                if (declaredAnnotation != null) {
                    // get directive name from annotation (this is the tag
                    // name that will be used in the template)
                    String directiveName = ((Widget) declaredAnnotation).value();

                    if (Str.isEmpty(directiveName))
                        directiveName = ((Widget) declaredAnnotation).name();

                    // Wrap the widget in a freemarker compatible directive
                    WidgetWrapperDirective widgetDirective = new WidgetWrapperDirective(foundClass);

                    if (!Str.isEmpty(directiveName)) {
                        // Add it to the configuration as a shared variable
                        conf.setSharedVariable(directiveName, widgetDirective);
                    }
                }
            } catch (Throwable t) {
                RuntimeException re = new RuntimeException(t);
                re.setStackTrace(t.getStackTrace());
                throw re;
            }
        }
    }
}
 
开发者ID:geetools,项目名称:geeCommerce-Java-Shop-Software-and-PIM,代码行数:42,代码来源:FreemarkerHelper.java


注:本文中的freemarker.template.Configuration.setSharedVariable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。