// Get parameters
final String[] attributes = name.split(":");
if (attributes.length < 3) {
throw new ConfigurationException("Invalid number of parameters: " + attributes.length
+ ". Expected area, document-id, language.");
}
final String area = attributes[0];
final String documentId = attributes[1];
final String language = attributes[2];
String value = null;
try {
PageEnvelope envelope = PageEnvelopeFactory.getInstance().getPageEnvelope(objectModel);
Publication publication = envelope.getPublication();
DocumentBuilder builder = publication.getDocumentBuilder();
// Create canonical URL
String canonicalUrl = builder
.buildCanonicalUrl(publication, area, documentId, language);
if (getLogger().isDebugEnabled()) {
getLogger().debug("Created canonicalURL: " + canonicalUrl);
}
// Get proxy for document
serviceSelector = (ServiceSelector) this.manager.lookup(AccessControllerResolver.ROLE
+ "Selector");
acResolver = (AccessControllerResolver) serviceSelector
.select(AccessControllerResolver.DEFAULT_RESOLVER);
AccessController accessController = acResolver.resolveAccessController(canonicalUrl);
if (accessController instanceof DefaultAccessController) {
DefaultAccessController defaultAccessController = (DefaultAccessController) accessController;
accreditableManager = defaultAccessController.getAccreditableManager();
Authorizer[] authorizers = defaultAccessController.getAuthorizers();
for (int i = 0; i < authorizers.length; i++) {
if (authorizers[i] instanceof PolicyAuthorizer) {
PolicyAuthorizer policyAuthorizer = (PolicyAuthorizer) authorizers[i];
policyManager = policyAuthorizer.getPolicyManager();
}
}
}
Policy policy = policyManager.getPolicy(accreditableManager, canonicalUrl);
Document doc = builder.buildDocument(publication, canonicalUrl);
Proxy proxy = doc.getPublication().getProxy(doc, policy.isSSLProtected());
if (proxy != null) {
value = proxy.getURL(doc);
} else {
// Take server name and port from request.
Request request = ObjectModelHelper.getRequest(objectModel);
value = "http://" + request.getServerName() + ":" + request.getServerPort()
+ request.getContextPath() + doc.getCompleteURL();
}
} catch (Exception e) {
throw new ConfigurationException("Obtaining value for [" + name + "] failed: ", e);
}
return value;
}