ContextUtility contextUtility = null;
try {
contextUtility = (ContextUtility) serviceManager.lookup(ContextUtility.ROLE);
Session session = RepositoryUtil.getSession(this.serviceManager, contextUtility
.getRequest());
DocumentFactory map = DocumentUtil.createDocumentFactory(this.serviceManager, session);
// always check for authoring URL since the live document doesn't
// have to exist
URLInformation info = new URLInformation(webappUrl);
// Danger, Will Robinson! If area or pubId is null, webappUrl.substring()
// will be out of bounds, because null becomes "null" in string concatenation
String pubId = info.getPublicationId();
String area = info.getArea();
String prefix = "/" + ((pubId != null) ? pubId + "/" : "");
// String prefix = "/" + pubId + "/";
String prefixWithArea = prefix + ((area != null) ? area : "");
// String prefixWithArea = prefix + area;
String authoringUrl = prefix + Publication.AUTHORING_AREA
+ ((webappUrl.length()>prefixWithArea.length())?webappUrl.substring(prefixWithArea.length()):"/");
if (map.isDocument(authoringUrl)) {
Document authoringDoc = map.getFromURL(authoringUrl);
url = "/" + authoringDoc.getPublication().getId() + "/" + area
+ authoringDoc.getPath();
if (getLogger().isDebugEnabled()) {
getLogger().debug(" Document exists");
getLogger().debug(" Document path: [" + authoringDoc.getPath() + "]");