Skip to Content
author's profile photo Former Member
Former Member

KM API to get userhome links to favorites

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

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • author's profile photo Former Member
    Former Member
    Posted on Jan 05, 2009 at 09:37 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      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

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.