1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
29 import convwatch
.GraphicalDifferenceCheck
;
30 import convwatch
.GraphicalTestArguments
;
31 import convwatch
.DirectoryHelper
;
32 import convwatch
.FileHelper
;
34 import lib
.TestParameters
;
36 import java
.io
.FileFilter
;
37 import java
.io
.IOException
;
39 import util
.compare
.DocComparator
;
40 import convwatch
.ConvWatchException
;
42 // -----------------------------------------------------------------------------
43 class GraphicalComparator
implements DocComparator
45 GraphicalTestArguments m_aArguments
;
47 protected GraphicalComparator(TestParameters aParams
)
49 m_aArguments
= new GraphicalTestArguments(aParams
);
53 * @return an instance of this object, but only it's interface
55 static DocComparator
getInstance(TestParameters aParams
)
57 // setting the default test parameter
59 GraphicalComparator a
= new GraphicalComparator(aParams
);
64 * return a (FileFilter) function, which returns true, if the filename is a '*.prn' file
66 FileFilter
getTrueIfPRNFile_FileFilter()
68 FileFilter aFileFilter
= new FileFilter()
70 public boolean accept( File pathname
)
72 if (pathname
.getName().endsWith(".prn"))
83 * build a new file from _sEntry by
84 * replacing the path equals to _sInputPath with _sReferencePath and replace it's suffix by _sNewSuffix.
85 * If _sInputPath is empty, replace the whole path by _sReferencePath.
87 protected String
createSpecialFile(String _sEntry
, String _sInputPath
, String _sReferencePath
, String _sNewSuffix
)
89 String fs
= System
.getProperty("file.separator");
90 String sNewSubDir
= "";
91 if (_sInputPath
.length() > 0)
93 sNewSubDir
= FileHelper
.removeFirstDirectorysAndBasenameFrom(_sEntry
, _sInputPath
);
95 String sNameNoSuffix
= FileHelper
.getNameNoSuffix(FileHelper
.getBasename(_sEntry
));
97 // add the sub path to the difference path
98 String sNewReferencePath
;
99 if (sNewSubDir
.length() > 0)
101 sNewReferencePath
= _sReferencePath
+ fs
+ sNewSubDir
;
105 sNewReferencePath
= _sReferencePath
;
107 // add the difference name
108 sNewReferencePath
+= fs
+ sNameNoSuffix
+ _sNewSuffix
;
109 return sNewReferencePath
;
112 boolean isReferenceOrDiffExistent(String _sNewSuffix
)
114 boolean isExistent
= false;
116 // LLA? What if sReferencePath is a directory, but directory is empty? is the result then true or false;
118 // wir muessen durch den InputPath durch und dann fuer jedes Dokument prufen, ob im angegebenen ReferencePath eine Reference existiert.
119 String sInputPath
= m_aArguments
.getInputPath();
120 if (FileHelper
.isDir(sInputPath
))
122 Object
[] aList
= DirectoryHelper
.traverse(sInputPath
, FileHelper
.getFileFilter(), m_aArguments
.includeSubDirectories());
123 for (int i
=0;i
<aList
.length
;i
++)
125 // get document + path
126 String sEntry
= (String
)aList
[i
];
127 String sNewReferencePath
= createSpecialFile(sEntry
, sInputPath
, m_aArguments
.getReferencePath(), _sNewSuffix
);
128 // split path from document path which only is equal to sInputPath (sub path)
129 if (FileHelper
.exists(sNewReferencePath
))
137 // sInputPath is a file
138 String sNewReferencePath
= createSpecialFile(sInputPath
, "", m_aArguments
.getReferencePath(), _sNewSuffix
);
139 if (FileHelper
.exists(sNewReferencePath
))
148 * REFERENCE_PATH must set to directory/file, where the reference (*.prn files) (should) exist
150 public boolean isReferenceExistent()
152 return isReferenceOrDiffExistent(".prn");
156 * INPUT_PATH must set, to directory/file, where the documents exist.
157 * REFERENCE_PATH must set to directory/file, where the created references (*.prn files) will create.
159 public void createReference() throws IOException
161 // woher kommt das TestDocument
165 // mit was (Reference Application)
169 String referenceInputPath
= null;
170 if(m_aArguments
.getReferenceInputPath() == null)
172 GraphicalDifferenceCheck
.createReferences(m_aArguments
.getInputPath(), m_aArguments
.getReferencePath(), m_aArguments
);
176 referenceInputPath
= m_aArguments
.getReferenceInputPath();
177 GraphicalDifferenceCheck
.createReferences(referenceInputPath
, m_aArguments
.getReferencePath(), m_aArguments
);
180 catch (ConvWatchException e
)
182 // wrap it to IOException
183 throw new java
.io
.IOException(e
.getMessage());
188 * INPUT_PATH must set, to directory/file, where the documents exist.
189 * REFERENCE_PATH must set to directory/file, where the created references (*.prn files) will create.
190 * OUTPUT_PATH must set to a directory, there the whole ouptut will create
192 public boolean compare() throws IOException
196 if (FileHelper
.isDebugEnabled())
198 System
.err
.println(" Inputpath: '" + m_aArguments
.getInputPath() + "'");
199 System
.err
.println(" Outputpath: '" + m_aArguments
.getOutputPath() + "'");
200 System
.err
.println("Referencepath: '" + m_aArguments
.getReferencePath() + "'");
202 return GraphicalDifferenceCheck
.check(m_aArguments
.getInputPath(), m_aArguments
.getOutputPath(), m_aArguments
.getReferencePath(), m_aArguments
);
204 catch(ConvWatchException e
)
206 // wrap it to IOException
207 if (FileHelper
.isDebugEnabled())
209 System
.err
.println("Exception caught");
210 System
.err
.println(" Inputpath: '" + m_aArguments
.getInputPath() + "'");
211 System
.err
.println(" Outputpath: '" + m_aArguments
.getOutputPath() + "'");
212 System
.err
.println("Referencepath: '" + m_aArguments
.getReferencePath() + "'");
214 throw new java
.io
.IOException(e
.getMessage());
220 * INPUT_PATH must set to the original documents the directory structure is taken to see if the references exist in the DIFF_PATH
221 * DIFF_PATH must set to the diff references
223 public boolean isDiffReferenceExistent() throws IOException
225 return isReferenceOrDiffExistent(".prn.diff0001.jpg");
229 * INPUT_PATH must set, to directory/file, where the documents exist.
230 * REFERENCE_PATH must set to directory/file, where the created references (*.prn files) exists.
231 * OUTPUT_PATH must set to a directory, where the whole ouptut will create. Here the diffReference will create.
232 * At the momemt it's not possible to say only where the diffreferences will create.
234 public void createDiffReference() throws IOException
236 // this is the same like compareDiff(), but trash the result.
241 * INPUT_PATH must set, to directory/file, where the documents exist.
242 * REFERENCE_PATH must set to directory/file, where the created references (*.prn files) exists.
243 * OUTPUT_PATH must set to a directory, where the whole ouptut will create.
244 * DIFF_PATH must set to a directory, where the older difference references exist, it's possible to set this to the same as REFERENCE_PATH
245 * but this is not the default and will not automatically set.
247 public boolean compareDiff() throws IOException
251 return GraphicalDifferenceCheck
.check(m_aArguments
.getInputPath(), m_aArguments
.getOutputPath(), m_aArguments
.getReferencePath(), m_aArguments
.getDiffPath(), m_aArguments
);
253 catch(ConvWatchException e
)
255 // wrap it to IOException
256 throw new java
.io
.IOException(e
.getMessage());