Changes for page XML-RPC Java Examples
Last modified by Thomas Mortagne on 2023/10/10 14:31
From version 5.3
edited by Marius Dumitru Florea
on 2010/05/04 08:49
on 2010/05/04 08:49
Change comment:
There is no comment for this version
To version 6.1
edited by mawoki
on 2010/08/09 11:19
on 2010/08/09 11:19
Change comment:
There is no comment for this version
Summary
-
Page properties (2 modified, 0 added, 0 removed)
Details
- Page properties
-
- Author
-
... ... @@ -1,1 +1,1 @@ 1 -xwiki:XWiki.m florea1 +xwiki:XWiki.mawoki - Content
-
... ... @@ -1,4 +1,6 @@ 1 -{{box cssClass="floatinginfobox" title="**Contents**"}}{{toc/}}{{/box}} 1 +{{box cssClass="floatinginfobox" title="**Contents**"}} 2 +{{toc/}} 3 +{{/box}} 2 2 3 3 = Requirements = 4 4 ... ... @@ -177,7 +177,8 @@ 177 177 178 178 Removal of a space is far more easier than creating one. All it requires is the "Key" (the visible name of the space) to be provided to the remove() method. 179 179 180 -{{warning}}Please note that deletion of space removes all pages in the space too. It is recommended to always make sure that the space is empty before deleting it. 182 +{{warning}} 183 +Please note that deletion of space removes all pages in the space too. It is recommended to always make sure that the space is empty before deleting it. 181 181 {{/warning}} 182 182 183 183 {{code language="java"}} ... ... @@ -374,9 +374,7 @@ 374 374 375 375 We saw code to search a Page, create a Page and get all it's revisions. Now, we move to updating a Page. In our example, we have used the Page called "Update Page" in the "demo code" Space. The basic intent is to get the content first from XWiki. Then add our updated content or "concatenate" new content with the existing content. Then, update the final content back to XWiki. Only the methods of the Page class & the rpc.getPage() & rpc.storePage() would be used here. 376 376 377 -{{warning}} 378 -It is strongly advised that if this is the first time you are using XWiki XMLRPC, go through the examples at the start of this article. Each example tries to build up on the previous one & you would find understanding the API easier. 379 -{{/warning}} 380 +{{warning}}It is strongly advised that if this is the first time you are using XWiki XMLRPC, go through the examples at the start of this article. Each example tries to build up on the previous one & you would find understanding the API easier.{{/warning}} 380 380 381 381 {{code language="java"}} 382 382 ... ... @@ -439,12 +439,8 @@ 439 439 440 440 Removal of Pages is straight forward. You are required to know the fully qualified name of the Page i.e. SpaceName.PageName (in our example, this would be "demo code.New Page"). We test the safe deletion of the Page using a boolean variable. The rpc.removePage() method returns true if the Page was successfully removed from the wiki. 441 441 442 -{{warning}} 443 -You would need to have the deletion rights assigned to the user credentials you are passing to the rpc.login() method 444 -{{/warning}} 445 -{{warning}} 446 -rpc.removePage() method does not completely delete a Page in ordinary circumstances. If you have a recycle bin option enabled (by default, it is enabled for XWiki), then the "removed/deleted Page" is stored in the recycle bin from where it will cleaned out as per the settings for recycle bin in the xwiki.cfg file of your XWiki instance. 447 -{{/warning}} 443 +{{warning}}You would need to have the deletion rights assigned to the user credentials you are passing to the rpc.login() method{{/warning}} 444 +{{warning}}rpc.removePage() method does not completely delete a Page in ordinary circumstances. If you have a recycle bin option enabled (by default, it is enabled for XWiki), then the "removed/deleted Page" is stored in the recycle bin from where it will cleaned out as per the settings for recycle bin in the xwiki.cfg file of your XWiki instance.{{/warning}} 448 448 449 449 {{code language="java"}} 450 450 ... ... @@ -548,6 +548,66 @@ 548 548 } 549 549 {{/code}} 550 550 548 += Attachment: Add an attachment to a page = 549 + 550 +This is a simple example, how to add an attachment to a specific page. 551 + 552 +{{code language="java"}} 553 +import java.io.ByteArrayOutputStream; 554 +import java.io.File; 555 +import java.io.FileInputStream; 556 + 557 +import org.xwiki.xmlrpc.XWikiXmlRpcClient; 558 +import org.codehaus.swizzle.confluence.Attachment; 559 + 560 +public class UploadAttachment { 561 + public static void main(String[] args) { 562 + File f = new File("xwiki.txt"); // put your file HERE 563 + 564 + String url = "http://localhost:8080/xwiki/xmlrpc/confluence"; 565 + String user = "Admin"; 566 + String pass = "admin"; 567 + 568 + XWikiXmlRpcClient rpc = null; 569 + try { 570 + XWikiXmlRpcClient rpc = new XWikiXmlRpcClient(url); 571 + rpc.login(user, pass); 572 + 573 + // read file content into memory 574 + FileInputStream fis = new FileInputStream(f); 575 + ByteArrayOutputStream baos = new ByteArrayOutputStream(); 576 + byte[] buffer = new byte[8192]; 577 + int read = -1; 578 + while ((read = fis.read(buffer)) > 0) { 579 + baos.write(buffer, 0, read); 580 + } 581 + fis.close(); 582 + 583 + // prepare upload, set meta information 584 + Attachment a = new Attachment(); 585 + a.setFileName(f.getName()); 586 + a.setFileSize(Long.toString(f.length())); 587 + a.setPageId("Sandbox.WebHome"); // your page id 588 + 589 + // do upload 590 + // note: the first integer parameter has no impact, 591 + // cause it gets ignored on the server side. 592 + rpc.addAttachment(new Integer(f.getName().hashCode()), a, baos.toByteArray()); 593 + } catch (Exception e) { 594 + e.printStackTrace(); 595 + } finally { 596 + if (rpc != null) { 597 + try { 598 + rpc.logout(); 599 + } catch (Exception e2) { 600 + // something real bad happens. 601 + } 602 + } 603 + } 604 + } 605 +} 606 +{{/code}} 607 + 551 551 = User: Create A New User = 552 552 553 553 This is an Administrative function in XWiki & needs Admin privileges for the User with whose credential we connect through the XML-RPC. Creating a new User involves the following steps: