Source Code Cross Referenced for Transformer.java in  » Web-Services » restlet-1.0.8 » org » restlet » 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 Services » restlet 1.0.8 » org.restlet 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2005-2007 Noelios Consulting.
003:         * 
004:         * The contents of this file are subject to the terms of the Common Development
005:         * and Distribution License (the "License"). You may not use this file except in
006:         * compliance with the License.
007:         * 
008:         * You can obtain a copy of the license at
009:         * http://www.opensource.org/licenses/cddl1.txt See the License for the specific
010:         * language governing permissions and limitations under the License.
011:         * 
012:         * When distributing Covered Code, include this CDDL HEADER in each file and
013:         * include the License file at http://www.opensource.org/licenses/cddl1.txt If
014:         * applicable, add the following below this CDDL HEADER, with the fields
015:         * enclosed by brackets "[]" replaced with your own identifying information:
016:         * Portions Copyright [yyyy] [name of copyright owner]
017:         */
018:
019:        package org.restlet;
020:
021:        import java.util.ArrayList;
022:        import java.util.List;
023:
024:        import org.restlet.data.CharacterSet;
025:        import org.restlet.data.Encoding;
026:        import org.restlet.data.Language;
027:        import org.restlet.data.MediaType;
028:        import org.restlet.data.Request;
029:        import org.restlet.data.Response;
030:        import org.restlet.resource.Representation;
031:        import org.restlet.resource.TransformRepresentation;
032:
033:        /**
034:         * Filter that can transform XML representations by applying an XSLT transform
035:         * sheet. It uses the {@link org.restlet.resource.TransformRepresentation} to
036:         * actually transform the XML entities.
037:         * 
038:         * @author Jerome Louvel (contact@noelios.com) <a
039:         *         href="http://www.noelios.com/">Noelios Consulting</a>
040:         */
041:        public class Transformer extends Filter {
042:            /**
043:             * Mode that transforms request entities before their handling by the
044:             * attached Restlet.
045:             */
046:            public static final int MODE_REQUEST = 1;
047:
048:            /**
049:             * Mode that transforms response entities after their handling by the
050:             * attached Restlet.
051:             */
052:            public static final int MODE_RESPONSE = 2;
053:
054:            /** The transformation mode. */
055:            private int mode;
056:
057:            /** The XSLT transform sheet to apply to message entities. */
058:            private Representation transformSheet;
059:
060:            /**
061:             * The character set of the result representation. The default value is
062:             * null.
063:             */
064:            private CharacterSet resultCharacterSet;
065:
066:            /**
067:             * The encodings of the result representation.
068:             */
069:            private List<Encoding> resultEncodings;
070:
071:            /** The languages of the result representation. */
072:            private List<Language> resultLanguages;
073:
074:            /**
075:             * The media type of the result representation. MediaType.APPLICATION_XML by
076:             * default.
077:             */
078:            private MediaType resultMediaType;
079:
080:            /**
081:             * Constructor.
082:             * 
083:             * @param mode
084:             *                The transformation mode.
085:             * @param transformSheet
086:             *                The XSLT transform sheet to apply to message entities.
087:             */
088:            public Transformer(int mode, Representation transformSheet) {
089:                this .mode = mode;
090:                this .transformSheet = transformSheet;
091:                this .resultMediaType = MediaType.APPLICATION_XML;
092:                this .resultLanguages = null;
093:                this .resultCharacterSet = null;
094:            }
095:
096:            @Override
097:            protected void afterHandle(Request request, Response response) {
098:                if (getMode() == MODE_RESPONSE) {
099:                    response.setEntity(transform(response.getEntity()));
100:                }
101:            }
102:
103:            @Override
104:            protected void beforeHandle(Request request, Response response) {
105:                if (getMode() == MODE_REQUEST) {
106:                    request.setEntity(transform(request.getEntity()));
107:                }
108:            }
109:
110:            /**
111:             * Returns the transformation mode. See MODE_* constants.
112:             * 
113:             * @return The transformation mode.
114:             */
115:            public int getMode() {
116:                return this .mode;
117:            }
118:
119:            /**
120:             * Returns the character set of the result representation. The default value
121:             * is null.
122:             * 
123:             * @return The character set of the result representation.
124:             */
125:            public CharacterSet getResultCharacterSet() {
126:                return this .resultCharacterSet;
127:            }
128:
129:            /**
130:             * Returns the encoding of the result representation. The default value is
131:             * null.
132:             * 
133:             * @return The encoding of the result representation.
134:             */
135:            public List<Encoding> getResultEncodings() {
136:                if (this .resultEncodings == null)
137:                    this .resultEncodings = new ArrayList<Encoding>();
138:                return this .resultEncodings;
139:            }
140:
141:            /**
142:             * Returns the languages of the result representation.
143:             * 
144:             * @return The language of the result representation.
145:             */
146:            public List<Language> getResultLanguages() {
147:                if (this .resultLanguages == null)
148:                    this .resultLanguages = new ArrayList<Language>();
149:                return this .resultLanguages;
150:            }
151:
152:            /**
153:             * Returns the media type of the result representation. The default value is
154:             * MediaType.APPLICATION_XML.
155:             * 
156:             * @return The media type of the result representation.
157:             */
158:            public MediaType getResultMediaType() {
159:                return this .resultMediaType;
160:            }
161:
162:            /**
163:             * Returns the XSLT transform sheet to apply to message entities.
164:             * 
165:             * @return The XSLT transform sheet to apply to message entities.
166:             */
167:            public Representation getTransformSheet() {
168:                return this .transformSheet;
169:            }
170:
171:            /**
172:             * Sets the transformation mode. See MODE_* constants.
173:             * 
174:             * @param mode
175:             *                The transformation mode.
176:             */
177:            public void setMode(int mode) {
178:                this .mode = mode;
179:            }
180:
181:            /**
182:             * Sets the character set of the result representation.
183:             * 
184:             * @param resultCharacterSet
185:             *                The character set of the result representation.
186:             */
187:            public void setResultCharacterSet(CharacterSet resultCharacterSet) {
188:                this .resultCharacterSet = resultCharacterSet;
189:            }
190:
191:            /**
192:             * Sets the media type of the result representation.
193:             * 
194:             * @param resultMediaType
195:             *                The media type of the result representation.
196:             */
197:            public void setResultMediaType(MediaType resultMediaType) {
198:                this .resultMediaType = resultMediaType;
199:            }
200:
201:            /**
202:             * Sets the XSLT transform sheet to apply to message entities.
203:             * 
204:             * @param transformSheet
205:             *                The XSLT transform sheet to apply to message entities.
206:             */
207:            public void setTransformSheet(Representation transformSheet) {
208:                this .transformSheet = transformSheet;
209:            }
210:
211:            /**
212:             * Transforms a source XML representation by applying an XSLT transform
213:             * sheet to it.
214:             * 
215:             * @param source
216:             *                The source XML representation.
217:             * @return The generated result representation.
218:             */
219:            public Representation transform(Representation source) {
220:                Representation result = new TransformRepresentation(
221:                        getContext(), source, getTransformSheet());
222:
223:                if (this.resultLanguages != null) {
224:                    result.getLanguages().addAll(getResultLanguages());
225:                }
226:
227:                result.setCharacterSet(getResultCharacterSet());
228:                if (this.resultEncodings != null) {
229:                    result.getEncodings().addAll(getResultEncodings());
230:                }
231:
232:                result.setMediaType(getResultMediaType());
233:                return result;
234:            }
235:
236:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.