Changes for page XML-RPC Java Examples

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

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

Summary

Details

Page properties
Content
... ... @@ -487,13 +487,12 @@
487 487  
488 488  {{/code}}
489 489  
490 -= Page: List And Add Tags =
490 += Page: List Tags =
491 491  
492 492  Pages are tagged via objects of type XWiki.TagClass. Thus you can switch to object edit mode on any page and edit tags this way. This is also the way, done by XMLRPC-API.
493 493  
494 494  {{code language="java"}}
495 495  import java.net.MalformedURLException;
496 -import java.util.ArrayList;
497 497  import java.util.List;
498 498  
499 499  import org.apache.xmlrpc.XmlRpcException;
... ... @@ -501,7 +501,7 @@
501 501  import org.xwiki.xmlrpc.model.XWikiObject;
502 502  import org.xwiki.xmlrpc.model.XWikiObjectSummary;
503 503  
504 -public class ListAndAddTags {
503 +public class ListTags {
505 505   public static void main(String[] args) throws MalformedURLException,
506 506   XmlRpcException {
507 507  
... ... @@ -521,7 +521,6 @@
521 521  
522 522   // retrieve current page object informations
523 523   XWikiObject xwo = rpc.getObject(xosum);
524 - // The tags are one String, separated by | or , or 'SPACE'
525 525   List<String> tags = (List<String>) xwo.getProperty("tags");
526 526   System.out.println("--- CURRENT TAGS -----------------------");
527 527   for (String tag : tags) {
... ... @@ -528,28 +528,7 @@
528 528   System.out.println(tag);
529 529   }
530 530   } catch (Exception e) {
531 - // may be it's
532 - // "Failed to invoke method getObject in class
533 - // com.xpn.xwiki.xmlrpc.XWikiXmlRpcApiImpl: [Unable to find
534 - // object XWiki.TagClass[0] on page 'Sandbox.Wdscfaq']"
535 - // This means: no tags already given.
536 536   System.out.println(e.getMessage());
537 - }
538 - // try to place a new tag.
539 - try {
540 - System.out.println("--- NEW TAG -----------------------");
541 - // add a new random tag
542 - String tag = "NOW"+System.currentTimeMillis();
543 - System.out.println(tag);
544 - List<String> tags = new ArrayList<String>();
545 - tags.add(tag);
546 - XWikiObject xwo = new XWikiObject();
547 - xwo.setProperty("tags", tags);
548 - xwo.setPageId(pageId);
549 - xwo.setClassName("XWiki.TagClass");
550 - rpc.storeObject(xwo);
551 - } catch (XmlRpcException e) {
552 - System.out.println(e.getMessage());
553 553   } finally {
554 554   rpc.logout();
555 555   }
... ... @@ -557,6 +557,10 @@
557 557  }
558 558  {{/code}}
559 559  
537 += Page: Add Tags =
538 +
539 +{{code language="java"}}{{/code}}
540 +
560 560  = Attachment: List Attachments For Page =
561 561  
562 562  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.

Get Connected