List of usage examples for org.apache.commons.lang StringUtils splitPreserveAllTokens
public static String[] splitPreserveAllTokens(String str, String separatorChars)
Splits the provided text into an array, separators specified, preserving all tokens, including empty tokens created by adjacent separators.
From source file:org.openflamingo.fs.hdfs.HdfsFileSystemServiceImpl.java
@Override public List<String> copyFiles(Context context, FileSystemCommand command) { ResourceBundleRetreiver bundle = getResourceBundle(context); String[] paths = StringUtils.splitPreserveAllTokens(context.getString("hdfs.delete.forbidden.paths"), ","); AntPathMatcher antPathMatcher = new AntPathMatcher(); for (String path : paths) { String destinationPath = command.getString("to"); String pathToValid = FileUtils.getPath(destinationPath); boolean isMatch = antPathMatcher.match(path, pathToValid); if (isMatch) { throw new FileSystemException( bundle.message("S_FS_SERVICE", "INCLUDED_FOBIDDEN_RULES", pathToValid)); }/*from w ww. ja v a 2 s. c om*/ } try { FileSystemProvider provider = getFileSystemProvider(context); List<String> ps = (List<String>) command.getObject("from"); List<String> copied = new ArrayList(); for (String p : ps) { long length = getFileInfo(context, p).getLength(); boolean isCopied = provider.copy(p, command.getString("to")); if (isCopied) { copied.add(p); auditService.log(context, FileSystemType.HDFS, AuditType.COPY, FileType.FILE, p, command.getString("to"), length); } } return copied; } catch (Exception ex) { throw new FileSystemException(bundle.message("S_FS_SERVICE", "CANNOT_COPY_FILE"), ex); } }
From source file:org.openflamingo.fs.hdfs.HdfsFileSystemServiceImpl.java
@Override public List<String> moveFiles(Context context, FileSystemCommand command) { ResourceBundleRetreiver bundle = getResourceBundle(context); String[] paths = StringUtils.splitPreserveAllTokens(context.getString("hdfs.delete.forbidden.paths"), ","); AntPathMatcher antPathMatcher = new AntPathMatcher(); for (String path : paths) { String pathToValid = command.getString("to"); boolean isMatch = antPathMatcher.match(path, pathToValid); if (isMatch) { throw new FileSystemException( bundle.message("S_FS_SERVICE", "INCLUDED_FOBIDDEN_RULES", pathToValid)); }// ww w. j a v a 2 s . co m } for (String path : paths) { String destinationPath = ((List<String>) command.getObject("from")).get(0); String pathToValid = FileUtils.getPath(destinationPath); boolean isMatch = antPathMatcher.match(path, pathToValid); if (isMatch) { throw new FileSystemException( bundle.message("S_FS_SERVICE", "INCLUDED_FOBIDDEN_RULES", pathToValid)); } } try { FileSystemProvider provider = getFileSystemProvider(context); List<String> ps = (List<String>) command.getObject("from"); List<String> moved = new ArrayList(); for (String p : ps) { long length = getFileInfo(context, p).getLength(); boolean isMoved = provider.move(p, command.getString("to")); if (isMoved) { moved.add(p); auditService.log(context, FileSystemType.HDFS, AuditType.MOVE, FileType.FILE, p, command.getString("to"), length); } } return moved; } catch (Exception ex) { throw new FileSystemException(bundle.message("S_FS_SERVICE", "CANNOT_MOVE_FILE"), ex); } }
From source file:org.openflamingo.fs.hdfs.HdfsFileSystemServiceImpl.java
@Override public List<String> deleteFiles(Context context, FileSystemCommand command) { ResourceBundleRetreiver bundle = getResourceBundle(context); String[] paths = StringUtils.splitPreserveAllTokens(context.getString("hdfs.delete.forbidden.paths"), ","); AntPathMatcher antPathMatcher = new AntPathMatcher(); String first = ((List<String>) command.getObject("path")).get(0); for (String path : paths) { String pathToValid = FileUtils.getPath(first); boolean isMatch = antPathMatcher.match(path, pathToValid); if (isMatch) { throw new FileSystemException( bundle.message("S_FS_SERVICE", "INCLUDED_FOBIDDEN_RULES", pathToValid)); }//from w ww. ja v a2 s .co m } try { FileSystemProvider provider = getFileSystemProvider(context); List<String> ps = (List<String>) command.getObject("path"); List<String> deleted = new ArrayList(); for (String p : ps) { long length = getFileInfo(context, p).getLength(); boolean isDeleted = provider.delete(p); if (isDeleted) { deleted.add(p); auditService.log(context, FileSystemType.HDFS, AuditType.DELETE, FileType.FILE, p, "", length); } } return deleted; } catch (Exception ex) { throw new FileSystemException(bundle.message("S_FS_SERVICE", "CANNOT_DELETE_FILE"), ex); } }
From source file:org.openflamingo.fs.hdfs.HdfsFileSystemServiceImpl.java
@Override public boolean save(Context context, FileSystemCommand command) { ResourceBundleRetreiver bundle = getResourceBundle(context); String[] paths = StringUtils.splitPreserveAllTokens(context.getString("hdfs.delete.forbidden.paths"), ","); AntPathMatcher antPathMatcher = new AntPathMatcher(); for (String path : paths) { String pathToValid = command.getString("path"); boolean isMatch = antPathMatcher.match(path, pathToValid); if (isMatch) { throw new FileSystemException( bundle.message("S_FS_SERVICE", "INCLUDED_FOBIDDEN_RULES", pathToValid)); }//from w ww .j a v a2 s . c om } FileSystemProvider provider = getFileSystemProvider(context); if (provider.exists(command.getString("path"))) { throw new FileSystemException(bundle.message("S_FS_SERVICE", "ALREADY_EXISTS_FILE")); } try { boolean saved = provider.save(command.getString("path"), (byte[]) command.getObject("content")); auditService.log(context, FileSystemType.HDFS, AuditType.UPLOAD, FileType.FILE, command.getString("path"), "", getFileInfo(context, command.getString("path")).getLength()); return saved; } catch (Exception ex) { throw new FileSystemException(bundle.message("S_FS_SERVICE", "CANNOT_UPLOAD"), ex); } }
From source file:org.openflamingo.uploader.el.ELService.java
/** * Comma Separated String? ./*from w w w . j a v a 2 s .c o m*/ * Trim . * * @param commaSeparatedList Comma Separated String * @return ? */ private String[] split(String commaSeparatedList) { List<String> params = new ArrayList<String>(); String[] values = StringUtils.splitPreserveAllTokens(commaSeparatedList.trim(), ","); for (String value : values) { params.add(value.trim()); } return org.openflamingo.uploader.util.StringUtils.collectionToStringArray(params); }
From source file:org.openmrs.module.clinicalsummary.evaluator.VelocityEvaluatorTest.java
public void evaluate_shouldSubstituteString() throws Exception { File directory = new File("/home/nribeka/Desktop/Yaw"); File substitutionFile = new File(directory, "substitute.txt"); Map<String, String> substitutes = new HashMap<String, String>(); // read and create the substitution map String line = null;/*from www .j a va 2 s . c o m*/ BufferedReader reader = new BufferedReader(new FileReader(substitutionFile)); while ((line = reader.readLine()) != null) { String[] elements = StringUtils.split(line, ","); if (elements.length == 2) substitutes.put(elements[0], elements[1]); } reader.close(); // start reading and substitute the file FileFilter fileFilter = new WildcardFileFilter("invalid*.txt"); for (File file : directory.listFiles(fileFilter)) { System.out.println(file.getName()); File outputFile = new File(directory, FilenameUtils.getBaseName(file.getName())); BufferedReader bufferedReader = new BufferedReader(new FileReader(file)); BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(outputFile)); String invalidLine = null; while ((invalidLine = bufferedReader.readLine()) != null) { System.out.println(invalidLine); String[] elements = StringUtils.splitPreserveAllTokens(invalidLine, ","); StringBuilder builder = new StringBuilder(); if (substitutes.containsKey(elements[0])) builder.append(substitutes.get(elements[0])); else builder.append(elements[0]); builder.append(","); builder.append(elements[1]); bufferedWriter.write(builder.toString()); bufferedWriter.newLine(); } bufferedReader.close(); bufferedWriter.close(); } }
From source file:org.openmrs.module.clinicalsummary.web.controller.service.ResponseController.java
private void processResponse(final UtilService utilService, final String[] parameterValues, final Patient patient) { for (String parameterValue : parameterValues) { try {//w ww .j a va 2 s . c o m String[] parameter = StringUtils.splitPreserveAllTokens(parameterValue, "|"); if (StringUtils.equalsIgnoreCase(HEADER_REMINDER, parameter[0])) saveReminderResponse(utilService, patient, parameter); else if (StringUtils.equalsIgnoreCase(HEADER_ARV_MEDICATION, parameter[0]) || StringUtils.equalsIgnoreCase(HEADER_OI_MEDICATION, parameter[0])) saveMedicationResponse(utilService, patient, parameter); } catch (ConstraintViolationException e) { log.info("Ignoring constrain violation and skipping the record"); } } }
From source file:org.openmrs.module.clinicalsummary.web.controller.service.ResponseController.java
private void processDeviceLogs(final UtilService utilService, final String id, final String[] parameterValues) { for (String parameterValue : parameterValues) { String[] parameter = StringUtils.splitPreserveAllTokens(parameterValue, "|"); if (StringUtils.equalsIgnoreCase(HEADER_LOG, parameter[0])) try { DeviceLog deviceLog = new DeviceLog(); deviceLog.setDeviceId(id); deviceLog.setKey(parameter[1]); deviceLog.setValue(parameter[2]); deviceLog.setTimestamp(parameter[3]); deviceLog.setUser(Context.getAuthenticatedUser().getPerson()); utilService.saveDeviceLog(deviceLog); } catch (ConstraintViolationException e) { log.info("Ignoring constrain violation and skipping the record"); }// w w w . j a va 2s . c om } }
From source file:org.openmrs.module.clinicalsummary.web.controller.utils.ExtendedDataEncounterController.java
@RequestMapping(method = RequestMethod.POST) public void processSubmit(final @RequestParam(required = true, value = "data") MultipartFile data, final @RequestParam(required = true, value = "conceptNames") String conceptNames, final HttpServletResponse response) throws IOException { List<Concept> concepts = new ArrayList<Concept>(); for (String conceptName : StringUtils.splitPreserveAllTokens(conceptNames, ",")) { Concept concept = Context.getConceptService().getConcept(conceptName); if (concept != null) concepts.add(concept);/*from w w w . ja va 2 s. c o m*/ } PatientService patientService = Context.getPatientService(); PatientSetService patientSetService = Context.getPatientSetService(); File identifierData = File.createTempFile(STUDY_DATA, INPUT_PREFIX); OutputStream identifierDataStream = new BufferedOutputStream(new FileOutputStream(identifierData)); FileCopyUtils.copy(data.getInputStream(), identifierDataStream); File extendedData = File.createTempFile(STUDY_DATA, OUTPUT_PREFIX); BufferedWriter writer = new BufferedWriter(new FileWriter(extendedData)); String line; BufferedReader reader = new BufferedReader(new FileReader(identifierData)); while ((line = reader.readLine()) != null) { Patient patient = null; String[] elements = StringUtils.splitPreserveAllTokens(line, ","); try { if (isDigit(StringUtils.trim(elements[1]))) patient = patientService.getPatient(NumberUtils.toInt(elements[1])); else { Cohort cohort = patientSetService.convertPatientIdentifier(Arrays.asList(elements[1])); for (Integer patientId : cohort.getMemberIds()) { Patient cohortPatient = patientService.getPatient(patientId); if (cohortPatient != null && !cohortPatient.isVoided()) patient = cohortPatient; } } } catch (Exception e) { log.error("Unable to resolve patients!", e); } Date referenceDate = WebUtils.parse(elements[2], "MM/dd/yyyy", new Date()); if (patient != null) { ExtendedData extended = new ExtendedData(patient, referenceDate); extended.setEncounters(searchEncounters(patient)); for (Concept concept : concepts) extended.addObservations(concept, searchObservations(patient, concept)); writer.write(extended.generateEncounterData()); writer.newLine(); ResultCacheInstance.getInstance().clearCache(patient); } else { writer.write("Unresolved patient id or patient identifier for " + elements[1]); writer.newLine(); } } reader.close(); writer.close(); InputStream inputStream = new BufferedInputStream(new FileInputStream(extendedData)); response.setHeader("Content-Disposition", "attachment; filename=generated-" + data.getOriginalFilename()); response.setContentType("text/plain"); FileCopyUtils.copy(inputStream, response.getOutputStream()); }
From source file:org.openmrs.module.clinicalsummary.web.controller.utils.ExtendedDataGeneralController.java
@RequestMapping(method = RequestMethod.POST) public void processRequest(final @RequestParam(required = true, value = "data") MultipartFile data, final @RequestParam(required = true, value = "conceptNames") String conceptNames, final HttpServletResponse response) throws IOException { List<Concept> concepts = new ArrayList<Concept>(); for (String conceptName : StringUtils.splitPreserveAllTokens(conceptNames, ",")) { Concept concept = Context.getConceptService().getConcept(conceptName); if (concept != null) concepts.add(concept);/*from w w w . ja v a 2 s . c o m*/ } PatientService patientService = Context.getPatientService(); PatientSetService patientSetService = Context.getPatientSetService(); File identifierData = File.createTempFile(STUDY_DATA, INPUT_PREFIX); OutputStream identifierDataStream = new BufferedOutputStream(new FileOutputStream(identifierData)); FileCopyUtils.copy(data.getInputStream(), identifierDataStream); File extendedData = File.createTempFile(STUDY_DATA, OUTPUT_PREFIX); BufferedWriter writer = new BufferedWriter(new FileWriter(extendedData)); String line; BufferedReader reader = new BufferedReader(new FileReader(identifierData)); while ((line = reader.readLine()) != null) { Patient patient = null; if (isDigit(StringUtils.trim(line))) patient = patientService.getPatient(NumberUtils.toInt(line)); else { Cohort cohort = patientSetService.convertPatientIdentifier(Arrays.asList(line)); for (Integer patientId : cohort.getMemberIds()) { Patient cohortPatient = patientService.getPatient(patientId); if (cohortPatient != null && !cohortPatient.isVoided()) patient = cohortPatient; } } if (patient != null) { ExtendedData extended = new ExtendedData(patient, null); extended.setEncounters(searchEncounters(patient)); for (Concept concept : concepts) extended.addObservations(concept, searchObservations(patient, concept)); writer.write(extended.generatePatientData()); writer.newLine(); ResultCacheInstance.getInstance().clearCache(patient); } else { writer.write("Unresolved patient id or patient identifier for " + line); writer.newLine(); } } reader.close(); writer.close(); InputStream inputStream = new BufferedInputStream(new FileInputStream(extendedData)); response.setHeader("Content-Disposition", "attachment; filename=" + data.getName()); response.setContentType("text/plain"); FileCopyUtils.copy(inputStream, response.getOutputStream()); }