summaryrefslogtreecommitdiff
path: root/sources/scala/xml/parsing/ExternalSources.scala
diff options
context:
space:
mode:
authorburaq <buraq@epfl.ch>2005-05-26 14:02:47 +0000
committerburaq <buraq@epfl.ch>2005-05-26 14:02:47 +0000
commite389932a0948127ed9b34eb2c7c57aa9817a4368 (patch)
tree6ea6a8b3fde870f4ba4f732654241b38517f9f91 /sources/scala/xml/parsing/ExternalSources.scala
parent2a99a8010f8b129893d046976195997bc9feb363 (diff)
downloadscala-e389932a0948127ed9b34eb2c7c57aa9817a4368.tar.gz
scala-e389932a0948127ed9b34eb2c7c57aa9817a4368.tar.bz2
scala-e389932a0948127ed9b34eb2c7c57aa9817a4368.zip
even better dtd parsing! handled URLs now
Diffstat (limited to 'sources/scala/xml/parsing/ExternalSources.scala')
-rw-r--r--sources/scala/xml/parsing/ExternalSources.scala76
1 files changed, 76 insertions, 0 deletions
diff --git a/sources/scala/xml/parsing/ExternalSources.scala b/sources/scala/xml/parsing/ExternalSources.scala
new file mode 100644
index 0000000000..7d42d6ec6a
--- /dev/null
+++ b/sources/scala/xml/parsing/ExternalSources.scala
@@ -0,0 +1,76 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2003-2005, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+** $Id$
+\* */
+
+package scala.xml.parsing ;
+
+import scala.io.Source;
+import java.net._;
+import java.io._;
+
+trait ExternalSources : (MarkupParser with MarkupHandler) {
+
+
+ private def externalSourceFromURL(url:URL): Source = {
+ val in =
+ new BufferedReader(
+ new InputStreamReader(
+ url.openStream()));
+
+ //@todo: replace this hack with proper Source implementation
+
+ val str = new StringBuffer();
+ var inputLine:String = _;
+
+ //while (inputLine = in.readLine()) != null) {
+ while ({inputLine = in.readLine(); inputLine} != null) {
+ // Console.println(inputLine); // DEBUG
+ str.append(inputLine);
+ str.append('\n'); // readable output
+ }
+ in.close();
+
+ class MyClass extends Source {
+
+ def newIter = new Iterator[Char] {
+ var i = -1;
+ private val len = str.length()-1;
+ def hasNext = i < len;
+ def next = {
+ i = i + 1;
+ str.charAt(i);
+ }
+ }
+
+ val iter = newIter;
+
+ def reset: Source = new MyClass;
+
+ override var descr = url.toExternalForm();
+ }
+
+ return new MyClass;
+ }
+
+ def externalSource(systemId: String): Source = {
+ //Console.println("in external source("+systemId+")");
+ if(systemId.startsWith("http:")) {
+ return externalSourceFromURL(new URL(systemId));
+ }
+
+ var fileStr = input.descr;
+
+ if(input.descr.startsWith("file:")) {
+ fileStr = input.descr.substring(5, input.descr.length());
+ } else
+ fileStr = fileStr.substring(0,
+ fileStr.lastIndexOf(java.io.File.separator)+1);
+ Source.fromFile(fileStr + systemId);
+ }
+
+}