Initial revision
[mir.git] / source / mir / misc / InputSourceResolver.java
1 package mir.misc;
2
3 import java.io.FileInputStream;
4 import java.io.InputStream;
5 import java.io.FileNotFoundException;
6 import java.io.IOException;
7 import org.xml.sax.InputSource;
8 import org.xml.sax.SAXException;
9 import com.icl.saxon.ExtendedInputSource;
10
11 /**
12  * Title:
13  * Description:
14  * Copyright:    Copyright (c) 2001
15  * Company:
16  * @author
17  * @version 1.0
18  */
19
20
21 public class InputSourceResolver {
22   private static InputSourceResolver single     = new InputSourceResolver();
23   private String prefix = "";
24
25   /**
26    * InputSourceResolver constructor comment.
27    */
28   private InputSourceResolver() {
29     super();
30   }
31
32   /**
33    * Singleton Constructor
34    * @return de.matetrade.tools.InputSourceResolver
35    */
36   private static InputSourceResolver getInstance() {
37     return single;
38   }
39
40   /**
41    * This method was created in VisualAge.
42    * @return InputStream
43    * @param key java.lang.String
44    */
45   private InputStream getFileInputStream( String key )
46     throws IOException {
47
48     FileInputStream is = null;
49     try {
50       is = new FileInputStream( prefix + key );
51     } catch ( FileNotFoundException ex ) {
52       throw new IOException( "FileNotFoundExcpetion: input for <" + key + "> not found" );
53     }
54
55     return is;
56   }
57
58
59   /**
60    * This method was created in VisualAge.
61    * @return org.xml.sax.InputSource
62    * @param key java.lang.String
63    */
64   public static InputSource resolve( String key )
65     throws IOException {
66
67     InputSource is = new InputSource( single.getFileInputStream( key ) );
68     if ( key.indexOf( ':' ) >= 0 ) {
69       is.setSystemId( "file:///" + key );               // special for win (file:///c:/xxx)
70     } else {
71       is.setSystemId( "file://" + key );
72     }
73
74     return is;
75   }
76 }