View Javadoc

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