1   /**
2    * Copyright 2006 Apache Software Foundation 
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License"); 
5    * you may not use this file except in compliance with the License. 
6    * You may obtain a copy of the License at 
7    * 
8    *     http://www.apache.org/licenses/LICENSE-2.0 
9    * 
10   * Unless required by applicable law or agreed to in writing, software 
11   * distributed under the License is distributed on an "AS IS" BASIS, 
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
13   * See the License for the specific language governing permissions and 
14   * limitations under the License.
15   */
16  package tests.w3c;
17  
18  import org.w3c.dom.Element;
19  import org.w3c.dom.Node;
20  import org.w3c.dom.NodeList;
21  
22  /**
23   * Class representing a single schema test as described in a .testSet file.
24   *
25   */
26  public class SchemaTest {
27  
28      private final static String SCHEMA_DOCUMENT = "schemaDocument";
29  
30      private final static String EXPECTED = "expected";
31  
32      private final static String CURRENT = "current";
33  
34      String schemaDocumentLink = null;
35  
36      private String expectedValidity = null;
37  
38      String currentStatus = null;
39  
40      String currentDate = null;
41  
42      public SchemaTest(Element n) throws Exception {
43          NodeList nl = n.getChildNodes();
44          for (int i = 0; i < nl.getLength(); i++) {
45              Node c = nl.item(i);
46              if (!(c instanceof Element))
47                  continue;
48              Element elem = (Element) c;
49              String elemName = elem.getNodeName();
50              if (elemName.equals(SCHEMA_DOCUMENT)) {
51                   schemaDocumentLink = elem.getAttributeNS(
52                          "http://www.w3.org/1999/xlink", "href");
53                   
54                   // Workaround for mistake in the NISTXMLSchema1-0-20020116.testSet file
55                   // See http://lists.w3.org/Archives/Public/www-xml-schema-comments/2006JulSep/0000.html
56                   if (schemaDocumentLink.equals("./NISTTestsAll/NISTSchema-anyURI-maxLength-1.xsd")) {
57                       schemaDocumentLink = "./nisttest/NISTTestsAll/NISTSchema-anyURI-maxLength-1.xsd";
58                   }
59              }
60  
61              if (elemName.equals(EXPECTED)) {
62                  expectedValidity = elem.getAttribute("validity");
63              }
64  
65              if (elemName.equals(CURRENT)) {
66                  currentStatus = elem.getAttribute("status");
67                  currentDate = elem.getAttribute("date");
68              }
69          }
70      }
71  
72      public boolean isValid() {
73          return expectedValidity.equals("valid");
74      }
75      
76      public String toString() {
77          StringBuffer sb = new StringBuffer("href=");
78          sb.append(schemaDocumentLink);
79          sb.append(" expectedValidity=");
80          sb.append(expectedValidity);
81          sb.append(" currentStatus=");
82          sb.append(currentStatus);
83          sb.append(" currentDate=");
84          sb.append(currentDate);
85          
86          return sb.toString();
87      }
88  }