List of usage examples for org.apache.commons.lang StringUtils trimToNull
public static String trimToNull(String str)
Removes control characters (char <= 32) from both ends of this String returning null
if the String is empty ("") after the trim or if it is null
.
From source file:ch.entwine.weblounge.common.impl.request.RequestUtils.java
/** * Checks a parameter <code>parameter</code> is present in the url of the * request at the indicated position, starting with the action's mountpoint. * In this case, the parameter itself is returned, <code>null</code> * otherwise./*www. j av a 2s. c o m*/ * * @param request * the weblounge request * @param index * the parameter index * @return the parameter value or <code>null</code> if the parameter is not * available */ public static String getParameter(WebloungeRequest request, Action action, int index) { List<String> urlparams = getRequestedUrlParams(request, action); // Did we extract as many parameters as we should? if (index >= urlparams.size()) return null; String p = urlparams.get(index); try { p = decode(p, "utf-8"); } catch (UnsupportedEncodingException e) { logger.error("Encoding 'utf-8' is not supported on this platform"); } return StringUtils.trimToNull(p); }
From source file:adalid.commons.velocity.VelocityAid.java
/** * split a text into a list of lines./*ww w . j a v a 2s . c o m*/ * * @param string the text to split. * @param max the maximum line length. * @param separator the paragraph separator string. * @param separatorLine if true, the paragraph separator is added as a line between paragraphs. * @param prefix the new line prefix * @return the list of split. */ public static List<String> split(String string, int max, String separator, boolean separatorLine, String prefix) { List<String> strings = new ArrayList<>(); String str = StringUtils.trimToNull(string); if (str != null) { int maxLineLength, lineLength, wordLength, lastParagraph; String line, paragraph; String[] words, paragraphs; String sep = StringUtils.trimToNull(separator); String nlp = prefix == null ? "" : prefix; boolean sl = sep != null && separatorLine; paragraphs = sep == null ? new String[] { str } : StringUtils.splitByWholeSeparator(str, separator); lastParagraph = paragraphs.length - 1; for (int i = 0; i < paragraphs.length; i++) { // paragraph = paragraphs[i].trim(); paragraph = paragraphs[i].replaceAll(" +$", ""); // remove spaces at the end of the paragraph if (max > 0) { maxLineLength = max; if (paragraph.length() > maxLineLength) { line = ""; words = StringUtils.split(paragraph); for (String word : words) { lineLength = line.length(); wordLength = word.length() + 1; if (lineLength == 0) { line = word; } else if (lineLength + wordLength > maxLineLength) { strings.add(line); maxLineLength = max - nlp.length(); line = nlp + word; } else { line += " " + word; } } strings.add(line); } else { strings.add(paragraph); } } else { strings.add(paragraph); } if (sl && i < lastParagraph) { strings.add(sep); } } } return strings; }
From source file:ch.entwine.weblounge.contentrepository.impl.index.ContentRepositoryIndex.java
/** * Returns the identifier of the resource with uri <code>uri</code> or * <code>null</code> if the uri is not part of the index. * //w ww. j a va 2 s. co m * @param uri * the uri * @return the id * @throws IllegalArgumentException * if the uri does not contain a path * @throws ContentRepositoryException * if accessing the index fails */ public String getIdentifier(ResourceURI uri) throws ContentRepositoryException, IllegalArgumentException { if (uri.getIdentifier() != null) return uri.getIdentifier(); String path = StringUtils.trimToNull(uri.getPath()); if (path == null) throw new IllegalArgumentException("ResourceURI must contain a path"); // Load the identifier from the index SearchQuery q = new SearchQueryImpl(site).withPath(path); if (uri.getType() != null) q.withTypes(uri.getType()); SearchResultItem[] items = searchIdx.getByQuery(q).getItems(); if (items.length == 0) { logger.debug("Attempt to locate id for non-existing path {}", path); return null; } String id = (String) ((ResourceSearchResultItem) items[0]).getMetadataByKey(RESOURCE_ID).getValue(); uri.setIdentifier(id); return id; }
From source file:ch.entwine.weblounge.kernel.site.SiteDispatcherServiceImpl.java
/** * Configures this service using the given configuration properties. * // w w w.j av a 2 s .c om * @param config * the service configuration * @throws ConfigurationException * if configuration fails */ private boolean configure(Dictionary<?, ?> config) throws ConfigurationException { logger.debug("Configuring the site registration service"); boolean configurationChanged = true; // Activate precompilation? String precompileSetting = StringUtils.trimToNull((String) config.get(OPT_PRECOMPILE)); precompile = precompileSetting == null || ConfigurationUtils.isTrue(precompileSetting); logger.debug("Jsp precompilation {}", precompile ? "activated" : "deactivated"); // Log compilation errors? String logPrecompileErrors = StringUtils.trimToNull((String) config.get(OPT_PRECOMPILE_LOGGING)); logCompileErrors = logPrecompileErrors != null && ConfigurationUtils.isTrue(logPrecompileErrors); logger.debug("Precompilation errors will {} logged", logCompileErrors ? "be" : "not be"); // Store the jasper configuration keys Enumeration<?> keys = config.keys(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); if (key.startsWith(OPT_JASPER_PREFIX) && key.length() > OPT_JASPER_PREFIX.length()) { String value = (String) config.get(key); if (StringUtils.trimToNull(value) == null) continue; value = ConfigurationUtils.processTemplate(value); key = key.substring(OPT_JASPER_PREFIX.length()); boolean optionChanged = value.equalsIgnoreCase(jasperConfig.get(key)); configurationChanged |= !optionChanged; if (optionChanged) logger.debug("Jetty jsp parameter '{}' configured to '{}'", key, value); jasperConfig.put(key, value); // This is a work around for jasper's horrible implementation of the // compiler context configuration. Some keys are camel case, others are // lower case. jasperConfig.put(key.toLowerCase(), value); } } return configurationChanged; }
From source file:com.bluexml.xforms.generator.forms.Renderable.java
/** * Renders the element as nested into a div if the "appearance" property is set. The string * value of the property is the CSS class of the div. * /*from w w w. j a v a 2s. c o m*/ * @param rendered * the XML element of this field. WILL BE MODIFIED IF A STYLE IS DEFINED. */ protected void applyStyle(Rendered rendered, String style) { if (StringUtils.trimToNull(style) != null) { Element divStyle = XFormsGenerator.createElement("div", XFormsGenerator.NAMESPACE_XHTML); Element nestedElement = rendered.getXformsElement(); divStyle.setAttribute("class", style); divStyle.addContent(nestedElement); rendered.setXformsElement(divStyle); } }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopSearchField.java
protected void updateEditState() { Component editorComponent = comboBox.getEditor().getEditorComponent(); boolean value = required && isEditableWithParent() && isEnabledWithParent() && editorComponent instanceof JTextComponent && StringUtils.isEmpty(((JTextComponent) editorComponent).getText()); if (value) {//w w w .j av a 2 s .co m comboBox.setBackground(requiredBgColor); } else { comboBox.setBackground(defaultBgColor); if (editable && enabled) { if (editorComponent instanceof JTextComponent) { String inputText = StringUtils.trimToNull(((JTextComponent) editorComponent).getText()); if (prevValue == null) { String nullOptionText = null; if (nullOption != null) { nullOptionText = String.valueOf(nullOption); } if (StringUtils.isNotEmpty(inputText) && nullOption == null || !Objects.equals(nullOptionText, inputText)) { comboBox.setBackground(searchEditBgColor); } } else { String valueText = getDisplayString((Entity) prevValue); if (!Objects.equals(inputText, valueText)) { comboBox.setBackground(searchEditBgColor); } } } } } }
From source file:com.egt.core.aplicacion.web.GestorPaginaActualizacion.java
protected boolean isConsultaValida() { if (designing) { return true; }//from w w w. j ava 2 s. c o m this.track("isConsultaValida"); boolean ok = !this.isRestauracion() && this.getPaginaActualizacion().getRecursoDataProvider().isFuncionSelectAutorizada(); if (ok) { long f1 = this.getPaginaActualizacion().getRecursoDataProvider().getFuncionSelect(); long f2 = this.getPaginaActualizacion().getFuncionConsultarRecurso(); this.trace("funcion-actual=" + f1 + ", funcion-anterior=" + f2); ok = f1 == f2; } if (ok) { long v1 = this.getPaginaActualizacion().getRecursoDataProvider().getVersionComandoSelect(); long v2 = this.getPaginaActualizacion().getContextoSesion() .getVersionComandoSelectPagina(this.getClavePagina()); this.trace("version-actual=" + v1 + ", version-anterior=" + v2); ok = v1 == v2; } if (ok && this.isReinicio()) { String c1 = StringUtils .trimToNull(this.getPaginaActualizacion().getRecursoDataProvider().getCriteriosBusqueda()); String c2 = StringUtils .trimToNull(this.getPaginaActualizacion().getContextoPeticion().getCriteriosBusqueda()); this.trace("criterio-actual=" + c1 + ", criterio-anterior=" + c2); ok = c1 == null ? c2 == null : c1.equals(c2); } // if (ok && this.isPaginaConsultaConMaestro()) { // Long i1 = this.getIdentificacionRecursoMaestro(); // Long i2 = this.getPaginaActualizacion().getContextoSesion().getIdentificacionRecursoMaestroPagina(this.getClavePagina()); // this.trace("maestro-actual=" + i1 + ", maestro-anterior=" + i2); // ok = i1 == null ? i2 == null : i1.equals(i2); // } if (ok) { // String c1 = this.getColumnaIdentificacionRecursoMaestro(); String c1 = this.getPaginaActualizacion().getRecursoDataProvider().getColumnaMaestro(); String c2 = this.getPaginaActualizacion().getContextoSesion() .getColumnaIdentificacionRecursoMaestroPagina(this.getClavePagina()); this.trace("maestro-actual=" + c1 + ", maestro-anterior=" + c2); ok = c1 == null ? c2 == null : c1.equals(c2); } if (ok) { // Long i1 = this.getIdentificacionRecursoMaestro(); Long i1 = this.getPaginaActualizacion().getRecursoDataProvider().getIdentificacionMaestro(); Long i2 = this.getPaginaActualizacion().getContextoSesion() .getIdentificacionRecursoMaestroPagina(this.getClavePagina()); this.trace("maestro-actual=" + i1 + ", maestro-anterior=" + i2); ok = i1 == null ? i2 == null : i1.equals(i2); } return ok; }
From source file:com.egt.core.db.util.InterpreteSqlAbstracto.java
@Override public String getStringCriterioOrden(CriterioOrden criterio) { String columna = StringUtils.trimToNull(criterio.getColumna()); if (columna == null) { return null; }//from www.j av a 2 s . c o m if (EnumCriterioOrden.ORDEN_DESCENDENTE.equals(criterio.getOrden())) { return columna + " " + getDescending(); } else { // return columna + " " + getAscending(); return columna; } }
From source file:com.opengamma.examples.bloomberg.loader.ExampleEquityPortfolioLoader.java
protected Collection<ExternalId> readEquityTickers() { final Collection<ExternalId> result = new ArrayList<>(); final InputStream inputStream = ExampleEquityPortfolioLoader.class .getResourceAsStream("example-equity.csv"); try {/*from w w w. j a v a 2 s . c o m*/ if (inputStream != null) { final List<String> equityTickers = IOUtils.readLines(inputStream); for (String idStr : equityTickers) { idStr = StringUtils.trimToNull(idStr); if (idStr != null && !idStr.startsWith("#")) { result.add(ExternalSchemes.bloombergTickerSecurityId(idStr)); } } } else { throw new OpenGammaRuntimeException("File '" + EXAMPLE_EQUITY_FILE + "' could not be found"); } } catch (final IOException ex) { throw new OpenGammaRuntimeException( "An error occurred while reading file '" + EXAMPLE_EQUITY_FILE + "'"); } finally { IOUtils.closeQuietly(inputStream); } final StringBuilder sb = new StringBuilder(); sb.append("Parsed ").append(result.size()).append(" equities:\n"); for (final ExternalId equityId : result) { sb.append("\t").append(equityId.getValue()).append("\n"); } s_logger.info(sb.toString()); return result; }
From source file:com.bluexml.xforms.generator.forms.renderable.common.field.AbstractRenderableField.java
/** * Adds the hint, alert and help elements. Must be called after * {@link #applyConstraints(ModelElementBindSimple)} because of the lengths. * /*from www . j av a 2s .com*/ * @param input * the input */ protected void addHintAndMessages(Element input) { String hint = getHint(); if (StringUtils.trimToNull(hint) != null) { Element hintElement = XFormsGenerator.createElement("hint", XFormsGenerator.NAMESPACE_XFORMS); hintElement.setText(hint); input.addContent(hintElement); Element helpElement = XFormsGenerator.createElement("help", XFormsGenerator.NAMESPACE_XFORMS); helpElement.setText(hint); input.addContent(helpElement); } // deal with error message String errMsg = ""; if (isRequired()) { errMsg = MsgPool.getMsg(MsgId.MSG_FIELD_MANDATORY, getTitle()); } if (StringUtils.trimToNull(errMsg) != null) { errMsg += " "; } // get full message for the constraints of the field errMsg += getErrorMessage(); if (StringUtils.trimToNull(errMsg) != null) { Element alertElement = XFormsGenerator.createElement("alert", XFormsGenerator.NAMESPACE_XFORMS); alertElement.setText(errMsg); input.addContent(alertElement); } }