<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Voland.com.cn &#187; XML-RPC</title>
	<atom:link href="http://www.voland.com.cn/tag/xml-rpc/feed" rel="self" type="application/rss+xml" />
	<link>http://www.voland.com.cn</link>
	<description>人生百年,诸事记之</description>
	<lastBuildDate>Thu, 02 Feb 2012 23:09:02 +0000</lastBuildDate>
	<language>zh</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>用java程序向wordpress发布文章</title>
		<link>http://www.voland.com.cn/java-program-to-wordpress-with-articles-published</link>
		<comments>http://www.voland.com.cn/java-program-to-wordpress-with-articles-published#comments</comments>
		<pubDate>Thu, 13 May 2010 01:42:52 +0000</pubDate>
		<dc:creator>Nortan</dc:creator>
				<category><![CDATA[人生百味]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[XML-RPC]]></category>

		<guid isPermaLink="false">http://www.voland.com.cn/?p=486</guid>
		<description><![CDATA[java向wordpress发布文章也成？当然成！不仅能发布文章，读写都不成问题，还很方便，这些便利得益于XML-RPC协议。WordPress提供了XML-RPC API使得第三方的可以与之通信来发布和修改博客。我们也可以使用这个接口做一些工作，例如：在网站首页显示最新的博客、在博客之外的页面上发表博客文章、把博客与其他内容管理系统结合等。 一、开启XML-RPC支持 WordPress的XML-RPC协议默认是未开启的，需要到管理后台的“设置&#8211;>撰写”里的“远程发布”给XML-RPC打上勾。其说明文字为：启用 WordPress，Movable Type，MetaWeblog和Blogger 的 XML-RPC发布协议。 二、API接口选择 WordPress提供了对Blogger API、metaWeblog API、Movable Type API以及其自身的WordPress API的支持。其中WordPress API最为丰富，提供了包括操作评论文章在内的各种各样的支持。Blogger API功能较少，基本上淘汰不用了；而metaWeblog API提供了常用的接口且参数比较简洁，用得较多一些。所以我们以它作为例子。 三、例子代码 这个例子中，需要用到apache的XML-RPC项目包,大家可以到 apache 官方下载,使用这个例子，就可以与昨天的《通用文章采集器的设计与实现》结合，来生成自动发布的站点了，这个慎用哦，后果自负：） import java.net.URL; import java.util.HashMap; import java.util.Map; &#160; import org.apache.xmlrpc.client.XmlRpcClient; import org.apache.xmlrpc.client.XmlRpcClientConfigImpl; &#160; public class Test &#123; public static void post&#40;String title, String content&#41; &#123; try&#123; // Set up XML-RPC connection to server String [...]]]></description>
			<content:encoded><![CDATA[<p>java向wordpress发布文章也成？当然成！不仅能发布文章，读写都不成问题，还很方便，这些便利得益于XML-RPC协议。WordPress提供了XML-RPC API使得第三方的可以与之通信来发布和修改博客。我们也可以使用这个接口做一些工作，例如：在网站首页显示最新的博客、在博客之外的页面上发表博客文章、把博客与其他内容管理系统结合等。<span id="more-486"></span></p>
<p>一、开启XML-RPC支持</p>
<p>WordPress的XML-RPC协议默认是未开启的，需要到管理后台的“设置&#8211;>撰写”里的“远程发布”给XML-RPC打上勾。其说明文字为：启用 WordPress，Movable Type，MetaWeblog和Blogger 的 XML-RPC发布协议。</p>
<p>二、API接口选择</p>
<p>WordPress提供了对Blogger API、metaWeblog API、Movable Type API以及其自身的WordPress API的支持。其中WordPress API最为丰富，提供了包括操作评论文章在内的各种各样的支持。Blogger API功能较少，基本上淘汰不用了；而metaWeblog API提供了常用的接口且参数比较简洁，用得较多一些。所以我们以它作为例子。</p>
<p>三、例子代码</p>
<p>这个例子中，需要用到apache的XML-RPC项目包,大家可以到 <a href="http://ws.apache.org/xmlrpc/download.html" target="_blank">apache 官方</a>下载,使用这个例子，就可以与昨天的《<a href="http://www.voland.com.cn/common-article-collection-design-and-implementation">通用文章采集器的设计与实现</a>》结合，来生成自动发布的站点了，这个慎用哦，后果自负：）</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.net.URL</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.HashMap</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Map</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.xmlrpc.client.XmlRpcClient</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.xmlrpc.client.XmlRpcClientConfigImpl</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Test <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> post<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> title, <span style="color: #003399;">String</span> content<span style="color: #009900;">&#41;</span>  <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">try</span><span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">// Set up XML-RPC connection to server</span>
                        <span style="color: #003399;">String</span> domain <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;www.extbi.com&quot;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//你网站的域名</span>
			XmlRpcClientConfigImpl config <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> XmlRpcClientConfigImpl<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			config.<span style="color: #006633;">setServerURL</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">URL</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://&quot;</span><span style="color: #339933;">+</span>domain<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;/xmlrpc.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			XmlRpcClient client <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> XmlRpcClient<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			client.<span style="color: #006633;">setConfig</span><span style="color: #009900;">&#40;</span>config<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #666666; font-style: italic;">// Set up parameters required by newPost method</span>
			<span style="color: #003399;">Map</span> post <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">HashMap</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			post.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;title&quot;</span>, title<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//标题</span>
			post.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;mt_keywords&quot;</span>, <span style="color: #0000ff;">&quot;标签,标签2,标签3&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//标签</span>
			<span style="color: #003399;">Object</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> categories <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Object</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> <span style="color: #0000ff;">&quot;服饰&quot;</span>,<span style="color: #0000ff;">&quot;数码&quot;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//分类</span>
			post.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;categories&quot;</span>, categories<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			post.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;description&quot;</span>, content<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//内容</span>
			<span style="color: #003399;">Object</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> params <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Object</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> <span style="color: #0000ff;">&quot;1&quot;</span>, <span style="color: #0000ff;">&quot;用户名&quot;</span>, <span style="color: #0000ff;">&quot;密码&quot;</span>, post,
					<span style="color: #003399;">Boolean</span>.<span style="color: #000066; font-weight: bold;">TRUE</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #666666; font-style: italic;">// Call newPost</span>
			<span style="color: #003399;">String</span> result <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#41;</span> client.<span style="color: #006633;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;metaWeblog.newPost&quot;</span>, params<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; Created with blogid &quot;</span> <span style="color: #339933;">+</span> result<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">// TODO: handle exception</span>
                       <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; UnCreated &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>四、畅想</p>
<p>博客有如此大强大，灵活，好用的接口 ，那为什么国内常用的CMS没有呢？做一个也花不了多少时间，当然，在实际的管理软件中，如CRM中，我建议也可以加入这样的接口，那与其它系统集成是多么爽的一件事情。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.voland.com.cn/java-program-to-wordpress-with-articles-published/feed</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
	</channel>
</rss>

