Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

hide add/edit/import bookmarks per default. xml-bookmark import (this does not work, yet)

alloa4513523d64c
diff --git a/htroot/Bookmarks_p.html b/htroot/Bookmarks_p.html
index 8f94bebcf..941aa3852 100644
--- a/htroot/Bookmarks_p.html
+++ b/htroot/Bookmarks_p.html
@@ -12,6 +12,10 @@
<h2>Bookmarks</h2></p>
<!-- todo: div layout? -->
+#(mode)#
+<a href="Bookmarks_p.html?mode=add">Add Bookmark</a>
+<a href="Bookmarks_p.html?mode=importxml">Import XML Bookmarks</a>
+::
<form action="Bookmarks_p.html" method="GET">
<table border="0" width="100%" height="100%">
<tr>
@@ -52,6 +56,24 @@
</tr>
</table>
</form>
+::
+<form action="Bookmarks_p.html" method="POST" enctype="multipart/form-data">
+<table border="0" width="100%" height="100%">
+ <tr>
+ <td colspan="2" colspan="2" valign="top" class="TableHeader"><h3>Import XML Bookmarks</h3></td>
+ </tr>
+ <tr>
+ <td valign="top" class="TableCellDark">File:</td>
+ <td valign="top" class="TableCellLight" width="100%"><input type="file" name="xmlfile"></td>
+ </tr>
+ <tr>
+ <td colspan="2" colspan="2" valign="top" class="TableHeader" width="100%">
+ <input type="submit" name="importxml" value="import">
+ </td>
+ </tr>
+</table>
+</form>
+#(/mode)#
<hr>
<table width="100%" height="100%">
diff --git a/htroot/Bookmarks_p.java b/htroot/Bookmarks_p.java
index cad6069ce..d3525d2f1 100644
--- a/htroot/Bookmarks_p.java
+++ b/htroot/Bookmarks_p.java
@@ -66,13 +66,22 @@ public class Bookmarks_p {
int start=0;
//defaultvalues
- prop.put("edit", 0);
- prop.put("title", "");
- prop.put("description", "");
- prop.put("url", "");
- prop.put("tags", "");
- prop.put("public", 1); //1=is public
+ prop.put("mode", 0);
+ prop.put("mode_edit", 0);
+ prop.put("mode_title", "");
+ prop.put("mode_description", "");
+ prop.put("mode_url", "");
+ prop.put("mode_tags", "");
+ prop.put("mode_public", 1); //1=is public
if(post != null){
+ if(post.containsKey("mode")){
+ String mode=(String) post.get("mode");
+ if(mode.equals("add")){
+ prop.put("mode", 1);
+ }else if(mode.equals("importxml")){
+ prop.put("mode", 2);
+ }
+ }
if(post.containsKey("add")){ //add an Entry
String url=(String) post.get("url");
String title=(String) post.get("title");
@@ -97,46 +106,50 @@ public class Bookmarks_p {
}else{
//ERROR
}
- }
- if(post.containsKey("edit")){
+ }else if(post.containsKey("edit")){
String urlHash=(String) post.get("edit");
+ prop.put("mode", 1);
if (urlHash.length() == 0) {
- prop.put("edit", 0); // create mode
- prop.put("title", (String) post.get("title"));
- prop.put("description", (String) post.get("description"));
- prop.put("url", (String) post.get("url"));
- prop.put("tags", (String) post.get("tags"));
- prop.put("public", 0);
+ prop.put("mode_edit", 0); // create mode
+ prop.put("mode_title", (String) post.get("title"));
+ prop.put("mode_description", (String) post.get("description"));
+ prop.put("mode_url", (String) post.get("url"));
+ prop.put("mode_tags", (String) post.get("tags"));
+ prop.put("mode_public", 0);
} else {
bookmarksDB.Bookmark bookmark = switchboard.bookmarksDB.getBookmark(urlHash);
if (bookmark == null) {
// try to get the bookmark from the LURL database
try {
plasmaCrawlLURL.Entry urlentry = switchboard.urlPool.loadedURL.getEntry(urlHash, null);
- prop.put("edit", 0); // create mode
- prop.put("title", urlentry.descr());
- prop.put("description", urlentry.descr());
- prop.put("url", urlentry.url());
- prop.put("tags", "");
- prop.put("public", 0);
+ prop.put("mode_edit", 0); // create mode
+ prop.put("mode_title", urlentry.descr());
+ prop.put("mode_description", urlentry.descr());
+ prop.put("mode_url", urlentry.url());
+ prop.put("mode_tags", "");
+ prop.put("mode_public", 0);
} catch (IOException e) {
e.printStackTrace();
}
} else {
// get from the bookmark database
- prop.put("edit", 1); // edit mode
- prop.put("title", bookmark.getTitle());
- prop.put("description", bookmark.getDescription());
- prop.put("url", bookmark.getUrl());
- prop.put("tags", bookmark.getTags());
+ prop.put("mode_edit", 1); // edit mode
+ prop.put("mode_title", bookmark.getTitle());
+ prop.put("mode_description", bookmark.getDescription());
+ prop.put("mode_url", bookmark.getUrl());
+ prop.put("mode_tags", bookmark.getTags());
if (bookmark.getPublic()) {
- prop.put("public", 1);
+ prop.put("mode_public", 1);
} else {
- prop.put("public", 0);
+ prop.put("mode_public", 0);
}
}
}
}
+ if(post.containsKey("xmlfile")){
+ switchboard.bookmarksDB.importFromXML(new String((byte[])post.get("xmlfile$file")));
+ }
+
if(post.containsKey("delete")){
String urlHash=(String) post.get("delete");
switchboard.bookmarksDB.removeBookmark(urlHash);
diff --git a/htroot/xml/bookmarks/posts/all.java b/htroot/xml/bookmarks/posts/all.java
index 2ad988c3c..ec09770d4 100644
--- a/htroot/xml/bookmarks/posts/all.java
+++ b/htroot/xml/bookmarks/posts/all.java
@@ -45,7 +45,6 @@
// javac -classpath .:../classes IndexCreate_p.java
// if the shell's current path is HTROOT
package xml.bookmarks.posts;
-import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
@@ -77,7 +76,7 @@ public class all {
prop.put("posts_"+count+"_description", bookmark.getDescription());
prop.put("posts_"+count+"_md5", serverCodings.encodeMD5Hex(bookmark.getUrl()));
date=new Date(bookmark.getTimeStamp());
- prop.put("posts_"+count+"_time", (new SimpleDateFormat("yyyy-MM-dd")).format(date)+"T"+(new SimpleDateFormat("HH:mm:ss")).format(date)+"Z");
+ prop.put("posts_"+count+"_time", bookmarksDB.dateToiso8601(date));
prop.put("posts_"+count+"_tags", bookmark.getTags().replaceAll(","," "));
count++;
}
diff --git a/source/de/anomic/data/bookmarksDB.java b/source/de/anomic/data/bookmarksDB.java
index 46da978c6..30f140e1b 100644
--- a/source/de/anomic/data/bookmarksDB.java
+++ b/source/de/anomic/data/bookmarksDB.java
@@ -41,10 +41,13 @@
//Contributions and changes to the program code must be marked as such.
package de.anomic.data;
+import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.net.URL;
+import java.text.ParseException;
import java.text.SimpleDateFormat;
+import java.util.Calendar;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
@@ -54,6 +57,15 @@ import java.util.Map;
import java.util.TreeSet;
import java.util.Vector;
+import javax.xml.parsers.FactoryConfigurationError;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
import de.anomic.kelondro.kelondroDyn;
import de.anomic.kelondro.kelondroException;
import de.anomic.kelondro.kelondroMap;
@@ -65,6 +77,34 @@ public class bookmarksDB {
kelondroMap bookmarksTable;
kelondroMap datesTable;
+ public static String dateToiso8601(Date date){
+ return new SimpleDateFormat("yyyy-MM-dd").format(date)+"T"+(new SimpleDateFormat("HH:mm:ss")).format(date)+"Z";
+ }
+ public static Date iso8601ToDate(String iso8601){
+ String[] tmp=iso8601.split("T");
+ String day=tmp[0];
+ String time=tmp[1];
+ if(time.length()>8){
+ time=time.substring(0,8);
+ }
+ try {
+ Calendar date=Calendar.getInstance();
+ Calendar date2=Calendar.getInstance();
+ date.setTime(new SimpleDateFormat("yyyy-MM-dd").parse(day));
+ date2.setTime(new SimpleDateFormat("HH:mm:ss").parse(time));
+
+ date.set(Calendar.HOUR_OF_DAY, date2.get(Calendar.HOUR_OF_DAY));
+ date.set(Calendar.MINUTE, date2.get(Calendar.MINUTE));
+ date.set(Calendar.SECOND, date2.get(Calendar.SECOND));
+
+ return date.getTime();
+ } catch (ParseException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return new Date();
+ }
+
public bookmarksDB(File bookmarksFile, File tagsFile, File datesFile, int bufferkb){
//bookmarks
//check if database exists
@@ -348,6 +388,44 @@ public class bookmarksDB {
}
+ public void importFromXML(String input){
+
+ SAXParser parser;
+ try {
+ ByteArrayInputStream is=new ByteArrayInputStream(input.getBytes());
+ parser = SAXParserFactory.newInstance().newSAXParser();
+ xmlImportHandler handler=new xmlImportHandler();
+ parser.parse(is, handler);
+ } catch (ParserConfigurationException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (SAXException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (FactoryConfigurationError e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ public class xmlImportHandler extends DefaultHandler{
+ public void startElement(String uri, String localName, String qName, Attributes attributes) {
+ System.out.println(qName);
+ if (qName.equals("post")) {
+ Bookmark bm = new Bookmark(attributes.getValue("href"));
+ Vector tags = listManager.string2vector(attributes.getValue("tag").replace(' ', ','));
+ bm.setTags(tags);
+ bm.setTimeStamp(iso8601ToDate(attributes.getValue("time")).getTime());
+ bm.setProperty(Bookmark.BOOKMARK_TITLE, attributes.getValue("description"));
+ bm.setProperty(Bookmark.BOOKMARK_DESCRIPTION, attributes.getValue("extended"));
+ bm.setBookmarksTable();
+ System.out.println(bm.getUrl());
+ }
+ }
+ }
+
/**
* Subclass, which stores an Tag
*
@@ -624,6 +702,9 @@ public class bookmarksDB {
return 0;
}
}
+ public void setTimeStamp(long timestamp){
+ this.mem.put(BOOKMARK_TIMESTAMP, String.valueOf(timestamp));
+ }
}
public class tagIterator implements Iterator{
kelondroDyn.dynKeyIterator tagIter;