List of usage examples for org.apache.commons.lang StringUtils stripToNull
public static String stripToNull(String str)
Strips whitespace from the start and end of a String returning null
if the String is empty ("") after the strip.
From source file:org.o3project.odenos.remoteobject.RemoteObject.java
/** * Event handler to dispatch Request which is posted from another * RemoteObject./*from www . j a v a 2 s .c o m*/ * * @param request * the posted Request * @return response to the RemoteObject */ public Response dispatchRequest(Request request) { log.debug("dispatchRequest: " + request.method + ", " + request.path); if (StringUtils.stripToNull(request.path) == null) { return new Response(Response.BAD_REQUEST, null); } RequestParser<IActionCallback>.ParsedRequest parsed = parser.parse(request); Response response = null; if (parsed == null) { response = onRequest(request); } else { IActionCallback callback = parsed.getResult(); if (callback == null) { return new Response(Response.BAD_REQUEST, null); } try { response = callback.process(parsed); } catch (Exception e) { log.error("Exception Request: " + request.method + ", " + request.path); response = new Response(Response.BAD_REQUEST, null); } } if (response == null) { response = new Response(Response.BAD_REQUEST, null); } return response; }
From source file:org.objectstyle.cayenne.dataview.DataView.java
private static Map childrenToMap(Element element) { List children = element.getChildren(); if (children.isEmpty()) return Collections.EMPTY_MAP; else {//from w ww . j a v a2s .c o m Map map = new HashMap(children.size()); for (Iterator i = children.iterator(); i.hasNext();) { Element child = (Element) i.next(); map.put(child.getName(), StringUtils.stripToNull(child.getText())); } return map; } }
From source file:org.sakaiproject.nakamura.api.search.solr.DomainObjectSearchQueryHandler.java
/** * Utility method to eliminate blank and pure-wildcard parameter values. */// w w w.j av a2 s .c o m public String getSearchParam(Map<String, String> parametersMap, String key) { String param = StringUtils.stripToNull(parametersMap.get(key)); // solr hates long sequences of asterisks, so compress repeated *'s to single * if (param != null) { param = TWO_OR_MORE_STARS.matcher(param).replaceAll("*"); } if ("*".equals(param) || "*:*".equals(param)) { return null; } else { return param; } }
From source file:org.sakaiproject.nakamura.api.search.solr.DomainObjectSearchQueryHandler.java
/** * Translate servlet request parameters into a properly escaped map. * TODO Refactor out of SolrSearchServlet for re-use. *//* w w w . j a v a 2 s.c om*/ public Map<String, String> loadParametersMap(SlingHttpServletRequest request) { Map<String, String> propertiesMap = new HashMap<String, String>(); // 0. load authorizable (user) information String userId = request.getRemoteUser(); propertiesMap.put(REQUEST_PARAMETERS_PROPS._userId.toString(), ClientUtils.escapeQueryChars(userId)); // Remember the requested path, since it sometimes determines the type of query or results handling. propertiesMap.put(REQUEST_PARAMETERS_PROPS._requestPath.toString(), request.getRequestURI()); // If a recursion level was specified for hierarchical results, pass it along. Integer traversalDepth = SearchUtil.getTraversalDepthSelector(request); if (traversalDepth != null) { propertiesMap.put(REQUEST_PARAMETERS_PROPS._traversalDepth.toString(), traversalDepth.toString()); } // 2. load in properties from the request RequestParameterMap params = request.getRequestParameterMap(); for (Map.Entry<String, RequestParameter[]> entry : params.entrySet()) { RequestParameter[] vals = entry.getValue(); String requestValue = vals[0].getString(); if (StringUtils.stripToNull(requestValue) != null) { String key = entry.getKey(); String val = SearchUtil.escapeString(requestValue, Query.SOLR); propertiesMap.put(key, val); } } return propertiesMap; }
From source file:org.sakaiproject.tool.gradebook.ui.ConfigurationBean.java
/** * @param name/*from w w w .ja va 2 s . c o m*/ * @return the bean configured to match the given plug-in key, or null if none were found */ public Object getPlugin(String key) { Object target = null; if (log.isDebugEnabled()) log.debug("key=" + key + ", serverConfigurationService=" + serverConfigurationService + ", default=" + pluginDefaults.get(key)); if (serverConfigurationService != null) { // As of Sakai 2.4, the framework's configuration service // returns the empty string instead of null if a property isn't found. target = StringUtils.stripToNull(serverConfigurationService.getString(key)); } if (target == null) { target = pluginDefaults.get(key); } if (target != null) { if (target instanceof String) { // Assume that we got a bean name instead of the // bean itself. target = applicationContext.getBean((String) target); } } if (log.isDebugEnabled()) log.debug("for " + key + " returning " + target); return target; }
From source file:rapture.pipeline2.gcp.PubsubPipeline2Handler.java
@Override public void subscribe(String queueIdentifier, final QueueSubscriber qsubscriber) { if (StringUtils.stripToNull(queueIdentifier) == null) { throw new RuntimeException("Null topic"); }/* ww w . jav a 2 s .co m*/ SubscriptionName subscriptionName = SubscriptionName.create(projectId, qsubscriber.getSubscriberId()); Topic topic = getTopic(queueIdentifier); Subscription subscription = subscriptions.get(subscriptionName); if (subscription == null) { try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) { try { subscription = subscriptionAdminClient.getSubscription(subscriptionName); } catch (Exception e) { if (subscription == null) { subscription = subscriptionAdminClient.createSubscription(subscriptionName, topic.getNameAsTopicName(), PushConfig.getDefaultInstance(), 0); subscriptions.put(subscriptionName, subscription); } } } catch (Exception ioe) { System.err.println(ExceptionToString.format(ioe)); } } try { MessageReceiver receiver = new MessageReceiver() { @Override public void receiveMessage(PubsubMessage message, AckReplyConsumer consumer) { System.out.println("Received " + message.getData().toStringUtf8()); if (qsubscriber.handleEvent(message.getData().toByteArray())) consumer.ack(); } }; Subscriber.Builder builder = Subscriber.defaultBuilder(subscriptionName, receiver); // The default executor provider creates an insane number of threads. if (executor != null) builder.setExecutorProvider(executor); Subscriber subscriber = builder.build(); subscriber.addListener(new Subscriber.Listener() { @Override public void failed(Subscriber.State from, Throwable failure) { // Subscriber encountered a fatal error and is shutting down. System.err.println(failure); } }, MoreExecutors.directExecutor()); subscriber.startAsync().awaitRunning(); subscribers.put(qsubscriber, subscriber); } catch (Exception e) { String error = String.format("Cannot subscribe to topic %s:\n%s", topic.getName(), ExceptionToString.format(e)); logger.error(error); throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_INTERNAL_ERROR, error, e); } logger.debug("Subscribed to " + queueIdentifier + " as " + qsubscriber.getSubscriberId()); }
From source file:rapture.repo.google.GoogleDatastoreKeyStore.java
@Override public void setConfig(Map<String, String> config) { kind = StringUtils.stripToNull(config.get("prefix")); if (kind == null) throw new RuntimeException("Prefix not set in config " + JacksonUtil.formattedJsonFromObject(config)); if (datastore == null) { if (testDatastoreOptions != null) { datastore = testDatastoreOptions.getService(); } else {//w w w.j a v a 2 s . c o m String projectId = StringUtils.trimToNull(config.get("projectid")); if (projectId == null) { projectId = MultiValueConfigLoader.getConfig("GOOGLE-projectid"); if (projectId == null) { throw new RuntimeException( "Project ID not set in RaptureGOOGLE.cfg or in config " + config); } } datastore = DatastoreOptions.newBuilder().setProjectId(projectId).build().getService(); } } this.config = config; }
From source file:rapture.repo.google.GoogleDatastoreKeyStore.java
@Override public List<RaptureFolderInfo> getSubKeys(String prefix) { // Must be a better way of doing this, but PropertyFilter.hasAncestor did not work. if ((StringUtils.stripToNull(prefix) != null) && !prefix.endsWith("/")) prefix = prefix + "/"; List<RaptureFolderInfo> list = new ArrayList<>(); Map<String, RaptureFolderInfo> map = new HashMap<>(); KeyQuery.Builder query = Query.newKeyQueryBuilder().setKind(kind); // if (StringUtils.stripToNull(prefix) != null) { // query.setFilter(PropertyFilter.hasAncestor(datastore.newKeyFactory().setKind(kind).newKey(prefix))); // }//from w w w. ja va2s . co m QueryResults<Key> result = datastore.run(query.build()); while (result.hasNext()) { Key peele = result.next(); String jordan = decode(peele.getName()); int l = prefix.length(); if (jordan.startsWith(prefix)) { while (jordan.charAt(l) == '/') { l++; } String keegan = jordan.substring(l); int idx = keegan.indexOf('/'); if (idx > 0) { list.add(new RaptureFolderInfo(keegan.substring(0, idx), true)); } else { list.add(new RaptureFolderInfo(keegan, false)); } } } list.addAll(map.values()); return list; }
From source file:rapture.repo.google.IdGenGoogleDatastore.java
@Override public void setConfig(Map<String, String> config) { kind = StringUtils.stripToNull(config.get("prefix")); if (kind == null) throw new RuntimeException("Prefix not set in config " + JacksonUtil.formattedJsonFromObject(config)); String projectId = StringUtils.trimToNull(config.get("projectid")); if (projectId == null) { projectId = MultiValueConfigLoader.getConfig("GOOGLE-projectid"); if (projectId == null) { throw new RuntimeException("Project ID not set in RaptureGOOGLE.cfg or in config " + config); }/*from www. j a v a 2s . c o m*/ } datastore = DatastoreOptions.newBuilder().setProjectId(projectId).build().getService(); this.config = config; makeValid(); }
From source file:ru.org.linux.site.Tags.java
public static ImmutableList<String> parseTags(String tags) throws UserErrorException { Set<String> tagSet = new HashSet<String>(); // ?? ?//from w w w . j a v a 2s.c o m tags = tags.replaceAll("\\|", ","); String[] tagsArr = tags.split(","); if (tagsArr.length == 0) { return ImmutableList.of(); } for (String aTagsArr : tagsArr) { String tag = StringUtils.stripToNull(aTagsArr.toLowerCase()); // - ? if (tag == null) { continue; } // : //, ??, ?, ? <> checkTag(tag); tagSet.add(tag); } return ImmutableList.copyOf(tagSet); }