@ -1,10 +1,12 @@
package xml.bookmarks.xbel ;
package xml.bookmarks.xbel ;
import java.util.Date ;
import java.util.Iterator ;
import java.util.Iterator ;
import de.anomic.data.bookmarksDB ;
import de.anomic.data.bookmarksDB ;
import de.anomic.http.httpHeader ;
import de.anomic.http.httpHeader ;
import de.anomic.plasma.plasmaSwitchboard ;
import de.anomic.plasma.plasmaSwitchboard ;
import de.anomic.server.serverDate ;
import de.anomic.server.serverObjects ;
import de.anomic.server.serverObjects ;
import de.anomic.server.serverSwitch ;
import de.anomic.server.serverSwitch ;
@ -28,20 +30,27 @@ public class xbel {
prop . put ( "AUTHENTICATE" , "admin log-in" ) ;
prop . put ( "AUTHENTICATE" , "admin log-in" ) ;
}
}
}
}
if ( post . containsKey ( "tag" ) ) {
String tagName = ( String ) post . get ( "tag" ) ;
prop . put ( "folder" , tagName ) ;
if ( ! tagName . equals ( "" ) ) {
Iterator < String > bit = switchboard . bookmarksDB . getBookmarksIterator ( tagName , isAdmin ) ;
count = print_XBEL ( bit , count ) ;
prop . put ( "xbel" , count ) ;
return prop ;
}
}
}
if ( isAdmin ) {
}
// print bookmark folders as XBEL default
prop . put ( "folder" , "YaCy Bookmark Folder" ) ;
count = recurseFolders ( switchboard . bookmarksDB . getFolderList ( isAdmin ) , "/" , 0 , true , "" ) ;
count = recurseFolders ( switchboard . bookmarksDB . getFolderList ( isAdmin ) , "/" , 0 , true , "" ) ;
prop . put ( "xbel" , count ) ;
prop . put ( "xbel" , count ) ;
}
return prop ; // return from serverObjects respond()
return prop ; // return from serverObjects respond()
}
}
private static int recurseFolders ( Iterator < String > it , String root , int count , boolean next , String prev ) {
private static int recurseFolders ( Iterator < String > it , String root , int count , boolean next , String prev ) {
String fn = "" ;
String fn = "" ;
bookmarksDB . Bookmark bookmark ;
if ( next ) fn = it . next ( ) . toString ( ) ;
if ( next ) fn = it . next ( ) . toString ( ) ;
else fn = prev ;
else fn = prev ;
@ -62,19 +71,7 @@ public class xbel {
prop . put ( "xbel_" + count + "_elements" , "<title>" + fn . replaceFirst ( root + "/*" , "" ) + "</title>" ) ;
prop . put ( "xbel_" + count + "_elements" , "<title>" + fn . replaceFirst ( root + "/*" , "" ) + "</title>" ) ;
count + + ;
count + + ;
Iterator < String > bit = switchboard . bookmarksDB . getBookmarksIterator ( fn , isAdmin ) ;
Iterator < String > bit = switchboard . bookmarksDB . getBookmarksIterator ( fn , isAdmin ) ;
while ( bit . hasNext ( ) ) {
count = print_XBEL ( bit , count ) ;
bookmark = switchboard . bookmarksDB . getBookmark ( bit . next ( ) ) ;
prop . put ( "xbel_" + count + "_elements" , "<bookmark id=\"" + bookmark . getUrlHash ( ) + "\" href=\"" + bookmark . getUrl ( ) + "\">" ) ;
count + + ;
prop . put ( "xbel_" + count + "_elements" , "<title>" + bookmark . getTitle ( ) + "</title>" ) ;
count + + ;
prop . put ( "xbel_" + count + "_elements" , "<info><metadata owner=\"Mozilla\" ShortcutURL=\"" + bookmark . getTagsString ( ) . replaceAll ( "/.*," , "" ) + "\"/></info>" ) ;
count + + ;
prop . put ( "xbel_" + count + "_elements" , "<desc>" + bookmark . getDescription ( ) + "</desc>" ) ;
count + + ;
prop . put ( "xbel_" + count + "_elements" , "</bookmark>" ) ;
count + + ;
}
if ( it . hasNext ( ) ) {
if ( it . hasNext ( ) ) {
count = recurseFolders ( it , fn , count , true , fn ) ;
count = recurseFolders ( it , fn , count , true , fn ) ;
}
}
@ -87,4 +84,40 @@ public class xbel {
}
}
return count ;
return count ;
}
}
private static int print_XBEL ( Iterator < String > bit , int count ) {
bookmarksDB . Bookmark bookmark ;
Date date ;
while ( bit . hasNext ( ) ) {
bookmark = switchboard . bookmarksDB . getBookmark ( bit . next ( ) ) ;
date = new Date ( bookmark . getTimeStamp ( ) ) ;
prop . put ( "xbel_" + count + "_elements" , "<bookmark id=\"" + bookmark . getUrlHash ( ) + "\" href=\"" + bookmark . getUrl ( ) + "\" added=\"" + serverDate . formatISO8601 ( date ) + "\">" ) ;
count + + ;
prop . put ( "xbel_" + count + "_elements" , "<title>" ) ;
count + + ;
prop . putHTML ( "xbel_" + count + "_elements" , bookmark . getTitle ( ) , true ) ;
count + + ;
prop . put ( "xbel_" + count + "_elements" , "</title>" ) ;
count + + ;
prop . put ( "xbel_" + count + "_elements" , "<info>" ) ;
count + + ;
prop . put ( "xbel_" + count + "_elements" , "<metadata owner=\"Mozilla\" ShortcutURL=\"" + bookmark . getTagsString ( ) . replaceAll ( "/.*," , "" ) . toLowerCase ( ) + "\"/>" ) ;
count + + ;
prop . put ( "xbel_" + count + "_elements" , "<metadata owner=\"YaCy\" public=\"" + Boolean . toString ( bookmark . getPublic ( ) ) + "\"/>" ) ;
count + + ;
prop . put ( "xbel_" + count + "_elements" , "</info>" ) ;
count + + ;
prop . put ( "xbel_" + count + "_elements" , "<desc>" ) ;
count + + ;
prop . putHTML ( "xbel_" + count + "_elements" , bookmark . getDescription ( ) , true ) ;
count + + ;
prop . put ( "xbel_" + count + "_elements" , "</desc>" ) ;
count + + ;
prop . put ( "xbel_" + count + "_elements" , "</bookmark>" ) ;
count + + ;
}
return count ;
}
}
}