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:com.hmsinc.epicenter.webapp.EpiCenterController.java
@ModelAttribute("sldURL") public String getSldURL() { // This can come from JNDI, a properties file, or we can just ignore it and let the JS decide. String ret = ""; String override = StringUtils.trimToNull(geoServerSLDOverride); if (override.equals(".")) { if (applicationProperties.containsKey("geoserver.sld.override")) { override = applicationProperties.getProperty("geoserver.sld.override"); } else {// w ww .j a v a 2 s. c o m override = null; } } if (override != null) { ret = new StringBuilder("EpiCenter.GEOSERVER_SLD_OVERRIDE = \"").append(override).append("\";") .toString(); } return ret; }
From source file:com.opengamma.web.config.WebConfigResource.java
@PUT @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Produces(MediaType.TEXT_HTML)//from w ww . j av a 2s . c o m public Response putHTML(@FormParam("name") String name, @FormParam("configxml") String xml) { if (data().getConfig().isLatest() == false) { return Response.status(Status.FORBIDDEN).entity(getHTML()).build(); } name = StringUtils.trimToNull(name); xml = StringUtils.trimToNull(xml); if (name == null || xml == null) { final FlexiBean out = createRootData(); if (name == null) { out.put("err_nameMissing", true); } if (xml == null) { out.put("err_xmlMissing", true); } final String html = getFreemarker().build(HTML_DIR + "config-update.ftl", out); return Response.ok(html).build(); } Object parsed = parseXML(xml, data().getConfig().getConfig().getType()); final URI uri = updateConfig(name, parsed); return Response.seeOther(uri).build(); }
From source file:com.google.code.configprocessor.processing.AddAction.java
public String getFile() { return StringUtils.trimToNull(file); }
From source file:com.opengamma.web.portfolio.WebPortfolioNodeResource.java
@POST @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Produces(MediaType.APPLICATION_JSON)// ww w. j a va 2s . co m public Response postJSON(@FormParam("name") String name) { name = StringUtils.trimToNull(name); URI uri = createPortfolioNode(name); return Response.created(uri).build(); }
From source file:com.opengamma.master.region.impl.UnLocodeRegionFileReader.java
private Set<String> parseRequired() { InputStream stream = getClass().getResourceAsStream(LOAD_RESOURCE); if (stream == null) { throw new OpenGammaRuntimeException("Unable to find UnLocode.txt defining the UN/LOCODEs"); }/* w w w .jav a2 s . com*/ try { Set<String> lines = new HashSet<String>(IOUtils.readLines(stream, "UTF-8")); Set<String> required = new HashSet<String>(); for (String line : lines) { line = StringUtils.trimToNull(line); if (line != null) { required.add(line); } } return required; } catch (Exception ex) { throw new OpenGammaRuntimeException("Unable to read UnLocode.txt defining the UN/LOCODEs"); } finally { IOUtils.closeQuietly(stream); } }
From source file:eionet.meta.exports.json.VocabularyJSONOutputHelper.java
/** * Writes JSON to output stream.// www.j a v a 2 s. co m * <p> * NOTE: For readability purposes, nested blocks are used in this method while generating json contents. * </p> * * @param out * output stream * @param vocabulary * vocabulary base uri * @param concepts * list of vocabulary concepts * @param language * language for the preferred label * @throws java.io.IOException * if error in I/O */ public static void writeJSON(OutputStream out, VocabularyFolder vocabulary, List<VocabularyConcept> concepts, String language) throws IOException { OutputStreamWriter osw = new OutputStreamWriter(out, "UTF-8"); JsonFactory f = new JsonFactory(); JsonGenerator generator = f.createGenerator(out); generator.useDefaultPrettyPrinter(); language = StringUtils.trimToNull(language); boolean checkLanguage = StringUtils.isNotBlank(language); List<String> relationalDataElemIdentifiers = new ArrayList<String>(); relationalDataElemIdentifiers.add(BROADER); relationalDataElemIdentifiers.add(NARROWER); // start json object generator.writeStartObject(); // add context generator.writeObjectFieldStart(JSON_LD_CONTEXT); { generator.writeStringField(JSON_LD_BASE, VocabularyFolder.getBaseUri(vocabulary)); generator.writeStringField(VocabularyOutputHelper.LinkedDataNamespaces.SKOS, VocabularyOutputHelper.LinkedDataNamespaces.SKOS_NS); generator.writeStringField(JSON_LD_CONCEPTS, SKOS_CONCEPT); generator.writeStringField(PREF_LABEL, SKOS_PREF_LABEL); for (String dataElemShortIdentifier : relationalDataElemIdentifiers) { generator.writeStringField(dataElemShortIdentifier, DATA_ELEM_MAP.get(dataElemShortIdentifier)); } generator.writeStringField(JSON_LD_LANGUAGE, StringUtils.isNotBlank(language) ? language : DEFAULT_LANGUAGE); } generator.writeEndObject(); // start writing concepts... generator.writeArrayFieldStart(JSON_LD_CONCEPTS); // iterate on concepts for (VocabularyConcept concept : concepts) { generator.writeStartObject(); { generator.writeStringField(JSON_LD_ID, concept.getIdentifier()); generator.writeStringField(JSON_LD_TYPE, SKOS_CONCEPT); // start writing prefLabels generator.writeArrayFieldStart(PREF_LABEL); { String label; String labelLang; if (checkLanguage) { List<DataElement> dataElementValuesByNameAndLang = VocabularyOutputHelper .getDataElementValuesByNameAndLang(SKOS_PREF_LABEL, language, concept.getElementAttributes()); if (dataElementValuesByNameAndLang != null && dataElementValuesByNameAndLang.size() > 0) { label = dataElementValuesByNameAndLang.get(0).getAttributeValue(); labelLang = language; } else { dataElementValuesByNameAndLang = VocabularyOutputHelper .getDataElementValuesByNameAndLang(SKOS_PREF_LABEL, DEFAULT_LANGUAGE, concept.getElementAttributes()); if (dataElementValuesByNameAndLang != null && dataElementValuesByNameAndLang.size() > 0) { label = dataElementValuesByNameAndLang.get(0).getAttributeValue(); } else { label = concept.getLabel(); } labelLang = DEFAULT_LANGUAGE; } generator.writeStartObject(); { generator.writeStringField(JSON_LD_VALUE, label); generator.writeStringField(JSON_LD_LANGUAGE, labelLang); } generator.writeEndObject(); } else { generator.writeStartObject(); { generator.writeStringField(JSON_LD_VALUE, concept.getLabel()); generator.writeStringField(JSON_LD_LANGUAGE, DEFAULT_LANGUAGE); } generator.writeEndObject(); List<DataElement> dataElementValuesByName = VocabularyOutputHelper .getDataElementValuesByName(SKOS_PREF_LABEL, concept.getElementAttributes()); if (dataElementValuesByName != null && dataElementValuesByName.size() > 0) { for (DataElement elem : dataElementValuesByName) { generator.writeStartObject(); { generator.writeStringField(JSON_LD_VALUE, elem.getAttributeValue()); generator.writeStringField(JSON_LD_LANGUAGE, elem.getAttributeLanguage()); } generator.writeEndObject(); } } } } // end writing prefLabels generator.writeEndArray(); // write data elements for (String shortDataElemIdentifier : relationalDataElemIdentifiers) { // check if it has this element List<DataElement> dataElementValuesByName = VocabularyOutputHelper.getDataElementValuesByName( DATA_ELEM_MAP.get(shortDataElemIdentifier), concept.getElementAttributes()); if (dataElementValuesByName != null && dataElementValuesByName.size() > 0) { // start writing element values generator.writeArrayFieldStart(shortDataElemIdentifier); for (DataElement elem : dataElementValuesByName) { generator.writeStartObject(); { generator.writeStringField(JSON_LD_ID, elem.getRelatedConceptIdentifier()); } generator.writeEndObject(); } // end writing element values generator.writeEndArray(); } } } // end writing concept generator.writeEndObject(); } // end of iteration on concepts generator.writeEndArray(); // end of vocabulary name generator.writeEndObject(); // close writer and stream generator.close(); osw.close(); }
From source file:mitm.djigzo.web.pages.dkim.DKIMSettings.java
protected void onValidateForm() throws HierarchicalPropertiesException, WebServiceCheckedException { keyPair = StringUtils.trimToNull(keyPair); if (keyPair != null) { /*/*from w w w . j av a2 s . c o m*/ * Check if the keyPair is really a PEM encoded keypair */ PEMReader pem = new PEMReader(new StringReader(keyPair)); Object o = null; try { o = pem.readObject(); } catch (IOException e) { logKeyPairError("The input is not valid PEM encoded"); } if (o != null) { if (!(o instanceof KeyPair)) { String clazz = o.getClass().toString(); if (o instanceof PublicKey) { clazz = "public key"; } else if (o instanceof PrivateKey) { clazz = "private key"; } logKeyPairError("The input is not a valid key pair but is a " + clazz); } else { KeyPair keyPair = (KeyPair) o; if (keyPair.getPrivate() == null) { logKeyPairError("The private key is missing"); } else if (keyPair.getPublic() == null) { logKeyPairError("The public key is missing"); } } } else { logKeyPairError("The input does not contain a valid key pair"); } } else { logKeyPairError("The input does not contain a valid key pair"); } }
From source file:mitm.common.security.smime.SMIMEEncryptionAlgorithm.java
public static SMIMEEncryptionAlgorithm fromName(String name) { name = StringUtils.trimToNull(name); if (name != null) { for (SMIMEEncryptionAlgorithm algorithm : SMIMEEncryptionAlgorithm.values()) { if (algorithm.getName().equalsIgnoreCase(name)) { return algorithm; }// w w w. j av a 2s . c o m } } return null; }
From source file:com.opengamma.web.position.WebPositionResource.java
@PUT @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Produces(MediaType.APPLICATION_JSON)/*from www. j a va2s.c o m*/ public Response putJSON(@FormParam("quantity") String quantityStr, @FormParam("tradesJson") String tradesJson) { PositionDocument doc = data().getPosition(); if (doc.isLatest() == false) { return Response.status(Status.FORBIDDEN).entity(getHTML()).build(); } quantityStr = StringUtils.replace(StringUtils.trimToNull(quantityStr), ",", ""); tradesJson = StringUtils.trimToNull(tradesJson); Collection<ManageableTrade> trades = null; if (tradesJson != null) { trades = parseTrades(tradesJson); } else { trades = Collections.<ManageableTrade>emptyList(); } BigDecimal quantity = quantityStr != null && NumberUtils.isNumber(quantityStr) ? new BigDecimal(quantityStr) : null; updatePosition(doc, quantity, trades); return Response.ok().build(); }
From source file:com.bluexml.xforms.controller.alfresco.AlfrescoWebscriptException.java
private void analyzeError(Element exceptionElement) { Set<Entry<String, Element>> elements = getElements(exceptionElement).entrySet(); for (Entry<String, Element> entry : elements) { if (StringUtils.equals(entry.getKey(), "message")) { String message = entry.getValue().getTextContent(); ////w w w .j a v a2 s . c om if (StringUtils.containsIgnoreCase(message, "integrity violation")) { String assoName = getAssociationName(message, 0); // assoName should never trim to null ! if it is, algorithm problem! if (StringUtils.trimToNull(assoName) == null) { if (logger.isErrorEnabled()) { logger.error("Caught an unknown integrity violation: " + message); } sb = new StringBuilder(MsgPool.getMsg(MsgId.MSG_ERROR_DEFAULT_MSG)); } else { sb = new StringBuilder(MsgPool.getMsg(MsgId.MSG_ERROR_INTEGRITY_VIOLATION, assoName)); } gotCauseMessage = true; return; } // // if (message.contains("Unicity Checking Error")) { // sb = new StringBuilder(MsgPool.getMsg(MsgId.MSG_UNICITY_VIOLATION)); // gotCauseMessage = true; // return; // } // if (StringUtils.containsIgnoreCase(message, "access denied")) { sb = new StringBuilder(MsgPool.getMsg(MsgId.MSG_ERROR_ACCESS_DENIED)); gotCauseMessage = true; return; } errorMessage = message; sb.append(message); sb.append("\n\r"); } if (StringUtils.equals(entry.getKey(), "cause")) { Element exception = getElements(entry.getValue()).get("exception"); analyzeError(exception); } } }