22
33import java .util .Arrays ;
44import java .util .ArrayList ;
5+ import java .util .Collection ;
56import java .util .List ;
67import java .util .Map ;
78import java .util .Set ;
1213import ezvcard .Ezvcard ;
1314import ezvcard .Ezvcard .ParserChainJsonString ;
1415import 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 ;
1522
1623import net .apnic .rdap .conformance .Result ;
1724import net .apnic .rdap .conformance .Result .Status ;
@@ -33,6 +40,7 @@ public final class Entity implements SearchTest {
3340 private String handle = null ;
3441 private String fn = null ;
3542 private Set <String > knownAttributes = null ;
43+ private Set <String > standardKinds = null ;
3644
3745 /**
3846 * <p>Constructor for Entity.</p>
@@ -70,6 +78,8 @@ public void setSearchDetails(final String key, final String pattern) {
7078 public boolean run (final Context context , final Result proto ,
7179 final Map <String , Object > data ) {
7280 knownAttributes = Sets .newHashSet ("handle" , "roles" , "vcardArray" );
81+ standardKinds = Sets .newHashSet ("individual" , "org" , "group" ,
82+ "location" , "application" , "device" );
7383
7484 Result nr = new Result (proto );
7585 nr .setCode ("content" );
@@ -122,6 +132,7 @@ public boolean run(final Context context, final Result proto,
122132 }
123133 Result nrv = new Result (nr );
124134 Result nrv2 = null ;
135+ List <Result > nrvAdditionals = new ArrayList <Result >();
125136 nrv .addNode ("vcardArray" );
126137 if (error != null ) {
127138 nrv .setStatus (Status .Failure );
@@ -141,21 +152,97 @@ public boolean run(final Context context, final Result proto,
141152 if (warnings .size () > 0 ) {
142153 List <String > vcardWarnings = warnings .get (0 );
143154 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 );
145159 }
146160 }
147161 vcard = vcards .get (0 );
148162 ValidationWarnings vws =
149163 vcard .validate (vcard .getVersion ());
150- String validationWarnings = vws .toString ();
164+ String validationWarnings = vws .toString (). trim () ;
151165 nrv2 = new Result (nrv );
152166 nrv2 .setDetails ((validationWarnings .length () == 0 ),
153167 "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+ }
154238 }
155239 context .addResult (nrv );
156240 if (nrv2 != null ) {
157241 context .addResult (nrv2 );
158242 }
243+ for (Result nrvAdditional : nrvAdditionals ) {
244+ context .addResult (nrvAdditional );
245+ }
159246 }
160247
161248 if ((fn != null ) && searchContext ) {
0 commit comments