dtdentityresolver.java

来自「用jbuilder写的源程序」· Java 代码 · 共 41 行

JAVA
41
字号
package com.jdon.controller.config;

import java.net.URL;
import org.xml.sax.EntityResolver;
import org.xml.sax.SAXException;
import java.io.InputStream;
import java.io.IOException;
import org.xml.sax.InputSource;

public class DTDEntityResolver implements EntityResolver {
  //~ Methods ////////////////////////////////////////////////////////////////

  public InputSource resolveEntity(String publicId, String systemId) throws
      SAXException, IOException {
    if (systemId == null) {
      return null;
    }

    URL url = new URL(systemId);
    String file = url.getFile();

    if ( (file != null) && (file.indexOf('/') > -1)) {
      file = file.substring(file.lastIndexOf('/') + 1);
    }

    if ("www.jdon.com".equals(url.getHost())) {
      InputStream is = getClass().getResourceAsStream("/META-INF/" + file);

      if (is == null) {
        is = getClass().getResourceAsStream("/" + file);
      }

      if (is != null) {
        return new InputSource(is);
      }
    }

    return null;
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?