use of cn.bran.japid.rendererloader.RendererCompiler in project Japid by branaway.
the class JapidPlayRenderer method init.
/**
* The <em>optional</em> initialization step in using the JapidRender.
*
* Users do not need to call this method to initialize this class. It takes
* "japidroot" as the default template root, which is relative to the
* application root.
*
* @param opMode
* the operational mode of Japid. When set to OpMode.prod, it's
* assumed that all Java derivatives are already been generated
* and used directly. When set to OpMode.dev, and using
* none-static linking to using the renderer, file system changes
* are detected for every rendering request given the refresh
* interval is respected. New Java files are generated and
* compiled and new classes are loaded to serve the request.
* @param templateRoot
* the root directory to contain the "japidviews" directory tree.
* It must be out of the "app" directory, or it will interfere
* with Play's class loading.
* @param refreshInterval
* the minimal time, in second, that must elapse before trying to
* detect any changes in the file system.
*/
public static void init(Mode opMode, String templateRoot, int refreshInterval) {
JapidFlags.info("JapidPlayRenderer initializing");
mode = opMode;
setTemplateRoot(templateRoot);
setRefreshInterval(refreshInterval);
initJapidClassLoader();
compiler = new RendererCompiler(japidClasses, japidClassLoader);
try {
refreshClasses();
} catch (Exception e) {
JapidFlags.warn("There was an error in refreshing the japid classes. Will show the error in detail in processing a request: " + e);
}
JapidFlags.info("JapidPlayRenderer inited");
}
use of cn.bran.japid.rendererloader.RendererCompiler in project japid42 by branaway.
the class JapidRenderer method init.
/**
* The <em>required</em> initialization step in using the JapidRender.
*
* @param opMode
* the operational mode of Japid. When set to OpMode.prod, it's
* assumed that all Java derivatives are already been generated
* and used directly. When set to OpMode.dev, and using
* none-static linking to using the renderer, file system changes
* are detected for every rendering request given the refresh
* interval is respected. New Java files are generated and
* compiled and new classes are loaded to serve the request.
* @param templateRoot
* the root directory to contain the "japidviews" directory tree.
* @param refreshInterval
* the minimal time, in second, that must elapse before trying to
* detect any changes in the file system.
* @param app
* the Play application instance
* @throws IOException
*/
public static void init(OpMode opMode, String[] templateRoot, int refreshInterval, Map<String, Object> app, ClassLoader clr) throws IOException {
specialClasses.clear();
showCurrentDirectory();
File cf = new File(".");
String path = cf.getAbsolutePath();
setClassCacheRoot(path);
japidResourceCompiled = false;
inited = true;
JapidRenderer.opMode = opMode == null ? OpMode.dev : opMode;
if (!rootsSet)
setTemplateRoot(templateRoot);
setRefreshInterval(refreshInterval);
boolean yesno = false;
try {
String property = (String) app.get("japid.trace.file.html");
if (property == null)
yesno = false;
else if ("on".equalsIgnoreCase(property) || "yes".equalsIgnoreCase(property))
yesno = true;
} catch (Exception e) {
}
JapidTemplateBaseWithoutPlay.globalTraceFileHtml = yesno;
try {
String property = (String) app.get("japid.trace.file.json");
if (property == null)
yesno = false;
else if ("on".equalsIgnoreCase(property) || "yes".equalsIgnoreCase(property))
yesno = true;
} catch (Exception e) {
}
JapidTemplateBaseWithoutPlay.globalTraceFileJson = yesno;
// System.out.println("parent classloader: " + clr);
parentClassLoader = clr;
TemplateClassLoader classLoader = getClassLoader();
compiler = new RendererCompiler(japidClasses, classLoader);
// if (usePlay)
// initErrorRenderer();
touch();
if (opMode == OpMode.dev)
recoverClasses();
dynamicClasses.clear();
DirUtil.curVersion = VERSION;
AbstractTemplateClassMetaData.curVersion = VERSION;
JapidFlags.debug("Before compiling Japid script from classpath. version " + VERSION);
setupImports();
compileJapidResources();
try {
refreshClasses();
} catch (Exception e) {
JapidFlags.log("There was an error in refreshing the japid classes. Will show the error in detail in processing a request: " + e);
}
System.out.println("[Japid] initialized version " + VERSION + " in " + getOpMode() + " mode");
}
use of cn.bran.japid.rendererloader.RendererCompiler in project Japid by branaway.
the class JapidRenderer method init.
/**
* The <em>required</em> initialization step in using the JapidRender.
*
* @param opMode
* the operational mode of Japid. When set to OpMode.prod, it's
* assumed that all Java derivatives are already been generated
* and used directly. When set to OpMode.dev, and using
* none-static linking to using the renderer, file system changes
* are detected for every rendering request given the refresh
* interval is respected. New Java files are generated and
* compiled and new classes are loaded to serve the request.
* @param templateRoot
* the root directory to contain the "japidviews" directory tree.
* @param refreshInterval
* the minimal time, in second, that must elapse before trying to
* detect any changes in the file system.
* @param usePlay
* to indicate if the generated template classes are to be used
* with play. if true, Play's implicit objects are available in
* the japid script.
*/
public static void init(OpMode opMode, String templateRoot, int refreshInterval, ClassLoader parentClassLoader, boolean usePlay) {
JapidRenderer.opMode = opMode;
setTemplateRoot(templateRoot);
setRefreshInterval(refreshInterval);
_parentClassLoader = parentClassLoader;
if (_parentClassLoader == null) {
_parentClassLoader = JapidRenderer.class.getClassLoader();
}
crlr = new TemplateClassLoader(parentClassLoader);
compiler = new RendererCompiler(classes, crlr);
JapidRenderer.usePlay = usePlay;
refreshClasses();
inited = true;
System.out.println("[Japid] initialized version " + VERSION + " in " + getOpMode() + " mode");
}
Aggregations