KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > bull > eclipse > jonas > utils > xml > desc > CommonsDTDs


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or 1any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * Initial developer: Florent BENOIT
22  * --------------------------------------------------------------------------
23  * $Id: CommonsDTDs.java,v 1.1 2003/10/27 14:46:32 benoitf Exp $
24  * --------------------------------------------------------------------------
25  */

26
27 package com.bull.eclipse.jonas.utils.xml.desc;
28
29 import java.net.URL JavaDoc;
30 import java.util.HashMap JavaDoc;
31 import java.util.Map JavaDoc;
32
33
34
35 /**
36  * This class defines the declarations of defaults DTDs used for J2EE 1.4 and less
37  * @author Florent Benoit
38  */

39 public abstract class CommonsDTDs implements DTDs {
40
41     /**
42      * List of default dtds
43      */

44     private static final String JavaDoc[] DEFAULT_DTDS = new String JavaDoc[] {
45         "XMLSchema.dtd",
46         "datatypes.dtd"
47     };
48
49     /**
50      * List of default publicId
51      */

52     private static final String JavaDoc[] DEFAULT_DTDS_PUBLIC_ID = new String JavaDoc[] {
53         "-//W3C//DTD XMLSCHEMA 200102//EN",
54         "datatypes"
55     };
56
57
58     /**
59      * Map where mapping publicId/dtds are stored
60      */

61     private static HashMap JavaDoc dtdsMapping = null;
62
63     /**
64      * Build a new object for DTDs handling
65      */

66     public CommonsDTDs() {
67         dtdsMapping = new HashMap JavaDoc();
68         addMapping(DEFAULT_DTDS, DEFAULT_DTDS_PUBLIC_ID);
69     }
70
71     /**
72      * Gets the mapping between publicIds and DTDs
73      * @return the mapping between publicIds and DTDs
74      */

75     public Map JavaDoc getMapping() {
76         return dtdsMapping;
77     }
78
79
80
81     /**
82      * Add to the list of DTDS the given dtds/publicId
83      * @param dtds array of dtds
84      * @param publicIds array of publicIds
85      */

86     protected void addMapping(String JavaDoc[] dtds, String JavaDoc[] publicIds) {
87         if (dtds.length != publicIds.length) {
88             throw new IllegalStateException JavaDoc("SEVERE ERROR !!! Number of dtds is different of the number of PublicId !!! check the source code");
89         }
90         
91         URL JavaDoc url = null;
92         for (int i = 0; i < dtds.length; i++) {
93             url = CommonsDTDs.class.getResource("/" + dtds[i]);
94             if (!(url == null)) {
95                 dtdsMapping.put(publicIds[i], url.toString()); //MANU
96
//MANU throw new IllegalStateException("'" + dtds[i] + "' was not found in the current classloader !");
97
}
98             //MANU dtdsMapping.put(publicIds[i], url.toString());
99
}
100     }
101
102 }
103
Popular Tags