Blogger moving

Blogger和Wordpress都被“和谐”掉很久了,一直没有什么起色。终于决定要搬家了。
新浪,搜狐那些就完全不考虑了,广告一大堆。
百度空间和Myspace的速度最快,但是博客功能少的可怜。倒是挺适合社交圈子的,但俺也不好那个,只想要个可高定制化的博客空间。

最终开始尝试Wordpress中国和YO2。花了几天时间,试了无数次。费尽了周折。。。

Online

最先想用YO2自己的导入功能,但是无论怎么样(开代理,自由门),都无法从Blogger正常读取数据。

然后试试Wordpress中国,结果…,连Google access验证都出错。

看来只好用网上流传的办法了,BlogBackupOnline,好不容易备份了Blogger,准备restore到YO2试试,结果发现restore是付费用户才能享受的功能-_-

接着用BlogSync想synchronize过去,开了自由门,好不容易能读取Blogger了,但是Wordpress中国和YO2怎么Recheck都fail。根本没办法synchronize。


Local

好吧,Online的导入导出是没办法了。能否将Blogger导出到本地feed,然后再导入其他网站呢?

BlogBackupOnline是可以导出完整的RSS feed,但是被Wordpress吃进去以后就连CDATA也给escape掉了,结果只有CDATA也显示在网页上了。

动手改,RSS feed的namespace加上xmlns:content=”http://purl.org/rss/1.0/modules/content/”,然后所有变成,终于可以正常导入到Wordpress中国和YO2了。

但是评论,分类什么的都没有了。想再找另外一种办法。用Blogger Backup Utility把整个博客备份下来成为Atom feed。因为这个工具使用Google提供的GDATA API,所以没有直接备份成RSS feed的功能。只好写程序用ROME将Atom feed转成RSS feed。

转完了才发现,所有的HTML entities都被escape掉了,完蛋了,网页全花了。

原来是jDom搞的鬼,XMLOutputter自作聪明的做了escaping。还是自己动手,丰衣足食,override了RSS20Generator,把feed里面的content都转成CDATA类型,然后去除了一些多余的东西,比如link,guid等等可能导致“撞墙”的链接。

转出来的东西可以被Wordpress和YO2正常消化了。正高兴呢,发现还是没有评论和分类,再次晕倒。。。

不过想想也好,自己可以制作RSS2.0的feed了,以后想转其他博客也容易一点啊,自我安慰一下吧。

下面的程序留作纪念:

public class Atom2RSS {

/**
* @param args
*/
public static void main(String[] args) {
// Input
SyndFeedInput input = new SyndFeedInput();
input.setXmlHealerOn(false);
SyndFeed feed = null;
try {
feed = input.build(new XmlReader(new File(
“E:\Backup\Blog\宝宝日记.xml”)));
} catch (Exception e) {
e.printStackTrace();
}
// Because Blogger Backup Utility will not generate the description in
// atom feed, the description has to be set manually.
feed.setDescription(feed.getTitle());

// Output
File outFile = new File(“E:\Backup\Blog\宝宝日记_rss20.xml”);
feed.setFeedType(“rss_2.0”);
try {
// Customized generator to adjust the output
WireFeedGenerator generator = new RSS20GeneratorAdj();
Document doc = generator.generate(feed.createWireFeed());

Format format = Format.getPrettyFormat();
format.setEncoding(CharEncoding.UTF_8);
format.setIgnoreTrAXEscapingPIs(true);

XMLOutputter xmlOut = new XMLOutputter(format);
xmlOut.output(doc, new FileOutputStream(outFile));

} catch (Exception e) {
e.printStackTrace();
}
}

}

i


public class RSS20GeneratorAdj extends RSS20Generator {

public void populateItem(Item item, Element eItem, int index) {
super.populateItem(item, eItem, index);
List itemList = eItem.getContent();
for (int i = 0; i
Element elem = (Element) itemList.get(i);
// Use CDATA to protect the encoding
if (“encoded”.equals(elem.getName()) && getContentNamespace().equals(elem.getNamespace())) {
String content = ((Content) elem.getContent().get(0)).getValue();
elem.setContent(0, new CDATA(content));
}
// Remove guid and link
if (“guid”.equals(elem.getName()) || “link”.equals(elem.getName())) {
itemList.remove(i);
i–;
}
// Resolve category attributes
if (“category”.equals(elem.getName())) {
elem.setAttribute(“domain”, “tag”);

}
}
}

protected void populateChannel(Channel channel, Element eChannel) {
super.populateChannel(channel, eChannel);

List contentList = eChannel.getContent();
for (int i = 0; i
Element elem = (Element) contentList.get(i);
if (“link”.equals(elem.getName())) {
elem.removeContent();
elem.addContent(“http://librazh.yo2.cn/”);
}
}
}

}

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据

Back to Top