本文整理汇总了Java中org.rythmengine.Rythm类的典型用法代码示例。如果您正苦于以下问题:Java Rythm类的具体用法?Java Rythm怎么用?Java Rythm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Rythm类属于org.rythmengine包,在下文中一共展示了Rythm类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getInternalEngine
import org.rythmengine.Rythm; //导入依赖的package包/类
protected RythmEngine getInternalEngine() throws IOException{
Properties props = ConfigUtils.filterWithPrefix("docx4j.rythm.", "docx4j.rythm.", Docx4jProperties.getProperties(), false);
props.put("engine.mode", Rythm.Mode.valueOf(props.getProperty("engine.mode", "dev")));
props.put("log.enabled", false);
props.put("feature.smart_escape.enabled", false);
props.put("feature.transform.enabled", false);
try {
props.put("home.template", Rythm.class.getResource(props.getProperty("home.template")).toURI().toURL().getFile());
} catch (URISyntaxException e) {
// ignore
props.put("home.tmp", "/");
}
props.put("codegen.dynamic_exp.enabled", true);
props.put("built_in.code_type", "false");
props.put("built_in.transformer", "false");
props.put("engine.file_write", "false");
props.put("codegen.compact.enabled", "false");
return new RythmEngine(props);
}
开发者ID:vindell,项目名称:docx4j-template,代码行数:22,代码来源:WordprocessingMLRythmTemplate.java
示例2: RythmHtmlRenderer
import org.rythmengine.Rythm; //导入依赖的package包/类
public RythmHtmlRenderer() {
templateDir = new File(appConfig.getString("dirs.templates"));
templateExtension = appConfig.getString("app.templates.file-type");
Properties p = new Properties();
p.put("rythm.engine.mode", ApplicationStage.DEV.equals(appStage) ? Rythm.Mode.dev : Rythm.Mode.prod);
p.put("rythm.engine.class_loader.parent", Application.getAppClassLoader());
// p.put("rythm.resource.loader", new TemplateResourceLoader());
p.put("rythm.resource.name.suffix", templateExtension);
if (templateDir.exists()) {
p.put("rythm.home.template", templateDir);
}
File rythmHomeTmp = new File(appConfig.getString("dirs.gen-src"));
if (!rythmHomeTmp.exists() && !rythmHomeTmp.mkdirs()) {
throw new RuntimeException("Failed to create temporary directory for Rythm templates.");
}
p.put("rythm.home.tmp", rythmHomeTmp);
engine = new RythmEngine(p);
}
开发者ID:gzlabs,项目名称:hightide,代码行数:20,代码来源:RythmHtmlRenderer.java
示例3: processBody
import org.rythmengine.Rythm; //导入依赖的package包/类
public String processBody(String body) {
if (isBodyTemplatesEnabled()) {
final Map<String, String> rythmParams = new HashMap<String, String>();
for (String key : world.keys()) {
Optional<String> value = world.get(key);
if (value.isPresent() && body.contains("@" + key)) rythmParams.put(key, value.get());
}
return Rythm.render(body, rythmParams);
}
return body;
}
开发者ID:ctco,项目名称:cukes,代码行数:12,代码来源:TemplatingEngine.java
示例4: testSimple
import org.rythmengine.Rythm; //导入依赖的package包/类
@Test
public void testSimple() {
assertTrue(Rythm.engine().isProdMode());
// Inline template
assertEquals("Hello world!", render("Hello @who!", "world"));
assertEquals("Hello world!", substitute("Hello @who!", "world"));
assertEquals("Hello worldXXX", render("Hello @(who)XXX", "world"));
// outline template
assertEquals("<html>\n" +
"<head>\n" +
"<title>Hello world from Rythm</title>\n" +
"</head>\n" +
"<body>\n" +
"<h1>Hello World</h1>\n" +
"</body>\n" +
"</html>", render("org/n3r/sandbox/template/RythmHello.html", "World"));
String expected = "<html>\n" +
"<head>\n" +
"<title>Hello world from Rythm</title>\n" +
"</head>\n" +
"<body>\n" +
"<h1>Greeting World</h1>\n" +
"</body>\n" +
"</html>";
String template = "org/n3r/sandbox/template/RythmGreeting.html";
assertEquals(expected, render(template, "Greeting", "World"));
assertEquals(expected, render(template, of("action", "Greeting", "who", "World")));
// variable placeholder by index
assertEquals("Hello world war!", render("Hello @1 @2!", "world", "war"));
assertEquals("Hello worldwar!", render("Hello @(1)@(2)!", "world", "war"));
// variable placeholder by name
assertEquals("Hello world", render("Hello @who", of("who", "world")));
assertEquals("Hello world", render("Hello @who @//comment", of("who", "world")));
assertEquals("Hello world", render("Hello @who @*comment*@", of("who", "world")));
NamedParams np = NamedParams.instance;
assertEquals("Hello world", render("Hello @who", np.from(np.pair("who", "world"))));
}
开发者ID:bingoohuang,项目名称:javacode-demo,代码行数:44,代码来源:RythmTest.java
示例5: onActivate
import org.rythmengine.Rythm; //导入依赖的package包/类
@Override
public void onActivate( Application application )
throws ActivationException
{
Map<String, Object> conf = new HashMap<>();
// Rythm base configuration
conf.put(
ENGINE_PLUGIN_VERSION.getKey(),
BuildVersion.VERSION
);
conf.put(
ENGINE_MODE.getKey(),
application.mode() == Mode.DEV ? Rythm.Mode.dev : Rythm.Mode.prod
);
conf.put(
ENGINE_CLASS_LOADER_PARENT_IMPL.getKey(),
application.classLoader()
);
conf.put(
RESOURCE_DEF_LOADER_ENABLED.getKey(),
false
);
conf.put(
RESOURCE_LOADER_IMPLS.getKey(),
new NamedTemplateLoader( application, application.config().string( "rythm.base_path" ) )
);
conf.put(
LOG_FACTORY_IMPL.getKey(),
new SLF4JLoggerFactory()
);
// Load Rythm configuration, possibly overriding base configuration
conf.putAll( application.config().stringMap( "rythm.config" ) );
// Activate Rythm Engine
RythmEngine ryhtm = new RythmEngine( conf );
// Done!
templates = new RythmTemplates(
ryhtm,
application.config().bool( "rythm.metrics" )
? new TemplatesMetricsHandler.Impl( application.plugin( Metrics.class ).metrics(), "rythm" )
: TemplatesMetricsHandler.NOOP
);
}
开发者ID:werval,项目名称:werval,代码行数:47,代码来源:RythmPlugin.java
示例6: createRythmEngine
import org.rythmengine.Rythm; //导入依赖的package包/类
/**
* Prepare the RythmEngine instance and return it.
* @return the RythmEngine instance
* @throws java.io.IOException if the config file wasn't found
* @throws RythmException on Rythm initialization failure
*/
public RythmEngine createRythmEngine() throws IOException, RythmException {
Map<String, Object> p = new HashMap<String, Object>();
p.put(RythmConfigurationKey.ENGINE_PLUGIN_VERSION.getKey(), Version.VALUE);
// Load config file if set.
if (this.configLocation != null) {
logger.info("Loading Rythm config from [%s]", this.configLocation);
CollectionUtils.mergePropertiesIntoMap(PropertiesLoaderUtils.loadProperties(this.configLocation), p);
}
// Merge local properties if set.
if (!this.engineConfig.isEmpty()) {
p.putAll(this.engineConfig);
}
// Set dev mode
if (null == devMode) {
// check if devMode is set in engineConfig
String k = RythmConfigurationKey.ENGINE_MODE.getKey();
if (p.containsKey(k)) {
String s = p.get(k).toString();
devMode = Rythm.Mode.dev.name().equalsIgnoreCase(s);
} else {
devMode = getDevModeFromDevModeSensor();
}
}
Rythm.Mode mode = devMode ? Rythm.Mode.dev : Rythm.Mode.prod;
p.put(RythmConfigurationKey.ENGINE_MODE.getKey(), mode);
// Cache
p.put(RythmConfigurationKey.CACHE_ENABLED.getKey(), enableCache);
// Set a resource loader path, if required.
List<ITemplateResourceLoader> loaders = null;
if (this.resourceLoaderPath != null) {
loaders = new ArrayList<ITemplateResourceLoader>();
String[] paths = StringUtils.commaDelimitedListToStringArray(resourceLoaderPath);
for (String path : paths) {
loaders.add(new SpringResourceLoader(path, resourceLoader));
}
p.put(RythmConfigurationKey.RESOURCE_LOADER_IMPLS.getKey(), loaders);
p.put(RythmConfigurationKey.RESOURCE_DEF_LOADER_ENABLED.getKey(), false);
}
// the i18 message resolver
ApplicationContext ctx = getApplicationContext();
if (null != ctx) {
SpringI18nMessageResolver i18n = new SpringI18nMessageResolver();
i18n.setApplicationContext(getApplicationContext());
p.put(RythmConfigurationKey.I18N_MESSAGE_RESOLVER.getKey(), i18n);
}
configRythm(p);
// Apply properties to RythmEngine.
RythmEngine engine = newRythmEngine(p);
if (null != loaders) {
for (ITemplateResourceLoader loader : loaders) {
loader.setEngine(engine);
}
}
postProcessRythmEngine(engine);
return engine;
}
开发者ID:rythmengine,项目名称:spring-rythm,代码行数:76,代码来源:RythmEngineFactory.java
注:本文中的org.rythmengine.Rythm类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论