Home > Articles > Software Development & Management

  • Print
  • + Share This
This chapter is from the book

Implementing a Simple Mashup

This section demonstrates the application of concepts discussed in this chapter to create a simple presentation-oriented mashup. Apart from a local service platform, the sources used for the mashup are publicly available and provide either a service API, an RSS data feed, or a dynamic script feed. This section does not discuss issues such as application keys, security, and governance for this mashup; these topics are discussed in depth in later chapters.

For the sake of complete coverage of the mashup domains discussed, the mashup will make service calls and retrieve data from external sites as well as a local service platform that operates around the model illustrated in Figure 1.11.

Figure 1.11

Figure 1.11 Services platform architecture

Figure 1.11 illustrates a service platform that uses only a small number of primary components to process service and resource requests. The platform uses the Representational State Transfer (REST) approach (to be discussed later) for service and resource request/responses. The service platform provides access to services and uses a simple resource framework to create, retrieve, update, and delete resources.

The application (shown in Listing 1.8 and in Figure 1.12) allows users to view disparate data that might be available in a typical enterprise. The data is presented in a portal-like manner to simplify the layout and UI-management code. The application integrates a list of corporate documents, a map feed, an RSS feed, a calendar gadget, a Twitter counter chicklet, and a Twitter archive list delivered as RSS.

Figure 1.12

Figure 1.12 Presentation-oriented mashup example

Listing 1.8. Presentation-Oriented Mashup Using Aggregated UI Artifacts

<html>
<head>
<!-- Include Google Maps Javascript Library -->
<script type="text/javascript" src="http://maps.google.com/maps?file=api&v=1& key=
ABQIAAAA01HpWF7mf2aW91RNaGDc7xTfGML3OZxtDDthfq-aZ1uFtrk9MRS_VWEizymnfki_h89lqU7A0ts2PA">
</script>

<script type="text/javascript">

Figure 1.12 illustrates the final result of the presentation-oriented mashup example discussed in this section.

The load function in Listing 1.9 retrieves a hard-coded Google map and applies it to the map div element in the HTML DOM.

Listing 1.9. Applying a Google Map to a Web Page

  function load()
  {
    if (GBrowserIsCompatible())
    {
      // create map component in div with the id = "map"
      var map = new GMap2(document.getElementById("map"));
      // create map components components
      map.addControl(new GSmallMapControl());
      map.addControl(new GMapTypeControl());
      // create center point when map is displayed
      map.setCenter(new GLatLng(37.4419, -122.1419), 13);
      map.openInfoWindow(map.getCenter(),
                         "<b>Your Company Here</b>");
      // re-open the info balloon if they close it
      var point = new GLatLng(37.395746, -121.952234);
      map.addOverlay(createMarker(point, 1));
    }
  }

  function createMarker(point, number)
  {
    var marker = new GMarker(point);
    // create clickable point with title for address
    GEvent.addListener(marker, "click", function()
    {
       marker.openInfoWindowHtml("<b>Your Company Here</b>");
    });
    return marker;
  }

  function retrieveExternalData()
  {
      var script = document.createElement("script");
      script.src =
        'http://www.example.com/mashups/someservice';
      script.type = 'text/javascript';
      document.body.appendChild(script);
  }

</script>
</head>
<body onload="load()">

In the example shown in Listing 1.10 a div element is added to contain a list of corporate documents retrieved from a Google Docs account using dynamic script.

Listing 1.10. Dynamic Script to Show a List of Documents

    <!-- div to hold documents -->
    <div id="docs"
         style="border-style:ridge; position: absolute;
            left: 10px; top: 10px; width:200px; height:930px">
    <script src="http://gmodules.com/ig/ifr?
            url=http://www.google.com/ig/modules/docs.xml
            &amp;up_numDocuments=9&amp;up_showLastEdit=1
            &amp;synd=open&amp;w=180&amp;h=860
            &amp;title=Company+Documents
            &amp;lang=en&amp;country=ALL
            &amp;border=%23ffffff%7C3px%2C1px+solid+%23999999
            &amp;output=js"></script>
    </div>

Listing 1.11 illustrates a div element that will hold the results from the Google map retrieval.

Listing 1.11. Element to Contain a Google Map

    <div id="map"
         style="border-style:ridge; position: absolute;
         left: 220px; top: 10px; width:400px; height:300px">
</div>

In Listing 1.12 a div element is added to contain an RSS feed using dynamic script.

Listing 1.12. Element to Contain an RSS Feed

    <!-- div to hold RSS feed -->
    <div id="feed"
         style="border-style:ridge; position: absolute;
         left: 630px; top: 10px; width:400px; height:300px">
    <script src="http://gmodules.com/ig/ifr?
      url=http://customrss.googlepages.com/customrss.xml
      &amp;up_rssurl=http%3A%2F%2Fwww.javaworld.com%2Findex.xml
      &amp;up_title=CustomRSS
      &amp;up_titleurl=http%3A%2F%2Fcustomrss.googlepages.com
      &amp;up_num_entries=10&amp;up_linkaction=showdescription
      &amp;up_background=E1E9C3&amp;up_border=CFC58E
      &amp;up_round=1&amp;up_fontfamily=Arial
      &amp;up_fontsize=8pt&amp;up_openfontsize=9pt
      &amp;up_itempadding=3px&amp;up_bullet=icon
      &amp;up_custicon=Overrides%20favicon.ico
      &amp;up_boxicon=1&amp;up_opacity=20
      &amp;up_itemlinkcolor=596F3E&amp;up_itemlinkweight=Normal
      &amp;up_itemlinkdecoration=None&amp;up_vlinkcolor=C7CFA8
      &amp;up_vlinkweight=Normal&amp;up_vlinkdecoration=None
      &amp;up_showdate=1&amp;up_datecolor=9F9F9F
      &amp;up_tcolor=1C57A9&amp;up_thighlight=FFF19D
      &amp;up_desclinkcolor=1B5790&amp;up_color=000000
      &amp;up_dback=FFFFFF&amp;up_dborder=DFCE6F
      &amp;up_desclinkweight=Bold&amp;up_desclinkdecoration=None
      &amp;synd=open&amp;w=380&amp;h=240&amp;title=JavaWorld
      &amp;border=%23ffffff%7C3px%2C1px+solid+%23999999
      &amp;output=js"></script>
    </div>

Listing 1.13 shows a div element to contain a Google calendar retrieved using a JavaScript badge.

Listing 1.13. Google Calendar Element

    <!-- div to hold calendar -->
    <div id="calendar"
         style="border-style:ridge; position: absolute;
         left: 220px; top: 320px; width:810px; height:620px">
    <iframe src="http://www.google.com/calendar/embed?
                 src=o78s3eqe3ov403cpuav2bje5ja9j1tp2%40
                 import.calendar.google.com&ctz=America/Denver"
      style="border: 0"
      width="800" height="600" frameborder="0" scrolling="no">
      </iframe>
    </div>

Shown in Listing 1.14 is a div element to contain the Twitter counter chicklet.

Listing 1.14. A div Element to Contain a Twitter Chicklet

    <!-- div to hold the Twitter counter chicklet -->
    <div id="chicklet"
         style="border-style:ridge; position: absolute;
         left: 1040px; top: 10px; width:200px; height:40px">
    <a href="http://twittercounter.com/?username=jhanson583"
       title="TwitterCounter for @jhanson583"><img src="http://twittercounter.com/
counter/?username=jhanson583"
                                           width="88"
                                           height="26"
                                           style="border:none;"
                                           alt="TwitterCounter
for @jhanson583" /></a>
    </div>

Listing 1.15 illustrates the div element to contain the Twitter RSS feed using dynamic script.

Listing 1.15. Twitter RSS Feed div Element

    <!-- div to hold twitter feed -->
    <div id="ufbadge"
         style="border-style:ridge; position: absolute;
         left: 1040px; top: 60px; width:200px; height:880px">
      <script src="http://pipes.yahoo.com/js/listbadge.js">
              {"pipe_id":"dq0Qhuqp3BG1psChjtzu1g",
               "_btype":"list",
               "pipe_params":{
                  "urlRSS":"http:\/\/twitter.com
                  \/statuses\/user_timeline\/10852552.rss"},
               "width":"190",
               "height":"870"}
      </script>
    </div>

In Listing 1.16 I add the div element to contain the local RSS feed using dynamic script.

Listing 1.16. RSS Feed Element

    <!-- div to hold local RSS feed -->
    <div id="localfeed"
         style="border-style:ridge; position: absolute;
         left: 10px; top: 950px; width:1210px; height:200px">
      <script src="http://localhost:8080/mashups/js/rssbadge.js">
              {"urlRSS":"http:\/\/localhost:8080
              \/mashups\/services\/feeds\/zurn.rss"}
</script>
    </div>
</body>
</html>

The mashup in the preceding example illustrates many different techniques and technologies as applied to a simple presentation-oriented mashup. In the next chapter I discuss the preparations that need to be made before building an enterprise mashup.

  • + Share This
  • 🔖 Save To Your Account