Merge lp:~vbkaisetsu/tomdroid/sql-args into lp:~tomdroid-maintainers/tomdroid/main

Proposed by Koichi Akabe
Status: Superseded
Proposed branch: lp:~vbkaisetsu/tomdroid/sql-args
Merge into: lp:~tomdroid-maintainers/tomdroid/main
Diff against target: 440 lines (+190/-33)
5 files modified
src/org/tomdroid/Note.java (+7/-1)
src/org/tomdroid/NoteManager.java (+42/-14)
src/org/tomdroid/NoteProvider.java (+73/-18)
src/org/tomdroid/sync/sd/NoteHandler.java (+17/-0)
src/org/tomdroid/util/StringConverter.java (+51/-0)
To merge this branch: bzr merge lp:~vbkaisetsu/tomdroid/sql-args
Reviewer Review Type Date Requested Status
Olivier Bilodeau Needs Fixing
Review via email: mp+80555@code.launchpad.net

This proposal has been superseded by a proposal from 2012-09-08.

Description of the change

This branch fixes following things:
    - Bug #562089: the search-bar search also XML tags Remove
    - Bug #880322: SQL query should use "?" and selectionArgs Remove
    - The list always shows system:template notes
    - Can't search words which contains "%" or "_"

New features:
    - Added notebook argument to NoteManager.getListAdapter() function

Please see it.

Regards,
Koichi Akabe

To post a comment you must log in.
Revision history for this message
Piotr Adamski (mcveat) wrote :

Please consider using StringBuilder for constructing where clause and wrapping it in separate function to increase readability and divide responsibilities a bit.

lp:~vbkaisetsu/tomdroid/sql-args updated
256. By Koichi Akabe

changed to use StringBuilder

Revision history for this message
Koichi Akabe (vbkaisetsu) wrote :

Hello Piotr,

Thanks your opinion.
I changed the code to use StringBuilder.

Regards,
Koichi Akabe.

Revision history for this message
Piotr Adamski (mcveat) wrote :

Great, Koichi! But your fix needs one more change in my opinion. The point of using StringBuilder is to avoid explicit string concatenation, as each produces new String in strings pool. It may strike back as memory issue, so it is worth to avoid them in cases like this, where there is a lot string operations. Consider replacing each concatenation with append method call. I know it doesn't look so concise, but in that situation i think it is worth it.

Regards
Piotr

Revision history for this message
Koichi Akabe (vbkaisetsu) wrote :

I think constants' normal operation is faster than using StringBuffer.
Because they are calculated in compiling.

Note.XXXXXs are defined with final, so they are constant.

lp:~vbkaisetsu/tomdroid/sql-args updated
257. By Koichi Akabe

added NOTE_CONTENT_PLAIN to restore plain text contents
changed to search NOTE_CONTENT_PLAIN

Revision history for this message
Koichi Akabe (vbkaisetsu) wrote :

The commit message is wrong: s/restore/store/

Sorry.

lp:~vbkaisetsu/tomdroid/sql-args updated
258. By Koichi Akabe

added some html escape codes

259. By Koichi Akabe

changed to use android.text.Html

260. By Koichi Akabe

changed SQL query to ignore templates

Revision history for this message
Stefan Hammer (j-4-deactivatedaccount) wrote :

Hi! The bug where searching for tags shows all notes is finally gone - great!
But somehow, the test notebook templates still show up in the notes list and in the search on my AVDevices. (even after complete reinstall.)
Do you have any idea?

Revision history for this message
Koichi Akabe (vbkaisetsu) wrote :

In my environment, templates have "system:template" tag and they are not shown on the list.
Please debug it and tell me more information.

Revision history for this message
Stefan Hammer (j-4-deactivatedaccount) wrote :

Hi! I use Android 1.6 AVD, the sdcard image (sdcard.img) from our sources and exactly your code branch, with additional log entries. I still have both two test notebook templates in the list.

In this templates the tags look like:
  <tags>

    <tag>system:template</tag>

    <tag>system:notebook:test</tag>

  </tags>

  <tags>
    <tag>system:notebook:Hipo</tag>
    <tag>system:template</tag>
  </tags>

My log gives:
10-30 11:04:27.107: I/Tomdroid(486): Tomdroid is first run.
10-30 11:04:27.227: V/FirstNote(486): Creating first note
10-30 11:04:27.537: V/NoteManager(486): A new note has been detected (not yet in db)
10-30 11:04:27.547: V/NoteManager(486): Note inserted in content provider. ID: content://org.tomdroid.notes/notes/1 TITLE:Tomdroid's first note GUID:8f837a99-c920-4501-b303-6a39af57a714
10-30 11:04:27.626: V/NoteManager(486): where is: tags NOT LIKE '%system:template%'
10-30 11:04:27.626: V/NoteManager(486): TAGS is: tags
10-30 11:04:52.287: V/FirstNote(486): Creating first note
10-30 11:04:52.556: V/NoteManager(486): A new note has been detected (not yet in db)
10-30 11:04:52.566: V/NoteManager(486): Note inserted in content provider. ID: content://org.tomdroid.notes/notes/1 TITLE:Tomdroid's first note GUID:8f837a99-c920-4501-b303-6a39af57a714
10-30 11:04:55.497: V/SdCardSyncService(486): Loading local notes
10-30 11:04:55.497: I/SdCardSyncService(486): Path /sdcard/tomdroid exists: true

It works when syncing the AVD with Ubuntu One, using my own notes. One difference is, that there i do not use notebooks.
So, the tags look like:

  <tags>
    <tag>system:template</tag>
  </tags>

10-30 11:34:44.367: V/FirstNote(652): Creating first note
10-30 11:34:44.786: V/NoteManager(652): A new note has been detected (not yet in db)
10-30 11:34:44.797: V/NoteManager(652): Note inserted in content provider. ID: content://org.tomdroid.notes/notes/1 TITLE:Tomdroid's first note GUID:8f837a99-c920-4501-b303-6a39af57a714
10-30 11:35:30.927: V/NoteManager(652): where is: tags NOT LIKE '%system:template%'
10-30 11:35:30.927: V/NoteManager(652): query is: null

Does this help?

Revision history for this message
Koichi Akabe (vbkaisetsu) wrote :

Notes list always shows templates on SD card, because Tomdroid doesn't check "tags" tag.

I registered another branch to solve it.
https://code.launchpad.net/~vbkaisetsu/tomdroid/sdcard-tags

Thanks for reporting!

lp:~vbkaisetsu/tomdroid/sql-args updated
261. By Koichi Akabe

marged sdcard-tags branch

Revision history for this message
Stefan Hammer (j-4-deactivatedaccount) wrote :

Thanks for your work. I already know the code very well and I think it's awesome. This is something we definitively have to include in the next release.
The new sql query system is much simpler/smarter and that notebook templates are in the database, but not shown - just as it should be ;-)

Problem is... I have never merged any important code and I am not sure, what Olivier's reviewing checklist/merging criteria contains. Therefore I suggest to wait for his opinion. If he is fine with it, I will merge immediately.

There was a idea coming up, when testing this stuff: We now store all tags, including the "system:notebook:****" tag. If you include Note.TAGS in the search query, it would be very easy to display all notes of one notebooks, just with the query "notebook:mynotebookname". Of course, we would have to think about a way to exclude queries like notebook, system or template from searching in Note.TAGS... But hey, intelligent searching! Further... how about title:mynotetitle?? :-D ... but this would be something for a new project, if you feel like it!

Revision history for this message
Koichi Akabe (vbkaisetsu) wrote :

Hello Stefan,

It's wonderful but there are many problems for notebooks.
We have to register another branch to solve them.

lp:~vbkaisetsu/tomdroid/sql-args updated
262. By Koichi Akabe

added notebook support

Revision history for this message
Koichi Akabe (vbkaisetsu) wrote :

I added notebook support to getListAdapter(), and you can search "%" and "_" now.
This code encodes some symbols of notes before store them.

I think this code is dirty. Please review it.

lp:~vbkaisetsu/tomdroid/sql-args updated
263. By Koichi Akabe

fixed wrong sql

Revision history for this message
Olivier Bilodeau (plaxx) wrote :

Doesn't automatically upgrade the SQL database. This can't be merged as-is.

Also, I would like to see the query arguments to be migrated into ? and selectionArgs as query() supports. docs/reference/android/database/sqlite/SQLiteDatabase.html#query(java.lang.String, java.lang.String[], java.lang.String, java.lang.String[], java.lang.String, java.lang.String, java.lang.String, java.lang.String)

review: Needs Fixing
lp:~vbkaisetsu/tomdroid/sql-args updated
264. By Koichi Akabe

merge with trunk to solve conflicts

265. By Koichi Akabe

change database version to 4 and support to update database from ver.2 or later

Revision history for this message
Koichi Akabe (vbkaisetsu) wrote :

changed onUpgrade to support update from old versions 2 or 3. But version 1 dosn't have GUID and note contents (title only) so it doesn't support.

Revision history for this message
Olivier Bilodeau (plaxx) wrote :

w/o looking at the code, I would say not upgrading from 1 is ok.

What I'm really concerned about is the 0.4.1 users on the android market. I want them to upgrade cleanly. Pretty sure this fixes it.

Revision history for this message
Stefan Hammer (j-4-deactivatedaccount) wrote :

Hi!

Since our new beta, a lot of things changed. However, we still need to fix parts of the things treated in this branch.
    - Bug #562089: the search-bar search also XML tags Remove
    - Bug #880322: SQL query should use "?" and selectionArgs Remove
    - Can't search words which contains "%" or "_"

All the other features are already implemented (i think)
As I assume that this branch won't merge with the new beta it is probably best to rewrite these things too (or copy/paste the neccesary stuff into the new beta code).

@Koichi: do you want to fix this three issues in a new branch, or do you prefere if somebody else does it?

Revision history for this message
Koichi Akabe (vbkaisetsu) wrote :

I hope to fix this branch, but the other hand, it's hard work.
I'll appreciate someone's help.

Unmerged revisions

265. By Koichi Akabe

change database version to 4 and support to update database from ver.2 or later

264. By Koichi Akabe

merge with trunk to solve conflicts

263. By Koichi Akabe

fixed wrong sql

262. By Koichi Akabe

added notebook support

261. By Koichi Akabe

marged sdcard-tags branch

260. By Koichi Akabe

changed SQL query to ignore templates

259. By Koichi Akabe

changed to use android.text.Html

258. By Koichi Akabe

added some html escape codes

257. By Koichi Akabe

added NOTE_CONTENT_PLAIN to restore plain text contents
changed to search NOTE_CONTENT_PLAIN

256. By Koichi Akabe

changed to use StringBuilder

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/org/tomdroid/Note.java'
--- src/org/tomdroid/Note.java 2011-10-27 16:33:12 +0000
+++ src/org/tomdroid/Note.java 2012-04-01 04:35:23 +0000
@@ -30,6 +30,7 @@
30import org.json.JSONArray;30import org.json.JSONArray;
31import org.json.JSONObject;31import org.json.JSONObject;
32import org.tomdroid.util.NoteContentBuilder;32import org.tomdroid.util.NoteContentBuilder;
33import org.tomdroid.util.StringConverter;
33import org.tomdroid.util.TLog;34import org.tomdroid.util.TLog;
34import org.tomdroid.util.XmlUtils;35import org.tomdroid.util.XmlUtils;
3536
@@ -47,6 +48,7 @@
47 public static final String FILE = "file";48 public static final String FILE = "file";
48 public static final String TAGS = "tags";49 public static final String TAGS = "tags";
49 public static final String NOTE_CONTENT = "content";50 public static final String NOTE_CONTENT = "content";
51 public static final String NOTE_CONTENT_PLAIN = "content_plain";
50 52
51 // Logging info53 // Logging info
52 private static final String TAG = "Note";54 private static final String TAG = "Note";
@@ -95,7 +97,7 @@
95 tags = new String();97 tags = new String();
96 if (jtags != null) {98 if (jtags != null) {
97 for (int i = 0; i < jtags.length(); i++ ) {99 for (int i = 0; i < jtags.length(); i++ ) {
98 tag = jtags.optString(i);100 tag = StringConverter.encode(jtags.optString(i));
99 tags += tag + ",";101 tags += tag + ",";
100 }102 }
101 }103 }
@@ -104,6 +106,10 @@
104 public String getTags() {106 public String getTags() {
105 return tags;107 return tags;
106 }108 }
109
110 public void setTags(String tags) {
111 this.tags = tags;
112 }
107113
108 public String getUrl() {114 public String getUrl() {
109 return url;115 return url;
110116
=== modified file 'src/org/tomdroid/NoteManager.java'
--- src/org/tomdroid/NoteManager.java 2011-10-27 16:33:12 +0000
+++ src/org/tomdroid/NoteManager.java 2012-04-01 04:35:23 +0000
@@ -24,11 +24,22 @@
24 */24 */
25package org.tomdroid;25package org.tomdroid;
2626
27import java.util.ArrayList;
28import java.util.regex.Matcher;
29import java.util.regex.Pattern;
30
31import org.tomdroid.ui.Tomdroid;
32import org.tomdroid.util.NoteListCursorAdapter;
33import org.tomdroid.util.StringConverter;
34import org.tomdroid.util.XmlUtils;
35
27import android.app.Activity;36import android.app.Activity;
28import android.content.ContentResolver;37import android.content.ContentResolver;
29import android.content.ContentValues;38import android.content.ContentValues;
30import android.database.Cursor;39import android.database.Cursor;
31import android.net.Uri;40import android.net.Uri;
41import android.text.Html;
42import android.util.Log;
32import android.widget.ListAdapter;43import android.widget.ListAdapter;
33import org.tomdroid.ui.Tomdroid;44import org.tomdroid.ui.Tomdroid;
34import org.tomdroid.util.NoteListCursorAdapter;45import org.tomdroid.util.NoteListCursorAdapter;
@@ -92,6 +103,9 @@
92 null);103 null);
93 activity.startManagingCursor(managedCursor);104 activity.startManagingCursor(managedCursor);
94 105
106 String xmlContent = note.getXmlContent();
107 String plainContent = StringConverter.encode(Html.fromHtml(xmlContent).toString());
108
95 // Preparing the values to be either inserted or updated109 // Preparing the values to be either inserted or updated
96 // depending on the result of the previous query110 // depending on the result of the previous query
97 ContentValues values = new ContentValues();111 ContentValues values = new ContentValues();
@@ -100,7 +114,8 @@
100 values.put(Note.GUID, note.getGuid().toString());114 values.put(Note.GUID, note.getGuid().toString());
101 // Notice that we store the date in UTC because sqlite doesn't handle RFC3339 timezone information115 // Notice that we store the date in UTC because sqlite doesn't handle RFC3339 timezone information
102 values.put(Note.MODIFIED_DATE, note.getLastChangeDate().format3339(false));116 values.put(Note.MODIFIED_DATE, note.getLastChangeDate().format3339(false));
103 values.put(Note.NOTE_CONTENT, note.getXmlContent());117 values.put(Note.NOTE_CONTENT, xmlContent);
118 values.put(Note.NOTE_CONTENT_PLAIN, plainContent);
104 values.put(Note.TAGS, note.getTags());119 values.put(Note.TAGS, note.getTags());
105 120
106 if (managedCursor.getCount() == 0) {121 if (managedCursor.getCount() == 0) {
@@ -148,26 +163,33 @@
148 }163 }
149 164
150165
151 public static ListAdapter getListAdapter(Activity activity, String querys) {166 public static ListAdapter getListAdapter(Activity activity, String querys, String notebook) {
152 167
153 String where;168 StringBuilder where = new StringBuilder();
154 if (querys==null) {169 ArrayList<String> qargs = new ArrayList<String>();
155 where=null;170
156 } else {171 where.append(Note.TAGS + " NOT LIKE 'system:template%' AND " + Note.TAGS + " NOT LIKE '%,system:template%'");
172
173 if(notebook != null) {
174 // sql statements to specify notebook
175 String encodedNotebook = StringConverter.encodeForTag(notebook);
176 where.append(" AND ("+Note.TAGS+" LIKE ? OR "+Note.TAGS+" LIKE ?)");
177 qargs.add("%,system:notebook:"+encodedNotebook+",%");
178 qargs.add("system:notebook:"+encodedNotebook+",%");
179 }
180
181 if (querys!=null) {
157 // sql statements to search notes182 // sql statements to search notes
158 String[] query = querys.split(" ");183 String[] query = querys.split(" ");
159 where="";
160 int count=0;
161 for (String string : query) {184 for (String string : query) {
162 if (count>0) where = where + " AND ";185 qargs.add("%"+StringConverter.encode(string)+"%");
163 where = where + "("+Note.TITLE+" LIKE '%"+string+"%' OR "+Note.NOTE_CONTENT+" LIKE '%"+string+"%')";186 where.append(" AND "+Note.TITLE+" || "+Note.NOTE_CONTENT_PLAIN+" LIKE ?");
164 count++;
165 } 187 }
166 }188 }
167189
168 // get a cursor representing all notes from the NoteProvider190 // get a cursor representing all notes from the NoteProvider
169 Uri notes = Tomdroid.CONTENT_URI;191 Uri notes = Tomdroid.CONTENT_URI;
170 Cursor notesCursor = activity.managedQuery(notes, LIST_PROJECTION, where, null, null);192 Cursor notesCursor = activity.managedQuery(notes, LIST_PROJECTION, where.toString(), qargs.toArray(new String[qargs.size()]), null);
171 193
172 // set up an adapter binding the TITLE field of the cursor to the list item194 // set up an adapter binding the TITLE field of the cursor to the list item
173 String[] from = new String[] { Note.TITLE };195 String[] from = new String[] { Note.TITLE };
@@ -175,9 +197,14 @@
175 return new NoteListCursorAdapter(activity, R.layout.main_list_item, notesCursor, from, to);197 return new NoteListCursorAdapter(activity, R.layout.main_list_item, notesCursor, from, to);
176 }198 }
177 199
200 public static ListAdapter getListAdapter(Activity activity, String querys) {
201
202 return getListAdapter(activity, querys, null);
203 }
204
178 public static ListAdapter getListAdapter(Activity activity) {205 public static ListAdapter getListAdapter(Activity activity) {
179 206
180 return getListAdapter(activity, null);207 return getListAdapter(activity, null, null);
181 }208 }
182209
183 // gets the titles of the notes present in the db, used in ViewNote.buildLinkifyPattern()210 // gets the titles of the notes present in the db, used in ViewNote.buildLinkifyPattern()
@@ -236,3 +263,4 @@
236 return xmlContent;263 return xmlContent;
237 }264 }
238}265}
266
239267
=== modified file 'src/org/tomdroid/NoteProvider.java'
--- src/org/tomdroid/NoteProvider.java 2011-10-27 16:33:12 +0000
+++ src/org/tomdroid/NoteProvider.java 2012-04-01 04:35:23 +0000
@@ -51,22 +51,26 @@
51import android.database.sqlite.SQLiteOpenHelper;51import android.database.sqlite.SQLiteOpenHelper;
52import android.database.sqlite.SQLiteQueryBuilder;52import android.database.sqlite.SQLiteQueryBuilder;
53import android.net.Uri;53import android.net.Uri;
54import android.text.Html;
54import android.text.TextUtils;55import android.text.TextUtils;
55import org.tomdroid.ui.Tomdroid;56import org.tomdroid.ui.Tomdroid;
57import org.tomdroid.util.StringConverter;
56import org.tomdroid.util.TLog;58import org.tomdroid.util.TLog;
5759
60import java.util.ArrayList;
58import java.util.HashMap;61import java.util.HashMap;
62import java.util.Map;
59import java.util.UUID;63import java.util.UUID;
6064
61public class NoteProvider extends ContentProvider {65public class NoteProvider extends ContentProvider {
62 66
63 // ContentProvider stuff67 // ContentProvider stuff
64 // -- 68 // --
65 private static final String DATABASE_NAME = "tomdroid-notes.db";69 private static final String DATABASE_NAME = "tomdroid-notes.db";
66 private static final String DB_TABLE_NOTES = "notes";70 private static final String DB_TABLE_NOTES = "notes";
67 private static final int DB_VERSION = 3;71 private static final int DB_VERSION = 4;
68 private static final String DEFAULT_SORT_ORDER = Note.MODIFIED_DATE + " DESC";72 private static final String DEFAULT_SORT_ORDER = Note.MODIFIED_DATE + " DESC";
69 73
70 private static HashMap<String, String> notesProjectionMap;74 private static HashMap<String, String> notesProjectionMap;
7175
72 private static final int NOTES = 1;76 private static final int NOTES = 1;
@@ -77,6 +81,14 @@
77 81
78 // Logging info82 // Logging info
79 private static final String TAG = "NoteProvider";83 private static final String TAG = "NoteProvider";
84
85 // List of each version's columns
86 private static final String[][] COLUMNS_VERSION = {
87 { Note.TITLE, Note.FILE, Note.MODIFIED_DATE },
88 { Note.GUID, Note.TITLE, Note.FILE, Note.NOTE_CONTENT, Note.MODIFIED_DATE },
89 { Note.GUID, Note.TITLE, Note.FILE, Note.NOTE_CONTENT, Note.MODIFIED_DATE, Note.TAGS },
90 { Note.GUID, Note.TITLE, Note.FILE, Note.NOTE_CONTENT, Note.NOTE_CONTENT_PLAIN, Note.MODIFIED_DATE, Note.TAGS }
91 };
8092
81 /**93 /**
82 * This class helps open, create, and upgrade the database file.94 * This class helps open, create, and upgrade the database file.
@@ -89,12 +101,13 @@
89101
90 @Override102 @Override
91 public void onCreate(SQLiteDatabase db) {103 public void onCreate(SQLiteDatabase db) {
92 db.execSQL("CREATE TABLE " + DB_TABLE_NOTES + " ("104 db.execSQL("CREATE TABLE " + DB_TABLE_NOTES + " ("
93 + Note.ID + " INTEGER PRIMARY KEY,"105 + Note.ID + " INTEGER PRIMARY KEY,"
94 + Note.GUID + " TEXT,"106 + Note.GUID + " TEXT,"
95 + Note.TITLE + " TEXT,"107 + Note.TITLE + " TEXT,"
96 + Note.FILE + " TEXT,"108 + Note.FILE + " TEXT,"
97 + Note.NOTE_CONTENT + " TEXT,"109 + Note.NOTE_CONTENT + " TEXT,"
110 + Note.NOTE_CONTENT_PLAIN + " TEXT,"
98 + Note.MODIFIED_DATE + " STRING,"111 + Note.MODIFIED_DATE + " STRING,"
99 + Note.TAGS + " STRING"112 + Note.TAGS + " STRING"
100 + ");");113 + ");");
@@ -102,10 +115,51 @@
102115
103 @Override116 @Override
104 public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {117 public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
105 TLog.d(TAG, "Upgrading database from version {0} to {1}, which will destroy all old data",118 TLog.d(TAG, "Upgrading database from version {0} to {1}", oldVersion, newVersion);
106 oldVersion, newVersion);119
120 Cursor notesCursor;
121 ArrayList<Map<String, String>> db_list = new ArrayList<Map<String, String>>();
122 notesCursor = db.query(DB_TABLE_NOTES, COLUMNS_VERSION[oldVersion - 1], null, null, null, null, null);
123 notesCursor.moveToFirst();
124
125 if (oldVersion == 1) {
126 // GUID and NOTE_CONTENT are not saved.
127 TLog.d(TAG, "Database version {0} is not supported to update, all old datas will be destroyed", oldVersion);
128 db.execSQL("DROP TABLE IF EXISTS notes");
129 onCreate(db);
130 return;
131 }
132
133 // Get old datas from the SQL
134 while(!notesCursor.isAfterLast()) {
135 Map<String, String> row = new HashMap<String, String>();
136 for(int i = 0; i < COLUMNS_VERSION[oldVersion - 1].length; i++) {
137 row.put(COLUMNS_VERSION[oldVersion - 1][i], notesCursor.getString(i));
138 }
139
140 // create new columns
141 if (oldVersion <= 2) {
142 row.put(Note.TAGS, "");
143 }
144 if (oldVersion <= 3) {
145 row.put(Note.NOTE_CONTENT_PLAIN, StringConverter.encode(Html.fromHtml(row.get(Note.NOTE_CONTENT)).toString()));
146 }
147
148 db_list.add(row);
149 notesCursor.moveToNext();
150 }
151
107 db.execSQL("DROP TABLE IF EXISTS notes");152 db.execSQL("DROP TABLE IF EXISTS notes");
108 onCreate(db);153 onCreate(db);
154
155 // put rows to the database
156 ContentValues row = new ContentValues();
157 for(int i = 0; i < db_list.size(); i++) {
158 for(int j = 0; j < COLUMNS_VERSION[newVersion - 1].length; j++) {
159 row.put(COLUMNS_VERSION[newVersion - 1][j], db_list.get(i).get(COLUMNS_VERSION[newVersion - 1][j]));
160 }
161 db.insert(DB_TABLE_NOTES, null, row);
162 }
109 }163 }
110 }164 }
111165
@@ -135,11 +189,11 @@
135 break;189 break;
136 190
137 case NOTE_TITLE:191 case NOTE_TITLE:
138 qb.setTables(DB_TABLE_NOTES);192 qb.setTables(DB_TABLE_NOTES);
139 qb.setProjectionMap(notesProjectionMap);193 qb.setProjectionMap(notesProjectionMap);
140 // TODO appendWhere + whereArgs instead (new String[] whereArgs = uri.getLas..)?194 // TODO appendWhere + whereArgs instead (new String[] whereArgs = uri.getLas..)?
141 qb.appendWhere(Note.TITLE + " LIKE '" + uri.getLastPathSegment()+"'");195 qb.appendWhere(Note.TITLE + " LIKE '" + uri.getLastPathSegment()+"'");
142 break;196 break;
143197
144 default:198 default:
145 throw new IllegalArgumentException("Unknown URI " + uri);199 throw new IllegalArgumentException("Unknown URI " + uri);
@@ -173,7 +227,7 @@
173 return Tomdroid.CONTENT_ITEM_TYPE;227 return Tomdroid.CONTENT_ITEM_TYPE;
174 228
175 case NOTE_TITLE:229 case NOTE_TITLE:
176 return Tomdroid.CONTENT_ITEM_TYPE;230 return Tomdroid.CONTENT_ITEM_TYPE;
177231
178 default:232 default:
179 throw new IllegalArgumentException("Unknown URI " + uri);233 throw new IllegalArgumentException("Unknown URI " + uri);
@@ -205,7 +259,7 @@
205 259
206 // The guid is the unique identifier for a note so it has to be set.260 // The guid is the unique identifier for a note so it has to be set.
207 if (values.containsKey(Note.GUID) == false) {261 if (values.containsKey(Note.GUID) == false) {
208 values.put(Note.GUID, UUID.randomUUID().toString());262 values.put(Note.GUID, UUID.randomUUID().toString());
209 }263 }
210264
211 // TODO does this make sense?265 // TODO does this make sense?
@@ -291,6 +345,7 @@
291 notesProjectionMap.put(Note.TITLE, Note.TITLE);345 notesProjectionMap.put(Note.TITLE, Note.TITLE);
292 notesProjectionMap.put(Note.FILE, Note.FILE);346 notesProjectionMap.put(Note.FILE, Note.FILE);
293 notesProjectionMap.put(Note.NOTE_CONTENT, Note.NOTE_CONTENT);347 notesProjectionMap.put(Note.NOTE_CONTENT, Note.NOTE_CONTENT);
348 notesProjectionMap.put(Note.NOTE_CONTENT_PLAIN, Note.NOTE_CONTENT_PLAIN);
294 notesProjectionMap.put(Note.TAGS, Note.TAGS);349 notesProjectionMap.put(Note.TAGS, Note.TAGS);
295 notesProjectionMap.put(Note.MODIFIED_DATE, Note.MODIFIED_DATE);350 notesProjectionMap.put(Note.MODIFIED_DATE, Note.MODIFIED_DATE);
296 }351 }
297352
=== modified file 'src/org/tomdroid/sync/sd/NoteHandler.java'
--- src/org/tomdroid/sync/sd/NoteHandler.java 2011-09-05 15:05:46 +0000
+++ src/org/tomdroid/sync/sd/NoteHandler.java 2012-04-01 04:35:23 +0000
@@ -24,6 +24,7 @@
24package org.tomdroid.sync.sd;24package org.tomdroid.sync.sd;
2525
26import org.tomdroid.Note;26import org.tomdroid.Note;
27import org.tomdroid.util.StringConverter;
27import org.xml.sax.Attributes;28import org.xml.sax.Attributes;
28import org.xml.sax.SAXException;29import org.xml.sax.SAXException;
29import org.xml.sax.helpers.DefaultHandler;30import org.xml.sax.helpers.DefaultHandler;
@@ -35,15 +36,20 @@
35 // position keepers36 // position keepers
36 private boolean inTitleTag = false;37 private boolean inTitleTag = false;
37 private boolean inLastChangeDateTag = false;38 private boolean inLastChangeDateTag = false;
39 private boolean inTagTag = false;
38 40
39 // -- Tomboy's notes XML tags names --41 // -- Tomboy's notes XML tags names --
40 // Metadata related42 // Metadata related
41 private final static String TITLE = "title";43 private final static String TITLE = "title";
42 private final static String LAST_CHANGE_DATE = "last-change-date";44 private final static String LAST_CHANGE_DATE = "last-change-date";
45 private final static String TAGS = "tags";
46 private final static String TAG = "tag";
43 47
44 // Buffers for parsed elements48 // Buffers for parsed elements
45 private StringBuilder title = new StringBuilder();49 private StringBuilder title = new StringBuilder();
46 private StringBuilder lastChangeDate = new StringBuilder();50 private StringBuilder lastChangeDate = new StringBuilder();
51 private StringBuilder tags = new StringBuilder();
52 private StringBuilder tag;
47 53
48 // link to model 54 // link to model
49 private Note note;55 private Note note;
@@ -61,6 +67,9 @@
61 inTitleTag = true;67 inTitleTag = true;
62 } else if (localName.equals(LAST_CHANGE_DATE)) {68 } else if (localName.equals(LAST_CHANGE_DATE)) {
63 inLastChangeDateTag = true;69 inLastChangeDateTag = true;
70 } else if (localName.equals(TAG)) {
71 inTagTag = true;
72 tag = new StringBuilder();
64 }73 }
6574
66 }75 }
@@ -75,6 +84,12 @@
75 } else if (localName.equals(LAST_CHANGE_DATE)) {84 } else if (localName.equals(LAST_CHANGE_DATE)) {
76 inLastChangeDateTag = false;85 inLastChangeDateTag = false;
77 note.setLastChangeDate(lastChangeDate.toString());86 note.setLastChangeDate(lastChangeDate.toString());
87 } else if (localName.equals(TAGS)) {
88 note.setTags(tags.toString());
89 } else if (localName.equals(TAG)) {
90 inTagTag = false;
91 tags.append(StringConverter.encodeForTag(tag.toString()));
92 tags.append(",");
78 }93 }
79 }94 }
8095
@@ -86,6 +101,8 @@
86 title.append(ch, start, length);101 title.append(ch, start, length);
87 } else if (inLastChangeDateTag) {102 } else if (inLastChangeDateTag) {
88 lastChangeDate.append(ch, start, length);103 lastChangeDate.append(ch, start, length);
104 } else if (inTagTag) {
105 tag.append(ch, start, length);
89 }106 }
90 }107 }
91}108}
92109
=== added file 'src/org/tomdroid/util/StringConverter.java'
--- src/org/tomdroid/util/StringConverter.java 1970-01-01 00:00:00 +0000
+++ src/org/tomdroid/util/StringConverter.java 2012-04-01 04:35:23 +0000
@@ -0,0 +1,51 @@
1/*
2 * Tomdroid
3 * Tomboy on Android
4 * http://www.launchpad.net/tomdroid
5 *
6 * Copyright 2011 Koichi Akabe <vbkaisetsu@gmail.com>
7 *
8 * This file is part of Tomdroid.
9 *
10 * Tomdroid is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * Tomdroid is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with Tomdroid. If not, see <http://www.gnu.org/licenses/>.
22 */
23package org.tomdroid.util;
24
25public class StringConverter {
26 public static String encode(String text) {
27 return text.replace("&", "&amp;")
28 .replace("%", "&pct;")
29 .replace("_", "&und;");
30 }
31
32 public static String decode(String text) {
33 return text.replace("&und;", "_")
34 .replace("&pct;", "%")
35 .replace("&amp;", "&");
36 }
37
38 public static String encodeForTag(String text) {
39 return text.replace("&", "&amp;")
40 .replace("%", "&pct;")
41 .replace(",", "&com;")
42 .replace("_", "&und;");
43 }
44
45 public static String decodeForTag(String text) {
46 return text.replace("&und;", "_")
47 .replace("&com;", ",")
48 .replace("&pct;", "%")
49 .replace("&amp;", "&");
50 }
51}

Subscribers

People subscribed via source and target branches