/* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ package convwatch; import helper.URLHelper; import java.io.File; public class ConvWatch { private String getBuildID_FromFile(String _sInfoFile) { String sBuildID = ""; IniFile aIniFile = new IniFile(_sInfoFile); if (aIniFile.is()) { sBuildID = aIniFile.getValue("", "buildid"); } return sBuildID; } /** * Check if given document (_sAbsoluteInputFile) and it's postscript representation (_sAbsoluteReferenceFile) produce * the same output like the StarOffice / OpenOffice.org which is accessible with XMultiServiceFactory. * Here a simple graphically difference check is run through. * * Hint: In the OutputPath all needed files will create, there must * be very much space. It's not possible to say how much. * One page need up to 800kb as jpeg. * Sample: If a document contains 2 pages, we need 2*800kb for prn * output and 2*800kb for ps output and 2*800kb for it's difference * output. So up to 4800kb or 4.8mb. * * RAM is need least 300mb. Will say, it's tested on a pc with 128mb RAM and 256mb swap. * * It's also absolutlly impossible to say, how much time this functions consume. */ private StatusHelper[] createPostscriptStartCheck(GraphicalTestArguments _aGTA, String _sOutputPath, String _sAbsoluteInputFile, String _sAbsoluteReferenceFile) throws ConvWatchCancelException { // TODO: some more checks if (! FileHelper.exists(_sAbsoluteInputFile)) { throw new ConvWatchCancelException("createPostscriptStartCheck: Input file: " + _sAbsoluteInputFile + " does not exist."); } if (_sAbsoluteReferenceFile == null) { // we assume, that the prn file is near the document String sAbsoluteInputFileNoSuffix = FileHelper.getNameNoSuffix(_sAbsoluteInputFile); _sAbsoluteReferenceFile = sAbsoluteInputFileNoSuffix + ".prn"; } String fs = System.getProperty("file.separator"); File aAbsoluteReferenceFile = new File(_sAbsoluteReferenceFile); if (aAbsoluteReferenceFile.isDirectory()) { String sBasename = FileHelper.getBasename(_sAbsoluteInputFile); String sNameNoSuffix = FileHelper.getNameNoSuffix(sBasename); String sAbsoluteReferenceFileInfo = _sAbsoluteReferenceFile + fs + sNameNoSuffix + ".info"; _sAbsoluteReferenceFile = _sAbsoluteReferenceFile + fs + sNameNoSuffix + ".prn"; // Read the reference from the info file String sRefBuildID = ""; if (FileHelper.exists(sAbsoluteReferenceFileInfo)) { sRefBuildID = getBuildID_FromFile(sAbsoluteReferenceFileInfo); } _aGTA.setRefBuildID(sRefBuildID); } else { // java file has problems to check for directories, if the given directory doesn't exist. String sName = FileHelper.getBasename(_sAbsoluteReferenceFile); // thanks to Mircosoft, every document has a suffix, so if a name doesn't have a suffix, it must be a directory name int nIdx = sName.indexOf('.'); if (nIdx == -1) { // must be a directory throw new ConvWatchCancelException("createPostscriptStartCheck: Given reference directory: '" + _sAbsoluteReferenceFile + "' does not exist."); } } boolean bAbsoluteReferenceFile = true; if (! FileHelper.exists(_sAbsoluteReferenceFile)) { if (_aGTA.createDefaultReference()) { GlobalLogWriter.get().println("Reference File doesn't exist, will create a default"); bAbsoluteReferenceFile = false; } else { throw new ConvWatchCancelException("createPostscriptStartCheck: Given reference file: " + _sAbsoluteReferenceFile + " does not exist."); } } FileHelper.makeDirectories("", _sOutputPath); String sAbsoluteInputFileURL = URLHelper.getFileURLFromSystemPath(_sAbsoluteInputFile); String sInputFile = FileHelper.getBasename(_sAbsoluteInputFile); FileHelper.getNameNoSuffix(sInputFile); String sAbsoluteOutputFile = _sOutputPath + fs + sInputFile; String sAbsoluteOutputFileURL = URLHelper.getFileURLFromSystemPath(sAbsoluteOutputFile); String sReferenceFile = FileHelper.getBasename(_sAbsoluteReferenceFile); String sReferenceFileNoSuffix = FileHelper.getNameNoSuffix(sReferenceFile); String sPostScriptFile = sReferenceFileNoSuffix + ".ps"; String sAbsolutePrintFile = _sOutputPath + fs + sPostScriptFile; String sAbsolutePrintFileURL = URLHelper.getFileURLFromSystemPath(sAbsolutePrintFile); // store and print the sAbsoluteInputFileURL file with StarOffice / OpenOffice.org OfficePrint.printToFile(_aGTA, sAbsoluteInputFileURL, sAbsoluteOutputFileURL, sAbsolutePrintFileURL); if (! FileHelper.exists(sAbsolutePrintFile)) { throw new ConvWatchCancelException("createPostscriptStartCheck: Printed file " + sAbsolutePrintFile + " does not exist."); } if (!bAbsoluteReferenceFile) { // copy AbsolutePrintFile to AbsoluteReferenceFile String sDestinationFile = sAbsolutePrintFile; // URLHelper.getSystemPathFromFileURL(...) String sSourceFile = _sAbsoluteReferenceFile; FileHelper.copy(sDestinationFile, sSourceFile); // now the fix reference of the AbsoluteReferenceFile should exist. if (! FileHelper.exists(_sAbsoluteReferenceFile)) { throw new ConvWatchCancelException("createPostscriptStartCheck: Given reference file: " + _sAbsoluteReferenceFile + " does not exist, after try to copy."); } } PRNCompare a = new PRNCompare(); String sInputPath = FileHelper.getPath(_sAbsoluteInputFile); String sReferencePath = FileHelper.getPath(_sAbsoluteReferenceFile); a.setReferencePath( sReferencePath ); a.setOutputPath( _sOutputPath ); a.setReferenceFile( sReferenceFile ); a.setPostScriptFile(sPostScriptFile ); if (_aGTA.printAllPages()) { a.setMaxPages(9999); } else { if (_aGTA.getMaxPages() > 0) { a.setMaxPages(_aGTA.getMaxPages()); } if (_aGTA.getOnlyPages().length() != 0) { // we can't interpret the string of getOnlyPages() right without much logic, so print all pages here! a.setMaxPages(9999); } } a.setResolutionInDPI(_aGTA.getResolutionInDPI()); a.setBorderMove(_aGTA.getBorderMove()); a.setDocumentType(_aGTA.getDocumentType()); StatusHelper[] aList = a.compare(); _aGTA.setBorderMove(a.getBorderMove()); return aList; } // This creates a status for exact on document private static boolean createINIStatus(StatusHelper[] aList, String _sFilenamePrefix, String _sOutputPath, String _sAbsoluteInputFile, String _sBuildID, String _sRefBuildID) { System.getProperty("file.separator"); String sBasename = FileHelper.getBasename(_sAbsoluteInputFile); String sNameNoSuffix = FileHelper.getNameNoSuffix(sBasename); // TODO: version info was fine // HTMLoutput.checkSection(sBasename); // Status end String sINIFile = _sFilenamePrefix + sNameNoSuffix + ".ini"; INIOutputter INIoutput = INIOutputter.create(_sOutputPath, sINIFile, ""); INIoutput.createHeader(); // TODO: version info was fine INIoutput.writeSection("global"); INIoutput.writeValue("pages", String.valueOf(aList.length)); INIoutput.writeValue("buildid", _sBuildID); INIoutput.writeValue("refbuildid", _sRefBuildID); INIoutput.writeValue("diffdiff", "no"); INIoutput.writeValue("basename", sBasename); boolean bResultIsOk = true; // result over all pages for (int i=0;i