List of usage examples for org.apache.commons.io.filefilter FileFilterUtils directoryFileFilter
public static IOFileFilter directoryFileFilter()
From source file:org.geoserver.taskmanager.external.impl.FileServiceImpl.java
private ArrayList<String> listFolders(URI rootfolder, File file) { String[] folders = file.list(FileFilterUtils.directoryFileFilter()); ArrayList<String> paths = new ArrayList<>(); if (folders != null) { for (String folder : folders) { paths.add(Paths.get(rootfolder).relativize(Paths.get(file.toString(), folder)).toString()); paths.addAll(listFolders(rootfolder, new File(Paths.get(file.toString(), folder).toUri()))); }// w ww. ja va 2 s .c o m } return paths; }
From source file:org.geotools.gce.imagemosaic.catalogbuilder.CatalogBuilder.java
/** * @return/* www .jav a2s . c om*/ */ private IOFileFilter createGranuleFilterRules() { final IOFileFilter specialWildCardFileFilter = new WildcardFileFilter(runConfiguration.getWildcard(), IOCase.INSENSITIVE); IOFileFilter dirFilter = FileFilterUtils.andFileFilter(FileFilterUtils.directoryFileFilter(), HiddenFileFilter.VISIBLE); IOFileFilter fileFilter = Utils.excludeFilters( FileFilterUtils.makeSVNAware(FileFilterUtils.makeFileOnly( FileFilterUtils.andFileFilter(specialWildCardFileFilter, HiddenFileFilter.VISIBLE))), FileFilterUtils.suffixFileFilter("shp"), FileFilterUtils.suffixFileFilter("dbf"), FileFilterUtils.suffixFileFilter("shx"), FileFilterUtils.suffixFileFilter("qix"), FileFilterUtils.suffixFileFilter("lyr"), FileFilterUtils.suffixFileFilter("prj"), FileFilterUtils.nameFileFilter("error.txt"), FileFilterUtils.nameFileFilter("error.txt.lck"), FileFilterUtils.suffixFileFilter("properties"), FileFilterUtils.suffixFileFilter("svn-base")); // exclude common extensions Set<String> extensions = WorldImageFormat.getWorldExtension("png"); for (String ext : extensions) { fileFilter = FileFilterUtils.andFileFilter(fileFilter, FileFilterUtils.notFileFilter(FileFilterUtils.suffixFileFilter(ext.substring(1)))); } extensions = WorldImageFormat.getWorldExtension("gif"); for (String ext : extensions) { fileFilter = FileFilterUtils.andFileFilter(fileFilter, FileFilterUtils.notFileFilter(FileFilterUtils.suffixFileFilter(ext.substring(1)))); } extensions = WorldImageFormat.getWorldExtension("jpg"); for (String ext : extensions) { fileFilter = FileFilterUtils.andFileFilter(fileFilter, FileFilterUtils.notFileFilter(FileFilterUtils.suffixFileFilter(ext.substring(1)))); } extensions = WorldImageFormat.getWorldExtension("tiff"); for (String ext : extensions) { fileFilter = FileFilterUtils.andFileFilter(fileFilter, FileFilterUtils.notFileFilter(FileFilterUtils.suffixFileFilter(ext.substring(1)))); } extensions = WorldImageFormat.getWorldExtension("bmp"); for (String ext : extensions) { fileFilter = FileFilterUtils.andFileFilter(fileFilter, FileFilterUtils.notFileFilter(FileFilterUtils.suffixFileFilter(ext.substring(1)))); } //sdw fileFilter = FileFilterUtils.andFileFilter(fileFilter, FileFilterUtils.notFileFilter(FileFilterUtils.suffixFileFilter("sdw"))); //aux fileFilter = FileFilterUtils.andFileFilter(fileFilter, FileFilterUtils.notFileFilter(FileFilterUtils.suffixFileFilter("aux"))); //wld fileFilter = FileFilterUtils.andFileFilter(fileFilter, FileFilterUtils.notFileFilter(FileFilterUtils.suffixFileFilter("wld"))); //svn fileFilter = FileFilterUtils.andFileFilter(fileFilter, FileFilterUtils.notFileFilter(FileFilterUtils.suffixFileFilter("svn"))); final IOFileFilter finalFilter = FileFilterUtils.orFileFilter(dirFilter, fileFilter); return finalFilter; }
From source file:org.geotools.gce.imagemosaic.ImageMosaicDirectoryWalker.java
/** * @return/* w w w . ja v a2 s . c om*/ */ private IOFileFilter createDefaultGranuleExclusionFilter() { final IOFileFilter specialWildCardFileFilter = new WildcardFileFilter( configHandler.getRunConfiguration().getParameter(Prop.WILDCARD), IOCase.INSENSITIVE); IOFileFilter dirFilter = FileFilterUtils.and(FileFilterUtils.directoryFileFilter(), HiddenFileFilter.VISIBLE); IOFileFilter filesFilter = Utils.excludeFilters( FileFilterUtils.makeSVNAware(FileFilterUtils .makeFileOnly(FileFilterUtils.and(specialWildCardFileFilter, HiddenFileFilter.VISIBLE))), FileFilterUtils.suffixFileFilter("shp"), FileFilterUtils.suffixFileFilter("dbf"), FileFilterUtils.suffixFileFilter("sbn"), FileFilterUtils.suffixFileFilter("sbx"), FileFilterUtils.suffixFileFilter("shx"), FileFilterUtils.suffixFileFilter("qix"), FileFilterUtils.suffixFileFilter("lyr"), FileFilterUtils.suffixFileFilter("prj"), FileFilterUtils.nameFileFilter("error.txt"), FileFilterUtils.nameFileFilter("error.txt.lck"), FileFilterUtils.suffixFileFilter("properties"), FileFilterUtils.suffixFileFilter("svn-base"), FileFilterUtils.suffixFileFilter("ncx"), FileFilterUtils.suffixFileFilter("gbx9")); filesFilter = FileFilterUtils.or(filesFilter, FileFilterUtils.nameFileFilter("indexer.properties")); // exclude common extensions Set<String> extensions = WorldImageFormat.getWorldExtension("png"); for (String ext : extensions) { filesFilter = FileFilterUtils.and(filesFilter, FileFilterUtils.notFileFilter(FileFilterUtils.suffixFileFilter(ext.substring(1)))); } extensions = WorldImageFormat.getWorldExtension("gif"); for (String ext : extensions) { filesFilter = FileFilterUtils.and(filesFilter, FileFilterUtils.notFileFilter(FileFilterUtils.suffixFileFilter(ext.substring(1)))); } extensions = WorldImageFormat.getWorldExtension("jpg"); for (String ext : extensions) { filesFilter = FileFilterUtils.and(filesFilter, FileFilterUtils.notFileFilter(FileFilterUtils.suffixFileFilter(ext.substring(1)))); } extensions = WorldImageFormat.getWorldExtension("tiff"); for (String ext : extensions) { filesFilter = FileFilterUtils.and(filesFilter, FileFilterUtils.notFileFilter(FileFilterUtils.suffixFileFilter(ext.substring(1)))); } extensions = WorldImageFormat.getWorldExtension("bmp"); for (String ext : extensions) { filesFilter = FileFilterUtils.and(filesFilter, FileFilterUtils.notFileFilter(FileFilterUtils.suffixFileFilter(ext.substring(1)))); } // sdw filesFilter = FileFilterUtils.and(filesFilter, FileFilterUtils.notFileFilter(FileFilterUtils.suffixFileFilter("sdw")), FileFilterUtils.notFileFilter(FileFilterUtils.suffixFileFilter("aux")), FileFilterUtils.notFileFilter(FileFilterUtils.suffixFileFilter("wld")), FileFilterUtils.notFileFilter(FileFilterUtils.suffixFileFilter("svn"))); if (this.fileFilter != null) { filesFilter = FileFilterUtils.and(this.fileFilter, filesFilter); } final IOFileFilter finalFilter = FileFilterUtils.or(dirFilter, filesFilter); return finalFilter; }
From source file:org.geotools.gce.imagepyramid.Utils.java
static URL checkSource(Object source, Hints hints) { URL sourceURL = null;/*from w w w . j a v a2 s . c o m*/ File sourceFile = null; // // Check source // // if it is a URL or a String let's try to see if we can get a file to // check if we have to build the index if (source instanceof File) { sourceFile = (File) source; sourceURL = DataUtilities.fileToURL(sourceFile); } else if (source instanceof URL) { sourceURL = (URL) source; if (sourceURL.getProtocol().equals("file")) { sourceFile = DataUtilities.urlToFile(sourceURL); } } else if (source instanceof String) { // is it a File? final String tempSource = (String) source; File tempFile = new File(tempSource); if (!tempFile.exists()) { // is it a URL try { sourceURL = new URL(tempSource); source = DataUtilities.urlToFile(sourceURL); } catch (MalformedURLException e) { sourceURL = null; source = null; } } else { sourceURL = DataUtilities.fileToURL(tempFile); sourceFile = tempFile; } } else { // we really don't know how to convert the thing... give up if (LOGGER.isLoggable(Level.WARNING)) { LOGGER.warning("we really don't know how to convert the thing:" + source != null ? source.toString() : "null"); } return null; } // logging if (LOGGER.isLoggable(Level.INFO)) { if (sourceFile != null) { final String message = fileStatus(sourceFile); LOGGER.info(message); } } // // Handle cases where the pyramid descriptor file already exists // // can't do anything with it if (sourceFile == null || !sourceFile.exists()) return sourceURL; // if it's already a file we don't need to adjust it, will try to open as is if (!sourceFile.isDirectory()) return sourceURL; // it's a directory, let's see if it already has a pyramid description file inside File directory = sourceFile; sourceFile = new File(directory, directory.getName() + ".properties"); // logging if (LOGGER.isLoggable(Level.INFO)) { if (sourceFile != null) { final String message = fileStatus(sourceFile); LOGGER.info(message); } } if (sourceFile.exists()) return DataUtilities.fileToURL(sourceFile); // // Try to build the sub-folders mosaics // // if the structure of the directories is gdal_retile like, move the root files in their // own sub directory File zeroLevelDirectory = new File(directory, "0"); IOFileFilter directoryFilter = FileFilterUtils.directoryFileFilter(); File[] numericDirectories = directory.listFiles(new NumericDirectoryFilter()); File[] directories = directory.listFiles((FileFilter) directoryFilter); // do we have at least one sub-directory? if (directories.length == 0) { if (LOGGER.isLoggable(Level.INFO)) { LOGGER.info("I was unable to determine a structure similar to the GDAL Retile one!!"); } return null; } // check the gdal case and move files if necessary if (!zeroLevelDirectory.exists() && numericDirectories.length == directories.length) { LOGGER.log(Level.INFO, "Detected gdal_retile file structure, " + "moving root files to the '0' subdirectory"); if (zeroLevelDirectory.mkdir()) { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Created '0' subidr, now moving files"); } FileFilter notDirFilter = FileFilterUtils.notFileFilter(directoryFilter); for (File f : directory.listFiles(notDirFilter)) { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Moving file" + f.getAbsolutePath()); } if (LOGGER.isLoggable(Level.FINEST)) { LOGGER.finest(fileStatus(f)); } if (!f.renameTo(new File(zeroLevelDirectory, f.getName()))) LOGGER.log(Level.WARNING, "Could not move " + f.getAbsolutePath() + " to " + zeroLevelDirectory + " check the permission inside the source directory " + f.getParent() + " and target directory " + zeroLevelDirectory); } directories = directory.listFiles((FileFilter) directoryFilter); } else { if (LOGGER.isLoggable(Level.INFO)) { LOGGER.info( "I was unable to create the 0 directory. check the file permission in the parent directory:" + sourceFile.getParent()); } return null; } } // scan each subdirectory and try to build a mosaic in it, accumulate the resulting mosaics List<MosaicInfo> mosaics = new ArrayList<MosaicInfo>(); ImageMosaicFormat mosaicFactory = new ImageMosaicFormat(); for (File subdir : directories) { if (mosaicFactory.accepts(subdir, hints)) { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Trying to build mosaic for the directory:" + subdir.getAbsolutePath()); } mosaics.add(new MosaicInfo(subdir, mosaicFactory.getReader(subdir, hints))); } else { if (LOGGER.isLoggable(Level.INFO)) { LOGGER.info("Unable to build mosaic for the directory:" + subdir.getAbsolutePath()); } } } // do we have at least one level? if (mosaics.size() == 0) return null; // sort the mosaics by resolution and check they are actually in ascending resolution order // for both X and Y resolutions Collections.sort(mosaics); for (int i = 1; i < mosaics.size(); i++) { double[] resprev = mosaics.get(i - 1).getResolutions(); double[] res = mosaics.get(i).getResolutions(); if (resprev[1] > res[1]) { LOGGER.log(Level.INFO, "Invalid mosaic, y resolution in " + mosaics.get(i - 1).getPath() + " is greater than the one in " + mosaics.get(i).getPath() + " whilst x resolutions " + "have the opposite relationship"); return null; } } // // We have everything we need, build the final pyramid descriptor info // // build the property file Properties properties = new Properties(); properties.put("Name", directory.getName()); properties.put("LevelsNum", String.valueOf(mosaics.size())); StringBuilder sbDirNames = new StringBuilder(); StringBuilder sbLevels = new StringBuilder(); for (MosaicInfo mi : mosaics) { sbDirNames.append(mi.getName()).append(" "); double[] resolutions = mi.getResolutions(); sbLevels.append(resolutions[0]).append(",").append(resolutions[1]).append(" "); } properties.put("LevelsDirs", sbDirNames.toString()); properties.put("Levels", sbLevels.toString()); GeneralEnvelope envelope = mosaics.get(0).getEnvelope(); properties.put("Envelope2D", envelope.getMinimum(0) + "," + envelope.getMinimum(1) + " " + envelope.getMaximum(0) + "," + envelope.getMaximum(1)); OutputStream os = null; try { os = new FileOutputStream(sourceFile); properties.store(os, "Automatically generated"); } catch (IOException e) { LOGGER.log(Level.INFO, "We could not generate the pyramid propert file " + sourceFile.getPath(), e); return null; } finally { if (os != null) IOUtils.closeQuietly(os); } // build the .prj file if possible if (envelope.getCoordinateReferenceSystem() != null) { File prjFile = new File(directory, directory.getName() + ".prj"); PrintWriter pw = null; try { pw = new PrintWriter(new FileOutputStream(prjFile)); pw.print(envelope.getCoordinateReferenceSystem().toString()); } catch (IOException e) { LOGGER.log(Level.INFO, "We could not write out the projection file " + prjFile.getPath(), e); return null; } finally { pw.close(); } } return DataUtilities.fileToURL(sourceFile); }
From source file:org.jenkinsci.plugins.periodicbackup.ConfigOnly.java
@Override public Iterable<File> getFilesToBackup() throws PeriodicBackupException { File rootDir = Hudson.getInstance().getRootDir(); List<File> filesToBackup = Lists.newArrayList(); // First find the xml files in the home directory File[] xmlsInRoot = rootDir.listFiles(Util.extensionFileFilter("xml")); filesToBackup.addAll(Arrays.asList(xmlsInRoot)); File jobsDir = new File(rootDir, "jobs"); if (jobsDir.exists() && jobsDir.isDirectory()) { // Each job directory should have a config.xml file File[] dirsInJobs = jobsDir.listFiles((FileFilter) FileFilterUtils.directoryFileFilter()); for (File job : dirsInJobs) { File jobConfig = new File(job, "config.xml"); if (jobConfig.exists() && jobConfig.isFile()) { filesToBackup.add(jobConfig); } else { LOGGER.warning(jobConfig.getAbsolutePath() + " does not exist or is not a file."); }//from w ww .j av a2 s . c o m } } return filesToBackup; }
From source file:org.jumpmind.symmetric.model.FileTrigger.java
public IOFileFilter createIOFileFilter() { String[] includes = StringUtils.isNotBlank(includesFiles) ? includesFiles.split(",") : new String[] { "*" }; String[] excludes = StringUtils.isNotBlank(excludesFiles) ? excludesFiles.split(",") : null; IOFileFilter filter = new WildcardFileFilter(includes); if (excludes != null && excludes.length > 0) { List<IOFileFilter> fileFilters = new ArrayList<IOFileFilter>(); fileFilters.add(filter);/*from www. j av a2s .c o m*/ fileFilters.add(new NotFileFilter(new WildcardFileFilter(excludes))); filter = new AndFileFilter(fileFilters); } if (!recurse) { List<IOFileFilter> fileFilters = new ArrayList<IOFileFilter>(); fileFilters.add(filter); fileFilters.add(new NotFileFilter(FileFilterUtils.directoryFileFilter())); filter = new AndFileFilter(fileFilters); } else { List<IOFileFilter> fileFilters = new ArrayList<IOFileFilter>(); fileFilters.add(filter); fileFilters.add(FileFilterUtils.directoryFileFilter()); filter = new OrFileFilter(fileFilters); } return filter; }
From source file:org.jvnet.hudson.plugins.thinbackup.backup.HudsonBackup.java
private void backupBuildArchive(final File buildSrcDir, final File buildDestDir) throws IOException { if (plugin.isBackupBuildArchive()) { final File archiveSrcDir = new File(buildSrcDir, ARCHIVE_DIR_NAME); if (archiveSrcDir.isDirectory()) { final IOFileFilter filter = FileFilterUtils.or(FileFilterUtils.directoryFileFilter(), FileFilterUtils.and(FileFileFilter.FILE, getFileAgeDiffFilter())); FileUtils.copyDirectory(archiveSrcDir, new File(buildDestDir, "archive"), filter); }//from www .j a v a 2 s . c o m } }
From source file:org.jwebsocket.config.JWebSocketConfig.java
/** * @return the jWebSocketHome (environment variable or command line option) *//*from w w w. j av a 2 s.c om*/ public static String findJWebSocketHome() { // check Java property first // check if instance mJWebSocketHome is still null (not yet set) if (null == mJWebSocketHome) { mJWebSocketHome = System.getProperty(JWebSocketServerConstants.JWEBSOCKET_HOME); if (null != mJWebSocketHome) { System.out.println(JWebSocketServerConstants.JWEBSOCKET_HOME + ": Using property " + JWebSocketServerConstants.JWEBSOCKET_HOME + ": " + mJWebSocketHome); } } // if no Java property check environment variable if (null == mJWebSocketHome) { mJWebSocketHome = System.getenv(JWebSocketServerConstants.JWEBSOCKET_HOME); if (null != mJWebSocketHome) { System.out.println(JWebSocketServerConstants.JWEBSOCKET_HOME + ": Using environment variable " + JWebSocketServerConstants.JWEBSOCKET_HOME + ": " + mJWebSocketHome); } } // check current folders (only if not Web Application) if (!isWebApp() && null == mJWebSocketHome) { IOFileFilter lFileFilter = new WildcardFileFilter("jWebSocketServer*.jar"); IOFileFilter lDirFilter; lDirFilter = FileFilterUtils.directoryFileFilter(); Collection<File> lFiles; File lDir; // we are in development mode (NetBeans)? try { lDir = new File("../../../rte/jWebSocket-1.0/libs"); lFiles = FileUtils.listFiles(lDir, lFileFilter, lDirFilter); } catch (Exception lEx) { lFiles = null; } if (null != lFiles && !lFiles.isEmpty()) { lDir = new File("../../../rte/jWebSocket-1.0"); mJWebSocketHome = FilenameUtils.normalize(lDir.getAbsolutePath()); } else { // we are in the /libs folder? try { lDir = new File("."); lFiles = FileUtils.listFiles(lDir, lFileFilter, lDirFilter); } catch (Exception lEx) { lFiles = null; } if (null != lFiles && !lFiles.isEmpty()) { lDir = new File("../"); mJWebSocketHome = FilenameUtils.normalize(lDir.getAbsolutePath()); } else { // we are in the /bin folder? try { lDir = new File("../libs"); lFiles = FileUtils.listFiles(lDir, lFileFilter, lDirFilter); } catch (Exception lEx) { lFiles = null; } if (null != lFiles && !lFiles.isEmpty()) { lDir = new File("../"); mJWebSocketHome = FilenameUtils.normalize(lDir.getAbsolutePath()); } else { // we are in the base folder? try { lDir = new File("libs"); lFiles = FileUtils.listFiles(lDir, lFileFilter, lDirFilter); } catch (Exception lEx) { lFiles = null; } if (lFiles != null && !lFiles.isEmpty()) { lDir = new File("."); mJWebSocketHome = FilenameUtils.normalize(lDir.getAbsolutePath()); } } } } } // ensure that we get at least an empty string to avoid null pointer exceptions if (null == mJWebSocketHome) { mJWebSocketHome = ""; } adjustJWebSocketHome(); System.setProperty(JWebSocketServerConstants.JWEBSOCKET_HOME, mJWebSocketHome); return mJWebSocketHome; }
From source file:org.jwebsocket.plugins.filesystem.FileSystemPlugIn.java
/** * Gets the file list from a given alias an optionally from a sub path. * * @param aUsername The requester client username. * @param aToken//from w w w .j av a 2 s .c om * @return */ private Token mGetFilelist(WebSocketConnector aConnector, Token aToken) { String lAlias = aToken.getString("alias"); boolean lRecursive = aToken.getBoolean("recursive", false); boolean lIncludeDirs = aToken.getBoolean("includeDirs", false); List<Object> lFilemasks = aToken.getList("filemasks", new FastList<Object>()); String lSubPath = aToken.getString("path", null); Object lObject; String lBaseDir; Token lToken = TokenFactory.createToken(); lObject = mSettings.getAliasPath(lAlias); if (lObject != null) { lBaseDir = (String) lObject; lBaseDir = replaceAliasVars(aConnector, lBaseDir); /* lBaseDir = JWebSocketConfig.expandEnvVarsAndProps(lBaseDir). replace("{username}", aConnector.getUsername()); */ File lDir; if (null != lSubPath) { lDir = new File(lBaseDir + File.separator + lSubPath); } else { lDir = new File(lBaseDir + File.separator); } if (!isPathInFS(lDir, lBaseDir)) { lToken.setInteger("code", -1); lToken.setString("msg", "The path '" + lSubPath + "' is out of the file-system location!"); return lToken; } else if (!(lDir.exists() && lDir.isDirectory())) { lToken.setInteger("code", -1); lToken.setString("msg", "The path '" + lSubPath + "' is not directory on target '" + lAlias + "' alias!"); return lToken; } // IOFileFilter lFileFilter = FileFilterUtils.nameFileFilter(lFilemask); String[] lFilemaskArray = new String[lFilemasks.size()]; int lIdx = 0; for (Object lMask : lFilemasks) { lFilemaskArray[lIdx] = (String) lMask; lIdx++; } IOFileFilter lFileFilter = new WildcardFileFilter(lFilemaskArray); IOFileFilter lDirFilter = null; if (lRecursive) { lDirFilter = FileFilterUtils.directoryFileFilter(); } Collection<File> lFiles = FileUtils.listFilesAndDirs(lDir, lFileFilter, lDirFilter); List<Map> lFileList = new FastList<Map>(); File lBasePath = new File(lBaseDir); MimetypesFileTypeMap lMimesMap = new MimetypesFileTypeMap(); String lRelativePath; for (File lFile : lFiles) { if (lFile == lDir // we don't want directories to be returned // except explicitely requested || (!lIncludeDirs && lFile.isDirectory())) { continue; } Map<String, Object> lFileData = new FastMap<String, Object>(); String lFilename = lFile.getAbsolutePath().replace(lBasePath.getAbsolutePath() + File.separator, ""); // we always return the path in unix/url/java format String lUnixPath = FilenameUtils.separatorsToUnix(lFilename); int lSeparator = lUnixPath.lastIndexOf("/"); if (lSeparator != -1) { lFilename = lUnixPath.substring(lSeparator + 1); lRelativePath = lUnixPath.substring(0, lSeparator + 1); } else { lRelativePath = ""; } lFileData.put("relativePath", lRelativePath); lFileData.put("filename", lFilename); lFileData.put("size", lFile.length()); lFileData.put("modified", Tools.DateToISO8601(new Date(lFile.lastModified()))); lFileData.put("hidden", lFile.isHidden()); lFileData.put("canRead", lFile.canRead()); lFileData.put("canWrite", lFile.canWrite()); lFileData.put("directory", lFile.isDirectory()); lFileData.put("mime", lMimesMap.getContentType(lFile)); if (lAlias.equals(PRIVATE_ALIAS_DIR_KEY)) { lFileData.put("url", getString(ALIAS_WEB_ROOT_KEY, ALIAS_WEB_ROOT_DEF) // in URLs we only want forward slashes + FilenameUtils.separatorsToUnix(lFilename)); } lFileList.add(lFileData); } lToken.setList("files", lFileList); lToken.setInteger("code", 0); lToken.setString("msg", "ok"); } else { lToken.setInteger("code", -1); lToken.setString("msg", "No alias '" + lAlias + "' defined for filesystem plug-in"); } return lToken; }
From source file:org.jwebsocket.plugins.scripting.ScriptingPlugIn.java
/** * Deploy an application/*w w w . ja v a 2 s . com*/ * * @param aConnector * @param aToken * @throws Exception */ public void deployAction(WebSocketConnector aConnector, Token aToken) throws Exception { // getting calling arguments String lAppFile = aToken.getString("appFile"); boolean lDeleteAfterDeploy = aToken.getBoolean("deleteAfterDeploy", false); boolean lHotDeploy = aToken.getBoolean("hotDeploy", false); // getting the FSP instance TokenPlugIn lFSP = (TokenPlugIn) getPlugInChain().getPlugIn("jws.filesystem"); Assert.notNull(lFSP, "FileSystem plug-in is not running!"); // creating invoke request for FSP Token lCommand = TokenFactory.createToken(JWebSocketServerConstants.NS_BASE + ".plugins.filesystem", "getAliasPath"); lCommand.setString("alias", "privateDir"); Token lResult = lFSP.invoke(aConnector, lCommand); Assert.notNull(lResult, "Unable to communicate with the FileSystem plug-in " + "to retrieve the client private directory!"); // locating the app zip file File lAppZipFile = new File(lResult.getString("aliasPath") + File.separator + lAppFile); Assert.isTrue(lAppZipFile.exists(), "The target application file '" + lAppFile + "' does not exists" + " on the user file-system scope!"); // validating MIME type String lFileType = new MimetypesFileTypeMap().getContentType(lAppZipFile); Assert.isTrue("application/zip, application/octet-stream".contains(lFileType), "The file format is not valid! Expecting a ZIP compressed directory."); // umcompressing in TEMP unique folder File lTempDir = new File(FileUtils.getTempDirectory().getCanonicalPath() + File.separator + UUID.randomUUID().toString() + File.separator); try { Tools.unzip(lAppZipFile, lTempDir); if (lDeleteAfterDeploy) { lAppZipFile.delete(); } } catch (IOException lEx) { throw new Exception("Unable to uncompress zip file: " + lEx.getMessage()); } // validating structure File[] lTempAppDirContent = lTempDir.listFiles((FileFilter) FileFilterUtils.directoryFileFilter()); Assert.isTrue(1 == lTempAppDirContent.length && lTempAppDirContent[0].isDirectory(), "Compressed application has invalid directory structure! " + "Expecting a single root folder."); // executing before-load checks execAppBeforeLoadChecks(lTempAppDirContent[0].getName(), lTempAppDirContent[0].getPath()); // copying application content to apps directory File lAppDir = new File(mSettings.getAppsDirectory() + File.separator + lTempAppDirContent[0].getName()); FileUtils.copyDirectory(lTempAppDirContent[0], lAppDir); FileUtils.deleteDirectory(lTempDir); // getting the application name String lAppName = lAppDir.getName(); // checking security if (!hasAuthority(aConnector, NS + ".deploy.*") && !hasAuthority(aConnector, NS + ".deploy." + lAppName)) { sendToken(aConnector, createAccessDenied(aToken)); return; } // loading the script app loadApp(lAppName, lAppDir.getAbsolutePath(), lHotDeploy); // broadcasting event to other ScriptingPlugIn nodes MapMessage lMessage = getServer().getJMSManager().buildMessage(NS, ClusterMessageTypes.LOAD_APP.name()); lMessage.setStringProperty("appName", lAppName); lMessage.setBooleanProperty("hotLoad", lHotDeploy); lMessage.setStringProperty(Attributes.NODE_ID, JWebSocketConfig.getConfig().getNodeId()); // sending the message getServer().getJMSManager().send(lMessage); // finally send acknowledge response sendToken(aConnector, createResponse(aToken)); }