KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > bull > eclipse > jonas > utils > xml > 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;
28
29 import java.net.URL JavaDoc;
30 import java.util.HashMap JavaDoc;
31 import java.util.Map JavaDoc;
32
33 import com.bull.eclipse.jonas.utils.xml.desc.DTDs;
34
35
36 /**
37  * This class defines the declarations of defaults DTDs used for J2EE 1.4 and less
38  * @author Florent Benoit
39  */

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

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

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

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

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

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

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