Java Code Examples for play.vfs.VirtualFile#isDirectory()

The following examples show how to use play.vfs.VirtualFile#isDirectory() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TemplateLoader.java    From restcommander with Apache License 2.0 6 votes vote down vote up
private static void scan(List<Template> templates, VirtualFile current) {
    if (!current.isDirectory() && !current.getName().startsWith(".") && !current.getName().endsWith(".scala.html")) {
        long start = System.currentTimeMillis();
        Template template = load(current);
        if (template != null) {
            try {
                template.compile();
                if (Logger.isTraceEnabled()) {
                    Logger.trace("%sms to load %s", System.currentTimeMillis() - start, current.getName());
                }
            } catch (TemplateCompilationException e) {
                Logger.error("Template %s does not compile at line %d", e.getTemplate().name, e.getLineNumber());
                throw e;
            }
            templates.add(template);
        }
    } else if (current.isDirectory() && !current.getName().startsWith(".")) {
        for (VirtualFile virtualFile : current.list()) {
            scan(templates, virtualFile);
        }
    }
}
 
Example 2
Source File: ApplicationClassloader.java    From restcommander with Apache License 2.0 5 votes vote down vote up
void scan(List<ApplicationClass> classes, String packageName, VirtualFile current) {
    if (!current.isDirectory()) {
        if (current.getName().endsWith(".java") && !current.getName().startsWith(".")) {
            String classname = packageName + current.getName().substring(0, current.getName().length() - 5);
            classes.add(Play.classes.getApplicationClass(classname));
        }
    } else {
        for (VirtualFile virtualFile : current.list()) {
            scan(classes, packageName + current.getName() + ".", virtualFile);
        }
    }
}
 
Example 3
Source File: ApplicationClassloader.java    From restcommander with Apache License 2.0 5 votes vote down vote up
void scanPrecompiled(List<ApplicationClass> classes, String packageName, VirtualFile current) {
    if (!current.isDirectory()) {
        if (current.getName().endsWith(".class") && !current.getName().startsWith(".")) {
            String classname = packageName.substring(5) + current.getName().substring(0, current.getName().length() - 6);
            classes.add(new ApplicationClass(classname));
        }
    } else {
        for (VirtualFile virtualFile : current.list()) {
            scanPrecompiled(classes, packageName + current.getName() + ".", virtualFile);
        }
    }
}
 
Example 4
Source File: ClassStateHashCreator.java    From restcommander with Apache License 2.0 5 votes vote down vote up
private void scan(StringBuffer buf, VirtualFile current) {
    if (!current.isDirectory()) {
        if (current.getName().endsWith(".java")) {
            buf.append( getClassDefsForFile(current));
        }
    } else if (!current.getName().startsWith(".")) {
        // TODO: we could later optimizie it further if we check if the entire folder is unchanged
        for (VirtualFile virtualFile : current.list()) {
            scan(buf, virtualFile);
        }
    }
}
 
Example 5
Source File: ServletWrapper.java    From restcommander with Apache License 2.0 5 votes vote down vote up
public void serveStatic(HttpServletResponse servletResponse, HttpServletRequest servletRequest, RenderStatic renderStatic) throws IOException {

        VirtualFile file = Play.getVirtualFile(renderStatic.file);
        if (file == null || file.isDirectory() || !file.exists()) {
            serve404(servletRequest, servletResponse, new NotFound("The file " + renderStatic.file + " does not exist"));
        } else {
            servletResponse.setContentType(MimeTypes.getContentType(file.getName()));
            boolean raw = Play.pluginCollection.serveStatic(file, Request.current(), Response.current());
            if (raw) {
                copyResponse(Request.current(), Response.current(), servletRequest, servletResponse);
            } else {
                if (Play.mode == Play.Mode.DEV) {
                    servletResponse.setHeader("Cache-Control", "no-cache");
                    servletResponse.setHeader("Content-Length", String.valueOf(file.length()));
                    if (!servletRequest.getMethod().equals("HEAD")) {
                        copyStream(servletResponse, file.inputstream());
                    } else {
                        copyStream(servletResponse, new ByteArrayInputStream(new byte[0]));
                    }
                } else {
                    long last = file.lastModified();
                    String etag = "\"" + last + "-" + file.hashCode() + "\"";
                    if (!isModified(etag, last, servletRequest)) {
                        servletResponse.setHeader("Etag", etag);
                        servletResponse.setStatus(304);
                    } else {
                        servletResponse.setHeader("Last-Modified", Utils.getHttpDateFormatter().format(new Date(last)));
                        servletResponse.setHeader("Cache-Control", "max-age=" + Play.configuration.getProperty("http.cacheControl", "3600"));
                        servletResponse.setHeader("Etag", etag);
                        copyStream(servletResponse, file.inputstream());
                    }
                }
            }
        }
    }
 
Example 6
Source File: PlayGrizzlyAdapter.java    From restcommander with Apache License 2.0 4 votes vote down vote up
public void serveStatic(GrizzlyRequest grizzlyRequest, GrizzlyResponse grizzlyResponse, RenderStatic renderStatic) {
    VirtualFile file = Play.getVirtualFile(renderStatic.file);
    if (file == null || file.isDirectory() || !file.exists()) {
        serve404(grizzlyRequest, grizzlyResponse, new NotFound("The file " + renderStatic.file + " does not exist"));
    } else {
        grizzlyResponse.setContentType(MimeTypes.getContentType(file.getName()));
        boolean raw = false;
        for (PlayPlugin plugin : Play.plugins) {
            if (plugin.serveStatic(file, Request.current(), Response.current())) {
                raw = true;
                break;
            }
        }
        try {
            if (raw) {
                copyResponse(Request.current(), Response.current(), grizzlyRequest, grizzlyResponse);
            } else {
                if (Play.mode == Play.Mode.DEV) {
                    grizzlyResponse.setHeader("Cache-Control", "no-cache");
                    grizzlyResponse.setHeader("Content-Length", String.valueOf(file.length()));
                    if (!grizzlyRequest.getMethod().equals("HEAD")) {
                        copyStream(grizzlyResponse, file.inputstream());
                    } else {
                        copyStream(grizzlyResponse, new ByteArrayInputStream(new byte[0]));
                    }
                } else {
                    long last = file.lastModified();
                    String etag = "\"" + last + "-" + file.hashCode() + "\"";
                    if (!isModified(etag, last, grizzlyRequest)) {
                        grizzlyResponse.setHeader("Etag", etag);
                        grizzlyResponse.setStatus(304);
                    } else {
                        grizzlyResponse.setHeader("Last-Modified", Utils.getHttpDateFormatter().format(new Date(last)));
                        grizzlyResponse.setHeader("Cache-Control", "max-age=" + Play.configuration.getProperty("http.cacheControl", "3600"));
                        grizzlyResponse.setHeader("Etag", etag);
                        copyStream(grizzlyResponse, file.inputstream());
                    }
                }

            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}