Source Code Cross Referenced for JspPageRequest.java in  » Search-Engine » regain » net » sf » regain » util » sharedtag » taglib » 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.taglib 
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-08-10 16:00:46 +0200 (Mi, 10 Aug 2005) $
025:         *   $Author: til132 $
026:         * $Revision: 155 $
027:         */
028:        package net.sf.regain.util.sharedtag.taglib;
029:
030:        import java.io.File;
031:        import java.io.IOException;
032:        import java.net.MalformedURLException;
033:        import java.net.URL;
034:        import java.util.Enumeration;
035:        import java.util.Locale;
036:
037:        import javax.servlet.http.HttpServletRequest;
038:        import javax.servlet.jsp.PageContext;
039:
040:        import net.sf.regain.RegainException;
041:        import net.sf.regain.util.sharedtag.PageRequest;
042:
043:        /**
044:         * Adapter from a JSP page context to a SharedTag PageRequest.
045:         *
046:         * @author Til Schneider, www.murfman.de
047:         */
048:        public class JspPageRequest extends PageRequest {
049:
050:            /** The JSP page context to adapt. */
051:            private PageContext mPageContext;
052:
053:            /** The base URL where the JSP files and resources are located. */
054:            private static URL mBaseUrl;
055:
056:            /** The working directory of the web server. */
057:            private static File mWorkingDir;
058:
059:            /**
060:             * Creates a new instance of JspPageRequest.
061:             * 
062:             * @param pageContext The JSP page context to adapt.
063:             */
064:            public JspPageRequest(PageContext pageContext) {
065:                mPageContext = pageContext;
066:            }
067:
068:            /**
069:             * Gets a request parameter that was given to page via GET or POST.
070:             * 
071:             * @param name The name of the parameter.
072:             * @return The given parameter or <code>null</code> if no such parameter was
073:             *         given.
074:             */
075:            public String getParameter(String name) {
076:                return mPageContext.getRequest().getParameter(name);
077:            }
078:
079:            /**
080:             * Gets all request parameters with the given name that were given to the page
081:             * via GET or POST.
082:             * 
083:             * @param name The name of the parameter.
084:             * @return The parameters or <code>null</code> if no such parameter was
085:             *         given.
086:             * @throws RegainException If getting the parameter failed.
087:             */
088:            public String[] getParameters(String name) throws RegainException {
089:                return mPageContext.getRequest().getParameterValues(name);
090:            }
091:
092:            /**
093:             * Gets the names of the given parameters.
094:             * 
095:             * @return The names of the given parameters.
096:             */
097:            public Enumeration getParameterNames() {
098:                return mPageContext.getRequest().getParameterNames();
099:            }
100:
101:            /**
102:             * Gets the header with the given name.
103:             * 
104:             * @param name The name of the header.
105:             * @return The header or <code>null</code> if no such header exists.
106:             * @throws RegainException If getting the header failed.
107:             */
108:            public String getHeader(String name) throws RegainException {
109:                HttpServletRequest request = (HttpServletRequest) mPageContext
110:                        .getRequest();
111:                return request.getHeader(name);
112:            }
113:
114:            /**
115:             * Gets the header with the given name as date.
116:             * 
117:             * @param name The name of the header.
118:             * @return The date header or <code>-1</code> if no such header exists.
119:             * @throws RegainException If getting the header failed.
120:             */
121:            public long getHeaderAsDate(String name) throws RegainException {
122:                HttpServletRequest request = (HttpServletRequest) mPageContext
123:                        .getRequest();
124:                return request.getDateHeader(name);
125:            }
126:
127:            /**
128:             * Gets the locale of the client.
129:             * 
130:             * @return The locale.
131:             * @throws RegainException If getting the locale failed.
132:             */
133:            public Locale getLocale() throws RegainException {
134:                HttpServletRequest request = (HttpServletRequest) mPageContext
135:                        .getRequest();
136:                return request.getLocale();
137:            }
138:
139:            /**
140:             * Sets an attribute at the page context.
141:             * 
142:             * @param name The name of the attribute to set.
143:             * @param value The value of the attribute to set.
144:             */
145:            public void setContextAttribute(String name, Object value) {
146:                mPageContext.setAttribute(name, value);
147:            }
148:
149:            /**
150:             * Gets an attribute from the page context.
151:             * 
152:             * @param name The name of the attribute to get.
153:             * @return The attribute's value or <code>null</code> if there is no such
154:             *         attribute.
155:             */
156:            public Object getContextAttribute(String name) {
157:                return mPageContext.getAttribute(name);
158:            }
159:
160:            /**
161:             * Sets an attribute at the session.
162:             * 
163:             * @param name The name of the attribute to set.
164:             * @param value The value of the attribute to set.
165:             */
166:            public void setSessionAttribute(String name, Object value) {
167:                mPageContext.getSession().setAttribute(name, value);
168:            }
169:
170:            /**
171:             * Gets an attribute from the session.
172:             * 
173:             * @param name The name of the attribute to get.
174:             * @return The attribute's value or <code>null</code> if there is no such
175:             *         attribute.
176:             */
177:            public Object getSessionAttribute(String name) {
178:                return mPageContext.getSession().getAttribute(name);
179:            }
180:
181:            /**
182:             * Gets an init parameter.
183:             * 
184:             * @param name The name of the init parameter.
185:             * @return The value of the init parameter.
186:             */
187:            public String getInitParameter(String name) {
188:                return mPageContext.getServletContext().getInitParameter(name);
189:            }
190:
191:            /**
192:             * Gets the base URL where the JSP files and resources are located.
193:             * 
194:             * @return The base URL where the JSP files and resources are located.
195:             * @throws RegainException If getting the base URL failed.
196:             */
197:            public URL getResourceBaseUrl() throws RegainException {
198:                if (mBaseUrl == null) {
199:                    try {
200:                        mBaseUrl = mPageContext.getServletContext()
201:                                .getResource("/");
202:                        System.out.println("mBaseUrl: " + mBaseUrl);
203:                    } catch (MalformedURLException exc) {
204:                        throw new RegainException("Getting base URL failed",
205:                                exc);
206:                    }
207:                }
208:                return mBaseUrl;
209:            }
210:
211:            /**
212:             * Gets the working directory of the web server.
213:             * 
214:             * @return The working directory of the web server.
215:             * @throws RegainException If getting the working directory failed.
216:             */
217:            public File getWorkingDir() throws RegainException {
218:                if (mWorkingDir == null) {
219:                    // Check whether we get a realpath
220:                    String realpath = mPageContext.getServletContext()
221:                            .getRealPath(".");
222:                    if (realpath != null) {
223:                        // Use the parent directory of the realpath
224:                        // E.g. "c:\tomcat\webapps\regain\." -> "c:\tomcat\webapps"
225:                        // NOTE: getCanonicalFile is needed to get rid of "\." is a save way
226:                        try {
227:                            mWorkingDir = new File(realpath).getCanonicalFile()
228:                                    .getParentFile();
229:                        } catch (IOException exc) {
230:                            throw new RegainException(
231:                                    "Getting the working directory of "
232:                                            + "the web server failed", exc);
233:                        }
234:                    } else {
235:                        // We got no real path -> Return the current directory
236:                        mWorkingDir = new File(".");
237:                    }
238:                }
239:                return mWorkingDir;
240:            }
241:
242:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.