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


Java BeansWrapperBuilder类代码示例

本文整理汇总了Java中freemarker.ext.beans.BeansWrapperBuilder的典型用法代码示例。如果您正苦于以下问题:Java BeansWrapperBuilder类的具体用法?Java BeansWrapperBuilder怎么用?Java BeansWrapperBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: getAppConfiguration

import freemarker.ext.beans.BeansWrapperBuilder; //导入依赖的package包/类
/**
 * appConfig配置所有参数 重写freemarker中的  reader方法,读取该配置文件
 *
 * @return config
 */
private static Configuration getAppConfiguration() {
    if (appConfig == null) {
        //从freemarker 视图中获取所有配置
        appConfig = (Configuration) FreeMarkerRender.getConfiguration().clone();
        try {
            //设置模板路径
            appConfig.setDirectoryForTemplateLoading(
                    new File(PathKit.getWebRootPath() + Goja.viewPath));
            appConfig.setObjectWrapper(new BeansWrapperBuilder(Configuration.VERSION_2_3_21).build());
        } catch (IOException e) {
            logger.error("The Freemarkers has error!", e);
        }
    }
    return appConfig;
}
 
开发者ID:GojaFramework,项目名称:goja,代码行数:21,代码来源:Freemarkers.java

示例2: getRoot

import freemarker.ext.beans.BeansWrapperBuilder; //导入依赖的package包/类
public Map<String, Object> getRoot(HttpServletRequest request) throws ServletException {
	Map<String, Object> root = new HashMap<String, Object>();
	root.put("basePath", this.getBasePath());

	try {
		BeansWrapper beansWrapper = new BeansWrapperBuilder(Configuration.VERSION_2_3_21).build();
		TemplateHashModel staticModels = beansWrapper.getStaticModels();
		TemplateHashModel stringUtils = (TemplateHashModel) staticModels.get(StringUtils.class.getCanonicalName());
		TemplateHashModel planInvocationHelper = (TemplateHashModel) staticModels.get(PlanInvocationHelper.class
				.getCanonicalName());
		root.put("StringUtils", stringUtils);
		root.put("PlanInvocationHelper", planInvocationHelper);
	} catch (TemplateModelException e) {
		throw new ServletException(e);
	}

	root.put(ERRORS, request.getSession().getAttribute(ERRORS));
	root.put(SUCCESSES, request.getSession().getAttribute(SUCCESSES));
	request.getSession().setAttribute(ERRORS, new ArrayList<String>());
	request.getSession().setAttribute(SUCCESSES, new ArrayList<String>());
	return root;
}
 
开发者ID:CloudCycle2,项目名称:CSAR_Repository,代码行数:23,代码来源:AbstractServlet.java

示例3: useStaticPackage

import freemarker.ext.beans.BeansWrapperBuilder; //导入依赖的package包/类
public static TemplateHashModel useStaticPackage(String key) {
    try {
        BeansWrapper wrapper = new BeansWrapperBuilder(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS).build();
        TemplateHashModel staticModels = wrapper.getStaticModels();
        TemplateHashModel statics = (TemplateHashModel) staticModels.get(key);
        return statics;

    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:zouzhirong,项目名称:configx,代码行数:13,代码来源:FreemarkerStaticModels.java

示例4: handle

import freemarker.ext.beans.BeansWrapperBuilder; //导入依赖的package包/类
@Override
public HttpResponse handle(HttpRequest request, MiddlewareChain chain) {
    ContentNegotiable negotiable = ContentNegotiable.class.cast(MixinUtils.mixin(request, ContentNegotiable.class));
    HttpResponse response = castToHttpResponse(chain.next(request));
    if (TemplatedHttpResponse.class.isInstance(response)) {
        TemplatedHttpResponse tres = TemplatedHttpResponse.class.cast(response);
        ResourceBundle bundle = config.getMessageResource().getBundle(negotiable.getLocale());
        tres.getContext().put("t", new ResourceBundleModel(bundle,
                new BeansWrapperBuilder(new Version(2,3,23)).build()));
    }
    return response;
}
 
开发者ID:kawasima,项目名称:bouncr,代码行数:13,代码来源:I18nMiddleware.java

示例5: registerResourceBundleResolver

import freemarker.ext.beans.BeansWrapperBuilder; //导入依赖的package包/类
private static void registerResourceBundleResolver(Map<String, Object> model, Locale locale, StampoGlobalConfiguration configuration) {
  model.put("message", new ResourceBundleModel(ResourceBundle.getBundle("messages", locale, configuration.getResourceBundleControl()), new BeansWrapperBuilder(Configuration.VERSION_2_3_22).build()));
  
  TemplateMethodModelEx messageWithBundle = (arguments) -> {
    if (arguments.size() < 2) {
      throw new IllegalArgumentException(
          "messageWithBundle must have at least 2 parameters, passed only " + arguments.size());
    }
    
    String bundleName = arguments.get(0).toString();
    String code = arguments.get(1).toString();
    
    List<Object> parameters = new ArrayList<>();
    for (int i = 2; i < arguments.size(); i++) {
      parameters.add(arguments.get(i));
    }
    
    return MessageFormat.format(
        ResourceBundle.getBundle(bundleName, locale, configuration.getResourceBundleControl()).getString(code),
        parameters.toArray());
  };
  
  model.put("messageWithBundle", messageWithBundle);
  
  TemplateMethodModelEx defaultOrLocale = (arguments) -> {
    String loc = arguments.get(0).toString();
    return configuration.getDefaultLocale().map(l -> l.toLanguageTag().equals(loc) ? "" : loc)
        .orElse(loc);
  };
  model.put("defaultOrLocale", defaultOrLocale);
  
  TemplateMethodModelEx switchToLocale = (arguments) -> {
    String localeToSwitch = arguments.get(0).toString();
    Path fileResourceOutputPath = (Path) model.get("fileResourceOutputPath");
    return PathUtils.switchToLocale(Locale.forLanguageTag(localeToSwitch), locale, fileResourceOutputPath, configuration);
  };
  
  model.put("switchToLocale", switchToLocale);
}
 
开发者ID:digitalfondue,项目名称:stampo,代码行数:40,代码来源:FreemarkerRenderer.java

示例6: getTemplate

import freemarker.ext.beans.BeansWrapperBuilder; //导入依赖的package包/类
private Template getTemplate(DataFile datafile) throws IOException {
    try (InputStream stream = datafile.getStream()) {
        String templatefile = IOUtils.toString(stream);
        Configuration cfg = new Configuration(Configuration.getVersion());
        StringTemplateLoader loader = new StringTemplateLoader();
        loader.putTemplate("template", templatefile);
        cfg.setTemplateLoader(loader);
        BeansWrapper wrapper = new BeansWrapperBuilder(Configuration.getVersion()).build();
        wrapper.setSimpleMapWrapper(true);
        cfg.setObjectWrapper(wrapper);
        return cfg.getTemplate("template");
    }
}
 
开发者ID:Kloudtek,项目名称:kloudmake,代码行数:14,代码来源:FileResource.java

示例7: ParamObjectAdapter

import freemarker.ext.beans.BeansWrapperBuilder; //导入依赖的package包/类
public ParamObjectAdapter(Object paramObject, ArrayList generatedParams) {
  beanModel = new BeanModel(paramObject, new BeansWrapperBuilder(Configuration.VERSION_2_3_22).build());
  this.generatedParams = generatedParams;
}
 
开发者ID:mybatis,项目名称:freemarker-scripting,代码行数:5,代码来源:ParamObjectAdapter.java

示例8: execute

import freemarker.ext.beans.BeansWrapperBuilder; //导入依赖的package包/类
@Override
public void execute() throws MojoExecutionException, MojoFailureException {

    this.pluginDescriptor = ((PluginDescriptor) getPluginContext().get("pluginDescriptor"));

    tempDirectory.mkdirs();
    outputDirectory.mkdirs();

    try {
        // build the full pom
        Configuration cfg = new Configuration(Configuration.VERSION_2_3_21);

        // Specify the data source where the template files come from. Here I set a
        // plain directory for it, but non-file-system are possible too:
        cfg.setDirectoryForTemplateLoading(tempDirectory);

        // Specify how templates will see the data-model. This is an advanced topic...
        // for now just use this:
        BeansWrapperBuilder wrapperBuilder = new BeansWrapperBuilder(Configuration.VERSION_2_3_21);
        wrapperBuilder.setStrict(false);
        cfg.setObjectWrapper(wrapperBuilder.build());

        // Set your preferred charset template files are stored in. UTF-8 is
        // a good choice in most applications:
        cfg.setDefaultEncoding("UTF-8");

        // Sets how errors will appear. Here we assume we are developing HTML pages.
        // For production systems TemplateExceptionHandler.RETHROW_HANDLER is better.
        cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);

        // At least in new projects, specify that you want the fixes that aren't
        // 100% backward compatible too (these are very low-risk changes as far as the
        // 1st and 2nd version number remains):
        cfg.setIncompatibleImprovements(Configuration.VERSION_2_3_21);  // FreeMarker 2.3.20

        // copy the template from jar freemaker can't read stream
        getLog().debug("get the template localy.");
        String ftlName = "mojo-doc.ftl";
        try (
                InputStream input = getClass().getClassLoader().getResourceAsStream("documentation/" + ftlName);
                FileOutputStream outputStream = new FileOutputStream(new File(this.tempDirectory, ftlName))
        ) {
            IOUtils.copy(input, outputStream);
            outputStream.flush();
        }

        getLog().debug("Parse the  ftl.");
        Template temp = cfg.getTemplate(ftlName);

        for (MojoDescriptor mojoDescriptor : pluginDescriptor.getMojos()) {
            getLog().info("Build documentation into " + this.outputDirectory.getAbsolutePath() + "/" + mojoDescriptor.getGoal() + ".html");
            File pom = new File(this.outputDirectory, mojoDescriptor.getGoal() + ".html");
            try (Writer out = new FileWriter(pom)) {
                temp.process(mojoDescriptor, out);
                out.flush();
            }
        }

    } catch (IOException | TemplateException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }


}
 
开发者ID:famaridon,项目名称:vdoc-maven-plugin,代码行数:65,代码来源:GeneratePluginDocMojo.java

示例9: setUp

import freemarker.ext.beans.BeansWrapperBuilder; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    initMocks(this);

    loopVariables = new TemplateModel[0];
    body = null;

    parameters = new HashMap();

    beansWrapper = new BeansWrapperBuilder(Configuration.getVersion()).build();

    environment = new Environment(template, null, writer);

    formatterDirective = new RestrictableDateFormatterDirective();
}
 
开发者ID:NHS-digital-website,项目名称:hippo,代码行数:16,代码来源:RestrictableDateFormatterDirectiveTest.java


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