3 using System
.Collections
;
5 using System
.Reflection
;
9 abstract public class Content
{
11 static Hashtable registry
= new Hashtable();
13 static public void Register(Type handler
) {
14 if (! handler
.IsSubclassOf(typeof(Content
))) {
15 // throw exception: type not subclass of Content
18 Content dummy
= (Content
)Activator
.CreateInstance(handler
);
19 foreach (String mime_type
in dummy
.HandledMimeTypes()) {
20 if (registry
.Contains(mime_type
)) {
21 // throw exception: duplicated mime type
23 registry
[mime_type
] = handler
;
27 static public Content
Extract(String mime_type
, Stream stream
) {
28 Content content
= null;
29 if (registry
.Contains(mime_type
)) {
30 Type handler
= registry
[mime_type
] as Type
;
31 content
= Activator
.CreateInstance(handler
) as Content
;
33 if (! content
.Read(stream
))
39 //////////////////////////////
41 Hashtable metadata
= new Hashtable();
46 abstract public String
[] HandledMimeTypes();
47 abstract public bool Read(Stream content_stream
);
49 protected void SetMetadata(String key
, String
value) {
50 metadata
[key
.ToLower()] = value;
53 protected void SetBody(String _body
) {
55 // FIXME: complain that you can't set the body twice
60 public ICollection MetadataKeys
{
61 get { return metadata.Keys; }
64 public String
this[String key
] {
65 get { return metadata[key.ToLower()] as String; }