1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.backsource.utils.xml;
21 import java.util.Vector;
22
23 import org.apache.log4j.Logger;
24
25 import org.apache.xml.resolver.CatalogException;
26 /***
27 * A simple wrapper to make it easier to create {@link org.apache.xml.resolver.CatalogEntry} entries programatically.
28 *
29 * @author <a href="mailto:pra@tim.se">Peter Antman</a>
30 * @version $Revision: 1.1.1.1 $
31 */
32
33 public class CatalogEntry {
34 private static final Logger log = Logger.getLogger(CatalogEntry.class);
35 public static final CatalogEntryType PUBLIC = new CatalogEntryType("public",
36 org.apache.xml.resolver.Catalog.PUBLIC
37 );
38 public static final CatalogEntryType SYSTEM = new CatalogEntryType("system",org.apache.xml.resolver.Catalog.SYSTEM);
39 public static final CatalogEntryType REWRITE_SYSTEM = new CatalogEntryType("rewriteSystem",org.apache.xml.resolver.Catalog.REWRITE_SYSTEM);
40 public static final CatalogEntryType URI = new CatalogEntryType("uri",org.apache.xml.resolver.Catalog.URI);
41 public static final CatalogEntryType REWRITE_URI = new CatalogEntryType("rewriteUri",org.apache.xml.resolver.Catalog.REWRITE_URI);
42
43 private org.apache.xml.resolver.CatalogEntry entry;
44 private CatalogEntryType type;
45
46 protected CatalogEntry (CatalogEntryType type, String id, String alternative)throws CatalogException {
47 this.type = type;
48 Vector args = new Vector();
49 args.add(id);
50 args.add(alternative);
51 entry = new org.apache.xml.resolver.CatalogEntry(type.getType(),args );
52 }
53
54 public static CatalogEntry getPublicEntry(String publicId, String uri) throws CatalogException {
55 return new CatalogEntry(PUBLIC, publicId,uri);
56 }
57
58 public static CatalogEntry getSystemEntry(String systemId, String uri) throws CatalogException {
59 return new CatalogEntry(SYSTEM, systemId,uri);
60 }
61
62 public static CatalogEntry getRewriteSystemEntry(String systemIdStartString, String rewritePrefix) throws CatalogException {
63 return new CatalogEntry(REWRITE_SYSTEM, systemIdStartString,rewritePrefix);
64 }
65 public static CatalogEntry getUriEntry(String name, String uri) throws CatalogException {
66 return new CatalogEntry(URI, name,uri);
67 }
68 public static CatalogEntry getRewriteUriEntry(String uriStartString, String rewritePrefix) throws CatalogException {
69 return new CatalogEntry(REWRITE_URI, uriStartString,rewritePrefix);
70 }
71
72 public CatalogEntryType getType() {
73 return type;
74 }
75
76 public org.apache.xml.resolver.CatalogEntry getEntry() {
77 return entry;
78 }
79
80 public static class CatalogEntryType {
81 private String name;
82 private int type;
83 private CatalogEntryType(String name,int type) {
84 this.name = name;
85 this.type = type;
86 }
87
88 public int getType() {
89 return type;
90 }
91
92 public String getName() {
93 return name;
94 }
95
96 public boolean equals(Object other) {
97 if ( other instanceof CatalogEntryType) {
98 return other == this;
99 }
100 return false;
101 }
102 }
103
104 }