Search in sources :

Example 1 with RendererCompiler

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");
}
Also used : RendererCompiler(cn.bran.japid.rendererloader.RendererCompiler) JapidTemplateException(cn.bran.japid.exceptions.JapidTemplateException) CompilationException(play.exceptions.CompilationException) JapidCompilationException(cn.bran.japid.compiler.JapidCompilationException) IOException(java.io.IOException)

Example 2 with RendererCompiler

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");
}
Also used : RendererCompiler(cn.bran.japid.rendererloader.RendererCompiler) JarFile(java.util.jar.JarFile) File(java.io.File) TemplateClassLoader(cn.bran.japid.rendererloader.TemplateClassLoader) JapidTemplateException(cn.bran.japid.exceptions.JapidTemplateException) JapidCompilationException(cn.bran.japid.compiler.JapidCompilationException) IOException(java.io.IOException)

Example 3 with RendererCompiler

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");
}
Also used : RendererCompiler(cn.bran.japid.rendererloader.RendererCompiler) TemplateClassLoader(cn.bran.japid.rendererloader.TemplateClassLoader)

Aggregations

RendererCompiler (cn.bran.japid.rendererloader.RendererCompiler)3 JapidCompilationException (cn.bran.japid.compiler.JapidCompilationException)2 JapidTemplateException (cn.bran.japid.exceptions.JapidTemplateException)2 TemplateClassLoader (cn.bran.japid.rendererloader.TemplateClassLoader)2 IOException (java.io.IOException)2 File (java.io.File)1 JarFile (java.util.jar.JarFile)1 CompilationException (play.exceptions.CompilationException)1