2
2
3
3
import java .util .Arrays ;
4
4
import java .util .ArrayList ;
5
+ import java .util .Collection ;
5
6
import java .util .List ;
6
7
import java .util .Map ;
7
8
import java .util .Set ;
12
13
import ezvcard .Ezvcard ;
13
14
import ezvcard .Ezvcard .ParserChainJsonString ;
14
15
import ezvcard .ValidationWarnings ;
16
+ import ezvcard .property .VCardProperty ;
17
+ import ezvcard .property .RawProperty ;
18
+ import ezvcard .property .Address ;
19
+ import ezvcard .property .Email ;
20
+ import ezvcard .property .Kind ;
21
+ import org .apache .commons .validator .routines .EmailValidator ;
15
22
16
23
import net .apnic .rdap .conformance .Result ;
17
24
import net .apnic .rdap .conformance .Result .Status ;
@@ -33,6 +40,7 @@ public final class Entity implements SearchTest {
33
40
private String handle = null ;
34
41
private String fn = null ;
35
42
private Set <String > knownAttributes = null ;
43
+ private Set <String > standardKinds = null ;
36
44
37
45
/**
38
46
* <p>Constructor for Entity.</p>
@@ -70,6 +78,8 @@ public void setSearchDetails(final String key, final String pattern) {
70
78
public boolean run (final Context context , final Result proto ,
71
79
final Map <String , Object > data ) {
72
80
knownAttributes = Sets .newHashSet ("handle" , "roles" , "vcardArray" );
81
+ standardKinds = Sets .newHashSet ("individual" , "org" , "group" ,
82
+ "location" , "application" , "device" );
73
83
74
84
Result nr = new Result (proto );
75
85
nr .setCode ("content" );
@@ -122,6 +132,7 @@ public boolean run(final Context context, final Result proto,
122
132
}
123
133
Result nrv = new Result (nr );
124
134
Result nrv2 = null ;
135
+ List <Result > nrvAdditionals = new ArrayList <Result >();
125
136
nrv .addNode ("vcardArray" );
126
137
if (error != null ) {
127
138
nrv .setStatus (Status .Failure );
@@ -141,21 +152,97 @@ public boolean run(final Context context, final Result proto,
141
152
if (warnings .size () > 0 ) {
142
153
List <String > vcardWarnings = warnings .get (0 );
143
154
for (String s : vcardWarnings ) {
144
- System .err .println (s );
155
+ Result nrvAdditional = new Result (nrv );
156
+ nrvAdditional .setStatus (Status .Failure );
157
+ nrvAdditional .setInfo (s );
158
+ nrvAdditionals .add (nrvAdditional );
145
159
}
146
160
}
147
161
vcard = vcards .get (0 );
148
162
ValidationWarnings vws =
149
163
vcard .validate (vcard .getVersion ());
150
- String validationWarnings = vws .toString ();
164
+ String validationWarnings = vws .toString (). trim () ;
151
165
nrv2 = new Result (nrv );
152
166
nrv2 .setDetails ((validationWarnings .length () == 0 ),
153
167
"valid" , "invalid: " + validationWarnings );
168
+
169
+ Collection <VCardProperty > properties =
170
+ vcard .getProperties ();
171
+ for (VCardProperty property : properties ) {
172
+ if (property instanceof ezvcard .property .Email ) {
173
+ Email emailProperty =
174
+ (ezvcard .property .Email ) property ;
175
+ String email = emailProperty .getValue ();
176
+ boolean valid =
177
+ EmailValidator .getInstance ().isValid (email );
178
+ Result nrvAdditional = new Result (nrv );
179
+ nrvAdditional .setDetails (
180
+ valid ,
181
+ "email address is valid" ,
182
+ "email address is invalid"
183
+ );
184
+ nrvAdditionals .add (nrvAdditional );
185
+ }
186
+ if (property instanceof ezvcard .property .Address ) {
187
+ Address addressProperty =
188
+ (ezvcard .property .Address ) property ;
189
+
190
+ String poBox = addressProperty .getPoBox ();
191
+ Result nrvAdditionalPoBox = new Result (nrv );
192
+ nrvAdditionalPoBox .setDocument ("rfc6350" );
193
+ nrvAdditionalPoBox .setReference ("6.3.1" );
194
+ nrvAdditionalPoBox .setInfo ("PO box should not be set" );
195
+ nrvAdditionalPoBox .setStatus (
196
+ (poBox == null )
197
+ ? Status .Success
198
+ : Status .Warning
199
+ );
200
+ nrvAdditionals .add (nrvAdditionalPoBox );
201
+
202
+ String extendedAddress =
203
+ addressProperty .getExtendedAddress ();
204
+ Result nrvAdditionalEA = new Result (nrv );
205
+ nrvAdditionalEA .setDocument ("rfc6350" );
206
+ nrvAdditionalEA .setReference ("6.3.1" );
207
+ nrvAdditionalEA .setInfo ("extended address should not be set" );
208
+ nrvAdditionalEA .setStatus (
209
+ (extendedAddress == null )
210
+ ? Status .Success
211
+ : Status .Warning
212
+ );
213
+ nrvAdditionals .add (nrvAdditionalEA );
214
+ }
215
+ if (property instanceof ezvcard .property .Kind ) {
216
+ Kind kindProperty =
217
+ (ezvcard .property .Kind ) property ;
218
+ String value = kindProperty .getValue ();
219
+ if (!standardKinds .contains (value )) {
220
+ Result nrvAdditional = new Result (nrv );
221
+ nrvAdditional .setStatus (Status .Warning );
222
+ nrvAdditional .setInfo ("found non-standard kind " +
223
+ "'" + value + "'" );
224
+ nrvAdditionals .add (nrvAdditional );
225
+ }
226
+ }
227
+ }
228
+ List <RawProperty > extendedProperties =
229
+ vcard .getExtendedProperties ();
230
+ for (RawProperty property : extendedProperties ) {
231
+ Result nrvAdditional = new Result (nrv );
232
+ nrvAdditional .setStatus (Status .Warning );
233
+ nrvAdditional .setInfo ("found non-standard property " +
234
+ "'" + property .getPropertyName ()
235
+ + "'" );
236
+ nrvAdditionals .add (nrvAdditional );
237
+ }
154
238
}
155
239
context .addResult (nrv );
156
240
if (nrv2 != null ) {
157
241
context .addResult (nrv2 );
158
242
}
243
+ for (Result nrvAdditional : nrvAdditionals ) {
244
+ context .addResult (nrvAdditional );
245
+ }
159
246
}
160
247
161
248
if ((fn != null ) && searchContext ) {
0 commit comments