Package yalp.vfs

Examples of yalp.vfs.VirtualFile


            throw new RuntimeException(e);
        }
    }

    public void serveStatic(GrizzlyRequest grizzlyRequest, GrizzlyResponse grizzlyResponse, RenderStatic renderStatic) {
        VirtualFile file = Yalp.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 (YalpPlugin plugin : Yalp.plugins) {
                if (plugin.serveStatic(file, Request.current(), Response.current())) {
                    raw = true;
                    break;
                }
            }
            try {
                if (raw) {
                    copyResponse(Request.current(), Response.current(), grizzlyRequest, grizzlyResponse);
                } else {
                    if (Yalp.mode == Yalp.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=" + Yalp.configuration.getProperty("http.cacheControl", "3600"));
                            grizzlyResponse.setHeader("Etag", etag);
                            copyStream(grizzlyResponse, file.inputstream());
                        }
                    }

                }
            } catch (IOException e) {
View Full Code Here


        Template template = null;
        for (VirtualFile vf : Yalp.templatesPath) {
            if (vf == null) {
                continue;
            }
            VirtualFile tf = vf.child(path);
            if (tf.exists()) {
                template = TemplateLoader.load(tf);
                break;
            }
        }
        /*
        if (template == null) {
        //When using the old 'key = (file.relativePath().hashCode() + "").replace("-", "M");',
        //the next line never return anything, since all values written to templates is using the
        //above key.
        //when using just file.relativePath() as key, the next line start returning stuff..
        //therefor I have commented it out.
        template = templates.get(path);
        }
         */
        //TODO: remove ?
        if (template == null) {
            VirtualFile tf = Yalp.getVirtualFile(path);
            if (tf != null && tf.exists()) {
                template = TemplateLoader.load(tf);
            } else {
                throw new TemplateNotFoundException(path);
            }
        }
View Full Code Here

        List<Template> res = new ArrayList<Template>();
        for (VirtualFile virtualFile : Yalp.templatesPath) {
            scan(res, virtualFile);
        }
        for (VirtualFile root : Yalp.roots) {
            VirtualFile vf = root.child("conf/routes");
            if (vf != null && vf.exists()) {
                Template template = load(vf);
                if (template != null) {
                    template.compile();
                }
            }
View Full Code Here

        boolean weShouldAddTheMainProject = false;

        for (String specificModule : specificModules) {
            if (Yalp.modules.containsKey(specificModule)) {
                VirtualFile moduleRoot = Yalp.modules.get(specificModule);

                if (moduleRoot.child("db/evolutions").exists()) {
                    modulesWithEvolutions.put(specificModule, moduleRoot.child("db/evolutions"));
                } else {
                    System.out.println("~ '" + specificModule + "' module doesn't have any evolutions scripts in it.");
                    System.out.println("~");
                    System.exit(-1);
                }
View Full Code Here

            Messages.defaults.putAll(IO.readUtf8Properties(is));
        } catch (Exception e) {
            Logger.warn("Defaults messsages file missing");
        }
        for (VirtualFile module : Yalp.modules.values()) {
            VirtualFile messages = module.child("conf/messages");
            if (messages != null && messages.exists()) {
                Messages.defaults.putAll(read(messages));
            }
        }
        VirtualFile appDM = Yalp.getVirtualFile("conf/messages");
        if (appDM != null && appDM.exists()) {
            Messages.defaults.putAll(read(appDM));
        }
        for (String locale : Yalp.langs) {
            Properties properties = new Properties();
            for (VirtualFile module : Yalp.modules.values()) {
                VirtualFile messages = module.child("conf/messages." + locale);
                if (messages != null && messages.exists()) {
                    properties.putAll(read(messages));
                }
            }
            VirtualFile appM = Yalp.getVirtualFile("conf/messages." + locale);
            if (appM != null && appM.exists()) {
                properties.putAll(read(appM));
            } else {
                Logger.warn("Messages file missing for locale %s", locale);
            }
            Messages.locales.put(locale, properties);
View Full Code Here

     * The format of the YAML file is constrained, see the Fixtures manual page
     *
     * @param name Name of a YAML file somewhere in the classpath (or conf/)
     */
    public static void loadModels(String name) {
        VirtualFile yamlFile = null;
        try {
            for (VirtualFile vf : Yalp.javaPath) {
                yamlFile = vf.child(name);
                if (yamlFile != null && yamlFile.exists()) {
                    break;
                }
            }
            if (yamlFile == null || !yamlFile.exists()) {
                throw new RuntimeException("Cannot load fixture " + name + ", the file was not found");
            }

            String renderedYaml = TemplateLoader.load(yamlFile).render();

View Full Code Here

        return (T) loadYaml(name, yaml);
    }

    @SuppressWarnings("unchecked")
    public static <T> T loadYaml(String name, Yaml yaml) {
        VirtualFile yamlFile = null;
        try {
            for (VirtualFile vf : Yalp.javaPath) {
                yamlFile = vf.child(name);
                if (yamlFile != null && yamlFile.exists()) {
                    break;
                }
            }
            InputStream is = Yalp.classloader.getResourceAsStream(name);
            if (is == null) {
View Full Code Here

                serialized.put(prefix + "." + key.toString(), r);
            } else if (value instanceof String && value.toString().matches("<<<\\s*\\{[^}]+}\\s*")) {
                Matcher m = Pattern.compile("<<<\\s*\\{([^}]+)}\\s*").matcher(value.toString());
                m.find();
                String file = m.group(1);
                VirtualFile f = Yalp.getVirtualFile(file);
                if (f != null && f.exists()) {
                    serialized.put(prefix + "." + key.toString(), new String[]{f.contentAsString()});
                }
            } else {
                serialized.put(prefix + "." + key.toString(), new String[]{value.toString()});
            }
        }
View Full Code Here

public class TestRunnerPlugin extends YalpPlugin {

    @Override
    public void onLoad() {
        VirtualFile appRoot = VirtualFile.open(Yalp.applicationPath);
        Yalp.javaPath.add(appRoot.child("test"));
        for (VirtualFile module : Yalp.modules.values()) {
            File modulePath = module.getRealFile();
            if (!modulePath.getAbsolutePath().startsWith(Yalp.frameworkPath.getAbsolutePath()) && !Yalp.javaPath.contains(module.child("test"))) {
                Yalp.javaPath.add(module.child("test"));
            }
View Full Code Here

       
        List<String> modules = new ArrayList();
        List<String> apis = new ArrayList();
        if (id.equals("home") && module == null) {
            for (String key : Yalp.modules.keySet()) {
                VirtualFile mr = Yalp.modules.get(key);
                VirtualFile home = mr.child("documentation/manual/" + "home.textile");
                if (home.exists()) {
                    modules.add(key);
                }
                if (mr.child("documentation/api/index.html").exists()) {
                    apis.add(key);
                }
View Full Code Here

TOP

Related Classes of yalp.vfs.VirtualFile

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.