List of usage examples for org.springframework.util AntPathMatcher match
@Override public boolean match(String pattern, String path)
From source file:org.openflamingo.fs.hdfs.HdfsFileSystemServiceImpl.java
@Override public boolean renameDirectory(Context context, FileSystemCommand command) { ResourceBundleRetreiver bundle = getResourceBundle(context); String[] paths = StringUtils.splitPreserveAllTokens(context.getString("hdfs.delete.forbidden.paths"), ","); AntPathMatcher antPathMatcher = new AntPathMatcher(); for (String path : paths) { String pathToValid = command.getString("from"); boolean isMatch = antPathMatcher.match(path, pathToValid); if (isMatch) { throw new FileSystemException( bundle.message("S_FS_SERVICE", "INCLUDED_FOBIDDEN_RULES", pathToValid)); }//from w ww. ja v a2s .com } try { FileSystemProvider provider = getFileSystemProvider(context); boolean renamed = provider.rename(command.getString("from"), command.getString("to")); auditService.log(context, FileSystemType.HDFS, AuditType.RENAME, FileType.DIRECTORY, command.getString("from"), command.getString("to"), 0); return renamed; } catch (Exception ex) { throw new FileSystemException(bundle.message("S_FS_SERVICE", "CANNOT_RENAME_DIRECTORY"), ex); } }
From source file:org.openflamingo.fs.hdfs.HdfsFileSystemServiceImpl.java
@Override public boolean moveDirectory(Context context, FileSystemCommand command) { ResourceBundleRetreiver bundle = getResourceBundle(context); String[] paths = StringUtils.splitPreserveAllTokens(context.getString("hdfs.delete.forbidden.paths"), ","); AntPathMatcher antPathMatcher = new AntPathMatcher(); for (String path : paths) { String pathToValid = command.getString("to"); boolean isMatch = antPathMatcher.match(path, pathToValid); if (isMatch) { throw new FileSystemException( bundle.message("S_FS_SERVICE", "INCLUDED_FOBIDDEN_RULES", pathToValid)); }// w ww .j av a2s . co m } for (String path : paths) { String pathToValid = command.getString("from"); boolean isMatch = antPathMatcher.match(path, pathToValid); if (isMatch) { throw new FileSystemException( bundle.message("S_FS_SERVICE", "INCLUDED_FOBIDDEN_RULES", pathToValid)); } } try { FileSystemProvider provider = getFileSystemProvider(context); long length = getFileInfo(context, command.getString("from")).getLength(); boolean moved = provider.rename(command.getString("from"), command.getString("to")); auditService.log(context, FileSystemType.HDFS, AuditType.MOVE, FileType.DIRECTORY, command.getString("from"), command.getString("to"), length); return moved; } catch (Exception ex) { throw new FileSystemException(bundle.message("S_FS_SERVICE", "CANNOT_MOVE_DIRECTORY"), ex); } }
From source file:org.openflamingo.fs.hdfs.HdfsFileSystemServiceImpl.java
@Override public boolean copyDirectory(Context context, FileSystemCommand command) { ResourceBundleRetreiver bundle = getResourceBundle(context); String[] paths = StringUtils.splitPreserveAllTokens(context.getString("hdfs.delete.forbidden.paths"), ","); AntPathMatcher antPathMatcher = new AntPathMatcher(); for (String path : paths) { String pathToValid = command.getString("to"); boolean isMatch = antPathMatcher.match(path, pathToValid); if (isMatch) { throw new FileSystemException( bundle.message("S_FS_SERVICE", "INCLUDED_FOBIDDEN_RULES", pathToValid)); }/* ww w . j a v a 2 s .co m*/ } try { FileSystemProvider provider = getFileSystemProvider(context); boolean copied = provider.copy(command.getString("from"), command.getString("to")); auditService.log(context, FileSystemType.HDFS, AuditType.COPY, FileType.DIRECTORY, command.getString("from"), command.getString("to"), getFileInfo(context, command.getString("from")).getLength()); return copied; } catch (Exception ex) { throw new FileSystemException(bundle.message("S_FS_SERVICE", "CANNOT_COPY_DIRECTORY"), ex); } }
From source file:org.openflamingo.fs.hdfs.HdfsFileSystemServiceImpl.java
@Override public boolean renameFile(Context context, FileSystemCommand command) { ResourceBundleRetreiver bundle = getResourceBundle(context); String[] paths = StringUtils.splitPreserveAllTokens(context.getString("hdfs.delete.forbidden.paths"), ","); AntPathMatcher antPathMatcher = new AntPathMatcher(); for (String path : paths) { String pathToValid = FileUtils.getPath(command.getString("path")); boolean isMatch = antPathMatcher.match(path, pathToValid); if (isMatch) { throw new FileSystemException( bundle.message("S_FS_SERVICE", "INCLUDED_FOBIDDEN_RULES", pathToValid)); }//w w w .j a v a2s .c o m } try { FileSystemProvider provider = getFileSystemProvider(context); boolean renamed = provider.rename(command.getString("path"), command.getString("filename")); auditService.log(context, FileSystemType.HDFS, AuditType.RENAME, FileType.FILE, command.getString("path"), FileUtils.getPath(command.getString("path")) + "/" + command.getString("filename"), 0); return renamed; } catch (Exception ex) { throw new FileSystemException(bundle.message("S_FS_SERVICE", "CANNOT_LIST_FILES"), ex); } }
From source file:org.openflamingo.fs.hdfs.HdfsFileSystemServiceImpl.java
@Override public List<String> copyFiles(Context context, FileSystemCommand command) { ResourceBundleRetreiver bundle = getResourceBundle(context); String[] paths = StringUtils.splitPreserveAllTokens(context.getString("hdfs.delete.forbidden.paths"), ","); AntPathMatcher antPathMatcher = new AntPathMatcher(); for (String path : paths) { String destinationPath = command.getString("to"); String pathToValid = FileUtils.getPath(destinationPath); boolean isMatch = antPathMatcher.match(path, pathToValid); if (isMatch) { throw new FileSystemException( bundle.message("S_FS_SERVICE", "INCLUDED_FOBIDDEN_RULES", pathToValid)); }/*from ww w. j a v a 2 s.c o m*/ } try { FileSystemProvider provider = getFileSystemProvider(context); List<String> ps = (List<String>) command.getObject("from"); List<String> copied = new ArrayList(); for (String p : ps) { long length = getFileInfo(context, p).getLength(); boolean isCopied = provider.copy(p, command.getString("to")); if (isCopied) { copied.add(p); auditService.log(context, FileSystemType.HDFS, AuditType.COPY, FileType.FILE, p, command.getString("to"), length); } } return copied; } catch (Exception ex) { throw new FileSystemException(bundle.message("S_FS_SERVICE", "CANNOT_COPY_FILE"), ex); } }
From source file:org.openflamingo.fs.hdfs.HdfsFileSystemServiceImpl.java
@Override public List<String> moveFiles(Context context, FileSystemCommand command) { ResourceBundleRetreiver bundle = getResourceBundle(context); String[] paths = StringUtils.splitPreserveAllTokens(context.getString("hdfs.delete.forbidden.paths"), ","); AntPathMatcher antPathMatcher = new AntPathMatcher(); for (String path : paths) { String pathToValid = command.getString("to"); boolean isMatch = antPathMatcher.match(path, pathToValid); if (isMatch) { throw new FileSystemException( bundle.message("S_FS_SERVICE", "INCLUDED_FOBIDDEN_RULES", pathToValid)); }/*from w ww . j a va 2 s. c o m*/ } for (String path : paths) { String destinationPath = ((List<String>) command.getObject("from")).get(0); String pathToValid = FileUtils.getPath(destinationPath); boolean isMatch = antPathMatcher.match(path, pathToValid); if (isMatch) { throw new FileSystemException( bundle.message("S_FS_SERVICE", "INCLUDED_FOBIDDEN_RULES", pathToValid)); } } try { FileSystemProvider provider = getFileSystemProvider(context); List<String> ps = (List<String>) command.getObject("from"); List<String> moved = new ArrayList(); for (String p : ps) { long length = getFileInfo(context, p).getLength(); boolean isMoved = provider.move(p, command.getString("to")); if (isMoved) { moved.add(p); auditService.log(context, FileSystemType.HDFS, AuditType.MOVE, FileType.FILE, p, command.getString("to"), length); } } return moved; } catch (Exception ex) { throw new FileSystemException(bundle.message("S_FS_SERVICE", "CANNOT_MOVE_FILE"), ex); } }
From source file:org.openflamingo.fs.hdfs.HdfsFileSystemServiceImpl.java
@Override public List<String> deleteFiles(Context context, FileSystemCommand command) { ResourceBundleRetreiver bundle = getResourceBundle(context); String[] paths = StringUtils.splitPreserveAllTokens(context.getString("hdfs.delete.forbidden.paths"), ","); AntPathMatcher antPathMatcher = new AntPathMatcher(); String first = ((List<String>) command.getObject("path")).get(0); for (String path : paths) { String pathToValid = FileUtils.getPath(first); boolean isMatch = antPathMatcher.match(path, pathToValid); if (isMatch) { throw new FileSystemException( bundle.message("S_FS_SERVICE", "INCLUDED_FOBIDDEN_RULES", pathToValid)); }// ww w . j a va 2s .c om } try { FileSystemProvider provider = getFileSystemProvider(context); List<String> ps = (List<String>) command.getObject("path"); List<String> deleted = new ArrayList(); for (String p : ps) { long length = getFileInfo(context, p).getLength(); boolean isDeleted = provider.delete(p); if (isDeleted) { deleted.add(p); auditService.log(context, FileSystemType.HDFS, AuditType.DELETE, FileType.FILE, p, "", length); } } return deleted; } catch (Exception ex) { throw new FileSystemException(bundle.message("S_FS_SERVICE", "CANNOT_DELETE_FILE"), ex); } }
From source file:org.openflamingo.fs.hdfs.HdfsFileSystemServiceImpl.java
@Override public boolean save(Context context, FileSystemCommand command) { ResourceBundleRetreiver bundle = getResourceBundle(context); String[] paths = StringUtils.splitPreserveAllTokens(context.getString("hdfs.delete.forbidden.paths"), ","); AntPathMatcher antPathMatcher = new AntPathMatcher(); for (String path : paths) { String pathToValid = command.getString("path"); boolean isMatch = antPathMatcher.match(path, pathToValid); if (isMatch) { throw new FileSystemException( bundle.message("S_FS_SERVICE", "INCLUDED_FOBIDDEN_RULES", pathToValid)); }/* w w w.j a v a 2 s.com*/ } FileSystemProvider provider = getFileSystemProvider(context); if (provider.exists(command.getString("path"))) { throw new FileSystemException(bundle.message("S_FS_SERVICE", "ALREADY_EXISTS_FILE")); } try { boolean saved = provider.save(command.getString("path"), (byte[]) command.getObject("content")); auditService.log(context, FileSystemType.HDFS, AuditType.UPLOAD, FileType.FILE, command.getString("path"), "", getFileInfo(context, command.getString("path")).getLength()); return saved; } catch (Exception ex) { throw new FileSystemException(bundle.message("S_FS_SERVICE", "CANNOT_UPLOAD"), ex); } }