Translate

Saturday, March 28, 2015

UI/Functionality: Developing Gadgets

This blog is about rendering Gadgets: Static content, Dynamic content and CS-based content.

Before jumping into creating Gadgets, it is better to go through architecture of Gadget server and the topic: About Developing Gadgets.

Applies to only 11.1.1.8.0 and above. All the following examples were tested using JSK 11.1.1.8.0 (installed all sites + community-gadget) on Windows 7 64-bit machine.

Gadget created with Static Content (JSON):

1. Create one following text file which contains json (json.txt) as shown and save it as location where it can be fetched by ContentServer (I saved it under <webapps>/cs/custom/ folder) :

{"Name" : "Rowan", "Breed" : "Labrador Retriever", "Hobbies" : ["fetching", "swimming", "tugging", "eating"]}

2. Create one simple XML (gadget descriptor) file which parses JSON and save it as FetchJson.xml in the same above folder location

<?xml version="1.0" encoding="UTF-8" ?>
<Module>
  <ModulePrefs title="Fetch JSON Example"/>
  <Content type="html">
  <![CDATA[
    <div id="content_div"></div>
    <script type="text/javascript">

    function makeJSONRequest() {    
      var params = {};
      params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.JSON;
      // This URL returns a JSON-encoded string that represents a JavaScript object
      var url = "http://localhost:9080/cs/custom/gadgets/json.txt";
      gadgets.io.makeRequest(url, response, params);
    };

    function response(obj) { 
      var jsondata = obj.data;
      var html = "";
      // Process returned JS object as an associative array
      for (var key in jsondata) {
        var value = jsondata[key];
        html += key + ": ";
        // If 'value' is an array, render its contents as a bulleted list
        if (value instanceof Array)
        {
          html += "<br /><ul>";
          for (var i = 0; i < value.length ; i++)
          {
            html += "<li>"+ jsondata.Hobbies[i] + "</li>";
          }
          html+= "</ul>";
        }  
        // If 'value' isn't an array, just write it out as a string
        else {        
          html += value + "<br />";
        }      
      }               
      document.getElementById('content_div').innerHTML = html;
     };
     gadgets.util.registerOnLoadHandler(makeJSONRequest);
     </script>
  ]]>
  </Content>
</Module>

3. Login to WebCenter Sites -  Go to "Gadgets" UI - Select Catalog - Register Gadget
4. Paste the following URL: http://localhost:9080/cs/custom/gadgets/FetchJson.xml (Your location hostname, portname and location may vary according to your installation). Provide all the other fields and SAVE. Deploy your gadget or dashboard. Your gadget on Dashboard should look like this:

Gadget created dynamically: If you have a gadget descriptor XML url, then you can directly "Register Gadget" and  preview. You can try with this "Hello World" example (just copy the URL and paste) which ends up like this:

Usage: If you have certain dynamic URLs, like feeds, dictionary, weather, news, map, calendar, clock. etc. , then they can be deployed directly into Gadgets Server and can be viewed on site as required.

CS-Based Gadget created with content from WebCenter Sites:
Although detailed explanation is provided in Developer's Guide and User's Guide , it seems difficult to understand and test the examples provided. So after understanding the main concept, I created one of the example - List Gadget. (All other examples can be downloaded from oracle edelivery)Before we jump into example, one should understand the template flow. For List Gadget, template flow is as shown:
Description of Figure 92-1 follows

Procedure (download all files from here):
1. Create one basic asset type using AssetMaker Utility - FW_CSGadget (field: assetdescriptor) and add an association to it: DataAsset (type: recommendation) and create one asset: ListGadget from Contributor UI. Associate Recommendation (Content_C) to the DataAsset association.
2. Create Main template - GenerateGadgetXML (Type:FW_CSGadget; Template can be called externally or in browser) which is responsible for generating the Gadget Descriptor XML file.
3. This main template calls - ListGadget template (G_List: Type-FW_CSGadget and Template can be called externally or in browser) which basically loads the ListGadget asset and the associated recommendation (this recommendation contains list of Content_C assets) which calls recommendation template (AdvCols/G_JSON) and which in turn calls Content_C(Content_C/G_JSON)
4. Few files are deployed to <webapps>/cs/FirstSiteII/gadget location for <locale> attribute of XML.
5. If you have followed the above procedure by copying all the code from the shared folder and deploying gadget folder to the above mentioned location, then there should be no issue in creating ListGagdet. Go to "Gadget UI" - Catalog - "Register Gadget" and enter the URL, fill other fields and save. All done!! (Note: cid in the URL should be your ListGadget basic asset id)
6. Now you either deploy it as a single Gadget or update your Dashboard and then deploy full Dashboard itself. This is how ListGadget looks in Dashboard:



----------------------------------------------------
SUGGESTIONS/COMMENTS ARE INVITED
----------------------------------------------------

Wednesday, March 18, 2015

UI Customization: Changing icons in FatWire/Oracle WebCenter Sites

This is just a simple UI customization which may or may not be required but just listing it down (mostly applies to Oracle WebCenter Sites 11g)

1. Changing login icon: Few Client may want to show their own logo while logging to Sites instance

Procedure:
  • Just add all the image files under this folder - <webapps>/cs/js/fw/images/logos/
  • Update login.css file placed under this folder - <webapps>/cas/fatwire/css/ to include your image name
2.  Changing Asset Type icon (Only applies to Oracle WebCenter Sites 11g): It is possible to show different icons on basis of asset types and definitions. For e.g. If you have media flex family and have 2-3 different asset type under it like video, image, audio, etc. Your client may ask to show icons which loads up everywhere like tree tabs in Admin UI, content tree in Contributor UI, etc. wherever this asset types shows up.

 Procedure:
  • Download all the icons (recommended: 16x16 png)
  • Place all the files under this folder with correct asset name:<App_Server>/webapps/cs/Xcelerate/OMTree/TreeImages/AssetTypes/<ASSET_TYPE>.png
  • If your asset name is - "Content_A", your icon name should be Content_A.png placed under the folder mentioned above.
  • For showing icon on definition basis(i.e. subtype): <App_Server>/webapps/cs/Xcelerate/OMTree/TreeImages/AssetTypes/<ASSET_TYPE>/<ASSET_TYPE>-<SUBTYPE>.png
----------------------------------------------------
SUGGESTIONS/COMMENTS ARE INVITED
----------------------------------------------------

Sunday, March 15, 2015

UI/Functionality Customization: Proxy Assets (Google Map)

After the introduction of Proxy Assets in Oracle WebCenter Sites 11.1.1.8.0, it has become easy to fetch data from external repository. As content is not stored in Sites (rather its present in the service provider database) there is no longer need for storing data or importing bulk content in Sites and later bothering with content storing, publishing and handling tell-tale errors (given that there is API for fetching data from third party repository which generates data on the fly).

Hence, the use of Proxy Assets opens up plethora of opportunities for implementation like:
  • Use of Google Translator API (only paid version is available) to replace use of Dimensions (May be possible, not tried though)
  • Use of Google Map API (free and paid, both available) to include Google Map on your site. Other maps like MapQuest, etc. can also be included if such API is available.
  • Including location based weather information on your site (various free and paid version are available)
  • Including NewsLetter (automatically get updated news on daily basis) from various News provider and target audience via Segments and Recommendation (Implemented and works perfectly)
  • Including third-party search which rankes your web pages first (Note: Google no longer supports custom search API. Other search providers like Yahoo and Bing are open to use with either both free and/or paid version API)
  • Google Youtube API to include youtube videos.

Proxy Asset follows the architecture:
Proxy Asset Architecture

Requirements for using Proxy Assets (Applies only to Oracle WebCenter Sites 11.1.1.8.0 and above):
  1. You need to have service URL (API provided by third-party service) whose output on querying results in either JSON or XML(mainly these 2 because already there are jar present in webapps/cs/WEB-INF/lib folder to process them). Other outputs can also be handled, but will require deploying jar for them.
  2.  You may or may not need a key to access these API (API can be public or from some organization; again depends on service provider)
Implemenation:
There is already an example present in JSK 11.1.1.8.0 for Youtube Proxy Assets and an excerpt in guide for static content. So I just thought to create my own example and ended up creating Google Map Proxy Asset.

For testing Youtube proxy assets, navigate to Contributor UI (avisports), select Youtube and search any video. The search result views are customized for Youtube proxy assets: List View and Thumbnail View. You can check the code under <Sites_Installation>/Shared/elements/CustomElements/Youtube folders where folder structure looks like this:


I will just summarize what each of them does:
  1. Youtube/UI/Data/Search/SearchAction.jsp: This element is responsible for searching against third-party API on basis of keyword (keyword can be anything and depends on API, check the service provider API documentation) and gets JSON output and then registers the proxy assets (saves one unique key for later use)
  2. Youtube/UI/Data/Search/SearchJson.jsp: Just stores the proxy asset
  3. Youtube/Layout/CenterPane/Form/ProxyHtml.jsp: This element shows an invidual youtube proxy asset. It fetches the registered proxy asset, uses the stored unique key (externalid) and then uses the API to retrieve the data on the fly. This element is called when you click on any search results from either View (List or Thumbnail).
  4. Rest of them are search view customization: Read about them here -> Customizing the Contributor Interface
Creating Proxy Assets for GoogleMap (ReverseGeoCoding) (AssetType name - "GoogleMap") :
  1. Get a key (available free but with some limitations or the paid one). Details present here.
  2. Just get any icon for GoogleMap (16x16 png file) and place it under <App_Server>/webapps/cs/Xcelerate/OMTree/TreeImages/AssetTypes/GoogleMap.png 



  3. Create one Proxy Asset Type from Admin Tab. In the Admin tab, expand Proxy Asset Manager and Double-click Add New.   
  4. Open Sites Explorer and create folder structure under CustomElements (same as it was done for Youtube proxy asset but name would be assettype i.e. GoogleMap) which should end up like this:
  5.  Create "SearchAction.jsp", "SearchJson.jsp" and "ProxyHtml.jsp" file under respective folder from SitesExplorer and save. Navigate to <Sites_Installation>/Shared/elements/CustomElements/ to see if there is a "GoogleMap" named folder created and the structure will be as shown above.
  6. Copy the element code from SearchAction.jsp, SearchJson.jsp and ProxyHtml.jsp and paste it in respective elements.
  7. Open ProxyHtml.jsp in some file editor and paste your Google Map key on line number 23. Just replace <USE YOUR OWN KEY> with GoogleMap key
  8. Create new "search" start menu for GoogleMap proxy asset (Google Map location) and enable GoogleMap proxy asset for your site. I enabled it for AviSports.

    Select "Google Map Location" and search against any location. You may get one or more results. Click on any one of the result to view it, which should look this:


    Note: I am storing latitude, longitude and address in externalid so that when map loads up, I can use latitude and longitude for finding location on map (reverse geocoding) and address for dropping marker on the map.

    Furthermore, you can change search views, add custom tree tabs, add the proxy asset via insite editing to your assets, etc. All details are present in developer's guide and the templates for Youtube proxy asset. 


    ----------------------------------------------------
    SUGGESTIONS/COMMENTS ARE INVITED
    ----------------------------------------------------