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:ips1ap101.lib.base.util.StrUtils.java
public static Object getObjeto(String string, Class<?> clazz) { if (string == null || clazz == null) { return null; }//from ww w. ja v a2 s . c o m try { String value = StringUtils.trimToNull(string); if (value == null) { return null; } else if (Character.class.isAssignableFrom(clazz)) { return new Character(value.charAt(0)); } else if (String.class.isAssignableFrom(clazz)) { // ALFANUMERICO return string; } else if (Boolean.class.isAssignableFrom(clazz)) { return BitUtils.valueOf(value); } else if (Byte.class.isAssignableFrom(clazz)) { return new Byte(new BigDecimal(value).byteValue()); } else if (Short.class.isAssignableFrom(clazz)) { return new Short(new BigDecimal(value).shortValue()); } else if (Integer.class.isAssignableFrom(clazz)) { // ENTERO return new Integer(new BigDecimal(value).intValue()); } else if (Long.class.isAssignableFrom(clazz)) { return new Long(new BigDecimal(value).longValue()); } else if (Float.class.isAssignableFrom(clazz)) { return new Float(new BigDecimal(value).floatValue()); } else if (Double.class.isAssignableFrom(clazz)) { return new Double(new BigDecimal(value).doubleValue()); } else if (BigInteger.class.isAssignableFrom(clazz)) { // ENTERO_GRANDE return new Long(new BigDecimal(value).longValue()); } else if (BigDecimal.class.isAssignableFrom(clazz)) { // NUMERICO return new BigDecimal(value); } else if (java.util.Date.class.isAssignableFrom(clazz)) { // FECHA_HORA java.util.Date dateTime = TimeUtils.parse(value); if (Timestamp.class.isAssignableFrom(clazz)) { return new Timestamp(dateTime.getTime()); } else if (Time.class.isAssignableFrom(clazz)) { return new Time(dateTime.getTime()); } else if (Date.class.isAssignableFrom(clazz)) { return new Date(dateTime.getTime()); } else { return dateTime; } } // } catch (NumberFormatException e) { // return null; } catch (RuntimeException e) { return null; } return null; }
From source file:com.manydesigns.portofino.pageactions.text.TextAction.java
@Button(list = "edit-content", key = "update", order = 1, type = Button.TYPE_PRIMARY) @RequiresPermissions(level = AccessLevel.VIEW, permissions = { PERMISSION_EDIT }) public Resolution updateContent() { title = context.getRequest().getParameter("title"); title = StringUtils.trimToNull(title); if (title == null) { SessionMessages.addErrorMessage(ElementsThreadLocals.getText("title.cannot.be.empty")); return new ForwardResolution("/m/text/edit-content.jsp"); }/*from w w w. j a va 2 s .co m*/ Page page = pageInstance.getPage(); page.setTitle(title); try { DispatcherLogic.savePage(pageInstance.getDirectory(), page); saveContent(); SessionMessages.addInfoMessage(ElementsThreadLocals.getText("object.updated.successfully")); } catch (Exception e) { logger.error("Could not save content for page " + pageInstance.getPath(), e); SessionMessages.addInfoMessage(ElementsThreadLocals.getText("update.failed")); } return cancel(); }
From source file:com.bluexml.xforms.controller.mapping.MappingToolCommon.java
/** * Gets the id.// w w w . ja v a 2 s. c o m * * @param node * the node * @return the id */ public String getId(Node node) { Element idElement = DOMUtil.getChild(node, MsgId.INT_INSTANCE_SIDEID.getText()); String id = null; if (idElement != null) { id = StringUtils.trimToNull(idElement.getTextContent()); } return id; }
From source file:eionet.web.action.VocabularyFoldersActionBean.java
public void setOldSitePrefix(String oldSitePrefix) { this.oldSitePrefix = StringUtils.trimToNull(oldSitePrefix); }
From source file:com.bluexml.xforms.controller.navigation.NavigationManager.java
/** * @param req// w w w . j a v a 2s . com * @return -1 if all files are loaded OK. 0 if an exception occurred. 1 if * failed at properties * files. 2 if failed at redirection file. * @throws IOException * @throws Exception */ private int loadConfiguration(HttpServletRequest req, boolean fromInitCall) { int result = -1; try { String formsPath = req.getParameter(MsgId.PARAM_PROPERTIES_FILE_FORMS.getText()); String msgPath = req.getParameter(MsgId.PARAM_PROPERTIES_FILE_MESSAGES.getText()); if (AlfrescoController.loadProperties(formsPath, msgPath) == false) { return 1; } String redirectPath = req.getParameter(MsgId.PARAM_REDIRECTOR_CONFIG_FILE.getText()); if (controller.loadRedirectionTable(redirectPath) == false) { result = 2; // continue anyway cause some projects may not use workflows } if (fromInitCall) { // we'll also deal with CSS, alfrescoHost this.setCssUrl(req); String host = req.getParameter(MsgId.PARAM_ALFRESCO_HOST.getText()); if (StringUtils.trimToNull(host) != null) { controller.setAlfrescoUrl(host); } } } catch (Exception e) { if (logger.isErrorEnabled()) { logger.error("Couldn't load all configuration files.", e); } return 0; } return result; }
From source file:com.opengamma.bbg.util.BloombergDataUtils.java
public static Set<ExternalId> getOptionChain(final ReferenceDataProvider refDataProvider, final String securityID) { ArgumentChecker.notNull(securityID, "security name"); final Set<ExternalId> result = new TreeSet<ExternalId>(); final FudgeMsg fieldData = refDataProvider .getReferenceData(Collections.singleton(securityID), Collections.singleton(FIELD_OPT_CHAIN)) .get(securityID);// w w w . ja v a 2 s . c o m if (fieldData == null) { s_logger.info("Reference data for security {} cannot be null", securityID); return null; } for (final FudgeField field : fieldData.getAllByName(FIELD_OPT_CHAIN)) { final FudgeMsg chainContainer = (FudgeMsg) field.getValue(); final String identifier = StringUtils.trimToNull(chainContainer.getString("Security Description")); if (identifier != null) { final ExternalId ticker = ExternalSchemes .bloombergTickerSecurityId(BloombergDataUtils.removeDuplicateWhiteSpace(identifier, " ")); result.add(ticker); } } return result; }
From source file:eionet.web.action.VocabularyFoldersActionBean.java
public void setNewSitePrefix(String newSitePrefix) { this.newSitePrefix = StringUtils.trimToNull(newSitePrefix); }
From source file:com.bluexml.xforms.controller.mapping.MappingToolFormsToAlfresco.java
/** * Collect fields. //$$ TRACE LOG//from w w w. jav a 2 s. c o m * * @param formName * the name of the current form, used for messages. * @param rootElt * the root element of the instance * @param formType * the form type * @param classType * the class type * @param alfClass * the GenericClass to be filled * @param isMassTagging * if <code>true</code>, only fields that have a value will end in the GenericClass */ private void collectFields(String formName, Element rootElt, List<FormFieldType> fields, GenericClass alfClass, Map<String, String> initParams, boolean isMassTagging) { for (FormFieldType fieldType : fields) { String uniqueName = fieldType.getUniqueName(); String alfrescoName = fieldType.getAlfrescoName(); Element fieldElement = DOMUtil.getChild(rootElt, uniqueName); if (fieldElement == null) { throw new RuntimeException("No DOM element was found in the instance for field: " + uniqueName + "' (" + alfrescoName + "). Probably another form has the same id as this one ('" + formName + "') or there's a bug in the XForms engine."); } // whether the attribute will make it into the genericClass object boolean gotValue = false; // GenericAttribute attribute = alfrescoObjectFactory.createGenericAttribute(); attribute.setQualifiedName(alfrescoName); String type = fieldType.getType(); String inputTextContent = fieldElement.getTextContent(); boolean readOnly = isReadOnly(fieldType); if (loggertrace.isTraceEnabled()) { logger.debug("Received value '" + inputTextContent + "' for attribute '" + alfrescoName + "' with type '" + type + "'. Read-only status '" + readOnly + "'. isFileField: " + (fieldType instanceof FileFieldType) + " . isServletRequest: N/A"); } // // convert the XForms field value to an attribute (possibly multiple) value if (isMultiple(fieldType)) { gotValue = convertXformsMultipleAttributeToAlfresco(attribute, inputTextContent, fieldElement, type, fieldType.getStaticEnumType(), initParams, isMassTagging); } else { if ((isMassTagging == false) || (isMassTagging && (StringUtils.trimToNull(inputTextContent) != null))) { String alfrescoValue = null; // if applicable, take the user format into account if (isAmendable(type, isReadOnly(fieldType), false)) { inputTextContent = getReadOnlyDateOrTimeModifiedValue(type, inputTextContent); } if (type.equals("DateTime")) { String date; String time; if (readOnly) { date = extractDateFromDateTimeModified(inputTextContent); time = extractTimeFromDateTimeModified(inputTextContent); } else { date = DOMUtil.getChild(fieldElement, "date").getTextContent(); time = DOMUtil.getChild(fieldElement, "time").getTextContent(); } alfrescoValue = getDateTimeFromDateAndTime(date, time); } else if (isSearchEnum(fieldType)) { alfrescoValue = DOMUtil.getChild(fieldElement, MsgId.INT_INSTANCE_SIDEID.getText()) .getTextContent(); } else if (isSelectionCapable(fieldType)) { alfrescoValue = DOMUtil .getElementInDescentByName(fieldElement, MsgId.INT_INSTANCE_SIDEID.getText()) .getTextContent(); } else { alfrescoValue = convertXformsAttributeToAlfresco(inputTextContent, type, fieldType.getStaticEnumType(), initParams, isMassTagging); } ValueType valueType = alfrescoObjectFactory.createValueType(); valueType.setValue(alfrescoValue); attribute.getValue().add(valueType); gotValue = true; } } // // mark FileFields with their destination. Useful for the webscript and for the upload // processing by the controller. if ((fieldType instanceof FileFieldType) && (isMassTagging == false)) { FileFieldType fileField = (FileFieldType) fieldType; String destination = isInRepository(fileField) ? MsgId.INT_UPLOAD_DEST_REPO.getText() : MsgId.INT_UPLOAD_DEST_FILE.getText(); attribute.setUploadTo(destination); // we need a name for the node (in case of upload to the repository) ValueType valueTypeNameAndExt = alfrescoObjectFactory.createValueType(); String nameAndExt = fieldElement.getAttribute("file"); valueTypeNameAndExt.setValue(nameAndExt); attribute.getValue().add(valueTypeNameAndExt); // we also want the MIME type; not needed but it won't hurt ValueType valueTypeMIME = alfrescoObjectFactory.createValueType(); String mimetype = fieldElement.getAttribute("type"); valueTypeMIME.setValue(mimetype); attribute.getValue().add(valueTypeMIME); } if ((isMassTagging == false) || (isMassTagging && gotValue)) { alfClass.getAttributes().getAttribute().add(attribute); } } // if applicable, append the implicit attribute that will keep info about the node content Element nodeContentElt = DOMUtil.getChild(rootElt, MsgId.INT_INSTANCE_SIDE_NODE_CONTENT.getText()); if ((isMassTagging == false) && (nodeContentElt != null)) { GenericAttribute contentAttr = alfrescoObjectFactory.createGenericAttribute(); contentAttr.setQualifiedName(MsgId.INT_INSTANCE_SIDE_NODE_CONTENT.getText()); contentAttr.setSkipMe("true"); // <-- this is MANDATORY! ValueType pathValue = alfrescoObjectFactory.createValueType(); ValueType nameValue = alfrescoObjectFactory.createValueType(); ValueType mimeValue = alfrescoObjectFactory.createValueType(); String path = nodeContentElt.getTextContent(); pathValue.setValue(path); String nameAndExt = nodeContentElt.getAttribute("file"); nameValue.setValue(nameAndExt); String mimetype = nodeContentElt.getAttribute("type"); mimeValue.setValue(mimetype); contentAttr.getValue().add(pathValue); contentAttr.getValue().add(nameValue); contentAttr.getValue().add(mimeValue); // append the attribute for content alfClass.getAttributes().getAttribute().add(contentAttr); } }
From source file:com.bluexml.xforms.controller.navigation.NavigationManager.java
/** * @param req/*www.java 2 s . c o m*/ */ private void setCssUrl(HttpServletRequest req) { String curCssUrl = StringUtils.trimToNull(req.getParameter(MsgId.PARAM_CSS_FILE.getText())); controller.setCssUrl(StringUtils.trimToNull(curCssUrl)); }