1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package tools.gsf.facade.assetapi;
18
19 import COM.FutureTense.Interfaces.ICS;
20 import com.fatwire.assetapi.data.AssetId;
21 import com.openmarket.xcelerate.asset.AssetIdImpl;
22 import org.apache.commons.lang3.StringUtils;
23
24
25
26
27
28
29
30 public final class AssetIdUtils {
31 private AssetIdUtils() {
32 }
33
34
35
36
37
38
39
40
41 public static AssetId fromString(String s) {
42 if (s == null) {
43 throw new IllegalArgumentException("Invalid null input.");
44 }
45 int colon = s.indexOf(":");
46 if (colon < 1) {
47 throw new IllegalArgumentException("Invalid input: " + s);
48 }
49 if (colon == s.length()) {
50 throw new IllegalArgumentException("Invalid input: " + s);
51 }
52 String type = s.substring(0, colon);
53 String sId = s.substring(colon + 1);
54 try {
55 return new AssetIdImpl(type, Long.valueOf(sId));
56 } catch (NumberFormatException e) {
57 throw new IllegalArgumentException("Invalid input: " + s, e);
58 }
59 }
60
61
62
63
64
65
66
67 public static String toString(AssetId id) {
68 if (id == null) {
69 throw new IllegalArgumentException("Invalid null input.");
70 }
71 return id.getType() + ":" + Long.toString(id.getId());
72 }
73
74
75
76
77
78
79
80
81 public static AssetId currentId(ICS ics) {
82 String c = ics.GetVar("c");
83 String cid = ics.GetVar("cid");
84 if (StringUtils.isBlank(c)) {
85 throw new IllegalArgumentException(
86 "CS variable 'c' is not found, cannot make an AssetId of current ICS context");
87 }
88 if (StringUtils.isBlank(cid)) {
89 throw new IllegalArgumentException(
90 "CS variable 'cid' is not found, cannot make an AssetId of current ICS context");
91 }
92 return new AssetIdImpl(c, Long.parseLong(cid));
93 }
94
95
96
97
98
99
100
101
102 public static AssetId currentPageId(ICS ics) {
103 String p = ics.GetVar("p");
104
105 if (StringUtils.isBlank(p)) {
106 throw new IllegalArgumentException(
107 "CS variable 'p' is not found, cannot make an AssetId of current ICS context");
108 }
109 return new AssetIdImpl("Page", Long.parseLong(p));
110 }
111
112
113
114
115
116
117
118
119
120 public static AssetId createAssetId(String c, String cid) {
121 if (StringUtils.isBlank(c)) {
122 throw new IllegalArgumentException("'c' is blank, cannot make an AssetId of current ICS context");
123 }
124 if (StringUtils.isBlank(cid)) {
125 throw new IllegalArgumentException("'cid' is blank, cannot make an AssetId of current ICS context");
126 }
127 return new AssetIdImpl(c, Long.parseLong(cid));
128 }
129
130
131
132
133
134
135
136
137
138 public static AssetId createAssetId(String c, long cid) {
139 if (StringUtils.isBlank(c)) {
140 throw new IllegalArgumentException("'c' is blank, cannot make an AssetId of current ICS context");
141 }
142 return new AssetIdImpl(c, cid);
143 }
144
145 }