From Apache OpenOffice Wiki
Jump to: navigation, search

Accessing the Children of a Folder

A UCB content that is a folder, that is, the value of the required property IsFolder is true, supports the command "open". This command takes an argument of type The value returned is an implementation of the service This DynamicResultSet holds the children of the folder and is a result set that can notify registered listeners about changes. To retrieve data from it, call getStaticResultSet() at its interface. The static result set is a that can be seen as a table, where each row contains a child content of the folder. Use the appropriate methods of to navigate through the rows:

  boolean first()
  boolean last()
  boolean next()
  boolean previous()
  boolean absolute( [in] long row) 
  boolean relative( [in] long rows)
  void afterLast()
  void beforeFirst()
  boolean isBeforeFirst()
  boolean isAfterLast()
  boolean isFirst()
  boolean isLast()
  long getRow()

The child contents are accessed by traveling to the appropriate row and using the interface, which is implemented by the returned result set:

  com::sun::star::ucb::XContent queryContent()
  string queryContentIdentifierString()
  com::sun::star::ucb::XContentIdentifier queryContentIdentifier()

You may supply a sequence of as part of the argument of the "open" command. In this case, the resultset contains one column for each property value that is requested. The property values are accessed by traveling to the appropriate row and calling methods of the interface Refer to the documentation of for more information about other parameters that can be passed to the "open" command.

To access the children of a UCB content:

  1. Fill the structure according to your requirements.
  2. Let the UCB content execute the "open" command.
  3. Access the children and the requested property values using the returned dynamic result set.

Accessing the children of a UCB folder content:

      XContent xContent = ...
      // Open a folder content, request property values for the string
      // property Title and the boolean property IsFolder...
      // Fill argument structure...
      OpenCommandArgument2 aArg = new OpenCommandArgument2();
      aArg.Mode = OpenMode.ALL;// FOLDER, DOCUMENTS -> simple filter
      aArg.Priority = 32768;// Ignored by most implementations
      // Fill info for the properties wanted.
      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;
      aArg.Properties = aProps;
      XDynamicResultSet xSet;
      try {
          // Execute command "open".
          // using helper method executeCommand (see [CHAPTER:UCB.Using.Commands].
          xSet = executeCommand(xContent, "open", aArg);
      catch ( e) {
          ... error ...
      catch ( e) {
          ... error ...
      XResultSet xResultSet = xSet.getStaticResultSet();
      // Iterate over children, access children and property values...
      try {
          // Move to begin.
          if (xResultSet.first()) {
              // obtain XContentAccess interface for child content access and XRow for properties
              XContentAccess xContentAccess = (XContentAccess)UnoRuntime.queryInterface( 
              XContentAccess.class, xResultSet);
              XRow xRow = (XRow)UnoRuntime.queryInterface(XRow.class, xResultSet);
              do {
                  // Obtain URL of child.
                  String aId = xContentAccess.queryContentIdentifierString();
                  // First column: Title (column numbers are 1-based!)
                  String aTitle = xRow.getString(1);
                  if (aTitle.length() == 0 && xRow.wasNull())
                      ... error ...
                  // Second column: IsFolder
                  boolean bFolder = xRow.getBoolean(2);
                  if (!bFolder && xRow.wasNull())
                      ... error ...
              } while ( // next child
      catch ( e) {
          ... error ...
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages