Source Code Cross Referenced for ExternalLink.java in  » J2EE » wicket » org » apache » wicket » markup » html » link » 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 » J2EE » wicket » org.apache.wicket.markup.html.link 
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.wicket.markup.html.link;
018:
019:        import org.apache.wicket.IPageMap;
020:        import org.apache.wicket.RequestCycle;
021:        import org.apache.wicket.markup.ComponentTag;
022:        import org.apache.wicket.markup.MarkupStream;
023:        import org.apache.wicket.markup.html.WebMarkupContainer;
024:        import org.apache.wicket.model.IModel;
025:        import org.apache.wicket.model.Model;
026:        import org.apache.wicket.util.string.Strings;
027:
028:        /**
029:         * A simple anchor link (<a href="http://url">) pointing to any URL.
030:         * Usually this is used for links to destinations outside of Wicket.
031:         * 
032:         * @author Juergen Donnerstag
033:         */
034:        public class ExternalLink extends WebMarkupContainer {
035:            private static final long serialVersionUID = 1L;
036:
037:            /** the href attribute. */
038:            private final IModel href;
039:
040:            /** this links' label. */
041:            private final IModel label;
042:
043:            private boolean contextRelative = false;
044:
045:            /**
046:             * The popup specification. If not-null, a javascript on-click event handler
047:             * will be generated that opens a new window using the popup properties.
048:             */
049:            private PopupSettings popupSettings = null;
050:
051:            /**
052:             * Constructor.
053:             * 
054:             * @param id
055:             *            See Component
056:             * @param href
057:             *            the href attribute to set
058:             * @param label
059:             *            the label (body)
060:             */
061:            public ExternalLink(final String id, final String href,
062:                    final String label) {
063:                super (id);
064:
065:                this .href = (href != null ? new Model(href) : null);
066:                this .label = (label != null ? new Model(label) : null);
067:            }
068:
069:            /**
070:             * Constructor.
071:             * 
072:             * @param id
073:             *            The name of this component
074:             * @param href
075:             *            the href attribute to set
076:             */
077:            public ExternalLink(final String id, final String href) {
078:                this (id, href, null);
079:            }
080:
081:            /**
082:             * Constructor.
083:             * 
084:             * @param id
085:             *            See Component
086:             * @param href
087:             *            the href attribute to set
088:             * @param label
089:             *            the label (body)
090:             */
091:            public ExternalLink(final String id, final IModel href,
092:                    final IModel label) {
093:                super (id);
094:
095:                this .href = wrap(href);
096:                this .label = wrap(label);
097:            }
098:
099:            /**
100:             * Constructor.
101:             * 
102:             * @param id
103:             *            The name of this component
104:             * @param href
105:             *            the href attribute to set
106:             */
107:            public ExternalLink(final String id, final IModel href) {
108:                this (id, href, null);
109:            }
110:
111:            /**
112:             * Gets the popup specification. If not-null, a javascript on-click event
113:             * handler will be generated that opens a new window using the popup
114:             * properties.
115:             * 
116:             * @return the popup specification.
117:             */
118:            public final PopupSettings getPopupSettings() {
119:                return popupSettings;
120:            }
121:
122:            /**
123:             * Sets the popup specification. If not-null, a javascript on-click event
124:             * handler will be generated that opens a new window using the popup
125:             * properties.
126:             * 
127:             * @param popupSettings
128:             *            the popup specification.
129:             * @return This
130:             */
131:            public final ExternalLink setPopupSettings(
132:                    final PopupSettings popupSettings) {
133:                this .popupSettings = popupSettings;
134:                return this ;
135:            }
136:
137:            /**
138:             * Processes the component tag.
139:             * 
140:             * @param tag
141:             *            Tag to modify
142:             * @see org.apache.wicket.Component#onComponentTag(org.apache.wicket.markup.ComponentTag)
143:             */
144:            protected void onComponentTag(ComponentTag tag) {
145:                super .onComponentTag(tag);
146:                if (href != null) {
147:                    Object hrefValue = href.getObject();
148:                    if (hrefValue != null) {
149:                        String url = hrefValue.toString();
150:
151:                        if (contextRelative) {
152:                            if (url.length() > 0 && url.charAt(0) == '/') {
153:                                url = url.substring(1);
154:                            }
155:                            url = RequestCycle.get().getRequest()
156:                                    .getRelativePathPrefixToContextRoot()
157:                                    + url;
158:                        }
159:
160:                        // if the tag is an anchor proper
161:                        if (tag.getName().equalsIgnoreCase("a")
162:                                || tag.getName().equalsIgnoreCase("link")
163:                                || tag.getName().equalsIgnoreCase("area")) {
164:                            // generate the href attribute
165:                            tag.put("href", Strings.replaceAll(url, "&",
166:                                    "&"));
167:
168:                            // Add any popup script
169:                            if (popupSettings != null) {
170:                                // NOTE: don't encode to HTML as that is not valid
171:                                // JavaScript
172:                                tag.put("onclick", popupSettings
173:                                        .getPopupJavaScript());
174:                            }
175:                        } else {
176:                            // generate a popup script by asking popup settings for one
177:                            if (popupSettings != null) {
178:                                popupSettings.setTarget("'" + url + "'");
179:                                String popupScript = popupSettings
180:                                        .getPopupJavaScript();
181:                                tag.put("onclick", popupScript);
182:                            } else {
183:                                // or generate an onclick JS handler directly
184:                                tag.put("onclick", "window.location.href='"
185:                                        + url + "';");
186:                            }
187:                        }
188:                    }
189:
190:                    if (popupSettings != null) {
191:                        IPageMap popupPageMap = popupSettings.getPageMap(this );
192:                        if (popupPageMap != null) {
193:                            tag.put("target", popupPageMap.getName());
194:                        }
195:                    }
196:                }
197:            }
198:
199:            /**
200:             * Handle the container's body.
201:             * 
202:             * @param markupStream
203:             *            The markup stream
204:             * @param openTag
205:             *            The open tag for the body
206:             * @see org.apache.wicket.Component#onComponentTagBody(org.apache.wicket.markup.MarkupStream,
207:             *      org.apache.wicket.markup.ComponentTag)
208:             */
209:            protected void onComponentTagBody(MarkupStream markupStream,
210:                    ComponentTag openTag) {
211:                if ((label != null) && (label.getObject() != null)) {
212:                    replaceComponentTagBody(markupStream, openTag,
213:                            getModelObjectAsString(label.getObject()));
214:                } else {
215:                    super .onComponentTagBody(markupStream, openTag);
216:                }
217:            }
218:
219:            /**
220:             * @return True if this link is automatically prepended with ../ to make it
221:             *         relative to the context root.
222:             */
223:            public boolean isContextRelative() {
224:                return contextRelative;
225:            }
226:
227:            /**
228:             * Set to true if this link should be automatically prepended with ../ to
229:             * make it relative to the context root.
230:             * 
231:             * @param contextRelative
232:             * @return This for chaining
233:             */
234:            public ExternalLink setContextRelative(boolean contextRelative) {
235:                this.contextRelative = contextRelative;
236:                return this;
237:            }
238:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.