001/**
002 * Copyright 2005-2016 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.freemarker;
017
018import java.io.IOException;
019import java.io.Serializable;
020import java.util.List;
021
022import org.kuali.rice.krad.uif.component.Component;
023import org.kuali.rice.krad.uif.container.CollectionGroup;
024import org.kuali.rice.krad.uif.layout.StackedLayoutManager;
025
026import freemarker.core.Environment;
027import freemarker.core.InlineTemplateAdaptor;
028import freemarker.template.TemplateException;
029
030/**
031 * Inline FreeMarker template adaptor for supporting stacked.ftl 
032 * 
033 * @author Kuali Rice Team (rice.collab@kuali.org)
034 */
035public class FreeMarkerStackedAdaptor implements InlineTemplateAdaptor, Serializable {
036
037    private static final long serialVersionUID = -4442716566711789593L;
038
039    /**
040     * Render a KRAD collection via the stacked layout manager inline.
041     * 
042     * {@inheritDoc}
043     */
044    @Override
045    public void accept(Environment env) throws TemplateException, IOException {
046        @SuppressWarnings("unchecked")
047        List<? extends Component> items = FreeMarkerInlineRenderUtils.resolve(env, "items", List.class);
048        StackedLayoutManager manager = FreeMarkerInlineRenderUtils.resolve(env, "manager", StackedLayoutManager.class);
049        CollectionGroup container = FreeMarkerInlineRenderUtils.resolve(env, "container", CollectionGroup.class);
050        FreeMarkerInlineRenderUtils.renderStacked(env, items, manager, container);
051    }
052
053}