|
|
|
@ -29,13 +29,13 @@ public class add_ymark {
|
|
|
|
|
final boolean isAuthUser = user!= null && user.hasRight(userDB.Entry.BOOKMARK_RIGHT);
|
|
|
|
|
|
|
|
|
|
if(isAdmin || isAuthUser) {
|
|
|
|
|
final String bmk_table = (isAuthUser ? user.getUserName() : "admin")+"_"+YMarkStatics.TABLE_BOOKMARKS_BASENAME;
|
|
|
|
|
final String tag_table = (isAuthUser ? user.getUserName() : "admin")+"_"+YMarkStatics.TABLE_TAGS_BASENAME;
|
|
|
|
|
final String bmk_table = (isAuthUser ? user.getUserName() : YMarkStatics.TABLE_BOOKMARKS_USER_ADMIN)+YMarkStatics.TABLE_BOOKMARKS_BASENAME;
|
|
|
|
|
final String tag_table = (isAuthUser ? user.getUserName() : YMarkStatics.TABLE_BOOKMARKS_USER_ADMIN)+YMarkStatics.TABLE_TAGS_BASENAME;
|
|
|
|
|
|
|
|
|
|
byte[] urlHash = null;
|
|
|
|
|
if(post.containsKey(YMarkStatics.TABLE_BOOKMARKS_COL_URL)) {
|
|
|
|
|
try {
|
|
|
|
|
urlHash = YMarkStatics.getBookmarkId(post.get(YMarkStatics.TABLE_BOOKMARKS_COL_URL,""));
|
|
|
|
|
urlHash = YMarkStatics.getBookmarkId(post.get(YMarkStatics.TABLE_BOOKMARKS_COL_URL,YMarkStatics.TABLE_BOOKMARKS_COL_DEFAULT));
|
|
|
|
|
} catch (MalformedURLException e) {
|
|
|
|
|
Log.logException(e);
|
|
|
|
|
}
|
|
|
|
@ -62,12 +62,12 @@ public class add_ymark {
|
|
|
|
|
if (bmk_row == null) {
|
|
|
|
|
// create and insert new entry
|
|
|
|
|
Data data = new Data();
|
|
|
|
|
final String tagsString = YMarkStatics.cleanTagsString(post.get(YMarkStatics.TABLE_BOOKMARKS_COL_TAGS,""));
|
|
|
|
|
final String tagsString = YMarkStatics.cleanTagsString(post.get(YMarkStatics.TABLE_BOOKMARKS_COL_TAGS,YMarkStatics.TABLE_BOOKMARKS_COL_DEFAULT));
|
|
|
|
|
final byte[] date = DateFormatter.formatShortMilliSecond(new Date()).getBytes();
|
|
|
|
|
|
|
|
|
|
data.put(YMarkStatics.TABLE_BOOKMARKS_COL_URL, post.get(YMarkStatics.TABLE_BOOKMARKS_COL_URL,"").getBytes());
|
|
|
|
|
data.put(YMarkStatics.TABLE_BOOKMARKS_COL_TITLE, post.get(YMarkStatics.TABLE_BOOKMARKS_COL_TITLE,"").getBytes());
|
|
|
|
|
data.put(YMarkStatics.TABLE_BOOKMARKS_COL_DESC, post.get(YMarkStatics.TABLE_BOOKMARKS_COL_DESC,"").getBytes());
|
|
|
|
|
data.put(YMarkStatics.TABLE_BOOKMARKS_COL_URL, post.get(YMarkStatics.TABLE_BOOKMARKS_COL_URL,YMarkStatics.TABLE_BOOKMARKS_COL_DEFAULT).getBytes());
|
|
|
|
|
data.put(YMarkStatics.TABLE_BOOKMARKS_COL_TITLE, post.get(YMarkStatics.TABLE_BOOKMARKS_COL_TITLE,YMarkStatics.TABLE_BOOKMARKS_COL_DEFAULT).getBytes());
|
|
|
|
|
data.put(YMarkStatics.TABLE_BOOKMARKS_COL_DESC, post.get(YMarkStatics.TABLE_BOOKMARKS_COL_DESC,YMarkStatics.TABLE_BOOKMARKS_COL_DEFAULT).getBytes());
|
|
|
|
|
data.put(YMarkStatics.TABLE_BOOKMARKS_COL_PUBLIC, post.get(YMarkStatics.TABLE_BOOKMARKS_COL_PUBLIC,"false").getBytes());
|
|
|
|
|
data.put(YMarkStatics.TABLE_BOOKMARKS_COL_TAGS, tagsString.getBytes());
|
|
|
|
|
data.put(YMarkStatics.TABLE_BOOKMARKS_COL_DATE_ADDED, date);
|
|
|
|
@ -76,20 +76,20 @@ public class add_ymark {
|
|
|
|
|
sb.tables.insert(bmk_table, urlHash, data);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final String[] tagArray = tagsString.split(",");
|
|
|
|
|
final String[] tagArray = tagsString.split(YMarkStatics.TABLE_TAGS_SEPARATOR);
|
|
|
|
|
for (final String tag : tagArray) {
|
|
|
|
|
updateTagTable(tag_table, tag, new String(urlHash), YMarkStatics.TABLE_TAGS_ACTION_ADD);
|
|
|
|
|
sb.tables.updateTAGTable(tag_table, tag, urlHash, YMarkStatics.TABLE_TAGS_ACTION_ADD);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
// modify and update existing entry
|
|
|
|
|
bmk_row.put(YMarkStatics.TABLE_BOOKMARKS_COL_TITLE, post.get(YMarkStatics.TABLE_BOOKMARKS_COL_TITLE,bmk_row.get(YMarkStatics.TABLE_BOOKMARKS_COL_TITLE,"")).getBytes());
|
|
|
|
|
bmk_row.put(YMarkStatics.TABLE_BOOKMARKS_COL_DESC, post.get(YMarkStatics.TABLE_BOOKMARKS_COL_DESC,bmk_row.get(YMarkStatics.TABLE_BOOKMARKS_COL_DESC,"")).getBytes());
|
|
|
|
|
bmk_row.put(YMarkStatics.TABLE_BOOKMARKS_COL_PUBLIC, post.get(YMarkStatics.TABLE_BOOKMARKS_COL_PUBLIC,bmk_row.get(YMarkStatics.TABLE_BOOKMARKS_COL_PUBLIC,"false")).getBytes());
|
|
|
|
|
bmk_row.put(YMarkStatics.TABLE_BOOKMARKS_COL_TITLE, post.get(YMarkStatics.TABLE_BOOKMARKS_COL_TITLE,bmk_row.get(YMarkStatics.TABLE_BOOKMARKS_COL_TITLE,YMarkStatics.TABLE_BOOKMARKS_COL_DEFAULT)).getBytes());
|
|
|
|
|
bmk_row.put(YMarkStatics.TABLE_BOOKMARKS_COL_DESC, post.get(YMarkStatics.TABLE_BOOKMARKS_COL_DESC,bmk_row.get(YMarkStatics.TABLE_BOOKMARKS_COL_DESC,YMarkStatics.TABLE_BOOKMARKS_COL_DEFAULT)).getBytes());
|
|
|
|
|
bmk_row.put(YMarkStatics.TABLE_BOOKMARKS_COL_PUBLIC, post.get(YMarkStatics.TABLE_BOOKMARKS_COL_PUBLIC,bmk_row.get(YMarkStatics.TABLE_BOOKMARKS_COL_PUBLIC,YMarkStatics.TABLE_BOOKMARKS_COL_PUBLIC_FALSE)).getBytes());
|
|
|
|
|
|
|
|
|
|
final String tagsString = YMarkStatics.cleanTagsString(post.get(YMarkStatics.TABLE_BOOKMARKS_COL_TAGS,""));
|
|
|
|
|
HashSet<String>old_tagSet = YMarkStatics.getTagSet(bmk_row.get(YMarkStatics.TABLE_BOOKMARKS_COL_TAGS,""), false);
|
|
|
|
|
final String tagsString = YMarkStatics.cleanTagsString(post.get(YMarkStatics.TABLE_BOOKMARKS_COL_TAGS,YMarkStatics.TABLE_BOOKMARKS_COL_DEFAULT));
|
|
|
|
|
HashSet<String>old_tagSet = YMarkStatics.getTagSet(bmk_row.get(YMarkStatics.TABLE_BOOKMARKS_COL_TAGS,YMarkStatics.TABLE_BOOKMARKS_COL_DEFAULT), false);
|
|
|
|
|
HashSet<String>new_tagSet = YMarkStatics.getTagSet(tagsString, false);
|
|
|
|
|
bmk_row.put(YMarkStatics.TABLE_BOOKMARKS_COL_TAGS, tagsString.getBytes());
|
|
|
|
|
|
|
|
|
@ -105,14 +105,14 @@ public class add_ymark {
|
|
|
|
|
new_tagSet.removeAll(old_tagSet);
|
|
|
|
|
tagIter = new_tagSet.iterator();
|
|
|
|
|
while(tagIter.hasNext()) {
|
|
|
|
|
updateTagTable(tag_table, tagIter.next(), new String(urlHash), YMarkStatics.TABLE_TAGS_ACTION_ADD);
|
|
|
|
|
sb.tables.updateTAGTable(tag_table, tagIter.next(), urlHash, YMarkStatics.TABLE_TAGS_ACTION_ADD);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
new_tagSet = YMarkStatics.getTagSet(tagsString, false);
|
|
|
|
|
old_tagSet.removeAll(new_tagSet);
|
|
|
|
|
tagIter=old_tagSet.iterator();
|
|
|
|
|
while(tagIter.hasNext()) {
|
|
|
|
|
updateTagTable(tag_table, tagIter.next(), new String(urlHash), YMarkStatics.TABLE_TAGS_ACTION_REMOVE);
|
|
|
|
|
sb.tables.updateTAGTable(tag_table, tagIter.next(), urlHash, YMarkStatics.TABLE_TAGS_ACTION_REMOVE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
@ -120,60 +120,9 @@ public class add_ymark {
|
|
|
|
|
}
|
|
|
|
|
prop.put("result", "1");
|
|
|
|
|
} else {
|
|
|
|
|
prop.put("AUTHENTICATE","Authentication required!");
|
|
|
|
|
prop.put(YMarkStatics.TABLE_BOOKMARKS_USER_AUTHENTICATE,YMarkStatics.TABLE_BOOKMARKS_USER_AUTHENTICATE_MSG);
|
|
|
|
|
}
|
|
|
|
|
// return rewrite properties
|
|
|
|
|
return prop;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static boolean updateTagTable(final String tag_table, final String tag, final String urlHash, final int action) {
|
|
|
|
|
Tables.Row tag_row = null;
|
|
|
|
|
final byte[] tagHash = YMarkStatics.getTagHash(tag);
|
|
|
|
|
HashSet<String>urlSet = new HashSet<String>();
|
|
|
|
|
try {
|
|
|
|
|
tag_row = sb.tables.select(tag_table, tagHash);
|
|
|
|
|
if(tag_row == null) {
|
|
|
|
|
switch (action) {
|
|
|
|
|
case YMarkStatics.TABLE_TAGS_ACTION_ADD:
|
|
|
|
|
urlSet.add(urlHash);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
Data tagEntry = new Data();
|
|
|
|
|
tagEntry.put(YMarkStatics.TABLE_TAGS_COL_TAG, tag.getBytes());
|
|
|
|
|
tagEntry.put(YMarkStatics.TABLE_TAGS_COL_URLS, YMarkStatics.keySetToBytes(urlSet));
|
|
|
|
|
sb.tables.insert(tag_table, tagHash, tagEntry);
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
urlSet = YMarkStatics.keysStringToKeySet(new String(tag_row.get(YMarkStatics.TABLE_TAGS_COL_URLS)));
|
|
|
|
|
if(urlSet.contains(urlHash))
|
|
|
|
|
Log.logInfo(YMarkStatics.TABLE_BOOKMARKS_LOG, "ok, urlHash found!");
|
|
|
|
|
switch (action) {
|
|
|
|
|
case YMarkStatics.TABLE_TAGS_ACTION_ADD:
|
|
|
|
|
urlSet.add(urlHash);
|
|
|
|
|
break;
|
|
|
|
|
case YMarkStatics.TABLE_TAGS_ACTION_REMOVE:
|
|
|
|
|
urlSet.remove(urlHash);
|
|
|
|
|
if(urlSet.isEmpty()) {
|
|
|
|
|
sb.tables.delete(tag_table, tagHash);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
tag_row.put(YMarkStatics.TABLE_TAGS_COL_URLS, YMarkStatics.keySetToBytes(urlSet));
|
|
|
|
|
sb.tables.update(tag_table, tag_row);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
Log.logException(e);
|
|
|
|
|
} catch (RowSpaceExceededException e) {
|
|
|
|
|
Log.logException(e);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|