package org.codecop.tool.android
import java.io.File
import scala.xml.NodeSeq
import org.codecop.tool.io.{ Favorite, Favorites }
/**
* Add list of IE favourites (bookmark.urls) to a bookmark backup from Guenmat's Bookmark Manager app.
* @author Peter Kofler, Copyright (c) 2010, Peter Kofler, licensed under BSD License.
* @since October 2010
*/
object GuenmatBookmarks {
def to_xml_list(bms: Favorites, order: Int): NodeSeq = {
if (bms.size > 0) {
to_xml(bms(0), order) ++ to_xml_list(bms.tail, order + 1000)
} else {
Nil
}
}
def to_xml(bm: Favorite, order: Int) = {
{ bm.name }{ bm.url }{ order }{ bm.fileDate.getTime }
}
def main(args: Array[String]): Unit = {
if (args.isEmpty) {
println("GuenmanBookmarks ")
println
println("Add list of IE favorites (bookmark.urls) to a bookmark backup from Guenmat's Bookmark Manager app.")
sys.exit()
}
// read urls
val favoritesFolder = args(0)
val bookmarks = Favorites.load(favoritesFolder)
val targetFolder = if (args.length > 1) args(1) else "."
val file = new File(targetFolder + "/bookmarks.xml")
val bookmarkXml = scala.xml.XML.loadFile(file)
val lastOrder = Integer.parseInt((bookmarkXml \\ "order").last.text)
// create XML
val oldNodes = bookmarkXml \\ "bookmark"
val newNodes = to_xml_list(bookmarks, lastOrder + 1000)
val root = { oldNodes }{ newNodes }
file.renameTo(new File(targetFolder + "/bookmarks.bak"))
scala.xml.XML.save(targetFolder + "/bookmarks.xml", root, "UTF8", true, null)
}
}