1 4 5 9 10 package org.openlaszlo.compiler; 11 import java.io.File ; 12 import java.util.Vector ; 13 import java.util.Enumeration ; 14 import org.openlaszlo.server.*; 15 import org.apache.log4j.*; 16 17 23 public interface FileResolver { 24 25 FileResolver DEFAULT_FILE_RESOLVER = new DefaultFileResolver(); 26 27 33 File resolve(String pathname, String base) 34 throws java.io.FileNotFoundException ; 35 } 36 37 42 class DefaultFileResolver implements FileResolver { 43 44 public DefaultFileResolver() { 45 } 46 47 48 public File resolve(String pathname, String base) 49 throws java.io.FileNotFoundException 50 { 51 Logger mLogger = Logger.getLogger(FileResolver.class); 52 53 final String FILE_PROTOCOL = "file"; 54 String protocol = FILE_PROTOCOL; 55 56 int pos = pathname.indexOf(':'); 59 if (pos > 1) { 60 protocol = pathname.substring(0, pos); 61 pathname = pathname.substring(pos + 1); 62 } 63 mLogger.debug("Resolving pathname: " + pathname + " and base: " + base); 64 if (!FILE_PROTOCOL.equals(protocol)) { 65 throw new CompilationError("unknown protocol: " + protocol); 66 } 67 68 69 File f = new File (base, pathname); 70 Vector v = new Vector (); 72 v.add(base); 73 if (!pathname.startsWith("./") && !pathname.startsWith("../")) { 74 v.add(LPS.getComponentsDirectory()); 75 v.add(LPS.getFontDirectory()); 76 v.add(LPS.getLFCDirectory()); 77 } 78 79 Enumeration e = v.elements(); 80 while (e.hasMoreElements()) { 81 String dir = (String )e.nextElement(); 82 f = new File (dir, pathname); 83 mLogger.debug("Trying " + f.getAbsolutePath()); 84 if (f.exists()) { 85 mLogger.debug("Resolving " + pathname + " to " + 87 f.getAbsolutePath()); 88 98 return f; 99 } 100 } 101 throw new java.io.FileNotFoundException (pathname); 102 } 103 } 104 | Popular Tags |