diff options
Diffstat (limited to 'src/library/scala/xml/pull/XMLEventReader.scala')
-rw-r--r-- | src/library/scala/xml/pull/XMLEventReader.scala | 86 |
1 files changed, 44 insertions, 42 deletions
diff --git a/src/library/scala/xml/pull/XMLEventReader.scala b/src/library/scala/xml/pull/XMLEventReader.scala index 130d7afe19..0577cc52c5 100644 --- a/src/library/scala/xml/pull/XMLEventReader.scala +++ b/src/library/scala/xml/pull/XMLEventReader.scala @@ -1,7 +1,7 @@ /* __ *\ ** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2006, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** +** / __/ __// _ | / / / _ | (c) 2003-2007, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** ** /____/\___/_/ |_/____/_/ | | ** ** |/ ** \* */ @@ -15,32 +15,34 @@ package scala.xml.pull import java.lang.{Runnable, Thread} import scala.io.Source -import scala.xml.parsing.{MarkupParser, MarkupHandler,ExternalSources} - -/** a pull parser that offers to view an XML document as a series of events. - * Please note that this API might change. Here's how to use this class +import scala.xml.parsing.{ExternalSources, MarkupHandler, MarkupParser} + +/** <p> + * A pull parser that offers to view an XML document as a series of events. + * Please note that this API might change. Here's how to use this class + * </p><pre> + * <b>import</b> scala.xml._ + * <b>import</b> scala.xml.pull._ + * <b>import</b> scala.io.Source * -<pre> -import scala.xml._ -import scala.xml.pull._ -import scala.io.Source - -object reader { - val src = Source.fromString("<hello><world/></hello>") - val er = new XMLEventReader().initialize(src) - - def main(args:Array[String]): unit = { - Console.println(er.next) - Console.println(er.next) - } -} -</pre> + * <b>object</b> reader { + * <b>val</b> src = Source.fromString("<hello><world/></hello>") + * <b>val</b> er = new XMLEventReader().initialize(src) + * + * <b>def</b> main(args: Array[String]) { + * Console.println(er.next) + * Console.println(er.next) + * } + * } + * </pre> + * + * @author Burak Emir */ class XMLEventReader extends Iterator[XMLEvent] { var src:Source = null def getSource = this.src - def initialize(src:Source): this.type = { + def initialize(src: Source): this.type = { this.src = src this.parserThread = new Thread(new Parser()) this.parserThread.start() @@ -55,7 +57,7 @@ class XMLEventReader extends Iterator[XMLEvent] { while(continue) { wait() } - continue = true; + continue = true notifyAll } def getAndClearEvent: XMLEvent = synchronized { @@ -66,21 +68,21 @@ class XMLEventReader extends Iterator[XMLEvent] { xmlEvent = null r } - def setEvent(e:XMLEvent) = { - xmlEvent = e; + def setEvent(e: XMLEvent) { + xmlEvent = e } def doNotify() = synchronized { - XMLEventReader.this.continue = false; + XMLEventReader.this.continue = false notifyAll() - while(!XMLEventReader.this.continue) wait(); + while (!XMLEventReader.this.continue) wait(); NodeSeq.Empty } // iterator methods def next: XMLEvent = { - myresume; + myresume val r = getAndClearEvent r } @@ -94,34 +96,34 @@ class XMLEventReader extends Iterator[XMLEvent] { val preserveWS = true val input = XMLEventReader.this.getSource - override def elemStart(pos:int, pre: String, label: String, attrs: MetaData, scope:NamespaceBinding):Unit = { - setEvent(ElemStart(pre,label,attrs,scope)); doNotify + override def elemStart(pos:int, pre: String, label: String, attrs: MetaData, scope: NamespaceBinding) { + setEvent(ElemStart(pre, label, attrs, scope)); doNotify } - override def elemEnd(pos: int, pre: String, label: String): Unit = { - setEvent(ElemEnd(pre,label)); doNotify + override def elemEnd(pos: int, pre: String, label: String) { + setEvent(ElemEnd(pre, label)); doNotify } final def elem(pos: int, pre: String, label: String, attrs: MetaData, pscope: NamespaceBinding, nodes: NodeSeq): NodeSeq = NodeSeq.Empty - def procInstr(pos: Int, target: String, txt: String ) = { - setEvent(ElemStart(null,"comm",null,null)); doNotify + def procInstr(pos: Int, target: String, txt: String) { + setEvent(ElemStart(null, "comm", null, null)); doNotify } - def comment(pos: Int, txt: String ) = { - setEvent(ElemStart(null,"comm",null,null)); doNotify + def comment(pos: Int, txt: String) { + setEvent(ElemStart(null, "comm", null, null)); doNotify } - def entityRef(pos: Int, n: String) = { - setEvent(ElemStart(null,"eref",null,null)); doNotify - } + def entityRef(pos: Int, n: String) { + setEvent(ElemStart(null, "eref", null, null)); doNotify + } - def text(pos: Int, txt:String) = { - setEvent(ElemStart(null,"tex",null,null)); doNotify + def text(pos: Int, txt:String) { + setEvent(ElemStart(null, "tex", null, null)); doNotify } - override def run(): unit = { + override def run() { curInput = input this.nextch doNotify() |