View Javadoc

1   /*
2    * Copyright (c) 2003 Peter Antman, Teknik i Media  <peter.antman@tim.se>
3    *
4    * $Id: CatalogEntry.java,v 1.1.1.1 2004/05/19 12:07:31 pra Exp $
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 of the License, or (at your option) any 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  USA
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           } // end of if ()
100          return false;
101       }
102    }
103    
104 }// CatalogEntry