List of usage examples for org.apache.commons.vfs FileType equals
public boolean equals(Object obj)
From source file:net.sf.jvifm.ui.ZipLister.java
private void changeCurrentNode() { boolean hasMatchSelectedName = false; FileObject[] children = null; try {//from ww w . j a v a2s.c o m children = currentFileObject.getChildren(); } catch (Exception e) { e.printStackTrace(); } if (children == null) return; sortFiles(children); String selectedName = historyManager.getSelectedItem(currentFileObject.getName().getPath()); table.removeAll(); TableItem item; for (int i = 0; i < children.length; i++) { FileName fileName = children[i].getName(); if (fileName.getBaseName().equals(selectedName)) { currentRow = i; hasMatchSelectedName = true; } item = new TableItem(table, SWT.NONE); item.setData("fileObject", children[i]); item.setText(fileName.getBaseName()); try { FileType fileType = children[i].getType(); FileContent fileContent = children[i].getContent(); if (fileType.equals(FileType.FOLDER)) { item.setImage(folderImage); item.setText(1, "--"); item.setText(2, StringUtil.formatDate(fileContent.getLastModifiedTime())); } else { item.setImage(fileImage); item.setText(1, StringUtil.formatSize(fileContent.getSize())); item.setText(2, StringUtil.formatDate(fileContent.getLastModifiedTime())); } } catch (Exception e) { e.printStackTrace(); } } if (!hasMatchSelectedName) currentRow = 0; table.setSelection(currentRow); table.setFocus(); }
From source file:net.sf.jvifm.ui.ZipLister.java
private void sortFiles(FileObject[] children) { Arrays.sort(children, new Comparator() { public int compare(Object o1, Object o2) { try { FileType fileType1 = ((FileObject) o1).getType(); FileType fileType2 = ((FileObject) o2).getType(); String filename1 = ((FileObject) o1).getName().getBaseName(); String filename2 = ((FileObject) o2).getName().getBaseName(); if (fileType1.equals(FileType.FILE) && fileType2.equals(FileType.FOLDER)) { return 1; }//ww w. j a v a 2 s . com if (fileType2.equals(FileType.FILE) && fileType1.equals(FileType.FOLDER)) { return -1; } return filename1.compareTo(filename2); } catch (Exception e) { return 1; } } }); }
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 {//from w w w . j a va 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.org.eclipse.core.utils.platform.tools.ArchivesToolBox.java
private static void decompressFileObjectTo(FileObject fileObject, File targetFolder, IWriteHinter writeHinter) throws IOException { for (FileObject child : fileObject.getChildren()) { String childName = child.getName().getBaseName(); FileType type = child.getType(); if (type.equals(FileType.FOLDER)) { String folderName = writeHinter.alterFolderName(targetFolder, childName); File folder = new File(targetFolder, folderName); if (!folder.exists()) { folder.mkdirs();/* w ww.jav a 2 s . com*/ } decompressFileObjectTo(child, folder, writeHinter); } if (type.equals(FileType.FILE)) { String fileName = writeHinter.alterFileName(targetFolder, childName); File newFile = new File(targetFolder, fileName); newFile.createNewFile(); WriteMode writeMode = writeHinter.getFileWriteMode(newFile); if (writeMode != WriteMode.SKIP) { FileOutputStream fileOutputStream = new FileOutputStream(newFile); InputStream inputStream = child.getContent().getInputStream(); try { IOToolBox.inToOut(inputStream, fileOutputStream); } finally { inputStream.close(); fileOutputStream.close(); } } } } }
From source file:org.pentaho.s3.vfs.S3FileObject.java
public void doDelete() throws Exception { S3Object s3obj = getS3Object(false); bucket = getS3Bucket();/*from w w w . j a v a 2 s .c om*/ if (s3obj == null) { // If the selected object is null, getName() will cause exception. if (bucket != null) { // Therefore, take care of the delete bucket case, first. fileSystem.getS3Service().deleteBucket(bucket); } return; } if (getName().getPath().equals("") || getName().getPath().equals(DELIMITER)) { return; } String key = s3obj.getKey(); FileType filetype = getName().getType(); if (filetype.equals(FileType.FILE)) { fileSystem.getS3Service().deleteObject(bucket, key); // Delete a file. } else if (filetype.equals(FileType.FOLDER)) { key = key + DELIMITER; // Delete a folder. fileSystem.getS3Service().deleteObject(bucket, key); // The folder will not get deleted if its key does not end with DELIMITER. } else { return; } ((S3FileObject) getParent()).folders.remove(getName().getBaseName()); s3ChildrenMap.remove(getS3BucketName()); }