List of usage examples for org.apache.commons.io FilenameUtils getName
public static String getName(String filename)
From source file:com.iyonger.apm.web.handler.ScriptHandler.java
/** * Get executable script path./* www. j a va 2 s.com*/ * * @param svnPath path in svn * @return path executable in agent. */ public String getScriptExecutePath(String svnPath) { return FilenameUtils.getName(svnPath); }
From source file:com.gitpitch.models.MarkdownModel.java
public String offline(String md) { if (videoService.found(md)) { return videoService.offline(); } else if (gistMarkdown(md)) { return gistService.offline(); } else if (imageService.background(md)) { return imageService.buildBackgroundOffline(md); } else if (imageService.inline(md)) { /*/*from www . jav a2 s .c o m*/ * Link found in markdown fragment, process. */ int delim = md.indexOf(MD_LINK_DELIM); if (delim == NOT_FOUND) { /* * Valid link syntax not found, return unmodified. */ return md; } else { /* * Valid link syntax found, now process link to * handle absolute, (GitHub) relative and video links. */ String splitLeft = md.substring(0, delim + 2); String splitRight = md.substring(delim + 2); /* * Clone and clean splitRight string to begin * extraction of the pitchLink. */ String pitchLink = cloneLink(splitRight); pitchLink = extractLink(pitchLink, null); String imageName = FilenameUtils.getName(pitchLink); return imageService.buildInlineOffline(imageName); } } else if (imageService.tagFound(md)) { return imageService.buildTagOffline(md); } else { /* * Link-free markdown, return unmodified. */ return md; } }
From source file:com.nuvolect.deepdive.lucene.Index.java
/** * Build a single document to be indexed with additional data to be returned with search results. * @param volumeId // Volume of the file * @param path // Path to the file/*from ww w .java2 s. c om*/ * @return * @throws IllegalArgumentException * @throws FileNotFoundException */ private static Document makeDoc(String volumeId, String path) throws IllegalArgumentException, FileNotFoundException { Document doc = new Document(); String fileName = FilenameUtils.getName(path); // Tokenize, index and store doc.add(new TextField(CConst.FIELD_FILENAME, fileName, Field.Store.YES)); // Only stored, not indexed doc.add(new StoredField(CConst.FIELD_VOLUME, volumeId)); // Only stored, not indexed doc.add(new StoredField(CConst.FIELD_PATH, path)); // Index only, do not store OmniFile file = new OmniFile(volumeId, path); java.io.Reader reader = new java.io.FileReader(file.getStdFile()); doc.add(new Field(CConst.FIELD_CONTENT, reader, TextField.TYPE_NOT_STORED)); return doc; }
From source file:es.gob.afirma.signers.ooxml.be.fedict.eid.applet.service.signer.ooxml.AbstractOOXMLSignatureService.java
private ZipOutputStream copyOOXMLContent(final String signatureZipEntryName, final OutputStream signedOOXMLOutputStream) throws IOException, ParserConfigurationException, SAXException, TransformerException { final ZipOutputStream zipOutputStream = new ZipOutputStream(signedOOXMLOutputStream); final ZipInputStream zipInputStream = new ZipInputStream( new ByteArrayInputStream(this.getOfficeOpenXMLDocument())); ZipEntry zipEntry;//from w w w . j a va 2 s . com boolean hasOriginSigsRels = false; while (null != (zipEntry = zipInputStream.getNextEntry())) { zipOutputStream.putNextEntry(new ZipEntry(zipEntry.getName())); if ("[Content_Types].xml".equals(zipEntry.getName())) { //$NON-NLS-1$ final Document contentTypesDocument = loadDocumentNoClose(zipInputStream); final Element typesElement = contentTypesDocument.getDocumentElement(); // We need to add an Override element. final Element overrideElement = contentTypesDocument.createElementNS( "http://schemas.openxmlformats.org/package/2006/content-types", "Override"); //$NON-NLS-1$ //$NON-NLS-2$ overrideElement.setAttribute("PartName", "/" + signatureZipEntryName); //$NON-NLS-1$ //$NON-NLS-2$ overrideElement.setAttribute("ContentType", //$NON-NLS-1$ "application/vnd.openxmlformats-package.digital-signature-xmlsignature+xml"); //$NON-NLS-1$ typesElement.appendChild(overrideElement); final Element nsElement = contentTypesDocument.createElement("ns"); //$NON-NLS-1$ nsElement.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:tns", //$NON-NLS-1$ "http://schemas.openxmlformats.org/package/2006/content-types"); //$NON-NLS-1$ final NodeList nodeList = XPathAPI.selectNodeList(contentTypesDocument, "/tns:Types/tns:Default[@Extension='sigs']", nsElement); //$NON-NLS-1$ if (0 == nodeList.getLength()) { // Add Default element for 'sigs' extension. final Element defaultElement = contentTypesDocument.createElementNS( "http://schemas.openxmlformats.org/package/2006/content-types", "Default"); //$NON-NLS-1$ //$NON-NLS-2$ defaultElement.setAttribute("Extension", "sigs"); //$NON-NLS-1$ //$NON-NLS-2$ defaultElement.setAttribute("ContentType", //$NON-NLS-1$ "application/vnd.openxmlformats-package.digital-signature-origin"); //$NON-NLS-1$ typesElement.appendChild(defaultElement); } writeDocumentNoClosing(contentTypesDocument, zipOutputStream, false); } else if ("_rels/.rels".equals(zipEntry.getName())) { //$NON-NLS-1$ final Document relsDocument = loadDocumentNoClose(zipInputStream); final Element nsElement = relsDocument.createElement("ns"); //$NON-NLS-1$ nsElement.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:tns", RELATIONSHIPS_SCHEMA); //$NON-NLS-1$ final NodeList nodeList = XPathAPI.selectNodeList(relsDocument, "/tns:Relationships/tns:Relationship[@Type='http://schemas.openxmlformats.org/package/2006/relationships/digital-signature/origin']", //$NON-NLS-1$ nsElement); if (0 == nodeList.getLength()) { final Element relationshipElement = relsDocument.createElementNS(RELATIONSHIPS_SCHEMA, "Relationship"); //$NON-NLS-1$ relationshipElement.setAttribute("Id", "rel-id-" + UUID.randomUUID().toString()); //$NON-NLS-1$ //$NON-NLS-2$ relationshipElement.setAttribute("Type", //$NON-NLS-1$ "http://schemas.openxmlformats.org/package/2006/relationships/digital-signature/origin"); //$NON-NLS-1$ relationshipElement.setAttribute("Target", "_xmlsignatures/origin.sigs"); //$NON-NLS-1$ //$NON-NLS-2$ relsDocument.getDocumentElement().appendChild(relationshipElement); } writeDocumentNoClosing(relsDocument, zipOutputStream, false); } else if (zipEntry.getName().startsWith("_xmlsignatures/_rels/") //$NON-NLS-1$ && zipEntry.getName().endsWith(".rels")) { //$NON-NLS-1$ hasOriginSigsRels = true; final Document originSignRelsDocument = loadDocumentNoClose(zipInputStream); final Element relationshipElement = originSignRelsDocument.createElementNS(RELATIONSHIPS_SCHEMA, "Relationship"); //$NON-NLS-1$ relationshipElement.setAttribute("Id", "rel-" + UUID.randomUUID().toString()); //$NON-NLS-1$ //$NON-NLS-2$ relationshipElement.setAttribute("Type", //$NON-NLS-1$ "http://schemas.openxmlformats.org/package/2006/relationships/digital-signature/signature"); //$NON-NLS-1$ relationshipElement.setAttribute("Target", FilenameUtils.getName(signatureZipEntryName)); //$NON-NLS-1$ originSignRelsDocument.getDocumentElement().appendChild(relationshipElement); writeDocumentNoClosing(originSignRelsDocument, zipOutputStream, false); } else { IOUtils.copy(zipInputStream, zipOutputStream); } } if (!hasOriginSigsRels) { // Add signature relationships document. addOriginSigsRels(signatureZipEntryName, zipOutputStream); addOriginSigs(zipOutputStream); } // Return. zipInputStream.close(); return zipOutputStream; }
From source file:com.ephesoft.dcma.gwt.admin.bm.server.ExportBatchClassDownloadServlet.java
private void validateFolderAndFile(BatchSchemaService batchSchemaService, File copiedFolder, boolean isImagemagickBaseFolder, boolean isSearchSampleName, File originalFolder) throws IOException { String[] folderList = originalFolder.list(); Arrays.sort(folderList);/*from www . j a va2s. c o m*/ for (int i = 0; i < folderList.length; i++) { if (FilenameUtils.getName(folderList[i]) .equalsIgnoreCase(batchSchemaService.getTestKVExtractionFolderName()) || FilenameUtils.getName(folderList[i]) .equalsIgnoreCase(batchSchemaService.getTestTableFolderName()) || FilenameUtils.getName(folderList[i]) .equalsIgnoreCase(batchSchemaService.getFileboundPluginMappingFolderName())) { // Skip this folder continue; } else if (FilenameUtils.getName(folderList[i]).equalsIgnoreCase( batchSchemaService.getImagemagickBaseFolderName()) && isImagemagickBaseFolder) { FileUtils.copyDirectoryWithContents(new File(originalFolder, folderList[i]), new File(copiedFolder, folderList[i])); } else if (FilenameUtils.getName(folderList[i]) .equalsIgnoreCase(batchSchemaService.getSearchSampleName()) && isSearchSampleName) { FileUtils.copyDirectoryWithContents(new File(originalFolder, folderList[i]), new File(copiedFolder, folderList[i])); } else if (!(FilenameUtils.getName(folderList[i]) .equalsIgnoreCase(batchSchemaService.getImagemagickBaseFolderName()) || FilenameUtils.getName(folderList[i]) .equalsIgnoreCase(batchSchemaService.getSearchSampleName()))) { FileUtils.copyDirectoryWithContents(new File(originalFolder, folderList[i]), new File(copiedFolder, folderList[i])); } } }
From source file:com.ephesoft.dcma.gwt.customworkflow.server.ImportPluginUploadServlet.java
/** * @param req/*ww w .ja v a2 s.c o m*/ * @param tempZipFile * @param exportSerailizationFolderPath * @param printWriter * @return */ private File readAndParseAttachedFile(HttpServletRequest req, String exportSerailizationFolderPath, PrintWriter printWriter) { List<FileItem> items; File tempZipFile = null; try { FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); InputStream instream = null; OutputStream out = null; items = upload.parseRequest(req); for (FileItem item : items) { if (!item.isFormField() && IMPORT_FILE.equals(item.getFieldName())) { zipFileName = item.getName(); if (zipFileName != null) { zipFileName = zipFileName.substring(zipFileName.lastIndexOf(File.separator) + 1); } zipPathname = exportSerailizationFolderPath + File.separator + zipFileName; // get only the file name not whole path zipPathname = zipFileName; if (zipFileName != null) { zipFileName = FilenameUtils.getName(zipFileName); } try { instream = item.getInputStream(); tempZipFile = new File(zipPathname); if (tempZipFile.exists()) { tempZipFile.delete(); } out = new FileOutputStream(tempZipFile); byte buf[] = new byte[1024]; int len = instream.read(buf); while (len > 0) { out.write(buf, 0, len); len = instream.read(buf); } } catch (FileNotFoundException e) { LOG.error("Unable to create the export folder." + e, e); printWriter.write("Unable to create the export folder.Please try again."); } catch (IOException e) { LOG.error("Unable to read the file." + e, e); printWriter.write("Unable to read the file.Please try again."); } finally { if (out != null) { try { out.close(); } catch (IOException ioe) { LOG.info("Could not close stream for file." + tempZipFile); } } if (instream != null) { try { instream.close(); } catch (IOException ioe) { LOG.info("Could not close stream for file." + zipFileName); } } } } } } catch (FileUploadException e) { LOG.error("Unable to read the form contents." + e, e); printWriter.write("Unable to read the form contents.Please try again."); } return tempZipFile; }
From source file:net.hillsdon.reviki.web.pages.impl.DefaultPageImpl.java
public View attach(final PageReference page, final ConsumedPath path, final HttpServletRequest request, final HttpServletResponse response) throws Exception { if (!ServletFileUpload.isMultipartContent(request)) { throw new InvalidInputException("multipart request expected."); }/*from ww w . j a va 2 s.c o m*/ List<FileItem> items = getFileItems(request); try { if (items.size() > 4) { throw new InvalidInputException("One file at a time."); } String attachmentName = null; Long baseRevision = null; String attachmentMessage = null; FileItem file = null; for (FileItem item : items) { if (PARAM_ATTACHMENT_NAME.equals(item.getFieldName())) { attachmentName = item.getString().trim(); } if (PARAM_BASE_REVISION.equals(item.getFieldName())) { baseRevision = RequestParameterReaders.getLong(item.getString().trim(), PARAM_BASE_REVISION); } if (PARAM_ATTACHMENT_MESSAGE.equals(item.getFieldName())) { attachmentMessage = item.getString().trim(); if (attachmentMessage.length() == 0) { attachmentMessage = null; } } if (!item.isFormField()) { file = item; } } if (baseRevision == null) { baseRevision = VersionedPageInfo.UNCOMMITTED; } if (file == null || file.getSize() == 0) { request.setAttribute("flash", ERROR_NO_FILE); return attachments(page, path, request, response); } else { InputStream in = file.getInputStream(); try { // get the page from store - needed to get content of the special // pages which were not saved yet PageInfo pageInfo = _store.get(page, -1); // IE sends the full file path. storeAttachment(pageInfo, attachmentName, baseRevision, attachmentMessage, FilenameUtils.getName(file.getName()), in); _store.expire(pageInfo); return new RedirectToPageView(_wikiUrls, page, "/attachments/"); } finally { IOUtils.closeQuietly(in); } } } finally { for (FileItem item : items) { item.delete(); } } }
From source file:com.siemens.sw360.datahandler.common.CommonUtils.java
public static String getTargetNameOfUrl(String url) { try {// w w w. j a v a 2 s .c o m String path = new URL(url).getPath(); String fileName = FilenameUtils.getName(path); return !isNullOrEmpty(fileName) ? fileName : path; } catch (MalformedURLException e) { return ""; } }
From source file:eu.openanalytics.rsb.component.JobsResource.java
private static String getPartFileName(final Attachment part) { return FilenameUtils.getName(part.getContentDisposition().getParameter("filename")); }
From source file:com.ephesoft.gxt.admin.server.ExportDocumentTypeDownloadServlet.java
/** * This API is used to check and copy selected document types . * //from ww w .ja va 2s. co m * @param DirList {@link String []} directories list. * @param documentType {@link DocumentType} selected document type. * @param srcPath {@link String} source path. * @param destPath {@link String} destination path. * @return */ private void copyDocumentType(final String[] DirList, final DocumentType documentType, final String srcPath, final String destPath) throws IOException { final File classificationDir = new File(srcPath); for (int i = 0; i < DirList.length; i++) { if (FilenameUtils.getName(DirList[i]).equalsIgnoreCase(documentType.getName())) { final File destFolder = new File(destPath); if (!destFolder.exists()) { destFolder.mkdirs(); } FileUtils.copyDirectoryWithContents(new File(classificationDir, DirList[i]), new File(destFolder, DirList[i])); } } }