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.Arrays;
20  import javax.servlet.jsp.JspException;
21  
22  import COM.FutureTense.Interfaces.ICS;
23  
24  import com.fatwire.assetapi.data.AssetId;
25  import com.fatwire.gst.foundation.facade.assetapi.asset.ScatteredAssetAccessTemplate;
26  
27  import org.apache.commons.lang.StringUtils;
28  
29  /**
30   *
31   * @author Tony Field
32   * @since 2011-09-20
33   */
34  public final class GetTagsTag extends GsfSimpleTag {
35  
36      private String c;
37      private long cid;
38      private String name;
39  
40      /*
41       * (non-Javadoc)
42       *
43       * @see javax.servlet.jsp.tagext.SimpleTagSupport#doTag()
44       */
45      @Override
46      public void doTag() throws JspException, IOException {
47  
48          final ICS ics = getICS();
49          final ScatteredAssetAccessTemplate t = new ScatteredAssetAccessTemplate(ics);
50          // todo: medium: find in page context if it's there (due to presence of
51          // gsf:root
52  
53  
54          if (StringUtils.isBlank(c) || cid == 0) {
55              String tag = (String) t.readCurrent("gsttag").get("gsttag");
56              if (tag != null) {
57                  getJspContext().setAttribute(name, Arrays.asList(tag.split(",")));
58              }
59          } else {
60              final AssetId id = t.createAssetId(c, cid);
61              String tag = (String) t.read(id, "gsttag").get("gsttag");
62              if (tag != null) {
63                  getJspContext().setAttribute(name, Arrays.asList(tag.split(",")));
64              }
65          }
66  
67          super.doTag();
68      }
69  
70      /**
71       * @param c the c to set
72       */
73      public void setC(final String c) {
74          this.c = c;
75      }
76  
77      /**
78       * @param cid the cid to set
79       */
80      public void setCid(final String cid) {
81          this.cid = Long.parseLong(cid);
82      }
83  
84      /**
85       * @param cid the cid to set
86       */
87      public void setCid(final long cid) {
88          this.cid = cid;
89      }
90  
91      /**
92       * @param name the name to set
93       */
94      public void setName(final String name) {
95          this.name = name;
96      }
97  }