~plaxx/tomdroid/iteration-3

« back to all changes in this revision

Viewing changes to src/org/tomdroid/xml/NoteHandler.java

  • Committer: Olivier Bilodeau
  • Date: 2008-12-11 05:51:16 UTC
  • Revision ID: olivier@bottomlesspit.org-20081211055116-jaz6p38jevb0lz1x
Parsing title and last-change-date tags in Note XML and setting them in Note object.
last-change-date is parsed using joda-time lib (jar added to lib/)

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 */
23
23
package org.tomdroid.xml;
24
24
 
 
25
import org.joda.time.format.DateTimeFormatter;
 
26
import org.joda.time.format.ISODateTimeFormat;
25
27
import org.tomdroid.Note;
26
28
import org.xml.sax.Attributes;
27
29
import org.xml.sax.SAXException;
45
47
public class NoteHandler extends DefaultHandler {
46
48
        
47
49
        // position keepers
 
50
        private boolean inTitleTag = false;
 
51
        private boolean inLastChangeDateTag = false;
48
52
        private boolean inNoteTag = false;
49
53
        private boolean inTextTag = false;
50
54
        private boolean inNoteContentTag = false;
61
65
        private boolean inListItem = false;
62
66
        
63
67
        // -- Tomboy's notes XML tags names --
 
68
        // Metadata related
 
69
        private final static String TITLE = "title";
 
70
        private final static String LAST_CHANGE_DATE = "last-change-date"; 
64
71
        // Style related
65
72
        private final static String NOTE_CONTENT = "note-content";
66
73
        private final static String BOLD = "bold";
101
108
                        // we are under the note-content tag
102
109
                        // we will append all its nested tags so I create a string builder to do that
103
110
                        inNoteContentTag = true;
 
111
                } else if (localName.equals(TITLE)) {
 
112
                        inTitleTag = true;
 
113
                } else if (localName.equals(LAST_CHANGE_DATE)) {
 
114
                        inLastChangeDateTag = true;
104
115
                }
105
116
 
106
117
                // if we are in note-content, keep and convert formatting tags
144
155
                        
145
156
                        // note-content is over, we can set the builded note to Note's noteContent
146
157
                        inNoteContentTag = false;
 
158
                } else if (localName.equals(TITLE)) {
 
159
                        inTitleTag = false;
 
160
                } else if (localName.equals(LAST_CHANGE_DATE)) {
 
161
                        inLastChangeDateTag = false;
147
162
                }
148
163
                
149
164
                // if we are in note-content, keep and convert formatting tags
184
199
                
185
200
                // TODO remove this call when we will be done
186
201
                Log.i(this.toString(), "char string: " + currentString);
 
202
                
 
203
                if (inTitleTag) {
 
204
                        note.setTitle(currentString);
 
205
                } else if (inLastChangeDateTag) {
 
206
                        //TODO there is probably a parsing error here we should trap 
 
207
                        DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
 
208
                        note.setLastChangeDate(fmt.parseDateTime(currentString));
 
209
                }
187
210
 
188
211
                if (inNoteContentTag) {
189
212
                        // while we are in note-content, append