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:info.magnolia.jcr.util.PropertiesImportExport.java
/** * Transforms the keys to the following inner notation: <code>/some/path/node.prop</code> or * <code>/some/path/node.@type</code>. *//* ww w .ja v a2s. c o m*/ private Properties keysToInnerFormat(Properties properties) { Properties cleaned = new OrderedProperties(); for (Object o : properties.keySet()) { String orgKey = (String) o; // explicitly enforce certain syntax if (!orgKey.startsWith("/")) { throw new IllegalArgumentException("Missing trailing '/' for key: " + orgKey); } if (StringUtils.countMatches(orgKey, ".") > 1) { throw new IllegalArgumentException("Key must not contain more than one '.': " + orgKey); } if (orgKey.contains("@") && !orgKey.contains(".@")) { throw new IllegalArgumentException("Key containing '@' must be preceded by a '.': " + orgKey); } // if this is a node definition (no property) String newKey = orgKey; String propertyName = StringUtils.substringAfterLast(newKey, "."); String keySuffix = StringUtils.substringBeforeLast(newKey, "."); String path = StringUtils.removeStart(keySuffix, "/"); // if this is a path (no property) if (StringUtils.isEmpty(propertyName)) { // no value --> is a node if (StringUtils.isEmpty(properties.getProperty(orgKey))) { // make this the type property if not defined otherwise if (!properties.containsKey(orgKey + ".@type")) { cleaned.put(path + ".@type", NodeTypes.ContentNode.NAME); } continue; } throw new IllegalArgumentException( "Key for a path (everything without a '.' is considered to be a path) must not contain a value ('='): " + orgKey); } cleaned.put(path + "." + propertyName, properties.get(orgKey)); } return cleaned; }
From source file:io.wcm.tooling.netbeans.sightly.completion.classLookup.MemberLookupCompleter.java
/** * This method tries to find the class which is defined for the given filter and returns a set with all methods and fields of the class * * @param variableName//from www .java 2s . c o m * @param text * @param document * @return Set of methods and fields, never null */ private Set<String> resolveClass(String variableName, String text, Document document) { Set<String> items = new LinkedHashSet<>(); FileObject fo = getFileObject(document); ClassPath sourcePath = ClassPath.getClassPath(fo, ClassPath.SOURCE); ClassPath compilePath = ClassPath.getClassPath(fo, ClassPath.COMPILE); ClassPath bootPath = ClassPath.getClassPath(fo, ClassPath.BOOT); if (sourcePath == null) { return items; } ClassPath cp = ClassPathSupport.createProxyClassPath(sourcePath, compilePath, bootPath); MemberLookupResolver resolver = new MemberLookupResolver(text, cp); Set<MemberLookupResult> results = resolver.performMemberLookup( StringUtils.defaultString(StringUtils.substringBeforeLast(variableName, "."), variableName)); for (MemberLookupResult result : results) { Matcher m = GETTER_PATTERN.matcher(result.getMethodName()); if (m.matches() && m.groupCount() >= 2) { items.add(result.getVariableName() + "." + WordUtils.uncapitalize(m.group(2))); } else { items.add(result.getVariableName() + "." + WordUtils.uncapitalize(result.getMethodName())); } } return items; }
From source file:info.magnolia.cms.module.ModuleUtil.java
public static void bootstrap(String[] resourceNames) throws IOException, RegisterException { HierarchyManager hm = MgnlContext.getHierarchyManager(ContentRepository.CONFIG); // sort by length --> import parent node first List list = new ArrayList(Arrays.asList(resourceNames)); Collections.sort(list, new Comparator() { public int compare(Object name1, Object name2) { return ((String) name1).length() - ((String) name2).length(); }//w w w . ja v a 2 s .c o m }); for (Iterator iter = list.iterator(); iter.hasNext();) { String resourceName = (String) iter.next(); // windows again resourceName = StringUtils.replace(resourceName, "\\", "/"); String name = StringUtils.removeEnd(StringUtils.substringAfterLast(resourceName, "/"), ".xml"); String repository = StringUtils.substringBefore(name, "."); String pathName = StringUtils.substringAfter(StringUtils.substringBeforeLast(name, "."), "."); //$NON-NLS-1$ String nodeName = StringUtils.substringAfterLast(name, "."); String fullPath; if (StringUtils.isEmpty(pathName)) { pathName = "/"; fullPath = "/" + nodeName; } else { pathName = "/" + StringUtils.replace(pathName, ".", "/"); fullPath = pathName + "/" + nodeName; } // if the path already exists --> delete it try { if (hm.isExist(fullPath)) { hm.delete(fullPath); if (log.isDebugEnabled()) log.debug("already existing node [{}] deleted", fullPath); } // if the parent path not exists just create it if (!pathName.equals("/")) { ContentUtil.createPath(hm, pathName, ItemType.CONTENT); } } catch (Exception e) { throw new RegisterException("can't register bootstrap file: [" + name + "]", e); } InputStream stream = ModuleUtil.class.getResourceAsStream(resourceName); DataTransporter.executeImport(pathName, repository, stream, name, false, ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING, true, true); } }
From source file:eionet.cr.web.action.factsheet.FolderActionBean.java
/** * Action event for displaying folder contents. * * @return/*from www . j a va2 s . co m*/ * @throws DAOException */ @DefaultHandler public Resolution view() throws DAOException { aclPath = FolderUtil.extractAclPath(uri); // allow to view the folder by default if there is no ACL boolean allowFolderView = CRUser.hasPermission(aclPath, getUser(), "v", true); if (!allowFolderView) { addSystemMessage("Viewing content of this folder is prohibited."); return new RedirectResolution(FolderActionBean.class).addParameter("uri", StringUtils.substringBeforeLast(uri, "/")); } initTabs(); FolderDAO folderDAO = DAOFactory.get().getDao(FolderDAO.class); Pair<FolderItemDTO, List<FolderItemDTO>> result = folderDAO.getFolderContents(uri); folder = result.getLeft(); folderItems = result.getRight(); return new ForwardResolution("/pages/folder/viewItems.jsp"); }
From source file:de.tudarmstadt.ukp.dkpro.core.io.conll.Conll2012Writer.java
@Override public void process(JCas aJCas) throws AnalysisEngineProcessException { PrintWriter out = null;/*from www . j av a2s . c o m*/ try { out = new PrintWriter(new OutputStreamWriter(getOutputStream(aJCas, filenameSuffix), encoding)); String documentId = DocumentMetaData.get(aJCas).getDocumentId(); int partNumber = 0; if (documentId.contains("#")) { partNumber = Integer.parseInt(StringUtils.substringAfterLast(documentId, "#")); documentId = StringUtils.substringBeforeLast(documentId, "#"); } out.printf("#begin document (%s); part %03d%n", documentId, partNumber); convert(aJCas, out); } catch (Exception e) { throw new AnalysisEngineProcessException(e); } finally { closeQuietly(out); } }
From source file:com.amalto.core.server.DefaultDataCluster.java
/** * Get a DataCluster - no exception is thrown: returns null if not found *///w ww. j a va 2s .c o m @Override public DataClusterPOJO existsDataCluster(DataClusterPOJOPK pk) throws XtentisException { if (pk == null) { throw new IllegalArgumentException("The Data Cluster should not be null!"); } if (pk.getUniqueId() == null) { throw new XtentisException("The Data cluster PK cannot be null."); } // Staging DataCluster should be changed to the Master DataCluster if (pk.getUniqueId().endsWith(StorageAdmin.STAGING_SUFFIX)) { String cluster = StringUtils.substringBeforeLast(pk.getUniqueId(), "#"); if (!Util.getXmlServerCtrlLocal().supportStaging(cluster)) { throw new XtentisException("Cluster '" + pk.getUniqueId() + "' (revision: 'null') does not exist"); //$NON-NLS-1$//$NON-NLS-2$ } pk = new DataClusterPOJOPK(cluster); } try { ILocalUser user = LocalUser.getLocalUser(); if (user != null && !user.userCanRead(DataClusterPOJO.class, pk.getUniqueId())) { String err = "Unauthorized read access by " + "user '" + user.getUsername() + "' on object " + ObjectPOJO.getObjectName(DataClusterPOJO.class) + " [" + pk.getUniqueId() + "] "; LOGGER.error(err); throw new XtentisException(err); } DataClusterPOJO value = MDMEhCacheUtil.getCache(DATA_CLUSTER_CACHE_NAME, pk.getUniqueId()); if (value != null) { return value; } DataClusterPOJO dataCluster = ObjectPOJO.load(DataClusterPOJO.class, pk); MDMEhCacheUtil.addCache(DATA_CLUSTER_CACHE_NAME, pk.getUniqueId(), dataCluster); return dataCluster; } catch (XtentisException e) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Exist data cluster check exception.", e); } return null; } catch (Exception e) { String info = "Could not check whether this Data Cluster \"" + pk.getUniqueId() + "\" exists: " + ": " + e.getClass().getName() + ": " + e.getLocalizedMessage(); LOGGER.debug("existsDataCluster() " + info, e); return null; } }
From source file:gobblin.data.management.retention.sql.SqlBasedRetentionPoc.java
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);/* www .jav a 2 s.c om*/ insert.setString(2, snapshotName); insert.setString(3, snapshotPath.toString()); insert.setTimestamp(4, new Timestamp(ts)); insert.setLong(5, recordCount); insert.executeUpdate(); }
From source file:info.magnolia.cms.servlets.RequestInterceptor.java
/** * @param request//from w w w . j a v a 2 s.c o m * @param hm * @throws PathNotFoundException * @throws RepositoryException * @throws AccessDeniedException */ private void updatePageMetaData(HttpServletRequest request, HierarchyManager hm) throws PathNotFoundException, RepositoryException, AccessDeniedException { String pagePath = StringUtils.substringBeforeLast(Path.getURI(request), "."); //$NON-NLS-1$ Content page = hm.getContent(pagePath); page.updateMetaData(); }
From source file:com.googlesource.gerrit.plugins.github.wizard.AccountController.java
private List<String> getCurrentGerritSshKeys(final IdentifiedUser user) throws IOException { AccountResource res = new AccountResource(user); try {//from w w w .ja v a 2 s .c o m List<SshKeyInfo> keysInfo = restGetSshKeys.apply(res); return Lists.transform(keysInfo, new Function<SshKeyInfo, String>() { @Override public String apply(SshKeyInfo keyInfo) { return StringUtils.substringBeforeLast(keyInfo.sshPublicKey, " "); } }); } catch (Exception e) { log.error("User list keys failed", e); throw new IOException("Cannot get list of user keys", e); } }
From source file:eionet.cr.web.action.factsheet.CompiledDatasetActionBean.java
/** * Gets the value and label from the data. * * @param data/* www .ja va2 s .co m*/ * @return Array, where element 0 is value and 1 is label. */ private String[] getValueAndLabel(String data) { String[] result = new String[2]; result[0] = StringUtils.substringBeforeLast(data, WebConstants.FILTER_LABEL_SEPARATOR); result[1] = StringUtils.substringAfterLast(data, WebConstants.FILTER_LABEL_SEPARATOR); return result; }