Java 类org.apache.velocity.tools.ToolManager 实例源码

项目:wiremock-velocity-transformer    文件:VelocityResponseTransformer.java   
@Override
public ResponseDefinition transform(final Request request,
        final ResponseDefinition responseDefinition, final FileSource files,
        final Parameters parameters) {
            if (responseDefinition.specifiesBodyFile() && templateDeclared(responseDefinition)) {
                  this.fileSource = files;
                  final VelocityEngine velocityEngine = new VelocityEngine();
                  velocityEngine.init();
                  final ToolManager toolManager = new ToolManager();
                  toolManager.setVelocityEngine(velocityEngine);
                  context = toolManager.createContext();
                  addBodyToContext(request.getBodyAsString());
                  addHeadersToContext(request.getHeaders());
                  context.put("requestAbsoluteUrl", request.getAbsoluteUrl());
                  context.put("requestUrl", request.getUrl());
                  context.put("requestMethod", request.getMethod());
                  final String body = getRenderedBody(responseDefinition);
                  return ResponseDefinitionBuilder.like(responseDefinition).but()
                          .withBody(body)
                          .build();
            } else {
                return responseDefinition;
            }
}
项目:wiremock-velocity-transformer    文件:VelocityResponseTransformer.java   
@Override
public ResponseDefinition transform(final Request request,
        final ResponseDefinition responseDefinition, final FileSource files,
        final Parameters parameters) {
            if (responseDefinition.specifiesBodyFile() && templateDeclared(responseDefinition)) {
                  this.fileSource = files;
                  final VelocityEngine velocityEngine = new VelocityEngine();
                  velocityEngine.init();
                  final ToolManager toolManager = new ToolManager();
                  toolManager.setVelocityEngine(velocityEngine);
                  context = toolManager.createContext();
                  addBodyToContext(request.getBodyAsString());
                  addHeadersToContext(request.getHeaders());
                  context.put("requestAbsoluteUrl", request.getAbsoluteUrl());
                  context.put("requestUrl", request.getUrl());
                  context.put("requestMethod", request.getMethod());
                  final String body = getRenderedBody(responseDefinition);
                  return ResponseDefinitionBuilder.like(responseDefinition).but()
                          .withBody(body)
                          .build();
            } else {
                return responseDefinition;
            }
}
项目:beyondj    文件:AbstractLocalisedServlet.java   
private Context createContextForLocale(Locale locale) {
    EasyFactoryConfiguration config = new EasyFactoryConfiguration();
    config.toolbox(Scope.APPLICATION)
            .tool(MSG, ResourceTool.class)
            .property(BUNDLES, MESSAGES)
            .property(LOCALE, locale);

    ToolManager manager = new ToolManager(false, false);
    manager.configure(config);
    return manager.createContext();
}
项目:communote-server    文件:NoteTemplateService.java   
/**
 * initialize required components
 */
@PostConstruct
public void init() {
    toolManager = new ToolManager(false, false);
    toolManager.setVelocityEngine(velocityEngine);
    toolManager.configure("com/communote/server/core/note/template/velocity-toolbox.xml");
    propertyManagement.addObjectPropertyFilter(PropertyType.NoteProperty,
            PropertyManagement.KEY_GROUP, NOTE_PROPERTY_KEY_TEMPLATE_ID);
    propertyManagement.addObjectPropertyFilter(PropertyType.NoteProperty,
            PropertyManagement.KEY_GROUP, NOTE_PROPERTY_KEY_TEMPLATE_PROPERTIES);
}
项目:servicedocgen-maven-plugin    文件:VelocityServicesGenerator.java   
/**
 * The constructor.
 *
 * @param templatePath the classpath location where to look for velocity templates.
 */
public VelocityServicesGenerator( String templatePath )
{
    super();
    this.engine = new VelocityEngine();
    this.engine.setProperty( RuntimeConstants.RESOURCE_LOADER, "classpath" );
    this.engine.setProperty( "classpath.resource.loader.class", ClasspathResourceLoader.class.getName() );
    this.engine.init();

    ToolManager manager = new ToolManager();
    this.context = manager.createContext();
    this.templatePath = templatePath;
    this.template = this.engine.getTemplate( templatePath, ENCODING );
}
项目:mashmesh    文件:VelocityUtils.java   
public static VelocityContext getContext() {
    if (toolManager == null) {
        ToolManager newToolManager = new ToolManager();
        newToolManager.configure("WEB-INF/velocity-tools.xml");
        toolManager = newToolManager;
    }

    return new VelocityContext(toolManager.createContext());
}