List of usage examples for org.apache.commons.lang StringUtils splitByWholeSeparator
public static String[] splitByWholeSeparator(String str, String separator)
Splits the provided text into an array, separator string specified.
From source file:org.eclipse.gyrex.admin.ui.internal.application.AdminApplication.java
private void attachHistoryListener() { final BrowserNavigation browserNavigation = RWT.getClient().getService(BrowserNavigation.class); if (browserNavigation != null) { browserNavigation.addBrowserNavigationListener(new BrowserNavigationListener() { private static final long serialVersionUID = 1L; @Override//from ww w . jav a 2 s .c o m public void navigated(final BrowserNavigationEvent event) { final String[] tokens = StringUtils.splitByWholeSeparator(event.getState(), HISTORY_TOKEN_SEPARATOR); final PageContribution contribution = AdminPageRegistry.getInstance().getPage(tokens[0]); if (contribution != null) { openPage(contribution, tokens); } } }); } }
From source file:org.eclipse.gyrex.cloud.internal.locking.ZooKeeperLock.java
/** * This method is only public for testing purposes. It must not be called by * clients.//from w w w . j a v a 2 s .c o m * * @noreference This method is not intended to be referenced by clients. */ public static String[] extractRecoveryKeyDetails(final String recoveryKey) { final String[] keySegments = StringUtils.splitByWholeSeparator(recoveryKey, SEPARATOR); if (keySegments.length < 2) throw new IllegalArgumentException("invalid recovery key format"); final String lockName = keySegments[0]; final String nodeContent = StringUtils.removeStart(recoveryKey, lockName.concat(SEPARATOR)); if (StringUtils.isBlank(lockName) || StringUtils.isBlank(nodeContent)) throw new IllegalArgumentException("invalid recovery key format"); return new String[] { lockName, nodeContent }; }
From source file:org.fabrician.enabler.KarafContainer.java
@Override protected void doInit(List<RuntimeContextVariable> additionalVariables) throws Exception { getEngineLogger().fine("doInit invoked"); clusterFeatureInfo = (KarafClusteringInfo) ContainerUtils.getFeatureInfo(KarafClusteringInfo.FEATURE_NAME, this, getCurrentDomain()); httpFeatureInfo = (HttpFeatureInfo) ContainerUtils.getFeatureInfo(Feature.HTTP_FEATURE_NAME, this, getCurrentDomain());//from w w w. ja v a 2 s . c om boolean httpEnabled = isHttpEnabled(); boolean httpsEnabled = isHttpsEnabled(); if (!httpEnabled && !httpsEnabled) { throw new Exception("HTTP or HTTPS must be enabled in the Domain"); } if (httpEnabled && !DynamicVarsUtils.validateIntegerVariable(this, HttpFeatureInfo.HTTP_PORT_VAR)) { throw new Exception("HTTP is enabled but the " + HttpFeatureInfo.HTTP_PORT_VAR + " runtime context variable is not set"); } if (httpsEnabled && !DynamicVarsUtils.validateIntegerVariable(this, HttpFeatureInfo.HTTPS_PORT_VAR)) { throw new Exception("HTTPS is enabled but the " + HttpFeatureInfo.HTTPS_PORT_VAR + " runtime context variable is not set"); } if (DynamicVarsUtils.variableHasValue(KARAF_DEBUG, "true") && !DynamicVarsUtils.validateIntegerVariable(this, KARAF_DEBUG_PORT)) { throw new Exception(KARAF_DEBUG_PORT + " runtime context variable is not set properly"); } if (!DynamicVarsUtils.validateIntegerVariable(this, KARAF_JMX_RMI_SERVER_PORT)) { throw new Exception(KARAF_JMX_RMI_SERVER_PORT + " runtime context variable is not set properly"); } if (!DynamicVarsUtils.validateIntegerVariable(this, KARAF_JMX_RMI_REGISTRY_PORT)) { throw new Exception(KARAF_JMX_RMI_REGISTRY_PORT + " runtime context variable is not set properly"); } if (!DynamicVarsUtils.validateIntegerVariable(this, KARAF_SSH_PORT)) { throw new Exception(KARAF_SSH_PORT + " runtime context variable is not set properly"); } String bindAllStr = getStringVariableValue(BIND_ON_ALL_LOCAL_ADDRESSES, "true"); boolean bindAll = BooleanUtils.toBoolean(bindAllStr); String karafBindAddress = bindAll ? "0.0.0.0" : getStringVariableValue(LISTEN_ADDRESS_VAR); additionalVariables.add(new RuntimeContextVariable(KARAF_BIND_ADDRESS, karafBindAddress, RuntimeContextVariable.STRING_TYPE)); additionalVariables.add(new RuntimeContextVariable(KARAF_JMX_SERVICE_URL, getJmxServiceUrl(), RuntimeContextVariable.STRING_TYPE, "Karaf JMX service url")); if (clusterFeatureInfo == null) { additionalVariables.add(new RuntimeContextVariable(CELLAR_CLUSTERING_ENABLED, "false", RuntimeContextVariable.STRING_TYPE)); } else { String group_membership = StringUtils .trimToEmpty(resolveVariables(clusterFeatureInfo.getGroupMembership())); group_membership = StringUtils.isBlank(group_membership) ? "default" : group_membership; String[] groups = StringUtils.splitByWholeSeparator(group_membership, ","); for (String g : groups) { if (StringUtils.trimToEmpty(g).isEmpty()) { throw new Exception( "'Cellar Group Membership' value specified in the Clustering feature is not set properly."); } } group_membership = StringUtils.join(groups, ","); // get rid of some misplaced "," additionalVariables.add(new RuntimeContextVariable(CELLAR_CLUSTERING_ENABLED, "true", RuntimeContextVariable.STRING_TYPE)); additionalVariables.add(new RuntimeContextVariable(CELLAR_GROUP_MEMBERSHIP, group_membership, RuntimeContextVariable.STRING_TYPE)); } super.doInit(additionalVariables); }
From source file:org.geoserver.security.iride.entity.IrideRole.java
/** * Utility method to parse an <code>IRIDE</code> Role mnemonic string representation.<br /> * It accepts a mnemonic string representation, expressed with the following format: <code>"role code{@link #SEPARATOR}domain code"</code>. * * @param mnemonic <code>IRIDE</code> Role mnemonic string representation * @return an <code>IRIDE</code> Role entity object * @throws IllegalArgumentException if the given mnemonic string representation is not in the expected format *///from w w w . j a va2 s. c o m public static IrideRole parseRole(String mnemonic) { final String[] tokens = StringUtils.splitByWholeSeparator(mnemonic, SEPARATOR); if (ArrayUtils.getLength(tokens) != 2) { throw new IllegalArgumentException(mnemonic); } return new IrideRole(tokens[0], tokens[1]); }
From source file:org.hippoecm.frontend.plugins.console.editor.PropertyValueEditor.java
/** * Creates property value editing component. * * @throws RepositoryException/*from w w w . ja v a 2 s .c o m*/ */ protected Component createValueEditor(final JcrPropertyValueModel valueModel) throws RepositoryException { List<ValueEditorFactory> factoryList = getEditorPlugin().getPluginContext() .getServices(ValueEditorFactory.SERVICE_ID, ValueEditorFactory.class); for (ValueEditorFactory factory : factoryList) { if (factory.canEdit(valueModel)) { return factory.createEditor("value", valueModel); } } if (propertyModel.getProperty().getType() == PropertyType.BINARY) { return new BinaryEditor("value", propertyModel, getEditorPlugin().getPluginContext()); } else if (propertyModel.getProperty().getDefinition().isProtected()) { return new Label("value", valueModel) { @Override public IConverter getConverter(final Class type) { if (type.equals(Date.class)) { return dateConverter; } return super.getConverter(type); } }; } else if (propertyModel.getProperty().getType() == PropertyType.BOOLEAN) { return new BooleanFieldWidget("value", valueModel); } else { StringConverter stringModel = new StringConverter(valueModel); String asString = stringModel.getObject(); if (asString.contains("\n")) { TextAreaWidget editor = new TextAreaWidget("value", stringModel); String[] lines = StringUtils.splitByWholeSeparator(asString, "\n"); int rowCount = lines.length; int columnCount = 1; for (String line : lines) { int length = line.length(); if (length > columnCount) { if (length > TEXT_AREA_MAX_COLUMNS) { columnCount = TEXT_AREA_MAX_COLUMNS; rowCount += (length / TEXT_AREA_MAX_COLUMNS) + 1; } else { columnCount = length; } } } editor.setRows(String.valueOf(rowCount + 1)); return editor; } else if (asString.length() > TEXT_AREA_MAX_COLUMNS) { TextAreaWidget editor = new TextAreaWidget("value", stringModel); editor.setRows(String.valueOf((asString.length() / 80))); return editor; } else { TextAreaWidget editor = new TextAreaWidget("value", stringModel); editor.setRows("1"); return editor; } } }
From source file:org.intermine.web.logic.WebUtil.java
/** * Return a string suitable for displaying a PathQuery's path, taking any * path descriptions it has configured into account. * * @param p The path to display/*w ww . j a v a 2 s . c o m*/ * @param pq The PathQuery it relates to * @param config The Web-Configuration to use to lookup labels * @return A string suitable for external display. */ public static String formatPathDescription(final Path p, final PathQuery pq, final WebConfig config) { final Map<String, String> descriptions = pq.getDescriptions(); final String withLabels = formatPath(p, config); final List<String> labeledParts = Arrays.asList(StringUtils.splitByWholeSeparator(withLabels, " > ")); if (descriptions.isEmpty()) { return StringUtils.join(labeledParts, " > "); } final String withReplaceMents = replaceDescribedPart(p.getNoConstraintsString(), descriptions); final List<String> originalParts = Arrays.asList(StringUtils.split(p.getNoConstraintsString(), '.')); final int originalPartsSize = originalParts.size(); final List<String> replacedParts = Arrays .asList(StringUtils.splitByWholeSeparator(withReplaceMents, " > ")); final int replacedSize = replacedParts.size(); // Else there are some described path segments... int partsToKeepFromOriginal = 0; int partsToTakeFromReplaced = replacedSize; for (int i = 0; i < originalPartsSize; i++) { final String fromOriginal = originalParts.get(originalPartsSize - (i + 1)); final int replaceMentsIndex = replacedSize - (i + 1); final String fromReplacement = replaceMentsIndex > 0 ? replacedParts.get(replaceMentsIndex) : null; if (fromOriginal != null && fromOriginal.equals(fromReplacement)) { partsToKeepFromOriginal++; partsToTakeFromReplaced--; } } final List<String> returners = new ArrayList<String>(); if (partsToTakeFromReplaced > 0) { returners.addAll(replacedParts.subList(0, partsToTakeFromReplaced)); } if (partsToKeepFromOriginal > 0) { final int start = Math.max(0, labeledParts.size() - partsToKeepFromOriginal); final int end = start + partsToKeepFromOriginal - (originalPartsSize - labeledParts.size()); returners.addAll(labeledParts.subList(start, end)); } return StringUtils.join(returners, " > "); }
From source file:org.jahia.services.content.JCRContentUtils.java
@SuppressWarnings({ "unchecked", "rawtypes" }) public static List<Map<String, Object>> getRolesForNode(JCRNodeWrapper node, boolean includeInherited, boolean expandGroups, String roles, int limit, boolean latestFirst) { List<Map<String, Object>> results = new LinkedList<Map<String, Object>>(); Map<String, List<String[]>> entries = node.getAclEntries(); if (latestFirst) { entries = reverse(entries);//from www.j a v a2 s .co m } String siteKey = null; List<String> rolesList = Arrays.asList(StringUtils.splitByWholeSeparator(roles, null)); JahiaUserManagerService userService = ServicesRegistry.getInstance().getJahiaUserManagerService(); JahiaGroupManagerService groupService = ServicesRegistry.getInstance().getJahiaGroupManagerService(); for (Map.Entry<String, List<String[]>> entry : entries.entrySet()) { Map<String, Object> m = new HashMap<String, Object>(); String entryKey = entry.getKey(); if (siteKey == null) { try { JCRSiteNode resolveSite = node.getResolveSite(); siteKey = resolveSite != null ? resolveSite.getSiteKey() : null; } catch (RepositoryException e) { logger.error(e.getMessage(), e); } } if (entryKey.startsWith("u:")) { String name = StringUtils.substringAfter(entryKey, "u:"); JCRUserNode u = userService.lookupUser(name, siteKey); if (u == null) { logger.warn("User {} cannot be found. Skipping.", name); continue; } m.put("principalType", "user"); m.put("principal", u); } else if (entryKey.startsWith("g:")) { String name = StringUtils.substringAfter(entryKey, "g:"); JCRGroupNode g = groupService.lookupGroup(siteKey, name); if (g == null) { g = groupService.lookupGroup(null, name); } if (g == null) { logger.warn("Group {} cannot be found. Skipping.", name); continue; } m.put("principalType", "group"); m.put("principal", g); } for (String[] details : entry.getValue()) { if (details[1].equals("GRANT")) { if (!rolesList.isEmpty()) { if (!rolesList.contains(details[2])) { continue; } } if (!includeInherited) { if (!details[0].equals(node.getPath())) { continue; } } if (!m.containsKey("roles")) { m.put("roles", new LinkedList<String>()); results.add(m); } ((List) m.get("roles")).add(details[2]); } } if (limit > 0 && results.size() >= limit) { break; } } if (expandGroups) { List<Map<String, Object>> expandedResults = new LinkedList<Map<String, Object>>(); for (Map<String, Object> result : results) { if (result.get("principalType").equals("group")) { JCRGroupNode g = (JCRGroupNode) result.get("principal"); Set<JCRUserNode> principals = g.getRecursiveUserMembers(); for (JCRUserNode user : principals) { Map<String, Object> m = new HashMap<String, Object>(result); m.put("principalType", "user"); m.put("principal", user); expandedResults.add(m); } } else { expandedResults.add(result); } } results = expandedResults; } return results; }
From source file:org.jahia.services.content.rules.RulesListener.java
/** * Sets the configuration for rules to be disabled. The string format is as follows: * //from w w w . j a v a2 s . c o m * <pre> * ["<workspace>".]"<package-name-1>"."<rule-name-1>",["<workspace>".]"<package-name-2>"."<rule-name-2>"... * </pre> * * The workspace part is optional. For example the following configuration: * * <pre> * "org.jahia.modules.rules"."Image update","live"."org.jahia.modules.dm.thumbnails"."Automatically generate thumbnail for the document" * </pre> * * will disable rule <code>Image update</code> (from package <code>org.jahia.modules.rules</code>) in rules for all workspaces (live and * default) and the rule <code>Automatically generate thumbnail for the document</code> (package * <code>org.jahia.modules.dm.thumbnails</code>) will be disabled in rules for live workspace only. * * @param rulesToDisable the configuration for rules to be disabled */ public void setDisabledRules(String rulesToDisable) { if (StringUtils.isBlank(rulesToDisable)) { this.disabledRules = null; return; } // get rid of first and last double quotes // split between rules considering possible multiple whitespaces between them String[] disabledRulesConfig = StringUtils.strip(rulesToDisable, "\"").split("\"\\s*\\,\\s*\""); if (disabledRulesConfig == null) { this.disabledRules = null; return; } Map<String, Map<String, Set<String>>> disabledRulesFromConfig = new HashMap<>(); for (String ruleCfg : disabledRulesConfig) { // split configuration of a rule into tokens String[] cfg = StringUtils.splitByWholeSeparator(ruleCfg, "\".\""); // check if we've got a workspace part specified; if not use "null" as a workspace key String workspace = cfg.length == 3 ? cfg[0] : null; String pkg = cfg[workspace != null ? 1 : 0]; String rule = cfg[workspace != null ? 2 : 1]; Map<String, Set<String>> rulesForWorkspace = disabledRulesFromConfig.get(workspace); if (rulesForWorkspace == null) { rulesForWorkspace = new HashMap<>(); disabledRulesFromConfig.put(workspace, rulesForWorkspace); } Set<String> rulesForPackage = rulesForWorkspace.get(pkg); if (rulesForPackage == null) { rulesForPackage = new HashSet<>(); rulesForWorkspace.put(pkg, rulesForPackage); } rulesForPackage.add(rule); } disabledRules = disabledRulesFromConfig; logger.info("The following rules are configured to be disabled: {}", disabledRules); }
From source file:org.jahia.services.search.jcr.JahiaJCRSearchProvider.java
public Suggestion suggest(String originalQuery, String[] sites, RenderContext context, int maxTermsToSuggest) { if (StringUtils.isBlank(originalQuery)) { return null; }//from w w w . j a va2 s. c o m if (sites.length == 1 && sites[0].equals("-all-")) { List<String> sitesNames = JahiaSitesService.getInstance().getSitesNames(); sites = sitesNames.toArray(new String[sitesNames.size()]); } Locale locale = context.getMainResourceLocale(); Suggestion suggestion = null; JCRSessionWrapper session; try { session = ServicesRegistry.getInstance().getJCRStoreService().getSessionFactory() .getCurrentUserSession(context.getWorkspace(), locale); QueryManager qm = session.getWorkspace().getQueryManager(); StringBuilder xpath = new StringBuilder(64); xpath.append("/jcr:root[rep:spellcheck(") .append(stringToJCRSearchExp(originalQuery + CompositeSpellChecker.SEPARATOR_IN_SUGGESTION + CompositeSpellChecker.MAX_TERMS_PARAM + "=" + maxTermsToSuggest + CompositeSpellChecker.SEPARATOR_IN_SUGGESTION + CompositeSpellChecker.SITES_PARAM + "=" + StringUtils.join(sites, "*"))) .append(")"); if (locale != null) { xpath.append(" or @jcr:language='").append(locale).append("'"); } xpath.append("]"); xpath.append("/(rep:spellcheck())"); Query query = qm.createQuery(xpath.toString(), Query.XPATH); RowIterator rows = query.execute().getRows(); if (rows.hasNext()) { Row r = rows.nextRow(); Value v = r.getValue("rep:spellcheck()"); if (v != null) { String[] suggestions = StringUtils.splitByWholeSeparator(v.getString(), CompositeSpellChecker.SEPARATOR_IN_SUGGESTION); suggestion = new Suggestion(originalQuery, suggestions[0], Arrays.asList(suggestions)); } if (logger.isDebugEnabled()) { logger.debug("Making spell check suggestion for '" + originalQuery + "' site '" + Arrays.asList(sites) + "' and locale '" + locale + "' using XPath query [" + xpath.toString() + "]. Result suggestion: " + suggestion); } } } catch (RepositoryException e) { logger.error(e.getMessage(), e); } return suggestion; }
From source file:org.jamwiki.utils.Utilities.java
/** * Convert a delimited string to a list. * * @param delimitedString A string consisting of the delimited list items. * @param delimiter The string used as the delimiter. * @return A list consisting of the delimited string items, or <code>null</code> if the * string is <code>null</code> or empty. *//*from w w w. ja va 2 s . co m*/ public static List<String> delimitedStringToList(String delimitedString, String delimiter) { if (delimiter == null) { throw new IllegalArgumentException( "Attempt to call Utilities.delimitedStringToList with no delimiter specified"); } if (StringUtils.isBlank(delimitedString)) { return null; } return Arrays.asList(StringUtils.splitByWholeSeparator(delimitedString, delimiter)); }