1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: GraphicalComparator.java,v $
10 * $Revision: 1.6.8.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 import convwatch
.GraphicalDifferenceCheck
;
33 import convwatch
.GraphicalTestArguments
;
34 import convwatch
.DirectoryHelper
;
35 import convwatch
.FileHelper
;
37 import lib
.TestParameters
;
39 import java
.io
.FileFilter
;
40 import java
.io
.IOException
;
42 import util
.compare
.DocComparator
;
43 import convwatch
.ConvWatchException
;
45 // -----------------------------------------------------------------------------
46 class GraphicalComparator
implements DocComparator
48 GraphicalTestArguments m_aArguments
;
50 protected GraphicalComparator(TestParameters aParams
)
52 m_aArguments
= new GraphicalTestArguments(aParams
);
56 * @return an instance of this object, but only it's interface
58 static DocComparator
getInstance(TestParameters aParams
)
60 // setting the default test parameter
62 GraphicalComparator a
= new GraphicalComparator(aParams
);
67 * return a (FileFilter) function, which returns true, if the filename is a '*.prn' file
69 FileFilter
getTrueIfPRNFile_FileFilter()
71 FileFilter aFileFilter
= new FileFilter()
73 public boolean accept( File pathname
)
75 if (pathname
.getName().endsWith(".prn"))
86 * build a new file from _sEntry by
87 * replacing the path equals to _sInputPath with _sReferencePath and replace it's suffix by _sNewSuffix.
88 * If _sInputPath is empty, replace the whole path by _sReferencePath.
90 protected String
createSpecialFile(String _sEntry
, String _sInputPath
, String _sReferencePath
, String _sNewSuffix
)
92 String fs
= System
.getProperty("file.separator");
93 String sNewSubDir
= "";
94 if (_sInputPath
.length() > 0)
96 sNewSubDir
= FileHelper
.removeFirstDirectorysAndBasenameFrom(_sEntry
, _sInputPath
);
98 String sNameNoSuffix
= FileHelper
.getNameNoSuffix(FileHelper
.getBasename(_sEntry
));
100 // add the sub path to the difference path
101 String sNewReferencePath
;
102 if (sNewSubDir
.length() > 0)
104 sNewReferencePath
= _sReferencePath
+ fs
+ sNewSubDir
;
108 sNewReferencePath
= _sReferencePath
;
110 // add the difference name
111 sNewReferencePath
+= fs
+ sNameNoSuffix
+ _sNewSuffix
;
112 return sNewReferencePath
;
115 boolean isReferenceOrDiffExistent(String _sNewSuffix
)
117 boolean isExistent
= false;
119 // LLA? What if sReferencePath is a directory, but directory is empty? is the result then true or false;
121 // wir muessen durch den InputPath durch und dann fuer jedes Dokument prufen, ob im angegebenen ReferencePath eine Reference existiert.
122 String sInputPath
= m_aArguments
.getInputPath();
123 if (FileHelper
.isDir(sInputPath
))
125 Object
[] aList
= DirectoryHelper
.traverse(sInputPath
, FileHelper
.getFileFilter(), m_aArguments
.includeSubDirectories());
126 for (int i
=0;i
<aList
.length
;i
++)
128 // get document + path
129 String sEntry
= (String
)aList
[i
];
130 String sNewReferencePath
= createSpecialFile(sEntry
, sInputPath
, m_aArguments
.getReferencePath(), _sNewSuffix
);
131 // split path from document path which only is equal to sInputPath (sub path)
132 if (FileHelper
.exists(sNewReferencePath
))
140 // sInputPath is a file
141 String sNewReferencePath
= createSpecialFile(sInputPath
, "", m_aArguments
.getReferencePath(), _sNewSuffix
);
142 if (FileHelper
.exists(sNewReferencePath
))
151 * REFERENCE_PATH must set to directory/file, where the reference (*.prn files) (should) exist
153 public boolean isReferenceExistent()
155 return isReferenceOrDiffExistent(".prn");
159 * INPUT_PATH must set, to directory/file, where the documents exist.
160 * REFERENCE_PATH must set to directory/file, where the created references (*.prn files) will create.
162 public void createReference() throws IOException
164 // woher kommt das TestDocument
168 // mit was (Reference Application)
172 String referenceInputPath
= null;
173 if(m_aArguments
.getReferenceInputPath() == null)
175 GraphicalDifferenceCheck
.createReferences(m_aArguments
.getInputPath(), m_aArguments
.getReferencePath(), m_aArguments
);
179 referenceInputPath
= m_aArguments
.getReferenceInputPath();
180 GraphicalDifferenceCheck
.createReferences(referenceInputPath
, m_aArguments
.getReferencePath(), m_aArguments
);
183 catch (ConvWatchException e
)
185 // wrap it to IOException
186 throw new java
.io
.IOException(e
.getMessage());
191 * INPUT_PATH must set, to directory/file, where the documents exist.
192 * REFERENCE_PATH must set to directory/file, where the created references (*.prn files) will create.
193 * OUTPUT_PATH must set to a directory, there the whole ouptut will create
195 public boolean compare() throws IOException
199 if (FileHelper
.isDebugEnabled())
201 System
.err
.println(" Inputpath: '" + m_aArguments
.getInputPath() + "'");
202 System
.err
.println(" Outputpath: '" + m_aArguments
.getOutputPath() + "'");
203 System
.err
.println("Referencepath: '" + m_aArguments
.getReferencePath() + "'");
205 return GraphicalDifferenceCheck
.check(m_aArguments
.getInputPath(), m_aArguments
.getOutputPath(), m_aArguments
.getReferencePath(), m_aArguments
);
207 catch(ConvWatchException e
)
209 // wrap it to IOException
210 if (FileHelper
.isDebugEnabled())
212 System
.err
.println("Exception caught");
213 System
.err
.println(" Inputpath: '" + m_aArguments
.getInputPath() + "'");
214 System
.err
.println(" Outputpath: '" + m_aArguments
.getOutputPath() + "'");
215 System
.err
.println("Referencepath: '" + m_aArguments
.getReferencePath() + "'");
217 throw new java
.io
.IOException(e
.getMessage());
223 * INPUT_PATH must set to the original documents the directory structure is taken to see if the references exist in the DIFF_PATH
224 * DIFF_PATH must set to the diff references
226 public boolean isDiffReferenceExistent() throws IOException
228 return isReferenceOrDiffExistent(".prn.diff0001.jpg");
232 * INPUT_PATH must set, to directory/file, where the documents exist.
233 * REFERENCE_PATH must set to directory/file, where the created references (*.prn files) exists.
234 * OUTPUT_PATH must set to a directory, where the whole ouptut will create. Here the diffReference will create.
235 * At the momemt it's not possible to say only where the diffreferences will create.
237 public void createDiffReference() throws IOException
239 // this is the same like compareDiff(), but trash the result.
244 * INPUT_PATH must set, to directory/file, where the documents exist.
245 * REFERENCE_PATH must set to directory/file, where the created references (*.prn files) exists.
246 * OUTPUT_PATH must set to a directory, where the whole ouptut will create.
247 * 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
248 * but this is not the default and will not automatically set.
250 public boolean compareDiff() throws IOException
254 return GraphicalDifferenceCheck
.check(m_aArguments
.getInputPath(), m_aArguments
.getOutputPath(), m_aArguments
.getReferencePath(), m_aArguments
.getDiffPath(), m_aArguments
);
256 catch(ConvWatchException e
)
258 // wrap it to IOException
259 throw new java
.io
.IOException(e
.getMessage());