List of usage examples for org.apache.commons.vfs FileType FILE_OR_FOLDER
FileType FILE_OR_FOLDER
To view the source code for org.apache.commons.vfs FileType FILE_OR_FOLDER.
Click Source Link
From source file:org.bibalex.gallery.storage.BAGStorage.java
public static List<String> listChildren(String dirUrlStr, FileType childrenType, int timeout) throws BAGException { try {/*from w w w. j a v a 2 s. c om*/ List<String> result; if (new URI(dirUrlStr).getScheme().startsWith("http")) { BasicHttpParams httpParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParams, timeout); DefaultHttpClient httpClient = new DefaultHttpClient(httpParams); try { result = listChildrenApacheHttpd(dirUrlStr, childrenType, httpClient); } finally { // When HttpClient instance is no longer needed, // shut down the connection manager to ensure // immediate deallocation of all system resources httpClient.getConnectionManager().shutdown(); } } else { result = new ArrayList<String>(); FileSystemManager fsMgr = VFS.getManager(); FileObject dir = fsMgr.resolveFile(dirUrlStr); final FileObject[] children = dir.getChildren(); for (final FileObject child : children) { if ((childrenType == FileType.FILE_OR_FOLDER) || (child.getType() == childrenType)) { result.add(child.getName().getBaseName()); } } } // TODO define a comparator that orders the files properly as in // http://forums.sun.com/thread.jspa?threadID=5289401 Collections.sort(result); return result; } catch (FileSystemException e) { throw new BAGException(e); } catch (URISyntaxException e) { throw new BAGException(e); } }
From source file:org.bibalex.gallery.storage.BAGStorage.java
protected static List<String> listChildrenApacheHttpd(String dirUrlStr, FileType childrenType, DefaultHttpClient httpclient) throws BAGException { ArrayList<String> result = new ArrayList<String>(); HttpGet httpReq = new HttpGet(dirUrlStr); try {//ww w. j a v a 2s . co m HttpResponse response = httpclient.execute(httpReq); if (response.getStatusLine().getStatusCode() / 100 != 2) { throw new BAGException("Connection error: " + response.getStatusLine().toString()); } // Get hold of the response entity HttpEntity entity = response.getEntity(); // If the response does not enclose an entity, there is no need // to bother about connection release if ((entity != null)) { entity = new BufferedHttpEntity(entity); if (entity.getContentType().getValue().startsWith("text/html")) { SAXBuilder saxBuilder = new SAXBuilder(); saxBuilder.setFeature("http://xml.org/sax/features/validation", false); saxBuilder.setFeature("http://xml.org/sax/features/namespaces", true); saxBuilder.setFeature("http://xml.org/sax/features/namespace-prefixes", true); String htmlresponse = EntityUtils.toString(entity); String xmlResponse = light_html2xml.Html2Xml(htmlresponse); Document doc = saxBuilder.build(new StringReader(xmlResponse)); XPath hrefXP = XPath.newInstance("//a/@href"); for (Object obj : hrefXP.selectNodes(doc)) { Attribute attr = (Attribute) obj; String name = attr.getValue(); if (name.startsWith("/")) { // parent dir continue; } else if (name.endsWith("/")) { if (childrenType.equals(FileType.FOLDER) || childrenType.equals(FileType.FILE_OR_FOLDER)) { result.add(name.substring(0, name.length() - 1)); } } else { if (childrenType.equals(FileType.FILE) || childrenType.equals(FileType.FILE_OR_FOLDER)) { result.add(name); } } } } } return result; } catch (IOException ex) { // In case of an IOException the connection will be released // back to the connection manager automatically throw new BAGException(ex); } catch (RuntimeException ex) { // In case of an unexpected exception you may want to abort // the HTTP request in order to shut down the underlying // connection and release it back to the connection manager. httpReq.abort(); throw ex; } catch (JDOMException e) { throw new BAGException(e); } finally { // connection closing is left for the caller to reuse connections } }
From source file:org.vivoweb.harvester.util.FileAide.java
/** * Determines if a folder is at the given path * @param path the path to determine if it is a folder * @return true if a folder, false otherwise * @throws IOException error resolving path *//*from w ww . jav a 2s.c o m*/ public static boolean isFolder(String path) throws IOException { FileType type = getFileObject(path).getType(); return (type == FileType.FOLDER || type == FileType.FILE_OR_FOLDER); }
From source file:org.vivoweb.harvester.util.FileAide.java
/** * Determines if a file is at the given path * @param path the path to determine if it is a file * @return true if a file, false otherwise * @throws IOException error resolving path *///from ww w .j a v a2s . c o m public static boolean isFile(String path) throws IOException { FileType type = getFileObject(path).getType(); return (type == FileType.FILE || type == FileType.FILE_OR_FOLDER); }