diff options
author | michelou <michelou@epfl.ch> | 2007-10-09 16:28:22 +0000 |
---|---|---|
committer | michelou <michelou@epfl.ch> | 2007-10-09 16:28:22 +0000 |
commit | f91bc93ad4767a86fea46d2d63e3b09cf2f64faf (patch) | |
tree | 37d901d19390abd0d769742354986b08a043aa86 /src/library | |
parent | d93d566e0845aeed5066c30b4bc0d99a2b4729c7 (diff) | |
download | scala-f91bc93ad4767a86fea46d2d63e3b09cf2f64faf.tar.gz scala-f91bc93ad4767a86fea46d2d63e3b09cf2f64faf.tar.bz2 scala-f91bc93ad4767a86fea46d2d63e3b09cf2f64faf.zip |
removed type aliases, update svn:keywords
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/scala/xml/include/sax/EncodingHeuristics.scala | 86 | ||||
-rw-r--r-- | src/library/scala/xml/include/sax/Main.scala | 32 | ||||
-rw-r--r-- | src/library/scala/xml/include/sax/XIncludeFilter.scala | 160 | ||||
-rw-r--r-- | src/library/scala/xml/include/sax/XIncluder.scala | 20 |
4 files changed, 146 insertions, 152 deletions
diff --git a/src/library/scala/xml/include/sax/EncodingHeuristics.scala b/src/library/scala/xml/include/sax/EncodingHeuristics.scala index 976d475975..adab470106 100644 --- a/src/library/scala/xml/include/sax/EncodingHeuristics.scala +++ b/src/library/scala/xml/include/sax/EncodingHeuristics.scala @@ -43,14 +43,14 @@ object EncodingHeuristics { //System.err.println("EncodingHeuristics::readEncodingFromStream"); // This may fail if there are a lot of space characters before the end // of the encoding declaration - in.mark(1024); - var ret: String = null; + in.mark(1024) + var ret: String = null try { // lots of things can go wrong here. If any do, I just return null // so that we'll fall back on the encoding declaration or the // UTF-8 default - val byte1 = in.read(); - val byte2 = in.read(); + val byte1 = in.read() + val byte2 = in.read() if (byte1 == 0xFE && byte2 == 0xFF) { // don't reset because the byte order mark should not be included???? ret = "UnicodeBig"; // name for big-endian???? @@ -58,7 +58,7 @@ object EncodingHeuristics { else if (byte1 == 0xFF && byte2 == 0xFE) { // don't reset because the byte order mark should not be included???? // will the reader throw away the byte order mark or will it return it???? - ret = "UnicodeLittle"; + ret = "UnicodeLittle" } /* In accordance with the Character Model [Character Model], @@ -67,7 +67,7 @@ object EncodingHeuristics { selected range is non-normalized. When transcoding characters to a Unicode encoding from a legacy encoding, a normalizing transcoder must be used. */ - val byte3 = in.read(); + val byte3 = in.read() // check for UTF-8 byte order mark if (byte1 == 0xEF && byte2 == 0xBB && byte3 == 0xBF) { // don't reset because the byte order mark should not be included???? @@ -89,29 +89,29 @@ object EncodingHeuristics { // less than sign or white space // Let's look for less-than signs first if (byte1 == 0x00 && byte2 == 0x00 && byte3 == 0x00 && byte4 == '<') { - in.reset(); - ret = "UCS-4"; // right name for big-endian UCS-4 in Java 1.4???? + in.reset() + ret = "UCS-4" // right name for big-endian UCS-4 in Java 1.4???? } else if (byte1 == '<' && byte2 == 0x00 && byte3 == 0x00 && byte4 == 0x00) { - in.reset(); - ret = "UCS-4"; // right name for little-endian UCS-4 in Java 1.4???? + in.reset() + ret = "UCS-4" // right name for little-endian UCS-4 in Java 1.4???? } else if (byte1 == 0x00 && byte2 == '<' && byte3 == 0x00 && byte4 == '?') { - in.reset(); - ret = "UnicodeBigUnmarked"; + in.reset() + ret = "UnicodeBigUnmarked" } else if (byte1 == '<' && byte2 == 0x00 && byte3 == '?' && byte4 == 0x00) { - in.reset(); - ret = "UnicodeLittleUnmarked"; + in.reset() + ret = "UnicodeLittleUnmarked" } else if (byte1 == '<' && byte2 == '?' && byte3 == 'x' && byte4 == 'm') { // ASCII compatible, must read encoding declaration // 1024 bytes will be far enough to read most XML declarations - val data = new Array[byte](1024); - data(0) = byte1.asInstanceOf[byte]; - data(1) = byte2.asInstanceOf[byte];; - data(2) = byte3.asInstanceOf[byte];; - data(3) = byte4.asInstanceOf[byte];; + val data = new Array[Byte](1024) + data(0) = byte1.asInstanceOf[Byte] + data(1) = byte2.asInstanceOf[Byte] + data(2) = byte3.asInstanceOf[Byte] + data(3) = byte4.asInstanceOf[Byte] val length = in.read(data, 4, 1020) + 4; // Use Latin-1 (ISO-8859-1) because it's ASCII compatible and // all byte sequences are legal Latin-1 sequences so I don't have @@ -122,37 +122,36 @@ object EncodingHeuristics { // we just fall into the catch bloclk and return null // since this can't be well-formed XML var position = declaration.indexOf("encoding") + 8; - var c: char = '\0'; // bogus init value + var c: Char = '\0' // bogus init value // get rid of white space before equals sign do { - c = declaration.charAt(position); - position = position + 1; + c = declaration.charAt(position) + position += 1 } while (c == ' ' || c == '\t' || c == '\r' || c == '\n') ; if (c != '=') { // malformed - in.reset(); - ret = "UTF-8"; + in.reset() + ret = "UTF-8" } // get rid of white space after equals sign do { - c = declaration.charAt(position); - position = position + 1; + c = declaration.charAt(position) + position += 1 } while (c == ' ' || c == '\t' || c == '\r' || c == '\n') ; - var delimiter: char = c; + var delimiter: Char = c if (delimiter != '\'' && delimiter != '"') { // malformed - in.reset(); - ret = "UTF-8"; + in.reset() + ret = "UTF-8" } // now positioned to read encoding name - val encodingName = new StringBuffer(); + val encodingName = new StringBuffer() do { - c = declaration.charAt(position); - position = position + 1; - encodingName.append(c); - } while(c != delimiter); - encodingName.setLength(encodingName.length() - 1); // rm delim - in.reset(); - ret = encodingName.toString(); - + c = declaration.charAt(position) + position += 1 + encodingName.append(c) + } while(c != delimiter) + encodingName.setLength(encodingName.length() - 1) // rm delim + in.reset() + ret = encodingName.toString() } else if (byte1 == 0x4C && byte2 == 0x6F && byte3 == 0xA7 && byte4 == 0x94) { // EBCDIC compatible, must read encoding declaration @@ -160,18 +159,19 @@ object EncodingHeuristics { } } catch { - case e: Exception => in.reset(); - ret = "UTF-8"; + case e: Exception => + in.reset() + ret = "UTF-8" } // no XML or text declaration present //System.err.println("exit EncodingHeuristics::readEncodingFromStream"); if (ret != null) - return ret + ret else { - in.reset(); - return "UTF-8"; + in.reset() + "UTF-8" } } } diff --git a/src/library/scala/xml/include/sax/Main.scala b/src/library/scala/xml/include/sax/Main.scala index 795ca0fbfa..1ed32fee36 100644 --- a/src/library/scala/xml/include/sax/Main.scala +++ b/src/library/scala/xml/include/sax/Main.scala @@ -51,14 +51,14 @@ object Main { } catch { case e:SAXException => - System.err.println(e); + System.err.println(e) err = true } - if(err) return; + if (err) return - if (args.length == 0) return; - var resolver: EntityResolver = null; - var arg: int = 0; + if (args.length == 0) return + var resolver: EntityResolver = null + var arg: Int = 0 if (args(0).equals("-r")) { try { resolver = Class.forName(args(1)).newInstance().asInstanceOf[EntityResolver]; @@ -66,30 +66,30 @@ object Main { } catch { case ex:Exception => - System.err.println("Could not load requested EntityResolver"); - err = true; + System.err.println("Could not load requested EntityResolver") + err = true } - arg = 2; + arg = 2 } - if (err) return; + if (err) return while (arg < args.length) { try { val includer = new XIncludeFilter(); - includer.setParent(parser); - val s = new XIncluder(System.out, "UTF-8"); - includer.setContentHandler(s); - if (resolver != null) includer.setEntityResolver(resolver); + includer.setParent(parser) + val s = new XIncluder(System.out, "UTF-8") + includer.setContentHandler(s) + if (resolver != null) includer.setEntityResolver(resolver) try { includer.setProperty( "http://xml.org/sax/properties/lexical-handler", - s); - s.setFilter(includer); + s) + s.setFilter(includer) } catch { case e:SAXException => // Will not support comments } - includer.parse(args(arg)); + includer.parse(args(arg)) } catch { case e:SAXParseException => diff --git a/src/library/scala/xml/include/sax/XIncludeFilter.scala b/src/library/scala/xml/include/sax/XIncludeFilter.scala index 23033c239c..7a0bcfe1fc 100644 --- a/src/library/scala/xml/include/sax/XIncludeFilter.scala +++ b/src/library/scala/xml/include/sax/XIncludeFilter.scala @@ -113,17 +113,17 @@ class XIncludeFilter extends XMLFilterImpl { // what if this isn't called???? // do I need to check this in startDocument() and push something // there???? - override def setDocumentLocator(locator: Locator): Unit = { - locators.push(locator); - val base = locator.getSystemId(); + override def setDocumentLocator(locator: Locator) { + locators.push(locator) + val base = locator.getSystemId() try { - bases.push(new URL(base)); + bases.push(new URL(base)) } catch { case e:MalformedURLException => - throw new UnsupportedOperationException("Unrecognized SYSTEM ID: " + base); + throw new UnsupportedOperationException("Unrecognized SYSTEM ID: " + base) } - super.setDocumentLocator(locator); + super.setDocumentLocator(locator) } @@ -142,7 +142,7 @@ class XIncludeFilter extends XMLFilterImpl { * * @return boolean */ - def insideIncludeElement(): boolean = level != 0 + def insideIncludeElement(): Boolean = level != 0 override def startElement(uri: String, localName: String, qName: String, atts1: Attributes) { var atts = atts1 @@ -150,31 +150,31 @@ class XIncludeFilter extends XMLFilterImpl { // Adjust bases stack by pushing either the new // value of xml:base or the base of the parent - val base = atts.getValue(NamespaceSupport.XMLNS, "base"); - val parentBase = bases.peek().asInstanceOf[URL]; - var currentBase = parentBase; + val base = atts.getValue(NamespaceSupport.XMLNS, "base") + val parentBase = bases.peek().asInstanceOf[URL] + var currentBase = parentBase if (base != null) { try { - currentBase = new URL(parentBase, base); + currentBase = new URL(parentBase, base) } catch { case e: MalformedURLException => throw new SAXException("Malformed base URL: " - + currentBase, e); + + currentBase, e) } } bases.push(currentBase); if (uri.equals(XINCLUDE_NAMESPACE) && localName.equals("include")) { // include external document - val href = atts.getValue("href"); + val href = atts.getValue("href") // Verify that there is an href attribute if (href==null) { - throw new SAXException("Missing href attribute"); + throw new SAXException("Missing href attribute") } - var parse = atts.getValue("parse"); - if (parse == null) parse = "xml"; + var parse = atts.getValue("parse") + if (parse == null) parse = "xml" if (parse.equals("text")) { val encoding = atts.getValue("encoding"); @@ -188,99 +188,94 @@ class XIncludeFilter extends XMLFilterImpl { throw new SAXException( "Illegal value for parse attribute: " + parse); } - level = level + 1; + level += 1 } - else { - if (atRoot) { - // add xml:base attribute if necessary - val attsImpl = new AttributesImpl(atts); - attsImpl.addAttribute(NamespaceSupport.XMLNS, "base", - "xml:base", "CDATA", currentBase.toExternalForm()); - atts = attsImpl; - atRoot = false; - } - super.startElement(uri, localName, qName, atts); + else { + if (atRoot) { + // add xml:base attribute if necessary + val attsImpl = new AttributesImpl(atts) + attsImpl.addAttribute(NamespaceSupport.XMLNS, "base", + "xml:base", "CDATA", currentBase.toExternalForm()) + atts = attsImpl + atRoot = false } - + super.startElement(uri, localName, qName, atts) + } } - } - override def endElement (uri: String, localName: String, qName: String ) { + override def endElement(uri: String, localName: String, qName: String) { if (uri.equals(XINCLUDE_NAMESPACE) && localName.equals("include")) { level -= 1; - } + } else if (level == 0) { - bases.pop(); - super.endElement(uri, localName, qName); + bases.pop() + super.endElement(uri, localName, qName) } } private var depth = 0; override def startDocument() { - level = 0; - if (depth == 0) super.startDocument(); + level = 0 + if (depth == 0) super.startDocument() depth += 1 } override def endDocument() { - locators.pop(); + locators.pop() bases.pop(); // pop the URL for the document itself - depth = depth - 1; - if (depth == 0) super.endDocument(); + depth -= 1 + if (depth == 0) super.endDocument() } - // how do prefix mappings move across documents???? - override def startPrefixMapping(prefix: String , uri: String ): Unit = { - if (level == 0) super.startPrefixMapping(prefix, uri); + // how do prefix mappings move across documents???? + override def startPrefixMapping(prefix: String , uri: String) { + if (level == 0) super.startPrefixMapping(prefix, uri) } - override def endPrefixMapping(prefix: String): Unit = { - if (level == 0) super.endPrefixMapping(prefix); + override def endPrefixMapping(prefix: String) { + if (level == 0) super.endPrefixMapping(prefix) } - override def characters(ch: Array[char], start: int, length: int): Unit = { - if (level == 0) super.characters(ch, start, length); + override def characters(ch: Array[Char], start: Int, length: Int) { + if (level == 0) super.characters(ch, start, length) } - override def ignorableWhitespace(ch: Array[char] , start: int, length: int): Unit = { - if (level == 0) super.ignorableWhitespace(ch, start, length); + override def ignorableWhitespace(ch: Array[Char], start: Int, length: Int) { + if (level == 0) super.ignorableWhitespace(ch, start, length) } - override def processingInstruction(target: String, data: String): Unit = { - if (level == 0) super.processingInstruction(target, data); + override def processingInstruction(target: String, data: String) { + if (level == 0) super.processingInstruction(target, data) } - override def skippedEntity(name: String): Unit = { - if (level == 0) super.skippedEntity(name); + override def skippedEntity(name: String) { + if (level == 0) super.skippedEntity(name) } // convenience method for error messages private def getLocation(): String = { - - var locationString = ""; - val locator = locators.peek().asInstanceOf[Locator]; - var publicID = ""; - var systemID = ""; - var column = -1; - var line = -1; + var locationString = "" + val locator = locators.peek().asInstanceOf[Locator] + var publicID = "" + var systemID = "" + var column = -1 + var line = -1 if (locator != null) { - publicID = locator.getPublicId(); - systemID = locator.getSystemId(); - line = locator.getLineNumber(); - column = locator.getColumnNumber(); + publicID = locator.getPublicId() + systemID = locator.getSystemId() + line = locator.getLineNumber() + column = locator.getColumnNumber() } locationString = (" in document included from " + publicID + " at " + systemID + " at line " + line + ", column " + column); - return locationString; - + locationString } - /** * <p> * This utility method reads a document at a specified URL @@ -296,13 +291,13 @@ class XIncludeFilter extends XMLFilterImpl { be downloaded from the specified URL or if the encoding is not recognized */ - private def includeTextDocument(url: String, encoding1: String): Unit = { - var encoding = encoding1; + private def includeTextDocument(url: String, encoding1: String) { + var encoding = encoding1 if (encoding == null || encoding.trim().equals("")) encoding = "UTF-8"; - var source: URL = null; + 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 => @@ -313,11 +308,12 @@ class XIncludeFilter extends XMLFilterImpl { } try { - val uc = source.openConnection(); - val in = new BufferedInputStream(uc.getInputStream()); - var encodingFromHeader = uc.getContentEncoding(); - var contentType = uc.getContentType(); - if (encodingFromHeader != null) encoding = encodingFromHeader; + val uc = source.openConnection() + val in = new BufferedInputStream(uc.getInputStream()) + var encodingFromHeader = uc.getContentEncoding() + var contentType = uc.getContentType() + if (encodingFromHeader != null) + encoding = encodingFromHeader else { // What if file does not have a MIME type but name ends in .xml???? // MIME types are case-insensitive @@ -332,9 +328,9 @@ class XIncludeFilter extends XMLFilterImpl { } } } - val reader = new InputStreamReader(in, encoding); - val c = new Array[char](1024); - var charsRead: Int = 0; // bogus init value + val reader = new InputStreamReader(in, encoding) + val c = new Array[Char](1024) + var charsRead: Int = 0 // bogus init value do { charsRead = reader.read(c, 0, 1024); if (charsRead > 0) this.characters(c, 0, charsRead); @@ -375,15 +371,15 @@ class XIncludeFilter extends XMLFilterImpl { case e:MalformedURLException => val ex = new UnavailableResourceException("Unresolvable URL " + url + getLocation()); - ex.setRootCause(e); - throw new SAXException("Unresolvable URL " + url + getLocation(), ex); + ex.setRootCause(e) + throw new SAXException("Unresolvable URL " + url + getLocation(), ex) } try { // make this more robust var parser: XMLReader = null try { - parser = XMLReaderFactory.createXMLReader(); + parser = XMLReaderFactory.createXMLReader() } catch { case e:SAXException => try { @@ -392,7 +388,7 @@ class XIncludeFilter extends XMLFilterImpl { ); } catch { case e2: SAXException => - System.err.println("Could not find an XML parser"); + System.err.println("Could not find an XML parser") } } if(parser != null) { diff --git a/src/library/scala/xml/include/sax/XIncluder.scala b/src/library/scala/xml/include/sax/XIncluder.scala index f9e2ab1466..79c1807fb9 100644 --- a/src/library/scala/xml/include/sax/XIncluder.scala +++ b/src/library/scala/xml/include/sax/XIncluder.scala @@ -145,22 +145,22 @@ with ContentHandler with LexicalHandler { } // LexicalHandler methods - private var inDTD: boolean = false; - private val entities: Stack = new Stack(); + private var inDTD: Boolean = false + private val entities: Stack = new Stack() - def startDTD(name: String, publicID: String, systemID: String): Unit = { - inDTD = true; + def startDTD(name: String, publicID: String, systemID: String) { + inDTD = true // if this is the source document, output a DOCTYPE declaration if (entities.size() == 0) { - var id = ""; + var id = "" if (publicID != null) id = " PUBLIC \"" + publicID + "\" \"" + systemID + '"'; else if (systemID != null) id = " SYSTEM \"" + systemID + '"'; try { - out.write("<!DOCTYPE " + name + id + ">\r\n"); + out.write("<!DOCTYPE " + name + id + ">\r\n") } catch { case e:IOException => - throw new SAXException("Error while writing DOCTYPE", e); + throw new SAXException("Error while writing DOCTYPE", e) } } } @@ -170,7 +170,6 @@ with ContentHandler with LexicalHandler { entities.push(name) } - def endEntity(name: String) { entities.pop() } @@ -180,14 +179,13 @@ with ContentHandler with LexicalHandler { // Just need this reference so we can ask if a comment is // inside an include element or not - private var filter: XIncludeFilter = null; + private var filter: XIncludeFilter = null def setFilter(filter: XIncludeFilter) { this.filter = filter } def comment(ch: Array[Char], start: Int, length: Int) { - if (!inDTD && !filter.insideIncludeElement()) { try { out.write("<!--") @@ -195,7 +193,7 @@ with ContentHandler with LexicalHandler { out.write("-->") } catch { - case e:IOException => + case e: IOException => throw new SAXException("Write failed", e) } } |