~dobey/shardbridge/trunk

« back to all changes in this revision

Viewing changes to src/shardbridge-document.vala

  • Committer: Rodney Dawes
  • Date: 2011-12-26 21:06:50 UTC
  • Revision ID: dobey@wayofthemonkey.com-20111226210650-7r87fr2456k1paes
Allow Document content and revision to be null
Allow Document.get_content_string to return null
Implement Database.delete_doc, and test it

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
                private string _revision;
24
24
                private bool   _conflicted;
25
25
 
26
 
                private Json.Object _content;
 
26
                private Json.Object _content = null;
27
27
 
28
28
 
29
29
                public Document (string doc_id, string doc_revision,
30
 
                                                 string doc_content,
 
30
                                                 string? doc_content,
31
31
                                                 bool has_conflicts=false) throws DataError {
32
32
                        var match = Regex.match_simple ("^[^/\\\\]+$", doc_id);
33
33
                        if (! match)
36
36
                        _id = doc_id;
37
37
                        _revision = doc_revision;
38
38
                        _conflicted = has_conflicts;
39
 
                        set_content_string (doc_content);
 
39
                        if (doc_content != null && doc_content != "")
 
40
                                set_content_string (doc_content);
40
41
                }
41
42
 
42
43
                public string id {
57
58
                        get { return _conflicted; }
58
59
                }
59
60
 
60
 
                public string get_content_string () {
 
61
                public string? get_content_string () {
 
62
                        if (_content == null)
 
63
                                return null;
 
64
 
61
65
                        var generator = new Generator ();
62
66
                        var root = new Json.Node (NodeType.OBJECT);
63
67
                        string data;
70
74
                }
71
75
 
72
76
                public void set_content_string (string content_string)
73
 
                        throws DataError {
 
77
                throws DataError
 
78
                {
 
79
                        if (content_string == "")
 
80
                                return;
 
81
 
74
82
                        try {
75
83
                                var parser = new Parser ();
76
84
                                if (!parser.load_from_data (content_string, -1))