001/**
002 * Copyright 2005-2015 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.krad.uif.view;
017
018import java.util.List;
019
020import org.kuali.rice.krad.datadictionary.parse.BeanTag;
021import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
022import org.kuali.rice.krad.uif.component.Component;
023import org.kuali.rice.krad.uif.element.Iframe;
024import org.kuali.rice.krad.uif.lifecycle.ViewLifecycle;
025import org.kuali.rice.krad.uif.util.ComponentFactory;
026import org.kuali.rice.krad.uif.util.LifecycleElement;
027import org.kuali.rice.krad.uif.util.UrlInfo;
028
029/**
030 * IframeView is a View component that shows another website's content in an iframe.
031 *
032 * <p>This View will always have one page itself and will always contain an iframe component.  The location
033 * property allows ease of setting the url for the iframe.  If the site being shown in the iframe is a KRAD View
034 * itself, the default bean for this class will attempt to pass a url parameter notifying the View that it is being
035 * shown in an iframe; this can be used in SpringEL to invoke special logic (such as not rendering some components,
036 * like the app header)</p>
037 *
038 * @author Kuali Rice Team (rice.collab@kuali.org)
039 */
040@BeanTag(name = "iframeView", parent = "Uif-IframeView")
041public class IframeView extends FormView {
042    private UrlInfo location;
043    private Iframe iframe;
044
045    /**
046     * Forces this view to be only one page, and sets the iframe as one of its items
047     *
048     * {@inheritDoc}
049     */
050    @Override
051    public void performInitialization(Object model) {
052        super.performInitialization(model);
053
054        super.setSinglePageView(true);
055
056        List<Component> modifiedItems = (List<Component>) this.getPage().getItems();
057        modifiedItems.add(iframe);
058        this.getPage().setItems(modifiedItems);
059    }
060
061    /**
062     * Evaluates expressions that may appear in location properties and sets the source of iframe automatically
063     *
064     * {@inheritDoc}
065     */
066    @Override
067    public void performApplyModel(Object model, LifecycleElement parent) {
068        super.performApplyModel(model, parent);
069
070        if (location != null) {
071            ViewLifecycle.getExpressionEvaluator().populatePropertyExpressionsFromGraph(location, false);
072            ViewLifecycle.getExpressionEvaluator().evaluateExpressionsOnConfigurable(this, location, this.getContext());
073
074            iframe.setSource(location.getHref());
075        }
076    }
077
078    /**
079     * Get the url object representing the location
080     *
081     * @return the url location object
082     */
083    @BeanTagAttribute
084    public UrlInfo getLocation() {
085        return location;
086    }
087
088    /**
089     * @see org.kuali.rice.krad.uif.view.IframeView#getLocation()
090     */
091    public void setLocation(UrlInfo location) {
092        this.location = location;
093    }
094
095    /**
096     * @see org.kuali.rice.krad.uif.util.UrlInfo#getHref()
097     */
098    @BeanTagAttribute
099    public String getHref() {
100        if (this.location != null) {
101            return this.location.getHref();
102        }
103
104        return null;
105    }
106
107    /**
108     * @see IframeView#getHref()
109     */
110    public void setHref(String href) {
111        if (this.location == null) {
112            this.location = ComponentFactory.getUrlInfo();
113        }
114
115        this.location.setHref(href);
116    }
117
118    /**
119     * The iframe component to be used as the content of this view, nothing needs to be set on this directly if
120     * using the default bean for this View
121     *
122     * @return the iframe component
123     */
124    @BeanTagAttribute
125    public Iframe getIframe() {
126        return iframe;
127    }
128
129    /**
130     * @see org.kuali.rice.krad.uif.view.IframeView#getIframe()
131     */
132    public void setIframe(Iframe iframe) {
133        this.iframe = iframe;
134    }
135}