View Javadoc

1   /*
2    * Copyright 2010 FatWire Corporation. All Rights Reserved.
3    *
4    * Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0
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  
17  package com.fatwire.gst.foundation.taglib.navigation;
18  
19  import java.io.IOException;
20  import java.util.Collection;
21  
22  import javax.servlet.jsp.JspException;
23  
24  import org.apache.commons.lang.StringUtils;
25  
26  import COM.FutureTense.Interfaces.ICS;
27  
28  import com.fatwire.gst.foundation.navigation.NavigationNode;
29  import com.fatwire.gst.foundation.navigation.NavigationService;
30  import com.fatwire.gst.foundation.taglib.GsfSimpleTag;
31  
32  /**
33   * 
34   * jsp tag to generate the navigation data structure.
35   * 
36   * @author Dolf Dijkstra
37   * @since August 31, 2012
38   * 
39   */
40  public class PluggableNavigationTag extends GsfSimpleTag {
41  
42      private String name;
43      private int depth = 1;
44      private String pagename;
45  
46      /**
47       * @param name the name to set
48       */
49      public void setName(final String name) {
50          this.name = name;
51      }
52  
53      /**
54       * @param depth the depth to set
55       */
56      public void setDepth(final int depth) {
57          this.depth = depth;
58      }
59  
60      /**
61       * @param pagename the pagename to set
62       */
63      public void setPagename(final String pagename) {
64          this.pagename = pagename;
65      }
66  
67      /*
68       * (non-Javadoc)
69       * 
70       * @see javax.servlet.jsp.tagext.SimpleTagSupport#doTag()
71       */
72      @Override
73      public void doTag() throws JspException, IOException {
74          super.doTag();
75          final ICS ics = (ICS) getICS();
76  
77          final NavigationService nh = getService("navigationService", NavigationService.class);
78          if (nh == null)
79              throw new IllegalStateException("No NavigationService found, cannot retrieve navigation node.");
80          String site = ics.GetVar("site");
81          if (StringUtils.isBlank(site))
82              throw new IllegalStateException("site is not a valid 'ics' variable.");
83          if (StringUtils.isBlank(pagename)) {
84  
85              Collection<NavigationNode> nav = nh.getRootNodesForSite(site, depth);
86              getJspContext().setAttribute(name, nav);
87          } else {
88              NavigationNode nav = nh.getNodeByName(site, pagename, depth);
89              getJspContext().setAttribute(name, nav);
90  
91          }
92          depth = 1;
93          pagename = null;
94  
95      }
96  }