XML import works.

Please backup your bookmarks.db before trying it, i had many kelondro errors while importing del.icio.us xml-Files

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@1620 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
allo 19 years ago
parent a4513523d6
commit fb5c387368

@ -44,7 +44,7 @@
<option value="private" #(public)#selected::#(/public)#>no</option> <option value="private" #(public)#selected::#(/public)#>no</option>
</select> </select>
</td> </td>
</tr> </tr>
<tr> <tr>
<td colspan="2" colspan="2" valign="top" class="TableHeader" width="100%"> <td colspan="2" colspan="2" valign="top" class="TableHeader" width="100%">
#(edit)# #(edit)#
@ -66,6 +66,14 @@
<td valign="top" class="TableCellDark">File:</td> <td valign="top" class="TableCellDark">File:</td>
<td valign="top" class="TableCellLight" width="100%"><input type="file" name="xmlfile"></td> <td valign="top" class="TableCellLight" width="100%"><input type="file" name="xmlfile"></td>
</tr> </tr>
<tr>
<td valign="top" class="TableCellDark">import as Public:</td>
<td valign="top" class="TableCellLight"><select name="public">
<option value="public">yes</option>
<option value="private">no</option>
</select>
</td>
</tr>
<tr> <tr>
<td colspan="2" colspan="2" valign="top" class="TableHeader" width="100%"> <td colspan="2" colspan="2" valign="top" class="TableHeader" width="100%">
<input type="submit" name="importxml" value="import"> <input type="submit" name="importxml" value="import">
@ -82,7 +90,7 @@
<td><h3>Tags</h3></td> <td><h3>Tags</h3></td>
</tr> </tr>
<tr> <tr>
<td width="100%"> <td width="100%" valign="top">
#{bookmarks}# #{bookmarks}#
<p style="border-bottom:1px #000 dashed; padding-bottom: 1em;"> <p style="border-bottom:1px #000 dashed; padding-bottom: 1em;">
#(public)#<img class="bookmarkIcon" src="env/grafics/bookmarkpriv.gif" alt="private">::<img class="bookmarkIcon" src="env/grafics/bookmarkpub.gif" alt="public">#(/public)# #(public)#<img class="bookmarkIcon" src="env/grafics/bookmarkpriv.gif" alt="private">::<img class="bookmarkIcon" src="env/grafics/bookmarkpub.gif" alt="public">#(/public)#

@ -100,7 +100,11 @@ public class Bookmarks_p {
if(bookmark != null){ if(bookmark != null){
bookmark.setProperty(bookmarksDB.Bookmark.BOOKMARK_TITLE, title); bookmark.setProperty(bookmarksDB.Bookmark.BOOKMARK_TITLE, title);
bookmark.setProperty(bookmarksDB.Bookmark.BOOKMARK_DESCRIPTION, description); bookmark.setProperty(bookmarksDB.Bookmark.BOOKMARK_DESCRIPTION, description);
bookmark.setProperty(bookmarksDB.Bookmark.BOOKMARK_PUBLIC, (String) post.get("public")); if(((String) post.get("public")).equals("public")){
bookmark.setPublic(true);
}else{
bookmark.setPublic(false);
}
bookmark.setTags(tags); bookmark.setTags(tags);
bookmark.setBookmarksTable(); bookmark.setBookmarksTable();
}else{ }else{
@ -145,9 +149,12 @@ public class Bookmarks_p {
} }
} }
} }
} }else if(post.containsKey("xmlfile")){
if(post.containsKey("xmlfile")){ boolean isPublic=false;
switchboard.bookmarksDB.importFromXML(new String((byte[])post.get("xmlfile$file"))); if(((String) post.get("public")).equals("public")){
isPublic=true;
}
switchboard.bookmarksDB.importFromXML(new String((byte[])post.get("xmlfile$file")), isPublic);
} }
if(post.containsKey("delete")){ if(post.containsKey("delete")){

@ -388,13 +388,13 @@ public class bookmarksDB {
} }
public void importFromXML(String input){ public void importFromXML(String input, boolean isPublic){
SAXParser parser; SAXParser parser;
try { try {
ByteArrayInputStream is=new ByteArrayInputStream(input.getBytes()); ByteArrayInputStream is=new ByteArrayInputStream(input.getBytes());
parser = SAXParserFactory.newInstance().newSAXParser(); parser = SAXParserFactory.newInstance().newSAXParser();
xmlImportHandler handler=new xmlImportHandler(); xmlImportHandler handler=new xmlImportHandler(isPublic);
parser.parse(is, handler); parser.parse(is, handler);
} catch (ParserConfigurationException e) { } catch (ParserConfigurationException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
@ -411,17 +411,38 @@ public class bookmarksDB {
} }
} }
public class xmlImportHandler extends DefaultHandler{ public class xmlImportHandler extends DefaultHandler{
boolean importPublic;
public xmlImportHandler(boolean isPublic){
importPublic=isPublic;
}
public void startElement(String uri, String localName, String qName, Attributes attributes) { public void startElement(String uri, String localName, String qName, Attributes attributes) {
System.out.println(qName);
if (qName.equals("post")) { if (qName.equals("post")) {
Bookmark bm = new Bookmark(attributes.getValue("href")); String url=attributes.getValue("href");
Vector tags = listManager.string2vector(attributes.getValue("tag").replace(' ', ',')); if(url.equals("")){
return;
}
Bookmark bm = new Bookmark(url);
String tagsString=attributes.getValue("tag").replace(' ', ',');
String title=attributes.getValue("description");
String description=attributes.getValue("extended");
String time=attributes.getValue("time");
Vector tags=new Vector();
if(title != null){
bm.setProperty(Bookmark.BOOKMARK_TITLE, title);
}
if(tagsString!=null){
tags = listManager.string2vector(tagsString);
}
bm.setTags(tags); bm.setTags(tags);
bm.setTimeStamp(iso8601ToDate(attributes.getValue("time")).getTime()); if(time != null){
bm.setProperty(Bookmark.BOOKMARK_TITLE, attributes.getValue("description")); bm.setTimeStamp(iso8601ToDate(time).getTime());
bm.setProperty(Bookmark.BOOKMARK_DESCRIPTION, attributes.getValue("extended")); }
if(description!=null){
bm.setProperty(Bookmark.BOOKMARK_DESCRIPTION, description);
}
bm.setPublic(importPublic);
bm.setBookmarksTable(); bm.setBookmarksTable();
System.out.println(bm.getUrl());
} }
} }
} }
@ -663,6 +684,13 @@ public class bookmarksDB {
return false; return false;
} }
} }
public void setPublic(boolean isPublic){
if(isPublic){
this.mem.put(BOOKMARK_PUBLIC, "public");
}else{
this.mem.put(BOOKMARK_PUBLIC, "private");
}
}
public void setProperty(String name, String value){ public void setProperty(String name, String value){
mem.put(name, value); mem.put(name, value);
//setBookmarksTable(); //setBookmarksTable();
@ -692,7 +720,7 @@ public class bookmarksDB {
} }
public void setBookmarksTable(){ public void setBookmarksTable(){
try { try {
bookmarksDB.this.bookmarksTable.set(getUrlHash(), mem); bookmarksDB.this.bookmarksTable.set(urlHash, mem);
} catch (IOException e) {} } catch (IOException e) {}
} }
public long getTimeStamp(){ public long getTimeStamp(){

Loading…
Cancel
Save