001    /**
002     * Copyright 2005-2014 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     */
016    package org.kuali.rice.krad.uif.view;
017    
018    import java.util.List;
019    
020    import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
021    import org.kuali.rice.krad.uif.component.Component;
022    import org.kuali.rice.krad.uif.element.Iframe;
023    import org.kuali.rice.krad.uif.lifecycle.ViewLifecycle;
024    import org.kuali.rice.krad.uif.util.ComponentFactory;
025    import org.kuali.rice.krad.uif.util.LifecycleElement;
026    import org.kuali.rice.krad.uif.util.UrlInfo;
027    
028    /**
029     * IframeView is a View component that shows another website's content in an iframe.
030     *
031     * <p>This View will always have one page itself and will always contain an iframe component.  The location
032     * property allows ease of setting the url for the iframe.  If the site being shown in the iframe is a KRAD View
033     * itself, the default bean for this class will attempt to pass a url parameter notifying the View that it is being
034     * shown in an iframe; this can be used in SpringEL to invoke special logic (such as not rendering some components,
035     * like the app header)</p>
036     */
037    public class IframeView extends FormView {
038        private UrlInfo location;
039        private Iframe iframe;
040    
041        /**
042         * Forces this view to be only one page, and sets the iframe as one of its items
043         *
044         * {@inheritDoc}
045         */
046        @Override
047        public void performInitialization(Object model) {
048            super.performInitialization(model);
049    
050            super.setSinglePageView(true);
051    
052            List<Component> modifiedItems = (List<Component>) this.getPage().getItems();
053            modifiedItems.add(iframe);
054            this.getPage().setItems(modifiedItems);
055        }
056    
057        /**
058         * Evaluates expressions that may appear in location properties and sets the source of iframe automatically
059         *
060         * {@inheritDoc}
061         */
062        @Override
063        public void performApplyModel(Object model, LifecycleElement parent) {
064            super.performApplyModel(model, parent);
065    
066            if (location != null) {
067                ViewLifecycle.getExpressionEvaluator().populatePropertyExpressionsFromGraph(location, false);
068                ViewLifecycle.getExpressionEvaluator().evaluateExpressionsOnConfigurable(this, location, this.getContext());
069    
070                iframe.setSource(location.getHref());
071            }
072        }
073    
074        /**
075         * Get the url object representing the location
076         *
077         * @return the url location object
078         */
079        @BeanTagAttribute(name = "location", type = BeanTagAttribute.AttributeType.SINGLEBEAN)
080        public UrlInfo getLocation() {
081            return location;
082        }
083    
084        /**
085         * @see org.kuali.rice.krad.uif.view.IframeView#getLocation()
086         */
087        public void setLocation(UrlInfo location) {
088            this.location = location;
089        }
090    
091        /**
092         * Convenience setter for setting the href (full URL) of the location object
093         *
094         * @param href URL for location option
095         */
096        public void setHref(String href) {
097            if (this.location == null) {
098                this.location = ComponentFactory.getUrlInfo();
099            }
100    
101            this.location.setHref(href);
102        }
103    
104        /**
105         * The iframe component to be used as the content of this view, nothing needs to be set on this directly if
106         * using the default bean for this View
107         *
108         * @return the iframe component
109         */
110        public Iframe getIframe() {
111            return iframe;
112        }
113    
114        /**
115         * @see org.kuali.rice.krad.uif.view.IframeView#getIframe()
116         */
117        public void setIframe(Iframe iframe) {
118            this.iframe = iframe;
119        }
120    }