4 // Copyright (C) 2004 Christopher Orr
5 // Copyright (C) 2004 Novell, Inc.
9 // Permission is hereby granted, free of charge, to any person obtaining a
10 // copy of this software and associated documentation files (the "Software"),
11 // to deal in the Software without restriction, including without limitation
12 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 // and/or sell copies of the Software, and to permit persons to whom the
14 // Software is furnished to do so, subject to the following conditions:
16 // The above copyright notice and this permission notice shall be included in
17 // all copies or substantial portions of the Software.
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 // DEALINGS IN THE SOFTWARE.
33 namespace Beagle
.Util
{
35 public abstract class Note
{
38 private string filename
;
39 public string subject
;
41 public DateTime timestamp
;
43 //////////////////////////
45 protected Note (string _type
, string _filename
) {
47 this.filename
= _filename
;
50 // FIXME: this is a mess
53 return BuildNoteUri (filename
, type
);
57 public static Uri
BuildNoteUri (string _filename
, string _type
)
59 string name
= Path
.GetFileNameWithoutExtension (_filename
);
60 string uri
= String
.Format ("note://{0}/{1}", _type
, name
);
61 return new Uri (uri
, true);
65 ///////////////////////////////////////////////////////////////////////////////
71 public class TomboyNote
: Note
{
73 private TomboyNote (string type
, string filename
) : base ("tomboy", filename
)
76 private TomboyNote (string filename
) : base ("tomboy", filename
)
79 public static Note
ParseNote (FileInfo file
)
81 // Tomboy uses .note files.
82 // Don't index the backup folder.
83 if (file
.Extension
!= ".note"
84 || file
.DirectoryName
.EndsWith ("/Backup")) {
88 // Create new note instance
89 Note note
= new TomboyNote(file
.FullName
);
90 note
.timestamp
= file
.LastWriteTimeUtc
;
92 // Parse XML info from file
93 StreamReader reader
= new StreamReader (file
.FullName
, System
.Text
.Encoding
.UTF8
);
94 XmlTextReader doc
= new XmlTextReader (reader
);
95 doc
.Namespaces
= false;
97 bool read_text
= false;
98 StringBuilder sb
= new StringBuilder ();
100 while (doc
.Read ()) {
101 // FIXME: Extract more information than mere text from the tags in note-content
102 // for hottext, linking notes etc.
103 if (doc
.NodeType
== XmlNodeType
.Element
&& doc
.Name
== "note-content") {
108 if (doc
.NodeType
== XmlNodeType
.EndElement
&& doc
.Name
== "note-content") {
113 if (doc
.NodeType
== XmlNodeType
.Element
&& doc
.Name
== "title") {
114 note
.subject
= doc
.ReadString ();
118 if (doc
.NodeType
== XmlNodeType
.Text
) {
120 sb
.Append (doc
.Value
);
126 note
.text
= sb
.ToString ();
131 private static string StripTags (string line
)
135 i
= line
.IndexOf ('<');
138 j
= line
.IndexOf ('>', i
);
139 line
= line
.Substring (0, i
) + line
.Substring (j
+1);