List of usage examples for org.apache.commons.lang StringUtils startsWith
public static boolean startsWith(String str, String prefix)
Check if a String starts with a specified prefix.
From source file:org.jahia.ajax.gwt.helper.NavigationHelper.java
public List<GWTJahiaNode> retrieveRoot(List<String> paths, List<String> nodeTypes, List<String> mimeTypes, List<String> filters, final List<String> fields, final JCRSiteNode site, Locale uiLocale, JCRSessionWrapper currentUserSession, boolean checkSubChild, boolean displayHiddenTypes, List<String> hiddenTypes, String hiddenRegex) throws RepositoryException, GWTJahiaServiceException { final List<GWTJahiaNode> userNodes = new ArrayList<GWTJahiaNode>(); final boolean checkLicense = haveToCheckLicense(fields); for (String path : paths) { // replace $user and $site by the right values String displayName = null; if (site != null) { if (path.contains("$site/") || path.endsWith("$site")) { String sitePath = site.getPath(); if (StringUtils.startsWith(sitePath, "/modules/")) { String moduleName = sitePath.indexOf('/', "/modules/".length()) != -1 ? StringUtils.substringBetween(sitePath, "/modules/", "/") : StringUtils.substringAfter(sitePath, "/modules/"); JahiaTemplatesPackage module = ServicesRegistry.getInstance() .getJahiaTemplateManagerService().getTemplatePackageById(moduleName); if (module == null) { return userNodes; }//from w w w. j av a2 s. c o m path = StringUtils.replace(path, "$site", sitePath + "/" + module.getVersion().toString()); } else { path = StringUtils.replace(path, "$site", sitePath); } } if (path.contains("$siteKey/")) { path = path.replace("$siteKey", site.getSiteKey()); } } if (path.contains("$moduleversion")) { String moduleName = StringUtils.split(path, '/')[1]; if (ServicesRegistry.getInstance().getJahiaTemplateManagerService() .getTemplatePackageById(moduleName) != null) { path = path.replace("$moduleversion", ServicesRegistry.getInstance().getJahiaTemplateManagerService() .getTemplatePackageById(moduleName).getVersion().toString()); } else { logger.warn("read version - Unable to get bundle " + moduleName + " from registry"); continue; } } if (path.contains("$systemsite")) { String systemSiteKey = JCRContentUtils.getSystemSitePath(); path = path.replace("$systemsite", systemSiteKey); } if (site != null && path.contains("$sites")) { JCRTemplate.getInstance().doExecuteWithSystemSession(new JCRCallback<Object>() { public Object doInJCR(JCRSessionWrapper session) throws RepositoryException { final JCRNodeWrapper parent = site.getParent(); NodeIterator nodes = parent.getNodes(); while (nodes.hasNext()) { JCRNodeWrapper nodeWrapper = (JCRNodeWrapper) nodes.next(); if (!checkLicense || isAllowedByLicense(nodeWrapper)) { userNodes.add(getGWTJahiaNode(nodeWrapper, fields)); } } return null; } }); } if (path.contains("$user")) { final JCRNodeWrapper userFolder = JCRContentUtils.getInstance() .getDefaultUserFolder(currentUserSession, StringUtils.substringAfter(path, "$user")); path = userFolder.getPath(); displayName = Messages.getInternal("label.personalFolder", uiLocale, "label.personalFolder"); } if (path.startsWith("/")) { try { if (path.endsWith("/*")) { getMatchingChildNodes(nodeTypes, mimeTypes, filters, fields, currentUserSession.getNode(StringUtils.substringBeforeLast(path, "/*")), userNodes, checkSubChild, displayHiddenTypes, hiddenTypes, hiddenRegex, false, uiLocale); } else { GWTJahiaNode root = getNode(path, fields, currentUserSession, uiLocale); if (root != null) { if (displayName != null) { root.setDisplayName(JCRContentUtils.unescapeLocalNodeName(displayName)); } userNodes.add(root); } } } catch (PathNotFoundException e) { // do nothing is the path is not found } } } return userNodes; }
From source file:org.jahia.modules.external.admin.mount.AbstractMountPointFactoryHandler.java
protected JSONArray getSiteFolders(Workspace workspace, boolean local) throws RepositoryException { JSONArray folders = new JSONArray(); Query sitesQuery = workspace.getQueryManager().createQuery(SITES_QUERY, Query.JCR_SQL2); NodeIterator sites = sitesQuery.execute().getNodes(); while (sites.hasNext()) { Node site = sites.nextNode(); Node siteFiles;//from w ww . j av a 2 s. com try { siteFiles = site.getNode("files"); folders.put(escape(siteFiles.getPath())); } catch (RepositoryException e) { // no files under the site continue; } StringBuilder filter = new StringBuilder("isdescendantnode(f,['") .append(JCRContentUtils.sqlEncode(siteFiles.getPath())).append("'])"); for (JCRStoreProvider provider : JCRStoreService.getInstance().getSessionFactory().getProviderList()) { if (!provider.isDefault() && StringUtils.startsWith(provider.getMountPoint(), siteFiles.getPath())) { filter.append(" and (not isdescendantnode(f,['") .append(JCRContentUtils.sqlEncode(provider.getMountPoint())).append("']))"); } } Query siteFoldersQuery = workspace.getQueryManager() .createQuery("select * from [jnt:folder] as f where " + filter, Query.JCR_SQL2); NodeIterator siteFolders = siteFoldersQuery.execute().getNodes(); while (siteFolders.hasNext()) { Node siteFolder = siteFolders.nextNode(); folders.put(escape(siteFolder.getPath())); } } return folders; }
From source file:org.jahia.modules.external.modules.validator.ItemNameValidator.java
@Pattern(regexp = "^\\*$|^[A-Za-z]+[A-Za-z0-9:_]*") public String getName() { return StringUtils.startsWith(node.getName(), ModulesDataSource.UNSTRUCTURED_PROPERTY) || StringUtils.startsWith(node.getName(), ModulesDataSource.UNSTRUCTURED_CHILD_NODE) ? "*" : node.getName();/* w w w . ja va 2 s.co m*/ }
From source file:org.jahia.modules.jahiaoauth.impl.JahiaOAuthServiceImpl.java
private HashMap<String, Object> getPropertiesResult(ConnectorService connectorService, JSONObject responseJson) throws JSONException { HashMap<String, Object> propertiesResult = new HashMap<>(); List<Map<String, Object>> properties = connectorService.getAvailableProperties(); for (Map<String, Object> entry : properties) { String propertyName = (String) entry.get(JahiaOAuthConstants.PROPERTY_NAME); if ((boolean) entry.get(JahiaOAuthConstants.CAN_BE_REQUESTED) && responseJson.has(propertyName)) { propertiesResult.put(propertyName, responseJson.get(propertyName)); } else if (entry.containsKey(JahiaOAuthConstants.PROPERTY_TO_REQUEST)) { String propertyToRequest = (String) entry.get(JahiaOAuthConstants.PROPERTY_TO_REQUEST); if (responseJson.has(propertyToRequest)) { if (entry.containsKey(JahiaOAuthConstants.VALUE_PATH)) { String pathToProperty = (String) entry.get(JahiaOAuthConstants.VALUE_PATH); if (StringUtils.startsWith(pathToProperty, "/")) { extractPropertyFromJSON(propertiesResult, responseJson.getJSONObject(propertyToRequest), null, pathToProperty, propertyName); } else { extractPropertyFromJSON(propertiesResult, null, responseJson.getJSONArray(propertyToRequest), pathToProperty, propertyName); }/*from ww w . jav a 2 s.c o m*/ } else { propertiesResult.put(propertyName, responseJson.get(propertyToRequest)); } } } } return propertiesResult; }
From source file:org.jahia.modules.jahiaoauth.impl.JahiaOAuthServiceImpl.java
private void extractPropertyFromJSON(HashMap<String, Object> propertiesResult, JSONObject jsonObject, JSONArray jsonArray, String pathToProperty, String propertyName) throws JSONException { if (StringUtils.startsWith(pathToProperty, "/")) { String key = StringUtils.substringAfter(pathToProperty, "/"); String potentialKey1 = StringUtils.substringBefore(key, "["); String potentialKey2 = StringUtils.substringBefore(key, "/"); if (potentialKey1.length() <= potentialKey2.length()) { key = potentialKey1;/*from w w w . ja v a 2 s . c o m*/ } else if (potentialKey1.length() > potentialKey2.length()) { key = potentialKey2; } pathToProperty = StringUtils.substringAfter(pathToProperty, "/" + key); if (StringUtils.isBlank(pathToProperty) && jsonObject.has(key)) { propertiesResult.put(propertyName, jsonObject.get(key)); } else { if (StringUtils.startsWith(pathToProperty, "/") && jsonObject.has(key)) { extractPropertyFromJSON(propertiesResult, jsonObject.getJSONObject(key), null, pathToProperty, propertyName); } else if (jsonObject.has(key)) { extractPropertyFromJSON(propertiesResult, null, jsonObject.getJSONArray(key), pathToProperty, propertyName); } } } else { int arrayIndex = new Integer(StringUtils.substringBetween(pathToProperty, "[", "]")); pathToProperty = StringUtils.substringAfter(pathToProperty, "]"); if (StringUtils.isBlank(pathToProperty) && jsonArray.length() >= arrayIndex) { propertiesResult.put(propertyName, jsonArray.get(arrayIndex)); } else { if (StringUtils.startsWith(pathToProperty, "/") && jsonArray.length() >= arrayIndex) { extractPropertyFromJSON(propertiesResult, jsonArray.getJSONObject(arrayIndex), null, pathToProperty, propertyName); } else if (jsonArray.length() >= arrayIndex) { extractPropertyFromJSON(propertiesResult, null, jsonArray.getJSONArray(arrayIndex), pathToProperty, propertyName); } } } }
From source file:org.jahia.modules.jahiaoauth.tag.JahiaOAuthFunctions.java
public static Boolean isModuleActiveOnSite(String siteKey, String path) throws JahiaException { List<JahiaTemplatesPackage> jahiaTemplatesPackageList = jahiaTemplateManagerService .getInstalledModulesForSite(siteKey, false, true, false); for (JahiaTemplatesPackage jahiaTemplatesPackage : jahiaTemplatesPackageList) { if (StringUtils.startsWith(path, jahiaTemplatesPackage.getRootFolderPath() + "/" + jahiaTemplatesPackage.getVersion().toString())) { return true; }/*from w ww. ja v a 2 s . com*/ } return false; }
From source file:org.jahia.modules.modulemanager.flow.ModuleManagementFlowHandler.java
public void validateScmInfo(String scmUri, String branchOrTag, String moduleVersion, MutableAttributeMap flashScope) throws IOException { if ((StringUtils.startsWith(scmUri, "scm:git:") && StringUtils.isBlank(branchOrTag)) || (StringUtils.startsWith(scmUri, "scm:svn:") && StringUtils.contains(scmUri, "/trunk/"))) { Map<String, String> branchTagInfos = listBranchOrTags(moduleVersion, scmUri); flashScope.put("branchTagInfos", branchTagInfos); branchOrTag = guessBranchOrTag(moduleVersion, scmUri, branchTagInfos, null); flashScope.put("branchOrTag", branchOrTag); }//w ww. j av a 2 s. c o m }
From source file:org.jahia.osgi.JahiaBundleTemplatesPackageHandler.java
private static boolean hasResourceBundle(Bundle bundle, String resourceBundleName) { boolean found = false; // check if there is a resource bundle file in the resources folder Enumeration<String> paths = bundle.getEntryPaths("/resources/"); while (paths != null && paths.hasMoreElements()) { String path = paths.nextElement(); if (StringUtils.startsWith(path, "resources/" + resourceBundleName) && StringUtils.endsWith(path, ".properties")) { return true; }//w ww .j av a2 s . co m } return false; }
From source file:org.jahia.services.content.interceptor.TemplateModuleInterceptor.java
@Override public Value afterGetValue(JCRPropertyWrapper property, Value storedValue) throws ValueFormatException, RepositoryException { RenderContext renderContext = renderContextThreadLocal.get(); if (renderContext != null) { String contextSitePath = renderContext.getSite().getPath(); if (StringUtils.startsWith(contextSitePath, "/sites")) { // we are under a site String propertyPath = property.getPath(); if (propertyPath.startsWith("/modules/")) { // node is under /modules String[] propertyPathTokens = StringUtils.split(propertyPath, "/", TEMPLATES_TOKEN_POSITION + 2); if (propertyPathTokens.length >= (TEMPLATES_TOKEN_POSITION + 2) && "templates".equals(propertyPathTokens[TEMPLATES_TOKEN_POSITION])) { // our node is under "templates" node in a module try { String referencePath = property.getSession() .getNodeByIdentifier(storedValue.getString()).getPath(); if (referencePath.startsWith("/modules/")) { // target is also in a module String[] path = StringUtils.split(referencePath, "/"); if (path.length >= TEMPLATES_TOKEN_POSITION && !"templates".equals(path[TEMPLATES_TOKEN_POSITION])) { StringBuilder sitePath = new StringBuilder(64); sitePath.append(contextSitePath); for (int i = TEMPLATES_TOKEN_POSITION; i < path.length; i++) { sitePath.append("/").append(path[i]); }/*from ww w .jav a 2 s .com*/ return JCRValueFactoryImpl.getInstance() .createValue(property.getSession().getNode(sitePath.toString())); } } } catch (PathNotFoundException e) { logger.warn("Cannot get reference in local site " + e.getMessage()); renderContext.getRequest().setAttribute("expiration", "0"); } catch (ItemNotFoundException e) { // referenced node not available } } } } } return storedValue; }
From source file:org.jahia.services.content.JCRPropertyWrapperImpl.java
public JCRNodeWrapper getNode() throws ValueFormatException, RepositoryException { Value value = getValue();/* ww w . j a v a 2 s. c o m*/ int type = value.getType(); switch (type) { case PropertyType.REFERENCE: case PropertyType.WEAKREFERENCE: return session.getNodeByUUID(value.getString()); case PropertyType.PATH: case PropertyType.NAME: String path = value.getString(); boolean absolute = StringUtils.startsWith(path, "/"); return (absolute) ? session.getNode(path) : getParent().getNode(path); case PropertyType.STRING: try { Value refValue = ValueHelper.convert(value, PropertyType.REFERENCE, session.getValueFactory()); return session.getNodeByUUID(refValue.getString()); } catch (RepositoryException e) { // try if STRING value can be interpreted as PATH value Value pathValue = ValueHelper.convert(value, PropertyType.PATH, session.getValueFactory()); absolute = StringUtils.startsWith(pathValue.getString(), "/"); return (absolute) ? session.getNode(pathValue.getString()) : getParent().getNode(pathValue.getString()); } default: throw new ValueFormatException( "Property value cannot be converted to a PATH, REFERENCE or WEAKREFERENCE"); } }