xiaoma20082008 opened a new pull request #25:
URL: https://github.com/apache/velocity-engine/pull/25
I want to refactor the velocity with a more scalable API (for Users) and SPI
(for Developers), but I don't know whether it's needed, So I created this pr
for ensure it (Please tell me if you need otherwise please close this pr, Thank
you! ).
The target is:
1. compile the template(*.vm) to a java class(*.java), also provide a
interpreter like now.
2. the template#render will compile the generated java code to a java class
and execute it.
The sample usage For User:
```java
Template template = VelocityEngine.getTemplate(name, locale, encoding);
template.render(context, writer);
```
Sample Implementation is:
```java
Template getTemplate(String name, Locale locale, String encoding) {
// 0. cache
Resource r = cache.get(name);
// 1. load (the loader maybe is ClasspathLoader, FileLoader, JarLoader... )
r = loader.load(name, locale, encoding);
// 2. read a .vm file to string with encoding
String source = r.getSource();
// 3. convert xxs characters
source = converter.convert(name, source);
// 4. compile
Class<?> templateClass = compiler.compile(source); // maybe a
CompiledTemplate or a InterpretedTemplate
// 5. create template instance
return templateClass.getConstructor().newInstance();
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]