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
33   * query the GSTTagRegistry and retrieve the assets that point to the specified
34   * tag. Input tagname - the name of the tag outlist - name of output list Output
35   * The 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   * @since Aug 13, 2010
42   */
43  public final class TaggedListTag extends GsfSimpleTag {
44  
45      private String tag = null;
46      private String outlist = null;
47  
48      public TaggedListTag() {
49      }
50  
51      public void setTag(final String tag) {
52          this.tag = tag;
53      }
54  
55      public void setOutlist(final String outlist) {
56          this.outlist = outlist;
57      }
58  
59      /*
60       * (non-Javadoc)
61       * 
62       * @see javax.servlet.jsp.tagext.SimpleTagSupport#doTag()
63       */
64      @Override
65      public void doTag() throws JspException, IOException {
66          final ICS ics = getICS();
67          final AssetTaggingService svc = new TableTaggingServiceImpl(ics);
68          final Collection<AssetId> ids = svc.lookupTaggedAssets(TagUtils.asTag(tag));
69          ics.RegisterList(outlist, new AssetIdIList(outlist, ids));
70          getJspContext().setAttribute(outlist, ids);
71          super.doTag();
72      }
73  }