Changes for page XML-RPC Java Examples

Last modified by Thomas Mortagne on 2023/10/10 14:31

From version 12.1
edited by mawoki
on 2010/08/09 13:29
Change comment: There is no comment for this version
To version 13.1
edited by mawoki
on 2010/08/09 14:40
Change comment: There is no comment for this version

Summary

Details

Page properties
Content
... ... @@ -536,6 +536,55 @@
536 536  
537 537  = Page: Add Tags =
538 538  
539 +Adding tags is a similar procedure to listening them. There are two starting points: a) retrieve current tags and a new one or b) set entirely new ones at once. Most often, you want to add tags, so this is one way to do it ...
540 +{{code language="java"}}import java.net.MalformedURLException;
541 +import java.util.List;
542 +
543 +import org.apache.xmlrpc.XmlRpcException;
544 +import org.xwiki.xmlrpc.XWikiXmlRpcClient;
545 +import org.xwiki.xmlrpc.model.XWikiObject;
546 +import org.xwiki.xmlrpc.model.XWikiObjectSummary;
547 +
548 +public class AddTags {
549 + public static void main(String[] args) throws MalformedURLException, XmlRpcException {
550 +
551 + String url = "http://localhost:8080/xwiki/xmlrpc/confluence";
552 + String user = "Admin";
553 + String pass = "admin";
554 +
555 + XWikiXmlRpcClient rpc = new XWikiXmlRpcClient(url);
556 + XWikiObjectSummary xosum = new XWikiObjectSummary();
557 + xosum.setClassName("XWiki.TagClass");
558 + // your page id
559 + String pageId = "Sandbox.Wdscfaq";
560 + xosum.setPageId(pageId);
561 + try {
562 + // Perform Login & Authentication
563 + rpc.login(user, pass);
564 +
565 + // retrieve current page object informations
566 + XWikiObject xwo = rpc.getObject(xosum);
567 + List<String> tags = (List<String>) xwo.getProperty("tags");
568 + System.out.println("--- CURRENT TAGS -----------------------");
569 + for (String tag : tags) {
570 + System.out.println(tag);
571 + }
572 + System.out.println("--- NEW TAG -----------------------");
573 + // add a new random tag
574 + String tag = "NOW"+System.currentTimeMillis();
575 + System.out.println(tag);
576 + tags.add(tag);
577 + rpc.storeObject(xwo);
578 + } catch (XmlRpcException e) {
579 + System.out.println(e.getMessage());
580 + } finally {
581 + rpc.logout();
582 + }
583 + }
584 +}{{/code}}
585 +
586 += Page: Add Tags =
587 +
539 539  {{code language="java"}}{{/code}}
540 540  
541 541  = Attachment: List Attachments For Page =

Get Connected