List of usage examples for org.apache.commons.vfs2 FileObject getName
FileName getName();
From source file:org.esupportail.portlet.filemanager.services.vfs.VfsAccessImpl.java
@Override public String createFile(String parentPath, String title, String type, SharedUserPortletParameters userParameters) { try {//ww w .ja va 2 s .c o m FileObject parent = cd(parentPath, userParameters); FileObject child = parent.resolveFile(title); if (!child.exists()) { if ("folder".equals(type)) { child.createFolder(); log.info("folder " + title + " created"); } else { child.createFile(); log.info("file " + title + " created"); } return child.getName().getPath(); } else { log.info("file " + title + " already exists !"); } } catch (FileSystemException e) { log.info("can't create file because of FileSystemException : " + e.getMessage(), e); } return null; }
From source file:org.esupportail.portlet.filemanager.services.vfs.VfsAccessImpl.java
@Override public boolean moveCopyFilesIntoDirectory(String dir, List<String> filesToCopy, boolean copy, SharedUserPortletParameters userParameters) { try {//from w ww. ja v a 2s. c om FileObject folder = cd(dir, userParameters); for (String fileToCopyPath : filesToCopy) { FileObject fileToCopy = cd(fileToCopyPath, userParameters); FileObject newFile = folder.resolveFile(fileToCopy.getName().getBaseName()); if (copy) { newFile.copyFrom(fileToCopy, Selectors.SELECT_ALL); } else { fileToCopy.moveTo(newFile); } } return true; } catch (FileSystemException e) { log.warn("can't move/copy file because of FileSystemException : " + e.getMessage(), e); } return false; }
From source file:org.freedesktop.AbstractFreedesktopEntity.java
protected void init(FileObject... bases) { if (bases.length == 0) throw new IllegalArgumentException("Entity must have at least one base."); this.bases.addAll(Arrays.asList(bases)); String base = null;// w w w . j a v a 2 s .co m for (FileObject s : bases) { if (base == null) { base = s.getName().getBaseName(); } else if (!base.equals(s.getName().getBaseName())) { throw new IllegalArgumentException("All bases must have the same filename."); } } internalName = base; }
From source file:org.freedesktop.cursors.DefaultCursorService.java
protected Collection<CursorTheme> scanBase(FileObject base) throws IOException { List<CursorTheme> themes = new ArrayList<CursorTheme>(); for (FileObject dir : listDirs(base)) { FileObject cursorTheme = dir.resolveFile("cursor.theme"); FileObject cursorsDir = dir.resolveFile("cursors"); if (cursorTheme.exists() || cursorsDir.exists()) { try { themes.add(new CursorTheme(dir)); } catch (FileNotFoundException fnfe) { // Skip Log.debug("Skipping " + dir + " because index.theme is missing."); } catch (IOException ioe) { Log.warn("Invalid theme directory " + dir.getName().getPath() + "." + ioe.getMessage()); } catch (ParseException ioe) { Log.warn("Invalid theme definition in " + dir.getName().getPath() + ". " + ioe.getMessage()); }/*from w ww . jav a 2s . c om*/ } else { // Skip Log.debug("Skipping " + dir + " because it is an icon theme."); } } return themes; }
From source file:org.freedesktop.desktopentry.DefaultDesktopEntryService.java
protected Collection<DesktopEntry> scanBase(FileObject base) throws IOException { List<DesktopEntry> entries = new ArrayList<DesktopEntry>(); for (FileObject file : listEntries(base)) { try {//from w w w.ja v a2 s.co m entries.add(new DesktopEntry(file)); } catch (IOException ioe) { Log.warn("Invalid desktop entry directory " + file.getName().getPath() + ". " + ioe.getMessage()); } catch (ParseException ioe) { Log.warn("Invalid desktop entry in " + file.getName().getPath() + ". " + ioe.getMessage()); } } return entries; }
From source file:org.freedesktop.icons.DefaultIconService.java
protected Collection<IconTheme> scanBase(FileObject base) throws IOException { List<IconTheme> themes = new ArrayList<IconTheme>(); FileObject[] listDirs = listDirs(base); for (FileObject dir : listDirs) { // TODO cursor themes not supported here FileObject cursorTheme = dir.resolveFile("cursor.theme"); FileObject cursorsDir = dir.resolveFile("cursors"); if (cursorTheme.exists() || cursorsDir.exists()) { // Skip Log.debug("Skipping " + dir + " because it is a cursor theme."); continue; }/*from w ww . j a v a 2 s . c o m*/ try { themes.add(new IconTheme(dir)); } catch (FileNotFoundException fnfe) { // Skip Log.debug("Skipping " + dir + " because index.theme is missing."); } catch (IOException ioe) { Log.warn("Invalid theme directory " + dir.getName().getPath() + "." + ioe.getMessage()); } } return themes; }
From source file:org.freedesktop.icons.Directory.java
public Directory(IconTheme theme, String key, Properties properties) throws ParseException, IOException { this.key = key; this.theme = theme; if (!properties.containsKey(SIZE)) { throw new ParseException("Size entry is required.", 0); }//from ww w.j av a 2 s. c o m size = Integer.parseInt(properties.getProperty(SIZE)); context = properties.getProperty(CONTEXT); if (properties.containsKey(TYPE)) { String typeName = properties.getProperty(TYPE).toLowerCase(); try { type = Type.valueOf(typeName); } catch (IllegalArgumentException iae) { throw new ParseException("Invalid Type ' " + typeName + "' in " + key, 0); } } if (properties.containsKey(MAX_SIZE)) { maxSize = Integer.parseInt(properties.getProperty(MAX_SIZE)); } else { maxSize = size; } if (properties.containsKey(MIN_SIZE)) { minSize = Integer.parseInt(properties.getProperty(MIN_SIZE)); } else { minSize = size; } if (properties.containsKey(THRESHOLD)) { minSize = Integer.parseInt(properties.getProperty(THRESHOLD)); } for (FileObject base : theme.getBases()) { FileObject dirBase = base.resolveFile(getKey()); // Loop over the supported extensions so we get files in supported // extension order for (String extension : DefaultIconService.SUPPORTED_EXTENSIONS) { FileObject[] files = dirBase.findFiles(new ExtensionSelector(extension)); if (files != null) { for (FileObject file : files) { String name = file.getName().getBaseName(); int lidx = name.lastIndexOf('.'); String basename = name.substring(0, lidx); if (!cache.containsKey(basename)) { cache.put(basename, file); } } } } } }
From source file:org.freedesktop.mime.DefaultMIMEService.java
@Override protected Collection<MIMEEntry> scanBase(FileObject base) throws IOException { FileObject[] d = listDirs(base); MimeBase mimeBase = new MimeBase(); mimeBases.put(base, mimeBase);//w w w .j a va2 s . co m if (d != null) { for (FileObject dir : d) { String family = dir.getName().getBaseName(); if (!family.equals("packages")) { Log.debug("Scanning family " + family); FileObject[] t = dir.findFiles(new FileSelector() { public boolean traverseDescendents(FileSelectInfo info) throws Exception { return info.getDepth() == 0; } public boolean includeFile(FileSelectInfo info) throws Exception { return info.getFile().getName().getBaseName().toLowerCase().endsWith(".xml"); } }); for (FileObject type : t) { String typeName = type.getName().getBaseName().substring(0, type.getName().getBaseName().length() - 4); MIMEEntry entry = new MIMEEntry(family, typeName, type); Log.debug(" Adding type " + entry.getInternalName()); mimeBase.byType.put(entry.getInternalName(), entry); } } } } return mimeBase.byType.values(); }
From source file:org.freedesktop.mime.DefaultMIMEService.java
public MIMEEntry getMimeTypeForFile(FileObject file, boolean useMagic) throws IOException { // Directories are always inode/directory try {/*from w ww. j a va 2 s . c om*/ if (file.getType().equals(FileType.FOLDER)) { return getEntryForMimeType("inode/directory"); } } catch (FileSystemException e) { throw new Error(e); } // First try matching using glob pattterns try { MIMEEntry mimeTypeForPattern = getMimeTypeForPattern(file.getName().getPath()); if (mimeTypeForPattern != null) { return mimeTypeForPattern; } } catch (MagicRequiredException mre) { Log.debug("Conflicting match, magic required"); // Try and get exact match using magic if (useMagic) { for (GlobEntry ge : mre.getAlternatives()) { MagicEntry me = magicService.getEntity(ge.getInternalName()); if (me == null) { Log.debug("NO Mime Entry for " + ge.getInternalName()); } if (me != null && me.match(file)) { MIMEEntry entity = getEntity(me.getInternalName()); if (entity != null) { Log.debug("Will use " + entity.getName()); return entity; } } } } // Return the first one we have a mime entry for for (GlobEntry ge : mre.getAlternatives()) { Log.debug("Trying " + ge.getInternalName()); MIMEEntry me = getEntity(ge.getInternalName()); if (me != null) { Log.debug("NO Mime Entry for " + ge.getInternalName()); } else { Log.debug("Will use " + me.getInternalName()); return me; } } } /* * If the glob matching fails or results in multiple conflicting * mimetypes, read the contents of the file and do magic sniffing on it. */ // // Log.warn("Slow magic search for " + file.getName()); // for (MagicEntry me : magicService.getAllEntities()) { // if (me.match(file)) { // return getEntity(me.getInternalName()); // } // } if (useMagic) { return checkForTextOrBinary(file); } else { return getEntity("application/octet-stream"); } }
From source file:org.freedesktop.mime.FileObjectComparator.java
public int compare(FileObject o1, FileObject o2) { return o1.getName().compareTo(o2.getName()); }