DTDEntityResolver xref

View Javadoc

    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.3 2004/11/03 06:59:09 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  			// Search for DTD
    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  			// use the default behaviour
    54  			return null;
    55  		}
    56  	}
    57
    58  }