本文整理汇总了Java中org.apache.velocity.runtime.directive.Directive类的典型用法代码示例。如果您正苦于以下问题:Java Directive类的具体用法?Java Directive怎么用?Java Directive使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Directive类属于org.apache.velocity.runtime.directive包,在下文中一共展示了Directive类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadDirective
import org.apache.velocity.runtime.directive.Directive; //导入依赖的package包/类
/**
* instantiates and loads the directive with some basic checks
*
* @param directiveClass
* classname of directive to load
*/
private void loadDirective(String directiveClass, String caption)
{
try
{
Object o = Class.forName(directiveClass).newInstance();
if (o instanceof Directive)
{
Directive directive = (Directive) o;
fDirectives.put(directive.getName(), directive);
} else
{
// error(caption + " Directive " + directiveClass + " is not org.apache.velocity.runtime.directive.Directive." + " Ignoring. ");
}
}
catch (Exception e)
{
// error("Exception Loading " + caption + " Directive: " + directiveClass + " : " + e);
}
}
示例2: CodeGenerator
import org.apache.velocity.runtime.directive.Directive; //导入依赖的package包/类
public CodeGenerator(CodeGeneratorContext context, M model, Writer writer, URL templateUrl, String templateResource, Set<Class<? extends Directive>> directives) {
this.context = context != null ? context : new CodeGeneratorContext();
this.model = model;
this.writer = writer;
this.templateResource = templateResource;
this.templateUrl = templateUrl;
this.directives = directives;
StringResourceRepository repo = StringResourceLoader.getRepository();
try {
repo.putStringResource(TEMPLATE, templateUrl != null ? loadResource(templateUrl) : loadResource(templateResource));
} catch (Exception e) {
throw new RuntimeException(TEMPLATE_READER_FAILURE, e);
}
for (Class<? extends Directive> directive : directives) {
context.getVelocityEngine().loadDirective(directive.getCanonicalName());
}
this.template = this.context.getVelocityEngine().getTemplate(TEMPLATE);
this.context.getVelocityContext().put(MODEL, model);
}
示例3: initialise
import org.apache.velocity.runtime.directive.Directive; //导入依赖的package包/类
/**
* Initialise Velocity
*
* @param templatePath the path to templates
*/
public static final void initialise(String templatePath)
{
// Setup Velocity
Properties velocityProperties = new Properties();
// create a list of custom directives we're using
List<Class<? extends Directive>> userDirectiveClasses = new ArrayList<Class<? extends Directive>>();
userDirectiveClasses.add(Decorate.class);
// build the user directive string
StringBuilder userDirectiveStr = new StringBuilder();
for (Class<? extends Directive> clz : userDirectiveClasses)
{
if (userDirectiveStr.length() > 0)
{
userDirectiveStr.append(",");
}
userDirectiveStr.append(clz.getName());
}
// wire in our custom directives
velocityProperties.setProperty("userdirective", userDirectiveStr.toString());
velocityProperties.setProperty("velocimacro.library", "");
// wire in our custom resource loader
velocityProperties.setProperty("resource.loader", "relativecp");
velocityProperties.setProperty("relativecp.resource.loader.description", "Relative CP Loader");
velocityProperties.setProperty("relativecp.resource.loader.class", RelativeClasspathResourceLoader.class.getName());
velocityProperties.setProperty(RelativeClasspathResourceLoader.RELATIVE_PATH, templatePath);
// initialise
Velocity.init(velocityProperties);
}
示例4: initialise
import org.apache.velocity.runtime.directive.Directive; //导入依赖的package包/类
/**
* Initialise Velocity
*
* @param templatePath the path to templates
*/
public static final void initialise(String templatePath)
{
// Setup Velocity
Properties velocityProperties = new Properties();
// create a list of custom directives we're using
List<Class<? extends Directive>> userDirectiveClasses = new ArrayList<Class<? extends Directive>>();
userDirectiveClasses.add(Decorate.class);
// build the user directive string
StringBuilder userDirectiveStr = new StringBuilder();
for (Class<? extends Directive> clz : userDirectiveClasses)
{
if (userDirectiveStr.length() > 0)
{
userDirectiveStr.append(",");
}
userDirectiveStr.append(clz.getName());
}
// wire in our custom directives
velocityProperties.setProperty("userdirective", userDirectiveStr.toString());
velocityProperties.setProperty("velocimacro.library", "");
// file resource loader
velocityProperties.setProperty("resource.loader", "file");
velocityProperties.setProperty("file.resource.loader.path", templatePath);
Velocity.init(velocityProperties);
// initialise
Velocity.init(velocityProperties);
}
示例5: getDirectives
import org.apache.velocity.runtime.directive.Directive; //导入依赖的package包/类
public Set<Class<? extends Directive>> getDirectives() {
return directives;
}