View Javadoc

1   /*
2    * EntityResolverImpl.java
3    *
4    * Created on June 28, 2001, 1:16 AM
5    */
6   
7   package hotsax.html.sax.helpers;
8   
9   
10  import java.util.*;
11  import java.io.*;
12  import org.xml.sax.*;
13  
14  /***
15   * Special Enitity resolver to handle URIs like file: etc
16   
17   * @author  edh
18   * @version 
19   */
20  public class EntityResolverImpl implements EntityResolver {
21  
22      /*** Creates new EntityResolverImpl */
23      public EntityResolverImpl() {
24      }
25  
26      
27      /*** 
28       * Resolve anu local entities based on URI. Like file://home/edh/index.html etc.
29       */
30      
31      public InputSource resolveEntity(String publicId, String systemId) 
32          throws org.xml.sax.SAXException, java.io.IOException {
33              
34          StringTokenizer tokenizer = new StringTokenizer(systemId, ":");
35  
36          if (tokenizer.hasMoreElements()) {
37              String protocol = tokenizer.nextToken();
38              if (protocol.equalsIgnoreCase("file")) {   // open a reader on the file stream
39                  String path = tokenizer.nextToken();
40                  path = path.substring(1);              // should be /home/edh/index.html
41                  Reader fileReader = new FileReader(path);
42                  return new InputSource(fileReader);
43              }
44          }
45  
46          return null;  // the default
47      }
48      
49  }