aded svn:keywords, file headers in XML classes
git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@12905 5e8d7ff9-d8ef-0310-90f0-a4852d11357a
This commit is contained in:
parent
0295a7db94
commit
3c241444e3
|
@ -972,7 +972,7 @@ TEST
|
|||
/>
|
||||
<!-- Build partest -->
|
||||
<mkdir dir="${strap.dir}/lib/partest"/>
|
||||
<starr
|
||||
<quick
|
||||
srcdir="${src.dir}/partest"
|
||||
destdir="${strap.dir}/lib/partest"
|
||||
addparams="${nsc.params}"
|
||||
|
@ -982,7 +982,7 @@ TEST
|
|||
<pathelement location="${strap.dir}/lib/compiler"/>
|
||||
<pathelement location="${strap.dir}/lib/actors"/>
|
||||
</classpath>
|
||||
</starr>
|
||||
</quick>
|
||||
<!-- Timing the build -->
|
||||
<stopwatch name="timer.strap" action="total"/>
|
||||
<!-- Copy support files to build folder and links external libraries-->
|
||||
|
|
|
@ -11,8 +11,6 @@
|
|||
|
||||
package scala.xml
|
||||
|
||||
import compat.StringBuilder
|
||||
|
||||
/** The class <code>Atom</code> provides an XML node for text (PCDATA).
|
||||
* It is used in both non-bound and bound XML representations.
|
||||
*
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* __ *\
|
||||
** ________ ___ / / ___ Scala API **
|
||||
** / __/ __// _ | / / / _ | (c) 2003-2007, LAMP/EPFL **
|
||||
** __\ \/ /__/ __ |/ /__/ __ | **
|
||||
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
|
||||
** /____/\___/_/ |_/____/_/ | | **
|
||||
** |/ **
|
||||
\* */
|
||||
|
@ -11,9 +11,6 @@
|
|||
|
||||
package scala.xml
|
||||
|
||||
|
||||
import compat.StringBuilder
|
||||
|
||||
/** The class <code>Comment</code> implements an XML node for comments.
|
||||
*
|
||||
* @author Burak Emir
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* __ *\
|
||||
** ________ ___ / / ___ Scala API **
|
||||
** / __/ __// _ | / / / _ | (c) 2003-2006, LAMP/EPFL **
|
||||
** __\ \/ /__/ __ |/ /__/ __ | **
|
||||
** / __/ __// _ | / / / _ | (c) 2003-2007, LAMP/EPFL **
|
||||
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
|
||||
** /____/\___/_/ |_/____/_/ | | **
|
||||
** |/ **
|
||||
\* */
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* __ *\
|
||||
** ________ ___ / / ___ Scala API **
|
||||
** / __/ __// _ | / / / _ | (c) 2002-2007, LAMP/EPFL **
|
||||
** __\ \/ /__/ __ |/ /__/ __ | **
|
||||
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
|
||||
** /____/\___/_/ |_/____/_/ | | **
|
||||
** |/ **
|
||||
\* */
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* __ *\
|
||||
** ________ ___ / / ___ Scala API **
|
||||
** / __/ __// _ | / / / _ | (c) 2003-2007, LAMP/EPFL **
|
||||
** __\ \/ /__/ __ |/ /__/ __ | **
|
||||
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
|
||||
** /____/\___/_/ |_/____/_/ | | **
|
||||
** |/ **
|
||||
\* */
|
||||
|
@ -11,8 +11,6 @@
|
|||
|
||||
package scala.xml
|
||||
|
||||
import compat.StringBuilder
|
||||
|
||||
/** The class <code>EntityRef</code> implements an XML node for entity
|
||||
* references.
|
||||
*
|
||||
|
|
|
@ -11,9 +11,6 @@
|
|||
|
||||
package scala.xml
|
||||
|
||||
|
||||
import compat.StringBuilder
|
||||
|
||||
/** A hack to group XML nodes in one node for output.
|
||||
*
|
||||
* @author Burak Emir
|
||||
|
|
|
@ -10,8 +10,6 @@
|
|||
|
||||
package scala.xml
|
||||
|
||||
// $Id$
|
||||
|
||||
/** <p>
|
||||
* Use this class to match on (unprefixed) attribute values
|
||||
* <p><pre>
|
||||
|
|
|
@ -11,8 +11,6 @@
|
|||
|
||||
package scala.xml
|
||||
|
||||
import compat.StringBuilder
|
||||
|
||||
/** <p>
|
||||
* Attribute information item, and linked list of attribute information items.
|
||||
* These are triples consisting of <code>prefix,key,value</code>. To obtain
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
package scala.xml
|
||||
|
||||
import Predef._
|
||||
import compat.StringBuilder
|
||||
|
||||
/** The class <code>NamespaceBinding</code> represents namespace bindings
|
||||
* and scopes. The binding for the default namespace is treated as a null
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* __ *\
|
||||
** ________ ___ / / ___ Scala API **
|
||||
** / __/ __// _ | / / / _ | (c) 2003-2006, LAMP/EPFL **
|
||||
** __\ \/ /__/ __ |/ /__/ __ | **
|
||||
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
|
||||
** /____/\___/_/ |_/____/_/ | | **
|
||||
** |/ **
|
||||
\* */
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* __ *\
|
||||
** ________ ___ / / ___ Scala API **
|
||||
** / __/ __// _ | / / / _ | (c) 2003-2006, LAMP/EPFL **
|
||||
** __\ \/ /__/ __ |/ /__/ __ | **
|
||||
** / __/ __// _ | / / / _ | (c) 2003-2007, LAMP/EPFL **
|
||||
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
|
||||
** /____/\___/_/ |_/____/_/ | | **
|
||||
** |/ **
|
||||
\* */
|
||||
|
@ -11,9 +11,6 @@
|
|||
|
||||
package scala.xml
|
||||
|
||||
|
||||
import compat.StringBuilder
|
||||
|
||||
case object Null extends MetaData {
|
||||
|
||||
/** appends given MetaData items to this MetaData list */
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
package scala.xml
|
||||
|
||||
import scala.collection.Map
|
||||
import compat.StringBuilder
|
||||
|
||||
/** Class for pretty printing. After instantiating, you can use the
|
||||
* toPrettyXML methods to convert XML to a formatted string. The class
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* __ *\
|
||||
** ________ ___ / / ___ Scala API **
|
||||
** / __/ __// _ | / / / _ | (c) 2003-2006, LAMP/EPFL **
|
||||
** __\ \/ /__/ __ |/ /__/ __ | **
|
||||
** / __/ __// _ | / / / _ | (c) 2003-2007, LAMP/EPFL **
|
||||
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
|
||||
** /____/\___/_/ |_/____/_/ | | **
|
||||
** |/ **
|
||||
\* */
|
||||
|
@ -11,8 +11,6 @@
|
|||
|
||||
package scala.xml
|
||||
|
||||
import compat.StringBuilder
|
||||
|
||||
/**
|
||||
* This object provides an extractor method to match a qualified node with its namespace URI
|
||||
*
|
||||
|
|
|
@ -1,3 +1,13 @@
|
|||
/* __ *\
|
||||
** ________ ___ / / ___ Scala API **
|
||||
** / __/ __// _ | / / / _ | (c) 2002-2007, LAMP/EPFL **
|
||||
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
|
||||
** /____/\___/_/ |_/____/_/ | | **
|
||||
** |/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
|
||||
package scala.xml.include
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,3 +1,13 @@
|
|||
/* __ *\
|
||||
** ________ ___ / / ___ Scala API **
|
||||
** / __/ __// _ | / / / _ | (c) 2002-2007, LAMP/EPFL **
|
||||
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
|
||||
** /____/\___/_/ |_/____/_/ | | **
|
||||
** |/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
|
||||
package scala.xml.include
|
||||
|
||||
/**
|
||||
|
@ -9,5 +19,5 @@ package scala.xml.include
|
|||
*/
|
||||
class UnavailableResourceException(message: String)
|
||||
extends XIncludeException(message) {
|
||||
def this() = this(null);
|
||||
def this() = this(null)
|
||||
}
|
||||
|
|
|
@ -1,3 +1,13 @@
|
|||
/* __ *\
|
||||
** ________ ___ / / ___ Scala API **
|
||||
** / __/ __// _ | / / / _ | (c) 2002-2007, LAMP/EPFL **
|
||||
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
|
||||
** /____/\___/_/ |_/____/_/ | | **
|
||||
** |/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
|
||||
package scala.xml.include
|
||||
|
||||
/**
|
||||
|
@ -20,9 +30,9 @@ class XIncludeException(message: String) extends Exception(message) {
|
|||
/**
|
||||
* uses <code>null</code> as its error detail message.
|
||||
*/
|
||||
def this() = this(null);
|
||||
def this() = this(null)
|
||||
|
||||
private var rootCause: Throwable = null;
|
||||
private var rootCause: Throwable = null
|
||||
|
||||
/**
|
||||
* When an <code>IOException</code>, <code>MalformedURLException</code>
|
||||
|
@ -34,8 +44,8 @@ class XIncludeException(message: String) extends Exception(message) {
|
|||
* @param nestedException the underlying exception which
|
||||
caused the XIncludeException to be thrown
|
||||
*/
|
||||
def setRootCause(nestedException: Throwable ): Unit = {
|
||||
this.rootCause = nestedException;
|
||||
def setRootCause(nestedException: Throwable ) {
|
||||
this.rootCause = nestedException
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -46,11 +56,9 @@ class XIncludeException(message: String) extends Exception(message) {
|
|||
* This method allows you to retrieve the original exception.
|
||||
* It returns null if no such exception caused this <code>XIncludeException</code>.
|
||||
*
|
||||
* @return Throwable the underlying exception which
|
||||
caused the XIncludeException to be thrown
|
||||
* @return Throwable the underlying exception which caused the
|
||||
* <code>XIncludeException</code> to be thrown
|
||||
*/
|
||||
def getRootCause(): Throwable = {
|
||||
return this.rootCause;
|
||||
}
|
||||
def getRootCause(): Throwable = this.rootCause
|
||||
|
||||
}
|
||||
|
|
|
@ -1,8 +1,16 @@
|
|||
package scala.xml.include.sax;
|
||||
/* __ *\
|
||||
** ________ ___ / / ___ Scala API **
|
||||
** / __/ __// _ | / / / _ | (c) 2002-2007, LAMP/EPFL **
|
||||
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
|
||||
** /____/\___/_/ |_/____/_/ | | **
|
||||
** |/ **
|
||||
\* */
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.InputStream;
|
||||
// $Id$
|
||||
|
||||
package scala.xml.include.sax
|
||||
|
||||
import java.io.{IOException, InputStreamReader, InputStream}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
@ -13,8 +21,10 @@ import java.io.InputStream;
|
|||
* If it fails to determine the type of the encoding,
|
||||
* it returns the default UTF-8.
|
||||
* </p>
|
||||
* <p>
|
||||
* Translated from Elliotte Rusty Harold's Java source
|
||||
* </p>
|
||||
*
|
||||
* translated from Elliotte Rusty Harold's Java source
|
||||
* @author Burak Emir
|
||||
*/
|
||||
object EncodingHeuristics {
|
||||
|
|
|
@ -1,3 +1,13 @@
|
|||
/* __ *\
|
||||
** ________ ___ / / ___ Scala API **
|
||||
** / __/ __// _ | / / / _ | (c) 2002-2007, LAMP/EPFL **
|
||||
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
|
||||
** /____/\___/_/ |_/____/_/ | | **
|
||||
** |/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
|
||||
package scala.xml.include.sax
|
||||
|
||||
import org.xml.sax.SAXException
|
||||
|
@ -16,21 +26,21 @@ object Main {
|
|||
* @param args contains the URLs and/or filenames
|
||||
* of the documents to be procesed.
|
||||
*/
|
||||
def main(args: Array[String]): Unit = {
|
||||
var parser: XMLReader = null;
|
||||
var err = false;
|
||||
def main(args: Array[String]) {
|
||||
var parser: XMLReader = null
|
||||
var err = false
|
||||
try {
|
||||
parser = XMLReaderFactory.createXMLReader();
|
||||
parser = XMLReaderFactory.createXMLReader()
|
||||
}
|
||||
catch {
|
||||
case e:SAXException =>
|
||||
try {
|
||||
parser = XMLReaderFactory.createXMLReader(
|
||||
"org.apache.xerces.parsers.SAXParser");
|
||||
"org.apache.xerces.parsers.SAXParser")
|
||||
} catch {
|
||||
case e2:SAXException =>
|
||||
System.err.println("Could not find an XML parser");
|
||||
err = true;
|
||||
System.err.println("Could not find an XML parser")
|
||||
err = true
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -61,7 +71,7 @@ object Main {
|
|||
}
|
||||
arg = 2;
|
||||
}
|
||||
if(err) return;
|
||||
if (err) return;
|
||||
|
||||
while (arg < args.length) {
|
||||
try {
|
||||
|
@ -83,14 +93,14 @@ object Main {
|
|||
}
|
||||
catch {
|
||||
case e:SAXParseException =>
|
||||
System.err.println(e);
|
||||
System.err.println(e)
|
||||
System.err.println("Problem in " + e.getSystemId()
|
||||
+ " at line " + e.getLineNumber());
|
||||
+ " at line " + e.getLineNumber())
|
||||
case e: Exception => // be specific about exceptions????
|
||||
System.err.println(e);
|
||||
e.printStackTrace();
|
||||
System.err.println(e)
|
||||
e.printStackTrace()
|
||||
}
|
||||
arg = arg + 1;
|
||||
arg += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,24 +1,34 @@
|
|||
/* __ *\
|
||||
** ________ ___ / / ___ Scala API **
|
||||
** / __/ __// _ | / / / _ | (c) 2002-2007, LAMP/EPFL **
|
||||
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
|
||||
** /____/\___/_/ |_/____/_/ | | **
|
||||
** |/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
|
||||
package scala.xml.include.sax
|
||||
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.XMLReader;
|
||||
import org.xml.sax.EntityResolver;
|
||||
import org.xml.sax.Locator;
|
||||
import org.xml.sax.helpers.XMLReaderFactory;
|
||||
import org.xml.sax.helpers.XMLFilterImpl;
|
||||
import org.xml.sax.helpers.NamespaceSupport;
|
||||
import org.xml.sax.helpers.AttributesImpl;
|
||||
import org.xml.sax.Attributes
|
||||
import org.xml.sax.SAXException
|
||||
import org.xml.sax.XMLReader
|
||||
import org.xml.sax.EntityResolver
|
||||
import org.xml.sax.Locator
|
||||
import org.xml.sax.helpers.XMLReaderFactory
|
||||
import org.xml.sax.helpers.XMLFilterImpl
|
||||
import org.xml.sax.helpers.NamespaceSupport
|
||||
import org.xml.sax.helpers.AttributesImpl
|
||||
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.Stack;
|
||||
import java.net.URL
|
||||
import java.net.URLConnection
|
||||
import java.net.MalformedURLException
|
||||
import java.io.UnsupportedEncodingException
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
import java.io.BufferedInputStream
|
||||
import java.io.InputStreamReader
|
||||
import java.util.Stack
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
@ -118,7 +128,7 @@ class XIncludeFilter extends XMLFilterImpl {
|
|||
|
||||
|
||||
// necessary to throw away contents of non-empty XInclude elements
|
||||
private var level = 0;
|
||||
private var level = 0
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
@ -132,13 +142,10 @@ class XIncludeFilter extends XMLFilterImpl {
|
|||
*
|
||||
* @return boolean
|
||||
*/
|
||||
def insideIncludeElement(): boolean = {
|
||||
return level != 0;
|
||||
}
|
||||
def insideIncludeElement(): boolean = level != 0
|
||||
|
||||
|
||||
override def startElement(uri: String, localName: String, qName: String, atts1: Attributes): Unit = {
|
||||
var atts = atts1;
|
||||
override def startElement(uri: String, localName: String, qName: String, atts1: Attributes) {
|
||||
var atts = atts1
|
||||
if (level == 0) { // We're not inside an xi:include element
|
||||
|
||||
// Adjust bases stack by pushing either the new
|
||||
|
@ -199,28 +206,26 @@ class XIncludeFilter extends XMLFilterImpl {
|
|||
|
||||
}
|
||||
|
||||
override def endElement (uri: String , localName: String , qName: String ): Unit = {
|
||||
|
||||
override def endElement (uri: String, localName: String, qName: String ) {
|
||||
if (uri.equals(XINCLUDE_NAMESPACE)
|
||||
&& localName.equals("include")) {
|
||||
level = level - 1;
|
||||
level -= 1;
|
||||
}
|
||||
else if (level == 0) {
|
||||
bases.pop();
|
||||
super.endElement(uri, localName, qName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private var depth = 0;
|
||||
|
||||
override def startDocument(): Unit = {
|
||||
override def startDocument() {
|
||||
level = 0;
|
||||
if (depth == 0) super.startDocument();
|
||||
depth = depth + 1;
|
||||
depth += 1
|
||||
}
|
||||
|
||||
override def endDocument(): Unit = {
|
||||
override def endDocument() {
|
||||
locators.pop();
|
||||
bases.pop(); // pop the URL for the document itself
|
||||
depth = depth - 1;
|
||||
|
@ -346,7 +351,7 @@ class XIncludeFilter extends XMLFilterImpl {
|
|||
|
||||
}
|
||||
|
||||
private var atRoot = false;
|
||||
private var atRoot = false
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
@ -360,11 +365,11 @@ class XIncludeFilter extends XMLFilterImpl {
|
|||
* @throws SAXException if the requested document cannot
|
||||
be downloaded from the specified URL.
|
||||
*/
|
||||
private def includeXMLDocument(url: String): Unit = {
|
||||
var source: URL = null;
|
||||
private def includeXMLDocument(url: String) {
|
||||
var source: URL = null
|
||||
try {
|
||||
val base = bases.peek().asInstanceOf[URL];
|
||||
source = new URL(base, url);
|
||||
val base = bases.peek().asInstanceOf[URL]
|
||||
source = new URL(base, url)
|
||||
}
|
||||
catch {
|
||||
case e:MalformedURLException =>
|
||||
|
@ -376,7 +381,7 @@ class XIncludeFilter extends XMLFilterImpl {
|
|||
|
||||
try {
|
||||
// make this more robust
|
||||
var parser: XMLReader = null;
|
||||
var parser: XMLReader = null
|
||||
try {
|
||||
parser = XMLReaderFactory.createXMLReader();
|
||||
} catch {
|
||||
|
@ -391,30 +396,30 @@ class XIncludeFilter extends XMLFilterImpl {
|
|||
}
|
||||
}
|
||||
if(parser != null) {
|
||||
parser.setContentHandler(this);
|
||||
val resolver = this.getEntityResolver();
|
||||
parser.setContentHandler(this)
|
||||
val resolver = this.getEntityResolver()
|
||||
if (resolver != null) parser.setEntityResolver(resolver);
|
||||
// save old level and base
|
||||
val previousLevel = level;
|
||||
this.level = 0;
|
||||
val previousLevel = level
|
||||
this.level = 0
|
||||
if (bases.contains(source)) {
|
||||
val e = new CircularIncludeException(
|
||||
"Circular XInclude Reference to " + source + getLocation()
|
||||
);
|
||||
throw new SAXException("Circular XInclude Reference", e);
|
||||
throw new SAXException("Circular XInclude Reference", e)
|
||||
}
|
||||
bases.push(source);
|
||||
atRoot = true;
|
||||
parser.parse(source.toExternalForm());
|
||||
bases.push(source)
|
||||
atRoot = true
|
||||
parser.parse(source.toExternalForm())
|
||||
// restore old level and base
|
||||
this.level = previousLevel;
|
||||
bases.pop();
|
||||
this.level = previousLevel
|
||||
bases.pop()
|
||||
}
|
||||
}
|
||||
catch {
|
||||
case e:IOException =>
|
||||
throw new SAXException("Document not found: "
|
||||
+ source.toExternalForm() + getLocation(), e);
|
||||
+ source.toExternalForm() + getLocation(), e)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,24 +1,29 @@
|
|||
/* __ *\
|
||||
** ________ ___ / / ___ Scala API **
|
||||
** / __/ __// _ | / / / _ | (c) 2002-2007, LAMP/EPFL **
|
||||
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
|
||||
** /____/\___/_/ |_/____/_/ | | **
|
||||
** |/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
|
||||
package scala.xml.include.sax
|
||||
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.SAXParseException;
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xml.sax.EntityResolver;
|
||||
import org.xml.sax.helpers.XMLReaderFactory;
|
||||
import org.xml.sax.XMLReader;
|
||||
import org.xml.sax.Locator;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.ext.LexicalHandler;
|
||||
import org.xml.sax.SAXException
|
||||
import org.xml.sax.SAXParseException
|
||||
import org.xml.sax.ContentHandler
|
||||
import org.xml.sax.EntityResolver
|
||||
import org.xml.sax.helpers.XMLReaderFactory
|
||||
import org.xml.sax.XMLReader
|
||||
import org.xml.sax.Locator
|
||||
import org.xml.sax.Attributes
|
||||
import org.xml.sax.ext.LexicalHandler
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.Writer;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.Stack;
|
||||
import java.io.{File, IOException, OutputStream, OutputStreamWriter,
|
||||
UnsupportedEncodingException, Writer}
|
||||
import java.net.{MalformedURLException, URL}
|
||||
import java.util.Stack
|
||||
|
||||
/** XIncluder is a SAX <code>ContentHandler</code>
|
||||
* that writes its XML document onto an output stream after resolving
|
||||
|
@ -31,36 +36,36 @@ import java.util.Stack;
|
|||
class XIncluder(outs:OutputStream, encoding:String) extends Object
|
||||
with ContentHandler with LexicalHandler {
|
||||
|
||||
var out = new OutputStreamWriter(outs, encoding);
|
||||
var out = new OutputStreamWriter(outs, encoding)
|
||||
|
||||
def setDocumentLocator(locator: Locator): Unit = {}
|
||||
def setDocumentLocator(locator: Locator) {}
|
||||
|
||||
def startDocument(): Unit = {
|
||||
def startDocument() {
|
||||
try {
|
||||
out.write("<?xml version='1.0' encoding='"
|
||||
+ encoding + "'?>\r\n");
|
||||
}
|
||||
catch {
|
||||
case e:IOException =>
|
||||
throw new SAXException("Write failed", e);
|
||||
throw new SAXException("Write failed", e)
|
||||
}
|
||||
}
|
||||
|
||||
def endDocument(): Unit = {
|
||||
def endDocument() {
|
||||
try {
|
||||
out.flush();
|
||||
out.flush()
|
||||
}
|
||||
catch {
|
||||
case e:IOException =>
|
||||
throw new SAXException("Flush failed", e);
|
||||
throw new SAXException("Flush failed", e)
|
||||
}
|
||||
}
|
||||
|
||||
def startPrefixMapping(prefix: String , uri: String): Unit = {}
|
||||
def startPrefixMapping(prefix: String , uri: String) {}
|
||||
|
||||
def endPrefixMapping(prefix: String): Unit = {}
|
||||
def endPrefixMapping(prefix: String) {}
|
||||
|
||||
def startElement(namespaceURI: String , localName: String, qualifiedName: String , atts:Attributes ) = {
|
||||
def startElement(namespaceURI: String, localName: String, qualifiedName: String, atts: Attributes) = {
|
||||
try {
|
||||
out.write("<" + qualifiedName);
|
||||
var i = 0; while (i < atts.getLength()) {
|
||||
|
@ -72,31 +77,29 @@ with ContentHandler with LexicalHandler {
|
|||
// can't support the character
|
||||
out.write(xml.Utility.escape(value))
|
||||
out.write("'");
|
||||
i = i + 1;
|
||||
i += 1
|
||||
}
|
||||
out.write(">");
|
||||
out.write(">")
|
||||
}
|
||||
catch {
|
||||
case e:IOException =>
|
||||
throw new SAXException("Write failed", e);
|
||||
throw new SAXException("Write failed", e)
|
||||
}
|
||||
}
|
||||
|
||||
def endElement(namespaceURI: String , localName:String , qualifiedName: String ): Unit = {
|
||||
def endElement(namespaceURI: String, localName:String, qualifiedName: String) {
|
||||
try {
|
||||
out.write("</" + qualifiedName + ">");
|
||||
out.write("</" + qualifiedName + ">")
|
||||
}
|
||||
catch {
|
||||
case e: IOException =>
|
||||
throw new SAXException("Write failed", e);
|
||||
throw new SAXException("Write failed", e)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// need to escape characters that are not in the given
|
||||
// encoding using character references????
|
||||
def characters(ch: Array[char] , start: int , length: int ): Unit = {
|
||||
|
||||
def characters(ch: Array[Char], start: Int, length: Int) {
|
||||
try {
|
||||
var i = 0; while (i < length) {
|
||||
val c = ch(start+i);
|
||||
|
@ -112,33 +115,32 @@ with ContentHandler with LexicalHandler {
|
|||
}
|
||||
catch {
|
||||
case e: IOException =>
|
||||
throw new SAXException("Write failed", e);
|
||||
throw new SAXException("Write failed", e);
|
||||
}
|
||||
}
|
||||
|
||||
def ignorableWhitespace(ch: Array[char], start: int , length: int): Unit = {
|
||||
this.characters(ch, start, length);
|
||||
def ignorableWhitespace(ch: Array[Char], start: Int , length: Int) {
|
||||
this.characters(ch, start, length)
|
||||
}
|
||||
|
||||
// do I need to escape text in PI????
|
||||
def processingInstruction(target: String , data: String): Unit = {
|
||||
|
||||
def processingInstruction(target: String, data: String) {
|
||||
try {
|
||||
out.write("<?" + target + " " + data + "?>");
|
||||
out.write("<?" + target + " " + data + "?>")
|
||||
}
|
||||
catch {
|
||||
case e:IOException =>
|
||||
throw new SAXException("Write failed", e);
|
||||
throw new SAXException("Write failed", e)
|
||||
}
|
||||
}
|
||||
|
||||
def skippedEntity(name: String): Unit = {
|
||||
def skippedEntity(name: String) {
|
||||
try {
|
||||
out.write("&" + name + ";");
|
||||
out.write("&" + name + ";")
|
||||
}
|
||||
catch {
|
||||
case e:IOException =>
|
||||
throw new SAXException("Write failed", e);
|
||||
throw new SAXException("Write failed", e)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -162,39 +164,39 @@ with ContentHandler with LexicalHandler {
|
|||
}
|
||||
}
|
||||
}
|
||||
def endDTD(): Unit = { }
|
||||
def endDTD() {}
|
||||
|
||||
def startEntity(name: String): Unit = {
|
||||
entities.push(name);
|
||||
def startEntity(name: String) {
|
||||
entities.push(name)
|
||||
}
|
||||
|
||||
|
||||
def endEntity(name: String): Unit = {
|
||||
entities.pop();
|
||||
def endEntity(name: String) {
|
||||
entities.pop()
|
||||
}
|
||||
|
||||
def startCDATA(): Unit = {}
|
||||
def endCDATA(): Unit = {}
|
||||
def startCDATA() {}
|
||||
def endCDATA() {}
|
||||
|
||||
// Just need this reference so we can ask if a comment is
|
||||
// inside an include element or not
|
||||
private var filter: XIncludeFilter = null;
|
||||
|
||||
def setFilter(filter: XIncludeFilter): Unit = {
|
||||
this.filter = filter;
|
||||
def setFilter(filter: XIncludeFilter) {
|
||||
this.filter = filter
|
||||
}
|
||||
|
||||
def comment(ch: Array[char], start: int, length: int): Unit = {
|
||||
def comment(ch: Array[Char], start: Int, length: Int) {
|
||||
|
||||
if (!inDTD && !filter.insideIncludeElement()) {
|
||||
try {
|
||||
out.write("<!--");
|
||||
out.write(ch, start, length);
|
||||
out.write("-->");
|
||||
out.write("<!--")
|
||||
out.write(ch, start, length)
|
||||
out.write("-->")
|
||||
}
|
||||
catch {
|
||||
case e:IOException =>
|
||||
throw new SAXException("Write failed", e);
|
||||
throw new SAXException("Write failed", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,28 @@
|
|||
/* __ *\
|
||||
** ________ ___ / / ___ Scala API **
|
||||
** / __/ __// _ | / / / _ | (c) 2002-2007, LAMP/EPFL **
|
||||
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
|
||||
** /____/\___/_/ |_/____/_/ | | **
|
||||
** |/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
|
||||
package scala.xml.persistent
|
||||
|
||||
import java.io.{File,FileOutputStream}
|
||||
import java.io.{File, FileOutputStream}
|
||||
import java.nio.ByteBuffer
|
||||
import java.nio.channels.Channels
|
||||
|
||||
/** mutable storage of immutable xml trees. Everything is kept in memory,
|
||||
* with a thread periodically checking for changes and writing to file.
|
||||
* To ensure atomicity, two files are used, filename1 and '$'+filename1.
|
||||
* The implementation switches between the two, deleting the older one
|
||||
* after a complete dump of the database has been written.
|
||||
/** <p>
|
||||
* Mutable storage of immutable xml trees. Everything is kept in memory,
|
||||
* with a thread periodically checking for changes and writing to file.
|
||||
* To ensure atomicity, two files are used, filename1 and '$'+filename1.
|
||||
* The implementation switches between the two, deleting the older one
|
||||
* after a complete dump of the database has been written.
|
||||
* </p>
|
||||
*
|
||||
* @author Burak Emir
|
||||
*/
|
||||
abstract class CachedFileStorage(private val file1: File)
|
||||
extends java.lang.Thread with scala.util.logging.Logged {
|
||||
|
@ -19,7 +33,7 @@ extends java.lang.Thread with scala.util.logging.Logged {
|
|||
*/
|
||||
private var theFile: File = null
|
||||
|
||||
private def switch = { theFile = if( theFile == file1 ) file2 else file1; }
|
||||
private def switch = { theFile = if (theFile == file1) file2 else file1; }
|
||||
|
||||
/** this storage modified since last modification check */
|
||||
protected var dirty = false
|
||||
|
@ -49,10 +63,10 @@ extends java.lang.Thread with scala.util.logging.Logged {
|
|||
def nodes: Iterator[Node]
|
||||
|
||||
/** adds a node, setting this.dirty to true as a side effect */
|
||||
def += ( e:Node ): Unit
|
||||
def += (e: Node): Unit
|
||||
|
||||
/** removes a tree, setting this.dirty to true as a side effect */
|
||||
def -= ( e:Node ): Unit
|
||||
def -= (e: Node): Unit
|
||||
|
||||
/* loads and parses XML from file */
|
||||
private def load: Iterator[Node] = {
|
||||
|
@ -68,13 +82,13 @@ extends java.lang.Thread with scala.util.logging.Logged {
|
|||
}
|
||||
|
||||
/** saves the XML to file */
|
||||
private def save = if( this.dirty ) {
|
||||
private def save = if (this.dirty) {
|
||||
log("[save]\ndeleting "+theFile);
|
||||
theFile.delete();
|
||||
log("creating new "+theFile);
|
||||
theFile.createNewFile();
|
||||
val fos = new FileOutputStream( theFile );
|
||||
val c = fos.getChannel();
|
||||
val fos = new FileOutputStream(theFile)
|
||||
val c = fos.getChannel()
|
||||
|
||||
// @todo: optimize
|
||||
val storageNode = <nodes>{ nodes.toList }</nodes>
|
||||
|
|
|
@ -1,3 +1,14 @@
|
|||
/* __ *\
|
||||
** ________ ___ / / ___ Scala API **
|
||||
** / __/ __// _ | / / / _ | (c) 2002-2007, LAMP/EPFL **
|
||||
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
|
||||
** /____/\___/_/ |_/____/_/ | | **
|
||||
** |/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
|
||||
|
||||
package scala.xml.persistent
|
||||
|
||||
/** an Index returns some unique key that is part of a node
|
||||
|
|
|
@ -1,3 +1,14 @@
|
|||
/* __ *\
|
||||
** ________ ___ / / ___ Scala API **
|
||||
** / __/ __// _ | / / / _ | (c) 2002-2007, LAMP/EPFL **
|
||||
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
|
||||
** /____/\___/_/ |_/____/_/ | | **
|
||||
** |/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
|
||||
|
||||
package scala.xml.persistent
|
||||
|
||||
import scala.collection.mutable
|
||||
|
@ -8,7 +19,7 @@ import java.io.File
|
|||
* xml nodes.
|
||||
*/
|
||||
class IndexedStorage[A](file: File, index: Index[A]) //@todo
|
||||
extends CachedFileStorage( file ) {
|
||||
extends CachedFileStorage(file) {
|
||||
|
||||
private var theMap: mutable.Map[A,Node] = new mutable.HashMap[A,Node]()
|
||||
|
||||
|
|
|
@ -1,10 +1,23 @@
|
|||
/* __ *\
|
||||
** ________ ___ / / ___ Scala API **
|
||||
** / __/ __// _ | / / / _ | (c) 2002-2007, LAMP/EPFL **
|
||||
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
|
||||
** /____/\___/_/ |_/____/_/ | | **
|
||||
** |/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
|
||||
package scala.xml.persistent
|
||||
|
||||
import scala.collection.mutable
|
||||
import java.io.File
|
||||
/** a persistent store with set semantics. This class allows to add and remove
|
||||
* trees, but never contains two structurally equal trees.
|
||||
*/
|
||||
|
||||
/** A persistent store with set semantics. This class allows to add and remove
|
||||
* trees, but never contains two structurally equal trees.
|
||||
*
|
||||
* @author Burak Emir
|
||||
*/
|
||||
class SetStorage(file: File) extends CachedFileStorage(file) {
|
||||
|
||||
private var theSet: mutable.HashSet[Node] = new mutable.HashSet[Node]
|
||||
|
@ -21,9 +34,9 @@ class SetStorage(file: File) extends CachedFileStorage(file) {
|
|||
|
||||
/* forwarding methods to hashset*/
|
||||
|
||||
def += ( e:Node ): Unit = synchronized { this.dirty = true; theSet += e }
|
||||
def += (e: Node): Unit = synchronized { this.dirty = true; theSet += e }
|
||||
|
||||
def -= ( e:Node ): Unit = synchronized { this.dirty = true; theSet -= e }
|
||||
def -= (e: Node): Unit = synchronized { this.dirty = true; theSet -= e }
|
||||
|
||||
def nodes = synchronized { theSet.elements }
|
||||
|
||||
|
|
Loading…
Reference in New Issue