本文整理汇总了Java中org.apache.velocity.runtime.parser.node.SimpleNode类的典型用法代码示例。如果您正苦于以下问题:Java SimpleNode类的具体用法?Java SimpleNode怎么用?Java SimpleNode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SimpleNode类属于org.apache.velocity.runtime.parser.node包,在下文中一共展示了SimpleNode类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: renderString
import org.apache.velocity.runtime.parser.node.SimpleNode; //导入依赖的package包/类
@Override
public void renderString(String templateContent, Map<String, Object> model, Writer writer) {
// create the velocity context
VelocityContext context = createVelocityContext(model);
// merge the template
try {
RuntimeServices runtimeServices = RuntimeSingleton.getRuntimeServices();
StringReader reader = new StringReader(templateContent);
SimpleNode node = runtimeServices.parse(reader, "StringTemplate");
Template template = new Template();
template.setRuntimeServices(runtimeServices);
template.setData(node);
template.initDocument();
template.merge(context, writer);
} catch (Exception e) {
throw new PippoRuntimeException(e);
}
}
示例2: render
import org.apache.velocity.runtime.parser.node.SimpleNode; //导入依赖的package包/类
@Override
public boolean render(InternalContextAdapter context, Writer writer,
Node node) throws IOException, ResourceNotFoundException,
ParseErrorException, MethodInvocationException
{
int argsNum = node.jjtGetNumChildren();
for(int step = 0 ; step < argsNum; step++)
{
SimpleNode simpleNode = (SimpleNode) node.jjtGetChild(step);
Object argObject = simpleNode.value(context);
//传入参数
if(argObject instanceof String)
{
System.out.println((String)argObject);
writer.write((String)argObject);
writer.flush();
}
}
return true;
}
示例3: mergeTemplateIntoString
import org.apache.velocity.runtime.parser.node.SimpleNode; //导入依赖的package包/类
public String mergeTemplateIntoString(String templateFilename, Map<String, Object> params)
throws VelocityTemplateParsingException {
try (InputStream is = settingsFacade.getRawConfig(templateFilename)) {
StringReader reader = new StringReader(IOUtils.toString(is));
SimpleNode node = rs.parse(reader, templateFilename);
Template template = new Template();
template.setRuntimeServices(rs);
template.setData(node);
template.initDocument();
StringWriter writer = new StringWriter();
template.merge(new VelocityContext(params), writer);
return writer.toString();
} catch (ParseException|IOException e) {
throw new VelocityTemplateParsingException("Couldn't merge template into string", e);
}
}
示例4: initTemplate
import org.apache.velocity.runtime.parser.node.SimpleNode; //导入依赖的package包/类
private void initTemplate(@NonNull final String verifyExpression) throws ParseException {
// Init pattern ...
final RuntimeServices runtimeServices = RuntimeSingleton.getRuntimeServices();
final StringReader reader = new StringReader(verifyExpression);
SimpleNode node = runtimeServices.parse(reader, this.getDocumentation().getId());
final Template template = new Template();
template.setRuntimeServices(runtimeServices);
template.setData(node);
template.initDocument();
this.template = template;
// Parse expression looking for variable ...
final Pattern pattern = Pattern.compile(VELOCITY_VARIABLE);
final Matcher matcher = pattern.matcher(verifyExpression);
while (matcher.find()) {
final String key = matcher.group(1);
final ClassProperty property = ClassProperty.to(key);
this.templateProperties.add(property);
}
}
示例5: create
import org.apache.velocity.runtime.parser.node.SimpleNode; //导入依赖的package包/类
public static Template create(String source, String templateName) throws ParseException {
RuntimeServices runtimeServices = RuntimeSingleton.getRuntimeServices();
StringReader reader = new StringReader(source);
SimpleNode node = runtimeServices.parse(reader, templateName);
Template template = new Template();
template.setRuntimeServices(runtimeServices);
template.setData(node);
template.initDocument();
return template;
}
示例6: VelocitySqlSource
import org.apache.velocity.runtime.parser.node.SimpleNode; //导入依赖的package包/类
public VelocitySqlSource(Configuration configuration, String scriptText) {
this.configuration = configuration;
try {
RuntimeServices runtimeServices = RuntimeSingleton.getRuntimeServices();
StringReader reader = new StringReader(scriptText);
SimpleNode node = runtimeServices.parse(reader, "Template name");
script = new Template();
script.setRuntimeServices(runtimeServices);
script.setData(node);
script.initDocument();
} catch (Exception ex) {
throw new BuilderException("Error parsing velocity script", ex);
}
}
示例7: createTemplate
import org.apache.velocity.runtime.parser.node.SimpleNode; //导入依赖的package包/类
/**
* @작성자 : KYJ
* @작성일 : 2017. 10. 14.
* @param url
* @return
* @throws Exception
*/
public static Template createTemplate(InputStream is) throws Exception {
String readFileToString = ValueUtil.toString(is);
RuntimeServices runtimeServices = RuntimeSingleton.getRuntimeServices();
StringReader reader = new StringReader(readFileToString);
SimpleNode node = runtimeServices.parse(reader, "URLTemplate");
Template template = new Template();
template.setRuntimeServices(runtimeServices);
template.setData(node);
template.initDocument();
return template;
}
示例8: create
import org.apache.velocity.runtime.parser.node.SimpleNode; //导入依赖的package包/类
public static Template create(String source, String templateName) throws ParseException {
RuntimeServices runtimeServices = RuntimeSingleton.getRuntimeServices();
StringReader reader = new StringReader(source);
SimpleNode node = runtimeServices.parse(reader, templateName);
Template template = new Template();
template.setRuntimeServices(runtimeServices);
template.setData(node);
template.initDocument();
return template;
}
示例9: toText
import org.apache.velocity.runtime.parser.node.SimpleNode; //导入依赖的package包/类
/**
* Returns the result of substituting the variables defined by the fields of this class
* (a concrete subclass of TemplateVars) into the template returned by {@link #parsedTemplate()}.
*/
String toText() {
VelocityContext velocityContext = toVelocityContext();
StringWriter writer = new StringWriter();
SimpleNode parsedTemplate = parsedTemplate();
boolean rendered = velocityRuntimeInstance.render(
velocityContext, writer, parsedTemplate.getTemplateName(), parsedTemplate);
if (!rendered) {
// I don't know when this happens. Usually you get an exception during rendering.
throw new IllegalArgumentException("Template rendering failed");
}
return writer.toString();
}
示例10: parsedTemplateForResource
import org.apache.velocity.runtime.parser.node.SimpleNode; //导入依赖的package包/类
static SimpleNode parsedTemplateForResource(String templateStr, String resourceName) {
try {
return velocityRuntimeInstance.parse(templateStr, resourceName);
} catch (ParseException e) {
throw new AssertionError(e);
}
}
示例11: parsedTemplateForString
import org.apache.velocity.runtime.parser.node.SimpleNode; //导入依赖的package包/类
static SimpleNode parsedTemplateForString(String string) {
try {
Reader reader = new StringReader(string);
return RuntimeSingleton.parse(reader, string);
} catch (ParseException e) {
throw new AssertionError(e);
}
}
示例12: compile
import org.apache.velocity.runtime.parser.node.SimpleNode; //导入依赖的package包/类
public static Object compile(String script, String name) {
try {
StringReader reader = new StringReader(script);
Template template = new Template();
SimpleNode node = engine.parse(reader, template);
template.setRuntimeServices(engine);
template.setData(node);
template.setName(name);
template.initDocument();
return template;
} catch (Exception ex) {
throw new BuilderException("Error parsing velocity script '" + name + "'", ex);
}
}
示例13: parsedTemplate
import org.apache.velocity.runtime.parser.node.SimpleNode; //导入依赖的package包/类
@Override
SimpleNode parsedTemplate() {
return TEMPLATE;
}
示例14: parsedTemplate
import org.apache.velocity.runtime.parser.node.SimpleNode; //导入依赖的package包/类
@Override SimpleNode parsedTemplate() {
return parsedTemplateForString("integer=$integer string=$string list=$list");
}