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.Page;
021: import org.apache.wicket.PageMap;
022: import org.apache.wicket.RequestCycle;
023: import org.apache.wicket.Session;
024: import org.apache.wicket.markup.ComponentTag;
025: import org.apache.wicket.markup.html.WebMarkupContainer;
026: import org.apache.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 IPageMap 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 IPageMap 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 IPageMap 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 org.apache.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 org.apache.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 IPageMap getPageMap() {
184: return PageMap.forName(this.pageMapName);
185: }
186: }
|