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