1 package com.ozacc.mail.impl;
2
3 import java.io.IOException;
4 import java.io.InputStream;
5
6 import org.apache.commons.logging.Log;
7 import org.apache.commons.logging.LogFactory;
8 import org.xml.sax.EntityResolver;
9 import org.xml.sax.InputSource;
10 import org.xml.sax.SAXException;
11
12 /***
13 * ozacc-mail libraryのDTDファイルをクラスパス上から検出するEntityResolver実装。
14 *
15 * @since 1.1
16 *
17 * @author Tomohiro Otsuka
18 * @version $Id: DTDEntityResolver.java,v 1.1.2.2 2004/11/25 08:01:07 otsuka Exp $
19 */
20 public class DTDEntityResolver implements EntityResolver {
21
22 private static Log log = LogFactory.getLog(DTDEntityResolver.class);
23
24 private static final String URL = "http://www.ozacc.com/library/dtd/";
25
26 /***
27 * クラスパス「com/ozacc/mail」上で、指定されたsystemIdのファイル名と同じファイルを検出します。
28 * もしも検出できなければnullを返します。(必ず検出できるはずです。)
29 *
30 * @see org.xml.sax.EntityResolver#resolveEntity(java.lang.String, java.lang.String)
31 */
32 public InputSource resolveEntity(String publicId, String systemId) throws SAXException,
33 IOException {
34 if (systemId != null && systemId.startsWith(URL)) {
35 log.debug("クラスパス[com/ozacc/mail/]上で'" + systemId + "'の取得を試みます。");
36
37
38 ClassLoader classLoader = this.getClass().getClassLoader();
39 InputStream dtdStream = classLoader.getResourceAsStream("com/ozacc/mail/"
40 + systemId.substring(URL.length()));
41
42 if (dtdStream == null) {
43 log.debug("'" + systemId + "'はクラスパス上に見つかりませんでした。");
44 return null;
45 } else {
46 log.debug("'" + systemId + "'をクラスパス上で取得しました。");
47 InputSource source = new InputSource(dtdStream);
48 source.setPublicId(publicId);
49 source.setSystemId(systemId);
50 return source;
51 }
52 } else {
53
54 return null;
55 }
56 }
57
58 }