2007-10-17 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mcs / class / System / System.Net.Mail / AlternateView.cs
1 //
2 // System.Net.Mail.AlternateView.cs
3 //
4 // Author:
5 //      John Luke (john.luke@gmail.com)
6 //
7 // Copyright (C) John Luke, 2005
8 //
9
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 #if NET_2_0
32
33 using System.IO;
34 using System.Net.Mime;
35 using System.Text;
36
37 namespace System.Net.Mail {
38         public class AlternateView : AttachmentBase
39         {
40                 #region Fields
41                 Uri baseUri;
42                 LinkedResourceCollection linkedResources = new LinkedResourceCollection ();
43
44                 #endregion // Fields
45
46                 #region Constructors
47
48                 public AlternateView (string fileName) : base (fileName)
49                 {
50                         if (fileName == null)
51                                 throw new ArgumentNullException ();
52                 }
53
54                 public AlternateView (string fileName, ContentType contentType) : base (fileName, contentType)
55                 {
56                         if (fileName == null)
57                                 throw new ArgumentNullException ();
58                 }
59
60                 public AlternateView (string fileName, string mediaType) : base (fileName, mediaType)
61                 {
62                         if (fileName == null)
63                                 throw new ArgumentNullException ();
64                 }
65
66                 public AlternateView (Stream contentStream) : base (contentStream)
67                 {
68                         if (contentStream == null)
69                                 throw new ArgumentNullException ();
70                 }
71                 
72                 public AlternateView (Stream contentStream, string mediaType) : base (contentStream, mediaType)
73                 {
74                         if (contentStream == null)
75                                 throw new ArgumentNullException ();
76                 }
77                 
78                 public AlternateView (Stream contentStream, ContentType contentType) : base (contentStream, contentType)
79                 {
80                         if (contentStream == null)
81                                 throw new ArgumentNullException ();
82                 }
83
84                 #endregion // Constructors
85
86                 #region Properties
87
88                 #endregion // Properties
89
90                 public Uri BaseUri {
91                         get { return baseUri; }
92                         set { baseUri = value; }
93                 }
94
95                 public LinkedResourceCollection LinkedResources {
96                         get { return linkedResources; }
97                 }
98                 
99                 #region Methods
100
101                 public static AlternateView CreateAlternateViewFromString (string content)
102                 {
103                         if (content == null)
104                                 throw new ArgumentNullException ();
105                         MemoryStream ms = new MemoryStream (Encoding.UTF8.GetBytes (content));
106                         return new AlternateView (ms);
107                 }
108
109                 public static AlternateView CreateAlternateViewFromString (string content, ContentType contentType)
110                 {
111                         if (content == null)
112                                 throw new ArgumentNullException ();
113                         MemoryStream ms = new MemoryStream (Encoding.UTF8.GetBytes (content));
114                         return new AlternateView (ms, contentType);
115                 }
116
117                 public static AlternateView CreateAlternateViewFromString (string content, Encoding encoding, string mediaType)
118                 {
119                         if (content == null)
120                                 throw new ArgumentNullException ();
121                         MemoryStream ms = new MemoryStream (encoding.GetBytes (content));
122                         return new AlternateView (ms, mediaType);
123                 }
124
125                 protected override void Dispose (bool disposing)
126                 {
127                         if (disposing)
128                                 foreach (LinkedResource lr in linkedResources)
129                                         lr.Dispose ();
130                         base.Dispose (disposing);
131                 }
132                 
133                 #endregion // Methods
134         }
135 }
136
137 #endif // NET_2_0