001: /*
002: * Copyright 2001-2006 C:1 Financial Services GmbH
003: *
004: * This software is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License Version 2.1, as published by the Free Software Foundation.
007: *
008: * This software is distributed in the hope that it will be useful,
009: * but WITHOUT ANY WARRANTY; without even the implied warranty of
010: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
011: * Lesser General Public License for more details.
012: *
013: * You should have received a copy of the GNU Lesser General Public
014: * License along with this library; if not, write to the Free Software
015: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
016: */
017:
018: package de.finix.contelligent.xml;
019:
020: import java.util.HashMap;
021: import java.util.Iterator;
022: import java.util.Map;
023:
024: import org.apache.commons.digester.Digester;
025:
026: /**
027: * Singleton which encapsulates the mapping between the public id of a DTD and
028: * the URL to that DTD. The URL must be requested via an additional unique short
029: * name which is set when {@link #addDTD adding} a new mapping. <BR>
030: * For most DTDs used within the Contelligent system their exist string
031: * constants containing the short name. For example to get the DTD for the XML
032: * description of a component use
033: *
034: * <PRE>
035: *
036: * DTDCatalog.getInstance().getFileURL(DTDCatalog.COMPONENT);
037: *
038: * </PRE>
039: */
040: public class DTDCatalog {
041: public static final String PUBLICID_URLPREFIX = "http://www.c1-fse.de/contelligent/dtds/";
042:
043: public static final String CONTELLIGENT_CONFIGURATION = "Contell Conf";
044:
045: public static final String CATEGORY_DEFINITION = "category-definition";// must
046:
047: // match
048: // element
049: // name!
050:
051: public static final String PACKAGE_DESCRIPTOR = "package"; // must match
052:
053: // element name!
054:
055: public static final String COMPONENT_LIST = "component-list"; // must
056:
057: // match
058: // element
059: // name!
060:
061: public static final String COMPONENT = "component";
062:
063: public static final String TYPE = "type"; // must match element name!
064:
065: public static final String TYPE_LIST = "type-list"; // must match element
066:
067: // name!
068:
069: public static final String ACL = "ACL";
070:
071: public static final String RESOURCE = "Resource";
072:
073: public static final String TYPE_METAINFO = "meta-info"; // must match
074:
075: // element name!
076:
077: public static final String DESCRIPTION = "description";
078:
079: public static final String PRINCIPAL_DATA = "principal-list"; // must
080:
081: // match
082: // element
083: // name!
084:
085: public static final String WORKFLOW_DEFINITION = "workflow";
086:
087: public static final String SEARCH_ENGINE = "search-engine";
088:
089: public static final String ERROR_MAPPING = "error-mapping";
090:
091: public static final String PROJECT_CONFIG = "project";
092:
093: final private static DTDCatalog instance = new DTDCatalog();
094:
095: final private Map publicIDs = new HashMap();
096:
097: final private Map dtds = new HashMap();
098:
099: final private Map realFileNames = new HashMap();
100:
101: final private Map pubIdToFileNames = new HashMap();
102:
103: public static DTDCatalog getInstance() {
104: return instance;
105: }
106:
107: /**
108: * Creates new DTDCatalog
109: *
110: * Note that {@link de.finix.contelligent.core.ContelligentImpl#copyDTDs}
111: * overwrites the real file-URLs of all registered DTDs so they point to the
112: * local copies of the DTDs.
113: */
114: private DTDCatalog() {
115:
116: addDTD(PACKAGE_DESCRIPTOR,
117: "-//finix AG/contelligent/Package Import File V9.1/EN",
118: "package-import_9_1.dtd");
119: addDTD(TYPE,
120: "-//finix AG/contelligent/Type Definition V1.0/EN",
121: "type_1_0.dtd");
122: addDTD(TYPE_LIST, "-//finix AG/contelligent/Type List V1.0/EN",
123: "type-list_1_0.dtd");
124: addDTD(
125: COMPONENT,
126: "-//finix AG/contelligent/Component Definition V9.1/EN",
127: "component_9_1.dtd");
128: addDTD(COMPONENT_LIST,
129: "-//Finix AG/Contelligent/DTD component-list V9.1/EN",
130: "component-list_9_1.dtd");
131: addDTD(COMPONENT_LIST + "-1.0",
132: "-//Finix AG/Contelligent/DTD component-list V1.0/EN",
133: "component-list_9_1.dtd"); // Yes,
134: // this
135: // is
136: // intentional
137: // since
138: // many pre-9.1 packages use the
139: // wrong version number
140: addDTD(CATEGORY_DEFINITION,
141: "-//finix AG/contelligent/Category Definition V1.0/EN",
142: "category-definition_1_0.dtd");
143: addDTD(
144: CONTELLIGENT_CONFIGURATION,
145: "-//finix AG/contelligent/Contelligent Configuration V9.1/EN",
146: "contelligent-configuration_9_1.dtd");
147: addDTD(ACL,
148: "-//finix AG/contelligent/Access Control List V9.1/EN",
149: "acl_9_1.dtd");
150: addDTD(RESOURCE, "-//finix AG/contelligent/Resource V1.0/EN",
151: "resource_1_0.dtd");
152: addDTD(
153: TYPE_METAINFO,
154: "-//finix AG/contelligent/Type Meta-Information V1.0/EN",
155: "type-metainfo_1_0.dtd");
156: addDTD(DESCRIPTION,
157: "-//finix AG/contelligent/Description V1.0/EN",
158: "description_1_0.dtd");
159: addDTD(PRINCIPAL_DATA,
160: "-//finix AG/contelligent/Principal Data V1.0/EN",
161: "principaldata_1_0.dtd");
162: addDTD(WORKFLOW_DEFINITION,
163: "-//finix AG/contelligent/Workflow Definition V1.0/EN",
164: "workflow-definition_1_0.dtd");
165: addDTD(
166: SEARCH_ENGINE,
167: "-//finix AG/contelligent/Search Engine Configuration V1.1/EN",
168: "searchengine_1_1.dtd");
169: addDTD(ERROR_MAPPING,
170: "-//finix AG/contelligent/Error-Mapping V1.0/EN",
171: "error-mapping_1_0.dtd");
172: addDTD(
173: PROJECT_CONFIG,
174: "-//finix AG/contelligent/Project Configuration V1.2/EN",
175: "project_1_2.dtd");
176: addDeprecatedDTDs();
177: }
178:
179: private void addDeprecatedDTDs() {
180: addDTD(PACKAGE_DESCRIPTOR + "-1.0",
181: "-//finix AG/contelligent/Package Import File V1.0/EN",
182: "package-import_1_0.dtd");
183: addDTD(PACKAGE_DESCRIPTOR + "-1.1",
184: "-//finix AG/contelligent/Package Import File V1.1/EN",
185: "package-import_1_1.dtd");
186: addDTD(PACKAGE_DESCRIPTOR + "-depr",
187: "-//finix AG/contelligent/Package Import File/EN",
188: "package-import_1_0.dtd");
189: addDTD(TYPE + "-depr",
190: "-//finix AG/contelligent/Type Definition/EN",
191: "type.dtd");
192: addDTD(TYPE_LIST + "-depr",
193: "-//finix AG/contelligent/Type List/EN",
194: "type-list.dtd");
195: addDTD(COMPONENT + "-depr",
196: "-//finix AG/contelligent/Component Definition/EN",
197: "component.dtd");
198: addDTD(COMPONENT_LIST + "-depr",
199: "-//Finix AG/Contelligent/DTD component-list 1.0/EN",
200: "component-list.dtd");
201: addDTD(CATEGORY_DEFINITION + "-depr",
202: "-//finix AG/contelligent/Category Definition/EN",
203: "category-definition.dtd");
204: addDTD(
205: CONTELLIGENT_CONFIGURATION + "-depr",
206: "-//finix AG/contelligent/Contelligent Configuration/EN",
207: "contelligent-configuration.dtd");
208: addDTD(ACL + "-1.0",
209: "-//finix AG/contelligent/Access Control List V1.0/EN",
210: "acl_1_0.dtd");
211: addDTD(ACL + "-depr",
212: "-//finix AG/contelligent/Access Control List/EN",
213: "acl.dtd");
214: addDTD(RESOURCE + "-depr",
215: "-//finix AG/contelligent/Resource/EN", "resource.dtd");
216: addDTD(TYPE_METAINFO + "-depr",
217: "-//finix AG/contelligent/Type Meta-Information/EN",
218: "type-metainfo.dtd");
219: addDTD(DESCRIPTION + "-depr",
220: "-//finix AG/contelligent/Description/EN",
221: "description.dtd");
222: addDTD(PRINCIPAL_DATA + "-depr",
223: "-//finix AG/contelligent/Principal Data/EN",
224: "principaldata.dtd");
225: addDTD(WORKFLOW_DEFINITION + "-depr",
226: "-//finix AG/contelligent/Workflow Definition/EN",
227: "workflow-definition.dtd");
228: addDTD(
229: SEARCH_ENGINE + "-depr",
230: "-//finix AG/contelligent/Search Engine Configuration V1.0/EN",
231: "searchengine_1_0.dtd");
232: addDTD(
233: SEARCH_ENGINE + "-1.0",
234: "-//finix AG/contelligent/Search Engine Configuration/EN",
235: "searchengine.dtd");
236: addDTD(ERROR_MAPPING + "-depr",
237: "-//finix AG/contelligent/Error-Mapping/EN",
238: "error-mapping.dtd");
239: addDTD(
240: PROJECT_CONFIG + "-1.1",
241: "-//finix AG/contelligent/Project Configuration V1.1/EN",
242: "project_1_1.dtd");
243: addDTD(
244: PROJECT_CONFIG + "-1.0",
245: "-//finix AG/contelligent/Project Configuration V1.0/EN",
246: "project_1_0.dtd");
247: addDTD(PROJECT_CONFIG + "-depr",
248: "-//finix AG/contelligent/Project Configuration/EN",
249: "project.dtd");
250: }
251:
252: public void registerAllDTDsWithDigester(Digester digester) {
253: Iterator i = pubIdToFileNames.entrySet().iterator();
254:
255: while (i.hasNext()) {
256: Map.Entry entry = (Map.Entry) i.next();
257: digester.register((String) entry.getKey(), (String) entry
258: .getValue());
259: }
260:
261: }
262:
263: public String getPublicId(String name) {
264: return (String) publicIDs.get(name);
265: }
266:
267: public String getFileName(String name) {
268: return (String) dtds.get(name);
269: }
270:
271: public String getFileURL(String name) {
272: return (String) realFileNames.get(name);
273: }
274:
275: public void setFileURL(String name, String fileName) {
276: realFileNames.put(name, fileName);
277: Object pubId = publicIDs.get(name);
278: pubIdToFileNames.put(pubId, fileName);
279: }
280:
281: public Map getFileNameMap() {
282: return new HashMap(dtds);
283: }
284:
285: public Map getPublicIdFileNames() {
286: return new HashMap(pubIdToFileNames);
287: }
288:
289: public void addDTD(String name, String publicId, String dtd) {
290: addDTD(name, publicId, dtd, dtd);
291: }
292:
293: public void addDTD(String name, String publicId, String dtd,
294: String realFileName) {
295: publicIDs.put(name, publicId);
296: dtds.put(name, dtd);
297: realFileNames.put(name, realFileName);
298: pubIdToFileNames.put(publicId, realFileName);
299: }
300:
301: }
|