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.model;
 
 
 import java.util.Map;

Maps a file to a file node; handles live resources.
 
 public class Resolver {
     private World world;
     private final LiveResolver live;
     private final Map<BaseNodebases;
 
     public Resolver(World world) {
         this(worldfalse);
     }
 
     public Resolver(World worldboolean live) {
         this. = world;
         this. = live ? new LiveResolver() : null;
         this. = new HashMap<>();
     }
 
     public World getWorld() {
         return ;
     }
 
     //--
 
     public boolean isLife() {
         return  != null;
     }
 
     public FileNode getLiveXml() {
         java.io.File file;
 
         file =  .getLiveXmlFile();
         return file != null ? .file(file) : null;
     }
 
     //--
 
     public Node get(Base base) {
         return .get(base);
     }
 
     public void add(Base baseNode node) {
         if (.put(basenode) != null) {
             throw new IllegalArgumentException("already mapped: " + base);
         }
     }
 
     public void reset() {
         .clear();
     }
 
     //--
 
     public File resolve(Node classpathBaseResource resourcethrows IOException {
         Base base;
         Node baseResolved;
         Node normal;
         String minimizedPath;
         Node minimized;
 
         base = resource.getBase();
         if (base == .) {
             baseResolved = classpathBase;
         } else {
             baseResolved = .get(base);
         }
         if (baseResolved == null) {
             throw new IllegalStateException("unknown base: " + base.toString());
         }
         normal = resolve(baseResolvedresource.getPath());
        minimizedPath = resource.getMinPath();
        minimized = minimizedPath == null ? null : resolve(baseResolvedminimizedPath);
        return new File(normalminimizedresource.getType(), resource.getVariant());
    }
    public Node resolve(Node rootString paththrows IOException {
        try {
            return doResolve(rootpath);
        } catch (IOException | RuntimeException e) {
            throw e;
        } catch (Exception e) {
            throw new IOException("LifeResolver failed"e);
        }
    }
    private Node doResolve(Node rootString paththrows Exception {
        java.io.File file;
        FileNode resolvedRoot;
        WebdavRoot webdavRoot;
        int idx;
        String pathPart;
        String queryPart;
        Node result;
        if (path.startsWith("/")) {
            throw new IllegalArgumentException(path);
        }
        if (root instanceof WebdavNode) {
            webdavRoot = ((WebdavNoderoot).getRoot();
            idx = path.indexOf('?');
            if (idx == -1) {
                pathPart = path;
                queryPart = null;
            } else {
                pathPart = path.substring(0, idx);
                queryPart = path.substring(idx + 1);
            }
            if (!root.getPath().isEmpty()) {
                pathPart = webdavRoot.getFilesystem().join(root.getPath(), pathPart);
            }
            return webdavRoot.node(pathPartqueryPart);
        }
        if ( != null) {
            if (root instanceof FileNode) {
                file = .resolveLiveRoot(((FileNoderoot).getAbsolute(), "/" + path);
            } else if (root instanceof ZipNode) {
                file = .resolveLiveRoot(((ZipNoderoot).getRoot().getZip().getName(), "/" + path);
            } else {
                file = null;
            }
            if (file != null) {
                resolvedRoot = .file(file);
                result = resolvedRoot.join(path);
                if (result.exists()) {
                    return result;
                }
            }
        }
        return root.join(path);
    }
New to GrepCode? Check out our FAQ X