Difference between revisions of "Documentation/DevGuide/Text/Saving Text Documents"

From Apache OpenOffice Wiki
Jump to: navigation, search
m
 
(One intermediate revision by the same user not shown)
Line 10: Line 10:
 
<!--<idltopic>com.sun.star.frame.XStorable</idltopic>-->
 
<!--<idltopic>com.sun.star.frame.XStorable</idltopic>-->
 
Documents are storable through their interface <idl>com.sun.star.frame.XStorable</idl>. This interface is discussed in detail in [[Documentation/DevGuide/OfficeDev/Office Development|Office Development]]. An <code>XStorable</code> implements these operations:
 
Documents are storable through their interface <idl>com.sun.star.frame.XStorable</idl>. This interface is discussed in detail in [[Documentation/DevGuide/OfficeDev/Office Development|Office Development]]. An <code>XStorable</code> implements these operations:
<source lang="idl">
+
<syntaxhighlight lang="idl">
 
   boolean hasLocation()
 
   boolean hasLocation()
 
   string getLocation()
 
   string getLocation()
Line 17: Line 17:
 
   void storeAsURL( [in] string aURL, sequence< com::sun::star::beans::PropertyValue > aArgs)
 
   void storeAsURL( [in] string aURL, sequence< com::sun::star::beans::PropertyValue > aArgs)
 
   void storeToURL( [in] string aURL, sequence< com::sun::star::beans::PropertyValue > aArgs)  
 
   void storeToURL( [in] string aURL, sequence< com::sun::star::beans::PropertyValue > aArgs)  
</source>
+
</syntaxhighlight>
 
The method names are evident. The method <code>storeAsUrl()</code> is the exact representation of '''File - Save As''', that is, it changes the current document location. In contrast, <code>storeToUrl()</code> stores a copy to a new location, but leaves the current document URL untouched.  
 
The method names are evident. The method <code>storeAsUrl()</code> is the exact representation of '''File - Save As''', that is, it changes the current document location. In contrast, <code>storeToUrl()</code> stores a copy to a new location, but leaves the current document URL untouched.  
  
Line 23: Line 23:
  
 
For exporting purposes, a filter name can be passed to <code>storeAsURL()</code> and <code>storeToURL()</code> that triggers an export to other file formats. The property needed for this purpose is the string argument <code>FilterName</code> that takes filter names defined in the configuration file:
 
For exporting purposes, a filter name can be passed to <code>storeAsURL()</code> and <code>storeToURL()</code> that triggers an export to other file formats. The property needed for this purpose is the string argument <code>FilterName</code> that takes filter names defined in the configuration file:
<source lang="xml">
+
<syntaxhighlight lang="xml">
 
   <OfficePath>\share\config\registry\instance\org\openoffice\Office\TypeDetection.xml
 
   <OfficePath>\share\config\registry\instance\org\openoffice\Office\TypeDetection.xml
 
</source>
 
</source>
Line 35: Line 35:
 
     <Data cfg:type="string">3,writer_MS_Word_97,com.sun.star.text.TextDocument,,67,CWW8,0,,</Data>  
 
     <Data cfg:type="string">3,writer_MS_Word_97,com.sun.star.text.TextDocument,,67,CWW8,0,,</Data>  
 
   </Filter>
 
   </Filter>
</source>
+
</syntaxhighlight>
 
The following method stores a document using this filter:  
 
The following method stores a document using this filter:  
 
<!--[SOURCE:Text/TextDocuments.java]-->
 
<!--[SOURCE:Text/TextDocuments.java]-->
<source lang="java">
+
<syntaxhighlight lang="java">
 
   /** Store a document, using the MS Word 97/2000/XP Filter */
 
   /** Store a document, using the MS Word 97/2000/XP Filter */
 
       protected void storeDocComponent(XComponent xDoc, String storeUrl) throws java.lang.Exception {
 
       protected void storeDocComponent(XComponent xDoc, String storeUrl) throws java.lang.Exception {
Line 49: Line 49:
 
           xStorable.storeAsURL(storeUrl, storeProps);  
 
           xStorable.storeAsURL(storeUrl, storeProps);  
 
       }  
 
       }  
</source>
+
</syntaxhighlight>
If an empty array of <code>PropertyValue</code> structs is passed, the native ''.odt'' format of {{PRODUCTNAME}} is used.
+
If an empty array of <code>PropertyValue</code> structs is passed, the native ''.odt'' format of {{AOo}} is used.
  
 
{{PDL1}}
 
{{PDL1}}
  
 
[[Category:Documentation/Developer's Guide/Text Documents]]
 
[[Category:Documentation/Developer's Guide/Text Documents]]

Latest revision as of 13:43, 3 January 2021



Storing

Documents are storable through their interface com.sun.star.frame.XStorable. This interface is discussed in detail in Office Development. An XStorable implements these operations:

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

The method names are evident. The method storeAsUrl() is the exact representation of File - Save As, that is, it changes the current document location. In contrast, storeToUrl() stores a copy to a new location, but leaves the current document URL untouched.

Exporting

For exporting purposes, a filter name can be passed to storeAsURL() and storeToURL() that triggers an export to other file formats. The property needed for this purpose is the string argument FilterName that takes filter names defined in the configuration file:

  <OfficePath>\share\config\registry\instance\org\openoffice\Office\TypeDetection.xml
</source>
In ''TypeDetection.xml'', look for <code><Filter/></code> elements, their <code>cfg:name</code> attribute contains the needed strings for <code>FilterName</code>. The proper filter name for StarWriter 5.x is "StarWriter 5.0", and the export format "MS Word 97" is also popular. This is the element in ''TypeDetection.xml'' that describes the MS Word 97 filter:
<source lang="xml">
  <Filter cfg:name="MS Word 97">
     <Installed cfg:type="boolean">true</Installed> 
     <UIName cfg:type="string" cfg:localized="true">
       <cfg:value xml:lang="en-US">Microsoft Word 97/2000/XP</cfg:value> 
     </UIName>
     <Data cfg:type="string">3,writer_MS_Word_97,com.sun.star.text.TextDocument,,67,CWW8,0,,</Data> 
  </Filter>

The following method stores a document using this filter:

  /** Store a document, using the MS Word 97/2000/XP Filter */
      protected void storeDocComponent(XComponent xDoc, String storeUrl) throws java.lang.Exception {
  
          XStorable xStorable = (XStorable)UnoRuntime.queryInterface(XStorable.class, xDoc);
          PropertyValue[] storeProps = new PropertyValue[1];
          storeProps[0] = new PropertyValue();
          storeProps[0].Name = "FilterName";
          storeProps[0].Value = "MS Word 97"; 
          xStorable.storeAsURL(storeUrl, storeProps); 
      }

If an empty array of PropertyValue structs is passed, the native .odt format of Apache OpenOffice is used.

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