Initial revision
[mir.git] / source / mir / misc / InputSourceResolver.java
diff --git a/source/mir/misc/InputSourceResolver.java b/source/mir/misc/InputSourceResolver.java
new file mode 100755 (executable)
index 0000000..0f85d1c
--- /dev/null
@@ -0,0 +1,76 @@
+package mir.misc;
+
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import com.icl.saxon.ExtendedInputSource;
+
+/**
+ * Title:
+ * Description:
+ * Copyright:    Copyright (c) 2001
+ * Company:
+ * @author
+ * @version 1.0
+ */
+
+
+public class InputSourceResolver {
+  private static InputSourceResolver single    = new InputSourceResolver();
+  private String prefix = "";
+
+  /**
+   * InputSourceResolver constructor comment.
+   */
+  private InputSourceResolver() {
+    super();
+  }
+
+  /**
+   * Singleton Constructor
+   * @return de.matetrade.tools.InputSourceResolver
+   */
+  private static InputSourceResolver getInstance() {
+    return single;
+  }
+
+  /**
+   * This method was created in VisualAge.
+   * @return InputStream
+   * @param key java.lang.String
+   */
+  private InputStream getFileInputStream( String key )
+    throws IOException {
+
+    FileInputStream is = null;
+    try {
+      is = new FileInputStream( prefix + key );
+    } catch ( FileNotFoundException ex ) {
+      throw new IOException( "FileNotFoundExcpetion: input for <" + key + "> not found" );
+    }
+
+    return is;
+  }
+
+
+  /**
+   * This method was created in VisualAge.
+   * @return org.xml.sax.InputSource
+   * @param key java.lang.String
+   */
+  public static InputSource resolve( String key )
+    throws IOException {
+
+    InputSource is = new InputSource( single.getFileInputStream( key ) );
+    if ( key.indexOf( ':' ) >= 0 ) {
+      is.setSystemId( "file:///" + key );              // special for win (file:///c:/xxx)
+    } else {
+      is.setSystemId( "file://" + key );
+    }
+
+    return is;
+  }
+}
\ No newline at end of file