1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.astrogrid.community.common.policy.data ;
25
26 import org.astrogrid.community.common.config.CommunityConfig ;
27
28 /***
29 * @todo deprecate the whole class.
30 *
31 *
32 */
33 public class CommunityIdent
34 {
35 /***
36 * The default account name.
37 *
38 */
39 public static String DEFAULT_ACCOUNT = "nobody" ;
40
41 /***
42 * The separator for name and community.
43 *
44 */
45 public static char IDENT_SEPARATOR = '@' ;
46
47 /***
48 * Flag to indicate the ident is valid.
49 *
50 */
51 private boolean valid = false ;
52
53 /***
54 * Flag to indicate the ident is local.
55 *
56 */
57 private boolean local = false ;
58
59 /***
60 * Our ident.
61 *
62 */
63 private String ident ;
64
65 /***
66 * Our ident name.
67 *
68 */
69 private String name ;
70
71 /***
72 * Our Ident community.
73 *
74 */
75 private String community ;
76
77 /***
78 * Public constructor.
79 *
80 */
81 public CommunityIdent(String ident)
82 {
83
84
85 if ((null == ident) || (0 == ident.length()))
86 {
87 ident = DEFAULT_ACCOUNT ;
88 }
89
90
91 ident = ident.toLowerCase() ;
92
93
94 this.ident = ident ;
95
96
97 int first = ident.indexOf(IDENT_SEPARATOR) ;
98 int last = ident.lastIndexOf(IDENT_SEPARATOR) ;
99
100
101 if (-1 != first)
102 {
103
104
105 if (first == last)
106 {
107
108
109 this.name = ident.substring(0, first) ;
110 this.community = ident.substring(first + 1) ;
111
112
113
114
115
116 if (CommunityConfig.getCommunityName().equals(this.community))
117 {
118 this.valid = true ;
119 this.local = true ;
120 }
121
122
123 else {
124 this.valid = true ;
125 this.local = false ;
126 }
127 }
128
129
130 else {
131 this.valid = false ;
132 this.local = false ;
133 this.name = null ;
134 this.community = null ;
135 }
136 }
137
138
139 else {
140
141
142 this.name = ident ;
143 this.community = CommunityConfig.getCommunityName() ;
144 this.ident = this.name + IDENT_SEPARATOR + this.community ;
145 this.valid = true ;
146 this.local = true ;
147 }
148 }
149
150 /***
151 * Public constructor.
152 *
153 */
154 public CommunityIdent(String name, String community)
155 {
156 this(name + IDENT_SEPARATOR + community) ;
157 }
158
159 /***
160 * Is this a valid ident.
161 *
162 */
163 public boolean isValid()
164 {
165 return this.valid ;
166 }
167
168 /***
169 * Is this a local ident.
170 *
171 */
172 public boolean isLocal()
173 {
174 return this.local ;
175 }
176
177 /***
178 * Get the name from this ident.
179 *
180 */
181 public String getName()
182 {
183 return this.name ;
184 }
185
186 /***
187 * Get the community name from this ident.
188 *
189 */
190 public String getCommunity()
191 {
192 return this.community ;
193 }
194
195 /***
196 * Convert the ident as a string.
197 *
198 */
199 public String toString()
200 {
201 return this.ident ;
202 }
203
204 }