Folders
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:
- Fill the com.sun.star.ucb.OpenCommandArgument2 structure according to your requirements.
- Let the UCB content execute the "
open
" command. - 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). |