Skip to content

Commit

Permalink
bookmarks import.
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@1697 6c8d7289-2bf4-0310-a012-ef5d649a1542
  • Loading branch information
allo committed Feb 18, 2006
1 parent dda143d commit e3dd67b
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 45 deletions.
32 changes: 32 additions & 0 deletions htroot/Bookmarks.html
Expand Up @@ -17,6 +17,7 @@ <h2>Bookmarks</h2></p>
::
<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%">
Expand Down Expand Up @@ -59,6 +60,7 @@ <h2>Bookmarks</h2></p>
</table>
</form>
::
<!-- import XML Bookmarks -->
<form action="Bookmarks.html" method="POST" enctype="multipart/form-data">
<table border="0" width="100%" height="100%">
<tr>
Expand All @@ -83,6 +85,36 @@ <h2>Bookmarks</h2></p>
</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>

Expand Down
20 changes: 19 additions & 1 deletion htroot/Bookmarks.java
Expand Up @@ -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;

Expand Down Expand Up @@ -90,6 +92,8 @@ public static serverObjects respond(httpHeader header, serverObjects post, serve
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");
Expand Down Expand Up @@ -155,6 +159,20 @@ public static serverObjects respond(httpHeader header, serverObjects post, serve
}
}
}
}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")){
Expand Down Expand Up @@ -243,7 +261,7 @@ public static serverObjects respond(httpHeader header, serverObjects post, serve
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;
Expand Down
81 changes: 37 additions & 44 deletions source/de/anomic/data/bookmarksDB.java
Expand Up @@ -44,6 +44,7 @@
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;
Expand All @@ -70,11 +71,14 @@
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 {
Expand Down Expand Up @@ -419,7 +423,35 @@ public Iterator bookmarkIterator(boolean up){
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);
Expand All @@ -429,15 +461,9 @@ public void importFromXML(String input, boolean importPublic){
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();
}

}
Expand Down Expand Up @@ -490,43 +516,6 @@ public void parseXMLimport(Node doc, boolean importPublic){
}
}
}
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
*
Expand Down Expand Up @@ -788,6 +777,10 @@ public void addTag(String tag){
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);
}
Expand Down

0 comments on commit e3dd67b

Please sign in to comment.