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