Source Code Cross Referenced for BaseTag.java in  » Web-Framework » struts-1.3.8 » org » apache » struts » taglib » html » 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 » struts 1.3.8 » org.apache.struts.taglib.html 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: BaseTag.java 471754 2006-11-06 14:55:09Z husted $
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:        package org.apache.struts.taglib.html;
022:
023:        import org.apache.struts.Globals;
024:        import org.apache.struts.taglib.TagUtils;
025:        import org.apache.struts.util.MessageResources;
026:        import org.apache.struts.util.RequestUtils;
027:
028:        import javax.servlet.http.HttpServletRequest;
029:        import javax.servlet.jsp.JspException;
030:        import javax.servlet.jsp.JspWriter;
031:        import javax.servlet.jsp.PageContext;
032:        import javax.servlet.jsp.tagext.TagSupport;
033:
034:        import java.io.IOException;
035:
036:        import java.util.StringTokenizer;
037:
038:        /**
039:         * Renders an HTML <base> element with an href attribute pointing to the
040:         * absolute location of the enclosing JSP page. This tag is only valid when
041:         * nested inside a head tag body. The presence of this tag allows the browser
042:         * to resolve relative URL's to images, CSS stylesheets  and other resources
043:         * in a manner independent of the URL used to call the ActionServlet.
044:         *
045:         * @version $Rev: 471754 $ $Date: 2005-09-20 02:29:01 -0400 (Tue, 20 Sep 2005)
046:         *          $
047:         */
048:        public class BaseTag extends TagSupport {
049:            /**
050:             * The message resources for this package.
051:             */
052:            protected static MessageResources messages = MessageResources
053:                    .getMessageResources(Constants.Package + ".LocalStrings");
054:            protected final String REF_SITE = "site";
055:            protected final String REF_PAGE = "page";
056:
057:            /**
058:             * The server name to use instead of request.getServerName().
059:             */
060:            protected String server = null;
061:
062:            /**
063:             * The target window for this base reference.
064:             */
065:            protected String target = null;
066:
067:            /**
068:             * The reference to which the base will created.
069:             */
070:            protected String ref = REF_PAGE;
071:
072:            /**
073:             * Gets the reference to which the base will be created
074:             */
075:            public String getRef() {
076:                return (this .ref);
077:            }
078:
079:            /**
080:             * Sets the reference to which the base will be created.
081:             *
082:             * @param ref Either "page" to render the base as the jsp path located, or
083:             *            "site" as the application's context
084:             */
085:            public void setRef(String ref) {
086:                if (ref == null) {
087:                    throw new IllegalArgumentException(
088:                            "Ref attribute cannot be null");
089:                }
090:
091:                ref = ref.toLowerCase();
092:
093:                if (ref.equals(REF_PAGE) || ref.equals(REF_SITE)) {
094:                    this .ref = ref;
095:                } else {
096:                    throw new IllegalArgumentException(
097:                            "Ref attribute must either be " + "'" + REF_PAGE
098:                                    + "' or '" + REF_SITE + "'");
099:                }
100:            }
101:
102:            public String getTarget() {
103:                return (this .target);
104:            }
105:
106:            public void setTarget(String target) {
107:                this .target = target;
108:            }
109:
110:            /**
111:             * Process the start of this tag.
112:             *
113:             * @throws JspException if a JSP exception has occurred
114:             */
115:            public int doStartTag() throws JspException {
116:                HttpServletRequest request = (HttpServletRequest) pageContext
117:                        .getRequest();
118:                String serverName = (this .server == null) ? request
119:                        .getServerName() : this .server;
120:
121:                int port = request.getServerPort();
122:                String headerHost = request.getHeader("Host");
123:
124:                if ((serverName == null) && (headerHost != null)) {
125:                    StringTokenizer tokenizer = new StringTokenizer(headerHost,
126:                            ":");
127:
128:                    serverName = tokenizer.nextToken();
129:
130:                    if (tokenizer.hasMoreTokens()) {
131:                        String portS = tokenizer.nextToken();
132:
133:                        try {
134:                            port = Integer.parseInt(portS);
135:                        } catch (Exception e) {
136:                            port = 80;
137:                        }
138:                    } else {
139:                        port = 80;
140:                    }
141:                }
142:
143:                String baseTag = renderBaseElement(request.getScheme(),
144:                        serverName, port, request.getRequestURI());
145:
146:                JspWriter out = pageContext.getOut();
147:
148:                try {
149:                    out.write(baseTag);
150:                } catch (IOException e) {
151:                    pageContext.setAttribute(Globals.EXCEPTION_KEY, e,
152:                            PageContext.REQUEST_SCOPE);
153:                    throw new JspException(messages.getMessage("common.io", e
154:                            .toString()));
155:                }
156:
157:                return EVAL_BODY_INCLUDE;
158:            }
159:
160:            /**
161:             * Render a fully formed HTML &lt;base&gt; element and return it as a
162:             * String.
163:             *
164:             * @param scheme     The scheme used in the url (ie. http or https).
165:             * @param serverName
166:             * @param port
167:             * @param uri        The portion of the url from the protocol name up to
168:             *                   the query string.
169:             * @return String An HTML &lt;base&gt; element.
170:             * @since Struts 1.1
171:             */
172:            protected String renderBaseElement(String scheme,
173:                    String serverName, int port, String uri) {
174:                StringBuffer tag = new StringBuffer("<base href=\"");
175:
176:                if (ref.equals(REF_SITE)) {
177:                    StringBuffer contextBase = new StringBuffer(
178:                            ((HttpServletRequest) pageContext.getRequest())
179:                                    .getContextPath());
180:
181:                    contextBase.append("/");
182:                    tag.append(RequestUtils.createServerUriStringBuffer(scheme,
183:                            serverName, port, contextBase.toString())
184:                            .toString());
185:                } else {
186:                    tag.append(RequestUtils.createServerUriStringBuffer(scheme,
187:                            serverName, port, uri).toString());
188:                }
189:
190:                tag.append("\"");
191:
192:                if (this .target != null) {
193:                    tag.append(" target=\"");
194:                    tag.append(this .target);
195:                    tag.append("\"");
196:                }
197:
198:                if (TagUtils.getInstance().isXhtml(this .pageContext)) {
199:                    tag.append(" />");
200:                } else {
201:                    tag.append(">");
202:                }
203:
204:                return tag.toString();
205:            }
206:
207:            /**
208:             * Returns the server.
209:             *
210:             * @return String
211:             */
212:            public String getServer() {
213:                return this .server;
214:            }
215:
216:            /**
217:             * Sets the server.
218:             *
219:             * @param server The server to set
220:             */
221:            public void setServer(String server) {
222:                this.server = server;
223:            }
224:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.