01: /*
02: * ====================================================================
03: *
04: * L2FProd.com Common Components 7.3 License.
05: *
06: * Copyright (c) 2005-2007 L2FProd.com. All rights reserved.
07: *
08: * Redistribution and use in source and binary forms, with or without
09: * modification, are permitted provided that the following conditions are met: 1.
10: * Redistributions of source code must retain the above copyright notice, this
11: * list of conditions and the following disclaimer. 2. Redistributions in
12: * binary form must reproduce the above copyright notice, this list of
13: * conditions and the following disclaimer in the documentation and/or other
14: * materials provided with the distribution. 3. The end-user documentation
15: * included with the redistribution, if any, must include the following
16: * acknowlegement: "This product includes software developed by L2FProd.com
17: * (http://www.L2FProd.com/)." Alternately, this acknowlegement may appear in
18: * the software itself, if and wherever such third-party acknowlegements
19: * normally appear. 4. The names "L2FProd.com Common Components", "l2fprod-common"
20: * and "L2FProd.com" must not be used to endorse or promote products derived
21: * from this software without prior written permission. For written permission,
22: * please contact info@L2FProd.com. 5. Products derived from this software may
23: * not be called "l2fprod-common" nor may "l2fprod-common" appear in
24: * their names without prior written permission of L2FProd.com.
25: *
26: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
27: * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
28: * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
29: * L2FPROD.COM OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
32: * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
35: * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36: * ====================================================================
37: */
38: package com.l2fprod.common.model;
39:
40: import com.l2fprod.common.util.ResourceManager;
41: import com.l2fprod.common.util.converter.ConverterRegistry;
42:
43: import java.io.File;
44:
45: /**
46: * DefaultObjectRenderer. <br>
47: *
48: */
49: public class DefaultObjectRenderer implements ObjectRenderer {
50:
51: private boolean idVisible = false;
52:
53: public void setIdVisible(boolean b) {
54: idVisible = b;
55: }
56:
57: public String getText(Object object) {
58: if (object == null) {
59: return null;
60: }
61:
62: // lookup the shared ConverterRegistry
63: try {
64: return (String) ConverterRegistry.instance().convert(
65: String.class, object);
66: } catch (IllegalArgumentException e) {
67: }
68:
69: if (object instanceof Boolean) {
70: return Boolean.TRUE.equals(object) ? ResourceManager
71: .common().getString("true") : ResourceManager
72: .common().getString("false");
73: }
74:
75: if (object instanceof File) {
76: return ((File) object).getAbsolutePath();
77: }
78:
79: StringBuffer buffer = new StringBuffer();
80: if (idVisible && object instanceof HasId) {
81: buffer.append(((HasId) object).getId());
82: }
83: if (object instanceof TitledObject) {
84: buffer.append(((TitledObject) object).getTitle());
85: }
86: if (!(object instanceof HasId || object instanceof TitledObject)) {
87: buffer.append(String.valueOf(object));
88: }
89: return buffer.toString();
90: }
91:
92: }
|