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;
18  
19  import javax.servlet.jsp.JspException;
20  import javax.servlet.jsp.PageContext;
21  import javax.servlet.jsp.tagext.BodyTagSupport;
22  import javax.servlet.jsp.tagext.Tag;
23  
24  import COM.FutureTense.Interfaces.ICS;
25  
26  import com.fatwire.gst.foundation.facade.assetapi.asset.ScatteredAssetAccessTemplate;
27  import com.fatwire.gst.foundation.facade.runtag.render.LogDep;
28  
29  import org.apache.commons.logging.Log;
30  import org.apache.commons.logging.LogFactory;
31  
32  public class GsfRootTag extends BodyTagSupport {
33      public static final String ICS_VARIABLE_NAME = "ics";
34      public static final String VARIABLE_SCOPE_NAME = "cs";
35      public static final String ASSET_DAO = "assetDao";
36      /**
37  	 * 
38  	 */
39      private static final long serialVersionUID = -5369419132504852400L;
40  
41      private static final Log LOG = LogFactory.getLog(GsfRootTag.class.getPackage().getName());
42  
43      /*
44       * (non-Javadoc)
45       * 
46       * @see COM.FutureTense.JspTags.Root#doStartTag()
47       */
48      @Override
49      public int doStartTag() throws JspException {
50          super.doStartTag();
51  
52          final ICS ics = getICS();
53  
54          if (ics != null) {
55              pageContext.setAttribute(VARIABLE_SCOPE_NAME, new ICSAsMap(ics), PageContext.PAGE_SCOPE);
56              final ScatteredAssetAccessTemplate assetTemplate = new ScatteredAssetAccessTemplate(ics);
57              pageContext.setAttribute(ASSET_DAO, assetTemplate, PageContext.PAGE_SCOPE);
58              if (ics.GetVar("tid") != null) {
59                  LogDep.logDep(ics, "Template", ics.GetVar("tid"));
60              }
61              if (ics.GetVar("seid") != null) {
62                  LogDep.logDep(ics, "SiteEntry", ics.GetVar("seid"));
63              }
64              if (ics.GetVar("eid") != null) {
65                  LogDep.logDep(ics, "CSElement", ics.GetVar("eid"));
66              }
67          } else {
68              throw new JspException("ics is not found on the page context. This tags needs to be nested in the <cs:ftcs> tag.");
69          }
70          return EVAL_BODY_INCLUDE;
71      }
72  
73      protected ICS getICS() {
74          final Object o = pageContext.getAttribute(ICS_VARIABLE_NAME, PageContext.PAGE_SCOPE);
75          if (o instanceof ICS) {
76              return (ICS) o;
77          }
78          return null;
79      }
80  
81      /*
82       * (non-Javadoc)
83       * 
84       * @see javax.servlet.jsp.tagext.BodyTagSupport#doEndTag()
85       */
86      @Override
87      public int doEndTag() throws JspException {
88          pageContext.removeAttribute(VARIABLE_SCOPE_NAME, PageContext.PAGE_SCOPE);
89          pageContext.removeAttribute(ASSET_DAO, PageContext.PAGE_SCOPE);
90          return Tag.EVAL_PAGE;
91      }
92  
93  }