Java Code Examples for org.apache.commons.lang.StringUtils#substringBeforeLast()
The following examples show how to use
org.apache.commons.lang.StringUtils#substringBeforeLast() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SQLUtils.java From rice with Educational Community License v2.0 | 6 votes |
public static Timestamp convertStringDateToTimestamp(String dateWithoutTime) { Pattern p = Pattern.compile(TIME_REGEX); Matcher util = p.matcher(dateWithoutTime); if (util.find()) { dateWithoutTime = StringUtils.substringBeforeLast(dateWithoutTime, " "); } DateComponent formattedDate = formatDateToDateComponent(dateWithoutTime, REGEX_EXPRESSION_MAP_TO_REGEX_SPLIT_EXPRESSION.keySet()); if (formattedDate == null) { return null; } Calendar c = Calendar.getInstance(); c.clear(); c.set(Calendar.MONTH, Integer.valueOf(formattedDate.getMonth()).intValue() - 1); c.set(Calendar.DATE, Integer.valueOf(formattedDate.getDate()).intValue()); c.set(Calendar.YEAR, Integer.valueOf(formattedDate.getYear()).intValue()); return convertCalendar(c); }
Example 2
Source File: BatchInputFileServiceTest.java From kfs with GNU Affero General Public License v3.0 | 6 votes |
/** * Clean up any files created during test methods that were not removed (possibly because of a failure). * * @see junit.framework.TestCase#tearDown() */ @Override protected void tearDown() throws Exception { super.tearDown(); if (createdTestFiles != null) { for (File createdFile : createdTestFiles) { if (createdFile.exists()) { createdFile.delete(); } String doneFileName = StringUtils.substringBeforeLast(createdFile.getPath(), ".") + ".done"; File doneFile = new File(doneFileName); if (doneFile.exists()) { doneFile.delete(); } } } }
Example 3
Source File: SimpleEsAdapter.java From canal-elasticsearch with Apache License 2.0 | 6 votes |
public SimpleEsAdapter(CanalConf canalConf) { String accept = canalConf.getAccept(); String[] acceptArr = accept.split(DELIMITER); for (String str : acceptArr) { String[] strArr = str.split(CONNECTOR); if (strArr.length == 3) { String dataBaseTable = StringUtils.substringBeforeLast(str, CONNECTOR_TEP); String idColumn = StringUtils.substringAfterLast(str, CONNECTOR_TEP); idPair.put(dataBaseTable, idColumn); logger.info("Add accept :{}", str); } } }
Example 4
Source File: ProjectCheckHeartBeatEvent.java From DBus with Apache License 2.0 | 6 votes |
/** * 从path中提取信息,放入node中 * * @param node * @param path 原始path: /DBus/HeartBeat/ProjectMonitor/project1/topo1/ds1.schema1.table1 * @param basePath * @return */ private ProjectMonitorNodeVo initNodeAttribute(ProjectMonitorNodeVo node, String path, String basePath) { //操作后path:project1/topo1/ds1.schema1.table1 path = StringUtils.replace(path, basePath + "/", StringUtils.EMPTY); //projectTopoName:project1/topo1 String projectTopoName = StringUtils.substringBeforeLast(path, "/"); node.setProjectName(StringUtils.substringBeforeLast(projectTopoName, "/")); node.setTopoName(StringUtils.substringAfterLast(projectTopoName, "/")); //ds1.schema1.table1 String leafNodeName = StringUtils.substringAfterLast(path, "/"); node.setTableName(StringUtils.substringAfterLast(path, ".")); //ds1.schema1 String datasourceSchemaName = StringUtils.substringBeforeLast(leafNodeName, "."); node.setDsName(StringUtils.substringBefore(datasourceSchemaName, ".")); node.setSchema(StringUtils.substringAfter(datasourceSchemaName, ".")); LOG.info(MsgUtil.format("node info: project: {0}, topo: {1}, ds: {2}, schema: {3}, table: {4}", node.getProjectName(), node.getTopoName(), node.getDsName(), node.getSchema(), node.getTableName())); return node; }
Example 5
Source File: SqlBasedRetentionPoc.java From incubator-gobblin with Apache License 2.0 | 6 votes |
private void insertSnapshot(Path snapshotPath) throws Exception { String datasetPath = StringUtils.substringBeforeLast(snapshotPath.toString(), Path.SEPARATOR); String snapshotName = StringUtils.substringAfterLast(snapshotPath.toString(), Path.SEPARATOR); long ts = Long.parseLong(StringUtils.substringBefore(snapshotName, "-PT-")); long recordCount = Long.parseLong(StringUtils.substringAfter(snapshotName, "-PT-")); PreparedStatement insert = connection.prepareStatement("INSERT INTO Snapshots VALUES (?, ?, ?, ?, ?)"); insert.setString(1, datasetPath); insert.setString(2, snapshotName); insert.setString(3, snapshotPath.toString()); insert.setTimestamp(4, new Timestamp(ts)); insert.setLong(5, recordCount); insert.executeUpdate(); }
Example 6
Source File: DefaultTaskContainer.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
public Task findByPath(String path) { if (!GUtil.isTrue(path)) { throw new InvalidUserDataException("A path must be specified!"); } if (!path.contains(Project.PATH_SEPARATOR)) { return findByName(path); } String projectPath = StringUtils.substringBeforeLast(path, Project.PATH_SEPARATOR); ProjectInternal project = this.project.findProject(!GUtil.isTrue(projectPath) ? Project.PATH_SEPARATOR : projectPath); if (project == null) { return null; } projectAccessListener.beforeRequestingTaskByPath(project); return project.getTasks().findByName(StringUtils.substringAfterLast(path, Project.PATH_SEPARATOR)); }
Example 7
Source File: AvatarQueryService.java From symphonyx with Apache License 2.0 | 6 votes |
/** * Gets the avatar URL for the specified user id with the specified size. * * @param user the specified user * @return the avatar URL */ public String getAvatarURLByUser(final JSONObject user) { if (null == user) { return DEFAULT_AVATAR_URL; } final String originalURL = user.optString(UserExt.USER_AVATAR_URL); if (StringUtils.isBlank(originalURL)) { return DEFAULT_AVATAR_URL; } if (Symphonys.getBoolean("qiniu.enabled")) { if (!StringUtils.contains(originalURL, "qnssl.com") && !StringUtils.contains(originalURL, "clouddn.com")) { return DEFAULT_AVATAR_URL; } } return StringUtils.substringBeforeLast(originalURL, "?"); }
Example 8
Source File: FileDescriptor.java From APM with Apache License 2.0 | 5 votes |
private static String getPathFromOriginalFileName(String savePath, String originalFileName) { if (originalFileName.contains("/")) { String subPath = StringUtils.substringBeforeLast(originalFileName, "/"); if (subPath.startsWith(savePath)) { subPath = StringUtils.substringAfter(subPath, savePath); } return savePath + (subPath.startsWith("/") ? subPath : "/" + subPath); } return savePath; }
Example 9
Source File: GenericsUtil.java From idea-php-generics-plugin with MIT License | 5 votes |
/** * Generate a full FQN class name out of a given short class name with respecting current namespace and use scope * * - "Foobar" needs to have its use statement attached * - No use statement match its on the same namespace as the class * * TODO: find a core function for this * * @param classNameScope \Foobar\Classes * @param shortClassName Foobar */ public static String getFqnClassNameFromScope(@NotNull String classNameScope, @NotNull String shortClassName, @NotNull Map<String, String> useImportMap) { // its already on the global namespace: "\Exception" if (shortClassName.startsWith("\\")) { return shortClassName; } // not use statement so stop here if (useImportMap.size() == 0) { return shortClassName; } // "Foo\Bar" split it on "subnamespace"; if no "subnamespace" only care about the first array item as out use match String[] split = shortClassName.split("\\\\"); if (useImportMap.containsKey(split[0])) { String shortClassImport = useImportMap.get(split[0]); // on "Foo\Bar" we must extend also "Bar" for the import // "Foo\Bar" => "\Car\Foo\Bar" if (split.length > 1) { String[] yourArray = Arrays.copyOfRange(split, 1, split.length); shortClassImport += "\\" + StringUtils.join(yourArray, "\\"); } return shortClassImport; } // strip the last namespace part and replace it with ours: "Foobar\Bar" => "Foobar\OurShortClass" return StringUtils.substringBeforeLast(classNameScope, "\\") + "\\" + shortClassName; }
Example 10
Source File: LockboxLoadServiceImpl.java From kfs with GNU Affero General Public License v3.0 | 5 votes |
/** * Clears out associated .done files for the processed data files. */ protected void removeDoneFiles(List<String> dataFileNames) { for (String dataFileName : dataFileNames) { File doneFile = new File(StringUtils.substringBeforeLast(dataFileName, ".") + ".done"); if (doneFile.exists()) { doneFile.delete(); } } }
Example 11
Source File: IconServlet.java From smarthome with Eclipse Public License 2.0 | 5 votes |
private String getState(HttpServletRequest req) { String state = req.getParameter(PARAM_STATE); if (state != null) { return state; } else { String filename = StringUtils.substringAfterLast(req.getRequestURI(), "/"); state = StringUtils.substringAfterLast(filename, "-"); state = StringUtils.substringBeforeLast(state, "."); if (StringUtils.isNotEmpty(state)) { return state; } else { return null; } } }
Example 12
Source File: AllTestResults.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
private PackageTestResults addPackageForClass(String className) { String packageName = StringUtils.substringBeforeLast(className, "."); if (packageName.equals(className)) { packageName = ""; } return addPackage(packageName); }
Example 13
Source File: FileReference.java From intellij-swagger with MIT License | 5 votes |
@Override public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException { final String referencePrefix = StringUtils.substringBeforeLast(originalRefValue, "/"); if (referencePrefix.equals(originalRefValue)) { return super.handleElementRename(newElementName); } return super.handleElementRename(referencePrefix + SLASH + newElementName); }
Example 14
Source File: DefaultBeanFactory.java From ymate-platform-v2 with Apache License 2.0 | 5 votes |
private boolean __hasPackageParent(List<String> targetList, String packageName) { boolean _flag = false; do { packageName = StringUtils.substringBeforeLast(packageName, "."); if (targetList.contains(packageName)) { _flag = true; } } while (!_flag && StringUtils.contains(packageName, ".")); // return _flag; }
Example 15
Source File: AssetBarcodeInventoryLoadServiceImpl.java From kfs with GNU Affero General Public License v3.0 | 5 votes |
/** * This method removes the *.done files. If not deleted, then the program will display the name of the file in a puldown menu * with a label of ready for process. * * @param file */ protected void removeDoneFile(File file) { String filePath = file.getAbsolutePath(); File doneFile = new File(StringUtils.substringBeforeLast(filePath, ".") + ".done"); if (doneFile.exists()) { doneFile.delete(); } }
Example 16
Source File: DefaultCobarClientInternalRouter.java From cobarclient with Apache License 2.0 | 5 votes |
public RoutingResult doRoute(IBatisRoutingFact routingFact) throws RoutingException { Validate.notNull(routingFact); String action = routingFact.getAction(); Validate.notEmpty(action); String namespace = StringUtils.substringBeforeLast(action, "."); List<Set<IRoutingRule<IBatisRoutingFact, List<String>>>> rules = getRulesGroupByNamespaces() .get(namespace); RoutingResult result = new RoutingResult(); result.setResourceIdentities(new ArrayList<String>()); if (!CollectionUtils.isEmpty(rules)) { IRoutingRule<IBatisRoutingFact, List<String>> ruleToUse = null; for (Set<IRoutingRule<IBatisRoutingFact, List<String>>> ruleSet : rules) { ruleToUse = searchMatchedRuleAgainst(ruleSet, routingFact); if (ruleToUse != null) { break; } } if (ruleToUse != null) { logger.info("matched with rule:{} with fact:{}", ruleToUse, routingFact); result.getResourceIdentities().addAll(ruleToUse.action()); } else { logger.info("No matched rule found for routing fact:{}", routingFact); } } return result; }
Example 17
Source File: SqlBasedRetentionPoc.java From incubator-gobblin with Apache License 2.0 | 4 votes |
private void insertDailyPartition(Path dailyPartitionPath) throws Exception { String datasetPath = StringUtils.substringBeforeLast(dailyPartitionPath.toString(), Path.SEPARATOR + "daily"); DateTime partition = DateTimeFormat.forPattern(DAILY_PARTITION_PATTERN).parseDateTime( StringUtils.substringAfter(dailyPartitionPath.toString(), "daily" + Path.SEPARATOR)); PreparedStatement insert = connection.prepareStatement("INSERT INTO Daily_Partitions VALUES (?, ?, ?)"); insert.setString(1, datasetPath); insert.setString(2, dailyPartitionPath.toString()); insert.setTimestamp(3, new Timestamp(partition.getMillis())); insert.executeUpdate(); }
Example 18
Source File: ExpressionUtils.java From rice with Educational Community License v2.0 | 4 votes |
/** * Pulls expressions within the expressionConfigurable's expression graph and moves them to the property * expressions * map for the expressionConfigurable or a nested expressionConfigurable (for the case of nested expression * property * names) * * <p> * Expressions that are configured on properties and pulled out by the {@link org.kuali.rice.krad.datadictionary.uif.UifBeanFactoryPostProcessor} * and put in the {@link org.kuali.rice.krad.datadictionary.uif.UifDictionaryBean#getExpressionGraph()} for the * bean * that is * at root (non nested) level. Before evaluating the expressions, they need to be moved to the * {@link org.kuali.rice.krad.datadictionary.uif.UifDictionaryBean#getPropertyExpressions()} map for the * expressionConfigurable that * property * is on. * </p> * * @param expressionConfigurable expressionConfigurable instance to process expressions for */ public static void populatePropertyExpressionsFromGraph(UifDictionaryBean expressionConfigurable) { if (expressionConfigurable == null || expressionConfigurable.getExpressionGraph() == null) { return; } // will hold graphs to populate the refreshExpressionGraph property on each expressionConfigurable // key is the path to the expressionConfigurable and value is the map of nested property names to expressions Map<String, Map<String, String>> refreshExpressionGraphs = new HashMap<String, Map<String, String>>(); Map<String, String> expressionGraph = expressionConfigurable.getExpressionGraph(); for (Map.Entry<String, String> expressionEntry : expressionGraph.entrySet()) { String propertyName = expressionEntry.getKey(); String expression = expressionEntry.getValue(); // by default assume expression belongs with passed in expressionConfigurable UifDictionaryBean configurableWithExpression = expressionConfigurable; // if property name is nested, we need to move the expression to the last expressionConfigurable String adjustedPropertyName = propertyName; if (StringUtils.contains(propertyName, ".")) { String configurablePath = StringUtils.substringBeforeLast(propertyName, "."); adjustedPropertyName = StringUtils.substringAfterLast(propertyName, "."); Object nestedObject = ObjectPropertyUtils.getPropertyValue(expressionConfigurable, configurablePath); // skip missing expression object for components skipping their lifecycle because objects // in these components may be missing (and are expected to be missing) if (nestedObject == null && expressionConfigurable instanceof LifecycleElement && ((LifecycleElement) expressionConfigurable).skipLifecycle()) { continue; } if ((nestedObject == null) || !(nestedObject instanceof UifDictionaryBean)) { throw new RiceRuntimeException("Object for which expression is configured on is null or does not " + "implement UifDictionaryBean: '" + configurablePath + "' on class " + expressionConfigurable.getClass().getName() + " while evaluating " + "expression for " + propertyName); } // use nested object as the expressionConfigurable which will get the property expression configurableWithExpression = (UifDictionaryBean) nestedObject; } configurableWithExpression.getPropertyExpressions().put(adjustedPropertyName, expression); } }
Example 19
Source File: PropertyResolver.java From openhab1-addons with Eclipse Public License 2.0 | 4 votes |
/** * Remove the last property expresson from the current expression. */ public static String removeLast(String expression) { return StringUtils.substringBeforeLast(expression, SEPERATOR); }
Example 20
Source File: UriUtils.java From io with Apache License 2.0 | 2 votes |
/** * getUnitUrl. * @param cellUrl String * @param index int from last * @return url String */ public static String getUnitUrl(String cellUrl, int index) { String[] list = cellUrl.split(STRING_SLASH); // 指定文字が最後から指定数で発見された文字より前の文字を切り出す return StringUtils.substringBeforeLast(cellUrl, list[list.length - index]); }