1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 package org.astrogrid.community.common.ivorn ;
29
30 import org.apache.commons.logging.Log ;
31 import org.apache.commons.logging.LogFactory ;
32
33 import org.astrogrid.store.Ivorn ;
34 import org.astrogrid.community.common.exception.CommunityIdentifierException ;
35
36 /***
37 * A factory for generating Community related Ivorn identifiers.
38 * @todo Need better integration with the MockIvorn factory.
39 *
40 */
41 public class CommunityIvornFactory
42 {
43 /***
44 * Our debug logger.
45 *
46 */
47 private static Log log = LogFactory.getLog(CommunityIvornFactory.class);
48
49 /***
50 * Create a new ident.
51 * @param community The Community ident, with no extra fields.
52 * @param resource The resource name.
53 * @return A new identifer.
54 * @throws CommunityIdentifierException if the community or resource identifiers are null.
55 *
56 */
57 protected static String createIdent(String community, String resource)
58 throws CommunityIdentifierException
59 {
60 return createIdent(
61 community,
62 resource,
63 null,
64 null,
65 null
66 ) ;
67 }
68
69 /***
70 * Create a Community ident.
71 * @param community The Community ident, with no extra fields.
72 * @param resource The resource name.
73 * @param path The URI path, added after the resource.
74 * @return A new identifer.
75 * @throws CommunityIdentifierException if the community or resource identifiers are null.
76 *
77 */
78 protected static String createIdent(String community, String resource, String path)
79 throws CommunityIdentifierException
80 {
81 return createIdent(
82 community,
83 resource,
84 path,
85 null,
86 null
87 ) ;
88 }
89
90 /***
91 * Create a Community ident.
92 * @param community The Community ident, with no extra fields.
93 * @param resource The resource name.
94 * @param path The URI path, added after the resource.
95 * @param fragment The URI fragment, added after the path.
96 * @return A new identifer.
97 * @throws CommunityIdentifierException if the community or resource identifiers are null.
98 *
99 */
100 protected static String createIdent(String community, String resource, String path, String fragment)
101 throws CommunityIdentifierException
102 {
103 return createIdent(
104 community,
105 resource,
106 path,
107 null,
108 fragment
109 ) ;
110 }
111
112 /***
113 * Create a Community ident.
114 * @param community The Community ident, with no extra fields.
115 * @param resource The resource name.
116 * @param path The URI path, added after the resource.
117 * @param query The URI query string, added after the path.
118 * @param fragment The URI fragment, added after the query.
119 * @return A new identifer.
120 * @throws CommunityIdentifierException if the community or resource identifiers are null.
121 *
122 */
123 protected static String createIdent(String community, String resource, String path, String query, String fragment)
124 throws CommunityIdentifierException
125 {
126 log.debug("") ;
127 log.debug("----\"----") ;
128 log.debug("CommunityIvornFactory.createIdent()") ;
129 log.debug(" Community : " + community) ;
130 log.debug(" Resource : " + resource) ;
131 log.debug(" Path : " + path) ;
132 log.debug(" Query : " + query) ;
133 log.debug(" Fragment : " + fragment) ;
134
135
136 if (null == community)
137 {
138 throw new CommunityIdentifierException(
139 "Null Community identifier"
140 ) ;
141 }
142 if (null == resource)
143 {
144 throw new CommunityIdentifierException(
145 "Null Resource identifier"
146 ) ;
147 }
148
149
150 StringBuffer buffer = new StringBuffer() ;
151
152
153 if (false == community.startsWith(Ivorn.SCHEME))
154 {
155 buffer.append(Ivorn.SCHEME) ;
156 buffer.append("://") ;
157 }
158 buffer.append(community) ;
159 buffer.append("/") ;
160 buffer.append(resource) ;
161 if (null != path)
162 {
163 buffer.append("/") ;
164 buffer.append(path) ;
165 }
166 if (null != query)
167 {
168 buffer.append("?") ;
169 buffer.append(query) ;
170 }
171 if (null != fragment)
172 {
173 buffer.append("#") ;
174 buffer.append(fragment) ;
175 }
176 log.debug(" Result : " + buffer.toString()) ;
177
178
179 return buffer.toString() ;
180 }
181 }