Source Code Cross Referenced for AbstractDSpaceTransformer.java in  » Content-Management-System » dspace » org » dspace » app » xmlui » cocoon » 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 » Content Management System » dspace » org.dspace.app.xmlui.cocoon 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * AbstractDSpaceTransformer.java
003:         *
004:         * Version: $Revision: 1.14 $
005:         *
006:         * Date: $Date: 2006/05/02 05:30:55 $
007:         *
008:         * Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
009:         * Institute of Technology.  All rights reserved.
010:         *
011:         * Redistribution and use in source and binary forms, with or without
012:         * modification, are permitted provided that the following conditions are
013:         * met:
014:         *
015:         * - Redistributions of source code must retain the above copyright
016:         * notice, this list of conditions and the following disclaimer.
017:         *
018:         * - Redistributions in binary form must reproduce the above copyright
019:         * notice, this list of conditions and the following disclaimer in the
020:         * documentation and/or other materials provided with the distribution.
021:         *
022:         * - Neither the name of the Hewlett-Packard Company nor the name of the
023:         * Massachusetts Institute of Technology nor the names of their
024:         * contributors may be used to endorse or promote products derived from
025:         * this software without specific prior written permission.
026:         *
027:         * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
028:         * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
029:         * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
030:         * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
031:         * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
032:         * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
033:         * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
034:         * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
035:         * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
036:         * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
037:         * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
038:         * DAMAGE.
039:         */
040:
041:        package org.dspace.app.xmlui.cocoon;
042:
043:        import java.io.IOException;
044:        import java.io.UnsupportedEncodingException;
045:        import java.net.URLDecoder;
046:        import java.net.URLEncoder;
047:        import java.sql.SQLException;
048:        import java.util.Map;
049:
050:        import org.apache.avalon.framework.parameters.Parameters;
051:        import org.apache.cocoon.ProcessingException;
052:        import org.apache.cocoon.components.flow.FlowHelper;
053:        import org.apache.cocoon.components.flow.WebContinuation;
054:        import org.apache.cocoon.environment.ObjectModelHelper;
055:        import org.apache.cocoon.environment.Request;
056:        import org.apache.cocoon.environment.SourceResolver;
057:        import org.dspace.app.xmlui.objectmanager.DSpaceObjectManager;
058:        import org.dspace.app.xmlui.utils.ContextUtil;
059:        import org.dspace.app.xmlui.utils.UIException;
060:        import org.dspace.app.xmlui.wing.AbstractWingTransformer;
061:        import org.dspace.app.xmlui.wing.WingException;
062:        import org.dspace.app.xmlui.wing.element.Body;
063:        import org.dspace.app.xmlui.wing.element.Options;
064:        import org.dspace.app.xmlui.wing.element.PageMeta;
065:        import org.dspace.app.xmlui.wing.element.UserMeta;
066:        import org.dspace.app.xmlui.wing.ObjectManager;
067:        import org.dspace.authorize.AuthorizeException;
068:        import org.dspace.core.Constants;
069:        import org.dspace.core.Context;
070:        import org.dspace.eperson.EPerson;
071:        import org.xml.sax.SAXException;
072:
073:        /**
074:         * @author Scott Phillips
075:         */
076:        public abstract class AbstractDSpaceTransformer extends
077:                AbstractWingTransformer implements  DSpaceTransformer {
078:
079:            private static final String NAME_TRIM = "org.dspace.app.xmlui.";
080:
081:            protected Map objectModel;
082:
083:            protected Context context;
084:
085:            protected String contextPath;
086:
087:            protected String servletPath;
088:
089:            protected String sitemapURI;
090:
091:            protected String url;
092:
093:            protected Parameters parameters;
094:
095:            protected EPerson eperson;
096:
097:            protected WebContinuation knot;
098:
099:            // Only access this through getObjectManager, so that we don't have to create one if we don't want too.
100:            private ObjectManager objectManager;
101:
102:            public void setup(SourceResolver resolver, Map objectModel,
103:                    String src, Parameters parameters)
104:                    throws ProcessingException, SAXException, IOException {
105:                this .objectModel = objectModel;
106:                this .parameters = parameters;
107:                try {
108:                    this .context = ContextUtil.obtainContext(objectModel);
109:                    this .eperson = context.getCurrentUser();
110:                    Request request = ObjectModelHelper.getRequest(objectModel);
111:                    this .contextPath = request.getContextPath();
112:                    if (contextPath == null)
113:                        contextPath = "/";
114:
115:                    this .servletPath = request.getServletPath();
116:                    this .sitemapURI = request.getSitemapURI();
117:                    this .knot = FlowHelper.getWebContinuation(objectModel);
118:                } catch (SQLException sqle) {
119:                    handleException(sqle);
120:                }
121:
122:                // Initialize the Wing framework.
123:                try {
124:                    this .setupWing();
125:                } catch (WingException we) {
126:                    throw new ProcessingException(we);
127:                }
128:            }
129:
130:            protected void handleException(Exception e) throws SAXException {
131:                throw new SAXException(
132:                        "An error was encountered while processing the '"
133:                                + this .getComponentName()
134:                                + "' Wing based component: "
135:                                + this .getClass().getName(), e);
136:            }
137:
138:            /** What to add at the end of the body */
139:            public void addBody(Body body) throws SAXException, WingException,
140:                    UIException, SQLException, IOException, AuthorizeException {
141:                // Do nothing
142:            }
143:
144:            /** What to add to the options list */
145:            public void addOptions(Options options) throws SAXException,
146:                    WingException, UIException, SQLException, IOException,
147:                    AuthorizeException {
148:                // Do nothing
149:            }
150:
151:            /** What user metadata to add to the document */
152:            public void addUserMeta(UserMeta userMeta) throws SAXException,
153:                    WingException, UIException, SQLException, IOException,
154:                    AuthorizeException {
155:                // Do nothing
156:            }
157:
158:            /** What page metadata to add to the document */
159:            public void addPageMeta(PageMeta pageMeta) throws SAXException,
160:                    WingException, UIException, SQLException, IOException,
161:                    AuthorizeException {
162:                // Do nothing
163:            }
164:
165:            public ObjectManager getObjectManager() {
166:                if (this .objectManager == null)
167:                    this .objectManager = new DSpaceObjectManager();
168:                return this .objectManager;
169:            }
170:
171:            /** What is a unique name for this component? */
172:            public String getComponentName() {
173:                String name = this .getClass().getName();
174:                if (name.startsWith(NAME_TRIM))
175:                    name = name.substring(NAME_TRIM.length());
176:                return name;
177:            }
178:
179:            /**
180:             * Encode the given string for URL transmission.
181:             * 
182:             * @param unencodedString
183:             *            The unencoded string.
184:             * @return The encoded string
185:             */
186:            public static String URLEncode(String unencodedString)
187:                    throws UIException {
188:                if (unencodedString == null)
189:                    return "";
190:
191:                try {
192:                    return URLEncoder.encode(unencodedString,
193:                            Constants.DEFAULT_ENCODING);
194:                } catch (UnsupportedEncodingException uee) {
195:                    throw new UIException(uee);
196:                }
197:
198:            }
199:
200:            /**
201:             * Decode the given string from URL transmission.
202:             * 
203:             * @param encodedString
204:             *            The encoded string.
205:             * @return The unencoded string
206:             */
207:            public static String URLDecode(String encodedString)
208:                    throws UIException {
209:                try {
210:                    return URLDecoder.decode(encodedString,
211:                            Constants.DEFAULT_ENCODING);
212:                } catch (UnsupportedEncodingException uee) {
213:                    throw new UIException(uee);
214:                }
215:
216:            }
217:
218:            /**
219:             * Generate a URL for the given base URL with the given parameters. This is
220:             * a convenance method to make it easier to generate URL refrences with
221:             * parameters.
222:             * 
223:             * Example
224:             * Map<String,String> parameters = new Map<String,String>();
225:             * parameters.put("arg1","value1");
226:             * parameters.put("arg2","value2");
227:             * parameters.put("arg3","value3");
228:             * String url = genrateURL("/my/url",parameters);
229:             * 
230:             * would result in the string:
231:             * url == "/my/url?arg1=value1&arg2=value2&arg3=value3"
232:             * 
233:             * @param baseURL The baseURL without any parameters.
234:             * @param parameters The parameters to be encoded on in the URL.
235:             * @return The parameterized Post URL.
236:             */
237:            public static String generateURL(String baseURL,
238:                    Map<String, String> parameters) {
239:                boolean first = true;
240:                for (String key : parameters.keySet()) {
241:                    if (first) {
242:                        baseURL += "?";
243:                        first = false;
244:                    } else {
245:                        baseURL += "&";
246:                    }
247:
248:                    baseURL += key + "=" + parameters.get(key);
249:                }
250:
251:                return baseURL;
252:            }
253:
254:            /**
255:             * Recyle
256:             */
257:            public void recycle() {
258:                this .objectModel = null;
259:                this .context = null;
260:                this .contextPath = null;
261:                this .servletPath = null;
262:                this .sitemapURI = null;
263:                this .url = null;
264:                this .parameters = null;
265:                this .eperson = null;
266:                this .knot = null;
267:                this .objectManager = null;
268:                super .recycle();
269:            }
270:
271:            /**
272:             * Dispose
273:             */
274:            public void dispose() {
275:                this.objectModel = null;
276:                this.context = null;
277:                this.contextPath = null;
278:                this.servletPath = null;
279:                this.sitemapURI = null;
280:                this.url = null;
281:                this.parameters = null;
282:                this.eperson = null;
283:                this.knot = null;
284:                this.objectManager = null;
285:                super.dispose();
286:            }
287:
288:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.