Storing Documents

From Apache OpenOffice Wiki
Jump to: navigation, search

After loading an office component successfully, the returned interface is used to manipulate the component. Document specific interfaces, such as the interfaces, or are retrieved using queryInterface().

If the office component supports the interface applying to every component implementing the service, it can be stored:

  void store ( ) 
  void storeAsURL ( [in] string sURL, 
                    [in] sequence< com::sun::star::beans::PropertyValue > lArguments ) 
  void storeToURL ( [in] string sURL, 
                    [in] sequence< com::sun::star::beans::PropertyValue > lArguments ) 
  boolean hasLocation ()
  string getLocation ()
  boolean isReadonly ()

The XStorable offers the methods store(), storeAsURL() and storeToURL() for storing. The latter two methods are called with a media descriptor.

The method store() overwrites an existing file. Calling this method on a document that was created from scratch using a private:factory/... URL leads to an exception.

The other two methods storeAsURL() and storeToURL() leave the original file untouched and differ after the storing procedure. The storeToURL() method saves the current document to the desired location without touching the internal state of the document. The method storeAsURL sets the Modified attribute of the document, accessible through its interface, to false and updates the internal media descriptor of the document with the parameters passed in the call. This changes the document URL.

The following example exports a Writer document, Writer/Web document or Calc sheet to HTML.

  // Conditions: sURL      = "file:///home/target.htm" 
  //             xDocument = m_xLoadedDocument  
  // Export can be achieved by saving the document and using 
  // a special filter which can write the desired format. 
  // Normally this filter should be searched inside the filter 
  // configuration (using service 
  // but here we use well known filter names directly. 
  String sFilter = null;
  // Detect document type by asking XServiceInfo xInfo = 
  ( (, xDocument); 
  // Determine suitable HTML filter name for export.
  if(xInfo.supportsService ("") == true) 
      sFilter = new String("HTML (StarWriter)"); 
  if(xInfo.supportsService ("") == true) 
      sFilter = new String("HTML"); 
  if(xInfo.supportsService ("") == true) 
      sFilter = new String("HTML (StarCalc)");
  // Build necessary argument list for store properties. 
  // Use flag "Overwrite" to prevent exceptions, if file already exists.[] lProperties = 
  lProperties[0]       = new; 
  lProperties[0].Name  = "FilterName"; 
  lProperties[0].Value = sFilter; 
  lProperties[1]       = new; 
  lProperties[1].Name  = "Overwrite"; 
  lProperties[1].Value = new Boolean(true); xStore = 
  ( (, xDocument); 
   xStore.storeAsURL (sURL, lProperties); 

If a model is loaded or stored successfully, all parts of the media descriptor not explicitly excluded according to the media descriptor table in section MediaDescriptor must be provided by the methods getURL() and getArgs() in the interface. The separation of the URL and the other arguments is used, because the URL is the often the most wanted part for itsperformance optimized access.

Tip.png The XModel offers a method attachResource() that changes the media descriptor of the document, but this method should only be used in special cases, for example, by the implementer of a new document model and controller. The method attachResource() does not force reloading of the document. Validation checks are done when a document is loaded through MediaDescriptor. For example, if the resource is write protected, add Readonly to the MediaDescriptor and the filter name must match the data. A possible use for attachResource() could be creating a document from a template, where after loading successfully, the document's resource is changed to an "unnamed" state by deleting the URL.

Printing Documents

Printing revolves around the interface Its methods and special printing features for the various document types are described in the document chapters Printing Text Documents, Printing Spreadsheet Documents, Printing Drawing Documents and Printing Presentation Documents.

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