List of usage examples for org.apache.commons.lang StringUtils indexOf
public static int indexOf(String str, String searchStr, int startPos)
Finds the first index within a String, handling null
.
From source file:org.apache.tajo.engine.function.string.Locate.java
/** * Returns the position of the first occurance of substr in string after position pos (using one-based index). * //from w ww . ja v a 2s . c o m * if substr is empty string, it always matches except * pos is greater than string length + 1.(mysql locate() function spec.) * At any not matched case, it returns 0. */ private int locate(String str, String substr, int pos) { if (substr.length() == 0) { if (pos <= (str.length() + 1)) { return pos; } else { return 0; } } int idx = StringUtils.indexOf(str, substr, pos - 1); if (idx == -1) { return 0; } return idx + 1; }
From source file:org.artifactory.api.maven.MavenArtifactInfo.java
public static MavenArtifactInfo fromRepoPath(RepoPath repoPath) { String groupId, artifactId, version, type = MavenArtifactInfo.NA, classifier = MavenArtifactInfo.NA; String path = repoPath.getPath(); String fileName = repoPath.getName(); //The format of the relative path in maven is a/b/c/artifactId/baseVer/fileName where //groupId="a.b.c". We split the path to elements and analyze the needed fields. LinkedList<String> pathElements = new LinkedList<>(); StringTokenizer tokenizer = new StringTokenizer(path, "/"); while (tokenizer.hasMoreTokens()) { pathElements.add(tokenizer.nextToken()); }//from ww w. jav a2s . c om //Sanity check, we need groupId, artifactId and version if (pathElements.size() < 3) { log.debug( "Cannot build MavenArtifactInfo from '{}'. The groupId, artifactId and version are unreadable.", repoPath); return new MavenArtifactInfo(); } //Extract the version, artifactId and groupId int pos = pathElements.size() - 2; // one before the last path element version = pathElements.get(pos--); artifactId = pathElements.get(pos--); StringBuilder groupIdBuff = new StringBuilder(); for (; pos >= 0; pos--) { if (groupIdBuff.length() != 0) { groupIdBuff.insert(0, '.'); } groupIdBuff.insert(0, pathElements.get(pos)); } groupId = groupIdBuff.toString(); //Extract the type and classifier except for metadata files boolean metaData = NamingUtils.isMetadata(fileName); if (!metaData) { if (MavenNaming.isUniqueSnapshotFileName(fileName)) { version = StringUtils.remove(version, "-" + MavenNaming.SNAPSHOT); version = version + "-" + MavenNaming.getUniqueSnapshotVersionTimestampAndBuildNumber(fileName); } type = StringUtils.substring(fileName, artifactId.length() + version.length() + 2); int versionStartIndex = StringUtils.indexOf(fileName, "-", artifactId.length()) + 1; int classifierStartIndex = StringUtils.indexOf(fileName, "-", versionStartIndex + version.length()); if (classifierStartIndex >= 0) { Set<String> customMavenTypes = getMavenCustomTypes(); for (String customMavenType : customMavenTypes) { if (StringUtils.endsWith(fileName, customMavenType)) { classifier = StringUtils.remove(type, "." + customMavenType); type = customMavenType; break; } } if (MavenArtifactInfo.NA.equals(classifier)) { int typeDotStartIndex = StringUtils.lastIndexOf(type, "."); classifier = StringUtils.substring(type, 0, typeDotStartIndex); type = StringUtils.substring(type, classifier.length() + 1); } } } return new MavenArtifactInfo(groupId, artifactId, version, classifier, type); }
From source file:org.artifactory.api.module.ModuleInfoUtils.java
/** * Constructs the module version pattern, starting from [baseRev] to [fileItegRev] * * @param itemPathPattern the item path containing all the tokens of a given repo layout * @return the tokens path representing the file name, empty string ("") in case of unsupported layout, * Unsupported layout is one which [fileItegRev] is before [baseRev] *//*from w ww.j a v a 2 s . c o m*/ private static String getModuleVersionPattern(String itemPathPattern) { String wrappedBaseRevisionToken = RepoLayoutUtils.wrapKeywordAsToken(RepoLayoutUtils.BASE_REVISION); String wrappedFileItegRevToken = RepoLayoutUtils .wrapKeywordAsToken(RepoLayoutUtils.FILE_INTEGRATION_REVISION); int baseRevStartPos = StringUtils.lastIndexOf(itemPathPattern, wrappedBaseRevisionToken); int fileItegRevEndPos = StringUtils.lastIndexOf(itemPathPattern, wrappedFileItegRevToken); int indexOfClosingOptionalBracket = StringUtils.indexOf(itemPathPattern, ")", fileItegRevEndPos); if (indexOfClosingOptionalBracket > 0) { fileItegRevEndPos = indexOfClosingOptionalBracket + 1; } if (fileItegRevEndPos >= baseRevStartPos) { return StringUtils.substring(itemPathPattern, baseRevStartPos, fileItegRevEndPos); } return ""; }
From source file:org.beangle.struts2.view.template.AbstractTemplateEngine.java
public String getParentTemplate(String template) { int start = StringUtils.indexOf(template, '/', 1) + 1; int end = StringUtils.lastIndexOf(template, '/'); String parentTheme = (String) getThemeProps(template.substring(start, end)).get("parent"); if (null == parentTheme) return null; return StrUtils.concat(template.substring(0, start), parentTheme, template.substring(end)); }
From source file:org.bigmouth.tfc.v1.PageImpl.java
protected String parseHost(String url) { int index = url.indexOf(Constants.PROTOCOL_STRING); if (index == -1) { throw new IllegalStateException("Illegal url. " + url); }/* w w w . j a v a2s . com*/ return url.substring(0, StringUtils.indexOf(url, '/', Constants.PROTOCOL_STRING.length())); }
From source file:org.codice.proxy.http.HttpProxyCamelHttpTransportServlet.java
private String getEndpointNameFromPath(String path) { // path is like: "/example1/something/0/thing.html" // or is like: "/example1" // endpointName is: "example1" String endpointName = (StringUtils.indexOf(path, "/", 1) != StringUtils.INDEX_NOT_FOUND) ? StringUtils.substring(path, 0, StringUtils.indexOf(path, "/", 1)) : path;/*from ww w . java2 s .c om*/ endpointName = StringUtils.remove(endpointName, "/"); return endpointName; }
From source file:org.eclipse.smarthome.core.extension.sample.internal.SampleExtensionService.java
private String createDescription() { int index = StringUtils.indexOf(LOREM_IPSUM, ' ', random.nextInt(LOREM_IPSUM.length())); return LOREM_IPSUM.substring(0, index); }
From source file:org.jahia.ajax.gwt.helper.UIConfigHelper.java
/** * Get edit configuration//ww w . ja va2 s. co m * * @return * @throws GWTJahiaServiceException */ public GWTEditConfiguration getGWTEditConfiguration(String name, String contextPath, JahiaUser jahiaUser, Locale locale, Locale uiLocale, HttpServletRequest request, JCRSessionWrapper session) throws GWTJahiaServiceException { try { EditConfiguration config = (EditConfiguration) SpringContextSingleton.getBean(name); if (config != null) { GWTEditConfiguration gwtConfig = new GWTEditConfiguration(); gwtConfig.setName(config.getName()); String defaultLocation = config.getDefaultLocation(); if (defaultLocation.contains("$defaultSiteHome")) { JahiaSitesService siteService = JahiaSitesService.getInstance(); JahiaSite resolvedSite = !Url.isLocalhost(request.getServerName()) ? siteService.getSiteByServerName(request.getServerName(), session) : null; if (resolvedSite == null) { resolvedSite = JahiaSitesService.getInstance().getDefaultSite(session); if (resolvedSite != null && !((JCRSiteNode) resolvedSite).hasPermission(config.getRequiredPermission())) { resolvedSite = null; } if (resolvedSite == null) { List<JCRSiteNode> sites = JahiaSitesService.getInstance().getSitesNodeList(session); for (JCRSiteNode site : sites) { if (!"systemsite".equals(site.getName()) && (site.hasPermission(config.getRequiredPermission()))) { resolvedSite = site; break; } } } } if (resolvedSite != null) { JCRSiteNode siteNode = (JCRSiteNode) session .getNode(((JCRSiteNode) resolvedSite).getPath()); if (siteNode.getHome() != null) { defaultLocation = defaultLocation.replace("$defaultSiteHome", siteNode.getHome().getPath()); } else { defaultLocation = null; } } else { defaultLocation = null; } } else if (defaultLocation.contains("$user")) { defaultLocation = defaultLocation.replace("$user", jahiaUser.getLocalPath()); } gwtConfig.setDefaultLocation(defaultLocation); JCRNodeWrapper contextNode = null; JCRSiteNode site = null; if (contextPath == null) { int nodeNameIndex = StringUtils.indexOf(defaultLocation, ".", StringUtils.lastIndexOf(defaultLocation, "/")); contextPath = StringUtils.substring(defaultLocation, 0, nodeNameIndex); if (defaultLocation != null && session.nodeExists(contextPath)) { contextNode = session.getNode(contextPath); site = contextNode.getResolveSite(); } } else { if (session.nodeExists(contextPath)) { contextNode = session.getNode(contextPath); site = contextNode.getResolveSite(); } } if (config.getForcedSite() != null) { site = (JCRSiteNode) session.getNode(config.getForcedSite()); } if (site == null) { contextNode = session.getNode("/sites/systemsite"); site = contextNode.getResolveSite(); } // check locale final List<Locale> languagesAsLocales = site.getLanguagesAsLocales(); if (languagesAsLocales != null && !languagesAsLocales.contains(locale)) { final String defaultLanguage = site.getDefaultLanguage(); if (StringUtils.isNotEmpty(defaultLanguage)) { locale = LanguageCodeConverters.languageCodeToLocale(defaultLanguage); } } gwtConfig.setTopToolbar(createGWTToolbar(contextNode, site, jahiaUser, locale, uiLocale, request, config.getTopToolbar())); gwtConfig.setSidePanelToolbar(createGWTToolbar(contextNode, site, jahiaUser, locale, uiLocale, request, config.getSidePanelToolbar())); gwtConfig.setMainModuleToolbar(createGWTToolbar(contextNode, site, jahiaUser, locale, uiLocale, request, config.getMainModuleToolbar())); gwtConfig.setContextMenu(createGWTToolbar(contextNode, site, jahiaUser, locale, uiLocale, request, config.getContextMenu())); gwtConfig.setTabs(createGWTSidePanelTabList(contextNode, site, jahiaUser, locale, uiLocale, request, config.getTabs())); gwtConfig.setEngineConfigurations(createGWTEngineConfigurations(contextNode, site, jahiaUser, locale, uiLocale, request, config.getEngineConfigurations())); gwtConfig.setSitesLocation(config.getSitesLocation()); gwtConfig.setEnableDragAndDrop(config.isEnableDragAndDrop()); gwtConfig.setDefaultUrlMapping(config.getDefaultUrlMapping()); gwtConfig.setComponentsPaths(config.getComponentsPaths()); gwtConfig.setEditableTypes(config.getEditableTypes()); gwtConfig.setNonEditableTypes(config.getNonEditableTypes()); gwtConfig.setSkipMainModuleTypesDomParsing(config.getSkipMainModuleTypesDomParsing()); gwtConfig.setVisibleTypes(config.getVisibleTypes()); gwtConfig.setNonVisibleTypes(config.getNonVisibleTypes()); gwtConfig.setExcludedNodeTypes(config.getExcludedNodeTypes()); List<String> configsList = new ArrayList<String>(); // configsList will define the list of modes that share the same configuration to avoid reloading the main resource // when switching from edit to preview or live or any mode that has the same default location. // An exception has been added for system site that is used for dashboard or administration. for (EditConfiguration configuration : SpringContextSingleton.getInstance().getContext() .getBeansOfType(EditConfiguration.class).values()) { if (StringUtils.equals(configuration.getSitesLocation(), (config.getSitesLocation())) && !StringUtils.equals(config.getSitesLocation(), "/sites/systemsite")) { configsList.add(configuration.getName()); } } gwtConfig.setSamePathConfigsList(configsList); gwtConfig.setSiteNode(navigation.getGWTJahiaNode(site, GWTJahiaNode.DEFAULT_SITE_FIELDS, uiLocale)); if (config.isLoadSitesList()) { List<GWTJahiaNode> sites = navigation.retrieveRoot(Arrays.asList(config.getSitesLocation()), Arrays.asList("jnt:virtualsite"), null, null, GWTJahiaNode.DEFAULT_SITEMAP_FIELDS, null, null, site, session, uiLocale, false, false, null, null); String permission = ((EditConfiguration) SpringContextSingleton.getBean(name)) .getRequiredPermission(); Map<String, GWTJahiaNode> sitesMap = new HashMap<String, GWTJahiaNode>(); for (GWTJahiaNode aSite : sites) { if (session.getNodeByUUID(aSite.getUUID()).hasPermission(permission)) { sitesMap.put(aSite.getSiteUUID(), aSite); } } GWTJahiaNode systemSite = navigation.getGWTJahiaNode(session.getNode("/sites/systemsite"), GWTJahiaNode.DEFAULT_SITEMAP_FIELDS); if (!sitesMap.containsKey(systemSite.getUUID())) { sitesMap.put(systemSite.getUUID(), systemSite); } gwtConfig.setSitesMap(sitesMap); } gwtConfig.setPermissions(JahiaPrivilegeRegistry.getRegisteredPrivilegeNames()); gwtConfig.setChannels(channelHelper.getChannels()); gwtConfig.setUseFullPublicationInfoInMainAreaModules( config.isUseFullPublicationInfoInMainAreaModules()); gwtConfig.setSupportChannelsDisplay(config.isSupportChannelsDisplay()); return gwtConfig; } else { throw new GWTJahiaServiceException(Messages .getInternal("label.gwt.error.bean.editconfig.not.found.in.spring.config.file", uiLocale)); } } catch (RepositoryException e) { logger.error(e.getMessage(), e); throw new GWTJahiaServiceException(Messages.getInternalWithArguments("label.gwt.error.config.not.found", uiLocale, name, e.getLocalizedMessage())); } }
From source file:org.jahia.services.render.URLResolver.java
/** * Initializes an instance of this class. This constructor is mainly used when * resolving URLs of incoming requests./*from ww w . j a v a2 s .co m*/ * * @param pathInfo the path info (usually obtained with @link javax.servlet.http.HttpServletRequest.getPathInfo()) * @param serverName the server name (usually obtained with @link javax.servlet.http.HttpServletRequest.getServerName()) * @param request the current HTTP servlet request object */ protected URLResolver(String pathInfo, String serverName, String workspace, HttpServletRequest request, Ehcache nodePathCache, Ehcache siteInfoCache) { super(); this.nodePathCache = nodePathCache; this.siteInfoCache = siteInfoCache; this.workspace = workspace; this.urlPathInfo = normalizeUrlPathInfo(pathInfo); if (!JahiaUserManagerService.isGuest(JCRSessionFactory.getInstance().getCurrentUser())) { Date date = getVersionDate(request); String versionLabel = getVersionLabel(request); setVersionDate(date); setVersionLabel(versionLabel); } if (urlPathInfo != null) { servletPart = StringUtils.substring(getUrlPathInfo(), 1, StringUtils.indexOf(getUrlPathInfo(), "/", 1)); path = StringUtils.substring(getUrlPathInfo(), servletPart.length() + 2, getUrlPathInfo().length()); } if (!resolveUrlMapping(serverName, request)) { init(); if (!Url.isLocalhost(serverName) && isMappable() && SettingsBean.getInstance().isPermanentMoveForVanityURL()) { try { if (siteKeyByServerName != null && siteKeyByServerName.equals(getNode().getResolveSite().getSiteKey())) { VanityUrl defaultVanityUrl = getVanityUrlService() .getVanityUrlForWorkspaceAndLocale(getNode(), this.workspace, locale, siteKey); if (defaultVanityUrl != null && defaultVanityUrl.isActive()) { redirect(request, defaultVanityUrl); } } } catch (PathNotFoundException e) { logger.debug("Path not found : " + urlPathInfo); } catch (AccessDeniedException e) { logger.debug("User has no access to the resource, so there will not be a redirection"); } catch (RepositoryException e) { logger.warn("Error when trying to check whether there is a vanity URL mapping", e); } } } }
From source file:org.kuali.ext.mm.ObjectUtil.java
/** * Tokenize the input line with the given deliminator and store the tokens in a list * * @param line the input line//from www . j a v a 2 s. c o m * @param delim the deminator that separates the fields in the given line * @return a list of tokens */ public static List<String> split(String line, String delim) { List<String> tokens = new ArrayList<String>(); int currentPosition = 0; for (int step = 0; step < line.length(); step++) { int previousPosition = currentPosition; currentPosition = StringUtils.indexOf(line, delim, currentPosition); currentPosition = currentPosition == -1 ? line.length() - 1 : currentPosition; String sub = line.substring(previousPosition, currentPosition); tokens.add(sub); // don't trim the string currentPosition += delim.length(); if (currentPosition >= line.length()) { break; } } return tokens; }