// private Map loadGlobFiles(List globPaths) throws IOException { private List loadGlobFiles(List globPaths) throws IOException { List ret = new LinkedList(); File fin; // URL u = getClass().getResource( "/META-INF/globs"); for (Iterator iter = globPaths.iterator(); iter.hasNext(); ) { String path = (String) iter.next(); BufferedReader in; if (path.indexOf("!") == -1) { if (false) { System.out.print("reading " + path + "... "); } fin = new File(path); in = new BufferedReader(new FileReader(fin)); if (false) { System.out.println("ok"); } } else { // System.out.println( "Voy por JarInputStream"); // System.out.println( "----> " + fin.getPath()); // in = new BufferedReader( new InputStreamReader( new JarInputStream( new URL( "jar:" + // fin.getPath()).openStream()))); // fin = new File( /*"jar:" +*/ path); // in = new BufferedReader( new InputStreamReader( new JarInputStream( new URL( // fin.getPath()).openStream()))); if (false) { System.out.print("reading default globs ... "); } try { in = new BufferedReader( new InputStreamReader(getClass().getResourceAsStream("/META-INF/globs"))); if (false) System.out.println("ok"); } catch (NullPointerException npe) { if (false) System.out.println("null error"); continue; } catch (Exception e) { if (false) System.out.println("error"); continue; } } String line; while ((line = in.readLine()) != null) { try { GlobElement globElement = new GlobElement(line); if (!globElement.isDiscard()) { ret.add(globElement); } } catch (ElementCreationException e) { // TODO Auto-generated catch block e.printStackTrace(); } } in.close(); } return ret; }
public String test(File file) { String mimetype = "application/octet-stream"; boolean findit = false; for (Iterator iter = this.glob.iterator(); iter.hasNext(); ) { GlobElement globElement = (GlobElement) iter.next(); findit = globElement.test(file, false); if (findit) { mimetype = globElement.getMimetype(); break; } } if (!findit) { for (Iterator iter = this.glob.iterator(); iter.hasNext(); ) { GlobElement globElement = (GlobElement) iter.next(); findit = globElement.test(file, true); if (findit) { mimetype = globElement.getMimetype(); break; } } } return mimetype; }