Changes for page XML-RPC Java Examples
Last modified by Thomas Mortagne on 2023/10/10 14:31
Summary
-
Page properties (1 modified, 0 added, 0 removed)
Details
- Page properties
-
- Content
-
... ... @@ -487,7 +487,57 @@ 487 487 488 488 {{/code}} 489 489 490 += Page: List And Add Tags = 490 490 492 +{{code language="java"}} 493 +import java.net.MalformedURLException; 494 +import java.util.List; 495 + 496 +import org.apache.xmlrpc.XmlRpcException; 497 +import org.xwiki.xmlrpc.XWikiXmlRpcClient; 498 +import org.xwiki.xmlrpc.model.XWikiObject; 499 +import org.xwiki.xmlrpc.model.XWikiObjectSummary; 500 + 501 +public class ListAndAddTags { 502 + public static void main(String[] args) throws MalformedURLException, 503 + XmlRpcException { 504 + 505 + String url = "http://localhost:8080/xwiki/xmlrpc/confluence"; 506 + String user = "Admin"; 507 + String pass = "admin"; 508 + 509 + XWikiXmlRpcClient rpc = new XWikiXmlRpcClient(url); 510 + try { 511 + // Perform Login & Authentication 512 + rpc.login(user, pass); 513 + 514 + XWikiObjectSummary xosum = new XWikiObjectSummary(); 515 + xosum.setClassName("XWiki.TagClass"); 516 + // your page id 517 + xosum.setPageId("Sandbox.WebHome"); 518 + // retrieve current page object informations 519 + XWikiObject xwo = rpc.getObject(xosum); 520 + // The tags are one String, separated by | or , or 'SPACE' 521 + List<String> tags = (List<String>) xwo.getProperty("tags"); 522 + System.out.println("--- CURRENT TAGS -----------------------"); 523 + for (String tag : tags) { 524 + System.out.println(tag); 525 + } 526 + System.out.println("--- NEW TAG -----------------------"); 527 + // add a new random tag 528 + String tag = "NOW"+System.currentTimeMillis(); 529 + System.out.println(tag); 530 + tags.add(tag); 531 + rpc.storeObject(xwo); 532 + } catch (XmlRpcException e) { 533 + System.out.println(e.getMessage()); 534 + } finally { 535 + rpc.logout(); 536 + } 537 + } 538 +} 539 +{{/code}} 540 + 491 491 = Attachment: List Attachments For Page = 492 492 493 493 So far, we worked with the Spaces (which are like directories/folders), Pages (which are the actual documents inside directories/folders). Both, Spaces & Pages can reside on their own & still be meaningful. However, there are other entities such as Attachments/Comments which are meaningful only when attached to Pages.