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