View Javadoc

1   /**
2    * Copyright 2005-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.uif.freemarker;
17  
18  import java.io.IOException;
19  import java.io.Serializable;
20  import java.util.List;
21  
22  import org.kuali.rice.krad.uif.component.Component;
23  import org.kuali.rice.krad.uif.container.CollectionGroup;
24  import org.kuali.rice.krad.uif.layout.StackedLayoutManager;
25  
26  import freemarker.core.Environment;
27  import freemarker.core.InlineTemplateAdaptor;
28  import freemarker.template.TemplateException;
29  
30  /**
31   * Inline FreeMarker template adaptor for supporting stacked.ftl 
32   * 
33   * @author Kuali Rice Team (rice.collab@kuali.org)
34   */
35  public class FreeMarkerStackedAdaptor implements InlineTemplateAdaptor, Serializable {
36  
37      private static final long serialVersionUID = -4442716566711789593L;
38  
39      /**
40       * Render a KRAD collection via the stacked layout manager inline.
41       * 
42       * @see freemarker.core.InlineKradAdaptor#accept(freemarker.core.Environment)
43       */
44      @Override
45      public void accept(Environment env) throws TemplateException, IOException {
46          @SuppressWarnings("unchecked")
47          List<? extends Component> items = FreeMarkerInlineRenderUtils.resolve(env, "items", List.class);
48          StackedLayoutManager manager = FreeMarkerInlineRenderUtils.resolve(env, "manager", StackedLayoutManager.class);
49          CollectionGroup container = FreeMarkerInlineRenderUtils.resolve(env, "container", CollectionGroup.class);
50          FreeMarkerInlineRenderUtils.renderStacked(env, items, manager, container);
51      }
52  
53  }