KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > celtix > bus > configuration > spring > CeltixBeansDtdResolver


1 package org.objectweb.celtix.bus.configuration.spring;
2
3
4
5
6
7 import java.io.IOException JavaDoc;
8 import java.io.InputStream JavaDoc;
9 import java.util.logging.Logger JavaDoc;
10
11 import org.xml.sax.EntityResolver JavaDoc;
12 import org.xml.sax.InputSource JavaDoc;
13
14 import org.objectweb.celtix.bus.resource.ResourceManagerImpl;
15 import org.objectweb.celtix.common.i18n.Message;
16 import org.objectweb.celtix.common.logging.LogUtils;
17 import org.objectweb.celtix.configuration.ConfigurationException;
18
19 public class CeltixBeansDtdResolver implements EntityResolver JavaDoc {
20
21     private static final String JavaDoc DTD_SYSTEM_ID =
22         "http://celtix.objectweb.org/configuration/spring/celtix-spring-beans.dtd";
23     private static final String JavaDoc DTD_FILE = "schemas/configuration/celtix-spring-beans.dtd";
24     private static final Logger JavaDoc LOG = LogUtils.getL7dLogger(CeltixBeansDtdResolver.class);
25
26     public InputSource JavaDoc resolveEntity(String JavaDoc publicId, String JavaDoc systemId) throws IOException JavaDoc {
27         if (systemId != null && systemId.equals(DTD_SYSTEM_ID)) {
28             InputStream JavaDoc is = ResourceManagerImpl.instance().getResourceAsStream(getDtdFile());
29             if (is == null) {
30                 throw new ConfigurationException(new Message("COULD_NOT_RESOLVE_BEANS_DTD_EXC", LOG,
31                                                              DTD_SYSTEM_ID));
32             }
33             InputSource JavaDoc source = new InputSource JavaDoc(is);
34             source.setPublicId(publicId);
35             source.setSystemId(systemId);
36             return source;
37         }
38         // Use the default behavior -> download from website or wherever.
39
return null;
40     }
41     
42     protected String JavaDoc getDtdFile() {
43         return DTD_FILE;
44     }
45 }
46
Popular Tags