From Apache OpenOffice Wiki
Jump to: navigation, search

A UCB content that implements the interface acts as a factory for new resources. For example, a file system folder can be a creator for other file system folders and files.

A new content object created by the implementation can be considered as an empty hull for a content object of a special type. This new content object has to be filled with some property values to become fully functional. For example, a file system folder could require a name, represented by the property Title in the UCB. The interface offers ways to determine what contents can be created and what properties need to be set. Information can be obtained on the general type, such as FOLDER, DOCUMENT, or LINK, of the objects. After the required property values are set, the creation process needs to be committed by using the command "insert". Note that this command is always executed by the new content, not by the content creator, because the creator is not necessarily the parent of the new content. The flag ReplaceExisting in the "insert" argument usually is false, because the caller does not want to destroy an already existing resource. The "insert" command implementation makes the new content persistent in the appropriate storage medium.

To create a new resource:

  1. Obtain the interface from a suitable UCB content.
  2. Call createNewContent() at the content creator. Supply information on the type of content to create with the arguments. The argument expected is a struct.
  3. Obtain and set the property values that are mandatory for the content just created.
  4. Let the new content execute the command "insert" to complete the creation process.

Creating a new resource:

      XContent xContent = ...
      // Create a new file system file object...
      // Obtain content creator interface.
      XContentCreator xCreator = (XContentCreator)UnoRuntime.queryInterface( 
          XContentCreator.class, xContent);
      // Note: The data for aInfo may have been obtained using
      // XContentCreator::queryCreatableContentsInfo().
      // A number of possible types is listed below
      ContentInfo aInfo = new ContentInfo();
      aInfo.Type = "application/vnd.sun.staroffice.fsys-file";
      aInfo.Attributes = 0;
      // Create new, empty content.
      XContent xNewContent = xCreator.createNewContent(aInfo);
      if (xNewContent == null)
          ... error ...
      // Set mandatory properties...
      // Obtain a name for the new file.
      String aFilename = ...
      // Define property value sequence.
      PropertyValue[] aProps = new PropertyValue[1];
      PropertyValue aProp = new PropertyValue;
      aProp.Name = "Title";
      aProp.Handle = -1; // n/a
      aProp.Value = aFilename;
      aProps[ 0 ] = aProp;
      try {
          // Execute command "setPropertyValues".
          // using helper method executeCommand (see [CHAPTER:UCB.Using.Commands])
          executeCommand(xNewContent, "setPropertyValues",aProps);
      catch ( e) {
          ... error ...
      catch ( e) {
          ... error ...
      // Write the new file to disk...
      // Obtain document data for the new file.
      XInputStream xData = ...
      // Fill argument structure...
      InsertCommandArgument aArg = new InsertCommandArgument();
      aArg.Data = xData;
      aArg.ReplaceExisting = false;
      try {
          // Execute command "insert".
          executeCommand(xNewContent, "insert", aArg);
      catch ( e) {
          ... error ...
      catch ( e) {
          ... error ...

Appendix C Universal Content Providers discusses the creation of contents for all available UCPs. The table below shows a number of types for creatable contents. Additionally, you can ask the content creator for its creatable contents using queryCreatableContentsInfo(). The UCB reference in the SDK and on offers comprehensive information about creatable contents.

Data source Content Info Type Content Content Service that Creates the Contents
FILE "application/vnd.sun.staroffice.fsys-folder" folder
"application/vnd.sun.staroffice.fsys-file" document
WebDAV and HTTP "application/" folder
"application/http-content" document
FTP "application/vnd.sun.staroffice.ftp-folder" folder
"application/vnd.sun.staroffice.ftp-file" document
Hierarchy "application/" folder
"application/" Link
ZIP and JAR files "application/" folder
"application/" document
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages