KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > dom > svg > SystemIdTest


1 /*
2  * Copyright 1999-2004 The 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
17 package org.apache.batik.dom.svg;
18
19 import java.util.Locale JavaDoc;
20 import java.util.ResourceBundle JavaDoc;
21 import java.util.StringTokenizer JavaDoc;
22 import java.util.MissingResourceException JavaDoc;
23
24 import org.apache.batik.test.AbstractTest;
25 import org.apache.batik.test.TestReport;
26 import org.apache.batik.test.DefaultTestReport;
27
28 /**
29  * This class tests that there is System Id for each public Id
30  * in the dtdids.properties resource file.
31  *
32  * @author <a HREF="mailto:vincent.hardy@sun.com">Vincent Hardy</a>
33  * @author $Id: SystemIdTest.java,v 1.3 2005/04/01 02:28:16 deweese Exp $
34  */

35 public class SystemIdTest extends AbstractTest {
36     public static final String JavaDoc ERROR_MISSING_SYSTEM_ID
37         = "error.missing.system.id";
38
39     public static final String JavaDoc KEY_MISSING_IDS
40         = "key.missing.ids";
41
42     public SystemIdTest() {
43     }
44
45     public TestReport runImpl() throws Exception JavaDoc {
46         ResourceBundle JavaDoc rb =
47             ResourceBundle.getBundle(SAXSVGDocumentFactory.DTDIDS,
48                                      Locale.getDefault());
49         String JavaDoc dtdids = rb.getString(SAXSVGDocumentFactory.KEY_PUBLIC_IDS);
50         
51         StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(dtdids, "-");
52         int nIds = st.countTokens();
53         String JavaDoc missingIds = "";
54         for (int i=0; i<nIds; i++) {
55             String JavaDoc publicId = st.nextToken();
56             publicId = "-" + publicId.trim();
57             System.out.println("Testing public id: " + publicId);
58             try {
59                 rb.getString(SAXSVGDocumentFactory.KEY_SYSTEM_ID
60                               + publicId.replace(' ', '_'));
61             } catch (MissingResourceException JavaDoc e) {
62                 missingIds += "[" + publicId + "] -- ";
63             }
64         }
65         
66         if (!"".equals(missingIds)) {
67             DefaultTestReport report = new DefaultTestReport(this);
68             report.setErrorCode(ERROR_MISSING_SYSTEM_ID);
69             report.addDescriptionEntry(KEY_MISSING_IDS, missingIds);
70             report.setPassed(false);
71             return report;
72         }
73
74         return reportSuccess();
75     }
76 }
77
Popular Tags