Changeset 97
- Timestamp:
- 03/26/08 22:20:27 (2 years ago)
- Location:
- limeberry/trunk
- Files:
-
- 18 modified
-
app/models/property.rb (modified) (1 diff)
-
app/models/resource.rb (modified) (3 diffs)
-
app/views/webdav/copy.rxml (modified) (1 diff)
-
app/views/webdav/move.rxml (modified) (1 diff)
-
app/views/webdav/propfind.rxml (modified) (1 diff)
-
app/views/webdav/proppatch.rxml (modified) (1 diff)
-
lib/dav_xml_builder.rb (modified) (1 diff)
-
lib/prop_key.rb (modified) (2 diffs)
-
lib/utility.rb (modified) (2 diffs)
-
test/functional/webdav_controller_test.rb (modified) (11 diffs)
-
test/unit/ace_test.rb (modified) (2 diffs)
-
test/unit/collection_test.rb (modified) (2 diffs)
-
test/unit/group_test.rb (modified) (3 diffs)
-
test/unit/lock_null_resource_test.rb (modified) (2 diffs)
-
test/unit/principal_test.rb (modified) (3 diffs)
-
test/unit/privilege_test.rb (modified) (2 diffs)
-
test/unit/resource_test.rb (modified) (10 diffs)
-
test/unit/user_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
limeberry/trunk/app/models/property.rb
r14 r97 58 58 self.namespace = Namespace.find_or_create_by_name!(element.namespace) 59 59 self.name = element.name 60 out = '' 61 element.write out 62 self.value = out 60 self.value = Utility.xml_print element 63 61 end 64 62 -
limeberry/trunk/app/models/resource.rb
r49 r97 432 432 433 433 def dav_displayname(xml) 434 xml.tag_with_unescaped_text! "D:displayname", self.displayname 434 xml.tag_with_unescaped_text!("D:displayname", 435 self.displayname, 436 'xmlns:D' => 'DAV:') 435 437 end 436 438 … … 591 593 end 592 594 593 594 595 def xml_wrap_liveprop(propkey, method, xml = nil, principal = nil) 595 596 method = self.method(method) … … 704 705 self.save! # should possibly be moved elsewhere 705 706 else 706 value = '' 707 element.write value 707 value = Utility.xml_print element 708 708 property = properties.find_or_build_by_propkey(pk) 709 709 property.value = value unless value.nil? # is the nil check still needed? -
limeberry/trunk/app/views/webdav/copy.rxml
r14 r97 23 23 # SOFTWARE. 24 24 25 xml. tag!("D:multistatus", "xmlns:D" => "DAV:")do25 xml.D :multistatus do 26 26 @error2urls.each do |e, urls| 27 27 xml.D :response do -
limeberry/trunk/app/views/webdav/move.rxml
r14 r97 23 23 # SOFTWARE. 24 24 25 xml. tag!("D:multistatus", "xmlns:D" => "DAV:")do25 xml.D :multistatus do 26 26 xml.D :response do 27 27 xml.D(:href, File.join(BASE_WEBDAV_PATH, @error.url)) -
limeberry/trunk/app/views/webdav/propfind.rxml
r14 r97 25 25 require 'set' 26 26 27 xml. tag!("D:multistatus", "xmlns:D" => "DAV:")do27 xml.D :multistatus do 28 28 resources_seen = Set.new if @depth.infinite? 29 29 -
limeberry/trunk/app/views/webdav/proppatch.rxml
r14 r97 23 23 # SOFTWARE. 24 24 25 xml. tag!("D:multistatus", "xmlns:D" => "DAV:")do25 xml.D :multistatus do 26 26 27 27 xml.D :response do -
limeberry/trunk/lib/dav_xml_builder.rb
r14 r97 49 49 end 50 50 51 def dav_ns_declared! 52 @dav_ns_declared 53 end 54 55 def tag_dav_ns!(sym, *args, &block) 56 @dav_ns_declared = true 57 args.push 'xmlns:D' => 'DAV:' 58 tag!(sym, *args, &block) 59 ensure 60 @dav_ns_declared = false 61 end 62 63 def D(*args, &block) 64 if dav_ns_declared! 65 method_missing('D', *args, &block) 66 else 67 args.push 'xmlns:D' => 'DAV:' 68 begin 69 @dav_ns_declared = true 70 method_missing('D', *args, &block) 71 ensure 72 @dav_ns_declared = false 73 end 74 end 75 end 76 51 77 end 52 78 -
limeberry/trunk/lib/prop_key.rb
r14 r97 75 75 end # End Class Methods 76 76 77 def tag_args 78 dav? ? ["D:#{name}"] : ["R:#{name}", { "xmlns:R" => ns }] 77 def tag_args xml 78 if dav? 79 args = [:D, name.to_sym] 80 args.push "xmlns:D" => "DAV:" unless xml.dav_ns_declared! 81 return args 82 else 83 return ["R:#{name}", { "xmlns:R" => ns }] 84 end 79 85 end 80 86 … … 82 88 def xml(xml, &block) 83 89 if block_given? 84 xml.tag!(*tag_args , &block)90 xml.tag!(*tag_args(xml), &block) 85 91 else 86 xml.tag!(*tag_args )92 xml.tag!(*tag_args(xml)) 87 93 end 88 94 end 89 95 90 96 def xml_with_unescaped_text(xml, text) 91 targs = tag_args << text97 targs = tag_args(xml) << text 92 98 xml.tag_with_unescaped_text!(*targs) 93 99 end -
limeberry/trunk/lib/utility.rb
r14 r97 23 23 require 'constants' 24 24 require 'digest/sha1' 25 require 'rexml/document' 25 26 26 27 … … 141 142 locktoken_to_uuid locktoken 142 143 end 143 end 144 end 144 145 146 147 XML_FORMATTER = REXML::Formatters::Default.new unless defined? XML_FORMATTER 148 149 # node: REXML node 150 def xml_print node 151 output = '' 152 XML_FORMATTER.write node, output 153 return output 154 end 155 145 156 end 146 157 -
limeberry/trunk/test/functional/webdav_controller_test.rb
r52 r97 111 111 <D:propstat> 112 112 <D:prop> 113 <D:displayname >Root Collection</D:displayname>113 <D:displayname xmlns:D='DAV:'>Root Collection</D:displayname> 114 114 </D:prop> 115 115 <D:status>HTTP/1.1 200 OK</D:status> … … 281 281 <D:propstat> 282 282 <D:prop> 283 <D:displayname >Foo Bar</D:displayname>283 <D:displayname xmlns:D='DAV:'>Foo Bar</D:displayname> 284 284 </D:prop> 285 285 <D:status>HTTP/1.1 200 OK</D:status> … … 304 304 <D:propstat> 305 305 <D:prop> 306 <D:displayname >#{n}</D:displayname>306 <D:displayname xmlns:D='DAV:'>#{n}</D:displayname> 307 307 </D:prop> 308 308 <D:status>HTTP/1.1 200 OK</D:status> … … 481 481 482 482 def test_proppatch_dead_set 483 484 # MAJOR HACK AND BREAKAGE! 485 # there should be no need to declare Z: twice! 486 483 487 @request.body = <<EOS 484 488 <?xml version="1.0" encoding="utf-8" ?> … … 486 490 <D:set> 487 491 <D:prop> 488 <Z:authors >492 <Z:authors xmlns:Z="http://www.w3.com/standards/z39.50/"> 489 493 <Z:Author>Jim Whitehead</Z:Author> 490 494 <Z:Author>Roy Fielding</Z:Author> … … 514 518 pk_authors = PropKey.get('http://www.w3.com/standards/z39.50/', 'authors') 515 519 expected = <<EOS 516 <Z:authors >520 <Z:authors xmlns:Z="http://www.w3.com/standards/z39.50/"> 517 521 <Z:Author>Jim Whitehead</Z:Author> 518 522 <Z:Author>Roy Fielding</Z:Author> … … 529 533 <D:set> 530 534 <D:prop> 531 <D:displayname >new name for foo</D:displayname>535 <D:displayname xmlns:D='DAV:'>new name for foo</D:displayname> 532 536 </D:prop> 533 537 </D:set> … … 562 566 <D:prop> 563 567 <dc:title xmlns:dc="http://purl.org/dc/elements/1.1/">Title for Dublin Core</dc:title> 564 <D:displayname >Display name for Dav</D:displayname>568 <D:displayname xmlns:D='DAV:'>Display name for Dav</D:displayname> 565 569 </D:prop> 566 570 </D:set> … … 635 639 <D:prop> 636 640 <dc:title xmlns:dc="http://purl.org/dc/elements/1.1/">Title for Dublin Core</dc:title> 637 <D:displayname >Display name for Dav</D:displayname>641 <D:displayname xmlns:D='DAV:'>Display name for Dav</D:displayname> 638 642 </D:prop> 639 643 </D:set> … … 889 893 <dc:title xmlns:dc="http://purl.org/dc/elements/1.1/">Title for Dublin Core</dc:title> 890 894 <N:randomname1 xmlns:N="randomns1">newvalue</N:randomname1> 891 <D:displayname >my new displayname</D:displayname>895 <D:displayname xmlns:D='DAV:'>my new displayname</D:displayname> 892 896 <D:getetag>"iwishicouldchangemyetag"</D:getetag> 893 897 </D:prop> … … 1473 1477 </D:supportedlock> 1474 1478 <D:source/> 1475 <D:displayname >#{resource.displayname}</D:displayname>1479 <D:displayname xmlns:D='DAV:'>#{resource.displayname}</D:displayname> 1476 1480 <D:lockdiscovery> 1477 1481 </D:lockdiscovery> -
limeberry/trunk/test/unit/ace_test.rb
r45 r97 62 62 63 63 def test_regenerate_principal_property_liveprop 64 @resource.displayname = "<D:href >/users/ren</D:href>"64 @resource.displayname = "<D:href xmlns:D='DAV:'>/users/ren</D:href>" 65 65 @resource.save! 66 66 ace = @resource.aces.create!(:grantdeny => Ace::GRANT, … … 69 69 assert_equal @ren, ace.principal 70 70 71 @resource.displayname = "<D:href >/users/joe</D:href>"71 @resource.displayname = "<D:href xmlns:D='DAV:'>/users/joe</D:href>" 72 72 @resource.save! 73 73 ace.reload.save! -
limeberry/trunk/test/unit/collection_test.rb
r48 r97 650 650 @root.liveprops[PropKey.get('DAV:', 'resourcetype'), xml] 651 651 652 expected_out = "<D:resourcetype ><D:collection/></D:resourcetype>"652 expected_out = "<D:resourcetype xmlns:D='DAV:'><D:collection/></D:resourcetype>" 653 653 assert_rexml_equal(expected_out, out) 654 654 end … … 699 699 def test_supported_privilege_set 700 700 expected = <<EOS 701 <D:supported-privilege-set >701 <D:supported-privilege-set xmlns:D='DAV:'> 702 702 <D:supported-privilege> 703 703 <D:privilege><D:all/></D:privilege> -
limeberry/trunk/test/unit/group_test.rb
r45 r97 66 66 @alpha.principal_url(xml) 67 67 68 assert_equal("<D:href >#{Group::GROUPS_COLLECTION_PATH}/alpha</D:href>", out)68 assert_equal("<D:href xmlns:D=\"DAV:\">#{Group::GROUPS_COLLECTION_PATH}/alpha</D:href>", out) 69 69 end 70 70 … … 75 75 76 76 [ @joe, sharad, shubham].each { |m| @alpha.add_member(m) 77 expected << "<D:href >#{User.users_collection_path}/#{m.name}</D:href>"77 expected << "<D:href xmlns:D=\"DAV:\">#{User.users_collection_path}/#{m.name}</D:href>" 78 78 } 79 79 out = "" … … 91 91 def test_group_member_set_set 92 92 expected, xml, out = setup_group_member_set 93 expected.sub!("<D:href >#{User.users_collection_path}/joe</D:href>", "")93 expected.sub!("<D:href xmlns:D=\"DAV:\">#{User.users_collection_path}/joe</D:href>", "") 94 94 prop_value="<D:group-member-set xmlns:D='DAV:'>" 95 95 prop_value << expected -
limeberry/trunk/test/unit/lock_null_resource_test.rb
r48 r97 60 60 setup_xml 61 61 @locknull.resourcetype(@xml) 62 assert_rexml_equal( '<D:resourcetype><D:locknullresource/></D:resourcetype>', @xml_out)62 assert_rexml_equal("<D:resourcetype xmlns:D='DAV:'><D:locknullresource/></D:resourcetype>", @xml_out) 63 63 end 64 64 … … 73 73 setup_xml 74 74 75 @xml.dummyroot{ @locknull.propfind(@xml, @limeberry, false, *propkeys) } 75 @xml.tag_dav_ns! :dummyroot do 76 @locknull.propfind(@xml, @limeberry, false, *propkeys) 77 end 76 78 77 79 expected_out = <<EOS 78 <dummyroot >80 <dummyroot xmlns:D='DAV:'> 79 81 <D:propstat> 80 82 <D:prop> -
limeberry/trunk/test/unit/principal_test.rb
r45 r97 98 98 @principal.principal_url(xml) 99 99 100 assert_equal("<D:href >#{Principal::PRINCIPALS_COLLECTION_PATH}/principal</D:href>", out)100 assert_equal("<D:href xmlns:D=\"DAV:\">#{Principal::PRINCIPALS_COLLECTION_PATH}/principal</D:href>", out) 101 101 end 102 102 … … 104 104 setup_xml 105 105 @limeberry.resourcetype(@xml) 106 assert_rexml_equal( '<D:resourcetype><D:principal/></D:resourcetype>',106 assert_rexml_equal("<D:resourcetype xmlns:D='DAV:'><D:principal/></D:resourcetype>", 107 107 @xml_out) 108 108 end … … 137 137 def test_supported_privilege_set 138 138 expected = <<EOS 139 <D:supported-privilege-set >139 <D:supported-privilege-set xmlns:D='DAV:'> 140 140 <D:supported-privilege> 141 141 <D:privilege><D:all/></D:privilege> -
limeberry/trunk/test/unit/privilege_test.rb
r45 r97 121 121 out = "" 122 122 Privilege.send('priv_' + priv).elem(Builder::XmlMarkup.new(:target => out)) 123 exp_out = "<D:privilege ><D:"+priv+"/></D:privilege>"123 exp_out = "<D:privilege xmlns:D='DAV:'><D:"+priv+"/></D:privilege>" 124 124 assert_rexml_equal exp_out, out 125 125 end … … 244 244 245 245 expected = <<EOS 246 <D:supported-privilege >246 <D:supported-privilege xmlns:D='DAV:'> 247 247 <D:privilege><D:all/></D:privilege> 248 248 <D:description xml:lang="en">#{Privilege.priv_all.description}</D:description> -
limeberry/trunk/test/unit/resource_test.rb
r49 r97 191 191 setup_xml 192 192 @resource.getcontentlength(@xml) 193 assert_rexml_equal("<D:getcontentlength >#{@src_content.size}</D:getcontentlength>", @xml_out)193 assert_rexml_equal("<D:getcontentlength xmlns:D='DAV:'>#{@src_content.size}</D:getcontentlength>", @xml_out) 194 194 end 195 195 … … 530 530 531 531 setup_xml 532 @xml. dummyrootdo532 @xml.tag_dav_ns! :dummyroot do 533 533 @resource.propfind(@xml, @joe, false, @pk1, @pk2, 534 534 acl_pk, displayname_pk) … … 536 536 537 537 expected_out = <<EOS 538 <dummyroot >538 <dummyroot xmlns:D='DAV:'> 539 539 <D:propstat> 540 540 <D:prop> … … 547 547 <N:randomname1 xmlns:N="randomns1">randomvalue1</N:randomname1> 548 548 <N:randomname2 xmlns:N="randomns2">randomvalue2</N:randomname2> 549 <D:displayname >this is my displayname</D:displayname>549 <D:displayname xmlns:D='DAV:'>this is my displayname</D:displayname> 550 550 </D:prop> 551 551 <D:status>HTTP/1.1 200 OK</D:status> … … 576 576 setup_xml 577 577 578 @xml. dummyroot do578 @xml.tag_dav_ns! :dummyroot do 579 579 @resource.send(:propfind_propname, @xml) 580 580 end 581 581 582 582 expected_out = <<EOS 583 <dummyroot >583 <dummyroot xmlns:D='DAV:'> 584 584 <D:creationdate/> 585 585 <D:displayname/> … … 615 615 @resource.dav_resource_id(@xml) 616 616 expected_urn = Utility.uuid_to_urn(@resource.uuid) 617 expected_out = "<D:resource-id ><D:href>#{expected_urn}</D:href></D:resource-id>"617 expected_out = "<D:resource-id xmlns:D='DAV:'><D:href>#{expected_urn}</D:href></D:resource-id>" 618 618 assert_rexml_equal(expected_out, @xml_out) 619 619 end … … 710 710 setup_xml 711 711 @resource.resourcetype(@xml) 712 assert_rexml_equal( '<D:resourcetype/>', @xml_out)712 assert_rexml_equal("<D:resourcetype xmlns:D='DAV:'/>", @xml_out) 713 713 end 714 714 … … 790 790 klass.new.supported_live_property_set(@xml) 791 791 792 expected_out = "<D:supported-live-property-set >"792 expected_out = "<D:supported-live-property-set xmlns:D='DAV:'>" 793 793 klass.liveprops.each do |propkey, live_prop_info| 794 794 expected_out << "<D:supported-live-property><D:prop>" … … 873 873 setup_xml 874 874 @resource.group @xml 875 assert_rexml_equal "<D:group />", @xml_out875 assert_rexml_equal "<D:group xmlns:D='DAV:'/>", @xml_out 876 876 end 877 877 … … 887 887 def test_supported_privilege_set 888 888 expected = <<EOS 889 <D:supported-privilege-set >889 <D:supported-privilege-set xmlns:D='DAV:'> 890 890 <D:supported-privilege> 891 891 <D:privilege><D:all/></D:privilege> -
limeberry/trunk/test/unit/user_test.rb
r45 r97 84 84 xml = Builder::XmlMarkup.new(:target => out) 85 85 @joe.principal_url(xml) 86 assert_equal("<D:href >#{User::USERS_COLLECTION_PATH}/joe</D:href>", out)86 assert_equal("<D:href xmlns:D=\"DAV:\">#{User::USERS_COLLECTION_PATH}/joe</D:href>", out) 87 87 end 88 88
