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:gov.nih.nci.calims2.ui.util.springmvc.CustomDateTimeEditor.java
/** * {@inheritDoc}/*from w ww .j a v a2s . c om*/ */ public void setAsText(String text) { String dateTimeString = StringUtils.stripToNull(text); if (dateTimeString == null) { if (allowEmpty) { setValue(null); return; } throw new IllegalArgumentException("Empty dates not allowed"); } if (allowEmpty && dateTimeString != null) { setValue(null); } setValue(formatter.parseDateTime(dateTimeString).toDateTime()); }
From source file:gov.nih.nci.calims2.taglib.form.FileInputTag.java
/** * @param invalidMessage the invalidMessage to set *///from ww w.j a va 2 s. co m public void setInvalidMessage(String invalidMessage) { this.invalidMessage = StringUtils.stripToNull(invalidMessage); }
From source file:io.dfox.junit.http.api.Path.java
/** * Create a TestPath. If name is all whitespace, empty, or null, an empty Optional will be used. * //from www. ja v a2 s .c om * @param grouping The group the test belongs to. For JUnit tests, this is the test class name. * @param name The name of the test. For JUnit tests, this is the test method name. */ public Path(final String grouping, final String name) { this(grouping, Optional.ofNullable(StringUtils.stripToNull(name))); }
From source file:cascading.hcatalog.CascadingHCatUtil.java
/** * /*from w ww .j ava 2s . co m*/ * @param db * @param table * @param filter * @param jobConf * @return A list of locations */ public static List<String> getDataStorageLocation(String db, String table, String filter, JobConf jobConf) { Preconditions.checkNotNull(table, "Table name must not be null"); HiveMetaStoreClient client = null; List<String> locations = new ArrayList<String>(); try { client = getHiveMetaStoreClient(jobConf); Table hiveTable = HCatUtil.getTable(client, db, table); if (hiveTable.isPartitioned()) { List<Partition> parts = null; if (null != StringUtils.stripToNull(filter)) { parts = client.listPartitionsByFilter(db, table, filter, (short) -1); } else { parts = client.listPartitions(db, table, (short) -1); } if (parts.size() > 0) { // Return more than one partitions when filter is // something // like ds >= 1234 for (Partition part : parts) { locations.addAll(getFilesInHivePartition(part, jobConf)); } } else { logError( "Table " + hiveTable.getTableName() + " doesn't have the specified partition:" + filter, null); } } else { locations.add(hiveTable.getTTable().getSd().getLocation()); } } catch (IOException e) { logError("Error occured when getting hiveconf", e); } catch (MetaException e) { logError("Error occured when getting HiveMetaStoreClient", e); } catch (NoSuchObjectException e) { logError("Table doesn't exist in HCatalog: " + table, e); } catch (TException e) { logError("Error occured when getting Table", e); } finally { HCatUtil.closeHiveClientQuietly(client); } return locations; }
From source file:com.egt.core.db.util.InterpreteSqlPostgreSQL.java
@Override public String getComandoExecute(String comando, int argumentos, EnumTipoResultadoSQL tipoResultado) { boolean retornaResultadoCompuesto = EnumTipoResultadoSQL.COMPUESTO.equals(tipoResultado); String execute = StringUtils.stripToNull(comando); String command = retornaResultadoCompuesto ? COMANDO_EXECUTE_2 : COMANDO_EXECUTE_1; if (execute != null) { String[] token = StringUtils.split(execute); String parametros = "()"; if (argumentos > 0) { parametros = ""; for (int i = 0; i < argumentos; i++, parametros += ",?") { }//from w w w . j a v a 2 s.c o m parametros = "(" + parametros.substring(1) + ")"; } if (!token[0].equalsIgnoreCase(COMANDO_EXECUTE_1)) { execute = command + " " + execute; } if (!execute.endsWith(parametros) && !execute.endsWith(";")) { execute += parametros; } } return execute; }
From source file:com.adobe.acs.commons.replication.BrandPortalAgentFilter.java
public boolean isIncluded(Agent agent) { final String transportURI = agent.getConfiguration().getTransportURI(); for (final Resource config : brandPortalConfigs) { if (log.isDebugEnabled()) { log.debug(//from ww w.java 2 s .c o m "Checking Agent [ {} ] against Brand Portal cloud service config [ {} ] for property [ {} ]", agent.getId(), config.getPath(), PROP_TENTANT_URL); } final ValueMap properties = config.getValueMap(); final String tenantUrl = StringUtils.stripToNull(properties.get(PROP_TENTANT_URL, String.class)); if (StringUtils.isNotBlank(tenantUrl)) { boolean included = StringUtils.startsWith(transportURI, tenantUrl + "/"); if (included) { log.debug("Including replication agent [ {} ]", agent.getId()); return true; } } } return false; }
From source file:gov.nih.nci.calims2.taglib.form.FileInputTag.java
/** * @param promptKey the promptKey to set */ public void setPromptKey(String promptKey) { this.promptKey = StringUtils.stripToNull(promptKey); }
From source file:com.adobe.acs.tools.csv.impl.CsvUtil.java
/** * Adds a populated terminating field to the ends of CSV entries. * If the last entry in a CSV row is empty, the CSV library has difficulty understanding that is the end of the row. * * @param is the CSV file as an inputstream * @param separator The field separator//from www . j ava 2s. c o m * @param charset The charset * @return An inputstream that is the same as is, but each line has a populated line termination entry * @throws IOException */ public static InputStream terminateLines(final InputStream is, final char separator, final String charset) throws IOException { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final PrintStream printStream = new PrintStream(baos); final LineIterator lineIterator = IOUtils.lineIterator(is, charset); while (lineIterator.hasNext()) { String line = StringUtils.stripToNull(lineIterator.next()); if (line != null) { line += separator + TERMINATED; printStream.println(line); } } return new ByteArrayInputStream(baos.toByteArray()); }
From source file:com.opengamma.web.analytics.rest.ViewResource.java
@PUT @Path("pauseOrResume") public Response pauseOrResumeView(@FormParam("state") String state) { state = StringUtils.stripToNull(state); Response response = Response.status(Status.BAD_REQUEST).build(); if (state != null) { ViewClientState currentState = _viewClient.getState(); state = state.toUpperCase();/*from w w w. j ava 2 s .co m*/ switch (state) { case "PAUSE": case "P": if (currentState != ViewClientState.TERMINATED) { _viewClient.pause(); response = Response.ok().build(); } break; case "RESUME": case "R": if (currentState != ViewClientState.TERMINATED) { _viewClient.resume(); response = Response.ok().build(); } break; default: s_logger.warn("client {} requesting for invalid view client state change to {}", _viewId, state); response = Response.status(Status.BAD_REQUEST).build(); break; } } return response; }
From source file:com.activecq.api.ActiveProperties.java
/** * Uses reflection to create a List of the keys defined in the ActiveField subclass (and its inheritance tree). * Only fields that meet the following criteria are returned: * - public//w w w.j a v a 2 s . c o m * - static * - final * - String * - Upper case * @return a List of all the Fields */ @SuppressWarnings("unchecked") public List<String> getKeys() { ArrayList<String> keys = new ArrayList<String>(); ArrayList<String> names = new ArrayList<String>(); Class cls = this.getClass(); if (cls == null) { return Collections.unmodifiableList(keys); } Field fieldList[] = cls.getFields(); for (Field fld : fieldList) { int mod = fld.getModifiers(); // Only look at public static final fields if (!Modifier.isPublic(mod) || !Modifier.isStatic(mod) || !Modifier.isFinal(mod)) { continue; } // Only look at String fields if (!String.class.equals(fld.getType())) { continue; } // Only look at uppercase fields if (!StringUtils.equals(fld.getName().toUpperCase(), fld.getName())) { continue; } // Get the value of the field String value; try { value = StringUtils.stripToNull((String) fld.get(this)); } catch (IllegalArgumentException e) { continue; } catch (IllegalAccessException e) { continue; } // Do not add duplicate or null keys, or previously added named fields if (value == null || names.contains(fld.getName()) || keys.contains(value)) { continue; } // Success! Add key to key list keys.add(value); // Add field named to process field names list names.add(fld.getName()); } return Collections.unmodifiableList(keys); }