in src/main/java/com/atlassian/uwc/ui/ConverterEngine.java [971:1021]
private void addAncestors(Page page) {
String ancestorDir = this.miscProperties.getProperty("page-history-load-as-ancestors-dir", null);
if (ancestorDir == null) {
log.warn("page-history-load-as-ancestors-dir must be set. Cannot add ancestors.");
return;
}
String relPath = getPageRelativePath(page);
if (!ancestorDir.endsWith(File.separator) && !relPath.startsWith(File.separator))
ancestorDir += File.separator;
String ancestorPath = ancestorDir + relPath;
File dir = new File(ancestorPath);
File[] allFiles = dir.listFiles();
for (File file : allFiles) {
String filename = file.getName();
Page newPage = new VersionPage(file);
newPage.setParent(page);
newPage = identifyHistoryOnePage(newPage, filename);
if (newPage.getName() == null) continue;
if (newPage.getName().equalsIgnoreCase(page.getName().replaceFirst("[.][^.]+$", ""))) {
newPage.setName(page.getName()); //we need them to have the same name for latestversion to work
log.debug("Found ancestor page: " + newPage.getFile().getPath());
newPage.setPath(getPath(newPage.getFile().getPath()));
page.addAncestor((VersionPage) newPage);
}
}
Collections.sort(page.getAncestors());
if (!page.getAncestors().isEmpty() &&
Boolean.parseBoolean(this.miscProperties.getProperty("page-history-sortwithtimestamp", "false"))) {
if (Boolean.parseBoolean(this.miscProperties.getProperty("page-history-load-as-ancestors-lastiscurrent", "false"))) {
page.getAncestors().remove(page.getAncestors().lastElement());//remove the last ancestor if its the same as current
}
for (int i = 1; i < page.getAncestors().size(); i++) {
VersionPage version = page.getAncestors().get(i);
version.setVersion(version.getLatestVersion()+1);
}
page.setSortWithTimestamp(true); //affects sorting of collections of pages (including hierarchies)
}
if (this.miscProperties.containsKey("page-history-maxversions")) { //useful for debugging
String maxString = this.miscProperties.getProperty("page-history-maxversions", null);
int max = Integer.parseInt(maxString);
if (max <= page.getAncestors().size()) {
log.debug("number of ancestors: " + page.getAncestors().size());
int actmax = page.getAncestors().size();
for (int i = actmax-1; i >=max; i--) {
page.getAncestors().remove(i);
}
log.debug("after limiting, number of ancestors: " + page.getAncestors().size());
}
}
}