Obtaining Content Properties

From Apache OpenOffice Wiki
Jump to: navigation, search

A UCB content maintains a set of properties. It supports the command "getPropertyValues", that obtains one or more property values from a content. This command takes a sequence of com.sun.star.beans.Property and returns an implementation of the interface com.sun.star.sdbc.XRow that is similar to a row of a JDBC resultset. To obtain property values from a UCB content:

  1. Define a sequence of properties you want to obtain the values for.
  2. Let the UCB content execute the command "getPropertyValues".
  3. Obtain the property values from the returned row object.

The following example demonstrates the use of content properties. Note that the method executeCommand() is used from the example above to execute the "getPropertyValues" command that takes a command name and creates a com.sun.star.ucb.Command struct from it:

  import com.sun.star.ucb.*;
  import com.sun.star.sdbc.XRow;
  import com.sun.star.beans.Property;
      XContent xContent = ...
      // Obtain value of the string property Title and the boolean property
      // IsFolder from xContent...
      // Define property sequence.
      Property[] aProps = new Property[2];
      Property prop1 = new Property();
      prop1.Name = "Title";
      prop1.Handle = -1;// n/a
      aProps[0] = prop1;
      Property prop2 = new Property();
      prop2.Name = "IsFolder";
      prop2.Handle = -1;// n/a
      aProps[1] = prop2;
      XRow xValues;
      try {
          // Execute command "getPropertyValues" 
          // using helper method executeCommand (see [CHAPTER:UCB.Using.Commands])
          xValues = executeCommand(xContent, "getPropertyValues", aProps);
      catch (com.sun.star.ucb.CommandAbortedException e) {
          ... error ...
      catch ( com.sun.star.uno.Exception e ) {
          ... error ...
      // Extract values from row object. Note that the
      // first column is 1, not 0.
      // Title: Obtain value of column 1 as string.
      String aTitle = xValues.getString(1));
      if (aTitle.length() == 0 && xValues.wasNull())
          ... error ...
      // IsFolder: Obtain value of column 2 as boolean.
      boolean bFolder = xValues.getBoolean(2);
      if (!bFolder && xValues.wasNull())
          ... error ...

The returned row for the content above has two columns Title and IsFolder, and could contain the following data. The column values are retrieved using the getXXX methods of the com.sun.star.sdbc.XRow interface. The command "getPropertyValues" always returns a single row for contents.

Title IsFolder
"MyFolder" TRUE
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages