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

From Apache OpenOffice Wiki
Jump to: navigation, search
m (1 revision(s))
m
Line 11: Line 11:
  
 
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:
 
+
<source lang="idl">
 
   void store ( )  
 
   void store ( )  
 
   void storeAsURL ( [in] string sURL,  
 
   void storeAsURL ( [in] string sURL,  
Line 20: Line 20:
 
   string getLocation ()
 
   string getLocation ()
 
   boolean isReadonly ()
 
   boolean isReadonly ()
 
+
</source>
 
The <code>XStorable</code> offers the methods <code>store()</code>, <code>storeAsURL()</code> and <code>storeToURL()</code> for storing. The latter two methods are called with a media descriptor.
 
The <code>XStorable</code> offers the methods <code>store()</code>, <code>storeAsURL()</code> and <code>storeToURL()</code> for storing. The latter two methods are called with a media descriptor.
  
Line 29: Line 29:
 
The following example exports a Writer document, Writer/Web document or Calc sheet to HTML.  
 
The following example exports a Writer document, Writer/Web document or Calc sheet to HTML.  
 
<!--[SOURCE:OfficeDev/DesktopEnvironment/FunctionHelper.java]-->
 
<!--[SOURCE:OfficeDev/DesktopEnvironment/FunctionHelper.java]-->
 
+
<source lang="java">
 
   // Conditions: sURL      = "file:///home/target.htm"  
 
   // Conditions: sURL      = "file:///home/target.htm"  
 
   //            xDocument = m_xLoadedDocument   
 
   //            xDocument = m_xLoadedDocument   
Line 73: Line 73:
 
   xStore.storeAsURL (sURL, lProperties);  
 
   xStore.storeAsURL (sURL, lProperties);  
 
   }
 
   }
 
+
</source>
 
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 [[Documentation/DevGuide/OfficeDev/Handling Documents#MediaDiscriptor|MediaDescriptor]] must be provided by the methods <code>getURL()</code> and <code>getArgs()</code> in the <idl>com.sun.star.frame.XModel</idl> 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.  
 
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 [[Documentation/DevGuide/OfficeDev/Handling Documents#MediaDiscriptor|MediaDescriptor]] must be provided by the methods <code>getURL()</code> and <code>getArgs()</code> in the <idl>com.sun.star.frame.XModel</idl> 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.  
  

Revision as of 17:14, 24 March 2008



After loading an office component successfully, the returned interface cis 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