List of usage examples for org.apache.commons.lang StringUtils removeEnd
public static String removeEnd(String str, String remove)
Removes a substring only if it is at the end of a source string, otherwise returns the source string.
From source file:com.adobe.acs.commons.workflow.bulk.impl.servlets.StatusServlet.java
@Override protected final void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); final ValueMap properties = request.getResource().adaptTo(ValueMap.class); final JSONObject json = new JSONObject(); int total = properties.get(BulkWorkflowEngine.KEY_TOTAL, 0); int complete = properties.get(BulkWorkflowEngine.KEY_COMPLETE_COUNT, 0); try {/*from ww w . j a v a 2s .c o m*/ json.put(BulkWorkflowEngine.KEY_STATE, properties.get(BulkWorkflowEngine.KEY_STATE, BulkWorkflowEngine.STATE_NOT_STARTED)); json.put(BulkWorkflowEngine.KEY_QUERY, properties.get(BulkWorkflowEngine.KEY_QUERY, "")); json.put(BulkWorkflowEngine.KEY_WORKFLOW_MODEL, StringUtils .removeEnd(properties.get(BulkWorkflowEngine.KEY_WORKFLOW_MODEL, ""), "/jcr:content/model")); json.put(BulkWorkflowEngine.KEY_BATCH_SIZE, properties.get(BulkWorkflowEngine.KEY_BATCH_SIZE, BulkWorkflowEngine.DEFAULT_BATCH_SIZE)); json.put(BulkWorkflowEngine.KEY_CURRENT_BATCH, properties.get(BulkWorkflowEngine.KEY_CURRENT_BATCH, "Unknown")); json.put(BulkWorkflowEngine.KEY_PURGE_WORKFLOW, properties.get(BulkWorkflowEngine.KEY_PURGE_WORKFLOW, BulkWorkflowEngine.DEFAULT_PURGE_WORKFLOW)); json.put(BulkWorkflowEngine.KEY_INTERVAL, properties.get(BulkWorkflowEngine.KEY_INTERVAL, BulkWorkflowEngine.DEFAULT_INTERVAL)); json.put(BulkWorkflowEngine.KEY_BATCH_TIMEOUT, properties.get(BulkWorkflowEngine.KEY_BATCH_TIMEOUT, BulkWorkflowEngine.DEFAULT_BATCH_TIMEOUT)); // Counts json.put(BulkWorkflowEngine.KEY_TOTAL, total); json.put(BulkWorkflowEngine.KEY_COMPLETE_COUNT, complete); json.put("remaining", total - complete); json.put("percentComplete", Math.round((complete / (total * 1F)) * DECIMAL_TO_PERCENT)); json.put(BulkWorkflowEngine.KEY_FORCE_TERMINATED_COUNT, properties.get(BulkWorkflowEngine.KEY_FORCE_TERMINATED_COUNT, 0)); // Times json.put(BulkWorkflowEngine.KEY_STARTED_AT, properties.get(BulkWorkflowEngine.KEY_STARTED_AT, Date.class)); json.put(BulkWorkflowEngine.KEY_STOPPED_AT, properties.get(BulkWorkflowEngine.KEY_STOPPED_AT, Date.class)); json.put(BulkWorkflowEngine.KEY_COMPLETED_AT, properties.get(BulkWorkflowEngine.KEY_COMPLETED_AT, Date.class)); final Resource currentBatch = bulkWorkflowEngine.getCurrentBatch(request.getResource()); if (currentBatch != null) { json.put(BulkWorkflowEngine.KEY_CURRENT_BATCH, currentBatch.getPath()); for (final Resource child : currentBatch.getChildren()) { json.accumulate("currentBatchItems", new JSONObject(child.adaptTo(ValueMap.class))); } final ValueMap currentBatchProperties = currentBatch.adaptTo(ValueMap.class); json.put(BulkWorkflowEngine.KEY_BATCH_TIMEOUT_COUNT, currentBatchProperties.get(BulkWorkflowEngine.KEY_BATCH_TIMEOUT_COUNT, 1)); } response.getWriter().write(json.toString()); } catch (JSONException e) { log.error("Could not collect Bulk Workflow status due to: {}", e); HttpErrorUtil.sendJSONError(response, SlingHttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Could not collect Bulk Workflow status.", TextUtil.getFirstNonEmpty(e.getMessage(), "Check to ensure the ACS AEM Commons bundle is " + "installed and active.")); } }
From source file:com.jayway.jaxrs.hateoas.DefaultHateoasContext.java
private void mapClass(Class<?> clazz, String path) { if (!isInitialized(clazz)) { logger.info("Mapping class {}", clazz); if (path.endsWith("/")) { path = StringUtils.removeEnd(path, "/"); }/*from w ww. j a va 2s .c o m*/ Method[] methods = clazz.getMethods(); for (Method method : methods) { if (!method.getDeclaringClass().equals(Object.class)) { mapMethod(clazz, path, method); } } } else { logger.info("Class {} already mapped. Skipped mapping.", clazz); } }
From source file:com.hangum.tadpole.rdb.core.editors.main.utils.ExtMakeContentAssistUtil.java
/** * make content assist util/*from ww w. j a v a2s . c om*/ * * @param userDB * @param strQuery * @param intPosition * @return */ public String makeContentAssist(final UserDBDAO userDB, String strQuery, final int intPosition) throws Exception { strQuery = StringUtils.replace(strQuery, "\n", " "); String listContentAssist = ""; // ? String[] strPrevArryCursor = SQLTextUtil.findPreCursorObjectArry(strQuery, intPosition); String strCursor = strPrevArryCursor[0] + strPrevArryCursor[1]; if (logger.isDebugEnabled()) logger.debug("\t position text is [" + strCursor + "]"); // ? . String strPrevKeyword = SQLTextUtil.findPrevKeywork(strQuery, intPosition); if (logger.isDebugEnabled()) logger.debug("\t prevous keyword is : [" + strPrevKeyword + "]"); CONTENT_ASSIST_KEYWORD_TYPE prevKeywordType = null; // ? ? . strQuery = StringUtils.removeEnd(StringUtils.trimToEmpty(strQuery), ";") + " "; // ? ? ? ?, ? . if (!"".equals(strPrevKeyword)) { if (SQLConstants.listTableKeywords.contains(strPrevKeyword)) { prevKeywordType = CONTENT_ASSIST_KEYWORD_TYPE.TABLE; } else if (SQLConstants.listColumnKeywords.contains(strPrevKeyword)) { prevKeywordType = CONTENT_ASSIST_KEYWORD_TYPE.COLUMN; } } if (prevKeywordType != null) { if (strCursor.length() == 0) { // ?? ?? . if (prevKeywordType == CONTENT_ASSIST_KEYWORD_TYPE.COLUMN) { if (logger.isDebugEnabled()) logger.debug("==========[0][CURSOR][COLUMN] content assist : "); listContentAssist = getTableColumnAlias(userDB, strQuery, strCursor); // ? ?? . } else { if (logger.isDebugEnabled()) logger.debug("==========[0][CURSOR][TABLE] content assist : "); // insert ? ? ? . listContentAssist = ifInsertGetColumn(userDB, strQuery, strCursor); // ? ? ?? . if ("".equals(listContentAssist)) { listContentAssist = getSchemaOrTableContentAssist(userDB, strPrevArryCursor); } } if (logger.isDebugEnabled()) logger.debug("\t result : " + listContentAssist); } else { // ?? ?? . if (prevKeywordType == CONTENT_ASSIST_KEYWORD_TYPE.COLUMN) { if (logger.isDebugEnabled()) logger.debug("+++++++++++[1][DEFAULT][COLUMN] content assist : " + listContentAssist); listContentAssist = getTableColumnAlias(userDB, strQuery, strCursor); } else { // ?, ? ?, ?? . if (logger.isDebugEnabled()) logger.debug("+++++++++++[1][DEFAULT][TABLE] content assist : " + listContentAssist); // insert ? ? ? . listContentAssist = ifInsertGetColumn(userDB, strQuery, strCursor); // ? ? ?? . if ("".equals(listContentAssist)) { listContentAssist = getSchemaOrTableContentAssist(userDB, strPrevArryCursor); } } if (logger.isDebugEnabled()) logger.debug("\t result : " + listContentAssist); } } else { if (logger.isDebugEnabled()) logger.debug("[NONE] content assist : " + listContentAssist); } return listContentAssist; }
From source file:com.dp2345.plugin.ftp.FtpController.java
/** * /*from w w w. j ava2 s . c o m*/ */ @RequestMapping(value = "/update", method = RequestMethod.POST) public String update(String host, Integer port, String username, String password, String urlPrefix, @RequestParam(defaultValue = "false") Boolean isEnabled, Integer order, RedirectAttributes redirectAttributes) { PluginConfig pluginConfig = ftpPlugin.getPluginConfig(); pluginConfig.setAttribute("host", host); pluginConfig.setAttribute("port", port.toString()); pluginConfig.setAttribute("username", username); pluginConfig.setAttribute("password", password); pluginConfig.setAttribute("urlPrefix", StringUtils.removeEnd(urlPrefix, "/")); pluginConfig.setIsEnabled(isEnabled); pluginConfig.setOrder(order); pluginConfigService.update(pluginConfig); addFlashMessage(redirectAttributes, SUCCESS_MESSAGE); return "redirect:/admin/storage_plugin/list.jhtml"; }
From source file:info.magnolia.module.delta.BootstrapConditionally.java
private static String cleanupFilename(String filename) { filename = StringUtils.replace(filename, "\\", "/"); filename = StringUtils.substringAfterLast(filename, "/"); filename = StringUtils.substringBeforeLast(filename, "."); return StringUtils.removeEnd(filename, DataTransporter.XML); }
From source file:com.adguard.compiler.SettingUtils.java
public static void updateManifestFile(File dest, Browser browser, String version, String extensionId, String updateUrl, String extensionNamePostfix) throws IOException { switch (browser) { case CHROMIUM: File manifestFile = new File(dest, "manifest.json"); String content = FileUtils.readFileToString(manifestFile, "utf-8").trim(); if (updateUrl != null) { content = StringUtils.removeEnd(content, "}").trim(); content = content + ",\r\n\r\n"; content = content + "\t\"update_url\": \"" + updateUrl + "\"\r\n}"; }/*from w w w. j a va 2s . c om*/ content = StringUtils.replace(content, "${version}", version); FileUtils.writeStringToFile(manifestFile, content); break; case SAFARI: File infoPlistFile = new File(dest, "Info.plist"); String contentInfoPlist = FileUtils.readFileToString(infoPlistFile, "utf-8"); contentInfoPlist = StringUtils.replace(contentInfoPlist, "${extensionId}", extensionId); contentInfoPlist = StringUtils.replace(contentInfoPlist, "${version}", version); contentInfoPlist = StringUtils.replace(contentInfoPlist, "${updateURL}", updateUrl != null ? updateUrl : ""); contentInfoPlist = StringUtils.replace(contentInfoPlist, "${extensionNamePostfix}", extensionNamePostfix); FileUtils.writeStringToFile(infoPlistFile, contentInfoPlist); break; case FIREFOX: case FIREFOX_LEGACY: File installRdf = new File(dest, "install.rdf"); String contentRdf = FileUtils.readFileToString(installRdf, "utf-8").trim(); //write update url link if (updateUrl == null) { updateUrl = ""; } else { updateUrl = "<em:updateURL>" + updateUrl + "</em:updateURL>"; } contentRdf = StringUtils.replace(contentRdf, "${updateUrl}", updateUrl); contentRdf = StringUtils.replace(contentRdf, "${version}", version); contentRdf = StringUtils.replace(contentRdf, "${extensionId}", extensionId); FileUtils.writeStringToFile(installRdf, contentRdf); //write version File packageJson = new File(dest, "package.json"); String contentPackageJson = FileUtils.readFileToString(packageJson); contentPackageJson = StringUtils.replace(contentPackageJson, "${version}", version); contentPackageJson = StringUtils.replace(contentPackageJson, "${extensionId}", extensionId); contentPackageJson = StringUtils.replace(contentPackageJson, "${extensionNamePostfix}", extensionNamePostfix); FileUtils.writeStringToFile(packageJson, contentPackageJson); break; } }
From source file:com.hangum.tadpole.erd.core.relation.CubridTableRelation.java
/** * ? relation ?/*from w w w. ja v a2 s . co m*/ * * @param userDB * @return */ public static List<ReferencedTableDAO> makeCubridRelation(UserDBDAO userDB) throws Exception { List<ReferencedTableDAO> listRealRefTableDAO = new ArrayList<ReferencedTableDAO>(); // ? ?? . try { SqlMapClient sqlClient = TadpoleSQLManager.getInstance(userDB); List showTables = sqlClient.queryForList("tableList", userDB.getDb()); //$NON-NLS-1$ String tables = ""; for (Object table : showTables) { tables += String.format("'%s',", table); } if ("".equals(tables)) return listRealRefTableDAO; return makeCubridRelation(userDB, StringUtils.removeEnd(tables, "'")); } catch (Exception e) { logger.error("cubrid all table", e); throw new Exception("Cubrid relation exception " + e.getMessage()); } }
From source file:info.magnolia.content2bean.impl.TypeMappingImpl.java
/** * Get a adder method. Transforms name to singular. *///from ww w .j a v a2s . c o m public Method getAddMethod(Class<?> type, String name, int numberOfParameters) { name = StringUtils.capitalize(name); Method method = getExactMethod(type, "add" + name, numberOfParameters); if (method == null) { method = getExactMethod(type, "add" + StringUtils.removeEnd(name, "s"), numberOfParameters); } if (method == null) { method = getExactMethod(type, "add" + StringUtils.removeEnd(name, "es"), numberOfParameters); } if (method == null) { method = getExactMethod(type, "add" + StringUtils.removeEnd(name, "ren"), numberOfParameters); } if (method == null) { method = getExactMethod(type, "add" + StringUtils.removeEnd(name, "ies") + "y", numberOfParameters); } return method; }
From source file:com.sammyun.plugin.ftp.FtpController.java
/** * /*from ww w .j a va 2 s . com*/ */ @RequestMapping(value = "/update", method = RequestMethod.POST) public String update(ModelMap model, String host, Integer port, String username, String password, String urlPrefix, @RequestParam(defaultValue = "false") Boolean isEnabled, Integer order, RedirectAttributes redirectAttributes) { PluginConfig pluginConfig = ftpPlugin.getPluginConfig(); pluginConfig.setAttribute("host", host); pluginConfig.setAttribute("port", port.toString()); pluginConfig.setAttribute("username", username); pluginConfig.setAttribute("password", password); pluginConfig.setAttribute("urlPrefix", StringUtils.removeEnd(urlPrefix, "/")); pluginConfig.setIsEnabled(isEnabled); pluginConfig.setOrder(order); pluginConfigService.update(pluginConfig); model.addAttribute("menuId", StoragePlugin.class.getSimpleName()); addFlashMessage(redirectAttributes, SUCCESS_MESSAGE); return "redirect:/console/storage_plugin/list.ct"; }
From source file:com.cloudbees.hudson.plugins.folder.computed.PeriodicFolderTrigger.java
/** * Turns an interval into milliseconds./ * * @param interval the interval./* w w w . ja v a 2 s .co m*/ * @return the milliseconds. */ private static long toIntervalMillis(String interval) { TimeUnit2 units = TimeUnit2.MINUTES; interval = interval.toLowerCase(); if (interval.endsWith("h")) { units = TimeUnit2.HOURS; interval = StringUtils.removeEnd(interval, "h"); } if (interval.endsWith("m")) { interval = StringUtils.removeEnd(interval, "m"); } else if (interval.endsWith("d")) { units = TimeUnit2.DAYS; interval = StringUtils.removeEnd(interval, "d"); } else if (interval.endsWith("ms")) { units = TimeUnit2.SECONDS; interval = StringUtils.removeEnd(interval, "ms"); } else if (interval.endsWith("s")) { units = TimeUnit2.SECONDS; interval = StringUtils.removeEnd(interval, "s"); } long value = 0; try { value = Long.parseLong(interval); } catch (NumberFormatException e) { value = 1; } return Math.min(TimeUnit2.DAYS.toMillis(30), Math.max(TimeUnit2.MINUTES.toMillis(1), units.toMillis(value))); }