List of usage examples for org.apache.commons.io FilenameUtils normalize
public static String normalize(String filename, boolean unixSeparator)
From source file:org.pepstock.jem.node.executors.gfs.GetFilesList.java
/** * Extracts all files from a folder// www. ja v a2 s .c om * @param parentPath parentPath is path define as mount poit * @param parent parent requisted from user, to add to the mount point * @return lsit of files of folder */ private Collection<GfsFile> getFilesList(String parentPath, File parent) { // creates the collection of files and reads them Collection<GfsFile> list = new ArrayList<GfsFile>(); File[] files = parent.listFiles(); if (files != null && files.length > 0) { // scans all files and loads them into a collection, normalizing the names for (int i = 0; i < files.length; i++) { // checks if is sub folder boolean isDirectory = files[i].isDirectory(); String name = files[i].getName(); // gets the long name of file String longName = StringUtils.removeStart(FilenameUtils.normalize(files[i].getAbsolutePath(), true), FilenameUtils.normalize(parentPath, true)).substring(1); // creates a bean with of file information GfsFile file = new GfsFile(); file.setDirectory(isDirectory); file.setName(name); file.setLongName(longName); file.setLength((isDirectory) ? -1 : files[i].length()); file.setLastModified(files[i].lastModified()); // sets the data path name to be showed on user interface file.setDataPathName(Main.DATA_PATHS_MANAGER.getAbsoluteDataPathName(files[i].getAbsolutePath())); // adds to the collection to be returned list.add(file); } } return list; }
From source file:org.pepstock.jem.node.executors.jobs.GetOutputTree.java
/** * Reads file system and returns the tree of job log folder. * /*from w w w . j a v a 2s.c o m*/ * @return output tree * @throws if I/O error occurs */ @Override public OutputTree execute() throws ExecutorException { // gets the jcl file to extract the directory File jclFile; try { jclFile = Main.getOutputSystem().getJclFile(job); } catch (IOException e) { // messo il job ma il node file va messo throw new ExecutorException(NodeMessage.JEMC242E, e, job); } // checks if file exists otherwise exception occurs if (!jclFile.exists()) { throw new ExecutorException(NodeMessage.JEMC242E, jclFile); } // creates the empty result OutputTree tree = new OutputTree(); // get the folder of JCL. is folder used for job output File jobOutputFolder = jclFile.getParentFile(); // lists all files File[] files = jobOutputFolder.listFiles(); Arrays.sort(files, COMPARATOR); // scans all files of folder and load the result tree for (int i = 0; i < files.length; i++) { File file = files[i]; // ignores JCL file because is already inside the job and // due to you need this data in UI, doesn't make sense to download it if (!file.getName().equalsIgnoreCase(OutputSystem.JCL_FILE) && !file.getName().equalsIgnoreCase(OutputSystem.JOB_FILE)) { // if is not the directory (means not syslog of step) // this is the first level of folder if (!file.isDirectory()) { if (file.getName().equalsIgnoreCase(OutputSystem.JOBLOG_FILE) || file.getName().equalsIgnoreCase(OutputSystem.MESSAGESLOG_FILE)) { // creates the items and sets label (to show on UI) and relative path of file OutputListItem item = new OutputListItem(); String label = (file.getName().equalsIgnoreCase(OutputSystem.JOBLOG_FILE)) ? JEM_LOG_LABEL : JOB_LOG_LABEL; item.setLabel(label); String fileRelativePath = StringUtils.remove(file.getAbsolutePath(), Main.getOutputSystem().getOutputPath().getAbsolutePath()); item.setFileRelativePath(FilenameUtils.normalize(fileRelativePath, true)); // adds to first level tree.getFirstLevelItems().add(item); } } else { // checks the folder which represents the folder for all syslog of step // loads all files in second level List<OutputListItem> secondLevelItems = new ArrayList<OutputListItem>(); // gets all files of folder, scanning them File[] stepFiles = file.listFiles(); for (int k = 0; k < stepFiles.length; k++) { File stepFile = stepFiles[k]; // ignores directory. it shouldn't be present directory here if (!stepFile.isDirectory()) { // creates the items and sets label (to show on UI) and relative path of file OutputListItem item = new OutputListItem(); item.setLabel(stepFile.getName()); item.setParent(file.getName()); String fileRelativePath = StringUtils.remove(stepFile.getAbsolutePath(), Main.getOutputSystem().getOutputPath().getAbsolutePath()); item.setFileRelativePath(FilenameUtils.normalize(fileRelativePath, true)); secondLevelItems.add(item); } } // adds to second level tree.getSecondLevelItems().add(secondLevelItems); } } } return tree; }
From source file:org.pepstock.jem.node.security.BatchSecurityManager.java
@Override public final void checkExec(String cmd) { String permission = Permissions.FILES_EXECUTE + FilenameUtils.normalize(cmd, true); if (!checkBatchPermission(permission)) { LogAppl.getInstance().emit(NodeMessage.JEMC104E, cmd); throw new SecurityException(NodeMessage.JEMC104E.toMessage().getFormattedMessage(cmd)); }//from w ww. ja v a 2 s . c o m }
From source file:org.pepstock.jem.node.security.BatchSecurityManager.java
@Override public void checkRead(String file) { String normalizedFile = FilenameUtils.normalize(file, true); int result = utils.checkReadFileName(normalizedFile); if (result == SecurityUtils.TO_BE_CHECKED) { if (!checkBatchPermission(Permissions.FILES_READ + utils.normalizeFileName(normalizedFile))) { LogAppl.getInstance().emit(NodeMessage.JEMC104E, normalizedFile); throw new SecurityException(NodeMessage.JEMC104E.toMessage().getFormattedMessage(normalizedFile)); }// w ww.j av a2 s . c om } else if (result == SecurityUtils.TO_BE_REJECTED) { LogAppl.getInstance().emit(NodeMessage.JEMC104E, normalizedFile); throw new SecurityException(NodeMessage.JEMC104E.toMessage().getFormattedMessage(normalizedFile)); } }
From source file:org.pepstock.jem.node.security.BatchSecurityManager.java
@Override public void checkWrite(String file) { String normalizedFile = FilenameUtils.normalize(file, true); int result = utils.checkWriteFileName(normalizedFile); if (result == SecurityUtils.TO_BE_CHECKED) { if (!checkBatchPermission(Permissions.FILES_WRITE + utils.normalizeFileName(normalizedFile))) { LogAppl.getInstance().emit(NodeMessage.JEMC104E, normalizedFile); throw new SecurityException(NodeMessage.JEMC104E.toMessage().getFormattedMessage(normalizedFile)); }/*www . j ava 2 s . c om*/ } else if (result == SecurityUtils.TO_BE_REJECTED) { LogAppl.getInstance().emit(NodeMessage.JEMC104E, normalizedFile); throw new SecurityException(NodeMessage.JEMC104E.toMessage().getFormattedMessage(normalizedFile)); } else if ((result == SecurityUtils.TO_BE_GFS_CHECKED) && (!checkBatchPermission(utils.getGfsPermission(file)))) { LogAppl.getInstance().emit(NodeMessage.JEMC104E, normalizedFile); throw new SecurityException(NodeMessage.JEMC104E.toMessage().getFormattedMessage(normalizedFile)); } else if ((result == SecurityUtils.TO_BE_LOCAL_FS_CHECKED) && (!checkBatchPermission(Permissions.LOCAL_FILE_SYSTEM_ACCESS))) { LogAppl.getInstance().emit(NodeMessage.JEMC104E, normalizedFile); throw new SecurityException(NodeMessage.JEMC104E.toMessage().getFormattedMessage(normalizedFile)); } }
From source file:org.pepstock.jem.node.security.SecurityUtils.java
/** * Constructs the object creating the temporary folder, using the JEM node * Operating system configuration. /*from ww w . j av a 2s.com*/ */ public SecurityUtils() { try { // creates a temporary file only to the absolute path // of the file, used as temporary files folder // it doesn't use the system property to avoid errors if not set temp = FilenameUtils.normalize(File.createTempFile("security", "tmp").getParentFile().getAbsolutePath(), true); } catch (IOException e) { // debug LogAppl.getInstance().debug(e.getMessage(), e); } }
From source file:org.pepstock.jem.node.StartUpSystem.java
/** * loads the environment configuration from configuration file, present in * the gfs, which is defined by a system property. * //from ww w. j a va2 s . c o m * @throws ConfigurationException */ private static void loadEnvConfiguration() throws ConfigurationException { // loads configuration file from node folder. // if doesn't exist, exception String configFile = System.getProperty(ConfigKeys.JEM_ENV_CONF); if (configFile == null) { LogAppl.getInstance().emit(NodeMessage.JEMC005E, ConfigKeys.JEM_ENV_CONF); throw new ConfigurationException( NodeMessage.JEMC005E.toMessage().getFormattedMessage(ConfigKeys.JEM_CONFIG)); } File fileConfig = new File(configFile); String xmlConfig = null; try { xmlConfig = FileUtils.readFileToString(fileConfig, CharSet.DEFAULT_CHARSET_NAME); } catch (IOException e) { LogAppl.getInstance().emit(NodeMessage.JEMC006E); throw new ConfigurationException(NodeMessage.JEMC006E.toMessage().getMessage(), e); } PROPERTIES.setProperty(ConfigKeys.JEM_ENV_CONF_FOLDER, FilenameUtils.normalize(fileConfig.getParent(), true)); JEM_ENV_CONFIG = Configuration.unmarshall(xmlConfig); LogAppl.getInstance().emit(NodeMessage.JEMC008I, configFile); loadDatabaseManagers(); loadNode(); loadFactories(); loadListeners(); loadResourceConfigurations(); }
From source file:org.pepstock.jem.node.StartUpSystem.java
/** * Normalize the path put in configuration, changing all separators * /*from www. j a v a 2 s. c o m*/ * @param path path to normalize * @return normalized path */ private static String normalizePath(String path) { File file = new File(path); return FilenameUtils.normalize(file.getAbsolutePath(), true); }
From source file:org.pepstock.jem.node.tasks.DefaultJobTask.java
@Override public void configure() throws IOException { // gets joib//from w w w .j a v a 2 s . c om Job job = getJob(); // gets initial and max heap size String initHeap = JavaUtils.getInitialHeapSize(); String maxHeap = JavaUtils.getMaximumHeapSize(); // gets JCL file File jclFile = Main.getOutputSystem().getJclFile(job); // gest the use of job String user = job.isUserSurrogated() ? job.getJcl().getUser() : job.getUser(); //creates the JAVA command to execute JavaCommand command = new JavaCommand(); // sets all java option // heap sizes // system properties command.setJavaOptions(initHeap, maxHeap, getHome(), getRmiPort(), "-D" + ConfigKeys.JEM_JOB_ID + "=" + job.getId(), getDataPath(), getClassPath(), getBinPath(), getLibPath(), "-D" + ConfigKeys.JEM_OUTPUT_PATH_NAME + "=" + FilenameUtils.normalize(jclFile.getParentFile().getAbsolutePath(), true), getSrcPath(), getPersistencePath(), "-D" + ConfigKeys.JAVA_USER_NAME + "=" + user); // loads system properties that has been set // during the submit of job if (!job.getInputArguments().isEmpty()) { // only the system properties // which start with "jem.custom." can be passed for (String prop : job.getInputArguments()) { if (prop.startsWith("-Djem.custom.")) { command.setJavaOptions(prop); } } } // sets command to be executed setCommand(command); }
From source file:org.pepstock.jem.node.tasks.platform.UnixPlatform.java
@Override public String getCommand(Job job, JavaCommand command, boolean sudo) throws IOException { String commandToExecute = null; // sets classpath using the variable // to avoid to have a command line too long command.setJavaOptions("-cp $CLASSPATH"); // gets log file File logFile = Main.getOutputSystem().getMessagesLogFile(job); // redirect all STD error and output to message log file // of the job String redirect = "> " + FilenameUtils.normalize(logFile.getAbsolutePath(), true) + " 2>&1"; // if sudo has been activated if (sudo) {//from ww w. j a va 2 s . c om // it creates a job shell file // with all command to execute. // the file is created on output folder of the job File outputFolder = Main.getOutputSystem().getOutputPath(job); File scriptFile = new File(outputFolder, JOB_FILE_SHELL); write(scriptFile, job, command); commandToExecute = scriptFile.getAbsolutePath() + " " + redirect; } else { // executes the command as is commandToExecute = command.toCommandLine() + " " + redirect; } return commandToExecute; }