KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > dom > GetElementsByTagNameNSTest


1 /*
2
3    Copyright 2002 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17  */

18 package org.apache.batik.dom;
19
20 import org.w3c.dom.*;
21
22 import java.io.*;
23 import java.net.*;
24 import org.apache.batik.dom.util.*;
25 import org.apache.batik.util.*;
26 import org.apache.batik.test.*;
27
28 /**
29  * This class tests the getElementsByTagNameNS method.
30  *
31  * @author <a HREF="mailto:stephane@hillion.org">Stephane Hillion</a>
32  * @version $Id: GetElementsByTagNameNSTest.java,v 1.3 2004/08/18 07:16:39 vhardy Exp $
33  */

34 public class GetElementsByTagNameNSTest extends AbstractTest {
35     protected String JavaDoc testFileName;
36     protected String JavaDoc rootTag;
37     protected String JavaDoc tagName;
38
39     public GetElementsByTagNameNSTest(String JavaDoc file,
40                                       String JavaDoc root,
41                                       String JavaDoc tag) {
42         testFileName = file;
43         rootTag = root;
44         tagName = tag;
45     }
46
47     public TestReport runImpl() throws Exception JavaDoc {
48         String JavaDoc parser =
49             XMLResourceDescriptor.getXMLParserClassName();
50
51         DocumentFactory df
52             = new SAXDocumentFactory
53             (GenericDOMImplementation.getDOMImplementation(), parser);
54
55         File f = (new File(testFileName));
56         URL url = f.toURL();
57         Document doc = df.createDocument(null,
58                                          rootTag,
59                                          url.toString(),
60                                          url.openStream());
61         
62         Element root = doc.getDocumentElement();
63         NodeList lst = root.getElementsByTagNameNS(null, tagName);
64
65         if (lst.getLength() != 1) {
66             DefaultTestReport report = new DefaultTestReport(this);
67             report.setErrorCode("error.getElementByTagNameNS.failed");
68             report.setPassed(false);
69             return report;
70         }
71         
72         Node n;
73         while ((n = root.getFirstChild()) != null) {
74             root.removeChild(n);
75         }
76
77         if (lst.getLength() != 0) {
78             DefaultTestReport report = new DefaultTestReport(this);
79             report.setErrorCode("error.getElementByTagNameNS.failed");
80             report.setPassed(false);
81             return report;
82         }
83
84         return reportSuccess();
85     }
86     
87 }
88
Popular Tags