~ubuntu-branches/debian/sid/scala/sid

« back to all changes in this revision

Viewing changes to src/library/scala/xml/XML.scala

  • Committer: Package Import Robot
  • Author(s): Emmanuel Bourg, Mehdi Dogguy, Lucas Satabin, Frank S. Thomas, Emmanuel Bourg
  • Date: 2015-06-05 23:52:59 UTC
  • mfrom: (1.2.11)
  • Revision ID: package-import@ubuntu.com-20150605235259-wk00vgk83dh8o19g
Tags: 2.10.5-1
* Team upload.

[ Mehdi Dogguy ]
* New upstream release (Closes: #744278).

[ Lucas Satabin ]
* Update patches
* Update the clean target
* Update paths of elements to install
* Update watch file

[ Frank S. Thomas ]
* Remove myself from Uploaders.

[ Emmanuel Bourg ]
* The package has been adopted by the Java Team (Closes: #754935)
* Patched the build to avoid downloading libraries from the Internet
* Replaced the minified JavaScript files with unobfuscated ones
* No longer build scala-partest.jar until diffutils is packaged or replaced
* debian/watch: Fixed the versions matched (x.y.z instead of x.y.z..z)
* debian/rules:
  - Added the missing get-orig-source target (Closes: #724704)
  - Improved the clean target
* debian/control:
  - Build depend on scala (>= 2.10) and bnd
  - Use canonical URLs for the Vcs-* fields
  - Standards-Version updated to 3.9.6 (no changes)
* Switch to debhelper level 9

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*                     __                                               *\
2
2
**     ________ ___   / /  ___     Scala API                            **
3
 
**    / __/ __// _ | / /  / _ |    (c) 2003-2011, LAMP/EPFL             **
 
3
**    / __/ __// _ | / /  / _ |    (c) 2003-2013, LAMP/EPFL             **
4
4
**  __\ \/ /__/ __ |/ /__/ __ |    http://scala-lang.org/               **
5
5
** /____/\___/_/ |_/____/_/ | |                                         **
6
6
**                          |/                                          **
7
7
\*                                                                      */
8
8
 
9
 
 
10
 
 
11
9
package scala.xml
12
10
 
13
11
import parsing.NoBindingFactoryAdapter
17
15
import java.nio.channels.Channels
18
16
import scala.util.control.Exception.ultimately
19
17
 
20
 
object Source
21
 
{
 
18
object Source {
22
19
  def fromFile(file: File)              = new InputSource(new FileInputStream(file))
23
20
  def fromFile(fd: FileDescriptor)      = new InputSource(new FileInputStream(fd))
24
21
  def fromFile(name: String)            = new InputSource(new FileInputStream(name))
28
25
  def fromSysId(sysID: String)          = new InputSource(sysID)
29
26
  def fromString(string: String)        = fromReader(new StringReader(string))
30
27
}
 
28
 
 
29
/**
 
30
 * Governs how empty elements (i.e. those without child elements) should be serialized.
 
31
 */
 
32
object MinimizeMode extends Enumeration {
 
33
  /** Minimize empty tags if they were originally empty when parsed, or if they were constructed
 
34
   *  with [[scala.xml.Elem]]`#minimizeEmpty` == true
 
35
   */
 
36
  val Default = Value
 
37
 
 
38
  /** Always minimize empty tags.  Note that this may be problematic for XHTML, in which
 
39
   * case [[scala.xml.Xhtml]]`#toXhtml` should be used instead.
 
40
   */
 
41
  val Always = Value
 
42
 
 
43
  /** Never minimize empty tags.
 
44
   */
 
45
  val Never = Value
 
46
}
 
47
 
31
48
import Source._
32
49
 
33
 
/** The object <code>XML</code> provides constants, and functions to load
 
50
/** The object `XML` provides constants, and functions to load
34
51
 *  and save XML elements. Use this when data binding is not desired, i.e.
35
 
 *  when XML is handled using <code>Symbol</code> nodes.
 
52
 *  when XML is handled using `Symbol` nodes.
36
53
 *
37
54
 *  @author  Burak Emir
38
55
 *  @version 1.0, 25/04/2005
39
56
 */
40
 
object XML extends XMLLoader[Elem]
41
 
{
 
57
object XML extends XMLLoader[Elem] {
42
58
  val xml       = "xml"
43
59
  val xmlns     = "xmlns"
44
60
  val namespace = "http://www.w3.org/XML/1998/namespace"
51
67
  def withSAXParser(p: SAXParser): XMLLoader[Elem] =
52
68
    new XMLLoader[Elem] { override val parser: SAXParser = p }
53
69
 
54
 
  @deprecated("Use save() instead", "2.8.0")
55
 
  final def saveFull(filename: String, node: Node, xmlDecl: Boolean, doctype: dtd.DocType): Unit =
56
 
    save(filename, node, encoding, xmlDecl, doctype)
57
 
 
58
 
  @deprecated("Use save() instead", "2.8.0")
59
 
  final def saveFull(filename: String, node: Node, enc: String, xmlDecl: Boolean, doctype: dtd.DocType): Unit =
60
 
    save(filename, node, enc, xmlDecl, doctype)
61
 
 
62
70
  /** Saves a node to a file with given filename using given encoding
63
71
   *  optionally with xmldecl and doctype declaration.
64
72
   *
89
97
   *
90
98
   *  @param w        the writer
91
99
   *  @param node     the xml node we want to write
92
 
   *  @param enc      the string to be used in <code>xmlDecl</code>
 
100
   *  @param enc      the string to be used in `xmlDecl`
93
101
   *  @param xmlDecl  if true, write xml declaration
94
102
   *  @param doctype  if not null, write doctype declaration
95
103
   */
96
 
  final def write(w: java.io.Writer, node: Node, enc: String, xmlDecl: Boolean, doctype: dtd.DocType) {
 
104
  final def write(w: java.io.Writer, node: Node, enc: String, xmlDecl: Boolean, doctype: dtd.DocType, minimizeTags: MinimizeMode.Value = MinimizeMode.Default) {
97
105
    /* TODO: optimize by giving writer parameter to toXML*/
98
106
    if (xmlDecl) w.write("<?xml version='1.0' encoding='" + enc + "'?>\n")
99
107
    if (doctype ne null) w.write( doctype.toString() + "\n")
100
 
    w.write(Utility.toXML(node).toString)
 
108
    w.write(Utility.serialize(node, minimizeTags = minimizeTags).toString)
101
109
  }
102
110
}