* @param versionDate the date to compare with. Note that it will find the closest version at OR BEFORE the date
* @return the closest version at or before the date specified.
* @throws RepositoryException
*/
public static Version findClosestVersion(VersionHistory vh, Date versionDate) throws RepositoryException {
VersionIterator vi = null;
try {
vi = vh.getAllLinearVersions();
} catch (ItemNotFoundException e) {
String[] labels = vh.getVersionLabels();
for (String label : labels) {
if (label.startsWith(vh.getSession().getWorkspace().getName()+"_removed")) {
Version base = vh.getVersionByLabel(label);
LinkedList<Version> versions = new LinkedList<Version>();
while (base != null) {
versions.addFirst(base);
Version[] preds = base.getPredecessors();
if (preds.length == 0) {
base = null;
} else {
base = preds[0];
}
}
vi = new VersionIteratorImpl(versions.iterator(), versions.size());
break;
}
}
if (vi == null) {
return null;
}
}
Version lastVersion = null;
Version closestVersion = null;
if (vi.hasNext()) {
vi.nextVersion();
// the first is the root version, which has no properties, so we will ignore it.
}
String nodeTitle = null;
StringBuffer propertyString = null;
while (vi.hasNext()) {
Version v = vi.nextVersion();
if (logger.isDebugEnabled()) {
try {
Node frozenNode = v.getFrozenNode();
propertyString = new StringBuffer();
PropertyIterator propertyIterator = frozenNode.getProperties();