Skip to content
This repository
Browse code

SI-6811 Remove scala.xml.include.sax.Main

  • Loading branch information...
commit a38629160637a3d3018fc0e486a27cf3b3d901f5 1 parent 98d3368
authored January 20, 2013
82  src/library/scala/xml/include/sax/Main.scala
... ...
@@ -1,82 +0,0 @@
1  
-/*                     __                                               *\
2  
-**     ________ ___   / /  ___     Scala API                            **
3  
-**    / __/ __// _ | / /  / _ |    (c) 2002-2013, LAMP/EPFL             **
4  
-**  __\ \/ /__/ __ |/ /__/ __ |    http://scala-lang.org/               **
5  
-** /____/\___/_/ |_/____/_/ | |                                         **
6  
-**                          |/                                          **
7  
-\*                                                                      */
8  
-
9  
-
10  
-package scala.xml
11  
-package include.sax
12  
-
13  
-import scala.util.control.Exception.{ catching, ignoring }
14  
-import org.xml.sax.XMLReader
15  
-import org.xml.sax.helpers.XMLReaderFactory
16  
-
17  
-@deprecated("Code example will be moved to documentation.", "2.10.0")
18  
-object Main {
19  
-  private val namespacePrefixes = "http://xml.org/sax/features/namespace-prefixes"
20  
-  private val lexicalHandler = "http://xml.org/sax/properties/lexical-handler"
21  
-
22  
-  /**
23  
-  * The driver method for xinc
24  
-  * Output is written to System.out via Conolse
25  
-  * </p>
26  
-  *
27  
-  * @param args  contains the URLs and/or filenames
28  
-  *              of the documents to be processed.
29  
-  */
30  
-  def main(args: Array[String]) {
31  
-    def saxe[T](body: => T) = catching[T](classOf[SAXException]) opt body
32  
-    def fail(msg: String) = System.err.println(msg)
33  
-
34  
-    val parser: XMLReader =
35  
-      saxe[XMLReader](XMLReaderFactory.createXMLReader()) getOrElse (
36  
-        saxe[XMLReader](XMLReaderFactory.createXMLReader(XercesClassName)) getOrElse (
37  
-          return fail("Could not find an XML parser")
38  
-        )
39  
-      )
40  
-
41  
-    // Need better namespace handling
42  
-    try parser.setFeature(namespacePrefixes, true)
43  
-    catch { case e: SAXException => return System.err.println(e) }
44  
-
45  
-    if (args.isEmpty)
46  
-      return
47  
-
48  
-    def dashR = args.size >= 2 && args(0) == "-r"
49  
-    val args2 = if (dashR) args drop 2 else args
50  
-    val resolver: Option[EntityResolver] =
51  
-      if (dashR) None
52  
-      else catching(classOf[Exception]) opt {
53  
-          val r = Class.forName(args(1)).newInstance().asInstanceOf[EntityResolver]
54  
-          parser setEntityResolver r
55  
-          r
56  
-        } orElse (return fail("Could not load requested EntityResolver"))
57  
-
58  
-    for (arg <- args2) {
59  
-      try {
60  
-        val includer = new XIncludeFilter()
61  
-        includer setParent parser
62  
-        val s = new XIncluder(System.out, "UTF-8")
63  
-        includer setContentHandler s
64  
-
65  
-        resolver map (includer setEntityResolver _)
66  
-        // SAXException here means will not support comments
67  
-        ignoring(classOf[SAXException]) {
68  
-          includer.setProperty(lexicalHandler, s)
69  
-          s setFilter includer
70  
-        }
71  
-        includer parse arg
72  
-      }
73  
-      catch {
74  
-        case e: SAXParseException =>
75  
-          fail(e.toString)
76  
-          fail("Problem in %s at line %d".format(e.getSystemId, e.getLineNumber))
77  
-        case e: SAXException =>
78  
-          fail(e.toString)
79  
-      }
80  
-    }
81  
-  }
82  
-}

0 notes on commit a386291

Please sign in to comment.
Something went wrong with that request. Please try again.