private void _saveVirtualLink(ActionRequest req, ActionResponse res,PortletConfig config,ActionForm form, User user)
throws Exception {
HostAPI hostAPI = APILocator.getHostAPI();
VirtualLinkForm mlForm = (VirtualLinkForm) form;
String completeUrl = null;
String url = mlForm.getUrl();
if( !url.startsWith("/") ) {
url = "/" + url;
}
if (InodeUtils.isSet(mlForm.getHostId())) {
Host host = hostAPI.find(mlForm.getHostId(), user, false);
completeUrl = host.getHostname() + ":" + url;
} else {
completeUrl = url;
}
if (completeUrl.trim().endsWith("/")) {
completeUrl = completeUrl.trim().substring(0, completeUrl.trim().length() - 1);
}
VirtualLink vl = null;
try{
vl = VirtualLinkFactory.getVirtualLinkByURL(completeUrl);
if(vl == null || !UtilMethods.isSet(vl.getIdentifier())){
vl = new VirtualLink();
vl.setUrl(completeUrl);
}
}
catch(DotHibernateException dhe){
vl = new VirtualLink();
vl.setUrl(completeUrl);
Logger.debug(VirtualLinksCache.class, "failed to find: " + completeUrl);
}
vl = virtualLinkAPI.checkVirtualLinkForEditPermissions(vl, user);
if(vl == null){
SessionMessages.add(req,"message", "message.virtuallink.nopermission.save");
throw new Exception(WebKeys.USER_PERMISSIONS_EXCEPTION);
}
if (vl != null && InodeUtils.isSet(vl.getInode()) && !mlForm.getInode().equalsIgnoreCase(vl.getInode())) {
//there is another virtual link with the same url... urls are unique
SessionMessages.add(req,"message", "message.virtuallink.uniquelink.save");
throw new Exception(WebKeys.UNIQUE_VIRTUAL_LINK_EXCEPTION);
}
else {
VirtualLink ml = (VirtualLink) req.getAttribute(WebKeys.VIRTUAL_LINK_EDIT);
//removes this URL from cache
if (UtilMethods.isSet(ml.getUrl())) {
VirtualLinksCache.removePathFromCache(ml.getUrl());
}
BeanUtils.copyProperties(ml,form);
ml.setUrl(completeUrl);
String htmlPageInode = mlForm.getHtmlInode();
if (InodeUtils.isSet(htmlPageInode)) {
//it's an internal page
HTMLPage htmlPage = (HTMLPage) InodeFactory.getInode(htmlPageInode+"",HTMLPage.class);
Identifier identifier = APILocator.getIdentifierAPI().find(htmlPage);
ml.setUri(identifier.getURI());