Source Code Cross Referenced for LinkInfo.java in  » Content-Management-System » apache-lenya-2.0 » org » apache » cocoon » portal » impl » 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 » apache lenya 2.0 » org.apache.cocoon.portal.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.apache.cocoon.portal.impl;
018:
019:        import java.io.UnsupportedEncodingException;
020:        import java.util.ArrayList;
021:        import java.util.Enumeration;
022:
023:        import org.apache.cocoon.environment.Request;
024:        import org.apache.cocoon.environment.wrapper.RequestParameters;
025:        import org.apache.cocoon.util.NetUtils;
026:        import org.apache.commons.lang.BooleanUtils;
027:
028:        /**
029:         * Helper class containing the information about common parts for each link
030:         * that will be generated in the portal page.
031:         *
032:         * @version $Id: LinkInfo.java 433543 2006-08-22 06:22:54Z crossley $
033:         */
034:        public class LinkInfo {
035:
036:            /** Link base contains the base url for the http protocol. */
037:            protected final String httpLinkBase;
038:            protected final String secureLinkBase;
039:            protected boolean hasParameters = false;
040:            protected final ArrayList comparableEvents = new ArrayList(5);
041:            protected final StringBuffer url = new StringBuffer();
042:            protected final Request request;
043:
044:            /** Is the page called using https? */
045:            protected final boolean isSecure;
046:
047:            public LinkInfo(Request request, int defaultPort,
048:                    int defaultSecurePort) {
049:                this .isSecure = request.getScheme().equals("https");
050:                // create relative url
051:                String relativeURI = getRelativeURI(request);
052:
053:                this .request = request;
054:                this .secureLinkBase = getSecureLinkBase(request, relativeURI,
055:                        defaultSecurePort);
056:                this .httpLinkBase = getHttpLinkBase(request, relativeURI,
057:                        defaultPort);
058:            }
059:
060:            protected String getRelativeURI(Request request) {
061:                String relativeURI = request.getSitemapURI();
062:                final int pos = relativeURI.lastIndexOf('/');
063:                if (pos != -1) {
064:                    relativeURI = relativeURI.substring(pos + 1);
065:                }
066:                return relativeURI;
067:            }
068:
069:            /**
070:             * Return the base url for a secure http request
071:             * @param relativeURI The current relative URI
072:             * @param defaultPort The default port to use
073:             * @return A String containing the base url for a secure http request
074:             */
075:            protected String getSecureLinkBase(Request request,
076:                    String relativeURI, int defaultPort) {
077:                return (this .isSecure) ? relativeURI : getAbsoluteUrl(request,
078:                        true, defaultPort);
079:            }
080:
081:            /**
082:             * Return the url for an http request
083:             * @param relativeURI The current relative URI
084:             * @param defaultPort The default port to use
085:             * @return A string containing the base url for an http request
086:             */
087:            protected String getHttpLinkBase(Request request,
088:                    String relativeURI, int defaultPort) {
089:                return (this .isSecure) ? getAbsoluteUrl(request, false,
090:                        defaultPort) : relativeURI;
091:            }
092:
093:            /**
094:             * Return the absolute URL for a reqeust
095:             * @param request The current Request
096:             * @param useSecure true if the Request should be secure
097:             * @param port The port to use
098:             * @return A String containing the absolute url for a request
099:             */
100:            protected String getAbsoluteUrl(Request request, boolean useSecure,
101:                    int port) {
102:                final StringBuffer buffer = new StringBuffer();
103:                if (useSecure) {
104:                    buffer.append("https://");
105:                } else {
106:                    buffer.append("http://");
107:                }
108:                buffer.append(request.getServerName());
109:                if ((useSecure && port != 443) || (!useSecure && port != 80)) {
110:                    buffer.append(':');
111:                    buffer.append(port);
112:                }
113:                if (request.getContextPath().length() > 0) {
114:                    buffer.append(request.getContextPath());
115:                }
116:                buffer.append('/');
117:                if (request.getSitemapURIPrefix().length() > 0) {
118:                    buffer.append(request.getSitemapURIPrefix());
119:                }
120:                buffer.append(request.getSitemapURI());
121:                return buffer.toString();
122:            }
123:
124:            public String getBase(Boolean secure) {
125:                // if no information is provided, we stay with the same protocol
126:                if (secure == null) {
127:                    secure = BooleanUtils.toBooleanObject(this .isSecure);
128:                }
129:                if (secure.booleanValue()) {
130:                    return this .secureLinkBase + this .url.toString();
131:                }
132:                return this .httpLinkBase + this .url.toString();
133:            }
134:
135:            public LinkInfo appendToBase(String value) {
136:                this .url.append(value);
137:                return this ;
138:            }
139:
140:            public LinkInfo appendToBase(char c) {
141:                this .url.append(c);
142:                return this ;
143:            }
144:
145:            public void deleteParameterFromBase(String parameterName) {
146:                if (this .hasParameters) {
147:                    final int pos = this .url.toString().indexOf("?");
148:                    final String queryString = this .url.substring(pos + 1);
149:                    final RequestParameters params = new RequestParameters(
150:                            queryString);
151:                    if (params.getParameter(parameterName) != null) {
152:                        // the parameter is available, so remove it
153:                        this .url.delete(pos, this .url.length() + 1);
154:                        this .hasParameters = false;
155:
156:                        Enumeration enumeration = params.getParameterNames();
157:                        while (enumeration.hasMoreElements()) {
158:                            final String paramName = (String) enumeration
159:                                    .nextElement();
160:                            if (!paramName.equals(parameterName)) {
161:                                String[] values = params
162:                                        .getParameterValues(paramName);
163:                                for (int i = 0; i < values.length; i++) {
164:                                    this .addParameterToBase(paramName,
165:                                            values[i]);
166:                                }
167:                            }
168:                        }
169:                    }
170:                }
171:            }
172:
173:            public void addParameterToBase(String name, String value) {
174:                if (this .hasParameters) {
175:                    this .appendToBase('&');
176:                } else {
177:                    this .appendToBase('?');
178:                }
179:                try {
180:                    this .appendToBase(name).appendToBase('=').appendToBase(
181:                            NetUtils.encode(value, "utf-8"));
182:                } catch (UnsupportedEncodingException uee) {
183:                    // ignore this as utf-8 is always supported
184:                }
185:                this .hasParameters = true;
186:            }
187:
188:            public boolean hasParameters() {
189:                return this.hasParameters;
190:            }
191:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.