*/
protected void doCheckPreconditions() throws Exception {
super.doCheckPreconditions();
if (!hasErrors()) {
Document document = getSourceDocument();
if (!document.getArea().equals(Publication.AUTHORING_AREA)) {
addErrorMessage("This usecase can only be invoked from the authoring area.");
return;
}
Publication publication = document.getPublication();
DocumentFactory map = document.getFactory();
SiteStructure liveSite = publication.getArea(Publication.LIVE_AREA).getSite();
List missingDocuments = new ArrayList();
ServiceSelector selector = null;
SiteManager siteManager = null;
try {
selector = (ServiceSelector) this.manager.lookup(SiteManager.ROLE + "Selector");
siteManager = (SiteManager) selector.select(publication.getSiteManagerHint());
if (!liveSite.contains(document.getPath())) {
DocumentLocator liveLoc = document.getLocator().getAreaVersion(
Publication.LIVE_AREA);
DocumentLocator[] requiredNodes = siteManager
.getRequiredResources(map, liveLoc);
for (int i = 0; i < requiredNodes.length; i++) {
String path = requiredNodes[i].getPath();
if (!liveSite.contains(path)) {
Link link = getExistingLink(path, document);
if (link != null) {
missingDocuments.add(link.getDocument());
}
}
}
}
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
if (selector != null) {
if (siteManager != null) {
selector.release(siteManager);
}
this.manager.release(selector);
}
}
if (!missingDocuments.isEmpty()) {
addErrorMessage("publish-missing-documents");
for (Iterator i = missingDocuments.iterator(); i.hasNext();) {
Document doc = (Document) i.next();
/*
* This doesn't work yet, see
* https://issues.apache.org/jira/browse/COCOON-2057
* String[] params = { doc.getCanonicalWebappURL(),
* doc.getPath() + " (" + doc.getLanguage() + ")" };
*/
String[] params = { doc.getPath() + ":" + doc.getLanguage(),
DublinCoreHelper.getTitle(doc, true) };
addErrorMessage("missing-document", params);
}
}