[Solved] Custom Properties for slides?

The Application Programming Interface and the OASIS Open Document Format

[Solved] Custom Properties for slides?

Postby privateRob » Thu Feb 24, 2011 7:08 pm

Hi everybody!

I know that it is possible to add custom properties to a whole document.
But is it possible to add new custom properties to each slide of a presentation (Impress)?

If this isn't possible, perhaps there is a way to add information in another way to each slide which I can read out with a java program. The data should not be modified throw the OpenOffice Presentation program itself or lost by saving a modified presentation.

thx for reading! :)
Last edited by privateRob on Fri Feb 25, 2011 9:50 pm, edited 1 time in total.
OpenOffice 3.2.1 on Ubuntu 10.10
privateRob
 
Posts: 4
Joined: Thu Feb 24, 2011 6:14 pm

Re: Custom Properties for slides?

Postby privateRob » Thu Feb 24, 2011 11:39 pm

Hi again!

I have found a solution but got still a problem when saving the presentation.
Every slide has a property called "UserDefinedAttributes". It's castable into a XNameContainer and therefore I can add AttributeData objects. If i run through the XNameContainer, I see my AttrubeData objects and everything seems to be fine. But after saving and then loading the presentation again, the "UserDefinedAttributes" are still empty. Now how do I force java to save the attributes?

This is the output I get from the code:
Code: Select all   Expand viewCollapse view
Loading Document(./presentation1.odp) : done
Slide 1
  Container is empty!
  Adding Costum DataCDATA -> Custom Data Slide 1
Slide 2
  Container is empty!
  Adding Costum DataCDATA -> Custom Data Slide 2
Saving Document(./presentation1.odp) : done
Closing Document : done


Here the code for adding costum properties to each slide of a presentation:
Code: Select all   Expand viewCollapse view
      XComponent xComponent = loadDocument(filePath);
      XDrawPagesSupplier supplier = (XDrawPagesSupplier) UnoRuntime.queryInterface(XDrawPagesSupplier.class, xComponent);
      XDrawPages pages = supplier.getDrawPages();

      for (int index = 0; index < pages.getCount(); index++) {
         XDrawPage page = (XDrawPage) UnoRuntime.queryInterface(XDrawPage.class, pages.getByIndex(index));
         XPropertySet pageProperties = UnoRuntime.queryInterface(XPropertySet.class, page);

         String slideName = (String) pageProperties.getPropertyValue("LinkDisplayName");
         System.out.println(slideName);

         Object containerObject = pageProperties.getPropertyValue("UserDefinedAttributes");
         XNameContainer container = UnoRuntime.queryInterface(XNameContainer.class, containerObject);

         if (container.hasElements()) {
            // Read custom properties
            System.out.println("  Container has " + container.getElementNames().length + " elements.");
         } else {
            System.out.println("  Container is empty!");
            try {
               AttributeData data = new AttributeData();
               data.Type = slideName;
               data.Value = "Custom Data " + slideName;
               container.insertByName(data.Type, data);
            } catch (com.sun.star.lang.IllegalArgumentException e) {
               System.err.println("XXX");
            }

            for (String key : container.getElementNames()) {
               AttributeData data = (AttributeData) container.getByName(key);
               System.out.println("  Adding Costum Data" + data.Type + " -> " + data.Value);
            }
         }
      }

      saveDocument(xComponent, filePath);
      closeDocument(xComponent);
      System.exit(0);


How I save presentations:
Code: Select all   Expand viewCollapse view
   public static boolean saveDocument(XComponent xComponent, String filePath) {
      System.out.print("Saving Document(" + filePath + ") : ");
      PropertyValue[] savingProperties = new com.sun.star.beans.PropertyValue[1];
      savingProperties[0] = new com.sun.star.beans.PropertyValue();
      savingProperties[0].Name = "Overwrite";
      savingProperties[0].Value = true;

      XStorable xStorable = (XStorable) UnoRuntime.queryInterface(XStorable.class, xComponent);
      try {
         xStorable.storeAsURL(createFilePath(filePath), savingProperties);
      } catch (IOException iOException) {
         iOException.printStackTrace();
         System.out.println("FAILED");
         return false;
      }
      System.out.println("done");
      return true;
   }
OpenOffice 3.2.1 on Ubuntu 10.10
privateRob
 
Posts: 4
Joined: Thu Feb 24, 2011 6:14 pm

Re: Custom Properties for slides?

Postby privateRob » Fri Feb 25, 2011 8:11 pm

Found the solution!!! :D :D

Will post the important code as soon as possible but first i want to make sure that nobody is still trying to find the error.
OpenOffice 3.2.1 on Ubuntu 10.10
privateRob
 
Posts: 4
Joined: Thu Feb 24, 2011 6:14 pm

Re: Custom Properties for slides?

Postby privateRob » Fri Feb 25, 2011 9:50 pm

Here I "found" the solution:
http://www.oooforum.org/forum/viewtopic ... 053#217053

The important line i forgot was:
Code: Select all   Expand viewCollapse view
propertySet.setPropertyValue("UserDefinedAttributes", container);


I took me nearly have a day to find my mistake :crazy:
OpenOffice 3.2.1 on Ubuntu 10.10
privateRob
 
Posts: 4
Joined: Thu Feb 24, 2011 6:14 pm


Return to UNO API and ODF

Who is online

Users browsing this forum: No registered users and 1 guest