Add --enable-deletion option to buildindex. If used, buildindex will remove deleted...
[beagle.git] / Util / XmpFile.cs
blob93978a79296400a2d14f55f19b128b018dac4d2f
1 using System.Xml;
2 using SemWeb;
5 namespace Beagle.Util {
6 public class XmpFile : SemWeb.StatementSource, SemWeb.StatementSink
8 MetadataStore store;
10 public MetadataStore Store {
11 get { return store; }
14 public XmpFile (System.IO.Stream stream) : this ()
16 Load (stream);
19 public XmpFile ()
21 store = new MetadataStore ();
24 public void Load (System.IO.Stream stream)
26 try {
27 store.Import (new SemWeb.RdfXmlReader (stream));
28 //Dump ();
29 } catch (System.Exception e) {
30 System.Console.WriteLine (e.ToString ());
34 public void Save (System.IO.Stream stream)
36 try {
37 XmlTextWriter text;
38 RdfXmlWriter writer;
40 text = new XmlTextWriter (stream, System.Text.Encoding.UTF8);
41 using (writer = new RdfXmlWriter (text, MetadataStore.Namespaces)) {
42 text.WriteProcessingInstruction ("xpacket", "begin=\"\ufeff\" id=\"testing\"");
43 text.WriteStartElement ("x:xmpmeta");
44 text.WriteAttributeString ("xmlns", "x", null, "adobe:ns:meta/");
45 store.Select (writer);
48 text.WriteEndElement ();
49 text.WriteProcessingInstruction ("xpacket", "end=\"r\"");
50 text.Close ();
52 } catch (System.Exception e) {
53 System.Console.WriteLine (e);
57 public bool Add (Statement stmt)
59 return ((SemWeb.StatementSink)store).Add (stmt);
62 public void Select (SemWeb.StatementSink sink)
64 store.Select (sink);
67 public void Dump ()
69 foreach (SemWeb.Statement stmt in store) {
70 System.Console.WriteLine(stmt);
74 #if TEST_XMP
75 static void Main (string [] args)
77 XmpFile xmp = new XmpFile (System.IO.File.OpenRead (args [0]));
78 //xmp.Store.Dump ();
79 #if false
80 System.IO.StreamReader stream = new System.IO.StreamReader (System.IO.File.OpenRead (args [0]));
82 while (stream.BaseStream.Position < stream.BaseStream.Length) {
83 System.Console.WriteLine (stream.ReadLine ());
85 #endif
87 #endif