xref: /AOO42X/main/qadevOOo/runner/convwatch/GraphicalDifferenceCheck.java (revision ef39d40d3f5e66cf3f035b3e93783012b340500d)
1*ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ef39d40dSAndrew Rist  * distributed with this work for additional information
6*ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9*ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15*ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18*ef39d40dSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*ef39d40dSAndrew Rist  *************************************************************/
21*ef39d40dSAndrew Rist 
22*ef39d40dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package convwatch;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import convwatch.GraphicalTestArguments;
27cdf0e10cSrcweir import convwatch.OfficePrint;
28cdf0e10cSrcweir import convwatch.ConvWatchCancelException;
29cdf0e10cSrcweir import convwatch.FileHelper;
30cdf0e10cSrcweir import java.io.File;
31cdf0e10cSrcweir 
32cdf0e10cSrcweir import helper.URLHelper;
33cdf0e10cSrcweir import com.sun.star.lang.XComponent;
34cdf0e10cSrcweir import com.sun.star.frame.XStorable;
35cdf0e10cSrcweir import com.sun.star.beans.PropertyValue;
36cdf0e10cSrcweir import com.sun.star.lang.XServiceInfo;
37cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
38cdf0e10cSrcweir 
39cdf0e10cSrcweir public class GraphicalDifferenceCheck
40cdf0e10cSrcweir {
41cdf0e10cSrcweir     private static void showVersion()
42cdf0e10cSrcweir         {
43cdf0e10cSrcweir             // DEBUG only
44cdf0e10cSrcweir             if (FileHelper.isDebugEnabled())
45cdf0e10cSrcweir             {
46cdf0e10cSrcweir                 GlobalLogWriter.get().println("");
47cdf0e10cSrcweir                 GlobalLogWriter.get().println("+##############################+");
48cdf0e10cSrcweir                 GlobalLogWriter.get().println("##### THIS IS CONVWATCH    #####");
49cdf0e10cSrcweir                 GlobalLogWriter.get().println("##### Debug Version 1.0015 #####");
50cdf0e10cSrcweir                 GlobalLogWriter.get().println("+##############################+");
51cdf0e10cSrcweir                 GlobalLogWriter.get().println("");
52cdf0e10cSrcweir             }
53cdf0e10cSrcweir         }
54cdf0e10cSrcweir 
55cdf0e10cSrcweir     /**
56cdf0e10cSrcweir      * Creates references form documents used by the graphical difference check
57cdf0e10cSrcweir      *
58cdf0e10cSrcweir      * @param _sInputPath       the original document path
59cdf0e10cSrcweir      * @param _sReferencePath   the directory where the document will print as file or export as pdf.
60cdf0e10cSrcweir      *
61cdf0e10cSrcweir      * @throws  ConvWatchException if there are problems, see message
62cdf0e10cSrcweir      *
63cdf0e10cSrcweir      * Stops rest, if one creation of reference fails.
64cdf0e10cSrcweir      */
65cdf0e10cSrcweir     public static void createReferences(String _sInputPath, String _sReferencePath, GraphicalTestArguments _aGTA) throws ConvWatchException
66cdf0e10cSrcweir         {
67cdf0e10cSrcweir //!
68cdf0e10cSrcweir //            System.out.println("createReferences() InputPath: " + _sInputPath + " refpath: " + _sReferencePath);
69cdf0e10cSrcweir             showVersion();
70cdf0e10cSrcweir             File aInputPath = new File(_sInputPath);
71cdf0e10cSrcweir 
72cdf0e10cSrcweir //            System.out.println("Inputpath in file: " + aInputPath.getAbsolutePath());
73cdf0e10cSrcweir //!
74cdf0e10cSrcweir //             if (aInputPath.exists())
75cdf0e10cSrcweir //             {
76cdf0e10cSrcweir //                 System.out.println("Inputpath exists");
77cdf0e10cSrcweir //             }
78cdf0e10cSrcweir //             else
79cdf0e10cSrcweir //             {
80cdf0e10cSrcweir //                 System.out.println("Inputpath doesn't exists");
81cdf0e10cSrcweir //                 return;
82cdf0e10cSrcweir //             }
83cdf0e10cSrcweir 
84cdf0e10cSrcweir             if (aInputPath.isDirectory())
85cdf0e10cSrcweir             {
86cdf0e10cSrcweir                 String fs = System.getProperty("file.separator");
87cdf0e10cSrcweir 
88cdf0e10cSrcweir                 String sRemovePath = aInputPath.getAbsolutePath();
89cdf0e10cSrcweir                 // a whole directory
90cdf0e10cSrcweir 
91cdf0e10cSrcweir                 Object[] aList = DirectoryHelper.traverse(_sInputPath, FileHelper.getFileFilter(), _aGTA.includeSubDirectories());
92cdf0e10cSrcweir                 for (int i=0;i<aList.length;i++)
93cdf0e10cSrcweir                 {
94cdf0e10cSrcweir                     String sEntry = (String)aList[i];
95cdf0e10cSrcweir                     String sNewReferencePath = _sReferencePath + fs + FileHelper.removeFirstDirectorysAndBasenameFrom(sEntry, _sInputPath);
96cdf0e10cSrcweir                     createOneReferenceFile(sEntry, sNewReferencePath, _aGTA);
97cdf0e10cSrcweir                 }
98cdf0e10cSrcweir             }
99cdf0e10cSrcweir             else
100cdf0e10cSrcweir             {
101cdf0e10cSrcweir //!
102cdf0e10cSrcweir                 // System.out.println("No directory.");
103cdf0e10cSrcweir                 createOneReferenceFile(_sInputPath, _sReferencePath, _aGTA);
104cdf0e10cSrcweir             }
105cdf0e10cSrcweir         }
106cdf0e10cSrcweir 
107cdf0e10cSrcweir 
108cdf0e10cSrcweir     /**
109cdf0e10cSrcweir      * Creates a reference for a single document used by the graphical difference check
110cdf0e10cSrcweir      *
111cdf0e10cSrcweir      * @param _sInputFile       the original document
112cdf0e10cSrcweir      * @param _sReferencePath   the directory where the document will print as file or export as pdf.
113cdf0e10cSrcweir      *
114cdf0e10cSrcweir      * @throws  ConvWatchException if the are problems, see containing message
115cdf0e10cSrcweir      */
116cdf0e10cSrcweir     public static boolean createOneReferenceFile(String _sInputFile, String _sReferencePath, GraphicalTestArguments _aGTA) throws ConvWatchException
117cdf0e10cSrcweir         {
118cdf0e10cSrcweir             showVersion();
119cdf0e10cSrcweir             if (_aGTA != null)
120cdf0e10cSrcweir             {
121cdf0e10cSrcweir                 _aGTA.setInputFile(_sInputFile);
122cdf0e10cSrcweir             }
123cdf0e10cSrcweir             return OfficePrint.buildReference(_aGTA, _sReferencePath, _sInputFile);
124cdf0e10cSrcweir         }
125cdf0e10cSrcweir 
126cdf0e10cSrcweir     /**
127cdf0e10cSrcweir      * Check if a reference exist
128cdf0e10cSrcweir      *
129cdf0e10cSrcweir      * @param _sInputFile       the original document
130cdf0e10cSrcweir      * @param _sReferencePath   the directory where the document will print as file or export as pdf.
131cdf0e10cSrcweir      *
132cdf0e10cSrcweir      * @throws  ConvWatchException if the are problems, see containing message
133cdf0e10cSrcweir      */
134cdf0e10cSrcweir     public static boolean isReferenceExists(String _sInputFile, String _sReferencePath, GraphicalTestArguments _aGTA)
135cdf0e10cSrcweir         {
136cdf0e10cSrcweir             return OfficePrint.isReferenceExists(_aGTA, _sReferencePath, _sInputFile);
137cdf0e10cSrcweir         }
138cdf0e10cSrcweir 
139cdf0e10cSrcweir 
140cdf0e10cSrcweir     /**
141cdf0e10cSrcweir      * Used for the comparance of graphical differences.
142cdf0e10cSrcweir      * Method compares one document (_sInputFile) with an older document of the same name in the provided directory (_sReferencePath).
143cdf0e10cSrcweir      *
144cdf0e10cSrcweir      * @param _sInputPath       the original document path
145cdf0e10cSrcweir      * @param _sOutputPath      path where the same directory structure of the given input path will create. All the result documents
146cdf0e10cSrcweir      *                          needed very much disk space (up to 10MB per page).
147cdf0e10cSrcweir      *                          The path _sOutputPath must be writeable.
148cdf0e10cSrcweir      * @param _sReferencePath   the directory where the document will print as file or export as pdf.
149cdf0e10cSrcweir      * @param _GTA              Helper class for lot of parameter to control the office.
150cdf0e10cSrcweir      *
151cdf0e10cSrcweir      * Disadvantage: stops rest if one test file has a problem.
152cdf0e10cSrcweir      */
153cdf0e10cSrcweir     public static boolean check(String _sInputPath, String _sOutputPath, String _sReferencePath, GraphicalTestArguments _aGTA ) throws ConvWatchException
154cdf0e10cSrcweir         {
155cdf0e10cSrcweir             return check(_sInputPath, _sOutputPath, _sReferencePath, null, _aGTA);
156cdf0e10cSrcweir         }
157cdf0e10cSrcweir 
158cdf0e10cSrcweir     /**
159cdf0e10cSrcweir      * Used for the comparance of graphical differences.
160cdf0e10cSrcweir      * Method compares one document (_sInputFile) with an older document of the same name in the provided directory (_sReferencePath).
161cdf0e10cSrcweir      *
162cdf0e10cSrcweir      * @param _sInputPath       the original document path
163cdf0e10cSrcweir      * @param _sReferencePath   the directory where the document will print as file or export as pdf.
164cdf0e10cSrcweir      * @param _sOutputPath      path where the same directory structure of the given input path will create. All the result documents
165cdf0e10cSrcweir      *                          needed very much disk space (up to 10MB per page).
166cdf0e10cSrcweir      *                          The path _sOutputPath must be writeable.
167cdf0e10cSrcweir      * @param _sDiffPath        Path to older differences.
168cdf0e10cSrcweir      * @param _GTA              Helper class for lot of parameter to control the office.
169cdf0e10cSrcweir      *
170cdf0e10cSrcweir      *
171cdf0e10cSrcweir      * Stops all, if one creation of reference fails
172cdf0e10cSrcweir      */
173cdf0e10cSrcweir     public static boolean check(String _sInputPath, String _sOutputPath, String _sReferencePath, String _sDiffPath, GraphicalTestArguments _aGTA ) throws ConvWatchException
174cdf0e10cSrcweir         {
175cdf0e10cSrcweir             showVersion();
176cdf0e10cSrcweir 
177cdf0e10cSrcweir             boolean bOk = true;
178cdf0e10cSrcweir 
179cdf0e10cSrcweir             File aInputPath = new File(_sInputPath);
180cdf0e10cSrcweir             if (aInputPath.isDirectory())
181cdf0e10cSrcweir             {
182cdf0e10cSrcweir                 String fs = System.getProperty("file.separator");
183cdf0e10cSrcweir                 // a whole directory
184cdf0e10cSrcweir                 Object[] aList = DirectoryHelper.traverse(_sInputPath, FileHelper.getFileFilter(), _aGTA.includeSubDirectories());
185cdf0e10cSrcweir                 if (aList.length != 0)
186cdf0e10cSrcweir                 {
187cdf0e10cSrcweir                     for (int i=0;i<aList.length;i++)
188cdf0e10cSrcweir                     {
189cdf0e10cSrcweir                         String sEntry = (String)aList[i];
190cdf0e10cSrcweir                         String sNewSubDir = FileHelper.removeFirstDirectorysAndBasenameFrom(sEntry, _sInputPath);
191cdf0e10cSrcweir                         String sNewReferencePath = _sReferencePath;
192cdf0e10cSrcweir                         String sNewOutputPath = _sOutputPath;
193cdf0e10cSrcweir                         String sNewDiffPath = _sDiffPath;
194cdf0e10cSrcweir                         if (sNewSubDir.length() > 0)
195cdf0e10cSrcweir                         {
196cdf0e10cSrcweir                             if (sNewReferencePath != null)
197cdf0e10cSrcweir                             {
198cdf0e10cSrcweir                                 sNewReferencePath = sNewReferencePath + fs + sNewSubDir;
199cdf0e10cSrcweir                             }
200cdf0e10cSrcweir 
201cdf0e10cSrcweir                             sNewOutputPath = sNewOutputPath + fs + sNewSubDir;
202cdf0e10cSrcweir                             if (sNewDiffPath != null)
203cdf0e10cSrcweir                             {
204cdf0e10cSrcweir                                 sNewDiffPath = sNewDiffPath + fs + sNewSubDir;
205cdf0e10cSrcweir                             }
206cdf0e10cSrcweir                         }
207cdf0e10cSrcweir                         bOk &= checkOneFile(sEntry, sNewOutputPath, sNewReferencePath, sNewDiffPath, _aGTA);
208cdf0e10cSrcweir                     }
209cdf0e10cSrcweir                 }
210cdf0e10cSrcweir             }
211cdf0e10cSrcweir             else
212cdf0e10cSrcweir             {
213cdf0e10cSrcweir                 bOk = /* GraphicalDifferenceCheck.*/ checkOneFile(_sInputPath, _sOutputPath, _sReferencePath, _sDiffPath, _aGTA);
214cdf0e10cSrcweir             }
215cdf0e10cSrcweir             return bOk;
216cdf0e10cSrcweir         }
217cdf0e10cSrcweir 
218cdf0e10cSrcweir     /**
219cdf0e10cSrcweir      * Used for the comparance of graphical differences.
220cdf0e10cSrcweir      * Method compares one document (_sInputFile) with an older document of the same name in the provided directory (_sReferencePath).
221cdf0e10cSrcweir      *
222cdf0e10cSrcweir      * The path _sOutputPath must be writeable
223cdf0e10cSrcweir      */
224cdf0e10cSrcweir     public static boolean checkOneFile(String _sInputFile, String _sOutputPath, String _sReferencePath, GraphicalTestArguments _aGTA)  throws ConvWatchException
225cdf0e10cSrcweir     {
226cdf0e10cSrcweir         return checkOneFile( _sInputFile, _sOutputPath, _sReferencePath, null, _aGTA);
227cdf0e10cSrcweir     }
228cdf0e10cSrcweir 
229cdf0e10cSrcweir 
230cdf0e10cSrcweir     /**
231cdf0e10cSrcweir      * Used for the comparance of graphical differences.
232cdf0e10cSrcweir      * Method compares one document (_sInputFile) with an older document of the same name in the provided directory (_sReferencePath).
233cdf0e10cSrcweir      *
234cdf0e10cSrcweir      * For scenarios, where a difference is known and further changes are of interest, differences itself can be compared.
235cdf0e10cSrcweir      * This functionality is provided by the difference path parameter (_sDiffPath). If set, the difference of the current comparance (between input and reference),
236cdf0e10cSrcweir      * will be compared with the (same named) difference document from a earlier comparance.
237cdf0e10cSrcweir      *
238cdf0e10cSrcweir      * The path _sOutputPath must be writeable
239cdf0e10cSrcweir      */
240cdf0e10cSrcweir     public static boolean checkOneFile(String _sInputFile, String _sOutputPath, String _sReferencePath, String _sDiffPath, GraphicalTestArguments _aGTA ) throws ConvWatchException
241cdf0e10cSrcweir         {
242cdf0e10cSrcweir             showVersion();
243cdf0e10cSrcweir             if (_aGTA != null)
244cdf0e10cSrcweir             {
245cdf0e10cSrcweir                 _aGTA.setInputFile(_sInputFile);
246cdf0e10cSrcweir             }
247cdf0e10cSrcweir 
248cdf0e10cSrcweir             boolean bOk = false;
249cdf0e10cSrcweir             if (_sDiffPath != null)
250cdf0e10cSrcweir             {
251cdf0e10cSrcweir                 // check with an old diff
252cdf0e10cSrcweir                 bOk = convwatch.ConvWatch.checkDiffDiff(_aGTA, _sOutputPath, _sInputFile, _sReferencePath, _sDiffPath);
253cdf0e10cSrcweir             }
254cdf0e10cSrcweir             else
255cdf0e10cSrcweir             {
256cdf0e10cSrcweir                 // one file
257cdf0e10cSrcweir                 bOk = convwatch.ConvWatch.check(_aGTA, _sOutputPath, _sInputFile, _sReferencePath);
258cdf0e10cSrcweir             }
259cdf0e10cSrcweir             return bOk;
260cdf0e10cSrcweir         }
261cdf0e10cSrcweir 
262cdf0e10cSrcweir     /**
263cdf0e10cSrcweir      * Instead of providing a saved document for graphical comparance a StarOffice xComponent
264cdf0e10cSrcweir      * will be saved and afterwards compared.
265cdf0e10cSrcweir      *
266cdf0e10cSrcweir      * @param xComponent        the test document to be compared as StarOffice component
267cdf0e10cSrcweir      * @param _sOutputPath      Path where test results are supposed to been saved. The path _sOutputPath must be writeable.
268cdf0e10cSrcweir      *                          These documents need sufficient disk space (up to 10MB per page).
269cdf0e10cSrcweir      *                          A directory structure will be created, which is a mirrored from input path.
270cdf0e10cSrcweir      *
271cdf0e10cSrcweir      * @param resultDocName     Name by which the xComponent shall be saved as OpenOffice.org XML document.
272cdf0e10cSrcweir      *                          If provided without suffix, the suffix will be derived from the export filter.
273cdf0e10cSrcweir      * @param _sReferencePath   the directory where the document will print as file or export as pdf.
274cdf0e10cSrcweir      * @param _GTA              Helper class for lot of parameter to control the office.
275cdf0e10cSrcweir      */
276cdf0e10cSrcweir     public static boolean checkOneFile(XComponent xComponent, String _sOutputPath, String _resultDocName, String _sReferencePath, GraphicalTestArguments _aGTA ) throws ConvWatchException
277cdf0e10cSrcweir         {
278cdf0e10cSrcweir             showVersion();
279cdf0e10cSrcweir 
280cdf0e10cSrcweir             // one file
281cdf0e10cSrcweir             String sInputFile;
282cdf0e10cSrcweir             sInputFile = createInputFile(xComponent, _sOutputPath, _resultDocName);
283cdf0e10cSrcweir             sInputFile = FileHelper.getSystemPathFromFileURL(sInputFile);
284cdf0e10cSrcweir             return convwatch.ConvWatch.check(_aGTA, _sOutputPath, sInputFile, _sReferencePath);
285cdf0e10cSrcweir         }
286cdf0e10cSrcweir 
287cdf0e10cSrcweir 
288cdf0e10cSrcweir // LLA: old!     /**
289cdf0e10cSrcweir // LLA: old!      * Returns 'true' if a reference document on the specific output path exists.
290cdf0e10cSrcweir // LLA: old!      * The name of the document is corresponding to the input document, which can be
291cdf0e10cSrcweir // LLA: old!      * provided by a single name or path.
292cdf0e10cSrcweir // LLA: old!      *
293cdf0e10cSrcweir // LLA: old!      * @param inputPath       the original document name (possibly including path)
294cdf0e10cSrcweir // LLA: old!      * @param referencePath   the directory where the reference document will be stored
295cdf0e10cSrcweir // LLA: old!
296cdf0e10cSrcweir // LLA: old!      */
297cdf0e10cSrcweir // LLA: old!     public static boolean isReferencExistent(String inputDocumentPath, String referencePath)
298cdf0e10cSrcweir // LLA: old!     {
299cdf0e10cSrcweir // LLA: old!        // isolate the document name
300cdf0e10cSrcweir // LLA: old!         if(inputDocumentPath.indexOf(File.separator) != -1)
301cdf0e10cSrcweir // LLA: old!             inputDocumentPath = inputDocumentPath.substring(inputDocumentPath.lastIndexOf(File.separator) + 1, inputDocumentPath.length());
302cdf0e10cSrcweir // LLA: old!
303cdf0e10cSrcweir // LLA: old!        // exchange any arbitray suffix against the refence suffix (.prn)
304cdf0e10cSrcweir // LLA: old!         if(inputDocumentPath.indexOf('.') != -1)
305cdf0e10cSrcweir // LLA: old!             inputDocumentPath = inputDocumentPath.substring(0, inputDocumentPath.lastIndexOf('.'));
306cdf0e10cSrcweir // LLA: old!         inputDocumentPath = inputDocumentPath + ".prn";
307cdf0e10cSrcweir // LLA: old! System.out.println("GraphicalDifference CheckReferenceDocument: " + inputDocumentPath);
308cdf0e10cSrcweir // LLA: old!
309cdf0e10cSrcweir // LLA: old!         File refFile = new File(referencePath + inputDocumentPath);
310cdf0e10cSrcweir // LLA: old!         if(refFile.exists()){
311cdf0e10cSrcweir // LLA: old!             return true;
312cdf0e10cSrcweir // LLA: old!         }else
313cdf0e10cSrcweir // LLA: old!             return false;
314cdf0e10cSrcweir // LLA: old!    }
315cdf0e10cSrcweir 
316cdf0e10cSrcweir 
317cdf0e10cSrcweir     private static String createInputFile(XComponent xComponent, String _sOutputPath, String resultDocName)
318cdf0e10cSrcweir         throws ConvWatchCancelException
319cdf0e10cSrcweir     {
320cdf0e10cSrcweir 
321cdf0e10cSrcweir         // find the adequate XML StarOffice output filter to save the document and adequate suffix
322cdf0e10cSrcweir         StringBuffer suffix = new StringBuffer();
323cdf0e10cSrcweir         String exportFilter = getXMLOutputFilterforXComponent(xComponent, suffix);
324cdf0e10cSrcweir         if(resultDocName == null)
325cdf0e10cSrcweir             resultDocName = "OOoTestDocument";
326cdf0e10cSrcweir         if(resultDocName.indexOf('.') == -1)
327cdf0e10cSrcweir             resultDocName = suffix.insert(0, resultDocName).toString();
328cdf0e10cSrcweir 
329cdf0e10cSrcweir         // create a result URL for storing the office document
330cdf0e10cSrcweir         String resultURL = URLHelper.getFileURLFromSystemPath(ensureEndingFileSep(_sOutputPath) + resultDocName);
331cdf0e10cSrcweir 
332cdf0e10cSrcweir         XStorable xStorable = null;
333cdf0e10cSrcweir         xStorable  = (com.sun.star.frame.XStorable)UnoRuntime.queryInterface(com.sun.star.frame.XStorable.class, xComponent);
334cdf0e10cSrcweir         if(xStorable == null)
335cdf0e10cSrcweir         {
336cdf0e10cSrcweir             throw new ConvWatchCancelException("com.sun.star.frame.XStorable could not be instantiated from the office.");
337cdf0e10cSrcweir         }
338cdf0e10cSrcweir 
339cdf0e10cSrcweir         PropertyValue pvFilterName = new PropertyValue("FilterName", -1, exportFilter, com.sun.star.beans.PropertyState.getDefault());
340cdf0e10cSrcweir         PropertyValue pvOverwrite = new PropertyValue("Overwrite", -1, new Boolean(true), com.sun.star.beans.PropertyState.getDefault());
341cdf0e10cSrcweir 
342cdf0e10cSrcweir         try
343cdf0e10cSrcweir         {
344cdf0e10cSrcweir             xStorable.storeAsURL(resultURL, new PropertyValue[]{pvFilterName, pvOverwrite});
345cdf0e10cSrcweir         }
346cdf0e10cSrcweir         catch (com.sun.star.io.IOException e)
347cdf0e10cSrcweir         {
348cdf0e10cSrcweir             // wrap IOException
349cdf0e10cSrcweir             throw new ConvWatchCancelException("Wrap IOException caught, " + e.getMessage());
350cdf0e10cSrcweir         }
351cdf0e10cSrcweir 
352cdf0e10cSrcweir         GlobalLogWriter.get().println("Saving XComponent as " + resultURL);
353cdf0e10cSrcweir 
354cdf0e10cSrcweir         return resultURL;
355cdf0e10cSrcweir     }
356cdf0e10cSrcweir 
357cdf0e10cSrcweir 
358cdf0e10cSrcweir     private static String getXMLOutputFilterforXComponent(XComponent xComponent, StringBuffer suffix){
359cdf0e10cSrcweir         XServiceInfo xSI = (XServiceInfo) UnoRuntime.queryInterface(XServiceInfo.class, xComponent);
360cdf0e10cSrcweir         if (xSI.supportsService("com.sun.star.text.TextDocument")){
361cdf0e10cSrcweir             resetBuffer(suffix, ".sxw");
362cdf0e10cSrcweir             return "swriter: StarOffice XML (Writer)";
363cdf0e10cSrcweir         }else if (xSI.supportsService("com.sun.star.sheet.SpreadsheetDocument")){
364cdf0e10cSrcweir             resetBuffer(suffix, ".sxc");
365cdf0e10cSrcweir             return "scalc: StarOffice XML (Calc)";
366cdf0e10cSrcweir         }else if (xSI.supportsService("com.sun.star.presentation.PresentationDocument")){
367cdf0e10cSrcweir             resetBuffer(suffix, ".sxi");
368cdf0e10cSrcweir             return "simpress: StarOffice XML (Impress)";
369cdf0e10cSrcweir         }else if(xSI.supportsService("com.sun.star.drawing.DrawingDocument")){
370cdf0e10cSrcweir             resetBuffer(suffix, ".sxd");
371cdf0e10cSrcweir             return "sdraw: StarOffice XML (Draw)";
372cdf0e10cSrcweir         }else if (xSI.supportsService("com.sun.star.formula.FormulaProperties")){
373cdf0e10cSrcweir             resetBuffer(suffix, ".sxm");
374cdf0e10cSrcweir             return "smath: StarOffice XML (Math)";
375cdf0e10cSrcweir         }
376cdf0e10cSrcweir         return null;
377cdf0e10cSrcweir     }
378cdf0e10cSrcweir 
379cdf0e10cSrcweir     private static StringBuffer resetBuffer(StringBuffer sb, String suffix)
380cdf0e10cSrcweir         {
381cdf0e10cSrcweir             if(sb != null)
382cdf0e10cSrcweir             {
383cdf0e10cSrcweir                 sb.replace(0, sb.length(), suffix);
384cdf0e10cSrcweir             }
385cdf0e10cSrcweir             return sb;
386cdf0e10cSrcweir         }
387cdf0e10cSrcweir 
388cdf0e10cSrcweir     private static String ensureEndingFileSep(String s)
389cdf0e10cSrcweir         {
390cdf0e10cSrcweir         if(s != null && !s.equals("") && !s.endsWith(File.separator))
391cdf0e10cSrcweir             {
392cdf0e10cSrcweir                 s = s.trim() + File.separator;
393cdf0e10cSrcweir             }
394cdf0e10cSrcweir             else
395cdf0e10cSrcweir             {
396cdf0e10cSrcweir                 if(s == null)
397cdf0e10cSrcweir                 {
398cdf0e10cSrcweir                     s = "";
399cdf0e10cSrcweir                 }
400cdf0e10cSrcweir             }
401cdf0e10cSrcweir 
402cdf0e10cSrcweir         return s;
403cdf0e10cSrcweir     }
404cdf0e10cSrcweir 
405cdf0e10cSrcweir 
406cdf0e10cSrcweir }
407