Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 1&1 Internet AG, https://github.com/1and1/ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 package net.oneandone.jasmin.main;
 
 
 import java.util.List;

Application configuration, factory for engines.
 
 public class Application {
     public static Application load(World worldServletConfig configFileNode docrootthrows Exception {
         String str;
         Node applicationDescriptor;
         boolean autoReload;
         Integer expires;
         Resolver resolver;
 
         str = getString(config"project"null);
         if (str != null) {
             throw new IOException("'project' parameter no longer supported");
         }
         autoReload = !"prod".equals(config.getServletContext().getInitParameter("mode"));
         autoReload = getBoolean(config"autoReload"autoReload);
         resolver = new Resolver(worldautoReload);
         applicationDescriptor = getApplicationDescriptor(configdocrootresolver);
         expires = getInteger(config"expires".);
         return new Application(config.getServletContext(), resolverapplicationDescriptorexpires);
     }
 
     public static FileNode file(World worldString strthrows IOException {
         if (str.endsWith("/")) {
             str = str.substring(0, str.length() - 1);
         }
         return world.file(new java.io.File(str).getCanonicalFile());
     }
 
     private static Node getApplicationDescriptor(ServletConfig configFileNode applicationResolver resolverthrows Exception {
         String explicit;
         Node result;
         Node resolvedProject;
 
         explicit = getString(config"projectDescriptor"null);
         if (explicit != null) {
             throw new IOException("'projectDescriptor' parameter no longer supported");
         }
         result = application.join(.);
         if (!result.exists()) {
             return null;
         }
         resolvedProject = resolver.resolve(applicationresult.getRelative(application));
         if (resolvedProject != null) {
             result = resolvedProject;
         }
         return result;
     }
 
     //--
 
     private final ServletContext context;
     public final Resolver resolver;

    
may be null.
 
     public final Node applicationDescriptor;

    
Response expires after the number of seconds specified here. Also used for Cache-Control: max-age. Null to disable expires header. See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
 
     public final Integer expires;
 
     public static final int MANY_YEARS = 60 * 60 * 24 * 365 * 15;
 
     public Application(ServletContext contextResolver resolverNode applicationDescriptorInteger expires) {
         this. = context;
         this. = resolver;
        this. = applicationDescriptor;
        this. = expires;
    }
    public String getContextPath() {
        return .getContextPath();
    }
    public Engine createEngineSimple(Node docrootNode localhostthrows IOException {
        return (EnginecreateEngine(docrootlocalhost)[0];
    }

    

Returns:
(engine, reloadFiles)
    public Object[] createEngine(Node docrootNode localhostthrows IOException {
        Repository repository;
        List<NodereloadFiles;
        .add(.docroot);
        .add(.localhost);
        try {
            repository = new Repository(new Attributes() {
                @Override
                public Object get(String name) {
                    return .getAttribute(name);
                }
            });
            repository.loadClasspath();
            if ( != null) {
                repository.loadApplication(docroot);
            }
            reloadFiles = repository.link();
            return new Object[] { new Engine(repository), reloadFiles };
        } catch (Throwable e) {
            .reset();
            throw e;
        }
    }
    //--
    private static Boolean getBoolean(ServletConfig configString keyboolean dflt) {
        String value;
        value = getString(configkeynull);
        if (value == null) {
            return dflt;
        }
        if ("true".equals(value)) {
            return true;
        } else if ("false".equals(value)) {
            return false;
        } else {
            throw new IllegalArgumentException(key + ": 'true' or 'false' expected, got '" + value + "'");
        }
    }
    private static Integer getInteger(ServletConfig configString keyInteger dflt) {
        String str;
        str = getString(configkeynull);
        return str == null ? dflt : Integer.valueOf(str);
    }
    private static String getString(ServletConfig configString keyString dflt) {
        String result;
        result = config.getInitParameter(key);
        return result == null ? dflt : result;
    }
New to GrepCode? Check out our FAQ X