Source Code Cross Referenced for SharedTagResource.java in  » Search-Engine » regain » net » sf » regain » util » sharedtag » simple » 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 » Search Engine » regain » net.sf.regain.util.sharedtag.simple 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * regain - A file search engine providing plenty of formats
003:         * Copyright (C) 2004  Til Schneider
004:         *
005:         * This library is free software; you can redistribute it and/or
006:         * modify it under the terms of the GNU Lesser General Public
007:         * License as published by the Free Software Foundation; either
008:         * version 2.1 of the License, or (at your option) any later version.
009:         *
010:         * This library is distributed in the hope that it will be useful,
011:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013:         * Lesser General Public License for more details.
014:         *
015:         * You should have received a copy of the GNU Lesser General Public
016:         * License along with this library; if not, write to the Free Software
017:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
018:         *
019:         * Contact: Til Schneider, info@murfman.de
020:         *
021:         * CVS information:
022:         *  $RCSfile$
023:         *   $Source$
024:         *     $Date: 2005-10-18 09:51:30 +0200 (Di, 18 Okt 2005) $
025:         *   $Author: til132 $
026:         * $Revision: 175 $
027:         */
028:        package net.sf.regain.util.sharedtag.simple;
029:
030:        import java.io.ByteArrayOutputStream;
031:        import java.io.File;
032:        import java.io.PrintStream;
033:
034:        import net.sf.regain.RegainException;
035:        import net.sf.regain.util.sharedtag.PageRequest;
036:        import net.sf.regain.util.sharedtag.PageResponse;
037:
038:        import org.apache.log4j.Logger;
039:
040:        import simple.http.Request;
041:        import simple.http.Response;
042:        import simple.http.serve.BasicResource;
043:        import simple.http.serve.Context;
044:
045:        /**
046:         * A simpleweb resource representing one JSP page.
047:         *
048:         * @see simple.http.serve.Resource
049:         * @author Til Schneider, www.murfman.de
050:         */
051:        public class SharedTagResource extends BasicResource {
052:
053:            /** The encoding used by the simpleweb implementation of shared tags. */
054:            public static final String SIMPLE_TAG_ENCODING = "UTF-8";
055:
056:            /** The logger for this class */
057:            private static Logger mLog = Logger
058:                    .getLogger(SharedTagResource.class);
059:
060:            /** The base directory where the provided files are located. */
061:            private static File mBaseDir;
062:
063:            /** The root executer holding the parsed JSP page. */
064:            private Executer mRootTagExecuter;
065:
066:            /**
067:             * Creates a new instance of SharedTagResource.
068:             * 
069:             * @param context The context of this resource.
070:             * @param root The root executer holding the parsed JSP page.
071:             * @throws RegainException If parsing the JSP file failed.
072:             */
073:            public SharedTagResource(Context context, Executer root)
074:                    throws RegainException {
075:                super (context);
076:
077:                mRootTagExecuter = root;
078:            }
079:
080:            /**
081:             * Processes a request.
082:             * 
083:             * @param req The request.
084:             * @param resp The response.
085:             * @throws Exception If executing the JSP page failed.
086:             */
087:            protected synchronized void process(Request req, Response resp)
088:                    throws Exception {
089:                process(req, resp, mRootTagExecuter, null);
090:            }
091:
092:            /**
093:             * Processes a request.
094:             * 
095:             * @param req The request.
096:             * @param resp The response.
097:             * @param executer The executer to use.
098:             * @param error The error to show. Is <code>null</code> if no error page is
099:             *        shown.
100:             * @throws Exception If executing the JSP page failed.
101:             */
102:            private synchronized void process(Request req, Response resp,
103:                    Executer executer, Throwable error) throws Exception {
104:                // Write the page to a buffer first
105:                // If an exception should be thrown the user gets a clear error message
106:                ByteArrayOutputStream stream = new ByteArrayOutputStream();
107:                PrintStream printStream = new PrintStream(stream, false,
108:                        SIMPLE_TAG_ENCODING);
109:
110:                PageRequest request = new SimplePageRequest(req);
111:                PageResponse response = new SimplePageResponse(this , req, resp,
112:                        printStream, SIMPLE_TAG_ENCODING);
113:
114:                // Add the error to the page attributes
115:                if (error != null) {
116:                    request.setContextAttribute("page.exception", error);
117:                }
118:
119:                try {
120:                    executer.execute(request, response);
121:                } catch (RedirectException exc) {
122:                    // Send a redirect
123:                    resp.set("Location", exc.getUrl());
124:                    handle(req, resp, 303);
125:                    return;
126:                } catch (Exception exc) {
127:                    mLog.error("Processing page failed", exc);
128:                    if (error == null) {
129:                        // This is the normal page -> Show the error page
130:                        try {
131:                            Executer errorExecuter = loadErrorPage();
132:                            process(req, resp, errorExecuter, exc);
133:                        } catch (RegainException loadingExc) {
134:                            mLog.error("Processing error page failed",
135:                                    loadingExc);
136:
137:                            // Throw the original error, so a simple error page is shown
138:                            throw exc;
139:                        }
140:                    } else {
141:                        // This already is the error page -> Show a simple error
142:                        throw exc;
143:                    }
144:                } finally {
145:                    printStream.close();
146:                    stream.close();
147:                }
148:
149:                // The page has been generated without exception -> Send it to the user
150:                resp.set("Content-Type", "text/html; charset="
151:                        + SIMPLE_TAG_ENCODING);
152:                PrintStream pageStream = resp.getPrintStream();
153:                try {
154:                    stream.writeTo(pageStream);
155:                } finally {
156:                    pageStream.close();
157:                }
158:            }
159:
160:            /**
161:             * Loads the error page executer.
162:             * 
163:             * @return The error page executer.
164:             * @throws RegainException If loading the error page executer failed.
165:             */
166:            private Executer loadErrorPage() throws RegainException {
167:                if (mBaseDir == null) {
168:                    mBaseDir = new File(context.getBasePath());
169:                }
170:
171:                return new ExecuterParser().parse(mBaseDir, "errorpage.jsp");
172:            }
173:
174:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.