Skip to content

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

bookmarks import.

alloe3dd67bba096
diff --git a/htroot/Bookmarks.html b/htroot/Bookmarks.html
index 9779484a5..7c9fa8e1c 100644
--- a/htroot/Bookmarks.html
+++ b/htroot/Bookmarks.html
@@ -17,6 +17,7 @@
::
<a href="Bookmarks.html?mode=add">Add Bookmark</a>
<a href="Bookmarks.html?mode=importxml">Import XML Bookmarks</a>
+<!-- <a href="Bookmarks.html?mode=importbookmarks">Import Bookmarks.html</a> -->
::
<form action="Bookmarks.html" method="GET">
<table border="0" width="100%" height="100%">
@@ -59,6 +60,7 @@
</table>
</form>
::
+<!-- import XML Bookmarks -->
<form action="Bookmarks.html" method="POST" enctype="multipart/form-data">
<table border="0" width="100%" height="100%">
<tr>
@@ -83,6 +85,36 @@
</tr>
</table>
</form>
+::
+<!-- import Netscape Bookmarks -->
+<form action="Bookmarks.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 Bookmarks</h3></td>
+ </tr>
+ <tr>
+ <td valign="top" class="TableCellDark">File:</td>
+ <td valign="top" class="TableCellLight" width="100%"><input type="file" name="bookmarksfile"></td>
+ </tr>
+ <tr>
+ <td valign="top" class="TableCellDark">Default Tags:</td>
+ <td valign="top" class="TableCellLight" width="100%"><input type="text" name="tags" value="imported"></td>
+ </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>
+ <td colspan="2" colspan="2" valign="top" class="TableHeader" width="100%">
+ <input type="submit" name="importbookmarks" value="import">
+ </td>
+ </tr>
+</table>
+</form>
#(/mode)#
<hr>
diff --git a/htroot/Bookmarks.java b/htroot/Bookmarks.java
index 5956c34cb..676c5abff 100644
--- a/htroot/Bookmarks.java
+++ b/htroot/Bookmarks.java
@@ -45,7 +45,9 @@
// javac -classpath .:../Classes Blacklist_p.java
// if the shell's current path is HTROOT
+import java.io.File;
import java.io.IOException;
+import java.net.MalformedURLException;
import java.util.Iterator;
import java.util.Vector;
@@ -90,6 +92,8 @@ public class Bookmarks {
prop.put("mode", 2);
}else if(mode.equals("importxml")){
prop.put("mode", 3);
+ }else if(mode.equals("importbookmarks")){
+ prop.put("mode", 4);
}
}else if(post.containsKey("add")){ //add an Entry
String url=(String) post.get("url");
@@ -155,6 +159,20 @@ public class Bookmarks {
}
}
}
+ }else if(post.containsKey("bookmarksfile")){
+ boolean isPublic=false;
+ if(((String) post.get("public")).equals("public")){
+ isPublic=true;
+ }
+ String tags=(String) post.get("tags");
+ if(tags.equals("")){
+ tags="unsorted";
+ }
+ try {
+ File file=new File((String)post.get("bookmarksfile"));
+ switchboard.bookmarksDB.importFromBookmarks(file.toURL() , new String((byte[])post.get("bookmarksfile$file")), tags, isPublic);
+ } catch (MalformedURLException e) {}
+
}else if(post.containsKey("xmlfile")){
boolean isPublic=false;
if(((String) post.get("public")).equals("public")){
@@ -243,7 +261,7 @@ public class Bookmarks {
prop.put("prev-page", 1);
prop.put("prev-page_start", start);
prop.put("prev-page_tag", tagName);
- prop.put("next-page_num", max_count);
+ prop.put("prev-page_num", max_count);
}
prop.put("bookmarks", count);
return prop;
diff --git a/source/de/anomic/data/bookmarksDB.java b/source/de/anomic/data/bookmarksDB.java
index bd6187251..8998af004 100644
--- a/source/de/anomic/data/bookmarksDB.java
+++ b/source/de/anomic/data/bookmarksDB.java
@@ -44,6 +44,7 @@ package de.anomic.data;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
+import java.io.OutputStream;
import java.net.URL;
import java.text.ParseException;
import java.text.SimpleDateFormat;
@@ -70,11 +71,14 @@ import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
+import de.anomic.htmlFilter.htmlFilterContentScraper;
+import de.anomic.htmlFilter.htmlFilterOutputStream;
import de.anomic.kelondro.kelondroDyn;
import de.anomic.kelondro.kelondroException;
import de.anomic.kelondro.kelondroMap;
import de.anomic.plasma.plasmaURL;
import de.anomic.plasma.plasmaWordIndexEntry;
+import de.anomic.server.serverFileUtils;
import de.anomic.server.logging.serverLog;
public class bookmarksDB {
@@ -419,7 +423,35 @@ public class bookmarksDB {
public void addBookmark(String url, String title, Vector tags){
}
+ public void importFromBookmarks(URL baseURL, String input, String tag, boolean importPublic){
+ HashMap links=new HashMap();
+ Iterator it;
+ String url,title;
+ Bookmark bm;
+ Vector tags=listManager.string2vector(tag); //this allow multiple default tags
+ try {
+ //load the links
+ htmlFilterContentScraper scraper = new htmlFilterContentScraper(baseURL);
+ OutputStream os = new htmlFilterOutputStream(null, scraper, null, false);
+ serverFileUtils.write(input.getBytes(),os);
+ os.close();
+ links = (HashMap) scraper.getAnchors();
+ } catch (IOException e) {}
+ it=links.keySet().iterator();
+ while(it.hasNext()){
+ url=(String) it.next();
+ title=(String) links.get(url);
+ if(title.equals("")){//cannot be displayed
+ title=url;
+ }
+ bm=new Bookmark(url);
+ bm.setProperty(Bookmark.BOOKMARK_TITLE, title);
+ bm.setTags(tags);
+ bm.setPublic(importPublic);
+ setBookmarksTable(bm);
+ }
+ }
public void importFromXML(String input, boolean importPublic){
DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
factory.setValidating(false);
@@ -429,15 +461,9 @@ public class bookmarksDB {
builder = factory.newDocumentBuilder();
Document doc=builder.parse(new ByteArrayInputStream(input.getBytes()));
parseXMLimport(doc, importPublic);
- } catch (ParserConfigurationException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ } catch (ParserConfigurationException e) {
} catch (SAXException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
} catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
}
}
@@ -490,43 +516,6 @@ public class bookmarksDB {
}
}
}
- public class xmlImportHandler extends DefaultHandler{
- boolean importPublic;
- public xmlImportHandler(boolean isPublic){
- importPublic=isPublic;
- }
- public void startElement(String uri, String localName, String qName, Attributes attributes) {
- if (qName.equals("post")) {
- String url=attributes.getValue("href");
- 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, true);
- if(time != null){
- bm.setTimeStamp(iso8601ToDate(time).getTime());
- }
- if(description!=null){
- bm.setProperty(Bookmark.BOOKMARK_DESCRIPTION, description);
- }
- bm.setPublic(importPublic);
- setBookmarksTable(bm);
- }
- }
- }
-
/**
* Subclass, which stores an Tag
*
@@ -788,6 +777,10 @@ public class bookmarksDB {
tags.add(tag);
this.setTags(tags, true);
}
+ /**
+ * set the Tags of the bookmark, and write them into the tags table.
+ * @param tags a vector with the tags
+ */
public void setTags(Vector tags){
setTags(tags, true);
}