Show TOC

Integrating External FavoritesLocate this document in the navigation structure

Use

The Favorites Provider API enables you to extend portal favorites by integrating favorites from various external sources and making them available from the Favorites menu of Ajax Framework Page.

For each source of favorites, you must implement the following interfaces:

  • IFavorite that represents a single favorite link

  • IFavoritesProvider that provides the common functionality of the favorites

Package

The Favorites Provider API is contained in the com.sap.portal.favorites package.

Procedure

The following procedure guides you through the steps necessary to implement a custom provider of favorites.

Setting Up the Project

  1. In SAP NetWeaver Developer Studio, open the Enterprise Portal perspective and create a portal application project named MyFavorites.

    For more information, see Creating a Portal Application Project .

  2. In portalapp.xml, add a sharing reference to the API:

                         
    <application-config>
        <property name="SharingReference"
        value="com.sap.portal.favorites.service.api"
    </application-config>
    
                      

Implementing a Custom Favorites Provider Service

  1. In the portal application project, create a portal service named CustomProvider. The Java interface ICustomProvider and its implementation class CustomProvider are automatically created in the src.api and src.core folders respectively.

    For more information, see Creating a Portal Service .

  2. In the service properties, add the startup property, setting it to true . This is required to ensure that your service is loaded each time the portal is started, or after your application is deployed.

    <property name="startup" value="true"/> is added to the <service-config> section of portalapp.xml.

  3. Make sure that ICustomProvider extends IFavoritesProvider.

  4. Define the service key and ID of ICustomProvider:

    Sample Code
                            
    public static final String KEY = MyFavorites.CustomProvider;
    public static final String ID = "CustomProviderID::";
                         
    Note

    It is important to include "::" at the end of the ID.

  5. Make sure that CustomProvider implements the generic portal service interface com.sapportals.portal.prt.service.IService and your ICustomProvider interface, and that the default implementations of the IService methods are added.

  6. To register your provider, paste the following code to the init() method of CustomProvider:

    Sample Code
                            
    IFavoritesProviderRegistration favoritesProviderRegistration = 
    (IFavoritesProviderRegistration)PortalRuntime.getRuntimeResources().
     getService(IFavoritesProviderRegistration.KEY);
    
    favoritesProviderRegistration.register(CustomProvider.ID, (IFavoritesProvider) this);
    
                         
  7. To unregister your provider, paste the following code to the destroy() method of CustomProvider:

    Sample Code
                            
    IFavoritesProviderRegistration favoritesProviderRegistration = 
    (IFavoritesProviderRegistration)PortalRuntime.getRuntimeResources().
     getService(IFavoritesProviderRegistration.KEY);
    
    favoritesProviderRegistration.unregister(CustomProvider.ID)
    
                         
  8. Implement the getID() method to return the ID your provider.

Implementing Favorites

Each favorite link or folder is represented by a Favorite object. To implement this object, perform the following steps:

  1. In the src.core folder, create a new class that represents your custom Favorite object, implementing the com.sap.portal.favorites.IFavorite interface. If required, implement this class to hold the state and its methods to perform the logic specific for your favorites.

  2. Implement other methods of the interface to support the required functionality. For example, to support deletion or renaming of the favorite, implement deleteFavorite() or renameFavorite() to perform the actual operations.

The following example illustrates how to build a folder of favorites with two child links to Web sites.

  1. Add the following code to CustomProvider:

    Sample Code
                            
    // List of capabilities for the Favorites
            private List<Capability> capabilitiesList = new ArrayList<Capability>();
    
    // Create a list of child favorites
    private List getChildrenList()
    {
                    List<Capability> capabilitiesList = new ArrayList<Capability>();
                    // Favorites can be deleted and removed
                    capabilitiesList.add(Capability.DELETE);
                    capabilitiesList.add(Capability.RENAME);
                            
                    WebFavorite googleFavorite = new WebFavorite(
                                    "Google Maps", 
                                    "http://maps.google.com/",
                                    "Google",   
                                    IFavorite.Type.OTHER,                                   
                                    0,
                                    null,
                                    capabilitiesList);
    
                            childrenList.add(googleFavorite);
                    
                            WebFavorite amazonFavorite = new WebFavorite(
                                    "Amazon", 
                                    "http://www.amazon.com/",
                                    "Amazon",   
                                    IFavorite.Type.OTHER,                                   
                                    0,
                                    null,
                                    capabilitiesList);
    
                            childrenList.add(amazonFavorite);
                    
                    return childrenList;
    }
    
                         
  2. Add the following code to the implementation of getFavoritesList() method. It creates the root folder with the child favorites, returned by the getChildrenList() function.

    Sample Code
                            
    // List of capabilities for the Favorites root folder
            private List<Capability> rootCapabilitiesList = new ArrayList<Capability>();
    
    IFavorite rootFavorite = new MyFavorite("My Favorites", targetURL, rootID, IFavorite.Type.OTHER, 0, getChildrenList(), rootCapabilitiesList);
                         

Testing Your Custom Provider

  1. Build and deploy your application to the portal.

  2. In the Provider Configuration screen, add and enable your search provider. For more information, see Configuring Providers .

  3. In the portal, verify that your root custom folder is visible in the Favorites menu, and the child favorites are visible in the submenu.

  4. Choose one of the favorites and verify that the appropriate target is launched in a new window.

  5. In the Favorites menu, choose Organize Favorites , and test the capabilities, supported by your provider.