1、分析bookmarker的数据结构,编写ftl
<!DOCTYPE NETSCAPE-Bookmark-file-1>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<TITLE>Bookmarks</TITLE>
<H1>Bookmarks</H1>
<DL><p>
<DT><H3 ADD_DATE="1477118590" LAST_MODIFIED="1486200186" PERSONAL_TOOLBAR_FOLDER="true">收藏栏</H3>
<DL><p>
<#list list as webSite>
<DT><H3 ADD_DATE="1486200186" LAST_MODIFIED="1486200195">${webSite.webtype}</H3>
<DL><p>
<#list webSite.web as web>
<DT><A HREF="${web.weburl}" ADD_DATE="1486200195" ICON="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAc0lEQVQ4jWNgGGjAiMYPJ6B+JboAC7rAy5cvV6CLiYuLR/z//38FIyMjhiFMhB2JAP///1+B7koMF/Dy8hI0BNklGAZgAxcuXFjByMgYgU2OKAPU1NQYvn37Bg8bLi4uuGEkhQE2MGoAFQzAiEbkKKILAADxTRpEuhAmjwAAAABJRU5ErkJggg==">${web.webname}</A>
</#list>
</DL><p>
</#list>
</DL><p>
</DL><p>
2、通过java的freemark生成html
Configuration cc = new Configuration();
cc.setDirectoryForTemplateLoading(new File(TEMPLATEFILE));
Map root = new HashMap();
root.put("list", list);
System.out.println("===="+list.size());
System.out.println(list.get(0).getWebtype());
Template template = cc.getTemplate(TEMPLATEFILENAME);
template.setEncoding("UTF-8");
Writer out = new OutputStreamWriter(System.out,"UTF-8");
template.process(root, out);
File fileDir = new File(SAVEDIR);
FileUtils.forceMkdir(fileDir);
File output = new File((new StringBuilder()).append(fileDir).append(SAVEFILE).toString());
// Writer writer = new FileWriter(output);
Writer writer = new BufferedWriter(
new OutputStreamWriter(new FileOutputStream(output),"UTF-8"));
template.process(root, writer);
writer.close();
out.flush();
out.close();
特别注意:Writer writer = new FileWriter(output); //可能导致生成的html出现乱码
因此改为:
Writer writer = new BufferedWriter(
new OutputStreamWriter(new FileOutputStream(output),”UTF-8”));
3、生成的html
4、浏览器导入html
5、导入成功