+ "]");
}
Map objectModel = ContextHelper.getObjectModel(this.context);
Request request = ObjectModelHelper.getRequest(objectModel);
DocumentFactory factory = DocumentUtil.getDocumentFactory(this.manager, request);
start = end + 1;
// Absolute vs. relative
if (location.startsWith("//", start)) {
// Absolute: get publication id
start += 2;
end = location.indexOf('/', start);
if (end == -1) {
throw new MalformedURLException("Malformed lenyadoc: URI: publication part not found ["
+ location + "]");
}
String publicationId = location.substring(start, end);
try {
pub = factory.getPublication(publicationId);
} catch (PublicationException e) {
throw new MalformedURLException("Malformed lenyadoc: Publication [" + publicationId
+ "] does not exist or could not be initialized");
}
if (pub == null || !pub.exists()) {
throw new SourceException("The publication [" + publicationId + "] does not exist!");
}
// Area
start = end + 1;
end = location.indexOf('/', start);
if (end == -1) {
throw new MalformedURLException("Malformed lenyadoc: URI: cannot find area ["
+ location + "]");
}
area = location.substring(start, end);
} else if (location.startsWith("/", start)) {
end += 1;
// Relative: get publication id and area from page envelope
try {
pub = PublicationUtil.getPublication(this.manager, objectModel);
} catch (PublicationException e) {
throw new SourceException("Error getting publication id / area from page envelope ["
+ location + "]");
}
if (pub != null && pub.exists()) {
String url = ServletHelper.getWebappURI(request);
area = new URLInformation(url).getArea();
} else {
throw new SourceException("Error getting publication id / area from page envelope ["
+ location + "]");
}
} else {
throw new MalformedURLException("Malformed lenyadoc: URI [" + location + "]");
}
// Language
start = end + 1;
end = location.indexOf('/', start);
if (end == -1) {
throw new MalformedURLException("Malformed lenyadoc: URI: cannot find language ["
+ location + "]");
}
language = location.substring(start, end);
// UUID
start = end + 1;
uuid = location.substring(start);
Session session;
try {
session = RepositoryUtil.getSession(this.manager, request);
} catch (RepositoryException e1) {
throw new RuntimeException(e1);
}
if (getLogger().isDebugEnabled()) {
getLogger().debug("Creating repository source for URI [" + location + "]");
}
Document document;
try {
document = factory.get(pub, area, uuid, language);
} catch (DocumentBuildException e) {
throw new MalformedURLException("Malformed lenyadoc: Document [" + uuid + ":"
+ language + "] could not be created.");
}