Source Code Cross Referenced for ServerData.java in  » Web-Framework » TURBINE » org » apache » turbine » util » 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 » TURBINE » org.apache.turbine.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.apache.turbine.util;
002:
003:        /*
004:         * Licensed to the Apache Software Foundation (ASF) under one
005:         * or more contributor license agreements.  See the NOTICE file
006:         * distributed with this work for additional information
007:         * regarding copyright ownership.  The ASF licenses this file
008:         * to you under the Apache License, Version 2.0 (the
009:         * "License"); you may not use this file except in compliance
010:         * with the License.  You may obtain a copy of the License at
011:         *
012:         *   http://www.apache.org/licenses/LICENSE-2.0
013:         *
014:         * Unless required by applicable law or agreed to in writing,
015:         * software distributed under the License is distributed on an
016:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017:         * KIND, either express or implied.  See the License for the
018:         * specific language governing permissions and limitations
019:         * under the License.
020:         */
021:
022:        import javax.servlet.http.HttpServletRequest;
023:
024:        import org.apache.commons.lang.StringUtils;
025:
026:        import org.apache.commons.logging.Log;
027:        import org.apache.commons.logging.LogFactory;
028:
029:        import org.apache.turbine.util.uri.URIConstants;
030:
031:        /**
032:         * Holds basic server information under which Turbine is running.
033:         * This class is accessable via the RunData object within the Turbine
034:         * system.  You can also use it as a placeholder for this information
035:         * if you are only emulating a servlet system.
036:         *
037:         * @author <a href="mailto:burton@apache.org">Kevin A. Burton</a>
038:         * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
039:         * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
040:         * @version $Id: ServerData.java 534527 2007-05-02 16:10:59Z tv $
041:         */
042:        public class ServerData {
043:            /** Cached serverName, */
044:            private String serverName = null;
045:
046:            /** Cached serverPort. */
047:            private int serverPort = 0;
048:
049:            /** Cached serverScheme. */
050:            private String serverScheme = null;
051:
052:            /** Cached script name. */
053:            private String scriptName = null;
054:
055:            /** Cached context path. */
056:            private String contextPath = null;
057:
058:            /** Logging */
059:            private static Log log = LogFactory.getLog(ServerData.class);
060:
061:            /**
062:             * Constructor.
063:             *
064:             * @param serverName The server name.
065:             * @param serverPort The server port.
066:             * @param serverScheme The server scheme.
067:             * @param scriptName The script name.
068:             * @param contextPath The context Path
069:             */
070:            public ServerData(String serverName, int serverPort,
071:                    String serverScheme, String scriptName, String contextPath) {
072:                if (log.isDebugEnabled()) {
073:                    StringBuffer sb = new StringBuffer();
074:                    sb.append("Constructor(");
075:                    sb.append(serverName);
076:                    sb.append(", ");
077:                    sb.append(serverPort);
078:                    sb.append(", ");
079:                    sb.append(serverScheme);
080:                    sb.append(", ");
081:                    sb.append(scriptName);
082:                    sb.append(", ");
083:                    sb.append(contextPath);
084:                    sb.append(")");
085:                    log.debug(sb.toString());
086:                }
087:
088:                setServerName(serverName);
089:                setServerPort(serverPort);
090:                setServerScheme(serverScheme);
091:                setScriptName(scriptName);
092:                setContextPath(contextPath);
093:            }
094:
095:            /**
096:             * Copy-Constructor
097:             *
098:             * @param serverData A ServerData Object
099:             */
100:            public ServerData(ServerData serverData) {
101:                log.debug("Copy Constructor(" + serverData + ")");
102:
103:                setServerName(serverData.getServerName());
104:                setServerPort(serverData.getServerPort());
105:                setServerScheme(serverData.getServerScheme());
106:                setScriptName(serverData.getScriptName());
107:                setContextPath(serverData.getContextPath());
108:            }
109:
110:            /**
111:             * A C'tor that takes a HTTP Request object and
112:             * builds the server data from its contents
113:             *
114:             * @param req The HTTP Request
115:             */
116:            public ServerData(HttpServletRequest req) {
117:                setServerName(req.getServerName());
118:                setServerPort(req.getServerPort());
119:                setServerScheme(req.getScheme());
120:                setScriptName(req.getServletPath());
121:                setContextPath(req.getContextPath());
122:            }
123:
124:            /**
125:             * generates a new Object with the same values as this one.
126:             *
127:             * @return A cloned object.
128:             */
129:            public Object clone() {
130:                log.debug("clone()");
131:                return new ServerData(this );
132:            }
133:
134:            /**
135:             * Get the name of the server.
136:             *
137:             * @return A String.
138:             */
139:            public String getServerName() {
140:                return StringUtils.isEmpty(serverName) ? "" : serverName;
141:            }
142:
143:            /**
144:             * Sets the cached serverName.
145:             *
146:             * @param serverName the server name.
147:             */
148:            public void setServerName(String serverName) {
149:                log.debug("setServerName(" + serverName + ")");
150:                this .serverName = serverName;
151:            }
152:
153:            /**
154:             * Get the server port.
155:             *
156:             * @return the server port.
157:             */
158:            public int getServerPort() {
159:                return this .serverPort;
160:            }
161:
162:            /**
163:             * Sets the cached serverPort.
164:             *
165:             * @param serverPort the server port.
166:             */
167:            public void setServerPort(int serverPort) {
168:                log.debug("setServerPort(" + serverPort + ")");
169:                this .serverPort = serverPort;
170:            }
171:
172:            /**
173:             * Get the server scheme.
174:             *
175:             * @return the server scheme.
176:             */
177:            public String getServerScheme() {
178:                return StringUtils.isEmpty(serverScheme) ? "" : serverScheme;
179:            }
180:
181:            /**
182:             * Sets the cached serverScheme.
183:             *
184:             * @param serverScheme the server scheme.
185:             */
186:            public void setServerScheme(String serverScheme) {
187:                log.debug("setServerScheme(" + serverScheme + ")");
188:                this .serverScheme = serverScheme;
189:            }
190:
191:            /**
192:             * Get the script name
193:             *
194:             * @return the script name.
195:             */
196:            public String getScriptName() {
197:                return StringUtils.isEmpty(scriptName) ? "" : scriptName;
198:            }
199:
200:            /**
201:             * Set the script name.
202:             *
203:             * @param scriptName the script name.
204:             */
205:            public void setScriptName(String scriptName) {
206:                log.debug("setScriptName(" + scriptName + ")");
207:                this .scriptName = scriptName;
208:            }
209:
210:            /**
211:             * Get the context path.
212:             *
213:             * @return the context path.
214:             */
215:            public String getContextPath() {
216:                return StringUtils.isEmpty(contextPath) ? "" : contextPath;
217:            }
218:
219:            /**
220:             * Set the context path.
221:             *
222:             * @param contextPath A String.
223:             */
224:            public void setContextPath(String contextPath) {
225:                log.debug("setContextPath(" + contextPath + ")");
226:                this .contextPath = contextPath;
227:            }
228:
229:            /**
230:             * Appends the Host URL to the supplied StringBuffer.
231:             *
232:             * @param url A StringBuffer object
233:             */
234:            public void getHostUrl(StringBuffer url) {
235:                url.append(getServerScheme());
236:                url.append("://");
237:                url.append(getServerName());
238:                if ((getServerScheme().equals(URIConstants.HTTP) && getServerPort() != URIConstants.HTTP_PORT)
239:                        || (getServerScheme().equals(URIConstants.HTTPS) && getServerPort() != URIConstants.HTTPS_PORT)) {
240:                    url.append(":");
241:                    url.append(getServerPort());
242:                }
243:            }
244:
245:            /**
246:             * Returns this object as an URL.
247:             *
248:             * @return The contents of this object as a String
249:             */
250:            public String toString() {
251:                StringBuffer url = new StringBuffer();
252:
253:                getHostUrl(url);
254:
255:                url.append(getContextPath());
256:                url.append(getScriptName());
257:                return url.toString();
258:            }
259:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.