source: extensions/gsdl-video/trunk/installed/cmdline/lib/ruby/1.8/soap/attachment.rb@ 18425

Last change on this file since 18425 was 18425, checked in by davidb, 15 years ago

Video extension to Greenstone

File size: 2.0 KB
Line 
1# soap/attachment.rb: SOAP4R - SwA implementation.
2# Copyright (C) 2002, 2003 Jamie Herre and NAKAMURA, Hiroshi <[email protected]>.
3
4# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
5# redistribute it and/or modify it under the same terms of Ruby's license;
6# either the dual license version in 2003, or any later version.
7
8
9require 'soap/baseData'
10require 'soap/mapping'
11
12
13module SOAP
14
15
16class SOAPAttachment < SOAPExternalReference
17 attr_reader :data
18
19 def initialize(value)
20 super()
21 @data = value
22 end
23
24private
25
26 def external_contentid
27 @data.contentid
28 end
29end
30
31
32class Attachment
33 attr_reader :io
34 attr_accessor :contenttype
35
36 def initialize(string_or_readable = nil)
37 @string_or_readable = string_or_readable
38 @contenttype = "application/octet-stream"
39 @contentid = nil
40 end
41
42 def contentid
43 @contentid ||= Attachment.contentid(self)
44 end
45
46 def contentid=(contentid)
47 @contentid = contentid
48 end
49
50 def mime_contentid
51 '<' + contentid + '>'
52 end
53
54 def content
55 if @content == nil and @string_or_readable != nil
56 @content = @string_or_readable.respond_to?(:read) ?
57 @string_or_readable.read : @string_or_readable
58 end
59 @content
60 end
61
62 def to_s
63 content
64 end
65
66 def write(out)
67 out.write(content)
68 end
69
70 def save(filename)
71 File.open(filename, "wb") do |f|
72 write(f)
73 end
74 end
75
76 def self.contentid(obj)
77 # this needs to be fixed
78 [obj.__id__.to_s, Process.pid.to_s].join('.')
79 end
80
81 def self.mime_contentid(obj)
82 '<' + contentid(obj) + '>'
83 end
84end
85
86
87module Mapping
88 class AttachmentFactory < SOAP::Mapping::Factory
89 def obj2soap(soap_class, obj, info, map)
90 soap_obj = soap_class.new(obj)
91 mark_marshalled_obj(obj, soap_obj)
92 soap_obj
93 end
94
95 def soap2obj(obj_class, node, info, map)
96 obj = node.data
97 mark_unmarshalled_obj(node, obj)
98 return true, obj
99 end
100 end
101
102 DefaultRegistry.add(::SOAP::Attachment, ::SOAP::SOAPAttachment,
103 AttachmentFactory.new, nil)
104end
105
106
107end
Note: See TracBrowser for help on using the repository browser.