Source Code Cross Referenced for AbstractBeanHandler.java in  » Web-Framework » rife-1.6.1 » com » uwyn » rife » template » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Framework » rife 1.6.1 » com.uwyn.rife.template 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003:         * Distributed under the terms of either:
004:         * - the common development and distribution license (CDDL), v1.0; or
005:         * - the GNU Lesser General Public License, v2.1 or later
006:         * $Id: AbstractBeanHandler.java 3634 2007-01-08 21:42:24Z gbevin $
007:         */
008:        package com.uwyn.rife.template;
009:
010:        import com.uwyn.rife.cmf.MimeType;
011:        import com.uwyn.rife.site.Constrained;
012:        import com.uwyn.rife.site.ConstrainedProperty;
013:        import com.uwyn.rife.site.ConstrainedUtils;
014:        import com.uwyn.rife.template.exceptions.BeanRemovalErrorException;
015:        import com.uwyn.rife.template.exceptions.BeanSettingErrorException;
016:        import com.uwyn.rife.template.exceptions.TemplateException;
017:        import com.uwyn.rife.tools.ArrayUtils;
018:        import com.uwyn.rife.tools.exceptions.BeanUtilsException;
019:        import java.util.Map;
020:
021:        public abstract class AbstractBeanHandler implements  BeanHandler {
022:            protected abstract MimeType getMimeType();
023:
024:            protected abstract Map<String, Object> getPropertyValues(
025:                    Template template, Object bean, String prefix)
026:                    throws BeanUtilsException;
027:
028:            public void setBean(Template template, Object bean, String prefix,
029:                    boolean encode) throws TemplateException {
030:                if (null == template)
031:                    throw new IllegalArgumentException(
032:                            "template can't be null.");
033:                if (null == bean) {
034:                    return;
035:                }
036:
037:                Constrained constrained = ConstrainedUtils
038:                        .makeConstrainedInstance(bean);
039:
040:                try {
041:                    Map<String, Object> property_values = getPropertyValues(
042:                            template, bean, prefix);
043:                    Object property_value = null;
044:                    String[] property_value_strings = null;
045:                    String[] property_values_encoded = null;
046:                    TemplateEncoder encoder = template.getEncoder();
047:                    ConstrainedProperty constrained_property = null;
048:                    for (String property_name : property_values.keySet()) {
049:                        property_value = property_values.get(property_name);
050:                        property_values_encoded = null;
051:
052:                        if (null == property_value) {
053:                            property_values_encoded = new String[1];
054:                            property_values_encoded[0] = "";
055:                        } else {
056:                            // get the constrained property if that's appropriate
057:                            if (constrained != null) {
058:                                if (prefix != null) {
059:                                    constrained_property = constrained
060:                                            .getConstrainedProperty(property_name
061:                                                    .substring(prefix.length()));
062:                                } else {
063:                                    constrained_property = constrained
064:                                            .getConstrainedProperty(property_name);
065:                                }
066:                            }
067:
068:                            // handle multiple values
069:                            property_value_strings = ArrayUtils
070:                                    .createStringArray(property_value,
071:                                            constrained_property);
072:                            if (property_value_strings != null
073:                                    && property_value_strings.length > 0) {
074:                                // encode the value if that's necessary
075:                                property_values_encoded = new String[property_value_strings.length];
076:                                for (int i = 0; i < property_values_encoded.length; i++) {
077:                                    if (null == encoder
078:                                            || !encode
079:                                            || (constrained_property != null && constrained_property
080:                                                    .isDisplayedRaw())) {
081:                                        // still encode if the mime type of the constrained property is different
082:                                        // from the mime type of the bean handler
083:                                        if (encoder != null
084:                                                && getMimeType() != null
085:                                                && constrained_property != null
086:                                                && constrained_property
087:                                                        .getMimeType() != null
088:                                                && constrained_property
089:                                                        .getMimeType() != getMimeType()) {
090:                                            property_values_encoded[i] = encoder
091:                                                    .encode(property_value_strings[i]);
092:                                        } else {
093:                                            property_values_encoded[i] = property_value_strings[i];
094:                                        }
095:                                    } else {
096:                                        property_values_encoded[i] = encoder
097:                                                .encode(property_value_strings[i]);
098:                                    }
099:                                }
100:                            }
101:                        }
102:
103:                        if (property_values_encoded != null) {
104:                            // plain values
105:                            if (template.hasValueId(property_name)) {
106:                                template.setValue(property_name,
107:                                        property_values_encoded[0]);
108:                            }
109:
110:                            if (getFormBuilder() != null) {
111:                                // handle form values
112:                                getFormBuilder().selectParameter(template,
113:                                        property_name, property_value_strings);
114:                            }
115:                        }
116:                    }
117:                } catch (BeanUtilsException e) {
118:                    throw new BeanSettingErrorException(bean, e);
119:                }
120:            }
121:
122:            public void removeBean(Template template, Object bean, String prefix)
123:                    throws TemplateException {
124:                if (null == template)
125:                    throw new IllegalArgumentException(
126:                            "template can't be null.");
127:                if (null == bean) {
128:                    return;
129:                }
130:
131:                try {
132:                    Constrained constrained = ConstrainedUtils
133:                            .makeConstrainedInstance(bean);
134:                    ConstrainedProperty constrained_property = null;
135:
136:                    Map<String, Object> property_values = getPropertyValues(
137:                            template, bean, prefix);
138:                    Object property_value = null;
139:                    String[] property_value_strings = null;
140:                    for (String property_name : property_values.keySet()) {
141:                        property_value = property_values.get(property_name);
142:
143:                        if (property_name != null) {
144:                            // plain values
145:                            if (template.hasValueId(property_name)) {
146:                                template.removeValue(property_name);
147:                            }
148:                        }
149:
150:                        if (getFormBuilder() != null) {
151:                            if (property_value != null) {
152:                                // get the constrained property if that's appropriate
153:                                if (constrained != null) {
154:                                    if (prefix != null) {
155:                                        constrained_property = constrained
156:                                                .getConstrainedProperty(property_name
157:                                                        .substring(prefix
158:                                                                .length()));
159:                                    } else {
160:                                        constrained_property = constrained
161:                                                .getConstrainedProperty(property_name);
162:                                    }
163:                                }
164:                                // handle multiple values
165:                                property_value_strings = ArrayUtils
166:                                        .createStringArray(property_value,
167:                                                constrained_property);
168:                                if (property_value_strings.length > 0) {
169:                                    // handle form values
170:                                    getFormBuilder().unselectParameter(
171:                                            template, property_name,
172:                                            property_value_strings);
173:                                }
174:                            }
175:                        }
176:                    }
177:                } catch (BeanUtilsException e) {
178:                    throw new BeanRemovalErrorException(bean, e);
179:                }
180:            }
181:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.