List of usage examples for org.apache.commons.lang StringUtils substringBeforeLast
public static String substringBeforeLast(String str, String separator)
Gets the substring before the last occurrence of a separator.
From source file:com.alibaba.otter.manager.biz.monitor.impl.ExceptionRuleMonitor.java
private void check(AlarmRule rule, NodeAlarmEvent alarmEvent) { if (!inPeriod(rule)) { return;//from w w w . j a va2 s .c om } String matchValue = rule.getMatchValue(); matchValue = StringUtils.substringBeforeLast(matchValue, "@"); String[] matchValues = StringUtils.split(matchValue, ","); for (String match : matchValues) { if (StringUtils.containsIgnoreCase(alarmEvent.getMessage(), match)) { String message = String.format(MESAGE_FORMAT, alarmEvent.getPipelineId(), alarmEvent.getNid(), alarmEvent.getMessage()); sendAlarm(rule, message); break; } } }
From source file:eu.europeana.enrichment.converters.concepts.FetcherOfVariousFromDbpediaSparqlEndpoint.java
public void fetch() throws Exception { String[] dbpediaResources = { "Art", "Architecture", "Art_Deco", "Art_Nouveau", "Baroque", "Cubism", "Contemporary_art", "Dada", "Digital_art", "Expressionism", "Fine-art_photography", "Folk_art", "Futurism", "Impressionism", "Neoclassicism", "Pre-Raphaelite_Brotherhood", "Kitsch", "Still_life", "Landscape", "Minimalism", "Modernism", "Renaissance", "Realism_(arts)", "Romanesque_art", "Romanticism", "Rococo", "Pastoral", "Portrait", "Street_art", "Surrealism", "Symbolism", "Music", "Theatre", "Painting", "Sculpture", "Drawing", "Poster", "Photograph", "Furniture", "Costume", "Fashion", "Jewellery", "Porcelain", "Tapestry", "Woodcut" }; Set<String> repos = new HashSet<String>(); for (String resource : dbpediaResources) { try {/*ww w . ja v a 2 s .com*/ String languageQuery = makeDbpediaSparqlQuery(resource, "sameAs", "<http://www.w3.org/2002/07/owl#sameAs>"); Repository repo = Helper.createRemoteRepository("http://dbpedia.org/sparql"); TupleQueryResult result = repo.getConnection() .prepareTupleQuery(QueryLanguage.SPARQL, languageQuery).evaluate(); List<String> fields = result.getBindingNames(); while (result.hasNext()) { BindingSet bs = result.next(); String str = bs.getValue(fields.get(1)).stringValue(); if (str.contains("dbpedia")) { repos.add(StringUtils.substringBeforeLast(str, "/resource") + "/sparql"); } } } catch (Exception e) { System.out.println("dbpedia resource " + resource + " does not have anything under it"); } } }
From source file:edu.cornell.kfs.fp.batch.ProcurementCardLoadFlatFileStep.java
/** * Clears out associated .done files for the processed data files. *//*from w w w. j a v a2 s . com*/ private void removeDoneFiles(List<String> dataFileNames) { for (String dataFileName : dataFileNames) { File doneFile = new File(StringUtils.substringBeforeLast(dataFileName, ".") + ".done"); if (doneFile.exists()) { doneFile.delete(); } } }
From source file:info.magnolia.importexport.PropertiesImportExport.java
public void createContent(Content root, InputStream propertiesStream) throws IOException, RepositoryException { Properties properties = new OrderedProperties(); properties.load(propertiesStream);/*from w w w .ja v a 2 s . com*/ properties = keysToInnerFormat(properties); for (Object o : properties.keySet()) { String key = (String) o; String valueStr = properties.getProperty(key); String propertyName = StringUtils.substringAfterLast(key, "."); String path = StringUtils.substringBeforeLast(key, "."); String type = null; if (propertyName.equals("@type")) { type = valueStr; } else if (properties.containsKey(path + ".@type")) { type = properties.getProperty(path + ".@type"); } type = StringUtils.defaultIfEmpty(type, ItemType.CONTENTNODE.getSystemName()); Content c = ContentUtil.createPath(root, path, new ItemType(type)); populateContent(c, propertyName, valueStr); } }
From source file:com.adobe.ac.pmd.rules.architecture.UseInternalClassOutsideApiClass.java
private String extractFunctionArea(final String packageName, final String visibilityPackageName, final boolean isInImport) { return StringUtils.substringAfterLast( StringUtils.substringBeforeLast(packageName, PACKAGE_SEPARATOR + visibilityPackageName + (isInImport ? PACKAGE_SEPARATOR : "")), PACKAGE_SEPARATOR);//from www .ja v a2s .c om }
From source file:com.github.fritaly.graphml4j.samples.GradleDependenciesWithGroups.java
private static Artifact createArtifact(String value) { // Examples of input values: // "org.springframework:spring-core:3.2.0.RELEASE (*)" // "com.acme:acme-logging:1.16.0 -> 1.16.3 (*)" // "junit:junit:3.8.1 -> 4.8.1" // "sun-jaxb:jaxb-impl:2.2" if (value.endsWith(" (*)")) { // Ex: "org.springframework:spring-core:3.2.0.RELEASE (*)" => "org.springframework:spring-core:3.2.0.RELEASE" value = value.replace(" (*)", ""); }/*from www .j a v a2 s. co m*/ if (value.contains(" -> ")) { // Ex: "junit:junit:3.8.1 -> 4.8.1" => "junit:junit:4.8.1" final String version = StringUtils.substringAfter(value, " -> "); value = StringUtils.substringBeforeLast(value, ":") + ":" + version; } return new Artifact(value); }
From source file:com.adobe.acs.commons.mcp.impl.processes.renovator.MovingFolder.java
private void createMissingTargetFolders(ResourceResolver rr, Resource source) throws RepositoryException, PersistenceException, MovingException { if (!resourceExists(rr, getDestinationPath())) { Actions.setCurrentItem(getSourcePath() + "->" + getDestinationPath()); String targetParentPath = StringUtils.substringBeforeLast(getDestinationPath(), "/"); String targetName = StringUtils.substringAfterLast(getDestinationPath(), "/"); if (getParent() == null) { if (!resourceExists(rr, getDestinationPath())) { createFolderNode(targetParentPath, rr); }// w w w.j av a 2 s . c om } else { waitUntilResourceFound(rr, targetParentPath); } Resource destParent = rr.getResource(targetParentPath); Logger.getLogger(MovingFolder.class.getName()).log(Level.INFO, "Creating target for {0}", getSourcePath()); rr.create(destParent, targetName, getClonedProperties(source)); rr.commit(); rr.refresh(); } }
From source file:com.cognifide.cq.cqsm.foundation.actions.check.exists.CheckAuthorizableExists.java
private void checkPath(final ActionResult actionResult, final Authorizable authorizable, final boolean execute) throws RepositoryException { if (path != null) { String realPath = authorizable.getPath(); realPath = StringUtils.substringBeforeLast(realPath, "/"); if (!StringUtils.equals(realPath, path)) { actionResult.logError("Authorizable " + id + " exists, but in different path: " + realPath); if (execute) { actionResult.logError(ActionUtils.ASSERTION_FAILED_MSG); }//from w w w . j ava2 s . c o m } } }
From source file:biz.netcentric.cq.tools.actool.helper.ContentHelper.java
public static void importContent(final Session session, final String path, String contentXmlStr) throws RepositoryException { String parentPath = StringUtils.substringBeforeLast(path, "/"); try {/* www .j a va2 s . c om*/ session.getNode(parentPath); } catch (PathNotFoundException e) { throw new PathNotFoundException( "Parent path " + parentPath + " for creating content at " + path + " does not exist", e); } String rootElementStr = "<jcr:root "; if (!contentXmlStr.contains(rootElementStr)) { throw new IllegalStateException("Invalid initial content for path " + path + ": " + rootElementStr + " must be provided as root element in XML"); } String contentXmlStrAdjusted = contentXmlStr; if (!contentXmlStrAdjusted.contains("xmlns:cq")) { contentXmlStrAdjusted = contentXmlStrAdjusted.replace(rootElementStr, rootElementStr + " xmlns:cq=\"http://www.day.com/jcr/cq/1.0\" "); } if (!contentXmlStrAdjusted.contains("xmlns:jcr")) { contentXmlStrAdjusted = contentXmlStrAdjusted.replace(rootElementStr, rootElementStr + " xmlns:jcr=\"http://www.jcp.org/jcr/1.0\" "); } if (!contentXmlStrAdjusted.contains("xmlns:sling")) { contentXmlStrAdjusted = contentXmlStrAdjusted.replace(rootElementStr, rootElementStr + " xmlns:sling=\"http://sling.apache.org/jcr/sling/1.0\" "); } LOG.debug("Importing content for path {}\n{}", path, contentXmlStrAdjusted); try { Archive archive = new SingleContentFileArchive(path, contentXmlStrAdjusted); ImportOptions importOptions = new ImportOptions(); importOptions.setAutoSaveThreshold(Integer.MAX_VALUE); // IMPORTANT: this disables saving the session in Importer importOptions.setStrict(true); importOptions.setListener(new ProgressTrackerListener() { @Override public void onMessage(Mode mode, String action, String pathForListener) { LOG.debug("FileVault: " + action + " " + pathForListener); } @Override public void onError(Mode mode, String pathForListener, Exception e) { throw new IllegalArgumentException( "Invalid content fragment at path " + pathForListener + ": " + e, e); } }); Importer importer = new Importer(importOptions); Node importRoot = session.getNode("/"); // importer uses session from importRoot node importer.run(archive, importRoot); } catch (IOException e) { throw new RepositoryException("I/O Error during import operation: " + e, e); } catch (ConfigurationException e) { throw new RepositoryException("ConfigurationException during import operation: " + e, e); } LOG.debug("Imported content for path {}\n{}", path, contentXmlStrAdjusted); }
From source file:com.alibaba.otter.manager.biz.monitor.impl.DelayStatRuleMonitor.java
private boolean checkDelayTime(AlarmRule rule, Long delayTime) { if (!inPeriod(rule)) { return false; }/*w w w .j av a2 s .c o m*/ String matchValue = rule.getMatchValue(); matchValue = StringUtils.substringBeforeLast(matchValue, "@"); Long maxDelayTime = Long.parseLong(StringUtils.trim(matchValue)); if (delayTime >= maxDelayTime * 1000) { sendAlarm(rule, String.format(DELAY_TIME_MESSAGE, rule.getPipelineId(), delayTime)); return true; } return false; }