cancel
Showing results for 
Search instead for 
Did you mean: 

Get WebDav URI from NodeRef

pedrosaraiva
Champ in-the-making
Champ in-the-making
Hello,

I'm new to Alfresco and I'm trying to implement a listener to integrate with another system that will be triggered when a file (or folder) is created, deleted, updated and versioned. I’ve created a behaviour and binded to the policies onContentUpdate, onCreateNode, onUpdateNode… etc. I'm using java.
Now I need to get some properties from the file that triggered that policy. How can I, for example, get the WebDav URL from the NodeRef of the file?

Kind regards,

Pedro Saraiva
6 REPLIES 6

mikeh
Star Contributor
Star Contributor
This is how it's done in org.alfresco.repo.jscript.ScriptNode:
    public String getWebdavUrl()
    {
        try
        {
            List<FileInfo> paths = this.services.getFileFolderService().getNamePath(null, getNodeRef());
           
            // build up the webdav url
            StringBuilder path = new StringBuilder(128);
            path.append("/webdav");
           
            // build up the path skipping the first path as it is the root folder
            for (int i=1; i<paths.size(); i++)
            {
                path.append("/")
                    .append(URLEncoder.encode(paths.get(i).getName()));
            }
            return path.toString();
        }
        catch (FileNotFoundException nodeErr)
        {
            // cannot build path if file no longer exists
            return "";
        }
    }

Thanks,
Mike

pedrosaraiva
Champ in-the-making
Champ in-the-making
Hello and thanks for the fast reply.

But how can access this:

this.services.getFileFolderService().getNamePath(null, getNodeRef());

?

Kind regards,

Pedro Saraiva

This is how it's done in org.alfresco.repo.jscript.ScriptNode:
    public String getWebdavUrl()
    {
        try
        {
            List<FileInfo> paths = this.services.getFileFolderService().getNamePath(null, getNodeRef());
           
            // build up the webdav url
            StringBuilder path = new StringBuilder(128);
            path.append("/webdav");
           
            // build up the path skipping the first path as it is the root folder
            for (int i=1; i<paths.size(); i++)
            {
                path.append("/")
                    .append(URLEncoder.encode(paths.get(i).getName()));
            }
            return path.toString();
        }
        catch (FileNotFoundException nodeErr)
        {
            // cannot build path if file no longer exists
            return "";
        }
    }

Thanks,
Mike

mikeh
Star Contributor
Star Contributor
Provide a setter function and configure it in your bean definition. It's probably easier if you just go straight to the org.alfresco.service.cmr.model.FileFolderService:
<property name="fileFolderService" ref="FileFolderService"/>
public void setFileFolderService(FileFolderService fileFolderService)
{
    this.fileFolderService = fileFolderService;
}

Thanks,
Mike

pedrosaraiva
Champ in-the-making
Champ in-the-making
Thanks, that did the trick!

However that only gives me path without the host part. How can I get alfresco tomcat port from Java?

Kind regards,

Pedro Saraiva

bluearth
Champ in-the-making
Champ in-the-making
Have a common situation here,

I found this on org.alfresco.web.beans.BaseDetailsBean ( bean that backs up the space / content detail page, where the webdav link is shown)


   public String getWebdavUrl()
   {
      Node node = getLinkResolvedNode();
      return Utils.generateURL(FacesContext.getCurrentInstance(), node, URLMode.WEBDAV);
   }

   public String getBookmarkUrl()
   {
      return Utils.generateURL(FacesContext.getCurrentInstance(), getNode(), URLMode.SHOW_DETAILS);
   }

Utils class and URLMode enum is at org.alfresco.web.ui.common.Utils and org.alfresco.web.ui.common.Utils.URLMode respectively

using that utility method, you should be able to get complete webdav url to your node.

pedrosaraiva
Champ in-the-making
Champ in-the-making
Hello,

Thanks for the answer. However, I'm still getting the last part of the URL.


public String getWebdavUrl( NodeRef nodeRef )
{
      Node node = new Node( nodeRef );
      return Utils.generateURL( FacesContext.getCurrentInstance(), node, URLMode.WEBDAV );
}

Can I ask what you do on the method getLinkResolvedNode()?

Kind regards,

Pedro Saraiva

Have a common situation here,

I found this on org.alfresco.web.beans.BaseDetailsBean ( bean that backs up the space / content detail page, where the webdav link is shown)


   public String getWebdavUrl()
   {
      Node node = getLinkResolvedNode();
      return Utils.generateURL(FacesContext.getCurrentInstance(), node, URLMode.WEBDAV);
   }

   public String getBookmarkUrl()
   {
      return Utils.generateURL(FacesContext.getCurrentInstance(), getNode(), URLMode.SHOW_DETAILS);
   }

Utils class and URLMode enum is at org.alfresco.web.ui.common.Utils and org.alfresco.web.ui.common.Utils.URLMode respectively

using that utility method, you should be able to get complete webdav url to your node.