Search in sources :

Example 6 with VirtualFile

use of play.vfs.VirtualFile in project Japid by branaway.

the class PlayExceptionUtils method mapJapidJavaCodeError.

public static Exception mapJapidJavaCodeError(Exception ex) {
    if (ex instanceof CompilationException) {
        CompilationException e = (CompilationException) ex;
        if (!e.isSourceAvailable())
            return e;
        // now map java error to japidview source code
        String srcFilePath = e.getSourceFile();
        if (!srcFilePath.startsWith("/app/japidviews/")) {
            return e;
        } else if (!srcFilePath.endsWith("java")) {
            return e;
        }
        String viewSourceFilePath = DirUtil.mapJavaToSrc(srcFilePath);
        // File file = new File(viewSourceFilePath);
        VirtualFile vf = VirtualFile.fromRelativePath(viewSourceFilePath);
        int oriLineNumber = mapJavaErrorLineToSrcLine(e.getSourceVirtualFile().contentAsString(), e.getLineNumber());
        e = new CompilationException(vf, "\"" + e.getMessage() + "\"", oriLineNumber, 0, 0);
        return e;
    }
    return ex;
}
Also used : VirtualFile(play.vfs.VirtualFile) CompilationException(play.exceptions.CompilationException)

Example 7 with VirtualFile

use of play.vfs.VirtualFile in project play-cookbook by spinscale.

the class RenderPDF method getTemplateFile.

private VirtualFile getTemplateFile(Object... args) {
    final Http.Request request = Http.Request.current();
    String templateName = null;
    List<String> renderNames = LocalVariablesNamesTracer.getAllLocalVariableNames(args[0]);
    if (args.length > 0 && args[0] instanceof String && renderNames.isEmpty()) {
        templateName = args[0].toString();
    } else {
        templateName = request.action.replace(".", "/") + ".fo";
    }
    if (templateName.startsWith("@")) {
        templateName = templateName.substring(1);
        if (!templateName.contains(".")) {
            templateName = request.controller + "." + templateName;
        }
        templateName = templateName.replace(".", "/") + ".fo";
    }
    VirtualFile file = VirtualFile.search(Play.templatesPath, templateName);
    return file;
}
Also used : VirtualFile(play.vfs.VirtualFile) Request(play.mvc.Http.Request) Http(play.mvc.Http)

Aggregations

VirtualFile (play.vfs.VirtualFile)7 File (java.io.File)4 CompilationException (play.exceptions.CompilationException)3 JapidCompilationException (cn.bran.japid.compiler.JapidCompilationException)2 JapidTemplateException (cn.bran.japid.exceptions.JapidTemplateException)1 RendererClass (cn.bran.japid.rendererloader.RendererClass)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 Http (play.mvc.Http)1 Request (play.mvc.Http.Request)1