List of usage examples for org.apache.commons.fileupload InvalidFileNameException InvalidFileNameException
public InvalidFileNameException(String pName, String pMessage)
From source file:de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.RemoteApiController.java
/** * Create a new project.// www . j ava2 s . c o m * * To test, use the Linux "curl" command. * * curl -v -F 'file=@test.zip' -F 'name=Test' -F 'filetype=tcf' * 'http://USERNAME:PASSWORD@localhost:8080/de.tudarmstadt.ukp.clarin.webanno.webapp/api/project * ' * * @param aName * the name of the project to create. * @param aFileType * the type of the files contained in the ZIP. The possible file types are configured * in the formats.properties configuration file of WebAnno. * @param aFile * a ZIP file containing the project data. * @throws Exception if there was en error. */ @RequestMapping(value = "/project", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE) public @ResponseStatus(HttpStatus.NO_CONTENT) void createProject(@RequestParam("file") MultipartFile aFile, @RequestParam("name") String aName, @RequestParam("filetype") String aFileType) throws Exception { LOG.info("Creating project [" + aName + "]"); if (!ZipUtils.isZipStream(aFile.getInputStream())) { throw new InvalidFileNameException("", "is an invalid Zip file"); } // Get current user String username = SecurityContextHolder.getContext().getAuthentication().getName(); User user = userRepository.get(username); Project project = null; // Configure project if (!projectRepository.existsProject(aName)) { project = new Project(); project.setName(aName); // Create the project and initialize tags projectRepository.createProject(project, user); annotationService.initializeTypesForProject(project, user, new String[] {}, new String[] {}, new String[] {}, new String[] {}, new String[] {}, new String[] {}, new String[] {}, new String[] {}); // Create permission for this user ProjectPermission permission = new ProjectPermission(); permission.setLevel(PermissionLevel.ADMIN); permission.setProject(project); permission.setUser(username); projectRepository.createProjectPermission(permission); permission = new ProjectPermission(); permission.setLevel(PermissionLevel.USER); permission.setProject(project); permission.setUser(username); projectRepository.createProjectPermission(permission); } // Existing project else { throw new IOException("The project with name [" + aName + "] exists"); } // Iterate through all the files in the ZIP // If the current filename does not start with "." and is in the root folder of the ZIP, // import it as a source document File zimpFile = File.createTempFile(aFile.getOriginalFilename(), ".zip"); aFile.transferTo(zimpFile); ZipFile zip = new ZipFile(zimpFile); for (Enumeration<?> zipEnumerate = zip.entries(); zipEnumerate.hasMoreElements();) { // // Get ZipEntry which is a file or a directory // ZipEntry entry = (ZipEntry) zipEnumerate.nextElement(); // If it is the zip name, ignore it if ((FilenameUtils.removeExtension(aFile.getOriginalFilename()) + "/").equals(entry.toString())) { continue; } // IF the current filename is META-INF/webanno/source-meta-data.properties store it // as // project meta data else if (entry.toString().replace("/", "") .equals((META_INF + "webanno/source-meta-data.properties").replace("/", ""))) { InputStream zipStream = zip.getInputStream(entry); projectRepository.savePropertiesFile(project, zipStream, entry.toString()); } // File not in the Zip's root folder OR not // META-INF/webanno/source-meta-data.properties else if (StringUtils.countMatches(entry.toString(), "/") > 1) { continue; } // If the current filename does not start with "." and is in the root folder of the // ZIP, import it as a source document else if (!FilenameUtils.getExtension(entry.toString()).equals("") && !FilenameUtils.getName(entry.toString()).equals(".")) { uploadSourceDocument(zip, entry, project, user, aFileType); } } LOG.info("Successfully created project [" + aName + "] for user [" + username + "]"); }
From source file:org.jumpmind.metl.core.util.DatabaseScript.java
public void parse(String fileName) { String[] parts = fileName.split(DELIMITER_MAIN); if (parts.length != 4) { throw new InvalidFileNameException(fileName, "Database scripts must have 3 parts : version_when_order_description.sql"); }//ww w .j a v a2 s. com parseVersion(parts[0]); when = parseWhen(parts[1]); order = new Integer(parts[2]); parseDescription(parts[3]); }