cancel
Showing results for 
Search instead for 
Did you mean: 

KM API to get userhome links to favorites

Former Member
0 Kudos

Hi

I am trying to get the list of portal favorites the user has checked for himself by using

KM API. What code should I use in order to get this list of favorites?

Thank you

yuval

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

portal favorites are links saved in USERHOME repository of the current user. So you should use standard KM API to get list of links in this RID:

/~alias~/userhome/<user.id>/favorites/

Hope this helps,

Romano

Former Member
0 Kudos

Romano

Thank you for your reply.

It helped but right now I get the list of links in my favorite folder, but I am unalbe to open

the link if I press it.

How do I make the linkToUrl open the iview this link points to ???

regards

yuval

Former Member
0 Kudos

Hi,

never tried, but it seems, that the KM property of the resource:

http://sapportals.com/xmlns/cm/rendering::contentlink

should be the right way.

I have found this code in FavoriteRetriever.java


private IMenuItemTemplate parseFavorite(IResource resource, boolean linked)
                throws ODIException
            {
/* 214*/        if(resource == null)
                {
/* 215*/            BaseLogManager.warn(com.sap.caf.eu.odi.mnuacc.util.impl.FavoriteRetriever.class, LoggingCategories.SERVER, "null passed as resource. Probably invalid structure of favorites.");
/* 216*/            return new MenuItemTemplate();
                }
                String name;
                String url;
/* 221*/        if(!LinkType.EXTERNAL.equals(resource.getLinkType()))
/* 225*/            break MISSING_BLOCK_LABEL_85;
/* 225*/        name = resource.getName();
/* 226*/        url = resource.getTargetURL().toString();
/* 228*/        return new MenuItemTemplate(name, url);
/* 230*/        if(LinkType.INTERNAL.equals(resource.getLinkType()))
/* 233*/            return parseFavorite(resource.getTargetResource(), true);
                String url;
/* 235*/        if(!resource.isCollection())
/* 240*/            break MISSING_BLOCK_LABEL_247;
/* 240*/        name = resource.getName();
/* 242*/        if(!linked)
/* 245*/            break MISSING_BLOCK_LABEL_184;
/* 245*/        IUriReference uri = m_urlGen.getRelativeUri(PathKey.NAVIGATION_PAGE);
/* 246*/        uri = uri.appendPath(resource.getRID().getPath());
/* 247*/        url = uri.toExternalForm();
/* 249*/        return new MenuItemTemplate(name, url);
                MenuItemTemplate item;
/* 253*/        item = new MenuItemTemplate(name);
/* 255*/        IResourceList list = ((ICollection)resource).getChildren();
/* 256*/        for(IResourceListIterator children = list.listIterator(); children.hasNext(); item.addChild(parseFavorite(children.next(), false)));
/* 261*/        return item;
/* 267*/        name = resource.getName();
/* 269*/        item = null;
/* 272*/        com.sapportals.wcm.repository.IPropertyName propName = new PropertyName("http://sapportals.com/xmlns/cm/rendering", "contentlink");
/* 273*/        IProperty property = resource.getProperty(propName);
/* 274*/        if(property != null)
                {
/* 275*/            String portalNavUrl = property.getStringValue();
/* 277*/            if(portalNavUrl.startsWith("<PORTAL_NAVIGATION>"))
/* 278*/                portalNavUrl = portalNavUrl.substring(19);
/* 281*/            item = "/irj/portal?NavigationTarget=" + portalNavUrl;
                }
/* 285*/        if(item == null)
                {
/* 286*/            IUriReference uri = m_urlGen.getRelativeUri(PathKey.VIEWER_PATH);
/* 287*/            uri = uri.appendPath(resource.getRID().getPath());
/* 288*/            item = uri.toExternalForm();
                }
/* 291*/        return new MenuItemTemplate(name, item);
                Exception e;
/* 294*/        e;
/* 295*/        if(e instanceof ODIException)
                {
/* 296*/            throw (ODIException)e;
                } else
                {
/* 298*/            BaseLogManager.error(com.sap.caf.eu.odi.mnuacc.util.impl.FavoriteRetriever.class, LoggingCategories.SERVER, "Unable to parse Favorites.", e);
/* 299*/            throw new ODIException(LOCATION, ODIResourceAccessor.getInstance(), "PORTAL_ACCESS_FAILED", e);
                }
            }

Romano