List of usage examples for org.apache.commons.vfs FileSystemManager resolveFile
public FileObject resolveFile(String name) throws FileSystemException;
From source file:pt.webdetails.cpf.repository.vfs.VfsRepositoryAccess.java
private FileObject setRepoPath(String path) { FileSystemManager fileSystemManager; try {// w w w .ja va 2 s.com if (!path.endsWith("" + File.separatorChar)) { path += File.separatorChar; } fileSystemManager = VFS.getManager(); FileObject fileObject; fileObject = fileSystemManager.resolveFile(path); if (fileObject == null) { throw new IOException("File cannot be resolved: " + path); } if (!fileObject.exists()) { throw new IOException("File does not exist: " + path); } return fileObject; } catch (Exception e) { log.error("Error setting path for repository: " + path, e); } return null; }
From source file:r.util.FileSystemUtils.java
public static FileObject workingDirectory(FileSystemManager fileSystemManager) { try {/*from w w w . j a v a 2s . com*/ return fileSystemManager.resolveFile(new File("").getAbsolutePath()); } catch (FileSystemException e) { throw new RuntimeException("Could not resolve current working directory", e); } }
From source file:uk.ac.liv.shaman.vfsme.CommonVFSMediaAdaptor.java
@Override public Object parse(INode parent) throws Exception { String html = null;/*from w ww . ja v a2 s. c o m*/ try { String pre = getExtension(); // Case for archive files if (pre != null) html = toHTML(pre); else { // case for files embedded in archives String s = getURI().toString(); int pos = s.lastIndexOf('/'); if (pos != -1) { s = s.substring(pos); pos = s.lastIndexOf('.'); if (pos != -1) s = s.substring(s.lastIndexOf('.')); else s = null; } else s = null; FileSystemManager m = VFS.getManager(); FileObject fo = m.resolveFile(getURI().toString()); // Workaround for loopy: loopy breaks when reading at the end of the input stram; // we stop at the lenght of the file to avoid an arrayindexoutofbound File f = Fab4utils.copyToTemp(fo.getContent().getInputStream(), "vfstemp", s, fo.getContent().getSize()); return Fab4utils.parseHelper(f, getURI(), getDocument(), parent); // FileInputStream is = new FileInputStream(f); // String mime = null; // String mime2 = null; // byte[] bufferData = new byte[Math.max(1024, FileGuess.minBytes)]; // int a; // MessageDigest md = null; // try { // md = MessageDigest.getInstance("MD5"); // } catch (NoSuchAlgorithmException e1) { // } // // while ((a = is.read(bufferData)) != -1) { // if (mime2 == null && a >= FileGuess.minBytes) { // mime2 = FileGuess // .guess(bufferData, getURI().toString()); // if (mime2 == null) // mime2 = ""; // } // if (md != null) // md.update(bufferData, 0, a); // } // is.close(); // is = new FileInputStream(f); // InputUni iu = InputUni.getInstance(is, getURI(), getGlobal() // .getCache()); // mime = iu.getContentType(); // byte[] digest = md.digest(); // 128 bit or 16 bytes // MediaLoader.MD5Cache.put(getURI(), digest); // MediaLoader.FileCache.put(getURI(), f); // if (mime == null // || mime.equalsIgnoreCase("application/octet-stream") // || mime.equals("text/html")) { // mime = mime2; // iu.setContentType(mime); // } // // String genre = getGlobal().getGenre(mime, getURI().toString()); // System.out.println(genre + " " + mime); // Layer dsl = getDocument().getLayers(); // Layer baseLayer = dsl.getInstance(Layer.BASE); // MediaAdaptor helper = (MediaAdaptor) Behavior.getInstance( // "helper", genre, null, baseLayer); // helper.setInput(iu); // float zoom = 1; // try { // zoom = Float.parseFloat(Multivalent.getInstance() // .getPreference(genre + "-zoom", "1")); // } catch (NumberFormatException nfe) { // } // helper.setZoom(zoom); // dsl.getInstance(genre); // // getDocument().setMediaAdaptor(helper); // // Node root = null; // try { // // root = (Node) helper.parse(parent); // } catch (Exception e) { // new LeafUnicode("ERROR " + e, null, parent); // // e.printStackTrace(); // } finally { // try { // helper.close(); // } catch (IOException ioe) { // } // } // // getDocument().removeAttr(Document.ATTR_LOADING); // return root; } } catch (Exception e) { e.printStackTrace(); html = e.toString(); } return parseHelper(html, "HTML", getLayer(), parent); }
From source file:uk.ac.liv.shaman.vfsme.CommonVFSMediaAdaptor.java
public String toHTML(String pre) throws IOException { URI u = getURI();//from w w w . ja va2s .c o m FileSystemManager m = VFS.getManager(); m.getSchemes(); String su = u.toString(); // if (pre.equals("iso:")) // su = su.replaceFirst("file:", ""); String uri = pre + su + "!"; System.out.println("VFS Open: " + uri); FileObject o = m.resolveFile(uri); StringBuilder sb = new StringBuilder(5000); sb.append("<html><head><style type=\"text/css\">\n" + "body {\n" + " color: black; background-color: white;\n" + " font-size: 14pts; /* Mozilla: 16 for proportional, 13 for fixed */\n" + " padding: 10px;}\n" + "\n" + "a:link { color: blue; }\n" + "a:visited { color: magenta; }\n" + "a:hover { color: red; }\n" + "a:active { color: red; }\n" + "\n" + "a:link, a:visited, \n" + "a:active, a:hover {\n" + " text-decoration: underline;\n" + "}\n" + "\n" + "p {\n" + " margin-top: 10px;\n" + "}\n" + "text { padding: 5px; }\n" + "\n" + "pre { font-family: monospace; }\n" + "\n\n" + "h1 { font-size: 24pt; font-weight: bold; margin: 10px 0px; }\n" + "h2 { font-size: 18pt; font-weight: bold; margin: 9px 0px; }\n" + "h3 { font-size: 14pt; font-weight: bold; margin: 7px 0px; }\n" + "h4 { font-size: 12pt; font-weight: bold; margin: 6px 0px; }\n" + "h5 { font-size: 10pt; font-weight: bold; margin: 5px 0px; }\n" + "h6 { font-size: 9pt; font-weight: bold; margin: 5px 0px; }\n" + "" + "" + "</style>"); sb.append("<title>").append("Contents of the archive").append(u.getPath()).append("</title>"); sb.append("\t<base href='").append(u).append("!/'>\n"); sb.append("</head>\n"); sb.append("<body>\n"); sb.append("<h2>").append("Contents of the archive").append(u.getPath()).append("</h2>"); sb.append("\n<pre><table width='90%'>\n"); // headers. click to sort sb.append("<tr><span Behavior='ScriptSpan' script='event tableSort <node>' title='Sort table'>"); sb.append( "<th align='left'>File / <b>Directory<th align='right'>Size<th align='right'>Last Modified</b></span>\n"); processChild(o, m, sb); sb.append("</table>\n</body></html>\n"); return sb.toString(); }
From source file:us.paulevans.basicxslt.Utils.java
/** * Returns the contents of the input XML file as an InputStream. Uses * Apache Jakarta commons-VFS to resolve the location. * @param aURI/*from ww w. j a v a 2s. c o m*/ * @return */ public static final byte[] getXMLContents(FileSystemManager aFSMgr, String aURI) throws IOException { FileObject file; FileContent content; file = aFSMgr.resolveFile(aURI); content = file.getContent(); return IOUtils.toByteArray(content.getInputStream()); }
From source file:us.paulevans.basicxslt.Utils.java
/** * Returns the contents of the input XSL file as a Source object. Uses * Apache Jakarta commons-VFS to resolve the location. * @param aURI/* w w w . j a v a 2s .co m*/ * @return */ public static final Source getXSLSource(FileSystemManager aFSMgr, String aURI) { FileObject file; FileContent content; try { file = aFSMgr.resolveFile(aURI); content = file.getContent(); return new StreamSource(content.getInputStream(), file.getURL().toURI().toString()); } catch (Throwable any) { throw new RuntimeException(any); } }