Difference between revisions of "Documentation/DevGuide/OfficeDev/Storing Documents"

From Apache OpenOffice Wiki
Jump to: navigation, search
m (FINAL VERSION FOR L10N)
m (fixed a typo.)
Line 9: Line 9:
 
  {{DISPLAYTITLE:Storing Documents}}
 
  {{DISPLAYTITLE:Storing Documents}}
 
<!--<idltopic>com.sun.star.frame.XStorable</idltopic>-->
 
<!--<idltopic>com.sun.star.frame.XStorable</idltopic>-->
After loading an office component successfully, the returned interface cis used to manipulate the component. Document specific interfaces, such as the interfaces <idl>com.sun.star.text.XTextDocument</idl>, <idl>com.sun.star.sheet.XSpreadsheetDocument</idl> or <idl>com.sun.star.drawing.XDrawPagesSupplier</idl> are retrieved using <code>queryInterface()</code>.  
+
After loading an office component successfully, the returned interface is used to manipulate the component. Document specific interfaces, such as the interfaces <idl>com.sun.star.text.XTextDocument</idl>, <idl>com.sun.star.sheet.XSpreadsheetDocument</idl> or <idl>com.sun.star.drawing.XDrawPagesSupplier</idl> are retrieved using <code>queryInterface()</code>.  
  
 
If the office component supports the <idl>com.sun.star.frame.XStorable</idl> interface applying to every component implementing the service <idl>com.sun.star.document.OfficeDocument</idl>, it can be stored:
 
If the office component supports the <idl>com.sun.star.frame.XStorable</idl> interface applying to every component implementing the service <idl>com.sun.star.document.OfficeDocument</idl>, it can be stored:

Revision as of 19:01, 29 December 2009



After loading an office component successfully, the returned interface is used to manipulate the component. Document specific interfaces, such as the interfaces com.sun.star.text.XTextDocument, com.sun.star.sheet.XSpreadsheetDocument or com.sun.star.drawing.XDrawPagesSupplier are retrieved using queryInterface().

If the office component supports the com.sun.star.frame.XStorable interface applying to every component implementing the service com.sun.star.document.OfficeDocument, 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 com.sun.star.util.XModifiable 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 com.sun.star.document.FilterFactory) 
  // but here we use well known filter names directly. 
  String sFilter = null;
 
  // Detect document type by asking XServiceInfo
   com.sun.star.lang.XServiceInfo xInfo = 
  (com.sun.star.lang.XServiceInfo)UnoRuntime.queryInterface ( 
   com.sun.star.lang.XServiceInfo.class, xDocument); 
  // Determine suitable HTML filter name for export.
  if(xInfo!=null) 
  { 
  if(xInfo.supportsService ("com.sun.star.text.TextDocument") == true) 
      sFilter = new String("HTML (StarWriter)"); 
  else 
  if(xInfo.supportsService ("com.sun.star.text.WebDocument") == true) 
      sFilter = new String("HTML"); 
  else 
  if(xInfo.supportsService ("com.sun.star.sheet.SpreadsheetDocument") == true) 
      sFilter = new String("HTML (StarCalc)");
  } 
  if(sFilter!=null) 
  { 
  // Build necessary argument list for store properties. 
  // Use flag "Overwrite" to prevent exceptions, if file already exists. 
  com.sun.star.beans.PropertyValue[] lProperties = 
      new com.sun.star.beans.PropertyValue[2]; 
  lProperties[0]       = new com.sun.star.beans.PropertyValue(); 
  lProperties[0].Name  = "FilterName"; 
  lProperties[0].Value = sFilter; 
  lProperties[1]       = new com.sun.star.beans.PropertyValue(); 
  lProperties[1].Name  = "Overwrite"; 
  lProperties[1].Value = new Boolean(true);  
 
   com.sun.star.frame.XStorable xStore = 
  (com.sun.star.frame.XStorable)UnoRuntime.queryInterface (
        com.sun.star.frame.XStorable.class, 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 com.sun.star.frame.XModel 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.

Template:Documentation/Tip

Printing Documents

Printing revolves around the interface com.sun.star.view.XPrintable. 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