01: package hero.xpdl;
02:
03: import java.util.HashMap;
04: import java.util.Map;
05: import java.net.URL;
06:
07: /**
08: * This class defines the declarations of defaults DTDs used for XPDL language
09: * @author Florent Benoit
10: */
11: public class XPDLDTDs implements DTDs {
12:
13: /**
14: * List of default dtds
15: */
16: private static final String[] DEFAULT_DTDS = new String[] { "xpdl.dtd", };
17:
18: /**
19: * List of default publicId
20: */
21: private static final String[] DEFAULT_DTDS_PUBLIC_ID = new String[] { "bonitaXPDL", };
22:
23: /**
24: * Map where mapping publicId/dtds are stored
25: */
26: private static HashMap dtdsMapping = null;
27:
28: /**
29: * Build a new object for DTDs handling
30: */
31: public XPDLDTDs() {
32: dtdsMapping = new HashMap();
33: addMapping(DEFAULT_DTDS, DEFAULT_DTDS_PUBLIC_ID);
34: }
35:
36: /**
37: * Gets the mapping between publicIds and DTDs
38: * @return the mapping between publicIds and DTDs
39: */
40: public Map getMapping() {
41: return dtdsMapping;
42: }
43:
44: /**
45: * Add to the list of DTDS the given dtds/publicId
46: * @param dtds array of dtds
47: * @param publicIds array of publicIds
48: */
49: protected void addMapping(String[] dtds, String[] publicIds) {
50: if (dtds.length != publicIds.length) {
51: throw new IllegalStateException(
52: "SEVER ERROR !!! Number of dtds is different of the number of PublicId !!! check the source code");
53: }
54:
55: URL url = null;
56: for (int i = 0; i < dtds.length; i++) {
57: url = XPDLDTDs.class
58: .getResource("/etc/xml/xpdl/" + dtds[i]);
59: if (url == null) {
60: throw new IllegalStateException(
61: "'"
62: + dtds[i]
63: + "' was not found in the current classloader !");
64: }
65: dtdsMapping.put(publicIds[i], url.toString());
66: }
67: }
68:
69: }
|