From 25339f93c77c9c14fd37272afc5db873e80e4770 Mon Sep 17 00:00:00 2001 From: apfelmaennchen Date: Tue, 9 Nov 2010 17:01:31 +0000 Subject: [PATCH] more updates to ymarks - working xbel import/export - exported xbel includes yacy specific metadata but still validates against PUBLIC DTD git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7315 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- htroot/api/ymarks/get_treeview.java | 11 +- htroot/api/ymarks/get_xbel.java | 178 +++++++++++------- htroot/api/ymarks/get_xbel.xml | 18 +- htroot/api/ymarks/import_ymark.java | 16 ++ htroot/api/ymarks/info.html | 9 +- htroot/api/ymarks/test_import.html | 2 +- source/de/anomic/data/YMarkIndex.java | 8 - source/de/anomic/data/YMarkTables.java | 47 +++-- source/de/anomic/data/YMarksXBELImporter.java | 165 ++++++++++------ 9 files changed, 289 insertions(+), 165 deletions(-) diff --git a/htroot/api/ymarks/get_treeview.java b/htroot/api/ymarks/get_treeview.java index 1c36a9f88..de1a27a07 100644 --- a/htroot/api/ymarks/get_treeview.java +++ b/htroot/api/ymarks/get_treeview.java @@ -122,10 +122,13 @@ public class get_treeview { while(it.hasNext()) { final String key = it.next(); if(key.startsWith("date")) { - final String date = DateFormatter.formatISO8601(new Date(Long.parseLong(new String(bmk_row.get(key))))); - prop.put("folders_"+count+"_foldername",""+key+": " + date + ""); - putProp(count, "date"); - count++; + final String d = new String(bmk_row.get(key)); + if(!d.isEmpty()) { + final String date = DateFormatter.formatISO8601(new Date(Long.parseLong(d))); + prop.put("folders_"+count+"_foldername",""+key+": " + date + ""); + putProp(count, "date"); + count++; + } } else { final String value = new String(bmk_row.get(key)); prop.put("folders_"+count+"_foldername",""+key+": " + value + ""); diff --git a/htroot/api/ymarks/get_xbel.java b/htroot/api/ymarks/get_xbel.java index ae5405238..54ca1ae1b 100644 --- a/htroot/api/ymarks/get_xbel.java +++ b/htroot/api/ymarks/get_xbel.java @@ -1,4 +1,5 @@ import java.io.IOException; +import java.util.HashSet; import java.util.Iterator; import net.yacy.cora.protocol.RequestHeader; @@ -6,8 +7,8 @@ import net.yacy.document.parser.html.CharacterCoding; import net.yacy.kelondro.blob.Tables; import net.yacy.kelondro.index.RowSpaceExceededException; import net.yacy.kelondro.logging.Log; -import de.anomic.data.YMarkIndex; import de.anomic.data.YMarkTables; +import de.anomic.data.YMarksXBELImporter; import de.anomic.data.userDB; import de.anomic.search.Switchboard; import de.anomic.server.serverObjects; @@ -16,24 +17,24 @@ import de.anomic.server.serverSwitch; public class get_xbel { public static final String ROOT = "root"; public static final String SOURCE = "source"; - - static Switchboard sb; - static serverObjects prop; - static String bmk_user; - + public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) { - sb = (Switchboard) env; - prop = new serverObjects(); - final userDB.Entry user = sb.userDB.getUser(header); + final Switchboard sb = (Switchboard) env; + final serverObjects prop = new serverObjects(); + final HashSet alias = new HashSet(); + final StringBuilder buffer = new StringBuilder(250); + final userDB.Entry user = sb.userDB.getUser(header); final boolean isAdmin = (sb.verifyAuthentication(header, true)); final boolean isAuthUser = user!= null && user.hasRight(userDB.Entry.BOOKMARK_RIGHT); + final String bmk_user; if(isAdmin || isAuthUser) { bmk_user = (isAuthUser ? user.getUserName() : YMarkTables.USER_ADMIN); String root = YMarkTables.FOLDERS_ROOT; String[] foldername = null; - + + // TODO: better handling of query if (post != null){ if (post.containsKey(ROOT)) { if (post.get(ROOT).equals(SOURCE) || post.get(ROOT).equals(YMarkTables.FOLDERS_ROOT)) { @@ -41,38 +42,111 @@ public class get_xbel { } else if (post.get(ROOT).startsWith(YMarkTables.FOLDERS_ROOT)) { root = post.get(ROOT); } else { - root = ""; - // root = YMarkTables.FOLDERS_ROOT + post.get(ROOT); + root = ""; } } + } else { + root = ""; } - Iterator it = null; - int count = 0; - int n = YMarkIndex.getFolderDepth(root); + final int root_depth = root.split(YMarkTables.FOLDERS_SEPARATOR).length; + Iterator fit = null; + Iterator bit = null; + int count = 0; + int n = root_depth; try { - it = sb.tables.bookmarks.folders.getFolders(bmk_user, root); + fit = sb.tables.bookmarks.folders.getFolders(bmk_user, root); } catch (IOException e) { Log.logException(e); } - while (it.hasNext()) { - String folder = it.next(); - foldername = folder.split(YMarkTables.FOLDERS_SEPARATOR); - Log.logInfo(YMarkTables.BOOKMARKS_LOG, "folder: "+folder+" getFolderDepth(folder): "+YMarkIndex.getFolderDepth(folder)+" n: "+n); - if (count > 0 && YMarkIndex.getFolderDepth(folder) <= n) { + Log.logInfo(YMarkTables.BOOKMARKS_LOG, "root: "+root+" root_deph: "+root_depth); + + while (fit.hasNext()) { + String folder = fit.next(); + foldername = folder.split(YMarkTables.FOLDERS_SEPARATOR); + Log.logInfo(YMarkTables.BOOKMARKS_LOG, "folder: "+folder+" n: "+n+" folder_length: "+foldername.length); + if (n != root_depth && foldername.length <= n) { prop.put("xbel_"+count+"_elements", ""); count++; - } - if (YMarkIndex.getFolderDepth(folder) >= n) { - n = YMarkIndex.getFolderDepth(folder); - prop.put("xbel_"+count+"_elements", ""); - count++; - prop.put("xbel_"+count+"_elements", "" + CharacterCoding.unicode2xml(foldername[n], true) + ""); - count++; + } + if (foldername.length >= n) { + n = foldername.length; + if(n != root_depth) { + prop.put("xbel_"+count+"_elements", ""); + count++; + prop.put("xbel_"+count+"_elements", "" + CharacterCoding.unicode2xml(foldername[n-1], true) + ""); + count++; + } try { - count = putBookmarks(folder, count); + bit = sb.tables.bookmarks.folders.getBookmarks(bmk_user, folder).iterator(); + Tables.Row bmk_row = null; + String urlHash; + while(bit.hasNext()){ + urlHash = new String(bit.next()); + if(alias.contains(urlHash)) { + buffer.setLength(0); + buffer.append(YMarksXBELImporter.XBEL.ALIAS.startTag(true)); + buffer.append(" ref=\"b:"); + buffer.append(urlHash); + buffer.append("\"/>"); + prop.put("xbel_"+count+"_elements", buffer.toString()); + count++; + } else { + alias.add(urlHash); + bmk_row = sb.tables.select(YMarkTables.TABLES.BOOKMARKS.tablename(bmk_user), urlHash.getBytes()); + if(bmk_row != null) { + buffer.setLength(0); + + buffer.append(YMarksXBELImporter.XBEL.BOOKMARK.startTag(true)); + buffer.append(" id=\"b:"); + buffer.append(urlHash); + + buffer.append(YMarkTables.BOOKMARK.URL.xbel()); + buffer.append(CharacterCoding.unicode2xml(bmk_row.get(YMarkTables.BOOKMARK.URL.key(), YMarkTables.BOOKMARK.URL.deflt()), true)); + + buffer.append(YMarkTables.BOOKMARK.DATE_ADDED.xbel()); + buffer.append(CharacterCoding.unicode2xml(YMarkTables.getISO8601(bmk_row.get(YMarkTables.BOOKMARK.DATE_ADDED.key())), true)); + + buffer.append(YMarkTables.BOOKMARK.DATE_MODIFIED.xbel()); + buffer.append(CharacterCoding.unicode2xml(YMarkTables.getISO8601(bmk_row.get(YMarkTables.BOOKMARK.DATE_MODIFIED.key())), true)); + + buffer.append(YMarkTables.BOOKMARK.DATE_VISITED.xbel()); + buffer.append(CharacterCoding.unicode2xml(YMarkTables.getISO8601(bmk_row.get(YMarkTables.BOOKMARK.DATE_VISITED.key())), true)); + + buffer.append(YMarkTables.BOOKMARK.TAGS.xbel()); + buffer.append(bmk_row.get(YMarkTables.BOOKMARK.TAGS.key(), YMarkTables.BOOKMARK.TAGS.deflt())); + + buffer.append(YMarkTables.BOOKMARK.PUBLIC.xbel()); + buffer.append(bmk_row.get(YMarkTables.BOOKMARK.PUBLIC.key(), YMarkTables.BOOKMARK.PUBLIC.deflt())); + + buffer.append(YMarkTables.BOOKMARK.VISITS.xbel()); + buffer.append(bmk_row.get(YMarkTables.BOOKMARK.VISITS.key(), YMarkTables.BOOKMARK.VISITS.deflt())); + + buffer.append("\"\n>"); + prop.put("xbel_"+count+"_elements", buffer.toString()); + count++; + + buffer.setLength(0); + buffer.append(YMarksXBELImporter.XBEL.TITLE.startTag(false)); + buffer.append(CharacterCoding.unicode2xml(bmk_row.get(YMarkTables.BOOKMARK.TITLE.key(), YMarkTables.BOOKMARK.TITLE.deflt()), true)); + buffer.append(YMarksXBELImporter.XBEL.TITLE.endTag(false)); + prop.put("xbel_"+count+"_elements", buffer.toString()); + count++; + + buffer.setLength(0); + buffer.append(YMarksXBELImporter.XBEL.DESC.startTag(false)); + buffer.append(CharacterCoding.unicode2xml(bmk_row.get(YMarkTables.BOOKMARK.DESC.key(), YMarkTables.BOOKMARK.DESC.deflt()), true)); + buffer.append(YMarksXBELImporter.XBEL.DESC.endTag(false)); + prop.put("xbel_"+count+"_elements", buffer.toString()); + count++; + + prop.put("xbel_"+count+"_elements", YMarksXBELImporter.XBEL.BOOKMARK.endTag(false)); + count++; + } + } + } } catch (IOException e) { Log.logException(e); continue; @@ -82,54 +156,20 @@ public class get_xbel { } } } - while(n >= YMarkIndex.getFolderDepth(root)) { - prop.put("xbel_"+count+"_elements", ""); + while(n > root_depth) { + prop.put("xbel_"+count+"_elements", YMarksXBELImporter.XBEL.FOLDER.endTag(false)); count++; n--; } + prop.put("user", bmk_user.substring(0,1).toUpperCase() + bmk_user.substring(1)); prop.put("xbel", count); + } else { prop.put(YMarkTables.USER_AUTHENTICATE,YMarkTables.USER_AUTHENTICATE_MSG); } // return rewrite properties return prop; } - public static int putBookmarks(final String folder, int count) throws IOException, RowSpaceExceededException { - final Iterator bit = sb.tables.bookmarks.folders.getBookmarks(bmk_user, folder).iterator(); - Tables.Row bmk_row = null; - String urlHash; - while(bit.hasNext()){ - urlHash = new String(bit.next()); - bmk_row = sb.tables.select(YMarkTables.TABLES.BOOKMARKS.tablename(bmk_user), urlHash.getBytes()); - if(bmk_row != null) { - prop.put("xbel_"+count+"_elements", ""); - count++; - prop.put("xbel_"+count+"_elements", "" - + CharacterCoding.unicode2xml(bmk_row.get(YMarkTables.BOOKMARK.TITLE.key(), YMarkTables.BOOKMARK.TITLE.deflt()), true) - + ""); - count++; - prop.put("xbel_"+count+"_elements", ""); - count++; - prop.put("xbel_"+count+"_elements", ""); - count++; - prop.put("xbel_"+count+"_elements", ""); - count++; - prop.put("xbel_"+count+"_elements", "" - + CharacterCoding.unicode2xml(bmk_row.get(YMarkTables.BOOKMARK.DESC.key(), YMarkTables.BOOKMARK.DESC.deflt()), true) - + ""); - count++; - prop.put("xbel_"+count+"_elements", ""); - count++; - } - } - return count; - } } + + diff --git a/htroot/api/ymarks/get_xbel.xml b/htroot/api/ymarks/get_xbel.xml index 69b9a7b45..de53be37e 100644 --- a/htroot/api/ymarks/get_xbel.xml +++ b/htroot/api/ymarks/get_xbel.xml @@ -1,8 +1,14 @@ - -#(style)#::#(/style)# - - #{xbel}# - #[elements]# - #{/xbel}# + +]> + +#[user]# YaCy Bookmarks + + + +#{xbel}# +#[elements]# +#{/xbel}# \ No newline at end of file diff --git a/htroot/api/ymarks/import_ymark.java b/htroot/api/ymarks/import_ymark.java index 9750bc5e4..f4f6225b1 100644 --- a/htroot/api/ymarks/import_ymark.java +++ b/htroot/api/ymarks/import_ymark.java @@ -2,6 +2,7 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.util.HashMap; +import java.util.Iterator; import org.xml.sax.SAXException; @@ -82,6 +83,21 @@ public class import_ymark { prop.put("result", "0"); return prop; } + } + // update bookmarks with aliases + final Iterator> it = xbelImporter.getAliases().iterator(); + while (it.hasNext()) { + try { + sb.tables.bookmarks.addBookmark(bmk_user, it.next(), true); + } catch (IOException e) { + Log.logWarning(YMarkTables.BOOKMARKS_LOG.toString(), "XBEL Importer - IOException for URL: "+bmk.get(YMarkTables.BOOKMARK.URL.key())); + continue; + } catch (RowSpaceExceededException e) { + //TODO: display an error message + Log.logException(e); + prop.put("result", "0"); + return prop; + } } prop.put("result", "1"); } diff --git a/htroot/api/ymarks/info.html b/htroot/api/ymarks/info.html index 4b5cf8747..ab21b4e2c 100644 --- a/htroot/api/ymarks/info.html +++ b/htroot/api/ymarks/info.html @@ -33,11 +33,16 @@
  • get_treeview.[xml | json]
      -
    • root:
    • +
    • root: the folder to display
    • bmtype:
  • -
  • get_xbel
  • +
  • get_xml +
      +
    • root: the root folder to start export from
    • +
    • type: xbel | rss | rdf
    • +
    +
  • import_ymark.xml
    • bmfile: the bookmark file you want to import diff --git a/htroot/api/ymarks/test_import.html b/htroot/api/ymarks/test_import.html index c61daa25a..5d3b2bbaa 100644 --- a/htroot/api/ymarks/test_import.html +++ b/htroot/api/ymarks/test_import.html @@ -4,7 +4,7 @@ YaCy Bookmarks -
      +
      Import Bookmarks
      diff --git a/source/de/anomic/data/YMarkIndex.java b/source/de/anomic/data/YMarkIndex.java index 486c69089..52db17983 100644 --- a/source/de/anomic/data/YMarkIndex.java +++ b/source/de/anomic/data/YMarkIndex.java @@ -60,14 +60,6 @@ public class YMarkIndex { return new String(row.get(INDEX.NAME.key(), INDEX.NAME.deflt())); } - public static int getFolderDepth(String folder) { - final int depth = folder.split(YMarkTables.FOLDERS_SEPARATOR).length -1; - if (depth < 0) - return 0; - else - return depth; - } - public Iterator getFolders(final String user, final String root) throws IOException { final String index_table = user + this.table_basename; final TreeSet folders = new TreeSet(); diff --git a/source/de/anomic/data/YMarkTables.java b/source/de/anomic/data/YMarkTables.java index 97901067b..e282986c0 100644 --- a/source/de/anomic/data/YMarkTables.java +++ b/source/de/anomic/data/YMarkTables.java @@ -16,7 +16,6 @@ import net.yacy.kelondro.blob.Tables.Data; import net.yacy.kelondro.data.meta.DigestURI; import net.yacy.kelondro.data.word.Word; import net.yacy.kelondro.index.RowSpaceExceededException; -import net.yacy.kelondro.logging.Log; import net.yacy.kelondro.util.DateFormatter; public class YMarkTables { @@ -57,15 +56,16 @@ public class YMarkTables { } public static enum BOOKMARK { + // key dflt html_attrb xbel_attrb type URL ("url", "", "href", "href", "link"), TITLE ("title", "", "", "", "meta"), DESC ("desc", "", "", "", "comment"), DATE_ADDED ("date_added", "", "add_date", "added", "date"), DATE_MODIFIED ("date_modified", "", "last_modified", "modified", "date"), DATE_VISITED ("date_visited", "", "last_visited", "visited", "date"), - PUBLIC ("public", "flase", "", "", "lock"), - TAGS ("tags", "unsorted", "shortcuturl", "", "tag"), - VISITS ("visits", "0", "", "", "stat"), + PUBLIC ("public", "flase", "", "yacy:public", "lock"), + TAGS ("tags", "unsorted", "shortcuturl", "yacy:tags", "tag"), + VISITS ("visits", "0", "", "yacy:visits", "stat"), FOLDERS ("folders", "/unsorted", "", "", "folder"); private String key; @@ -80,6 +80,8 @@ public class YMarkTables { lookup.put(b.key(), b); } + private static StringBuilder buffer = new StringBuilder(25);; + private BOOKMARK(String k, String s, String a, String x, String t) { this.key = k; this.dflt = s; @@ -105,6 +107,16 @@ public class YMarkTables { public String xbel_attrb() { return this.xbel_attrb; } + public String xbel() { + buffer.setLength(0); + buffer.append('"'); + buffer.append('\n'); + buffer.append(' '); + buffer.append(this.xbel_attrb); + buffer.append('='); + buffer.append('"'); + return buffer.toString(); + } public String type() { return this.type; } @@ -117,7 +129,7 @@ public class YMarkTables { public final static String FOLDERS_SEPARATOR = "/"; public final static String FOLDERS_ROOT = "/"; public final static String FOLDERS_UNSORTED = "/unsorted"; - public final static String FOLDERS_IMPORTED = "/imported"; + public final static String FOLDERS_IMPORTED = ""; public static final int FOLDER_BUFFER_SIZE = 100; public final static String BOOKMARKS_LOG = "BOOKMARKS"; @@ -138,17 +150,22 @@ public class YMarkTables { } public static Date parseISO8601(final String s) throws ParseException { - if(s == null) - throw new ParseException("parseISO8601 - NPE", 0); StringBuilder date = new StringBuilder(s); - SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz"); - if(date.charAt(date.length()) == 'Z') { - date.deleteCharAt(date.length()); - date.append("GMT-00:00"); - } else { - date.insert(date.length()-6, "GMT"); - } - Log.logInfo(YMarkTables.BOOKMARKS_LOG, "ISO8601: "+s+" =? "+dateformat.toString()); + SimpleDateFormat dateformat; + if(s == null || s.isEmpty()) { + throw new ParseException("parseISO8601 - empty string, nothing to parse", 0); + } + if(s.length()==10) + dateformat = new SimpleDateFormat("yyyy-MM-dd"); + else { + dateformat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz"); + if(date.charAt(date.length()-1) == 'Z') { + date.deleteCharAt(date.length()-1); + date.append("GMT-00:00"); + } else { + date.insert(date.length()-6, "GMT"); + } + } return dateformat.parse(date.toString()); } diff --git a/source/de/anomic/data/YMarksXBELImporter.java b/source/de/anomic/data/YMarksXBELImporter.java index 722e20f3f..87413e926 100644 --- a/source/de/anomic/data/YMarksXBELImporter.java +++ b/source/de/anomic/data/YMarksXBELImporter.java @@ -4,71 +4,99 @@ import java.io.IOException; import java.io.InputStream; import java.text.ParseException; import java.util.HashMap; +import java.util.HashSet; import java.util.concurrent.ArrayBlockingQueue; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; - import net.yacy.kelondro.logging.Log; import org.xml.sax.Attributes; +import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; +import org.xml.sax.XMLReader; import org.xml.sax.helpers.DefaultHandler; +import org.xml.sax.helpers.XMLReaderFactory; public class YMarksXBELImporter extends DefaultHandler implements Runnable { public static enum XBEL { - NOTHING, - XBEL, - TITLE, - DESC, - BOOKMARK, - FOLDER, - SEPARATOR, - ALIAS, - INFO, - METADATA; + NOTHING (""), + XBEL ("'); + return buffer.toString(); + } + public String startTag(boolean att) { + buffer.setLength(0); + buffer.append(tag); + if(!att) + buffer.append('>'); + return buffer.toString(); + } } - + + private HashMap ref; private HashMap bmk; private XBEL outer_state; // BOOKMARK, FOLDER, NOTHING private XBEL inner_state; // DESC, TITLE, INFO, ALIAS, (METADATA), NOTHING private boolean parse_value; + + private final HashMap> bmkRef; + private final HashSet> aliasRef; private final StringBuilder buffer; private final StringBuilder folder; - - private final InputStream input; + private final StringBuilder foldersString; + private final InputSource input; private final ArrayBlockingQueue> bookmarks; - private final SAXParser saxParser; - + private final XMLReader xmlReader; public YMarksXBELImporter (final InputStream input, int queueSize) throws SAXException { - this.bmk = null; - this.buffer = new StringBuilder(); - this.folder = new StringBuilder(YMarkTables.FOLDER_BUFFER_SIZE); + this.bmk = null; + this.buffer = new StringBuilder(); + this.foldersString = new StringBuilder(YMarkTables.FOLDER_BUFFER_SIZE); + this.folder = new StringBuilder(YMarkTables.FOLDER_BUFFER_SIZE); this.folder.append(YMarkTables.FOLDERS_IMPORTED); - this.bookmarks = new ArrayBlockingQueue>(queueSize); - this.input = input; - final SAXParserFactory factory = SAXParserFactory.newInstance(); - try { - this.saxParser = factory.newSAXParser(); - } catch (ParserConfigurationException e) { - Log.logException(e); - throw new SAXException (e.getMessage()); - } + this.bmkRef = new HashMap>(); + this.aliasRef = new HashSet>(); + this.bookmarks = new ArrayBlockingQueue>(queueSize); + this.input = new InputSource(input); + this.xmlReader = XMLReaderFactory.createXMLReader(); + this.xmlReader.setContentHandler(this); + this.xmlReader.setFeature("http://xml.org/sax/features/namespace-prefixes", false); + this.xmlReader.setFeature("http://xml.org/sax/features/namespaces", false); + this.xmlReader.setFeature("http://xml.org/sax/features/validation", false); } public void run() { - try { - this.saxParser.parse(this.input, this); + try { + this.xmlReader.parse(this.input); } catch (SAXParseException e) { - Log.logException(e); + Log.logException(e); } catch (SAXException e) { Log.logException(e); } catch (IOException e) { @@ -79,38 +107,41 @@ public class YMarksXBELImporter extends DefaultHandler implements Runnable { } catch (InterruptedException e1) { Log.logException(e1); } - try { - this.input.close(); - } catch (IOException e) { - Log.logException(e); - } } } + public void endDocument() throws SAXException { + // no need to keep the bookmark references any longer + // this.bmkRef.clear(); + } + public void startElement(final String uri, final String name, String tag, final Attributes atts) throws SAXException { String date; - if (tag == null) return; + if (tag == null) return; tag = tag.toLowerCase(); if (XBEL.BOOKMARK.tag().equals(tag)) { - this.bmk = new HashMap(); + this.bmk = new HashMap(); this.bmk.put(YMarkTables.BOOKMARK.URL.key(), atts.getValue(uri, YMarkTables.BOOKMARK.URL.xbel_attrb())); try { - date = String.valueOf(YMarkTables.parseISO8601(atts.getValue(uri, YMarkTables.BOOKMARK.DATE_ADDED.xbel_attrb()))); + date = String.valueOf(YMarkTables.parseISO8601(atts.getValue(uri, YMarkTables.BOOKMARK.DATE_ADDED.xbel_attrb())).getTime()); } catch (ParseException e) { date = String.valueOf(System.currentTimeMillis()); } this.bmk.put(YMarkTables.BOOKMARK.DATE_ADDED.key(), date); try { - date = String.valueOf(YMarkTables.parseISO8601(atts.getValue(uri, YMarkTables.BOOKMARK.DATE_VISITED.xbel_attrb()))); - this.bmk.put(YMarkTables.BOOKMARK.DATE_VISITED.key(), date); + date = String.valueOf(YMarkTables.parseISO8601(atts.getValue(uri, YMarkTables.BOOKMARK.DATE_VISITED.xbel_attrb())).getTime()); } catch (ParseException e) { - } + date = YMarkTables.BOOKMARK.DATE_VISITED.deflt(); + } + this.bmk.put(YMarkTables.BOOKMARK.DATE_VISITED.key(), date); try { - date = String.valueOf(YMarkTables.parseISO8601(atts.getValue(uri, YMarkTables.BOOKMARK.DATE_MODIFIED.xbel_attrb()))); + date = String.valueOf(YMarkTables.parseISO8601(atts.getValue(uri, YMarkTables.BOOKMARK.DATE_MODIFIED.xbel_attrb())).getTime()); } catch (ParseException e) { date = String.valueOf(System.currentTimeMillis()); } this.bmk.put(YMarkTables.BOOKMARK.DATE_MODIFIED.key(), date); + + UpdateBmkRef(atts.getValue(uri, "id"), true); outer_state = XBEL.BOOKMARK; inner_state = XBEL.NOTHING; this.parse_value = false; @@ -128,24 +159,19 @@ public class YMarksXBELImporter extends DefaultHandler implements Runnable { this.parse_value = false; } else if (XBEL.METADATA.tag().equals(tag)) { /* - this.meta_owner = atts.getValue(uri, "owner"); - this.inner_state = XBEL.METADATA; - this.parse_value = true; + atts.getValue(uri, "owner"); */ } else if (XBEL.ALIAS.tag().equals(tag)) { - // TODO: handle xbel aliases - /* - this.alias_ref = atts.getValue(uri, "ref"); - this.inner_state = XBEL.ALIAS; - this.parse_value = false; - */ + Log.logInfo(YMarkTables.BOOKMARKS_LOG, "ALIAS: "+this.ref.get(YMarkTables.BOOKMARK.URL.key())); + final String r = atts.getValue(uri, "ref"); + UpdateBmkRef(r, false); + this.aliasRef.add(this.bmkRef.get(r)); } else { this.outer_state = XBEL.NOTHING; this.inner_state = XBEL.NOTHING; this.parse_value = false; } - } public void endElement(final String uri, final String name, String tag) { @@ -153,8 +179,8 @@ public class YMarksXBELImporter extends DefaultHandler implements Runnable { tag = tag.toLowerCase(); if(XBEL.BOOKMARK.tag().equals(tag)) { // write bookmark - if (!this.bmk.isEmpty()) { - this.bmk.put(YMarkTables.BOOKMARK.FOLDERS.key(), this.folder.toString()); + if (!this.bmk.isEmpty()) { + this.bmk.put(YMarkTables.BOOKMARK.FOLDERS.key(), this.folder.toString()); try { this.bookmarks.put(this.bmk); bmk = new HashMap(); @@ -191,7 +217,6 @@ public class YMarksXBELImporter extends DefaultHandler implements Runnable { break; case METADATA: // TODO: handle xbel bookmark metadata - // this.meta_data = this.buffer.toString(); break; default: break; @@ -207,7 +232,6 @@ public class YMarksXBELImporter extends DefaultHandler implements Runnable { break; case METADATA: // TODO: handle xbel folder metadata - // this.meta_data = this.buffer.toString(); break; default: break; @@ -229,4 +253,25 @@ public class YMarksXBELImporter extends DefaultHandler implements Runnable { return null; } } + + public HashSet> getAliases() { + return this.aliasRef; + } + + private void UpdateBmkRef(final String id, final boolean url) { + this.foldersString.setLength(0); + + if(this.bmkRef.containsKey(id)) { + this.foldersString.append(this.bmkRef.get(id).get(YMarkTables.BOOKMARK.FOLDERS.key())); + this.foldersString.append(','); + this.ref = this.bmkRef.get(id); + } else { + this.ref = new HashMap(); + } + this.foldersString.append(this.folder); + if(url) + this.ref.put(YMarkTables.BOOKMARK.URL.key(), this.bmk.get(YMarkTables.BOOKMARK.URL.key())); + this.ref.put(YMarkTables.BOOKMARK.FOLDERS.key(), this.foldersString.toString()); + this.bmkRef.put(id, ref); + } }