List of usage examples for org.apache.commons.io FilenameUtils normalize
public static String normalize(String filename)
From source file:org.krakenapps.docxcod.FreeMarkerRunner.java
public FreeMarkerRunner(String string) { targets.add(FilenameUtils.normalize(string)); }
From source file:org.liberty.android.fantastischmemo.utils.RecentListUtil.java
private static String trimPath(String path) { return FilenameUtils.normalize(path); }
From source file:org.ngrinder.infra.AgentConfig.java
/** * Resolve NGrinder agent home path./* ww w . j a v a 2 s. c om*/ * * @return resolved {@link AgentHome} */ protected AgentHome resolveHome() { String userHomeFromEnv = trimToEmpty(System.getenv("NGRINDER_AGENT_HOME")); //printLog(" System Environment: NGRINDER_AGENT_HOME={}", userHomeFromEnv); String userHomeFromProperty = trimToEmpty(System.getProperty("ngrinder.agent.home")); //printLog(" Java System Property: ngrinder.agent.home={}", userHomeFromEnv); if (StringUtils.isNotEmpty(userHomeFromEnv) && !StringUtils.equals(userHomeFromEnv, userHomeFromProperty)) { printLog("The path to ngrinder agent home is ambiguous:"); printLog(" '{}' is accepted.", userHomeFromProperty); } String userHome = StringUtils.defaultIfEmpty(userHomeFromProperty, userHomeFromEnv); if (StringUtils.isEmpty(userHome)) { userHome = System.getProperty("user.home") + File.separator + NGRINDER_DEFAULT_FOLDER; } else if (StringUtils.startsWith(userHome, "~" + File.separator)) { userHome = System.getProperty("user.home") + File.separator + userHome.substring(2); } else if (StringUtils.startsWith(userHome, "." + File.separator)) { userHome = System.getProperty("user.dir") + File.separator + userHome.substring(2); } userHome = FilenameUtils.normalize(userHome); printLog("NGRINDER_AGENT_HOME : {}", userHome); File homeDirectory = new File(userHome); try { if (homeDirectory.mkdirs()) { noOp(); } if (!homeDirectory.canWrite()) { throw processException("home directory " + userHome + " is not writable."); } } catch (Exception e) { throw processException("Error while resolve the home directory.", e); } return new AgentHome(homeDirectory); }
From source file:org.normandra.orientdb.data.OrientDatabase.java
public static OrientDatabase createLocalFile(final File path, final String database, final EntityCacheFactory factory, final DatabaseConstruction mode, final Collection<Class> types) { final String url = "plocal:" + FilenameUtils.normalize(path.getAbsolutePath()); final OrientPool pool = new LocalFileOrientPool(url, database, "admin", "admin"); final AnnotationParser parser = new AnnotationParser(columnFactory, types); final DatabaseMeta meta = new DatabaseMeta(parser.read()); return new OrientDatabase(url, pool, factory, mode, meta); }
From source file:org.normandra.orientdb.data.OrientDatabase.java
public static OrientDatabase createLocalFile(final File path, final String database, final EntityCacheFactory factory, final DatabaseConstruction mode, final DatabaseMetaBuilder metaBuilder) { final String url = "plocal:" + FilenameUtils.normalize(path.getAbsolutePath()); final OrientPool pool = new LocalFileOrientPool(url, database, "admin", "admin"); final DatabaseMeta meta = metaBuilder.withColumnFactory(columnFactory).create(); return new OrientDatabase(url, pool, factory, mode, meta); }
From source file:org.normandra.orientdb.graph.OrientGraphDatabase.java
public static OrientGraphDatabase createLocalFile(final File path, final String database, final EntityCacheFactory factory, final DatabaseConstruction mode, final GraphMetaBuilder metaBuilder) { final String url = "plocal:" + FilenameUtils.normalize(path.getAbsolutePath()); final OrientPool pool = new LocalFileOrientPool(url, database, "admin", "admin"); final GraphMeta meta = metaBuilder.withColumnFactory(columnFactory).create(); return new OrientGraphDatabase(url, pool, factory, mode, meta); }
From source file:org.nuxeo.ecm.csv.core.CSVImporterWork.java
/** * Creates a {@code Blob} from a relative file path. The File will be looked up in the folder registered by the * {@code nuxeo.csv.blobs.folder} property. * * @since 9.3// w w w . j a v a2 s . c o m */ protected Blob createBlobFromFilePath(String fileRelativePath) throws IOException { String blobsFolderPath = Framework.getProperty(NUXEO_CSV_BLOBS_FOLDER); String path = FilenameUtils.normalize(blobsFolderPath + "/" + fileRelativePath); File file = new File(path); if (file.exists()) { return Blobs.createBlob(file, null, null, FilenameUtils.getName(fileRelativePath)); } else { return null; } }
From source file:org.nuxeo.ecm.csv.CSVImporterWork.java
protected Serializable convertValue(DocumentType docType, String fieldName, String headerValue, String stringValue, long lineNumber) { if (docType.hasField(fieldName)) { Field field = docType.getField(fieldName); if (field != null) { try { Serializable fieldValue = null; Type fieldType = field.getType(); if (fieldType.isComplexType()) { if (fieldType.getName().equals(CONTENT_FILED_TYPE_NAME)) { String blobsFolderPath = Framework.getProperty("nuxeo.csv.blobs.folder"); String path = FilenameUtils.normalize(blobsFolderPath + "/" + stringValue); File file = new File(path); if (file.exists()) { FileBlob blob = new FileBlob(file); blob.setFilename(file.getName()); fieldValue = blob; } else { logError(lineNumber, "The file '%s' does not exist", "label.csv.importer.notExistingFile", stringValue); return null; }//ww w .j a v a 2 s . c om } // other types not supported } else { if (fieldType.isListType()) { Type listFieldType = ((ListType) fieldType).getFieldType(); if (listFieldType.isSimpleType()) { /* * Array. */ fieldValue = stringValue.split(options.getListSeparatorRegex()); } else { /* * Complex list. */ fieldValue = (Serializable) Arrays .asList(stringValue.split(options.getListSeparatorRegex())); } } else { /* * Primitive type. */ Type type = field.getType(); if (type instanceof SimpleTypeImpl) { type = type.getSuperType(); } if (type.isSimpleType()) { if (type instanceof StringType) { fieldValue = stringValue; } else if (type instanceof IntegerType) { fieldValue = Integer.valueOf(stringValue); } else if (type instanceof LongType) { fieldValue = Long.valueOf(stringValue); } else if (type instanceof DoubleType) { fieldValue = Double.valueOf(stringValue); } else if (type instanceof BooleanType) { fieldValue = Boolean.valueOf(stringValue); } else if (type instanceof DateType) { fieldValue = getDateFormat().parse(stringValue); } } } } return fieldValue; } catch (ParseException | NumberFormatException e) { logError(lineNumber, "Unable to convert field '%s' with value '%s'", "label.csv.importer.cannotConvertFieldValue", headerValue, stringValue); log.debug(e, e); } } } else { logError(lineNumber, "Field '%s' does not exist on type '%s'", "label.csv.importer.notExistingField", headerValue, docType.getName()); } return null; }
From source file:org.nuxeo.ecm.user.center.profile.UserProfileImporter.java
protected Serializable convertValue(DocumentType docType, String fieldName, String headerValue, String stringValue, long lineNumber) { if (docType.hasField(fieldName)) { Field field = docType.getField(fieldName); if (field != null) { try { Serializable fieldValue = null; Type fieldType = field.getType(); if (fieldType.isComplexType()) { if (fieldType.getName().equals(CONTENT_FILED_TYPE_NAME)) { String blobsFolderPath = Framework.getProperty(BLOB_FOLDER_PROPERTY); String path = FilenameUtils.normalize(blobsFolderPath + "/" + stringValue); File file = new File(path); if (file.exists()) { FileBlob blob = new FileBlob(file); blob.setFilename(file.getName()); fieldValue = blob; } else { logImportError(lineNumber, "The file '%s' does not exist", stringValue); return null; }//w ww . ja va 2 s. c o m } // other types not supported } else { if (fieldType.isListType()) { Type listFieldType = ((ListType) fieldType).getFieldType(); if (listFieldType.isSimpleType()) { /* * Array. */ fieldValue = stringValue.split(config.getListSeparatorRegex()); } else { /* * Complex list. */ fieldValue = (Serializable) Arrays .asList(stringValue.split(config.getListSeparatorRegex())); } } else { /* * Primitive type. */ Type type = field.getType(); if (type instanceof SimpleTypeImpl) { type = type.getSuperType(); } if (type.isSimpleType()) { if (type instanceof StringType) { fieldValue = stringValue; } else if (type instanceof IntegerType) { fieldValue = Integer.valueOf(stringValue); } else if (type instanceof LongType) { fieldValue = Long.valueOf(stringValue); } else if (type instanceof DoubleType) { fieldValue = Double.valueOf(stringValue); } else if (type instanceof BooleanType) { fieldValue = Boolean.valueOf(stringValue); } else if (type instanceof DateType) { fieldValue = getDateFormat().parse(stringValue); } } } } return fieldValue; } catch (ParseException pe) { logImportError(lineNumber, "Unable to convert field '%s' with value '%s'", headerValue, stringValue); log.debug(pe, pe); } catch (NumberFormatException nfe) { logImportError(lineNumber, "Unable to convert field '%s' with value '%s'", headerValue, stringValue); log.debug(nfe, nfe); } } } else { logImportError(lineNumber, "Field '%s' does not exist on type '%s'", headerValue, docType.getName()); } return null; }
From source file:org.opencastproject.composer.gstreamer.AbstractGSEncoderEngine.java
/** * Executes encoding job. At least one source has to be specified. * //from w w w.jav a 2 s. co m * @param audioSource * File that contains audio source (if used) * @param videoSource * File that contains video source (if used) * @param profile * EncodingProfile used for this encoding job * @param properties * Map containing any additional properties * @return File created as result of this encoding job * @throws EncoderException * if encoding fails */ protected File process(File audioSource, File videoSource, EncodingProfile profile, Map<String, String> properties) throws EncoderException { Map<String, String> params = new HashMap<String, String>(); if (properties != null) { params.putAll(properties); } try { if (audioSource == null && videoSource == null) { throw new IllegalArgumentException("At least one source must be specified."); } // Set encoding parameters if (audioSource != null) { String audioInput = FilenameUtils.normalize(audioSource.getAbsolutePath()); params.put("in.audio.path", audioInput); params.put("in.audio.name", FilenameUtils.getBaseName(audioInput)); params.put("in.audio.suffix", FilenameUtils.getExtension(audioInput)); params.put("in.audio.filename", FilenameUtils.getName(audioInput)); params.put("in.audio.mimetype", MimetypesFileTypeMap.getDefaultFileTypeMap().getContentType(audioInput)); } if (videoSource != null) { String videoInput = FilenameUtils.normalize(videoSource.getAbsolutePath()); params.put("in.video.path", videoInput); params.put("in.video.name", FilenameUtils.getBaseName(videoInput)); params.put("in.video.suffix", FilenameUtils.getExtension(videoInput)); params.put("in.video.filename", FilenameUtils.getName(videoInput)); params.put("in.video.mimetype", MimetypesFileTypeMap.getDefaultFileTypeMap().getContentType(videoInput)); } File parentFile; if (videoSource == null) { parentFile = audioSource; } else { parentFile = videoSource; } String outDir = parentFile.getAbsoluteFile().getParent(); String outFileName = FilenameUtils.getBaseName(parentFile.getName()); String outSuffix = substituteTemplateValues(profile.getSuffix(), params, false); if (new File(outDir, outFileName + outSuffix).exists()) { outFileName += "_" + UUID.randomUUID().toString(); } params.put("out.dir", outDir); params.put("out.name", outFileName); params.put("out.suffix", outSuffix); File encodedFile = new File(outDir, outFileName + outSuffix); params.put("out.file.path", encodedFile.getAbsolutePath()); // create and launch gstreamer pipeline createAndLaunchPipeline(profile, params); if (audioSource != null) { logger.info("Audio track {} and video track {} successfully encoded using profile '{}'", new String[] { (audioSource == null ? "N/A" : audioSource.getName()), (videoSource == null ? "N/A" : videoSource.getName()), profile.getIdentifier() }); } else { logger.info("Video track {} successfully encoded using profile '{}'", new String[] { videoSource.getName(), profile.getIdentifier() }); } fireEncoded(this, profile, audioSource, videoSource); return encodedFile; } catch (EncoderException e) { if (audioSource != null) { logger.warn("Error while encoding audio track {} and video track {} using '{}': {}", new String[] { (audioSource == null ? "N/A" : audioSource.getName()), (videoSource == null ? "N/A" : videoSource.getName()), profile.getIdentifier(), e.getMessage() }); } else { logger.warn("Error while encoding video track {} using '{}': {}", new String[] { (videoSource == null ? "N/A" : videoSource.getName()), profile.getIdentifier(), e.getMessage() }); } fireEncodingFailed(this, profile, e, audioSource, videoSource); throw e; } catch (Exception e) { logger.warn("Error while encoding audio {} and video {} to {}:{}, {}", new Object[] { (audioSource == null ? "N/A" : audioSource.getName()), (videoSource == null ? "N/A" : videoSource.getName()), profile.getName(), e.getMessage() }); fireEncodingFailed(this, profile, e, audioSource, videoSource); throw new EncoderException(this, e.getMessage(), e); } }