01: /*
02: * Copyright 2007 The Kuali Foundation.
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.kuali.core.web.ui;
17:
18: import javax.servlet.jsp.PageContext;
19:
20: import org.apache.commons.lang.StringUtils;
21: import org.displaytag.decorator.DisplaytagColumnDecorator;
22: import org.displaytag.exception.DecoratorException;
23: import org.displaytag.properties.MediaTypeEnum;
24: import org.kuali.RiceConstants;
25: import org.kuali.core.web.comparator.CellComparatorHelper;
26:
27: public class FormatAwareDecorator implements DisplaytagColumnDecorator {
28:
29: /**
30: * Empty values don't show up properly in HTML. So, the String " " is substituted for an empty or null value of cellValue
31: * if mediaType is MediaTypeEnum.HTML. If mediaType is not {@link MediaTypeEnum.HTML} and cellValue is not null, then
32: * <code>CellComparatorHelper.getSanitizedValue(cellValue.toString())</code> is returned.
33: *
34: * @param cellValue
35: * @param pageContext
36: * @param mediaType
37: */
38: public Object decorate(Object cellValue, PageContext pageContext,
39: MediaTypeEnum mediaType) throws DecoratorException {
40: Object decoratedOutput = null;
41:
42: if (null == cellValue) {
43: decoratedOutput = MediaTypeEnum.HTML.equals(mediaType) ? " "
44: : RiceConstants.EMPTY_STRING;
45: }
46: //If a column resulting from lookup contains collection values, each of the collection entry
47: //should be printed on one line (i.e. separated by a <BR>). If there is no entry in the
48: //collection, then we'll just print an   for the column.
49: else if (cellValue.toString().indexOf("[") == 0
50: && cellValue.toString().indexOf("]") > 0) {
51: String cellContentToBeParsed = cellValue.toString()
52: .substring(1, cellValue.toString().indexOf("]"));
53: if (StringUtils.isNotBlank(cellContentToBeParsed)) {
54: String[] parsed = cellContentToBeParsed.split(",");
55: decoratedOutput = new String();
56: for (int i = 0; i < parsed.length; i++) {
57: decoratedOutput = decoratedOutput + parsed[i]
58: + "<BR>";
59: }
60: } else { //if the cellContentToBeParsed is blank
61: decoratedOutput = " ";
62: }
63: } else {
64: decoratedOutput = MediaTypeEnum.HTML.equals(mediaType) ? new StringBuffer(
65: cellValue.toString()).append(" ").toString()
66: : CellComparatorHelper
67: .getSanitizedStaticValue(cellValue
68: .toString());
69: }
70:
71: return decoratedOutput;
72: }
73:
74: }
|