List of usage examples for org.apache.commons.lang StringUtils substringAfter
public static String substringAfter(String str, String separator)
Gets the substring after the first occurrence of a separator.
From source file:nl.ucan.navigate.NestedPath.java
private NestedPath() { this.propertyInstance = new PropertyInstance() { public Object indexed(Object bean, String property, int index, Object value) { log.info("created indexed property " + property + " at " + index + " of bean " + bean + " and will be set to " + value); return value; }// w w w . j a v a 2s. com public Object simple(Object bean, String property, Object value) { log.info("created simple property " + property + " of bean " + bean + " and will be set to " + value); return value; } }; this.propertyValue = new PropertyValue() { public Object indexed(Object bean, String property, int index, Object value) { log.info("value of indexed property " + property + " at " + index + " of bean " + bean + " will be set to " + value); return value; } public Object mapped(Object bean, String property, Object key, Object value) { log.info("value of mapped property " + property + " at " + key + " of bean " + bean + " will be set to " + value); return value; } public Object simple(Object bean, String property, Object value) { log.info("value of simple property " + property + " of bean " + bean + " will be set to " + value); return value; } public Object valueOf(Class clasz, String property, String value) { log.info("value of valueOf " + property + " will be set to " + value); return value; } }; this.indexPointer = new IndexPointer() { public int size(Object bean) { return CollectionUtils.size(bean); } public Object get(Object bean, int idx) { return CollectionUtils.get(bean, idx); } public int firstIndexOf(Object bean, String undeterminedIndex) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, InstantiationException, IntrospectionException { this.setUndeterminedIndex(undeterminedIndex); for (int idx = 0; idx < size(bean); idx++) { Object object = get(bean, idx); if (object != null) { if (evaluate(object, this.getUndeterminedIndex())) return idx; } } return -1; } public void setIndexAsProperty(Object bean, String undeterminedIndex) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, InstantiationException, IntrospectionException { this.setUndeterminedIndex(undeterminedIndex); Object value = propertyValue.simple(bean, this.getProperty(), this.getValue()); pub.setProperty(bean, this.getProperty(), value); } private String undeterminedIndex; private void setUndeterminedIndex(String undeterminedIndex) { this.undeterminedIndex = undeterminedIndex; } private String getUndeterminedIndex() { return this.undeterminedIndex; } private boolean evaluate(Object bean, String undeterminedIndex) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, InstantiationException, IntrospectionException { this.setUndeterminedIndex(undeterminedIndex); String property = getProperty(); String valueOfIndex = getValue(); Object valueOfBean = pub.getProperty(bean, property); return ObjectUtils.equals(valueOfIndex, valueOfBean); } private String getProperty() { Map.Entry<String, String> entry = getNamedIndex(this.getUndeterminedIndex()); return entry.getKey(); } private String getValue() { Map.Entry<String, String> entry = getNamedIndex(this.getUndeterminedIndex()); return entry.getValue(); } private Map.Entry<String, String> getNamedIndex(String value) { final String SEP = "="; Map<String, String> keyValuePair = new HashMap<String, String>(); if (StringUtils.indexOf(value, SEP) == -1) return null; keyValuePair.put(StringUtils.substringBefore(value, SEP), StringUtils.substringAfter(value, SEP)); return keyValuePair.entrySet().iterator().next(); } }; this.pub = BeanUtilsBean.getInstance().getPropertyUtils(); this.pub.setResolver(new ResolverImpl()); }
From source file:no.freecode.translator.business.MessageImporter.java
/** * @param basename/*www . jav a 2 s . c o m*/ * e.g. "messages_nb_NO.properties", "messages_nb.properties" or * "messages.properties" (default/base locale). * @return */ private static MessageLocale getLocale(String filename) { String basename = FilenameUtils.getBaseName(filename); String localeString = StringUtils.substringAfter(basename, "_"); // --> e.g "nb" or "nb_NO" String name = StringUtils.defaultIfEmpty(localeString, ""); MessageLocale locale = MessageLocale.findMessageLocaleByName(name); if (locale == null) { locale = new MessageLocale(); locale.setName(name); } // MessageLocale locale = new MessageLocale(); // locale.setName(StringUtils.defaultIfEmpty(localeString, "")); return locale; }
From source file:opennlp.tools.similarity.apps.solr.SearchResultsReRankerRequestHandler.java
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) { // get query string String requestExpression = req.getParamString(); String[] exprParts = requestExpression.split("&"); for (String part : exprParts) { if (part.startsWith("q=")) requestExpression = part;/*from ww w. java 2s. c o m*/ } String query = StringUtils.substringAfter(requestExpression, ":"); LOG.info(requestExpression); SolrParams ps = req.getOriginalParams(); Iterator<String> iter = ps.getParameterNamesIterator(); List<String> keys = new ArrayList<String>(); while (iter.hasNext()) { keys.add(iter.next()); } List<HitBase> searchResults = new ArrayList<HitBase>(); for (Integer i = 0; i < MAX_SEARCH_RESULTS; i++) { String title = req.getParams().get("t" + i.toString()); String descr = req.getParams().get("d" + i.toString()); if (title == null || descr == null) continue; HitBase hit = new HitBase(); hit.setTitle(title); hit.setAbstractText(descr); hit.setSource(i.toString()); searchResults.add(hit); } /* * http://173.255.254.250:8983/solr/collection1/reranker/? * q=search_keywords:design+iphone+cases&fields=spend+a+day+with+a+custom+iPhone+case&fields=Add+style+to+your+every+day+fresh+design+with+a+custom+iPhone+case&fields=Add+style+to+your+every+day+with+mobile+case+for+your+family&fields=Add+style+to+your+iPhone+and+iPad&fields=Add+Apple+fashion+to+your+iPhone+and+iPad * */ if (searchResults.size() < 1) { int count = 0; for (String val : exprParts) { if (val.startsWith("fields=")) { val = StringUtils.mid(val, 7, val.length()); HitBase hit = new HitBase(); hit.setTitle(""); hit.setAbstractText(val); hit.setSource(new Integer(count).toString()); searchResults.add(hit); count++; } } } List<HitBase> reRankedResults = null; query = query.replace('+', ' '); if (tooFewKeywords(query) || orQuery(query)) { reRankedResults = searchResults; LOG.info("No re-ranking for " + query); } else reRankedResults = calculateMatchScoreResortHits(searchResults, query); /* * <scores> <score index="2">3.0005</score> <score index="1">2.101</score> <score index="3">2.1003333333333334</score> <score index="4">2.00025</score> <score index="5">1.1002</score> </scores> * * */ StringBuffer buf = new StringBuffer(); buf.append("<scores>"); for (HitBase hit : reRankedResults) { buf.append("<score index=\"" + hit.getSource() + "\">" + hit.getGenerWithQueryScore() + "</score>"); } buf.append("</scores>"); NamedList<Object> scoreNum = new NamedList<Object>(); for (HitBase hit : reRankedResults) { scoreNum.add(hit.getSource(), hit.getGenerWithQueryScore()); } StringBuffer bufNums = new StringBuffer(); bufNums.append("order>"); for (HitBase hit : reRankedResults) { bufNums.append(hit.getSource() + "_"); } bufNums.append("/order>"); LOG.info("re-ranking results: " + buf.toString()); NamedList<Object> values = rsp.getValues(); values.remove("response"); values.add("response", scoreNum); //values.add("new_order", bufNums.toString().trim()); rsp.setAllValues(values); }
From source file:opennlp.tools.similarity.apps.solr.SearchResultsReRankerStanfRequestHandler.java
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) { // get query string String requestExpression = req.getParamString(); String[] exprParts = requestExpression.split("&"); for (String part : exprParts) { if (part.startsWith("q=")) requestExpression = part;//from ww w. ja v a 2 s .c o m } String query = StringUtils.substringAfter(requestExpression, ":"); LOG.info(requestExpression); SolrParams ps = req.getOriginalParams(); Iterator<String> iter = ps.getParameterNamesIterator(); List<String> keys = new ArrayList<String>(); while (iter.hasNext()) { keys.add(iter.next()); } List<HitBase> searchResults = new ArrayList<HitBase>(); for (Integer i = 0; i < MAX_SEARCH_RESULTS; i++) { String title = req.getParams().get("t" + i.toString()); String descr = req.getParams().get("d" + i.toString()); if (title == null || descr == null) continue; HitBase hit = new HitBase(); hit.setTitle(title); hit.setAbstractText(descr); hit.setSource(i.toString()); searchResults.add(hit); } /* * http://173.255.254.250:8983/solr/collection1/reranker/? * q=search_keywords:design+iphone+cases&fields=spend+a+day+with+a+ * custom+iPhone+case&fields=Add+style+to+your+every+day+fresh+design+ * with+a+custom+iPhone+case&fields=Add+style+to+your+every+day+with+ * mobile+case+for+your+family&fields=Add+style+to+your+iPhone+and+iPad& * fields=Add+Apple+fashion+to+your+iPhone+and+iPad * */ if (searchResults.size() < 1) { int count = 0; for (String val : exprParts) { if (val.startsWith("fields=")) { val = StringUtils.mid(val, 7, val.length()); HitBase hit = new HitBase(); hit.setTitle(""); hit.setAbstractText(val); hit.setSource(new Integer(count).toString()); searchResults.add(hit); count++; } } } List<HitBase> reRankedResults = null; query = query.replace('+', ' '); if (tooFewKeywords(query) || orQuery(query)) { reRankedResults = searchResults; LOG.info("No re-ranking for " + query); } else reRankedResults = calculateMatchScoreResortHits(searchResults, query); /* * <scores> <score index="2">3.0005</score> <score * index="1">2.101</score> <score index="3">2.1003333333333334</score> * <score index="4">2.00025</score> <score index="5">1.1002</score> * </scores> * * */ StringBuffer buf = new StringBuffer(); buf.append("<scores>"); for (HitBase hit : reRankedResults) { buf.append("<score index=\"" + hit.getSource() + "\">" + hit.getGenerWithQueryScore() + "</score>"); } buf.append("</scores>"); NamedList<Object> scoreNum = new NamedList<Object>(); for (HitBase hit : reRankedResults) { scoreNum.add(hit.getSource(), hit.getGenerWithQueryScore()); } StringBuffer bufNums = new StringBuffer(); bufNums.append("order>"); for (HitBase hit : reRankedResults) { bufNums.append(hit.getSource() + "_"); } bufNums.append("/order>"); LOG.info("re-ranking results: " + buf.toString()); NamedList<Object> values = rsp.getValues(); values.remove("response"); values.add("response", scoreNum); values.add("new_order", bufNums.toString().trim()); rsp.setAllValues(values); }
From source file:org.adaptto.rookie.demo.models.TagSearchController.java
@SuppressWarnings("unchecked") public TagSearchController(SlingHttpServletRequest request) { Resource resource = request.getResource(); ResourceResolver resolver = request.getResourceResolver(); // get tag name to search for form suffix String suffix = request.getRequestPathInfo().getSuffix(); this.tag = StringUtils.substringAfter(suffix, "/"); // execute JCR query via Sling API String xpathQuery = "/jcr:root" + resource.getPath() + "//*[tags='" + this.tag + "']"; this.result = IteratorUtils.toList(resolver.findResources(xpathQuery, "xpath")); }
From source file:org.agric.oxm.utils.JpaUtils.java
/** * Gets a Path from Path using property path * /*from ww w . jav a 2 s . c o m*/ * @param path * the base path * @param propertyPath * property path String like "customer.order.price" * @return a new Path for property */ public static Path<?> getPath(Path<?> path, String propertyPath) { if (StringUtils.isEmpty(propertyPath)) return path; String name = StringUtils.substringBefore(propertyPath, PropertyUtils.PROPERTY_SEPARATOR); Path<?> p = path.get(name); return getPath(p, StringUtils.substringAfter(propertyPath, PropertyUtils.PROPERTY_SEPARATOR)); }
From source file:org.alfresco.repo.security.authentication.ResetPasswordServiceImplTest.java
public static Pair<String, String> getWorkflowIdAndKeyFromUrl(String url) { //url example: http://localhost:8081/share/page/reset-password?key=164e37bf-2590-414e-94db-8b8cfe5be790&id=activiti$156 assertNotNull(url);//from w ww . j a va 2 s. c o m String id = StringUtils.trimToNull(StringUtils.substringAfter(url, "id=")); String key = StringUtils.substringBetween(url, "key=", "&id="); Pair<String, String> pair = new Pair<>(id, key); return pair; }
From source file:org.apache.any23.extractor.html.HCardExtractor.java
private void fixIncludes(HTMLDocument document, Node node, IssueReport report) { NamedNodeMap attributes = node.getAttributes(); // header case test 32 if ("TD".equals(node.getNodeName()) && (null != attributes.getNamedItem("headers"))) { String id = attributes.getNamedItem("headers").getNodeValue(); Node header = document.findNodeById(id); if (null != header) { node.appendChild(header.cloneNode(true)); attributes.removeNamedItem("headers"); }/* w w w .ja v a 2 s . c o m*/ } // include pattern, test 31 for (Node current : DomUtils.findAllByAttributeName(document.getDocument(), "class")) { if (!DomUtils.hasClassName(current, "include")) continue; // we have to remove the field soon to avoid infinite loops // no null check, we know it's there or we won't be in the loop current.getAttributes().removeNamedItem("class"); ArrayList<TextField> res = new ArrayList<TextField>(); HTMLDocument.readUrlField(res, current); TextField id = res.get(0); if (null == id) continue; TextField refId = new TextField(StringUtils.substringAfter(id.value(), "#"), id.source()); Node included = document.findNodeById(refId.value()); if (null == included) continue; if (DomUtils.isAncestorOf(included, current)) { final int[] nodeLocation = DomUtils.getNodeLocation(current); report.notifyIssue(IssueReport.IssueLevel.Warning, "Current node tries to include an ancestor node.", nodeLocation[0], nodeLocation[1]); continue; } current.appendChild(included.cloneNode(true)); } }
From source file:org.apache.archiva.admin.repository.runtime.DefaultRedbackRuntimeConfigurationAdmin.java
@PostConstruct @Override//from www . ja va 2 s .c om public void initialize() throws UserConfigurationException { try { RedbackRuntimeConfiguration redbackRuntimeConfiguration = getRedbackRuntimeConfiguration(); // migrate or not data from redback if (!redbackRuntimeConfiguration.isMigratedFromRedbackConfiguration()) { // not migrated so build a new fresh one redbackRuntimeConfiguration = new RedbackRuntimeConfiguration(); // so migrate if available String userManagerImpl = userConfiguration.getConcatenatedList( UserConfigurationKeys.USER_MANAGER_IMPL, // DEFAULT_USER_MANAGER_IMPL); if (StringUtils.isNotEmpty(userManagerImpl)) { String[] impls = StringUtils.split(userManagerImpl, ','); for (String impl : impls) { redbackRuntimeConfiguration.getUserManagerImpls().add(impl); } } else { redbackRuntimeConfiguration.getUserManagerImpls().add(DEFAULT_USER_MANAGER_IMPL); } String rbacManagerImpls = userConfiguration.getConcatenatedList( UserConfigurationKeys.RBAC_MANAGER_IMPL, // DEFAULT_RBAC_MANAGER_IMPL); if (StringUtils.isNotEmpty(rbacManagerImpls)) { String[] impls = StringUtils.split(rbacManagerImpls, ','); for (String impl : impls) { redbackRuntimeConfiguration.getRbacManagerImpls().add(impl); } } else { redbackRuntimeConfiguration.getRbacManagerImpls().add(DEFAULT_RBAC_MANAGER_IMPL); } // now ldap LdapConfiguration ldapConfiguration = redbackRuntimeConfiguration.getLdapConfiguration(); if (ldapConfiguration == null) { ldapConfiguration = new LdapConfiguration(); redbackRuntimeConfiguration.setLdapConfiguration(ldapConfiguration); } ldapConfiguration .setHostName(userConfiguration.getString(UserConfigurationKeys.LDAP_HOSTNAME, null)); ldapConfiguration.setPort(userConfiguration.getInt(UserConfigurationKeys.LDAP_PORT, -1)); ldapConfiguration.setSsl(userConfiguration.getBoolean(UserConfigurationKeys.LDAP_SSL, false)); ldapConfiguration .setBaseDn(userConfiguration.getConcatenatedList(UserConfigurationKeys.LDAP_BASEDN, null)); ldapConfiguration.setBaseGroupsDn(userConfiguration.getConcatenatedList( UserConfigurationKeys.LDAP_GROUPS_BASEDN, ldapConfiguration.getBaseDn())); ldapConfiguration .setContextFactory(userConfiguration.getString(UserConfigurationKeys.LDAP_CONTEX_FACTORY, isSunContextFactoryAvailable() ? "com.sun.jndi.ldap.LdapCtxFactory" : "")); ldapConfiguration .setBindDn(userConfiguration.getConcatenatedList(UserConfigurationKeys.LDAP_BINDDN, null)); ldapConfiguration .setPassword(userConfiguration.getString(UserConfigurationKeys.LDAP_PASSWORD, null)); ldapConfiguration.setAuthenticationMethod( userConfiguration.getString(UserConfigurationKeys.LDAP_AUTHENTICATION_METHOD, null)); ldapConfiguration .setWritable(userConfiguration.getBoolean(UserConfigurationKeys.LDAP_WRITABLE, false)); ldapConfiguration.setUseRoleNameAsGroup( userConfiguration.getBoolean(UserConfigurationKeys.LDAP_GROUPS_USE_ROLENAME, false)); boolean ldapBindAuthenticatorEnabled = userConfiguration .getBoolean(UserConfigurationKeys.LDAP_BIND_AUTHENTICATOR_ENABLED, false); ldapConfiguration.setBindAuthenticatorEnabled(ldapBindAuthenticatorEnabled); // LDAP groups mapping reading !! // UserConfigurationKeys.LDAP_GROUPS_ROLE_START_KEY // userConfiguration.getKeys() Collection<String> keys = userConfiguration.getKeys(); List<LdapGroupMapping> ldapGroupMappings = new ArrayList<>(); for (String key : keys) { if (key.startsWith(UserConfigurationKeys.LDAP_GROUPS_ROLE_START_KEY)) { String group = StringUtils.substringAfter(key, UserConfigurationKeys.LDAP_GROUPS_ROLE_START_KEY); String val = userConfiguration.getConcatenatedList(key, ""); if (!StringUtils.isEmpty(val)) { String[] roles = StringUtils.split(val, ','); ldapGroupMappings.add(new LdapGroupMapping(group, roles)); } } } redbackRuntimeConfiguration.setLdapGroupMappings(ldapGroupMappings); redbackRuntimeConfiguration.setMigratedFromRedbackConfiguration(true); updateRedbackRuntimeConfiguration(redbackRuntimeConfiguration); } // we must ensure userManagerImpls list is not empty if so put at least jdo one ! if (redbackRuntimeConfiguration.getUserManagerImpls().isEmpty()) { log.info( "redbackRuntimeConfiguration with empty userManagerImpls so force at least jdo implementation !"); redbackRuntimeConfiguration.getUserManagerImpls().add("jdo"); updateRedbackRuntimeConfiguration(redbackRuntimeConfiguration); } else { log.info("using userManagerImpls: {}", redbackRuntimeConfiguration.getUserManagerImpls()); } // we ensure rbacManagerImpls is not empty if so put at least cached if (redbackRuntimeConfiguration.getRbacManagerImpls().isEmpty()) { log.info( "redbackRuntimeConfiguration with empty rbacManagerImpls so force at least cached implementation !"); redbackRuntimeConfiguration.getRbacManagerImpls().add("cached"); updateRedbackRuntimeConfiguration(redbackRuntimeConfiguration); } else { log.info("using rbacManagerImpls: {}", redbackRuntimeConfiguration.getRbacManagerImpls()); } boolean save = false; // NPE free if (redbackRuntimeConfiguration.getUsersCacheConfiguration() == null) { redbackRuntimeConfiguration.setUsersCacheConfiguration(new CacheConfiguration()); } // if -1 it means non initialized to take values from the spring bean if (redbackRuntimeConfiguration.getUsersCacheConfiguration().getTimeToIdleSeconds() < 0) { redbackRuntimeConfiguration.getUsersCacheConfiguration() .setTimeToIdleSeconds(usersCache.getTimeToIdleSeconds()); save = true; } usersCache.setTimeToIdleSeconds( redbackRuntimeConfiguration.getUsersCacheConfiguration().getTimeToIdleSeconds()); if (redbackRuntimeConfiguration.getUsersCacheConfiguration().getTimeToLiveSeconds() < 0) { redbackRuntimeConfiguration.getUsersCacheConfiguration() .setTimeToLiveSeconds(usersCache.getTimeToLiveSeconds()); save = true; } usersCache.setTimeToLiveSeconds( redbackRuntimeConfiguration.getUsersCacheConfiguration().getTimeToLiveSeconds()); if (redbackRuntimeConfiguration.getUsersCacheConfiguration().getMaxElementsInMemory() < 0) { redbackRuntimeConfiguration.getUsersCacheConfiguration() .setMaxElementsInMemory(usersCache.getMaxElementsInMemory()); save = true; } usersCache.setMaxElementsInMemory( redbackRuntimeConfiguration.getUsersCacheConfiguration().getMaxElementsInMemory()); if (redbackRuntimeConfiguration.getUsersCacheConfiguration().getMaxElementsOnDisk() < 0) { redbackRuntimeConfiguration.getUsersCacheConfiguration() .setMaxElementsOnDisk(usersCache.getMaxElementsOnDisk()); save = true; } usersCache.setMaxElementsOnDisk( redbackRuntimeConfiguration.getUsersCacheConfiguration().getMaxElementsOnDisk()); if (save) { updateRedbackRuntimeConfiguration(redbackRuntimeConfiguration); } } catch (RepositoryAdminException e) { throw new UserConfigurationException(e.getMessage(), e); } }
From source file:org.apache.archiva.admin.repository.runtime.DefaultRedbackRuntimeConfigurationAdmin.java
@Override public String getString(String key) { if (UserConfigurationKeys.USER_MANAGER_IMPL.equals(key)) { // possible false for others than archiva user manager return getRedbackRuntimeConfiguration().getUserManagerImpls().get(0); }// ww w . j a v a 2 s . c om if (StringUtils.startsWith(key, UserConfigurationKeys.LDAP_GROUPS_ROLE_START_KEY)) { RedbackRuntimeConfiguration redbackRuntimeConfiguration = getRedbackRuntimeConfiguration(); int index = redbackRuntimeConfiguration.getLdapGroupMappings().indexOf(new LdapGroupMapping( StringUtils.substringAfter(key, UserConfigurationKeys.LDAP_GROUPS_ROLE_START_KEY))); if (index > -1) { return StringUtils .join(redbackRuntimeConfiguration.getLdapGroupMappings().get(index).getRoleNames(), ','); } } RedbackRuntimeConfiguration conf = getRedbackRuntimeConfiguration(); if (conf.getConfigurationProperties().containsKey(key)) { return conf.getConfigurationProperties().get(key); } String value = userConfiguration.getString(key); if (value == null) { return null; } conf.getConfigurationProperties().put(key, value); try { updateRedbackRuntimeConfiguration(conf); } catch (RepositoryAdminException e) { log.error("fail to save RedbackRuntimeConfiguration: {}", e.getMessage(), e); throw new RuntimeException(e.getMessage(), e); } return value; }