Difference between revisions of "Documentation/DevGuide/UCB/Folders"

From Apache OpenOffice Wiki
Jump to: navigation, search
m (Robot: Changing Category:Universal Content Broker)
 
(2 intermediate revisions by one other user not shown)
Line 5: Line 5:
 
|NextPage=Documentation/DevGuide/UCB/Documents
 
|NextPage=Documentation/DevGuide/UCB/Documents
 
}}
 
}}
{{DISPLAYTITLE:Folders}}
+
{{Documentation/DevGuideLanguages|Documentation/DevGuide/UCB/{{SUBPAGENAME}}}}
 +
{{DISPLAYTITLE:Folders}}
 
=== Accessing the Children of a Folder ===
 
=== Accessing the Children of a Folder ===
  
 
<!--<idltopic>com.sun.star.ucb.OpenCommandArgument2;com.sun.star.ucb.DynamicResultSet</idltopic>-->
 
<!--<idltopic>com.sun.star.ucb.OpenCommandArgument2;com.sun.star.ucb.DynamicResultSet</idltopic>-->
 
A UCB content that is a folder, that is, the value of the required property <code>IsFolder</code> is true, supports the command "<code>open</code>". This command takes an argument of type <idl>com.sun.star.ucb.OpenCommandArgument2</idl>. The value returned is an implementation of the service <idl>com.sun.star.ucb.DynamicResultSet</idl>. This <code>DynamicResultSet</code> holds the children of the folder and is a result set that can notify registered listeners about changes. To retrieve data from it, call <code>getStaticResultSet()</code> at its <idl>com.sun.star.ucb.XDynamicResultSet</idl> interface. The static result set is a <idl>com.sun.star.sdbc.XResultSet</idl> that can be seen as a table, where each row contains a child content of the folder. Use the appropriate methods of <idl>com.sun.star.sdbc.XResultSet</idl> to navigate through the rows:
 
A UCB content that is a folder, that is, the value of the required property <code>IsFolder</code> is true, supports the command "<code>open</code>". This command takes an argument of type <idl>com.sun.star.ucb.OpenCommandArgument2</idl>. The value returned is an implementation of the service <idl>com.sun.star.ucb.DynamicResultSet</idl>. This <code>DynamicResultSet</code> holds the children of the folder and is a result set that can notify registered listeners about changes. To retrieve data from it, call <code>getStaticResultSet()</code> at its <idl>com.sun.star.ucb.XDynamicResultSet</idl> interface. The static result set is a <idl>com.sun.star.sdbc.XResultSet</idl> that can be seen as a table, where each row contains a child content of the folder. Use the appropriate methods of <idl>com.sun.star.sdbc.XResultSet</idl> to navigate through the rows:
  <source lang="idl">
+
<syntaxhighlight lang="idl">
 
   boolean first()
 
   boolean first()
 
   boolean last()
 
   boolean last()
Line 24: Line 25:
 
   boolean isLast()
 
   boolean isLast()
 
   long getRow()
 
   long getRow()
  </source>
+
</syntaxhighlight>
 
The child contents are accessed by traveling to the appropriate row and using the interface <idl>com.sun.star.ucb.XContentAccess</idl>, which is implemented by the returned result set:
 
The child contents are accessed by traveling to the appropriate row and using the interface <idl>com.sun.star.ucb.XContentAccess</idl>, which is implemented by the returned result set:
  <source lang="idl">
+
<syntaxhighlight lang="idl">
 
   com::sun::star::ucb::XContent queryContent()
 
   com::sun::star::ucb::XContent queryContent()
 
   string queryContentIdentifierString()
 
   string queryContentIdentifierString()
 
   com::sun::star::ucb::XContentIdentifier queryContentIdentifier()
 
   com::sun::star::ucb::XContentIdentifier queryContentIdentifier()
  </source>
+
</syntaxhighlight>
You may supply a sequence of <idl>com.sun.star.beans.Property</idl> as part of the argument of the "<code>open</code>" 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 <idl>com.sun.star.sdbc.XRow</idl>. Refer to the documentation of <idl>com.sun.star.ucb.OpenCommandArgument2</idl> for more information about other parameters that can be passed to the "<code>open</code>" command.
+
You may supply a sequence of <idl>com.sun.star.beans.Property</idl> as part of the argument of the "<code>open</code>" command. In this case, the result set 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 <idl>com.sun.star.sdbc.XRow</idl>. Refer to the documentation of <idl>com.sun.star.ucb.OpenCommandArgument2</idl> for more information about other parameters that can be passed to the "<code>open</code>" command.
  
 
To access the children of a UCB content:
 
To access the children of a UCB content:
Line 40: Line 41:
 
Accessing the children of a UCB folder content:  
 
Accessing the children of a UCB folder content:  
 
<!--[SOURCE:UCB/ChildrenRetriever.java]-->
 
<!--[SOURCE:UCB/ChildrenRetriever.java]-->
  <source lang="java">
+
<syntaxhighlight lang="java">
 
   import com.sun.star.uno.UnoRuntime;
 
   import com.sun.star.uno.UnoRuntime;
 
   import com.sun.star.ucb.*;
 
   import com.sun.star.ucb.*;
Line 118: Line 119:
 
       }
 
       }
 
   }
 
   }
  </source>
+
</syntaxhighlight>
 
{{PDL1}}
 
{{PDL1}}
  
[[Category:Documentation/Developers Guide/Universal Content Broker]]
+
[[Category:Documentation/Developer's Guide/Universal Content Broker]]

Latest revision as of 16:12, 21 December 2020



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 com.sun.star.ucb.OpenCommandArgument2. The value returned is an implementation of the service com.sun.star.ucb.DynamicResultSet. 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 com.sun.star.ucb.XDynamicResultSet interface. The static result set is a com.sun.star.sdbc.XResultSet that can be seen as a table, where each row contains a child content of the folder. Use the appropriate methods of com.sun.star.sdbc.XResultSet 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 com.sun.star.ucb.XContentAccess, 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 com.sun.star.beans.Property as part of the argument of the "open" command. In this case, the result set 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 com.sun.star.sdbc.XRow. Refer to the documentation of com.sun.star.ucb.OpenCommandArgument2 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 com.sun.star.ucb.OpenCommandArgument2 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:

  import com.sun.star.uno.UnoRuntime;
  import com.sun.star.ucb.*;
  import com.sun.star.sdbc.XResultSet;
  import com.sun.star.sdbc.XRow;
 
  {
      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 (com.sun.star.ucb.CommandAbortedException e) {
          ... error ...
      }
      catch (com.sun.star.uno.Exception 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 (xResultSet.next()) // next child
          }
      }
      catch (com.sun.star.ucb.ResultSetException e) {
          ... error ...
      }
  }
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages