如何在 confluence 上更新现有页面?
How do I update an existing page on confluence?
我正在使用以下代码在 Confluence 4.3 上创建一个页面:
public void publish() throws IOException {
DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
Date today = Calendar.getInstance().getTime();
XWikiXmlRpcClient rpc = new XWikiXmlRpcClient(CONFLUENCE_URI);
try {
rpc.login(USER_NAME, PASSWORD);
Page page = new Page();
page.setSpace(owrConf.getString(ConfigKeys.CONFLUENCE_SPACE));
page.setTitle(owrConf.getString(ConfigKeys.CONFLUENCE_PAGE_TITLE) + "_" + df.format(today));
List<String> lines = Files.readAllLines(Paths.get("summary.markup"), Charset.defaultCharset());
StringBuilder b = new StringBuilder();
for(int i=0; i < lines.size(); i++) {
b.append(String.format("%s%s", lines.get(i), "\r\n"));
}
page.setContent(b.toString());
page.setParentId(owrConf.getString(ConfigKeys.CONFLUENCE_PAGE_ID));
rpc.storePage(page);
} catch (XmlRpcException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
这很好用,但我只是想知道我是否可以更新现有页面而不是总是创建一个新页面。我找不到 API 有关 Confluence 4.3 的信息来执行此操作。
看看这个 post,它使用 Python 和 XMLRPC 更新页面。
How can I create a new page to confluence with Python
你也可以看看这个页面
https://answers.atlassian.com/questions/316106/how-to-update-a-page-in-confluence-by-java
但实际上在 2015 年你应该使用 Confluence REST API 来做这类事情。使用一些 JSON 数据对此 url 做一个简单的 post 并且您的页面已更新
https://docs.atlassian.com/atlassian-confluence/REST/latest/#d3e941
更新:
XWikiXmlRpcClient rpc = new XWikiXmlRpcClient(url);
try {
//Perform Login & Authentication
rpc.login(user, pass);
//Create a Page object to hold our Document information
Page page = new Page();
//Fetch the required page. In our example, the page is in Space "demo code"
//and the Page is "Update Page"
page=rpc.getPage("demo code.Update Page");
//Fetch the content of the page & store it in a string for temporary storage
//This is the present content of the Page
String presentContent=page.getContent();
//Create a string that will hold the new content that is to be added to the Page
String newContent="\\Some new content added";
//Set the content of the page as: present content + new content
//However, this page is not yet stored to XWiki. It only resides in your application
page.setContent(presentContent+newContent);
//Finally, store the "updated" Page to XWiki
rpc.storePage(page);
//Just to make sure everything saved all right, fetch the content again for the Page
System.out.println(page.getContent());
} catch (XmlRpcException e) {
System.out.println("invalid username/password was specified or communication problem or ");
System.out.println(e);
} finally {
rpc.logout();
}
从这个页面得到这个:http://extensions.xwiki.org/xwiki/bin/view/Extension/XML-RPC+Integration+Java+Examples
我正在使用以下代码在 Confluence 4.3 上创建一个页面:
public void publish() throws IOException {
DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
Date today = Calendar.getInstance().getTime();
XWikiXmlRpcClient rpc = new XWikiXmlRpcClient(CONFLUENCE_URI);
try {
rpc.login(USER_NAME, PASSWORD);
Page page = new Page();
page.setSpace(owrConf.getString(ConfigKeys.CONFLUENCE_SPACE));
page.setTitle(owrConf.getString(ConfigKeys.CONFLUENCE_PAGE_TITLE) + "_" + df.format(today));
List<String> lines = Files.readAllLines(Paths.get("summary.markup"), Charset.defaultCharset());
StringBuilder b = new StringBuilder();
for(int i=0; i < lines.size(); i++) {
b.append(String.format("%s%s", lines.get(i), "\r\n"));
}
page.setContent(b.toString());
page.setParentId(owrConf.getString(ConfigKeys.CONFLUENCE_PAGE_ID));
rpc.storePage(page);
} catch (XmlRpcException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
这很好用,但我只是想知道我是否可以更新现有页面而不是总是创建一个新页面。我找不到 API 有关 Confluence 4.3 的信息来执行此操作。
看看这个 post,它使用 Python 和 XMLRPC 更新页面。
How can I create a new page to confluence with Python
你也可以看看这个页面 https://answers.atlassian.com/questions/316106/how-to-update-a-page-in-confluence-by-java
但实际上在 2015 年你应该使用 Confluence REST API 来做这类事情。使用一些 JSON 数据对此 url 做一个简单的 post 并且您的页面已更新
https://docs.atlassian.com/atlassian-confluence/REST/latest/#d3e941
更新:
XWikiXmlRpcClient rpc = new XWikiXmlRpcClient(url);
try {
//Perform Login & Authentication
rpc.login(user, pass);
//Create a Page object to hold our Document information
Page page = new Page();
//Fetch the required page. In our example, the page is in Space "demo code"
//and the Page is "Update Page"
page=rpc.getPage("demo code.Update Page");
//Fetch the content of the page & store it in a string for temporary storage
//This is the present content of the Page
String presentContent=page.getContent();
//Create a string that will hold the new content that is to be added to the Page
String newContent="\\Some new content added";
//Set the content of the page as: present content + new content
//However, this page is not yet stored to XWiki. It only resides in your application
page.setContent(presentContent+newContent);
//Finally, store the "updated" Page to XWiki
rpc.storePage(page);
//Just to make sure everything saved all right, fetch the content again for the Page
System.out.println(page.getContent());
} catch (XmlRpcException e) {
System.out.println("invalid username/password was specified or communication problem or ");
System.out.println(e);
} finally {
rpc.logout();
}
从这个页面得到这个:http://extensions.xwiki.org/xwiki/bin/view/Extension/XML-RPC+Integration+Java+Examples