src/horaris/File2Horaro.java
changeset 12 3932322b7d83
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/horaris/File2Horaro.java	Wed Jan 17 19:14:26 2007 +0100
@@ -0,0 +1,53 @@
+package horaris;
+
+import javax.microedition.midlet.MIDlet;
+
+import ogdl.Graph;
+import ogdl.Ogdl2Graph;
+import ogdl.OgdlParser;
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.io.InputStreamReader;
+import java.lang.Class;
+
+public class File2Horaro
+{
+	public static Horaro load(String filename, MIDlet main)
+	{
+		/* Open file */
+		InputStream is = main.getClass().getResourceAsStream(filename);
+		if (is == null)
+		{
+			System.err.println("Resource "+ filename +
+					" not found");
+			return null;
+		}
+		InputStreamReader in;
+		try {
+			in = new InputStreamReader(is,
+					"UTF-8");
+		} catch (UnsupportedEncodingException e) {
+			System.err.println("Enconding error " + e);
+			return null;
+		}
+
+		Horaro horaroevents = new Horaro();
+		try {
+			OgdlParser parser = new OgdlParser(in, horaroevents);
+			parser.parse();
+		} catch (Exception e) {
+			System.err.println("Exception parsing." + e.getMessage());
+		}
+
+
+		try {
+			in.close();
+		} catch (IOException e)
+		{
+			System.err.println("Exception closing is");
+		}
+
+		return horaroevents;
+	}
+}