List of usage examples for org.apache.commons.lang ObjectUtils toString
public static String toString(Object obj)
Gets the toString
of an Object
returning an empty string ("") if null
input.
ObjectUtils.toString(null) = "" ObjectUtils.toString("") = "" ObjectUtils.toString("bat") = "bat" ObjectUtils.toString(Boolean.TRUE) = "true"
From source file:org.apache.solr.handler.clustering.carrot2.CarrotClusteringEngine.java
private String getConcatenated(SolrDocument sdoc, String fieldsSpec) { StringBuilder result = new StringBuilder(); for (String field : fieldsSpec.split("[, ]")) { Collection<Object> vals = sdoc.getFieldValues(field); if (vals == null) continue; Iterator<Object> ite = vals.iterator(); while (ite.hasNext()) { // Join multiple values with a period so that Carrot2 does not pick up // phrases that cross field value boundaries (in most cases it would // create useless phrases). result.append(ObjectUtils.toString(ite.next())).append(" . "); }//w w w. ja v a2 s. com } return result.toString().trim(); }
From source file:org.apache.torque.templates.transformer.om.OMTableAndViewTransformer.java
protected void setCreateDefaultDateMethodsAttributes(SourceElement tableElement) { for (SourceElement column : tableElement.getChildren(TorqueSchemaElementName.COLUMN)) { if ("java.util.Date".equals(column.getAttribute(JavaFieldAttributeName.FIELD_TYPE))) { String defaultValue = ObjectUtils.toString(column.getAttribute(TorqueSchemaAttributeName.DEFAULT)); if (CURRENT_DATE.equalsIgnoreCase(defaultValue)) { if (tableElement.getAttribute(TableAttributeName.GET_CURRENT_DATE_METHOD_NAME) == null) { tableElement.setAttribute(TableAttributeName.GET_CURRENT_DATE_METHOD_NAME, GET_DEFAULT_DATE_METHOD_NAME); }/*from w ww . jav a2 s .c o m*/ } else if (CURRENT_TIME.equalsIgnoreCase(defaultValue)) { if (tableElement.getAttribute(TableAttributeName.GET_CURRENT_TIME_METHOD_NAME) == null) { tableElement.setAttribute(TableAttributeName.GET_CURRENT_TIME_METHOD_NAME, GET_DEFAULT_TIME_METHOD_NAME); } } else if (CURRENT_TIMESTAMP.equalsIgnoreCase(defaultValue) && tableElement .getAttribute(TableAttributeName.GET_CURRENT_TIMESTAMP_METHOD_NAME) == null) { tableElement.setAttribute(TableAttributeName.GET_CURRENT_TIMESTAMP_METHOD_NAME, GET_DEFAULT_TIMESTAMP_METHOD_NAME); } } } }
From source file:org.apereo.portal.portlets.sitemap.SitemapPortletController.java
/** * Display the user sitemap.//from w w w .j av a 2 s . c om * * @param request * @return "sitemapView" and a supporting model * @throws XMLStreamException * @throws IllegalStateException if components required for the SiteMap portlet fail to auto-wire */ @RequestMapping public ModelAndView displaySitemap(PortletRequest request) throws XMLStreamException { Map<String, Object> model = new HashMap<String, Object>(); if (this.xsltPortalUrlProvider == null) { throw new IllegalStateException( "Sitemap portlet requires a XsltPortalUrlProvider but it failed to " + "auto-wire"); } if (this.attributeIncorporationComponent == null) { throw new IllegalStateException( "Sitemap portlet requires a StAXPipelineComponent with qualifier structureAttributeIncorporationComponent but it failed to auto-wire"); } if (this.portalRequestUtils == null) { throw new IllegalStateException( "Sitemap portlet requires an IPortalRequestUtils but it failed to " + "auto-wire"); } // retrieve the user layout with structure attributes applied (required in order to display tab groups) final HttpServletRequest httpServletRequest = this.portalRequestUtils.getPortletHttpRequest(request); final HttpServletResponse httpServletResponse = this.portalRequestUtils.getOriginalPortalResponse(request); final PipelineEventReader<XMLEventReader, XMLEvent> reader = attributeIncorporationComponent .getEventReader(httpServletRequest, httpServletResponse); // create a Source from the user's layout document StAXSource source = new StAXSource(reader.getEventReader()); model.put("source", source); model.put(XsltPortalUrlProvider.CURRENT_REQUEST, httpServletRequest); model.put(XsltPortalUrlProvider.XSLT_PORTAL_URL_PROVIDER, this.xsltPortalUrlProvider); model.put(USE_TAB_GROUPS, useTabGroups); model.put(USER_LANG, ObjectUtils.toString(request.getLocale())); return new ModelAndView("sitemapView", model); }
From source file:org.displaytag.decorator.CheckboxTableDecorator.java
public String getCheckbox() { String evaluatedId = ObjectUtils.toString(evaluate(id)); boolean checked = checkedIds.contains(evaluatedId); StringBuffer buffer = new StringBuffer(); buffer.append("<input type=\"checkbox\" name=\"_chk\" value=\""); buffer.append(evaluatedId);//w w w.j a v a2 s . co m buffer.append("\""); if (checked) { checkedIds.remove(evaluatedId); buffer.append(" checked=\"checked\""); } buffer.append("/>"); return buffer.toString(); }
From source file:org.displaytag.decorator.MultilevelTotalTableDecorator.java
public String getTotalsTdOpen(HeaderCell header, String totalClass) { String cssClass = ObjectUtils.toString(header.getHtmlAttributes().get("class")); StringBuffer buffer = new StringBuffer(); buffer.append(TagConstants.TAG_OPEN); buffer.append(TagConstants.TAGNAME_COLUMN); if (cssClass != null || totalClass != null) { buffer.append(" class=\""); if (cssClass != null) { buffer.append(cssClass);/*w w w .j a v a 2 s .c om*/ if (totalClass != null) { buffer.append(" "); } } if (totalClass != null) { buffer.append(totalClass); } buffer.append("\""); } buffer.append(TagConstants.TAG_CLOSE); return buffer.toString(); }
From source file:org.displaytag.decorator.TotalTableDecorator.java
protected String createTotalRow(boolean grandTotal) { StringBuffer buffer = new StringBuffer(1000); buffer.append("\n<tr class=\"total\">"); //$NON-NLS-1$ List headerCells = tableModel.getHeaderCellList(); for (Iterator it = headerCells.iterator(); it.hasNext();) { HeaderCell cell = (HeaderCell) it.next(); String cssClass = ObjectUtils.toString(cell.getHtmlAttributes().get("class")); buffer.append("<td"); //$NON-NLS-1$ if (StringUtils.isNotEmpty(cssClass)) { buffer.append(" class=\""); //$NON-NLS-1$ buffer.append(cssClass);/*from w w w. ja va2s .co m*/ buffer.append("\""); //$NON-NLS-1$ } buffer.append(">"); //$NON-NLS-1$ if (cell.isTotaled()) { String totalPropertyName = cell.getBeanPropertyName(); Object total = grandTotal ? grandTotals.get(totalPropertyName) : subTotals.get(totalPropertyName); DisplaytagColumnDecorator[] decorators = cell.getColumnDecorators(); for (int j = 0; j < decorators.length; j++) { try { total = decorators[j].decorate(total, this.getPageContext(), tableModel.getMedia()); } catch (DecoratorException e) { log.warn(e.getMessage(), e); // ignore, use undecorated value for totals } } buffer.append(total); } else if (groupPropertyName != null && groupPropertyName.equals(cell.getBeanPropertyName())) { buffer.append(grandTotal ? totalLabel : MessageFormat.format(subtotalLabel, new Object[] { previousValues.get(groupPropertyName) })); } buffer.append("</td>"); //$NON-NLS-1$ } buffer.append("</tr>"); //$NON-NLS-1$ // reset subtotal this.subTotals.clear(); return buffer.toString(); }
From source file:org.displaytag.model.Column.java
/** * Calculates the cell content, cropping or linking the value as needed. * //ww w . ja va 2 s . c o m * @return String * @throws ObjectLookupException for errors in bean property lookup * @throws DecoratorException if a column decorator is used and an exception is thrown during value decoration */ public String createChoppedAndLinkedValue() throws ObjectLookupException, DecoratorException { String fullValue = ObjectUtils.toString(this.getValue(true)); String choppedValue; // are we supposed to set up a link to the data being displayed in this column? if (this.header.getAutoLink()) { fullValue = AutolinkColumnDecorator.INSTANCE.decorate(fullValue); } // trim the string if a maxLength or maxWords is defined if (this.header.getMaxLength() > 0) { choppedValue = HtmlTagUtil.abbreviateHtmlString(fullValue, this.header.getMaxLength(), false); } else if (this.header.getMaxWords() > 0) { choppedValue = HtmlTagUtil.abbreviateHtmlString(fullValue, this.header.getMaxWords(), true); } else { choppedValue = fullValue; } // chopped content? add the full content to the column "title" attribute if (choppedValue.length() < fullValue.length()) { // clone the attribute map, don't want to add title to all the columns this.htmlAttributes = (HtmlAttributeMap) this.htmlAttributes.clone(); // add title this.htmlAttributes.put(TagConstants.ATTRIBUTE_TITLE, HtmlTagUtil.stripHTMLTags(fullValue)); } if (this.header.getHref() != null) { // generates the href for the link Href colHref = this.getColumnHref(fullValue); Anchor anchor = new Anchor(colHref, choppedValue); choppedValue = anchor.toString(); // SIGESP verifica se hrefType = replace if (this.header.getHrefType() != null && this.header.getHrefType().equals("replace")) { String strTmp = choppedValue; Object valor = LookupUtil.getBeanProperty(this.row.getObject(), this.header.getParamProperty()); String strValor = ""; if (valor == null) { strValor = "NULL"; } else { // Tratar aspas simples (retorno do javascript) strValor = Conversao.substituirExpressaoString(valor.toString(), "'", "\\u0027"); } int intPosicao = -1; StringBuffer stbNovaString = new StringBuffer(strTmp); while ((intPosicao = stbNovaString.indexOf(this.header.getParamName())) >= 0) { stbNovaString.replace(intPosicao, intPosicao + this.header.getParamName().length(), strValor.toString()); } int intPosicaoIgual = stbNovaString.indexOf(strValor.toString() + "="); if (intPosicaoIgual != -1) { stbNovaString.replace(intPosicaoIgual - 1, intPosicaoIgual - 1 + stbNovaString.substring(intPosicaoIgual - 1).indexOf(">") - 1, ";"); // stbNovaString.replace(stbNovaString.indexOf(valor.toString() + "=" + valor.toString()) - 1, // stbNovaString.substring(stbNovaString.indexOf(valor.toString() + "=" + valor.toString()) - // 1).indexOf(">"), ";"); } else { throw new RuntimeException("Os parmetros informados na display-tag esto incorretos"); } choppedValue = stbNovaString.toString(); } } return choppedValue; }
From source file:org.displaytag.render.HssfTableWriter.java
/** * Escape certain values that are not permitted in excel cells. * @param rawValue the object value/*from w ww . jav a 2s.co m*/ * @return the escaped value */ protected String escapeColumnValue(Object rawValue) { if (rawValue == null) { return null; } String returnString = ObjectUtils.toString(rawValue); // escape the String to get the tabs, returns, newline explicit as \t \r \n returnString = StringEscapeUtils.escapeJava(StringUtils.trimToEmpty(returnString)); // remove tabs, insert four whitespaces instead returnString = StringUtils.replace(StringUtils.trim(returnString), "\\t", " "); // remove the return, only newline valid in excel returnString = StringUtils.replace(StringUtils.trim(returnString), "\\r", " "); // unescape so that \n gets back to newline returnString = StringEscapeUtils.unescapeJava(returnString); return returnString; }
From source file:org.displaytag.render.HtmlTableWriter.java
private String esc(Object value) { String valueEscaped = StringUtils.replace(ObjectUtils.toString(value), "\"", "\\\""); return valueEscaped; }
From source file:org.displaytag.render.ItextTableWriter.java
/** * Returns a formatted cell for the given value. * @param value cell value/*from w w w . j a v a 2 s .com*/ * @return Cell * @throws BadElementException if errors occurs while generating content. */ private Cell getCell(Object value) throws BadElementException { Cell cell = new Cell(new Chunk(StringUtils.trimToEmpty(ObjectUtils.toString(value)), this.defaultFont)); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setLeading(8); return cell; }