if (count == 0 || "true".equals(config.getString(CRConfig.ADVPLR_HOST_FORCE))) { //not permitted or forced, build link
ret = getAlternateUrl(contentid);
} else {
Resolvable plinkObject;
try {
plinkObject = PortalConnectorFactory.getContentObject(contentid, ds);
//TODO: make this more beautiful and compatible with portlets
String filename_attribute = (String) config.get(CRConfig.ADVPLR_FN_KEY);
String pub_dir_attribute = (String) config.get(CRConfig.ADVPLR_PB_KEY);
String filename = (String) plinkObject.get(filename_attribute);
String pub_dir = (String) plinkObject.get(pub_dir_attribute);
HttpServletRequest servletRequest = (HttpServletRequest) request.get("request");
String contextPath = servletRequest.getContextPath();
String servletPath = servletRequest.getServletPath();
ret = contextPath + servletPath + pub_dir + filename;
} catch (DatasourceNotAvailableException e) {