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.PageContext;
20  import javax.servlet.jsp.tagext.SimpleTagSupport;
21  
22  import com.fatwire.gst.foundation.controller.action.support.IcsFactoryUtil;
23  
24  import COM.FutureTense.Interfaces.ICS;
25  
26  /**
27   * Abstract class, usefull to get to ICS in a SimpleTag.
28   * 
29   * @author Dolf Dijkstra
30   * @since Apr 11, 2011
31   */
32  public abstract class GsfSimpleTag extends SimpleTagSupport {
33  
34      protected final ICS getICS() {
35          final Object o = getJspContext().getAttribute(GsfRootTag.ICS_VARIABLE_NAME, PageContext.PAGE_SCOPE);
36          if (o instanceof ICS) {
37              return (ICS) o;
38          }
39          throw new RuntimeException("Can't find ICS object on the page context.");
40      }
41  
42      protected final PageContext getPageContext() {
43          return (PageContext) getJspContext();
44      }
45  
46      protected final <T> T getService(String name, Class<T> type) {
47          return IcsFactoryUtil.getFactory(getICS()).getObject(name, type);
48      }
49  
50  }