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.tasks.platform.WindowsPlatform.java
@Override public String getCommand(Job job, JavaCommand command, boolean sudo) throws IOException { String commandToExecute = null; // 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 www. ja v a 2s. 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_CMD); write(scriptFile, command); commandToExecute = scriptFile.getAbsolutePath() + " " + redirect; } else { // executes the command as is commandToExecute = command.toCommandLine() + " " + redirect; } return commandToExecute; }
From source file:org.pepstock.jem.springbatch.SpringBatchTask.java
/** * Implementations of abstract method.<br> * Sets the classpath, adding the source path of Spring Batch JCL file and * creates the command line./* w ww. j a v a 2 s.com*/ * * @throws IOException occurs if there is any error */ @Override public void configure() throws IOException { super.configure(); // gets CLASSPATH, setting the name of folders in JEM lib to add // to process to launch String currentClassPath = JavaUtils.getClassPath(FOLDER); // get job instance and get JCL file, necessary to pass to Spriong Batch Job job = getJob(); File jclFile = Main.getOutputSystem().getJclFile(job); currentClassPath = currentClassPath + File.pathSeparator + FilenameUtils.normalize(jclFile.getParentFile().getAbsolutePath(), true); getEnv().put(CLASSPATH_ENVIRONMENT_VARIABLE, currentClassPath); // adds the custom classpath if not null/ Jcl jcl = job.getJcl(); if (jcl.getPriorClassPath() != null) { currentClassPath = jcl.getPriorClassPath() + File.pathSeparator + currentClassPath; getEnv().put(CLASSPATH_ENVIRONMENT_VARIABLE, currentClassPath); } if (jcl.getClassPath() != null) { currentClassPath = currentClassPath + File.pathSeparator + jcl.getClassPath(); getEnv().put(CLASSPATH_ENVIRONMENT_VARIABLE, currentClassPath); } JavaCommand jCommand = getCommand(); jCommand.setClassPath(currentClassPath); Map<String, Object> jclMap = jcl.getProperties(); jCommand.setClassName(SpringBatchLauncher.class.getName()); jCommand.setClassArguments(jclFile.getName(), (jclMap.containsKey(JemBeanDefinitionParser.OPTIONS_ATTRIBUTE)) ? jclMap.get(JemBeanDefinitionParser.OPTIONS_ATTRIBUTE).toString() : "", job.getName(), (jclMap.containsKey(JemBeanDefinitionParser.PARAMETERS_ATTRIBUTE)) ? jclMap.get(JemBeanDefinitionParser.PARAMETERS_ATTRIBUTE).toString() : ""); }
From source file:org.pepstock.jem.springbatch.tasks.DataSetManager.java
/** * /*from w ww . ja v a 2s .c o m*/ * @param ddImpl * @param ds * @return * @throws BuildException */ private static FileWrapper getFile(DataSet ds, String disposition) throws SpringBatchException { // gets the data path and checks // if dataset name starts String dataPath = DataPathsContainer.getInstance().getAbsoluteDataPath(ds.getName()); //checks if the Dsname is a absolute file name // if absolute path is equals return the file // otherwise checks datapath File file = null; String fileName = null; //checks if the Dsname is a absolute file name // if absolute path is equals return the file // otherwise checks datapath if (dataPath != null) { // if name is absolute // creates a new FILE object with full pathname file = new File(ds.getName()); // normalizes using UNIX rules fileName = FilenameUtils.normalize(file.getAbsolutePath(), true); // extract the short name, taking the string after dataPath fileName = StringUtils.substringAfter(fileName, dataPath); // removes the first / of the filename fileName = fileName.substring(1); // we must check if full is correct in disposition NEW (only for new allocation) if (Disposition.NEW.equalsIgnoreCase(disposition)) { try { // checks all paths PathsContainer paths = DataPathsContainer.getInstance().getPaths(fileName); // creates a file with dataPath as parent, plus file name file = new File(paths.getCurrent().getContent(), fileName); } catch (InvalidDatasetNameException e) { throw new SpringBatchException(e.getMessageInterface(), e, e.getObjects()); } } } else { // should be relative file = new File(ds.getName()); // normalizes the full path and checks again with the name // if equals means that is absolute because the previuos checks only if it's using the // data paths if (FilenameUtils.normalize(file.getAbsolutePath(), true).equalsIgnoreCase(ds.getName())) { // normalizes using UNIX rules fileName = FilenameUtils.normalize(file.getAbsolutePath(), true); } else { try { // checks all paths PathsContainer paths = DataPathsContainer.getInstance().getPaths(ds.getName()); // is relative! // creates a file with dataPath as parent, plus file name file = new File(paths.getCurrent().getContent(), ds.getName()); // if disposition is not in new allocation and the file with current path doesn't exists, // try to use the old path is exist if (!Disposition.NEW.equalsIgnoreCase(disposition) && !file.exists() && paths.getOld() != null) { file = new File(paths.getOld().getContent(), ds.getName()); } // normalizes using UNIX rules fileName = FilenameUtils.normalize(ds.getName(), true); } catch (InvalidDatasetNameException e) { throw new SpringBatchException(e.getMessageInterface(), e, e.getObjects()); } } } return new FileWrapper(file, fileName); }
From source file:org.pepstock.jem.springbatch.tasks.utilities.MainLauncherTasklet.java
/** * Loads java class from className and for classpath * @param className classname to be loaded * @return class object loaded from classpath * @throws IOException if any error occurs * @throws ClassNotFoundException if any error occurs *///from ww w . j av a 2 s . c om private Class<?> loadCustomClass(String classNam) throws IOException, ClassNotFoundException { // CLASSPATH has been set therefore it an try to load the plugin by // a custom classloader // collection of all file of classpath Collection<File> files = new LinkedList<File>(); for (String classPathFile : classPath) { classPathFile = FilenameUtils.normalize(classPathFile, true); // checks if a item contains more than 1 path String[] paths = null; if (classPathFile.contains(File.pathSeparator)) { // substitute variables if there are and split paths = StringUtils.split(JobsProperties.getInstance().replacePlaceHolders(classPathFile), File.pathSeparator); } else if (classPathFile.contains(";")) { // substitute variables if there are and split paths = StringUtils.split(JobsProperties.getInstance().replacePlaceHolders(classPathFile), ";"); } else { // substitute variables if there are and assign paths = new String[] { JobsProperties.getInstance().replacePlaceHolders(classPathFile) }; } if (paths != null) { for (String path : paths) { // creates the file File file = new File(path); // if file ends with * could be only this folder or all folders // in cascade if (path.endsWith(ClassLoaderUtil.ALL_FOLDER)) { // checks if is all folders in cascade boolean cascade = path.endsWith(ClassLoaderUtil.ALL_FOLDER_IN_CASCADE); // gets the parent and asks for all JAR files File parent = file.getParentFile(); Collection<File> newFiles = FileUtils.listFiles(parent, ClassLoaderUtil.EXTENSIONS.toArray(new String[0]), cascade); // loads to the collection files.addAll(newFiles); } else if (file.isDirectory() && file.exists()) { // if here, we have a directory // adds the directory to collection files.add(file); } else if (file.isFile() && file.exists()) { // if here, a file has been indicated // adds the directory to collection files.add(file); } } } } // checks if the collection is empty. // if yes, all classpath definiton is wrong and no files have been // loaded if (!files.isEmpty()) { // gets where the class is located // because it must be added to classpath CodeSource codeSource = JavaMainClassLauncher.class.getProtectionDomain().getCodeSource(); if (codeSource != null) { // gets URL URL url = codeSource.getLocation(); if (url != null) { // adds URL to classpath files.add(FileUtils.toFile(url)); } } // exports files in URLs, for our classloader final URL[] urls = FileUtils.toURLs(files.toArray(new File[files.size()])); // loads a our classloader by access controller ClassLoader loader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { public ClassLoader run() { return new ReverseURLClassLoader(urls, MainLauncherTasklet.class.getClassLoader(), false); } }); // loads the plugin from classloader return loader.loadClass(className); } else { throw new IOException(UtilMessage.JEMB009E.toMessage().getMessage()); } }
From source file:org.silverpeas.components.gallery.model.InternalMedia.java
private String getPhotoThumbnailUrl(final MediaResolution mediaResolution) { if (MediaResolution.WATERMARK == mediaResolution) { SilverpeasFile fileWatermark = getFile(MediaResolution.WATERMARK); if (!fileWatermark.exists()) { return ""; }/* www .j a va 2s . c o m*/ } if (StringUtil.isDefined(getFileName()) && isPreviewable()) { return GalleryResourceURIs.buildMediaContentURI(this, mediaResolution).toString(); } else { String thumbnailUrl = URLUtil.getApplicationURL() + "/gallery/jsp/icons/notAvailable_" + MessageManager.getLanguage() + mediaResolution.getThumbnailSuffix() + ".jpg"; return FilenameUtils.normalize(thumbnailUrl, true); } }
From source file:org.silverpeas.components.gallery.model.Media.java
/** * Gets the Application URL thumbnail of the media according the specified media resolution. * @param mediaResolution/* w ww. j av a 2s. c o m*/ * @return the URL of media thumbnail. */ public String getApplicationThumbnailUrl(MediaResolution mediaResolution) { if (mediaResolution == null) { mediaResolution = MediaResolution.PREVIEW; } String thumbnailUrl = URLUtil.getApplicationURL() + "/gallery/jsp/icons/" + getType().name().toLowerCase() + "_"; switch (mediaResolution) { case TINY: thumbnailUrl += MediaResolution.TINY.getLabel(); break; case SMALL: thumbnailUrl += MediaResolution.SMALL.getLabel(); break; case WATERMARK: return ""; default: thumbnailUrl += MediaResolution.MEDIUM.getLabel(); break; } thumbnailUrl += ".png"; return FilenameUtils.normalize(thumbnailUrl, true); }
From source file:org.silverpeas.components.gallery.model.PhotoIT.java
private void assertDefaultPhoto(Photo photo) { final String timestamp = timestamp(); assertThat(photo.getType(), is(MediaType.Photo)); assertThat(photo.getWorkspaceSubFolderName(), is("imagemediaId")); assertThat(photo.getDefinition().getWidth(), is(800)); assertThat(photo.getDefinition().getHeight(), is(600)); assertThat(photo.getMetaDataProperties(), hasSize(1)); assertThat(photo.getMetaData(photo.getMetaDataProperties().iterator().next()).getValue(), is("ok")); assertThat(photo.getApplicationThumbnailUrl(MediaResolution.PREVIEW), is(GALLERY_REST_WEB_SERVICE_BASE_URI + "photos/mediaId/content?_t=" + timestamp + "&resolution=PREVIEW")); assertThat(photo.getApplicationOriginalUrl(), is(GALLERY_REST_WEB_SERVICE_BASE_URI + "photos/mediaId/content?_t=" + timestamp)); assertThat(FilenameUtils.normalize(photo.getFile(MediaResolution.ORIGINAL).getPath(), true), endsWith("/instanceId/imagemediaId/photoFile.jpg")); }
From source file:org.silverpeas.components.gallery.model.SoundIT.java
private void assertDefaultSound(Sound sound) { assertThat(sound.getType(), is(MediaType.Sound)); assertThat(sound.getWorkspaceSubFolderName(), is("soundmediaId")); assertThat(sound.getBitrate(), is(2048L)); assertThat(sound.getDuration(), is(72000000L)); assertThat(sound.getApplicationOriginalUrl(), is(GALLERY_REST_WEB_SERVICE_BASE_URI + "sounds/mediaId/content?_t=" + timestamp())); assertThat(FilenameUtils.normalize(sound.getFile(MediaResolution.ORIGINAL).getPath(), true), endsWith("/instanceId/soundmediaId/soundFile.mp3")); }
From source file:org.silverpeas.components.gallery.model.VideoIT.java
private void assertDefaultVideo(Video video) { assertThat(video.getType(), is(MediaType.Video)); assertThat(video.getWorkspaceSubFolderName(), is("videomediaId")); assertThat(video.getDefinition().getWidth(), is(800)); assertThat(video.getDefinition().getHeight(), is(600)); assertThat(video.getBitrate(), is(1024L)); assertThat(video.getDuration(), is(36000000L)); assertThat(video.getApplicationOriginalUrl(), is(GALLERY_REST_WEB_SERVICE_BASE_URI + "videos/mediaId/content?_t=" + timestamp())); assertThat(FilenameUtils.normalize(video.getFile(MediaResolution.ORIGINAL).getPath(), true), endsWith("/instanceId/videomediaId/videoFile.mp4")); }
From source file:org.silverpeas.core.calendar.CalendarSynchronizationIT.java
private String getFilePath(String pattern, String filename) { return FilenameUtils.normalize(MessageFormat.format(pattern, mavenTargetDirectoryRule.getResourceTestDirFile().getPath(), filename), true); }