List of usage examples for org.apache.commons.lang StringUtils substringBefore
public static String substringBefore(String str, String separator)
Gets the substring before the first occurrence of a separator.
From source file:org.exoplatform.services.wcm.extensions.publication.WCMPublicationServiceImpl.java
private boolean allowEnrollInPublication(Node node, String nodeType) throws Exception { String path = node.getPath(); Node parentNode = node.getParent(); while (!path.equals("/") && path.length() > 0) { parentNode = (Node) node.getSession().getItem(path); if (parentNode.isNodeType(nodeType)) return false; path = StringUtils.substringBefore(path, path.substring(path.lastIndexOf("/"), path.length())); }//from w w w . jav a2s.com return true; }
From source file:org.exoplatform.wcm.webui.search.UISearchResult.java
/** * Get string used to describe search result node. * * @param resultNode ResultNode// w ww . java2s.c om * @return result node description * @throws Exception */ private String getDetail(ResultNode resultNode) throws Exception { Node realNode = org.exoplatform.wcm.webui.Utils.getRealNode(resultNode.getNode()); String resultType = this.getResultType(); if (UIWCMSearchPortlet.SEARCH_CONTENT_MODE.equals(resultType)) { return WCMCoreUtils.getService(LivePortalManagerService.class).getLivePortalByChild(realNode).getName() .concat(org.exoplatform.services.cms.impl.Utils.fileSize(realNode)).concat(" - ") .concat(getModifiedDate(realNode)); } else { return StringUtils .substringBefore(StringUtils.substringAfter(realNode.getPath(), SiteSearchService.PATH_PORTAL_SITES.concat("/mop:")), "/") .concat(" - ").concat(resultNode.getUserNavigationURI()); } }
From source file:org.fao.geonet.kernel.ThesaurusManager.java
/** * /*from w w w.j a v a 2 s . c o m*/ * @param thesauriDirectory */ private void loadRepositories(File thesauriDirectory, String root, ServiceContext context) { FilenameFilter filter = new FilenameFilter() { public boolean accept(File dir, String name) { return name.endsWith(".rdf"); } }; String[] rdfDataFile = thesauriDirectory.list(filter); for (String aRdfDataFile : rdfDataFile) { Thesaurus gst = null; if (root.equals(Geonet.CodeList.REGISTER)) { if (Log.isDebugEnabled(Geonet.THESAURUS_MAN)) Log.debug(Geonet.THESAURUS_MAN, "Creating thesaurus : " + aRdfDataFile); File outputRdf = new File(thesauriDirectory, aRdfDataFile); String uuid = StringUtils.substringBefore(aRdfDataFile, ".rdf"); try { FileOutputStream outputRdfStream = new FileOutputStream(outputRdf); getRegisterMetadataAsRdf(context, uuid, outputRdfStream, true); outputRdfStream.close(); } catch (Exception e) { Log.error(Geonet.THESAURUS_MAN, "Register thesaurus " + aRdfDataFile + " could not be read/converted from ISO19135 record in catalog - skipping"); e.printStackTrace(); continue; } gst = new Thesaurus(aRdfDataFile, root, thesauriDirectory.getName(), outputRdf, dm.getSiteURL()); } else { gst = new Thesaurus(aRdfDataFile, root, thesauriDirectory.getName(), new File(thesauriDirectory, aRdfDataFile), dm.getSiteURL()); } try { addThesaurus(gst, false); } catch (Exception e) { e.printStackTrace(); // continue loading } } }
From source file:org.fao.geonet.services.util.z3950.Repositories.java
/** builds the repositories config file from template *//*from w ww. ja va2s. c o m*/ public static boolean build(URL cfgUrl, ServiceContext context) { try { if (cfgUrl == null) { context.warning("Cannot initialize Z39.50 repositories because the file " + Geonet.File.JZKITCONFIG_TEMPLATE + " could not be found in the classpath"); return false; } else { configPath = URLDecoder.decode(cfgUrl.getFile(), "UTF-8"); } //--- build repositories file from template repositories file String realRepo = StringUtils.substringBefore(configPath, ".tem"); String tempRepo = configPath; buildRepositoriesFile(tempRepo, realRepo); } catch (Exception e) { context.warning("Cannot initialize Z39.50 repositories : " + e.getMessage()); e.printStackTrace(); return false; } return true; }
From source file:org.fcrepo.indexer.persistence.BasePersistenceIndexer.java
/** * Return the path where a given record should be persisted. * @param id The record's URI//from www . j a v a2 s . c o m * @return the path where a given record should be persisted * @throws IOException if IO exception occurred **/ protected Path pathFor(final URI id) throws IOException { // strip the http protocol and replace column(:) in front of the port number String fullPath = id.toString().substring(id.toString().indexOf("//") + 2); fullPath = StringUtils.substringBefore(fullPath, "/").replace(":", "/") + "/" + StringUtils.substringAfter(fullPath, "/"); // URL encode the id final String idPath = URLEncoder.encode(substringAfterLast(fullPath, "/"), "UTF-8"); // URL encode and build the file path final String[] pathTokens = StringUtils.substringBeforeLast(fullPath, "/").split("/"); final StringBuilder pathBuilder = new StringBuilder(); for (final String token : pathTokens) { if (StringUtils.isNotBlank(token)) { pathBuilder.append(URLEncoder.encode(token, "UTF-8") + "/"); } } fullPath = pathBuilder.substring(0, pathBuilder.length() - 1).toString(); final Path dir = Paths.get(pathName, fullPath); if (Files.notExists(dir, LinkOption.NOFOLLOW_LINKS)) { Files.createDirectories(Paths.get(pathName, fullPath)); } return Paths.get(dir.toString(), idPath + extension); }
From source file:org.fusesource.mvnplugins.updatesite.UpdateSiteDeployMojo.java
/** * <p>//from ww w.j a v a 2 s. c om * Get the <code>ProxyInfo</code> of the proxy associated with the <code>host</code> * and the <code>protocol</code> of the given <code>repository</code>. * </p> * <p> * Extract from <a href="http://java.sun.com/j2se/1.5.0/docs/guide/net/properties.html"> * J2SE Doc : Networking Properties - nonProxyHosts</a> : "The value can be a list of hosts, * each separated by a |, and in addition a wildcard character (*) can be used for matching" * </p> * <p> * Defensively support for comma (",") and semi colon (";") in addition to pipe ("|") as separator. * </p> * * @param repository the Repository to extract the ProxyInfo from. * @param wagonManager the WagonManager used to connect to the Repository. * @return a ProxyInfo object instantiated or <code>null</code> if no matching proxy is found */ public static ProxyInfo getProxyInfo(Repository repository, WagonManager wagonManager) { ProxyInfo proxyInfo = wagonManager.getProxy(repository.getProtocol()); if (proxyInfo == null) { return null; } String host = repository.getHost(); String nonProxyHostsAsString = proxyInfo.getNonProxyHosts(); String[] nonProxyHosts = StringUtils.split(nonProxyHostsAsString, ",;|"); for (int i = 0; i < nonProxyHosts.length; i++) { String nonProxyHost = nonProxyHosts[i]; if (StringUtils.contains(nonProxyHost, "*")) { // Handle wildcard at the end, beginning or middle of the nonProxyHost String nonProxyHostPrefix = StringUtils.substringBefore(nonProxyHost, "*"); String nonProxyHostSuffix = StringUtils.substringAfter(nonProxyHost, "*"); // prefix* if (StringUtils.isNotEmpty(nonProxyHostPrefix) && host.startsWith(nonProxyHostPrefix) && StringUtils.isEmpty(nonProxyHostSuffix)) { return null; } // *suffix if (StringUtils.isEmpty(nonProxyHostPrefix) && StringUtils.isNotEmpty(nonProxyHostSuffix) && host.endsWith(nonProxyHostSuffix)) { return null; } // prefix*suffix if (StringUtils.isNotEmpty(nonProxyHostPrefix) && host.startsWith(nonProxyHostPrefix) && StringUtils.isNotEmpty(nonProxyHostSuffix) && host.endsWith(nonProxyHostSuffix)) { return null; } } else if (host.equals(nonProxyHost)) { return null; } } return proxyInfo; }
From source file:org.gaixie.micrite.security.action.UserAction.java
/** * ?// w w w. j a v a2 s .c o m * @return "success" */ public String forgotPasswordStepOne() { // ????? if (username == null) { resultMap.put("message", getText("forgotPassword.step1.description")); resultMap.put("showForm", true); } else { try { String baseUrl = StringUtils.substringBefore( ServletActionContext.getRequest().getRequestURL().toString(), "forgotPasswordStepOne.action"); userService.forgotPasswordStepOne(username, baseUrl, getLocale().toString()); resultMap.put("message", getText("forgotPassword.step1.successful")); resultMap.put("showForm", false); } catch (SecurityException e) { resultMap.put("message", getText(e.getMessage())); resultMap.put("showForm", true); logger.error(getText(e.getMessage())); } } return SUCCESS; }
From source file:org.hippoecm.frontend.plugins.console.editor.JcrName.java
/** * @return the namespace part of the JCR property name, or null if the property does not have a namespace. *//*from www . j a va2s. co m*/ public String getNamespace() { if (hasNamespace()) { return StringUtils.substringBefore(jcrPropName, NAMESPACE_NAME_SEPARATOR); } return null; }
From source file:org.hippoecm.frontend.plugins.gallery.columns.render.MimeTypeIconRenderer.java
private Icon mimetypeToIcon(String mimeType) { if (!mimeType.startsWith("application")) { mimeType = StringUtils.substringBefore(mimeType, "/"); }/*from ww w .j a v a 2 s .c o m*/ mimeType = mimeType.toLowerCase(); if (MIMETYPE_TO_ICON.containsKey(mimeType)) { return MIMETYPE_TO_ICON.get(mimeType); } return null; }
From source file:org.hippoecm.frontend.plugins.richtext.jcr.RichTextImageURLProvider.java
public String getURL(String link) throws RichTextException { final String facetName = StringUtils.substringBefore(link, "/"); final String type = StringUtils.substringAfterLast(link, "/"); final Node node = this.nodeModel.getObject(); final String uuid = RichTextFacetHelper.getChildDocBaseOrNull(node, facetName); if (uuid != null && linkFactory.getLinkUuids().contains(uuid)) { RichTextImage rti = imageFactory.loadImageItem(uuid, type); return rti.getUrl(); }// w w w . j ava 2 s. c om return link; }