當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。