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.google.gdt.eclipse.designer.smart.model.CanvasSizeSupport.java
/** * @return the {@link Integer} value if given size string is integer, else <code>null</code>. *///from w ww. j ava 2 s .co m static Integer getIntegerValue(String s) { s = StringUtils.substringBetween(s, "\""); s = StringUtils.substringBeforeLast(s, "px"); try { return Integer.valueOf(s); } catch (NumberFormatException e) { } return null; }
From source file:com.scit.sling.test.MockResourceFactory.java
/** * Build a {@link MockResourceResolver} with all {@link MockResource} and {@link MockValueMap}.<br> * The format of the JSON input is compatible with the Apache Sling json representations of the JCR, i.e. * <blockquote>curl -s -u admin:admin http://localhost:8080/content/path/to/node.infinity.json</blockquote> * /*w w w.j a va 2s. c o m*/ * @param basePath the parent path of this node (blank if it's meant to be the root) * @param in the input stream to load the JSON representation * * @return * @throws JsonParseException * @throws IOException */ public static ResourceNode loadRepositoryFromJson(String basePath, InputStream in) throws JsonParseException, IOException { JsonFactory jsonFactory = new JsonFactory(); JsonParser jp = jsonFactory.createJsonParser(in); ResourceNode root = new ResourceNode(StringUtils.substringBeforeLast(basePath, "/"), StringUtils.substringAfterLast(basePath, "/")); JsonToken token = jp.nextToken(); if (token == JsonToken.START_OBJECT) { parseJsonObject(root, jp); } return root; }
From source file:info.magnolia.jcr.util.PropertiesImportExport.java
/** * Each property or node in the stream has to be separated by the \n. *//*from w w w . jav a2 s . c o m*/ public void createNodes(Node root, InputStream propertiesStream) throws IOException, RepositoryException { Properties properties = new OrderedProperties(); properties.load(propertiesStream); 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, NodeTypes.ContentNode.NAME); Node c = NodeUtil.createPath(root, path, type); populateNode(c, propertyName, valueStr); } }
From source file:info.magnolia.cms.beans.config.Bootstrapper.java
/** * Repositories appears to be empty and the <code>"magnolia.bootstrap.dir</code> directory is configured in * web.xml. Loops over all the repositories and try to load any xml file found in a subdirectory with the same name * of the repository. For example the <code>config</code> repository will be initialized using all the * <code>*.xml</code> files found in <code>"magnolia.bootstrap.dir</code><strong>/config</strong> directory. * @param bootdirs bootstrap dir//from w w w . ja v a2 s . com */ protected static void bootstrapRepositories(String[] bootdirs) { if (log.isInfoEnabled()) { log.info("-----------------------------------------------------------------"); //$NON-NLS-1$ log.info("Trying to initialize repositories from:"); for (int i = 0; i < bootdirs.length; i++) { log.info(bootdirs[i]); } log.info("-----------------------------------------------------------------"); //$NON-NLS-1$ } MgnlContext.setInstance(MgnlContext.getSystemContext()); Iterator repositoryNames = ContentRepository.getAllRepositoryNames(); while (repositoryNames.hasNext()) { String repository = (String) repositoryNames.next(); Set xmlfileset = new TreeSet(new Comparator() { // remove file with the same name in different dirs public int compare(Object file1obj, Object file2obj) { File file1 = (File) file1obj; File file2 = (File) file2obj; String fn1 = file1.getParentFile().getName() + '/' + file1.getName(); String fn2 = file2.getParentFile().getName() + '/' + file2.getName(); return fn1.compareTo(fn2); } }); for (int j = 0; j < bootdirs.length; j++) { String bootdir = bootdirs[j]; File xmldir = new File(bootdir, repository); if (!xmldir.exists() || !xmldir.isDirectory()) { continue; } File[] files = xmldir.listFiles(new FilenameFilter() { public boolean accept(File dir, String name) { return name.endsWith(DataTransporter.XML) || name.endsWith(DataTransporter.ZIP) || name.endsWith(DataTransporter.GZ); //$NON-NLS-1$ } }); xmlfileset.addAll(Arrays.asList(files)); } if (xmlfileset.isEmpty()) { log.info("No bootstrap files found in directory [{}], skipping...", repository); //$NON-NLS-1$ continue; } log.info("Trying to import content from {} files into repository [{}]", //$NON-NLS-1$ Integer.toString(xmlfileset.size()), repository); File[] files = (File[]) xmlfileset.toArray(new File[xmlfileset.size()]); Arrays.sort(files, new Comparator() { public int compare(Object file1, Object file2) { String name1 = StringUtils.substringBeforeLast(((File) file1).getName(), "."); //$NON-NLS-1$ String name2 = StringUtils.substringBeforeLast(((File) file2).getName(), "."); //$NON-NLS-1$ // a simple way to detect nested nodes return name1.length() - name2.length(); } }); try { for (int k = 0; k < files.length; k++) { File xmlfile = files[k]; DataTransporter.executeBootstrapImport(xmlfile, repository); } } catch (IOException ioe) { log.error(ioe.getMessage(), ioe); } catch (OutOfMemoryError e) { int maxMem = (int) (Runtime.getRuntime().maxMemory() / 1024 / 1024); int needed = Math.max(256, maxMem + 128); log.error("Unable to complete bootstrapping: out of memory.\n" //$NON-NLS-1$ + "{} MB were not enough, try to increase the amount of memory available by adding the -Xmx{}m parameter to the server startup script.\n" //$NON-NLS-1$ + "You will need to completely remove the magnolia webapp before trying again", //$NON-NLS-1$ Integer.toString(maxMem), Integer.toString(needed)); break; } log.info("Repository [{}] has been initialized.", repository); //$NON-NLS-1$ } }
From source file:ips1ap101.lib.base.BaseBundle.java
public static String getLimiteFilasFuncionSelect(String key) { String string = getString(key, LIMITE_FILAS_FUNCION_SELECT); if (string == null) { String dominio = StringUtils.substringBeforeLast(key, "."); if (key.equals(dominio)) { } else {/*from w w w. ja va2s.c o m*/ string = getString(dominio, LIMITE_FILAS_FUNCION_SELECT); } } if (string == null) { string = getString(DEFAULT, LIMITE_FILAS_FUNCION_SELECT); } return string; }
From source file:eu.annocultor.utils.OntologySubtractor.java
private static Collection<String> listNameStamsForFilesWithDeletedStatements(File sourceDir) { Set<String> stamms = new HashSet<String>(); for (String file : sourceDir.list(new FilenameFilter() { @Override/* w w w . j a v a 2 s .c o m*/ public boolean accept(File dir, String name) { return name.endsWith(DELETED_RDF); } })) { String stam = StringUtils.substringBeforeLast(file, DELETED_RDF); // allow one word before: real.name.*.deleted.rdf stam = StringUtils.substringBeforeLast(stam, "."); stamms.add(stam); } return stamms; }
From source file:com.pedra.core.batch.task.BatchIntegrationTest.java
@Before public void setUp() throws Exception { random = new Random(); mediaHeader = batchMediaConverter.getHeader(); productId = Long.valueOf(Math.abs(random.nextLong())); sequenceId = Long.valueOf(Math.abs(random.nextLong())); importCsv("/pedracore/test/testBatch.impex", "utf-8"); // don't import binary data -> temporarily remove MediaTranslator ((DefaultImpexConverter) batchMediaConverter).setHeader(StringUtils.substringBeforeLast(mediaHeader, ";")); }
From source file:com.alibaba.cobar.client.router.config.support.InternalRuleLoader4DefaultInternalRouter.java
public void loadRulesAndEquipRouter(List<InternalRule> rules, DefaultCobarClientInternalRouter router, Map<String, Object> functionsMap) { if (CollectionUtils.isEmpty(rules)) { return;// w w w. j av a 2 s. c o m } for (InternalRule rule : rules) { String namespace = StringUtils.trimToEmpty(rule.getNamespace()); String sqlAction = StringUtils.trimToEmpty(rule.getSqlmap()); String shardingExpression = StringUtils.trimToEmpty(rule.getShardingExpression()); String destinations = StringUtils.trimToEmpty(rule.getShards()); Validate.notEmpty(destinations, "destination shards must be given explicitly."); if (StringUtils.isEmpty(namespace) && StringUtils.isEmpty(sqlAction)) { throw new IllegalArgumentException("at least one of 'namespace' or 'sqlAction' must be given."); } if (StringUtils.isNotEmpty(namespace) && StringUtils.isNotEmpty(sqlAction)) { throw new IllegalArgumentException( "'namespace' and 'sqlAction' are alternatives, can't guess which one to use if both of them are provided."); } if (StringUtils.isNotEmpty(namespace)) { List<Set<IRoutingRule<IBatisRoutingFact, List<String>>>> ruleSequence = setUpRuleSequenceContainerIfNecessary( router, namespace); if (StringUtils.isEmpty(shardingExpression)) { ruleSequence.get(3).add(new IBatisNamespaceRule(namespace, destinations)); } else { IBatisNamespaceShardingRule insr = new IBatisNamespaceShardingRule(namespace, destinations, shardingExpression); if (MapUtils.isNotEmpty(functionsMap)) { insr.setFunctionMap(functionsMap); } ruleSequence.get(2).add(insr); } } if (StringUtils.isNotEmpty(sqlAction)) { List<Set<IRoutingRule<IBatisRoutingFact, List<String>>>> ruleSequence = setUpRuleSequenceContainerIfNecessary( router, StringUtils.substringBeforeLast(sqlAction, ".")); if (StringUtils.isEmpty(shardingExpression)) { ruleSequence.get(1).add(new IBatisSqlActionRule(sqlAction, destinations)); } else { IBatisSqlActionShardingRule issr = new IBatisSqlActionShardingRule(sqlAction, destinations, shardingExpression); if (MapUtils.isNotEmpty(functionsMap)) { issr.setFunctionMap(functionsMap); } ruleSequence.get(0).add(issr); } } } }
From source file:eu.europa.esig.dss.applet.wizard.signature.SaveStep.java
private File prepareTargetFileName(final File file, final SignaturePackaging signaturePackaging, final String signatureLevel) { final File parentDir = file.getParentFile(); final String originalName = StringUtils.substringBeforeLast(file.getName(), "."); final String originalExtension = "." + StringUtils.substringAfterLast(file.getName(), "."); final String level = signatureLevel.toUpperCase(); if (((SignaturePackaging.ENVELOPING == signaturePackaging) || (SignaturePackaging.DETACHED == signaturePackaging)) && level.startsWith("XADES")) { final String form = "xades"; final String levelOnly = DSSUtils.replaceStrStr(level, "XADES-", "").toLowerCase(); final String packaging = signaturePackaging.name().toLowerCase(); return new File(parentDir, originalName + "-" + form + "-" + packaging + "-" + levelOnly + ".xml"); }//from ww w .ja v a2 s .co m if (level.startsWith("CADES") && !originalExtension.toLowerCase().equals(".p7m")) { return new File(parentDir, originalName + originalExtension + ".p7m"); } if (level.startsWith("ASIC_S")) { return new File(parentDir, originalName + originalExtension + ".asics"); } if (level.startsWith("ASIC_E")) { return new File(parentDir, originalName + originalExtension + ".asice"); } return new File(parentDir, originalName + "-signed" + originalExtension); }
From source file:com.acc.core.batch.task.BatchIntegrationTest.java
@Before public void setUp() throws Exception { random = new Random(); mediaHeader = batchMediaConverter.getHeader(); productId = Long.valueOf(Math.abs(random.nextLong())); sequenceId = Long.valueOf(Math.abs(random.nextLong())); importCsv("/bnccore/test/testBatch.impex", "utf-8"); // don't import binary data -> temporarily remove MediaTranslator ((DefaultImpexConverter) batchMediaConverter).setHeader(StringUtils.substringBeforeLast(mediaHeader, ";")); }