List of usage examples for org.apache.commons.lang StringUtils stripToEmpty
public static String stripToEmpty(String str)
Strips whitespace from the start and end of a String returning an empty String if null
input.
From source file:org.dishevelled.commandline.argument.IntegerSetArgument.java
/** {@inheritDoc} */ protected Set<Integer> convert(final String s) throws Exception { Set<Integer> set = new HashSet<Integer>(); StringTokenizer st = new StringTokenizer(s, ","); while (st.hasMoreTokens()) { String token = StringUtils.stripToEmpty(st.nextToken()); Integer i = Integer.valueOf(token); set.add(i);/* ww w. ja v a 2 s. c om*/ } return set; }
From source file:org.dishevelled.commandline.argument.LongListArgument.java
/** {@inheritDoc} */ protected List<Long> convert(final String s) throws Exception { List<Long> list = new ArrayList<Long>(); StringTokenizer st = new StringTokenizer(s, ","); while (st.hasMoreTokens()) { String token = StringUtils.stripToEmpty(st.nextToken()); Long l = Long.valueOf(token); list.add(l);//from w ww . jav a 2s . co m } return list; }
From source file:org.dishevelled.commandline.argument.LongSetArgument.java
/** {@inheritDoc} */ protected Set<Long> convert(final String s) throws Exception { Set<Long> set = new HashSet<Long>(); StringTokenizer st = new StringTokenizer(s, ","); while (st.hasMoreTokens()) { String token = StringUtils.stripToEmpty(st.nextToken()); Long l = Long.valueOf(token); set.add(l);//from w w w .j a v a 2 s.c o m } return set; }
From source file:org.dishevelled.commandline.argument.URLListArgument.java
/** {@inheritDoc} */ protected List<URL> convert(final String s) throws Exception { List<URL> list = new ArrayList<URL>(); StringTokenizer st = new StringTokenizer(s, ","); while (st.hasMoreTokens()) { String token = StringUtils.stripToEmpty(st.nextToken()); URL url = new URL(token); list.add(url);//from w w w.ja va 2 s. c o m } return list; }
From source file:org.dishevelled.commandline.argument.URLSetArgument.java
/** {@inheritDoc} */ protected Set<URL> convert(final String s) throws Exception { Set<URL> set = new HashSet<URL>(); StringTokenizer st = new StringTokenizer(s, ","); while (st.hasMoreTokens()) { String token = StringUtils.stripToEmpty(st.nextToken()); URL url = new URL(token); set.add(url);/* w w w . j ava2s. c om*/ } return set; }
From source file:org.jahia.services.htmlvalidator.WAIValidator.java
/** * Validates a link Element./* w ww . j a va 2 s. c om*/ * * * @param node * The HTMLAnchorElement. * @param source * @return Result or null if no error occurred. */ protected Result validateLink(Element node, Source source) throws DOMException { final Attribute href = node.getAttributes().get("href"); if (href == null) { return null; } // Criteria 6.1 String linkValue = node.getTextExtractor().toString(); if (StringUtils.isBlank(linkValue) && !node.getChildElements().isEmpty()) { linkValue = node.getChildElements().get(0).toString(); } linkValue = linkValue != null ? text2XMLEntityRef(StringUtils.stripToEmpty(linkValue)) : ""; final int length = linkValue.length(); if (length > 80) { Result ve = new Result( getFormatted("org.jahia.services.htmlvalidator.WAIValidator.6.1", "Link value should not be longer than 80 characters. Length = " + length, new Object[] { linkValue, Integer.toString(length) }), node.toString(), node.toString(), getMessage("org.jahia.services.htmlvalidator.WAIValidator.6.1.example", "")); setPosition(node, source, ve); return ve; } // Criteria 6.3 bis final Attribute title = node.getAttributes().get("title"); if (title != null) { final String titleValue = text2XMLEntityRef(title.getValue()); final int length2 = titleValue.length(); if (length2 > 80) { Result ve = new Result( getFormatted("org.jahia.services.htmlvalidator.WAIValidator.6.3.2", "Attribute 'title' should not be longer than 80 characters. Length = " + length2, new Object[] { linkValue, titleValue, Integer.toString(length2) }), node.toString(), node.toString(), getMessage("org.jahia.services.htmlvalidator.WAIValidator.6.3.2.example", "")); setPosition(node, source, ve); return ve; } } if (StringUtils.isNotEmpty(linkValue)) { // Criteria 6.5 final String hrefValue = href.getValue(); if (linkToDest.containsKey(linkValue)) { final String dest = linkToDest.get(linkValue); if (!hrefValue.equals(dest)) { Result ve = new Result( getFormatted("org.jahia.services.htmlvalidator.WAIValidator.6.5", "All same link values(" + hrefValue + ") should point to the same destination", new Object[] { hrefValue }), node.toString(), node.toString(), getMessage("org.jahia.services.htmlvalidator.WAIValidator.6.5.example", "")); setPosition(node, source, ve); return ve; } } else { linkToDest.put(linkValue, hrefValue); } } return null; }
From source file:org.objectstyle.cayenne.dataview.DataView.java
private void loadField(ObjEntityView entityView, Element element) { String name = element.getAttributeValue("name"); ObjEntityViewField field = new ObjEntityViewField(); field.setName(name);/*from w w w . j a v a 2 s. c o m*/ String prefIndex = element.getAttributeValue("pref-index"); field.setPreferredIndex(NumberUtils.stringToInt(prefIndex, -1)); entityView.insertField(field); String calcType = element.getAttributeValue("calc-type"); Validate.notNull(calcType); CalcTypeEnum fieldCalcType = CalcTypeEnum.getEnum(calcType); Validate.isTrue( CalcTypeEnum.NO_CALC_TYPE.equals(fieldCalcType) || CalcTypeEnum.LOOKUP_TYPE.equals(fieldCalcType), "Calc Type not supported yet: ", fieldCalcType); field.setCalcType(fieldCalcType); ObjEntity objEntity = entityView.getObjEntity(); if (CalcTypeEnum.NO_CALC_TYPE.equals(fieldCalcType)) { String objAttributeName = element.getAttributeValue("obj-attribute-name"); Validate.notNull(objAttributeName); ObjAttribute objAttribute = (ObjAttribute) objEntity.getAttribute(objAttributeName); field.setObjAttribute(objAttribute); } else if (CalcTypeEnum.LOOKUP_TYPE.equals(fieldCalcType)) { String objRelationshipName = element.getAttributeValue("obj-relationship-name"); Validate.notNull(objRelationshipName); ObjRelationship objRelationship = (ObjRelationship) objEntity.getRelationship(objRelationshipName); field.setObjRelationship(objRelationship); Element lookupElement = element.getChild("lookup"); Validate.notNull(lookupElement); String lookupEntityView = lookupElement.getAttributeValue("obj-entity-view-name"); Validate.notNull(lookupEntityView); String lookupEntityField = lookupElement.getAttributeValue("field-name"); Validate.notNull(lookupEntityField); String[] lookupDescriptor = new String[] { lookupEntityView, lookupEntityField }; lookupReferenceTable.put(field, lookupDescriptor); } String dataType = element.getAttributeValue("data-type"); Validate.notNull(dataType); field.setDataType(dataTypeSpec.getDataType(dataType)); String editable = element.getAttributeValue("editable"); field.setEditable(BooleanUtils.toBoolean(editable)); String visible = element.getAttributeValue("visible"); field.setVisible(BooleanUtils.toBoolean(visible)); Element captionElement = element.getChild("caption"); if (captionElement != null) field.setCaption(StringUtils.stripToEmpty(captionElement.getText())); Element editFormatElement = element.getChild("edit-format"); if (editFormatElement != null) { String formatClassName = editFormatElement.getAttributeValue("class"); Validate.notNull(formatClassName); Class formatClass; try { formatClass = Class.forName(formatClassName); Map parameters = DataView.childrenToMap(editFormatElement); Format format = formatFactory.createFormat(formatClass, locale, parameters); field.setEditFormat(format); } catch (ClassNotFoundException ex) { } } Element displayFormatElement = element.getChild("display-format"); if (displayFormatElement != null) { String formatClassName = displayFormatElement.getAttributeValue("class"); Validate.notNull(formatClassName); Class formatClass; try { formatClass = Class.forName(formatClassName); Map parameters = DataView.childrenToMap(displayFormatElement); Format format = formatFactory.createFormat(formatClass, locale, parameters); field.setDisplayFormat(format); } catch (ClassNotFoundException ex) { } } Element defaultValueElement = element.getChild("default-value"); if (defaultValueElement != null) { String defaultValueStr = StringUtils.stripToEmpty(defaultValueElement.getText()); Object defaultValue = dataTypeSpec.create(field.getDataType(), defaultValueStr); field.setDefaultValue(defaultValue); } }
From source file:se.inera.axel.riv.webconsole.ShsProductChoiceRenderer.java
@Override public Object getDisplayValue(String productId) { String displayValue = null;/*from w w w.j a va 2s .c o m*/ if (productId != null) { ShsProduct product = products.get(productId); displayValue = StringUtils.stripToEmpty(product.getCommonName()) + " (" + product.getUuid() + ")"; } else { displayValue = ""; } log.trace("displayValue={}", displayValue); return displayValue; }