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:edu.cornell.mannlib.vitro.webapp.visualization.visutils.UtilityFunctions.java
/** * Currently the approach for slugifying filenames is naive. In future if there is need, * we can write more sophisticated method. * @param textToBeSlugified/* w w w.j a v a 2 s.c o m*/ * @return */ public static String slugify(String textToBeSlugified) { String textBlockSeparator = "-"; return StringUtils.removeEnd(StringUtils.substring( textToBeSlugified.toLowerCase().trim().replaceAll("[^a-zA-Z0-9-]+", textBlockSeparator), 0, VisConstants.MAX_NAME_TEXT_LENGTH), textBlockSeparator); }
From source file:com.yhd.spark.oozie.OozieAuditLogParser.java
private void applyValueTo(OozieAuditLogObject oozieAuditLogObject, Matcher matcher) throws ParseException { oozieAuditLogObject.timestamp = DateTimeUtil.humanDateToMilliseconds(matcher.group(1)); oozieAuditLogObject.level = matcher.group(2); oozieAuditLogObject.ip = StringUtils.removeEnd(StringUtils.removeStart(matcher.group(6), "["), "]"); oozieAuditLogObject.user = StringUtils.removeEnd(StringUtils.removeStart(matcher.group(9), "["), "]"); oozieAuditLogObject.group = StringUtils.removeEnd(StringUtils.removeStart(matcher.group(12), "["), "]"); oozieAuditLogObject.app = StringUtils.removeEnd(StringUtils.removeStart(matcher.group(15), "["), "]"); oozieAuditLogObject.jobId = StringUtils.removeEnd(StringUtils.removeStart(matcher.group(18), "["), "]"); oozieAuditLogObject.operation = StringUtils.removeEnd(StringUtils.removeStart(matcher.group(21), "["), "]"); oozieAuditLogObject.parameter = StringUtils.removeEnd(StringUtils.removeStart(matcher.group(24), "["), "]"); oozieAuditLogObject.status = StringUtils.removeEnd(StringUtils.removeStart(matcher.group(27), "["), "]"); oozieAuditLogObject.httpcode = StringUtils.removeEnd(StringUtils.removeStart(matcher.group(30), "["), "]"); oozieAuditLogObject.errorcode = StringUtils.removeEnd(StringUtils.removeStart(matcher.group(33), "["), "]"); oozieAuditLogObject.errormessage = StringUtils.removeEnd(StringUtils.removeStart(matcher.group(36), "["), "]"); }
From source file:com.predic8.membrane.core.interceptor.IndexInterceptor.java
private ServiceInfo getServiceInfo(Exchange exc, AbstractServiceProxy sp) { if (sp.getInterceptors().size() == 1 && sp.getInterceptors().get(0) instanceof IndexInterceptor) return null; ServiceProxyKey k = (ServiceProxyKey) sp.getKey(); ServiceInfo ri = new ServiceInfo(); ri.method = k.getMethod();/*ww w.ja va 2 s. c o m*/ ri.ssl = sp.getSslInboundContext() != null;// NOTE: when running as servlet, we have no idea what the protocol was String protocol = ri.ssl ? "https" : "http"; String host = k.isHostWildcard() ? new HostColonPort(ri.ssl, exc.getRequest().getHeader().getHost()).host : fullfillRegexp(ServiceProxyKey.createHostPattern(k.getHost())); if (host == null || host.length() == 0) host = exc.getHandler().getLocalAddress().getHostAddress().toString(); int port = k.getPort(); if (port == -1 || !exc.getHandler().isMatchLocalPort()) port = exc.getHandler().getLocalPort(); String path; if (!k.isUsePathPattern()) { path = "/"; } else if (k.isPathRegExp()) { path = fullfillRegexp(k.getPath()); } else { path = "/" + StringUtils.removeStart(k.getPath(), "/"); } if (!"".equals(exc.getHandler().getContextPath(exc))) { path = StringUtils.removeEnd(exc.getHandler().getContextPath(exc), "/") + "/" + StringUtils.removeStart(path, "/"); } ri.name = sp.getName(); if (path != null) ri.url = protocol + "://" + host + ":" + port + path; ri.host = k.isHostWildcard() ? "" : StringEscapeUtils.escapeHtml(k.getHost()); ri.port = k.getPort() == -1 ? "" : "" + k.getPort(); ri.path = k.isUsePathPattern() ? "<tt>" + StringEscapeUtils.escapeHtml(k.getPath()) + "</tt>" + (k.isPathRegExp() ? " (regex)" : "") : ""; return ri; }
From source file:com.adobe.acs.commons.workflow.bulk.execution.impl.servlets.StatusServlet.java
@Override @SuppressWarnings({ "squid:S3776", "squid:S1192" }) protected final void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { SimpleDateFormat sdf = new SimpleDateFormat("EEE, d MMM yyyy hh:mm:ss aaa"); response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); Config config = request.getResource().adaptTo(Config.class); Workspace workspace = config.getWorkspace(); final JSONObject json = new JSONObject(); try {//from w ww.jav a 2 s . c om json.put("initialized", workspace.isInitialized()); json.put("status", workspace.getStatus()); if (workspace.getSubStatus() != null) { json.put("subStatus", workspace.getSubStatus()); } json.put("runnerType", config.getRunnerType()); json.put("queryType", config.getQueryType()); json.put("queryStatement", config.getQueryStatement()); json.put("workflowModel", StringUtils.removeEnd(config.getWorkflowModelId(), "/jcr:content/model")); json.put("batchSize", config.getBatchSize()); json.put("autoThrottle", config.isAutoThrottle()); json.put("purgeWorkflow", config.isPurgeWorkflow()); json.put("interval", config.getInterval()); json.put("retryCount", config.getRetryCount()); json.put("timeout", config.getTimeout()); json.put("throttle", config.getThrottle()); json.put("message", workspace.getMessage()); if (config.isUserEventData()) { json.put("userEventData", config.getUserEventData()); } ActionManager actionManager = actionManagerFactory.getActionManager(workspace.getActionManagerName()); if (actionManager != null && !Status.COMPLETED.equals(workspace.getStatus())) { // If Complete, then look to JCR for final accounts as ActionManager may be gone addActionManagerTrackedCounts(workspace.getActionManagerName(), json); for (com.adobe.acs.commons.fam.Failure failure : actionManager.getFailureList()) { JSONObject failureJSON = new JSONObject(); failureJSON.put(Failure.PN_PAYLOAD_PATH, failure.getNodePath()); failureJSON.put(Failure.PN_FAILED_AT, sdf.format(failure.getTime().getTime())); json.accumulate("failures", failureJSON); } } else { addWorkspaceTrackedCounts(workspace, json); // Failures for (Failure failure : workspace.getFailures()) { json.accumulate("failures", failure.toJSON()); } } // Times if (workspace.getStartedAt() != null) { json.put("startedAt", sdf.format(workspace.getStartedAt().getTime())); json.put("timeTakenInMillis", (Calendar.getInstance().getTime().getTime() - workspace.getStartedAt().getTime().getTime())); } if (workspace.getStoppedAt() != null) { json.put("stoppedAt", sdf.format(workspace.getStoppedAt().getTime())); json.put("timeTakenInMillis", (workspace.getStoppedAt().getTime().getTime() - workspace.getStartedAt().getTime().getTime())); } if (workspace.getCompletedAt() != null) { json.put("completedAt", sdf.format(workspace.getCompletedAt().getTime())); json.put("timeTakenInMillis", (workspace.getCompletedAt().getTime().getTime() - workspace.getStartedAt().getTime().getTime())); } if (AEMWorkflowRunnerImpl.class.getName().equals(config.getRunnerType())) { for (Payload payload : config.getWorkspace().getActivePayloads()) { json.accumulate("activePayloads", payload.toJSON()); } } json.put("systemStats", getSystemStats()); response.getWriter().write(json.toString()); } catch (JSONException e) { log.error("Could not collect Bulk Workflow status due to: {}", e); JSONErrorUtil.sendJSONError(response, SlingHttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Could not collect Bulk Workflow status.", e.getMessage()); } }
From source file:com.hangum.tadpole.engine.sql.util.export.SQLExporter.java
public static String makeFileMergeStatment(String tableName, QueryExecuteResultDTO rsDAO, List<String> listWhere, int intLimitCnt, int commit) throws Exception { String strTmpDir = PublicTadpoleDefine.TEMP_DIR + tableName + System.currentTimeMillis() + PublicTadpoleDefine.DIR_SEPARATOR; String strFile = tableName + ".sql"; String strFullPath = strTmpDir + strFile; final String MERGE_STMT = "MERGE INTO " + tableName + " A USING (\n SELECT %s FROM DUAL) B \n ON ( %s ) \n WHEN NOT MATCHED THEN \n INSERT ( %s ) \n VALUES ( %s ) \n WHEN MATCHED THEN \n UPDATE SET %s ;" + PublicTadpoleDefine.LINE_SEPARATOR; Map<Integer, String> mapColumnName = rsDAO.getColumnLabelName(); // ?? ./*from w ww. jav a 2 s . c o m*/ StringBuffer sbInsertInto = new StringBuffer(); int DATA_COUNT = 1000; List<Map<Integer, Object>> dataList = rsDAO.getDataList().getData(); Map<Integer, Integer> mapColumnType = rsDAO.getColumnType(); String strSource = ""; String strInsertColumn = ""; String strInsertValue = ""; String strUpdate = ""; String strMatchConditon = ""; for (int i = 0; i < dataList.size(); i++) { Map<Integer, Object> mapColumns = dataList.get(i); strSource = ""; strInsertColumn = ""; strInsertValue = ""; strUpdate = ""; strMatchConditon = ""; for (int j = 1; j < mapColumnName.size(); j++) { String strColumnName = mapColumnName.get(j); Object strValue = mapColumns.get(j); strValue = strValue == null ? "" : strValue; if (!RDBTypeToJavaTypeUtils.isNumberType(mapColumnType.get(j))) { strValue = StringEscapeUtils.escapeSql(strValue.toString()); strValue = StringHelper.escapeSQL(strValue.toString()); strValue = SQLUtil.makeQuote(strValue.toString()); } boolean isWhere = false; for (String strTmpColumn : listWhere) { if (strColumnName.equals(strTmpColumn)) { isWhere = true; break; } } strSource += String.format("%s as %s ,", strValue, strColumnName); strInsertColumn += String.format(" %s,", strColumnName); strInsertValue += String.format(" B.%s,", strColumnName); if (isWhere) strMatchConditon += String.format("A.%s = B.%s and", strColumnName, strColumnName); else strUpdate += String.format("A.%s = B.%s,", strColumnName, strColumnName); } strSource = StringUtils.removeEnd(strSource, ","); strInsertColumn = StringUtils.removeEnd(strInsertColumn, ","); strInsertValue = StringUtils.removeEnd(strInsertValue, ","); strUpdate = StringUtils.removeEnd(strUpdate, ","); strMatchConditon = StringUtils.removeEnd(strMatchConditon, "and"); sbInsertInto.append(String.format(MERGE_STMT, strSource, strMatchConditon, strInsertColumn, strInsertValue, strUpdate)); if (intLimitCnt == i) { return sbInsertInto.toString(); } if (commit > 0 && (i % commit) == 0) { sbInsertInto .append("COMMIT" + PublicTadpoleDefine.SQL_DELIMITER + PublicTadpoleDefine.LINE_SEPARATOR); } if ((i % DATA_COUNT) == 0) { FileUtils.writeStringToFile(new File(strFullPath), sbInsertInto.toString(), true); sbInsertInto.setLength(0); } } if (sbInsertInto.length() > 0) { if (commit > 0) { sbInsertInto .append("COMMIT" + PublicTadpoleDefine.SQL_DELIMITER + PublicTadpoleDefine.LINE_SEPARATOR); } FileUtils.writeStringToFile(new File(strFullPath), sbInsertInto.toString(), true); } return strFullPath; }
From source file:com.jgui.ttscrape.Show.java
/** * Parse the toString() result.// ww w . ja va 2 s.c o m * @param s toString() string to be parsed. * @return resulting show. */ public static Show fromString(String s) { SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM d hh:mm:ss z yyyy"); Show show = new Show(); int idx = s.indexOf('['); if (idx >= 0) { s = s.substring(idx + 1); } s = StringUtils.removeEnd(s, "]"); String[] fields = StringUtils.split(s, ','); for (String field : fields) { String[] keyval = StringUtils.split(field, '='); if (keyval.length == 2) { try { if (!"<null>".equals(keyval[1]) && (keyval[1] != null) && !"null".equals(keyval[1])) { if (keyval[0].equals("startTime")) { Date dt = sdf.parse(keyval[1]); BeanUtils.setProperty(show, keyval[0], dt); } else { BeanUtils.setProperty(show, keyval[0], keyval[1]); } } } catch (Exception ex) { System.err .println("failed to set " + keyval[0] + " to " + keyval[1] + " ex: " + ex.getMessage()); } } } return show; }
From source file:com.dp2345.plugin.oss.OssPlugin.java
@Override public List<FileInfo> browser(String path) { List<FileInfo> fileInfos = new ArrayList<FileInfo>(); PluginConfig pluginConfig = getPluginConfig(); if (pluginConfig != null) { String accessId = pluginConfig.getAttribute("accessId"); String accessKey = pluginConfig.getAttribute("accessKey"); String bucketName = pluginConfig.getAttribute("bucketName"); String urlPrefix = pluginConfig.getAttribute("urlPrefix"); try {/* w w w .ja va2s .c o m*/ OSSClient ossClient = new OSSClient(accessId, accessKey); ListObjectsRequest listObjectsRequest = new ListObjectsRequest(bucketName); listObjectsRequest.setPrefix(StringUtils.removeStart(path, "/")); listObjectsRequest.setDelimiter("/"); ObjectListing objectListing = ossClient.listObjects(listObjectsRequest); for (String commonPrefix : objectListing.getCommonPrefixes()) { FileInfo fileInfo = new FileInfo(); fileInfo.setName(StringUtils.substringAfterLast(StringUtils.removeEnd(commonPrefix, "/"), "/")); fileInfo.setUrl(urlPrefix + "/" + commonPrefix); fileInfo.setIsDirectory(true); fileInfo.setSize(0L); fileInfos.add(fileInfo); } for (OSSObjectSummary ossObjectSummary : objectListing.getObjectSummaries()) { if (ossObjectSummary.getKey().endsWith("/")) { continue; } FileInfo fileInfo = new FileInfo(); fileInfo.setName(StringUtils.substringAfterLast(ossObjectSummary.getKey(), "/")); fileInfo.setUrl(urlPrefix + "/" + ossObjectSummary.getKey()); fileInfo.setIsDirectory(false); fileInfo.setSize(ossObjectSummary.getSize()); fileInfo.setLastModified(ossObjectSummary.getLastModified()); fileInfos.add(fileInfo); } } catch (Exception e) { e.printStackTrace(); } } return fileInfos; }
From source file:net.sf.firemox.tools.MToolKit.java
/** * Return the root directory.// ww w .java 2 s. c o m * * @return the root directory. */ public static String getRootDir() { if (rootDir == null) { String requiredFile = RESOURCE_DEV; URL url = Thread.currentThread().getContextClassLoader().getResource(requiredFile); if (url == null) { requiredFile = RESOURCE_TEST; url = Thread.currentThread().getContextClassLoader().getResource(requiredFile); } if (url == null) { rootDir = new File("").getAbsolutePath(); } else { try { return StringUtils.removeEnd(new File(url.toURI()).getAbsolutePath(), requiredFile); } catch (URISyntaxException e) { rootDir = StringUtils.removeEnd(url.getPath(), requiredFile); } } if (rootDir.startsWith("/")) { rootDir = rootDir.substring(1); } rootDir = FilenameUtils.getFullPathNoEndSeparator(rootDir + "/") + "/"; } return rootDir; }
From source file:com.neatresults.mgnltweaks.ui.field.FieldTypeSelectFieldFactory.java
@Override public List<SelectFieldOptionDefinition> getSelectFieldOptionDefinition() { List<SelectFieldOptionDefinition> fields = new ArrayList<SelectFieldOptionDefinition>(); try {//from ww w . j a v a2s . c o m if (registry.getClass().getDeclaredFields().length == 0) { // 5.4 Collection<FieldTypeDefinition> defs = (Collection<FieldTypeDefinition>) registry.getClass() .getMethod("getAllDefinitions").invoke(registry, null); for (FieldTypeDefinition fieldDef : defs) { if (fieldDef == null || fieldDef.getDefinitionClass() == null || fieldDef.getDefinitionClass().getName() == null) { System.out.println("field def is not valid: " + fieldDef); continue; } SelectFieldOptionDefinition field = new SelectFieldOptionDefinition(); String label = fieldDef.getDefinitionClass().getName(); if (label.startsWith("com.neatresults.mgnltweaks")) { label = StringUtils.replace(label, "com.neatresults.mgnltweaks.ui.field.", " NeatTweaks "); label = StringUtils.removeEnd(label, "FieldFactory$Definition"); } if (label.startsWith("info.magnolia")) { label = StringUtils.replace(label, "info.magnolia.ui.form.field.definition.", " Default "); label = StringUtils.removeStart(label, "info.magnolia.module."); label = StringUtils.removeStart(label, "info.magnolia."); } field.setLabel(label); field.setName(definition.getName()); field.setValue(fieldDef.getDefinitionClass().getName()); fields.add(field); } } else { // 5.3 Field registryField = registry.getClass().getDeclaredField("registry"); registryField.setAccessible(true); RegistryMap<String, FieldTypeDefinitionProvider> providers = (RegistryMap<String, FieldTypeDefinitionProvider>) registryField .get(registry); for (String id : providers.keySet()) { SelectFieldOptionDefinition field = new SelectFieldOptionDefinition(); Class<? extends FieldDefinition> fieldDef = registry.get(id).getDefinitionClass(); // directly defined label String label = id + " (" + StringUtils.replaceOnce(fieldDef.getName(), "info.magnolia.module.", "i.m.m.") + ")"; field.setLabel(label); field.setName(definition.getName()); field.setValue(fieldDef.getName()); fields.add(field); } } } catch (SecurityException | IllegalArgumentException | IllegalAccessException | RegistrationException | NoSuchFieldException | InvocationTargetException | NoSuchMethodException e) { log.error(e.getMessage(), e); SelectFieldOptionDefinition field = new SelectFieldOptionDefinition(); field.setName(definition.getName()); field.setLabel("It looks like an error has occured. Please contact admin or developers about it: " + e.getMessage()); field.setValue(e.getMessage()); fields.add(field); } return fields; }
From source file:com.yoncabt.abys.core.util.EBRConf.java
/** * bu metod dier projelerimizde de bu class' kullanabilmek iin * @return/* w w w .ja va 2 s . com*/ */ private String getConfFileName() { String name = StringUtils.removeEnd(getClass().getSimpleName(), "Conf").toLowerCase(Locale.US); return name + ".conf"; }