001: /*
002: * $Id: ImageMap.java 5231 2006-04-01 15:34:49 -0800 (Sat, 01 Apr 2006) joco01 $
003: * $Revision: 1.9 $ $Date: 2006-04-01 15:34:49 -0800 (Sat, 01 Apr 2006) $
004: *
005: * ==============================================================================
006: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
007: * use this file except in compliance with the License. You may obtain a copy of
008: * the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
014: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
015: * License for the specific language governing permissions and limitations under
016: * the License.
017: */
018: package wicket.markup.html.link;
019:
020: import wicket.Page;
021: import wicket.PageMap;
022: import wicket.RequestCycle;
023: import wicket.Session;
024: import wicket.markup.ComponentTag;
025: import wicket.markup.html.WebMarkupContainer;
026: import wicket.util.string.Strings;
027:
028: /**
029: * Implementation of an <a
030: * href="http://www.w3.org/TR/REC-html40/present/frames.html#h-16.5">inline
031: * frame</a> component. Must be used with an iframe (<iframe src...)
032: * element. The src attribute will be generated.
033: *
034: * @author Sven Meier
035: * @author Ralf Ebert
036: *
037: * @deprecated will be replaced by {@link InlineFrame} in Wicket 2.0 as that's a
038: * better name for it.
039: */
040: public class InternalFrame extends WebMarkupContainer implements
041: ILinkListener {
042: private static final long serialVersionUID = 1L;
043:
044: /** The link. */
045: private final IPageLink pageLink;
046:
047: /**
048: * The pagemap name where the page that will be created by this inline frame
049: * will be created in.
050: */
051: private final String pageMapName;
052:
053: /**
054: * Constructs an inline frame that instantiates the given Page class when
055: * the content of the inline frame is requested. The instantiated Page is
056: * used to render a response to the user.
057: *
058: * @param id
059: * See Component
060: * @param pageMap
061: * the pagemap where the page of the inline frame must be in
062: * @param c
063: * Page class
064: */
065: public InternalFrame(final String id, final PageMap pageMap,
066: final Class c) {
067: this (id, pageMap, new IPageLink() {
068: private static final long serialVersionUID = 1L;
069:
070: public Page getPage() {
071: // Create page using page factory
072: return Session.get().getPageFactory().newPage(c);
073: }
074:
075: public Class getPageIdentity() {
076: return c;
077: }
078: });
079:
080: // Ensure that c is a subclass of Page
081: if (!Page.class.isAssignableFrom(c)) {
082: throw new IllegalArgumentException("Class " + c
083: + " is not a subclass of Page");
084: }
085: }
086:
087: /**
088: * This constructor is ideal if a Page object was passed in from a previous
089: * Page. Construct an inline frame containing the given Page.
090: *
091: * @param id
092: * See component
093: * @param pageMap
094: * the pagemap where the page of the inline frame must be in
095: * @param page
096: * The page
097: */
098: public InternalFrame(final String id, final PageMap pageMap,
099: final Page page) {
100: this (id, pageMap, new IPageLink() {
101: private static final long serialVersionUID = 1L;
102:
103: public Page getPage() {
104: // use given page
105: return page;
106: }
107:
108: public Class getPageIdentity() {
109: return page.getClass();
110: }
111: });
112: }
113:
114: /**
115: * This constructor is ideal for constructing pages lazily.
116: *
117: * Constructs an inline frame which invokes the getPage() method of the
118: * IPageLink interface when the content of the inline frame is requested.
119: * Whatever Page objects is returned by this method will be rendered back to
120: * the user.
121: *
122: * @param id
123: * See Component
124: * @param pageMap
125: * the pagemap where the page of the inline frame must be in
126: * @param pageLink
127: * An implementation of IPageLink which will create the page to
128: * be contained in the inline frame if and when the content is
129: * requested
130: */
131: public InternalFrame(final String id, final PageMap pageMap,
132: IPageLink pageLink) {
133: super (id);
134:
135: this .pageMapName = pageMap.getName();
136:
137: this .pageLink = pageLink;
138: }
139:
140: /**
141: * Gets the url to use for this link.
142: *
143: * @return The URL that this link links to
144: */
145: protected CharSequence getURL() {
146: return urlFor(ILinkListener.INTERFACE);
147: }
148:
149: /**
150: * Handles this frame's tag.
151: *
152: * @param tag
153: * the component tag
154: * @see wicket.Component#onComponentTag(ComponentTag)
155: */
156: protected final void onComponentTag(final ComponentTag tag) {
157: checkComponentTag(tag, "iframe");
158:
159: // Set href to link to this frame's frameRequested method
160: CharSequence url = getURL();
161:
162: // generate the src attribute
163: tag.put("src", Strings.replaceAll(url, "&", "&"));
164:
165: super .onComponentTag(tag);
166: }
167:
168: /**
169: * @see wicket.markup.html.link.ILinkListener#onLinkClicked()
170: */
171: public final void onLinkClicked() {
172: RequestCycle.get().getRequest().getRequestParameters()
173: .setPageMapName(pageMapName);
174:
175: setResponsePage(pageLink.getPage());
176: }
177:
178: /**
179: * Returns the pageMap.
180: *
181: * @return pageMap
182: */
183: public final PageMap getPageMap() {
184: return PageMap.forName(this.pageMapName);
185: }
186: }
|