List of usage examples for org.apache.commons.io FilenameUtils EXTENSION_SEPARATOR_STR
String EXTENSION_SEPARATOR_STR
To view the source code for org.apache.commons.io FilenameUtils EXTENSION_SEPARATOR_STR.
Click Source Link
From source file:org.apache.flex.compiler.internal.targets.SWCTarget.java
/** * Process a resource bundle represented by the specified compilation unit. * // w w w . ja v a 2 s.c o m * @param project active project * @param cu resource bundle compilation unit to process * @param swc target swc * @param problems problems collection */ private void processResourceBundle(FlexProject project, ResourceBundleCompilationUnit cu, SWC swc, Collection<ICompilerProblem> problems) { Collection<String> locales = null; if (cu.getLocale() == null) { //Create a file entry for each locale since this compilation unit is not locale specific locales = project.getLocales(); } else { //This compilation unit is for a locale specific file, //therefore create a file entry for only the locale comp unit depends on locales = Collections.singletonList(cu.getLocale()); } byte[] fileContent = cu.getFileContent(problems); //get file content if (fileContent == null) return; //Is this the right thing to do here? for (String locale : locales) { //Build the destination path. Destination path for a .properties file //is such as locale/{locale}/foo/bar/x.properties StringBuilder sb = new StringBuilder(); sb.append(ResourceBundleCompilationUnit.LOCALE); sb.append(File.separator); sb.append(locale); sb.append(File.separator); sb.append( QNameNormalization.normalize(cu.getBundleNameInColonSyntax()).replace('.', File.separatorChar)); sb.append(FilenameUtils.EXTENSION_SEPARATOR_STR); sb.append(ResourceBundleSourceFileHandler.EXTENSION); swc.addFile(sb.toString(), cu.getFileLastModified(), fileContent); } }
From source file:org.primefaces.util.FileUploadUtils.java
public static String getValidFilename(String filename) { if (LangUtils.isValueBlank(filename)) { return null; }//from www .j a v a2 s. c o m if (isSystemWindows()) { if (!filename.contains("\\\\")) { String[] parts = filename.substring(FilenameUtils.getPrefixLength(filename)) .split(Pattern.quote(File.separator)); for (String part : parts) { if (INVALID_FILENAME_PATTERN.matcher(part).find()) { throw new FacesException("Invalid filename: " + filename); } } } else { throw new FacesException("Invalid filename: " + filename); } } String name = FilenameUtils.getName(filename); String extension = FilenameUtils.EXTENSION_SEPARATOR_STR + FilenameUtils.getExtension(filename); if (extension.equals(FilenameUtils.EXTENSION_SEPARATOR_STR)) { throw new FacesException("File must have an extension"); } else if (name.isEmpty() || extension.equals(name)) { throw new FacesException("Filename can not be the empty string"); } return name; }
From source file:org.springframework.integration.zip.transformer.ZipTransformer.java
/** * The payload may encompass the following types: * * <ul>//from w w w . j ava 2 s . c o m * <li>{@link File} *...<li>{@link String} *...<li>byte[] *...<li>{@link Iterable} * </ul> * * When providing an {@link Iterable}, nested Iterables are not supported. However, * payloads can be of of any of the other supported types. * */ @Override protected Object doZipTransform(Message<?> message) throws Exception { final Object payload = message.getPayload(); final Object zippedData; final String baseFileName = this.fileNameGenerator.generateFileName(message); final String zipEntryName; final String zipFileName; if (message.getHeaders().containsKey(ZipHeaders.ZIP_ENTRY_FILE_NAME)) { zipEntryName = (String) message.getHeaders().get(ZipHeaders.ZIP_ENTRY_FILE_NAME); } else { zipEntryName = baseFileName; } if (message.getHeaders().containsKey(FileHeaders.FILENAME)) { zipFileName = (String) message.getHeaders().get(FileHeaders.FILENAME); } else { zipFileName = baseFileName + ZIP_EXTENSION; } final Date lastModifiedDate; if (message.getHeaders().containsKey(ZipHeaders.ZIP_ENTRY_LAST_MODIFIED_DATE)) { lastModifiedDate = (Date) message.getHeaders().get(ZipHeaders.ZIP_ENTRY_LAST_MODIFIED_DATE); } else { lastModifiedDate = new Date(); } java.util.List<ZipEntrySource> entries = new ArrayList<ZipEntrySource>(); if (payload instanceof Iterable<?>) { int counter = 1; String baseName = FilenameUtils.getBaseName(zipEntryName); String fileExtension = FilenameUtils.getExtension(zipEntryName); if (StringUtils.hasText(fileExtension)) { fileExtension = FilenameUtils.EXTENSION_SEPARATOR_STR + fileExtension; } for (Object item : (Iterable<?>) payload) { final ZipEntrySource zipEntrySource = createZipEntrySource(item, lastModifiedDate, baseName + "_" + counter + fileExtension, this.useFileAttributes); if (logger.isDebugEnabled()) { logger.debug("ZipEntrySource path: '" + zipEntrySource.getPath() + "'"); } entries.add(zipEntrySource); counter++; } } else { final ZipEntrySource zipEntrySource = createZipEntrySource(payload, lastModifiedDate, zipEntryName, this.useFileAttributes); entries.add(zipEntrySource); } final byte[] zippedBytes = SpringZipUtils.pack(entries, this.compressionLevel); if (ZipResultType.FILE.equals(this.zipResultType)) { final File zippedFile = new File(this.workDirectory, zipFileName); FileCopyUtils.copy(zippedBytes, zippedFile); zippedData = zippedFile; } else if (ZipResultType.BYTE_ARRAY.equals(this.zipResultType)) { zippedData = zippedBytes; } else { throw new IllegalStateException("Unsupported zipResultType " + this.zipResultType); } if (this.deleteFiles) { if (payload instanceof Iterable<?>) { for (Object item : (Iterable<?>) payload) { deleteFile(item); } } else { deleteFile(payload); } } return getMessageBuilderFactory().withPayload(zippedData).copyHeaders(message.getHeaders()) .setHeader(FileHeaders.FILENAME, zipFileName).build(); }
From source file:org.usc.wechat.mp.sdk.util.platform.MediaUtil.java
private static String getFileNameFromContentType(HttpResponse response, String mediaId) { Header header = response.getFirstHeader("Content-Type"); if (header == null) { return null; }//from ww w . j a va2s . co m String contentType = header.getValue(); String ext = MimeType.getExtensionFromContentType(contentType); if (StringUtils.isEmpty(ext)) { return null; } return StringUtils.join(mediaId, FilenameUtils.EXTENSION_SEPARATOR_STR, ext); }
From source file:se.vgregion.alfresco.repo.scripts.ExportJsonToExcel.java
private void streamContentLocalCopied(WebScriptRequest req, WebScriptResponse res, NodeRef nodeRef, boolean attach, QName propertyQName) throws IOException { String userAgent = req.getHeader("User-Agent"); userAgent = userAgent != null ? userAgent.toLowerCase() : ""; boolean rfc5987Supported = (userAgent.contains("msie") || userAgent.contains(" trident/") || userAgent.contains(" chrome/") || userAgent.contains(" firefox/")); try {/*from w ww . j a v a 2 s . c o m*/ if (attach && rfc5987Supported) { String name = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_NAME); //IE use file extension to get mimetype //So we set correct extension. see MNT-11246 if (userAgent.contains("msie") || userAgent.contains(" trident/")) { String mimeType = contentService.getReader(nodeRef, propertyQName).getMimetype(); // If we have an unknown mime type (usually marked as binary) // it is better to stay with the file extension we currently have // see MNT-14412 if (!mimeType.toLowerCase().equals(MimetypeMap.MIMETYPE_BINARY) && !mimetypeService.getMimetypes(FilenameUtils.getExtension(name)).contains(mimeType)) { name = FilenameUtils.removeExtension(name) + FilenameUtils.EXTENSION_SEPARATOR_STR + mimetypeService.getExtension(mimeType); } } streamContent(req, res, nodeRef, propertyQName, attach, name, null); } else { streamContent(req, res, nodeRef, propertyQName, attach, null, null); } } catch (AccessDeniedException e) { throw new WebScriptException(Status.STATUS_FORBIDDEN, e.getMessage()); } }