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  package com.fatwire.gst.foundation.taglib;
17  
18  import java.io.IOException;
19  import java.util.Collection;
20  
21  import javax.servlet.jsp.JspException;
22  
23  import COM.FutureTense.Interfaces.ICS;
24  
25  import com.fatwire.assetapi.data.AssetId;
26  import com.fatwire.gst.foundation.facade.assetapi.AssetIdIList;
27  import com.fatwire.gst.foundation.tagging.AssetTaggingService;
28  import com.fatwire.gst.foundation.tagging.TagUtils;
29  import com.fatwire.gst.foundation.tagging.db.TableTaggingServiceImpl;
30  
31  /**
32   * Tagged list tag support This tag uses ICS.SQL(PreparedStmt, boolean) to query
33   * the GSTTagRegistry and retrieve the assets that point to the specified tag.
34   * Input tagname - the name of the tag outlist - name of output list Output The
35   * name of an IList object to be placed in the list pool. It contains two
36   * columns: ASSETTYPE, ASSETID. Null is never returned, but the returned list
37   * can be empty. A java method is provided in order for the same logic to be
38   * called from java. *
39   * 
40   * @author Tony Field
41   * @author Dolf Dijkstra
42   * @since Aug 13, 2010
43   */
44  public final class AssetTaggedListTag extends GsfSimpleTag {
45  
46      private String assettype = null;
47      private String assetid = null;
48      private String outlist = null;
49  
50      public AssetTaggedListTag() {
51  
52      }
53  
54      public void setAssettype(final String assettype) {
55          this.assettype = assettype;
56      }
57  
58      public void setAssetid(final String assetid) {
59          this.assetid = assetid;
60      }
61  
62      public void setOutlist(final String outlist) {
63          this.outlist = outlist;
64      }
65  
66      public void release() {
67  
68          assettype = null;
69          assetid = null;
70          outlist = null;
71      }
72  
73      /*
74       * (non-Javadoc)
75       * 
76       * @see javax.servlet.jsp.tagext.SimpleTagSupport#doTag()
77       */
78      @Override
79      public void doTag() throws JspException, IOException {
80  
81          final ICS ics = getICS();
82          final AssetTaggingService svc = new TableTaggingServiceImpl(ics);
83          final Collection<AssetId> ids = svc.lookupTaggedAssets(TagUtils.asTag("asset-" + assetid + ":" + assettype));
84          ics.RegisterList(outlist, new AssetIdIList(outlist, ids));
85          getJspContext().setAttribute(outlist, ids);
86          super.doTag();
87      }
88  
89  }