Changeset - r547:fd80af68bedc » raw diff » download diff
commit 547: fd80af68bedc@2008-04-06 00:29:46
gravatar
Sean Russell
ser@ser1.net
0 9 0
Parent 546: 136151b71a9f
default
9 files affected with 116 additions and 116 deletions.
17
17
end
18
18

	
19
19
k = case ARGV[0]
20
    when /^t/: 'tag'
21
    when /^u/: 'url'
22
    when /^r/: 'revision'
23
    when /^a/: 'author'
24
    when /^d/: 'date'
20
    when /^t/ then 'tag'
21
    when /^u/ then 'url'
22
    when /^r/ then 'revision'
23
    when /^a/ then 'author'
24
    when /^d/ then 'date'
25
25
    else
26
26
      puts %Q{Unrecognized command "#{ARGV[0]}"}
27
27
      puts HELP
29
29

	
30
30
require 'getoptlong'
31
31
require 'rbconfig'
32
require 'ftools'
32
require 'FileUtils'
33
33
require 'find'
34
34

	
35
35
opts = GetoptLong.new( [ '--uninstall',	'-u',		GetoptLong::NO_ARGUMENT],
36
											[ '--destdir', '-d', GetoptLong::REQUIRED_ARGUMENT ],
37
											[ '--target', '-t', GetoptLong::REQUIRED_ARGUMENT ],
38
											[ '--concurrent', '-c', GetoptLong::NO_ARGUMENT],
39
											[ '--help', '-h', GetoptLong::NO_ARGUMENT],
40
											[ '--noop', '-n', GetoptLong::NO_ARGUMENT])
36
						[ '--destdir', '-d', GetoptLong::REQUIRED_ARGUMENT ],
37
						[ '--target', '-t', GetoptLong::REQUIRED_ARGUMENT ],
38
						[ '--concurrent', '-c', GetoptLong::NO_ARGUMENT],
39
						[ '--help', '-h', GetoptLong::NO_ARGUMENT],
40
						[ '--noop', '-n', GetoptLong::NO_ARGUMENT])
41
41

	
42
42

	
43
43
destdir = File.join(Config::CONFIG['sitedir'], 
2
2

	
3
3
Dir.chdir ".." if Dir.pwd =~ /bin.?$/
4
4

	
5
require "ftools"
5
require "FileUtils"
6
6

	
7
7
def copy_recursively( dir_name, dest )
8
8
	Dir.entries( dir_name ).each { |fname|
17
17
  # Document has a single child that can be accessed by root().
18
18
  # Note that if you want to have an XML declaration written for a document
19
19
  # you create, you must add one; REXML documents do not write a default
20
	# declaration for you.  See |DECLARATION| and |write|.
21
	class Document < Element
22
		# A convenient default XML declaration.  If you want an XML declaration,
23
		# the easiest way to add one is mydoc << Document::DECLARATION
24
    # +DEPRECATED+
25
    # Use: mydoc << XMLDecl.default
26
		DECLARATION = XMLDecl.default
20
  # declaration for you.  See |DECLARATION| and |write|.
21
  class Document < Element
22
	# A convenient default XML declaration.  If you want an XML declaration,
23
	# the easiest way to add one is mydoc << Document::DECLARATION
24
	# +DEPRECATED+
25
	# Use: mydoc << XMLDecl.default
26
	DECLARATION = XMLDecl.default
27
27

	
28
		# Constructor
29
		# @param source if supplied, must be a Document, String, or IO. 
30
		# Documents have their context and Element attributes cloned.
31
	  # Strings are expected to be valid XML documents.  IOs are expected
32
	  # to be sources of valid XML documents.
33
	  # @param context if supplied, contains the context of the document;
34
	  # this should be a Hash.
35
		def initialize( source = nil, context = {} )
36
			super()
37
			@context = context
38
			return if source.nil?
39
			if source.kind_of? Document
40
				@context = source.context
41
				super source
42
			else
43
				build(  source )
44
			end
45
		end
28
	# Constructor
29
	# @param source if supplied, must be a Document, String, or IO. 
30
	# Documents have their context and Element attributes cloned.
31
	# Strings are expected to be valid XML documents.  IOs are expected
32
	# to be sources of valid XML documents.
33
	# @param context if supplied, contains the context of the document;
34
	# this should be a Hash.
35
	def initialize( source = nil, context = {} )
36
	  super()
37
	  @context = context
38
	  return if source.nil?
39
	  if source.kind_of? Document
40
		@context = source.context
41
		super source
42
	  else
43
		build(  source )
44
	  end
45
	end
46
46

	
47
47
    def node_type
48
48
      :document
49
49
    end
50
50

	
51
		# Should be obvious
52
		def clone
53
			Document.new self
54
		end
51
	# Should be obvious
52
	def clone
53
	  Document.new self
54
	end
55
55

	
56
		# According to the XML spec, a root node has no expanded name
57
		def expanded_name
58
			''
59
			#d = doc_type
60
			#d ? d.name : "UNDEFINED"
61
		end
56
	# According to the XML spec, a root node has no expanded name
57
	def expanded_name
58
	  ''
59
	  #d = doc_type
60
	  #d ? d.name : "UNDEFINED"
61
	end
62
62

	
63
		alias :name :expanded_name
63
	alias :name :expanded_name
64
64

	
65
		# We override this, because XMLDecls and DocTypes must go at the start
66
		# of the document
67
		def add( child )
68
			if child.kind_of? XMLDecl
69
				@children.unshift child
65
	# We override this, because XMLDecls and DocTypes must go at the start
66
	# of the document
67
	def add( child )
68
	  if child.kind_of? XMLDecl
69
		@children.unshift child
70
70
        child.parent = self
71
			elsif child.kind_of? DocType
71
	  elsif child.kind_of? DocType
72
72
        # Find first Element or DocType node and insert the decl right 
73
73
        # before it.  If there is no such node, just insert the child at the
74
74
        # end.  If there is a child and it is an DocType, then replace it.
...
...
@@ -86,60 +86,60 @@
86
86
        else  # Insert at end of list
87
87
          @children[insert_before_index] = child
88
88
        end
89
				child.parent = self
90
			else
91
				rv = super
92
				raise "attempted adding second root element to document" if @elements.size > 1
93
				rv
94
			end
95
		end
96
		alias :<< :add
89
		child.parent = self
90
	  else
91
		rv = super
92
		raise "attempted adding second root element to document" if @elements.size > 1
93
		rv
94
	  end
95
	end
96
	alias :<< :add
97
97

	
98
		def add_element(arg=nil, arg2=nil)
99
			rv = super
100
			raise "attempted adding second root element to document" if @elements.size > 1
101
			rv
102
		end
98
	def add_element(arg=nil, arg2=nil)
99
	  rv = super
100
	  raise "attempted adding second root element to document" if @elements.size > 1
101
	  rv
102
	end
103
103

	
104
		# @return the root Element of the document, or nil if this document
105
		# has no children.
106
		def root
104
	# @return the root Element of the document, or nil if this document
105
	# has no children.
106
	def root
107
107
      elements[1]
108
108
      #self
109
109
      #@children.find { |item| item.kind_of? Element }
110
		end
110
	end
111
111

	
112
		# @return the DocType child of the document, if one exists,
113
		# and nil otherwise.
114
		def doctype
115
			@children.find { |item| item.kind_of? DocType }
116
		end
112
	# @return the DocType child of the document, if one exists,
113
	# and nil otherwise.
114
	def doctype
115
	  @children.find { |item| item.kind_of? DocType }
116
	end
117
117

	
118
		# @return the XMLDecl of this document; if no XMLDecl has been
119
		# set, the default declaration is returned.
120
		def xml_decl
121
			rv = @children[0]
118
	# @return the XMLDecl of this document; if no XMLDecl has been
119
	# set, the default declaration is returned.
120
	def xml_decl
121
	  rv = @children[0]
122
122
      return rv if rv.kind_of? XMLDecl
123
123
      rv = @children.unshift(XMLDecl.default)[0]
124
		end
124
	end
125
125

	
126
		# @return the XMLDecl version of this document as a String.
127
		# If no XMLDecl has been set, returns the default version.
128
		def version
129
			xml_decl().version
130
		end
126
	# @return the XMLDecl version of this document as a String.
127
	# If no XMLDecl has been set, returns the default version.
128
	def version
129
	  xml_decl().version
130
	end
131
131

	
132
		# @return the XMLDecl encoding of this document as a String.
133
		# If no XMLDecl has been set, returns the default encoding.
134
		def encoding
135
			xml_decl().encoding
136
		end
132
	# @return the XMLDecl encoding of this document as a String.
133
	# If no XMLDecl has been set, returns the default encoding.
134
	def encoding
135
	  xml_decl().encoding
136
	end
137
137

	
138
		# @return the XMLDecl standalone value of this document as a String.
139
		# If no XMLDecl has been set, returns the default setting.
140
		def stand_alone?
141
			xml_decl().stand_alone?
142
		end
138
	# @return the XMLDecl standalone value of this document as a String.
139
	# If no XMLDecl has been set, returns the default setting.
140
	def stand_alone?
141
	  xml_decl().stand_alone?
142
	end
143
143

	
144
144
    # Write the XML tree out, optionally with indent.  This writes out the
145
145
    # entire XML document, including XML declarations, doctype declarations,
...
...
@@ -194,16 +194,16 @@
194
194
		REXML::Formatters::Default.new( ie_hack )
195
195
	  end
196
196
      formatter.write( self, output )
197
		end
197
	end
198
198

	
199
199
		
200
		def Document::parse_stream( source, listener )
201
			Parsers::StreamParser.new( source, listener ).parse
202
		end
200
	def Document::parse_stream( source, listener )
201
	  Parsers::StreamParser.new( source, listener ).parse
202
	end
203
203

	
204
		private
205
		def build( source )
204
	private
205
	def build( source )
206
206
      Parsers::TreeParser.new( source, self ).parse
207
		end
208
207
	end
208
  end
209
209
end
91
91

	
92
92
	# Submitted by Kou
93
93
	def test_namespace_conflict
94
		assert_raises( ParseException, 
94
		assert_raise( ParseException, 
95
95
			"Declaring two attributes with the same namespace should be an error" ) do
96
96
			REXML::Document.new <<-XML
97
97
			<x xmlns:n1="http://www.w3.org" 
55
55
      '<a' + [0x0371].pack('U') + ' />',
56
56
      '<a a' + [0x0371].pack('U') + '="" />',
57
57
    ].each do |src|
58
      assert_raises( ParseException, %Q{Parse #{src.inspect} should have failed!} ) do
58
      assert_raise( ParseException, %Q{Parse #{src.inspect} should have failed!} ) do
59
59
        Document.new(src)
60
60
      end
61
61
    end
...
...
@@ -134,10 +134,10 @@
134
134
    comment2 = Comment.new comment
135
135
    assert_equal(comment, comment2)
136
136

	
137
    assert_raises(ParseException) {
137
    assert_raise(ParseException) {
138
138
      REXML::Document.new("<d><!- foo --></d>")
139
139
    }
140
    assert_raises(ParseException) {
140
    assert_raise(ParseException) {
141
141
      REXML::Document.new("<d><!-- foo -></d>")
142
142
    }
143
143
  end
...
...
@@ -286,7 +286,7 @@
286
286
    instruction2 = d[0]
287
287
    assert_equal(instruction.to_s, instruction2.to_s)
288
288

	
289
    assert_raises(ParseException) {
289
    assert_raise(ParseException) {
290
290
      REXML::Document.new("<d><?foo bar></d>")
291
291
    }
292
292
  end
...
...
@@ -855,7 +855,7 @@
855
855
  end
856
856

	
857
857
  def test_more_namespaces
858
    assert_raises( REXML::UndefinedNamespaceException, 
858
    assert_raise( REXML::UndefinedNamespaceException, 
859
859
                   %Q{Should have gotten an Undefined Namespace error} )  {
860
860
      doc1 = Document.new("<r><p><n:c/></p></r>")
861
861
    }
...
...
@@ -1044,7 +1044,7 @@
1044
1044

	
1045
1045
  def test_null_element_name
1046
1046
    a = REXML::Document.new 
1047
    assert_raises( RuntimeError ) {
1047
    assert_raise( RuntimeError ) {
1048
1048
      a.add_element( nil ) 
1049
1049
    }
1050
1050
  end
...
...
@@ -1193,14 +1193,14 @@
1193
1193

	
1194
1194
  def test_ticket_76
1195
1195
    src = "<div>at&t"
1196
    assert_raises( ParseException, %Q{"#{src}" is invalid XML} )  {
1196
    assert_raise( ParseException, %Q{"#{src}" is invalid XML} )  {
1197
1197
      REXML::Document.new(src)
1198
1198
    }
1199
1199
  end
1200
1200

	
1201
1201
  def test_ticket_21
1202
1202
    src = "<foo bar=value/>"
1203
    assert_raises( ParseException, "invalid XML should be caught" ) {
1203
    assert_raise( ParseException, "invalid XML should be caught" ) {
1204
1204
      d = REXML::Document.new(src)
1205
1205
    }
1206
1206
    begin
...
...
@@ -1324,7 +1324,7 @@
1324
1324

	
1325
1325
  def test_ticket_14
1326
1326
    # Per .2.5 Node Tests of XPath spec 
1327
    assert_raises( REXML::UndefinedNamespaceException, 
1327
    assert_raise( REXML::UndefinedNamespaceException, 
1328
1328
                   %Q{Should have gotten an Undefined Namespace error} )  {
1329
1329
      d = Document.new("<a><n:b/></a>") 
1330
1330
    }
32
32
  def test_bad_document
33
33
    source = "<a><b></a>"
34
34
    parser = REXML::Parsers::PullParser.new(source)
35
    assert_raises(ParseException, "Parsing should have failed") { 
35
    assert_raise(ParseException, "Parsing should have failed") { 
36
36
      results = parser.pull while parser.has_next? 
37
37
    }
38
38
  end
778
778
  def error( validator, source )
779
779
    parser = REXML::Parsers::TreeParser.new( source )
780
780
    parser.add_listener( validator.reset )
781
    assert_raises( REXML::Validation::ValidationException, 
781
    assert_raise( REXML::Validation::ValidationException, 
782
782
                  "Expected a validation error" ) { parser.parse }
783
783
  end
784
784

	
587
587
	end
588
588

	
589
589
	def test_name
590
    assert_raises( UndefinedNamespaceException, "x should be undefined" ) {
590
    assert_raise( UndefinedNamespaceException, "x should be undefined" ) {
591
591
      d = REXML::Document.new("<a x='foo'><b/><x:b/></a>")
592
592
    }
593
593
		d = REXML::Document.new("<a xmlns:x='foo'><b/><x:b/></a>")