1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package com.fatwire.gst.foundation.taglib;
17
18 import java.io.IOException;
19 import java.util.ArrayList;
20 import java.util.List;
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 import com.openmarket.xcelerate.asset.AssetIdImpl;
28
29 import org.apache.commons.lang.StringUtils;
30
31
32
33
34
35
36 public final class GetAssetTagsTag extends GsfSimpleTag {
37
38 private String c;
39 private long cid;
40 private String name;
41
42
43
44
45
46
47 @Override
48 public void doTag() throws JspException, IOException {
49
50 final ICS ics = getICS();
51 final ScatteredAssetAccessTemplate t = new ScatteredAssetAccessTemplate(ics);
52
53
54
55 if (StringUtils.isBlank(c) || cid == 0) {
56 String tag = (String) t.readCurrent("gsttag").get("gsttag");
57 if (tag != null) {
58 getJspContext().setAttribute(name, parseTags(tag));
59 }
60 } else {
61 final AssetId id = t.createAssetId(c, cid);
62 String tag = (String) t.read(id, "gsttag").get("gsttag");
63 if (tag != null) {
64 getJspContext().setAttribute(name, parseTags(tag));
65 }
66 }
67
68 super.doTag();
69 }
70
71 private static List<AssetId> parseTags(String tag) {
72 ArrayList<AssetId> tags = new ArrayList<AssetId>();
73 for (String assetEntry : tag.split(",")) {
74 int indexStart = assetEntry.indexOf("-");
75 int indexEnd = assetEntry.indexOf(":");
76 String assetId = assetEntry.substring(indexStart + 1, indexEnd);
77 String assetType = assetEntry.substring(indexEnd + 1, assetEntry.length());
78
79
80 AssetId aId = new AssetIdImpl(assetType, Long.parseLong(assetId));
81 tags.add(aId);
82 }
83 return tags;
84 }
85
86
87
88
89 public void setC(final String c) {
90 this.c = c;
91 }
92
93
94
95
96 public void setCid(final long cid) {
97 this.cid = cid;
98 }
99
100
101
102
103 public void setName(final String name) {
104 this.name = name;
105 }
106 }