List of usage examples for org.apache.commons.lang StringUtils trim
public static String trim(String str)
Removes control characters (char <= 32) from both ends of this String, handling null
by returning null
.
From source file:com.idocbox.common.file.ZipExtracter.java
/** * extract given zip entry file from zip file * to given destrination directory.//from w w w . j a va2s. c om * @param zf ZipFile object. * @param zipEntry zip entry to extract. * @param desDir destrination directory. * @param startDirLevel the level to start create directory. * Its value is 1,2,... * @throws IOException throw the exception whil desDir is no directory. */ private static void extract(final ZipFile zf, final ZipEntry zipEntry, final String desDir, final int... startDirLevel) throws IOException { //check destination directory. File desf = new File(desDir); if (!desf.exists()) { desf.mkdirs(); } int start = 1; if (null != startDirLevel && startDirLevel.length > 0) { start = startDirLevel[0]; if (start < 1) { start = 1; } } String startDir = ""; String zeName = zipEntry.getName(); String folder = zeName; boolean isDir = zipEntry.isDirectory(); if (null != folder) { String[] folders = folder.split("\\/"); if (null != folders && folders.length > 0) { int len = folders.length; if (start == 1) { startDir = zeName; } else { if (start > len) { //nothing to extract. } else { for (int i = start - 1; i < len; i++) { startDir += "/" + folders[i]; } if (null != startDir) { startDir = startDir.substring(1); } } } } } startDir = StringUtils.trim(startDir); if (StringUtils.isNotEmpty(startDir)) { StringBuilder desFileName = new StringBuilder(desDir); if (!desDir.endsWith("/") && !startDir.startsWith("/")) { desFileName.append("/"); } desFileName.append(startDir); File destFile = new File(desFileName.toString()); if (isDir) {//the entry is a dir. if (!destFile.exists()) { destFile.mkdirs(); } } else {//the entry is a file. File parentDir = new File(destFile.getParentFile().getPath()); if (!parentDir.exists()) { parentDir.mkdirs(); } //get entry input stream. InputStream is = zf.getInputStream(zipEntry); OutputStream os = new FileOutputStream(destFile); IOUtils.copy(is, os); if (null != is) { is.close(); } if (null != os) { os.close(); } } } }
From source file:com.intuit.tank.report.JobReportOptions.java
/** * @param maxUsers * the maxUsers to set */ public void setMaxUsers(String maxUsers) { this.maxUsers = StringUtils.trim(maxUsers); }
From source file:com.edgenius.wiki.PageTheme.java
public String getSidebarMarkup() { return StringUtils.trim(sidebarMarkup); }
From source file:com.junly.service.helper.TicketHelper.java
/** <p class="detail"> * header ticket/* ww w . ja v a 2 s . c om*/ * </p> * @author junly * @date 2017324 * @param request * @param httpChannelType * @return */ private String customHeadTicket(HttpServletRequest request, HttpChannelType httpChannelType) { String ticket = request.getHeader(ViewContants.LOGIN_TICKET_KEY); if (StringUtils.isNotBlank(ticket)) { logger.info(httpChannelType.name() + ": header?ticket=" + ticket); } /* Enumeration<?> headerNames = request.getHeaderNames(); while (headerNames.hasMoreElements()) { String key = (String) headerNames.nextElement(); logger.info(httpChannelType.name() + ": header: key=" + key + "; value=" + request.getHeader(key)); }*/ return StringUtils.trim(ticket); }
From source file:com.adobe.acs.commons.workflow.process.impl.BrandPortalSyncProcess.java
protected final ReplicationActionType getReplicationActionType(MetaDataMap metaDataMap) { final String processArgs = StringUtils .trim(metaDataMap.get("PROCESS_ARGS", ReplicationActionType.ACTIVATE.getName())); if (StringUtils.equalsIgnoreCase(processArgs, ReplicationActionType.ACTIVATE.getName())) { return ReplicationActionType.ACTIVATE; } else if (StringUtils.equalsIgnoreCase(processArgs, ReplicationActionType.DEACTIVATE.getName())) { return ReplicationActionType.DEACTIVATE; }//from w ww . j a v a2 s .com return null; }
From source file:com.hangum.tadpole.sql.util.sqlscripts.DDLScriptManager.java
/** * /*from w ww . j a v a 2s .c o m*/ * @param obj * @return */ public String getScript(Object obj) throws Exception { String retStr = ""; // find DDL Object if (PublicTadpoleDefine.DB_ACTION.TABLES == actionType) { retStr = rdbScript.getTableScript((TableDAO) obj); } else if (PublicTadpoleDefine.DB_ACTION.VIEWS == actionType) { retStr = rdbScript.getViewScript(obj.toString()); } else if (PublicTadpoleDefine.DB_ACTION.INDEXES == actionType) { retStr = rdbScript.getIndexScript((InformationSchemaDAO) obj); } else if (PublicTadpoleDefine.DB_ACTION.FUNCTIONS == actionType) { retStr = rdbScript.getFunctionScript((ProcedureFunctionDAO) obj); } else if (PublicTadpoleDefine.DB_ACTION.PROCEDURES == actionType) { retStr = rdbScript.getProcedureScript((ProcedureFunctionDAO) obj); } else if (PublicTadpoleDefine.DB_ACTION.PACKAGES == actionType) { retStr = rdbScript.getProcedureScript((ProcedureFunctionDAO) obj); } else if (PublicTadpoleDefine.DB_ACTION.TRIGGERS == actionType) { retStr = rdbScript.getTriggerScript((TriggerDAO) obj); } else { throw new Exception("Not support Database"); } // ; ? ??? . if (StringUtils.endsWith(StringUtils.trim(retStr), PublicTadpoleDefine.SQL_DELIMITER)) { return retStr; } else { return retStr + PublicTadpoleDefine.SQL_DELIMITER; } }
From source file:com.twitter.ambrose.hive.AmbroseHiveFinishHook.java
private String getLastCmd() { CliSessionState cliss = (CliSessionState) SessionState.get(); Scanner scanner = null;//from ww w .j av a 2s .c o m try { scanner = new Scanner(new File(cliss.fileName)); } catch (FileNotFoundException e) { LOG.error("Can't find Hive script", e); } if (scanner == null) { return null; } Pattern delim = Pattern.compile(";"); scanner.useDelimiter(delim); String lastLine = null; while (scanner.hasNext()) { String line = StringUtils.trim(scanner.next().replaceAll("\\n|\\r", "")); if (line.length() != 0 && !line.startsWith("--")) { lastLine = line; } } return lastLine; }
From source file:hydrograph.ui.expression.editor.dialogs.AddCategoreisDialog.java
public boolean createPropertyFileForSavingData() { IProject iProject = BuildExpressionEditorDataSturcture.INSTANCE.getCurrentProject(); IFolder iFolder = iProject.getFolder(PathConstant.PROJECT_RESOURCES_FOLDER); FileOutputStream file = null; Properties properties = new Properties(); try {/*from w ww .jav a 2 s. c om*/ if (!iFolder.exists()) { iFolder.create(true, true, new NullProgressMonitor()); } for (String items : categoriesDialogTargetComposite.getTargetList().getItems()) { String jarFileName = StringUtils.trim(StringUtils.substringAfter(items, Constants.DASH)); String packageName = StringUtils.trim(StringUtils.substringBefore(items, Constants.DASH)); properties.setProperty(packageName, jarFileName); } file = new FileOutputStream(iFolder.getLocation().toString() + File.separator + PathConstant.EXPRESSION_EDITOR_EXTERNAL_JARS_PROPERTIES_FILES); properties.store(file, ""); return true; } catch (IOException | CoreException exception) { LOGGER.error("Exception occurred while saving jar file path at projects setting folder", exception); } finally { if (file != null) { try { file.close(); } catch (IOException e) { LOGGER.warn("Exception in closing output stream. The error message is " + e.getMessage()); } } } return false; }
From source file:com.redhat.winddrop.mdb.WindupExecutionQueueMDB.java
@TransactionAttribute(TransactionAttributeType.REQUIRED) public void buildAndUploadReport(String hashValue, String submitter, String packages) { LOG.info(">>> buildAndUploadReport (hashValue=" + hashValue + ",packages=" + packages + ")"); List<File> filesToDelete = new ArrayList<File>(); try {//from w ww . j a v a 2s .c o m com.redhat.winddrop.model.File storedBinaryFile = fileRepository.findByHashValue(hashValue); String windupOutputDirectoryName = FileUtil.WINDDROP_TMP_DIR + hashValue + "_out" + FileUtil.FILE_SEPARATOR; File windupOutputDirectory = new File(windupOutputDirectoryName); windupOutputDirectory.mkdir(); filesToDelete.add(windupOutputDirectory); String windupInputDirectoryName = FileUtil.WINDDROP_TMP_DIR + hashValue + "_in" + FileUtil.FILE_SEPARATOR; File windupInputDirectory = new File(windupInputDirectoryName); windupInputDirectory.mkdir(); filesToDelete.add(windupInputDirectory); File windupInputFile = new File(windupInputDirectoryName + storedBinaryFile.getUploadedFileName()); // Copying the uploaded file and use it as input for windup. FileUtil.copy(new File(StringUtils.trim(storedBinaryFile.getStorageFileName())), windupInputFile); filesToDelete.add(windupInputFile); // Execute windup executeWindup(packages, windupInputFile, windupOutputDirectory); // Zip the resulting report String zippedReportFileName = storedBinaryFile.getUploadedFileName() + FileUtil.REPORT_EXTENSION; File zippedReport = new File(windupInputDirectoryName + zippedReportFileName); filesToDelete.add(zippedReport); LOG.info("[" + hashValue + "] Zipping the created report ..."); FileUtil.zip(windupOutputDirectory, zippedReport); // Upload the result LOG.info("[" + hashValue + "] Storing report ..."); fileRepository.removeReportRequest(hashValue); hashValue = FileUtil.storeFile(zippedReport, zippedReportFileName, fileRepository, submitter, packages, true, true); LOG.info("[" + hashValue + "] Execution successfull ... wget http://localhost:8080/winddrop/rest/dl/file/" + hashValue); } catch (Throwable t) { t.printStackTrace(); } finally { // Cleanup LOG.info("[" + hashValue + "] Cleaning temporary files ..."); for (File file : filesToDelete) { if (file.exists()) { if (file.isDirectory()) { try { FileUtils.deleteDirectory(file); } catch (IOException e) { } } else { file.delete(); } } } } LOG.info("<<< buildAndUploadReport"); }
From source file:mitm.common.postfix.SaslPasswordManager.java
protected static List<SaslPassword> parseContent(String input) { List<SaslPassword> passwords = new LinkedList<SaslPassword>(); if (StringUtils.isEmpty(input)) { return passwords; }/*w w w. ja v a 2 s.com*/ LineIterator lineIterator = IOUtils.lineIterator(new StringReader(input)); while (lineIterator.hasNext()) { String line = lineIterator.nextLine(); if (!StringUtils.isBlank(line)) { Matcher m = SASL_PASSWORD_PATTERN.matcher(line); if (m.matches()) { boolean mxLookup = !("[".equals(m.group(1)) && "]".equals(m.group(3))); String server = StringUtils.trim(m.group(2)); Integer port = NumberUtils.toInt(StringUtils.trim(m.group(4)), 0); String username = StringUtils.trim(m.group(5)); String password = StringUtils.trim(m.group(6)); SaslPassword saslPassword = new SaslPassword(); saslPassword.setMxLookup(mxLookup); saslPassword.setServer(server); saslPassword.setPort(port != 0 ? port : null); saslPassword.setUsername(username); saslPassword.setPassword(password); passwords.add(saslPassword); } } } return passwords; }