Application Programming Interface Reference IBM InfoSphere MashupHub
by user
Comments
Transcript
Application Programming Interface Reference IBM InfoSphere MashupHub
IBM InfoSphere MashupHub Application Programming Interface Reference Version 1.1 0 IBM InfoSphere MashupHub Application Programming Interface Reference Version 1.1 0 Note Before using this information and the product it supports, read the information in “Notices” on page 45. This edition applies to version 1.1 of IBM InfoSphere MashupHub and to all subsequent releases and modifications until otherwise indicated in new editions. © Copyright International Business Machines Corporation 2007, 2008. US Government Users Restricted Rights – Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. Contents Chapter 1. Introduction . . . . . . . . 1 Chapter 2. Search API. . . . . . . . . 3 Atom format . . . . Feed entry . . . . Page entry . . . . iWidget entry . . . Generic widget entry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 4 6 7 8 Chapter 3. Catalog API . . . . . . . . 11 Collections. APP Fetch . APP Create APP Edit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 12 12 13 Chapter 4. Metrics API . . . . . . . . 15 MashupHub tracking feed CSV . . . . . . . . JSON . . . . . . . Clear tracking data service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 18 18 19 Chapter 5. Feed API . . . . . . . . . 21 Plug-in packaging . . . Server-side . . . . . Package metadata . . Plug-in Interfaces . . Plug-in base classes. . Plug-in ViewBeans . . Library Considerations Client-side . . . . . . Wizard workflow . . Plug-in Base Classes . Developing plug-ins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 25 25 26 29 33 33 34 34 35 36 Appendix. Sample Plug-in . . . . . . 39 Feed editor component . . . . Editor component ViewBeans class Feed editor Java server page. . . Feed generator component . . . Feed generator implementation class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 40 40 41 41 Accessibility . . . . . . . . . . . . 43 Notices . . . . . . . . . . . . . . 45 Trademarks . . . . . . . . . . . . . . 46 Chapter 6. Plugin API . . . . . . . . 23 © Copyright IBM Corp. 2007, 2008 iii iv MashupHub API Reference Chapter 1. Introduction The IBM® MashupHub application programming interface (API) provides services for using the catalog and adding plug-in extensions to the MashupHub server. The catalog related services are all Representational State Transfer (REST) services based on the Atom Syndication Format and the Atom Publishing Protocol. The API provides these catalog services: v A service for searching the catalog v A service for adding new items to the catalog and for reading, updating and deleting those items v A service for collecting metrics on feed, widget and page usage MashupHub also provides a plug-in mechanism for adding extensions for the support of new content types and new feed data sources. For new feed data sources, developers can provide plug-in classes written in the Java™ language for Editor plug-in components, that provide a user interface for defining the contents of a feed, Generator plug-in components, that generate Atom or RSS feeds from particular data sources, and Collection plug-in components, that provide search and catalog API support. MashupHub can generate feeds from a number of data sources and it can support upload, download and other operations for widget and mashup pages. The feed generation for each type of data source is provided by a plug-in that is included as part of MashupHub. It also includes plug-ins for iWidgets, generic widgets and mashup pages. In the descriptions in this reference, all plug-ins, those provided by MashupHub and those added by third parties, are treated the same. Rather than refer to a data source or widget type, the descriptions will refer to the plug-ins that support them. © Copyright IBM Corp. 2007, 2008 1 2 MashupHub API Reference Chapter 2. Search API The Search API is an OpenSearch conformant REST interface. OpenSearch defines how a search provider exposes its search capability (the format and meaning of the search URIs) and the MashupHub feeds generated to return the search results. The Search API exposes an OpenSearch document that defines the queries it supports. The OpenSearch document is available at http://YourHostAnd Port/mashuphub/atom/os where YourHostAndPort is the base URL of the MashupHub installation. An example of this document follows: <?xml version="1.0" encoding="UTF-8"?> <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/" xmlns:moz="http://www.mozilla.org/2006/browser/search/" xmlns:catalog="http://www.ibm.com/opensearch/1.0"> <ShortName>MashupHub Catalog Search</ShortName> <LongName>MashupHub Catalog Search</LongName> <Developer>IBM</Developer> <Attribution>Search data Copyright 2007, IBM, All Rights Reserved</Attribution> <SyndicationRight>open</SyndicationRight> <AdultContent>false</AdultContent> <Language>en-us</Language> <OutputEncoding>UTF-8</OutputEncoding> <InputEncoding>UTF-8</InputEncoding> <Description>Feed of search results from a MashupHub catalog</Description> <Tags>feed</Tags> <Contact>admin@localhost</Contact> <Url type="application/atom+xml" template="https://localhost:8443/mashuphub/ atom?collection={catalog:collection}&searchType={catalog:searchType?} &searchTerms={searchTerm}&startIndex={startIndex?}&count={count?} &sortBy={catalog:sortBy?}&sortOrder={catalog:sortOrder?}"/> <Query role="example" catalog:collection="all" catalog:searchType="" searchTerms=""/> <Query role="catalog:all" catalog:collection="all" catalog:searchType="" /> <Query role="catalog:all-top" catalog:collection="all" catalog:searchType="top" /> <Query role="catalog:all-popular" catalog:collection="all" catalog:searchType="popular" /> <Query role="catalog:all-recent" catalog:collection="all" catalog:searchType="recent" /> <Query role="catalog:all-discussed" catalog:collection="all" catalog:searchType="discussed" /> <Query role="catalog:widget" catalog:collection="widget" catalog:searchType=""/> <Query role="catalog:widget-top" catalog:collection="widget" catalog:searchType="widget" /> <Query role="catalog:widget-popular" catalog:collection="widget" catalog:searchType="widget" /> <Query role="catalog:widget-recent" catalog:collection="widget" catalog:searchType="widget" /> <Query role="catalog:widget-discussed" catalog:collection="widget" catalog:searchType="widget" /> <Query role="catalog:feed" catalog:collection="feed" catalog:searchType=""/> <Query role="catalog:feed-top" catalog:collection="feed" catalog:searchType="top" /> <Query role="catalog:feed-popular" catalog:collection="feed" catalog:searchType="popular" /> <Query role="catalog:feed-recent" catalog:collection="feed" catalog:searchType="recent" /> <Query role="catalog:feed-discussed" catalog:collection="feed" catalog:searchType="discussed" /> © Copyright IBM Corp. 2007, 2008 3 <Query catalog:collection="pages" catalog:searchType="top" role="catalog:pages-top"/> <Query catalog:collection="pages" catalog:searchType="tag" role="catalog:pages-tag"/> <Query catalog:collection="pages" catalog:searchType="discussed" role="catalog:pages-discussed"/> <Query catalog:collection="pages" catalog:searchType="popular" role="catalog:pages-popular"/> <Query catalog:collection="pages" catalog:searchType="recent" role="catalog:pages-recent"/> <Query catalog:collection="pages" catalog:searchType="" role="catalog:pages"/> <Query catalog:collection="pages" catalog:searchType="favorites" role="catalog:pages-favorites"/> <Query catalog:collection="pages" catalog:searchType="category" role="catalog:pages-category"/> <Query catalog:collection="pages" catalog:searchType="user" role="catalog:pages-user"/> </OpenSearchDescription> The role attribute on a <Query> tag defines the searches supported over an Atom Publishing Protocol (APP) collection. See the Catalog API for more information about APP, the Catalog API, and collections. Atom format The feed containing the results of an OpenSearch query consists of entries in formats defined by the individual plug-ins. The entry format for all system plug-ins (i.e., plug-ins that ship with MashupHub) is specified in the following sections. Third-party plug-ins are free to format their OpenSearch results in any manner. A client should refer to the <category> element in each entry to determine to what plug-in an entry belongs and how to interpret its content. A client should refer to the element name of the child element under the <content> element to determine the collection to which an entry belongs. Server uses <category> to determine which collection plugin should handle entry. There are limitations: 1. An entry may be categorized in one category only. 2. For ″human-readable″ categorization of entries custom categorization mechanism may be used in XML body of entry. Feed entry The format for all system plug-ins in the feeds collection matches the following example: <entry> <author> <name>InfoSphere MashupHub Search Feed</name> </author> <title type="text">Entry Finance Spreadsheet</title> <summary>Finances for Q1-2008</summary> <updated>2008-01-24T11:47:09-05:00</updated> <id>urn:uuid:11</id> <link href="http://localhost/mashuphub/client/plugin/generate/pluginid/16/ entryid/11"/> <link rel="self" href="http://localhost/mashuphub/client/app/entry/objectid/11"/> <link rel="edit" href="http://localhost/mashuphub/client/app/entry/objectid/11"/> <category term="excel"/> 4 MashupHub API Reference <content type="application/xml"> <catalog:feed xmlns:catalog="http://www.ibm.com/xmlns/atom/opensearch/feeds/1.0/"> <version>1.0.1</version> <name>Finance Spreadsheet</name> <author>John Doe</author> <description>Finances for Q1-2008</description> <rating>3.25</rating> <downloads>12</downloads> <useCount>14</useCount> <dateModified></dateModified> <numComments>5</numComments> <downloadURL> http://localhost/mashuphub/client/plugin/generate/entryid/11/pluginid/16 </downloadURL> <tags> <tag>accounting</tag> <tag>2008</tag> ... <tag>business</tag> </tags> <categories> <category>Finance</category> <category>Sales</category> ... <category>Enterprise</category> </categories> <documentationURL></documentationURL> <permission>public</permission> </catalog:feed> </content> </content> If this had been an example of a internet or intranet feed that had been registered in MashupHub an additional element <url> would have been included, such as <url>www.somenewsorg.com/feed</url>. The child elements of <entry> follow the standard Atom feed format. The self link provides the URL for fetching this entry. The edit link provides the URL for posting changes to the entry. The child elements of the <content> element are the following: version The version number of the feed in the form x.y.z where x, y and z are any integer values. author The userid of the user who registered or created this feed. name The descriptive name of the feed. Its maximum length is 200 characters. description A text description of the feed. Its maximum length is 1000 characters. rating A decimal value from 1 to 5, inclusive, that indicates the average user rating of this feed. downloads An integer value representing the number of times this feed has been viewed through the catalog user interface. useCount An integer value representing the number of times the feed has been accessed, including views or MashupHub Publishing Protocol operations. Chapter 2. Search API 5 numComments The integer value of the number of comments that have been posted to the catalog entry for this feed. downloadURL The URL endpoint of the feed. Its maximum length is 2048 characters. url For registered feeds (feeds registered from internet or intranet syndication sites), this element is included in the feed. Its value is the URL of the source feed. The value of url differs from downloadURL since MashupHub proxies the registered feed. Through the catalog API, you can use url to supply the URL of the feed to be registered. tags This is a container element for the set of social tags that describe this feed. tags/tag A user defined tag for this feed. Maximum length is 50 characters. If the feed has not been tagged, the tags element will be empty. categories This is a container element for the set of categories by which this feed is classified. categories/category Administrator defined, user assigned category for this feed. Maximum length is 100 characters. If the feed has not been categorized, the categories element will be empty. documentationURL A URL that points to documentation for the feed, such as a microformat page. This value is optional. permission A string representing the permission that applies to this object. The possible values are: v pubic – all users can read the object and its metadata. v private – only the creator can read the object and its metadata and change the object. v custom – an access control list specifies view and edit permissions for the object. When registering a new feed or editing the metadata of a feed in the catalog the Atom entry should look like the above example. When the operation is complete, MashupHub will assign the ID for the entry and respond with the entry as it was entered into the collection. More information about updating the catalog through these Atom Publishing Protocol (APP) feeds is presented in the Catalog API section. Page entry The format for page plug-in entries in the pages collection is the following: <entry> <author> <name>InfoSphere MashupHub Search Feed</name> </author> <title type="text">Entry Finance Page</title> <summary>Mashup workspace for 2008 finance data</summary> <updated>2008-01-24T11:47:09-05:00</updated> <id>urn:uuid:10</id> <link href="http://localhost/mashuphub/client/plugin/generate/pluginid/15/ 6 MashupHub API Reference entryid/10"/> <link rel="self" href="http://localhost/mashuphub/client/app/entry/objectid/10"/> <link rel="edit" href="http://localhost/mashuphub/client/app/entry/objectid/10"/> <category term="page" /> <content type="application/xml"> <catalog:page xmlns:catalog="http://www.ibm.com/xmlns/atom/opensearch/feeds/1.0/"> <version>1.0.1</version> <name>Finance Page</name> <author>John Doe</author> <description>Mashup workspace for 2008 finance data </description> <rating>5</rating> <downloads>100</downloads> <useCount>120</useCount> <numComments>10</numComments> <url> http://localhost/mashuphub/client/plugin/generate/entryid/10/pluginid/15 </url> <tags> <tag>accounting</tag> <tag>2008</tag> ... <tag>business</tag> </tags> <categories> <category>Finance</category> <category>Sales</category> ... <category>Enterprise</category> </categories> <documentationURL></documentationURL> <definitionURL> http://lucenew.usca.ibm.com:9080/mum/ enabler#pid=09488F950B655D9E1F4E242D6C6C44000088</definitionURL> </catalog:feed> </content> </content> The child elements of the content element are the same as for the feeds collection except the <url> element is not used and the following element is made to apply specifically to pages: downloadURL The URL that can be used to download the page package. When downloadURL is present, definitionURL will not be included in the feed. definitionURL The URL of the location of the deployed page. When definitionURL is present, downloadURL will not be included in the feed. iWidget entry The format for iWidget plug-in entries in the widgets collection is the following: <entry> <author> <name>InfoSphere MashupHub Search Feed</name> </author> <title type="text">Entry Spending Monitor Widget</title> <summary>Plots spending trends across departments</summary> <updated>2008-01-24T11:47:09-05:00</updated> <id>urn:uuid:20</id> <link href="http://localhost/mashuphub/client/plugin/generate/pluginid/1/ entryid/20"/> <link rel="self" href="http://localhost/mashuphub/client/app/entry/objectid/20"/> <link rel="edit" href="http://localhost/mashuphub/client/app/entry/objectid/20"/> <category term="iwidget" /> Chapter 2. Search API 7 <content type="application/xml"> <catalog:widget xmlns:catalog="http://www.ibm.com/xmlns/atom/opensearch/ feeds/1.0/"> <version>1.0.1</version> <name>Spending Monitor Widget</name> <author>John Doe</author> <description>plots spending trends across departments</description> <rating>2</rating> <downloads>45</downloads> <useCount>90</useCount> <numComments>0</numComments> <url> http://localhost/mashuphub/client/plugin/generate/entryid/20/pluginid/1 </url> <tags> <tag>accounting</tag> <tag>2008</tag> ... <tag>business</tag> </tags> <categories> <category>Finance</category> <category>Sales</category> ... <category>Enterprise</category> </categories> <documentationURL></documentationURL> </catalog:feed> </content> </content> The child elements of the content element are the same as for the feeds collection except the <url> element is not used and the following element is made to apply specifically to iWidgets: downloadURL The URL that can be used to download the iWidget WAR package. When downloadURL is present, definitionURL will not be included in the feed. definitionURL The URL of the location of the deployed page. When definitionURL is present, downloadURL will not be included in the feed. Generic widget entry The format for the generic widget plug-in entries in the widget collection is the following: <entry> <author> <name>InfoSphere MashupHub Search Feed</name> </author> <title type="text">Hello World Widget</title> <summary>A HelloWorld test widget</summary> <updated>2008-01-24T11:47:09-05:00</updated> <id>urn:uuid:21</id> <link href="http://localhost/mashuphub/client/plugin/generate/pluginid/2/ entryid/21"/> <link rel="self" href="http://localhost/mashuphub/client/app/entry/objectid/21"/> <link rel="edit" href="http://localhost/mashuphub/client/app/entry/objectid/21"/> <category term="GenericWidget" /> <content type="application/xml"> <catalog:widget xmlns:catalog="http://www.ibm.com/xmlns/atom/opensearch/ feeds/1.0/"> <version>1.0.1</version> 8 MashupHub API Reference <name>Hello World Widget</name> <author>John Doe</author> <description>A HelloWorld test widget</description> <rating>0</rating> <downloads>0</downloads> <useCount>1</useCount> <numComments>5</numComments> <url> http://localhost/mashuphub/client/plugin/generate/entryid/21/ pluginid/2</url> <tags> <tag>sample</tag> <tag>test</tag> ... <tag>example</tag> </tags> <categories> <category>General</category> <category>IT</category> ... <category>Enterprise</category> </categories> <documentation></documentation> <documentationURL></documentationURL> <downloadUrl> http://localhost/mashuphub/client/plugin/generate/entryid/ 21/pluginid/2</downloadUrl> </catalog:feed> </content> </content> The child elements of the <content> element are the same as for the feed collection except for: downloadURL The URL that can be used to download the widget zip package. Chapter 2. Search API 9 10 MashupHub API Reference Chapter 3. Catalog API The Catalog API is a set of a MashupHub Atom Publishing Protocol (APP) feeds. The MashupHub collections represented by those feeds are defined by an APP service document located at http://yourURL/mashuphub/atom where yourURL is the base URL of the MashupHub installation. You can also use OpenSearch as a starting point since entries return can be used in APP operations. Accessing the service document using HTTP results in all URLs in the document using HTTP as the protocol. Accessing the document using HTTPS results in HTTPS URLs in the service document. A client can use either protocol, but all access through insecure HTTP is granted anonymous user permissions only. A client must use basic authentication via HTTPS. Collections Plug-ins identify the collections to which their content belongs. By default, the collection name corresponds to the OpenSearch query role for the collection. Multiple plug-ins can belong to a single collection. See the Package Metadata section for more details about how plug-ins define additional collections. The Catalog API defines the following APP collections by default. They correspond to the system plug-ins. feeds - Cataloged Feeds widget - Cataloged Widgets pages - Cataloged Pages all - All Each of these collections is organized into Atom categories that identify important constituents of the collection. A category is represented by the Atom <category> element that is a child of the Atom <entry> element. They are defined by the package.xml (<name> element) for a plug-in, as described below under Plug-in API. The categories in the Cataloged Feeds collection identify the feed types. They are: CSV Domino Excel Feed Registration IBM Information Server IMS LDAP Mashup (feed mashup) Microsoft Access Document pureXML Document SAP Relational TDI Web Service XML Document © Copyright IBM Corp. 2007, 2008 11 The categories in the Cataloged Widgets collection identify the widget types. They are: iWidgets Generic Widgets The Cataloged Pages collection includes one category, the Pages category. For convenience, there is a collection called all that is the union of the other collections and may contain members of any of the above categories. You can also use OpenSearch as a starting point since entries return can be used in APP operations. APP Fetch APP fetch (HTTP Get on the collection URL) operations on the Catalog API result in Atom feeds with entries identical in format to those defined in the Search API section. The format of entries for other plug-in defined collections is determined by the plug-ins themselves. The all feed is a union of all other defined feeds. A client should check the term attribute of the <category> of an <entry> to discover to which plug-in the entry belongs. The value of term is the fixed name of the plug-in responsible for the entry, information the client can use to interpret the metadata in the <content> element. APP Create For APP create (HTTP Post to the collection URL) operations, the default behavior of a plug-in is to register the URL of an existing feed hosted at an external location. A plug-in should override this default behavior by specifying a CollectionPlugin subclass (see the Package Metadata section). Plugin interface does not limit or restrict content of entry. When uploading binary artifacts (widgets, pages), they will be included as xsd:binary (BASE64 encoded) in an <archive> tag inside <content>. The <archive> element will have a ″type″ attribute to pass the content-type of the binary attachment. When getting these entries from the collection, binary elements will be substituted with <downloadURL> elements that can be fetched with extra HTTP request. Alternatively, the page and iWidget plugins define a <packageURL> element that provides a URL of the binary object that the plug-in can reference to read the object from its source. Finally, these two plug-ins support a third approach which allows the URL of the object to be registered to be passed in a <definitionURL> element. Such registration does not involve an upload but corresponds to the ″Register iWidget″ and ″Register Page″ actions provided by the user interface. The value of the <permission> element in the entry being submitted can only be set to ″public″ or ″private″. In general, MashupHub supports APP create operations for feed registration, uploading or registering an iWidget, uploading a generic widget, and uploading or registering a mashup page. 12 MashupHub API Reference APP Edit For APP edit (HTTP Put to the entry’s ″edit″ URL) operations, the default behavior of a plug-in is to allow changes to the basic MashupHub metadata defined for entries in the feed collection. A plug-in can override this default behavior by specifying a CollectionPlugin subclass (see the Package Metadata section). Consult the documentation for plugins other than the system plug-ins provided by MashupHub. The value of the <permission> element in the entry being submitted can only be changed to ″public″ or ″private″. If the entry being edited had a value of ″custom,,″ then <permission> can remain ″custom″ in the updated entry. MashupHub supports APP edit operations for updating common metadata for all objects in the catalog. The feed definition can only be changed when the feed was one that was registered with MashupHub (not one of the feeds generated by MashupHub). An edit operation can also upload a replacement iWidget, generic widget or mashup page. Chapter 3. Catalog API 13 14 MashupHub API Reference Chapter 4. Metrics API The Metrics API exposes tracking data collected by MashupHub for feed, widget and page usage and provides a means to prune unneeded records from the tracking store. The result of calling the “get service data” API is by default a MashupHub feed. The feed contains tracking information for each access of a particular object. In this way, the owner of each feed, widget or page in the MashupHub catalog can obtain a tracking feed each of his cataloged objects. To obtain this feed, read the REST URI for https://HostAndPort/mashuphub/client/ tracking/generate/entryid/{entryid}, where {entryid} is integer id of the object being tracked. You can find the entry id by looking at the integer entry ID in the URL of the object in which you are interested. For example, for this feed, http://HostAndPort/mashuphub/client/plugin/generate/entryid/9/pluginid/3, the entry ID is 9. MashupHub tracking feed The entries in the feed vary depending on the type of action recorded. Possible actions are: Generate Feed data has been generated in response to a client reading a feed URL or a widget or mashup page has been returned in response to a client reading the <downloadURL> for one of these objects. Create An object in the catalog has been created. Update An object has been updated, either in its definition or its access control. Delete An object has been deleted from the catalog. The returned MashupHub feed is in the form of: <?xml version="1.0" encoding="UTF-8"?> <feed xmlns="http://www.w3.org/2005/Atom"> <title type="text">Tracked Data</title> <link href="http://www.ibm.com/feed.atom" rel="self" type="application/atom+xml"></link> <updated>2008-10-01T20:22:37.156Z</updated> <id>1</id> <subtitle type="text">Mashup Hub</subtitle> <entry xmlns="http://www.w3.org/2005/Atom"> <title type="text">Item 1</title> <id>urn:uuid:1</id> <updated>2008-10-01T20:22:37.156Z</updated> <author> <name>Hub</name> </author> <summary type="text">Atom Feed entry 1</summary> <content type="application/xml"> <row xmlns="http://www.ibm.com/xmlns/atom/content/datarow/1.0"> <recordId>3</recordId> <unixtimestamp>1222892527953</unixtimestamp> <executiontime>32</executiontime> <timestamp>Wed+Oct+01+16%3A22%3A07+EDT+2008</timestamp> <username>HubAdmin</username> <ip>127.0.0.1</ip> © Copyright IBM Corp. 2007, 2008 15 <pluginid>1</pluginid> <objectid>33</objectid> <acl>%5B%7B%22acl%22%3A%22private%22%7D%5D</acl> <action>update</action> </row> </content> </entry> <entry xmlns="http://www.w3.org/2005/Atom"> <title type="text">Item 2</title> <id>urn:uuid:2</id> <updated>2008-10-01T20:22:37.171Z</updated> <author> <name>Hub</name> </author> <summary type="text">Atom Feed entry 2</summary> <content type="application/xml"> <row xmlns="http://www.ibm.com/xmlns/atom/content/datarow/1.0"> <recordId>2</recordId> <unixtimestamp>1222892521500</unixtimestamp> <executiontime>47</executiontime> <timestamp>Wed+Oct+01+16%3A22%3A01+EDT+2008</timestamp> <username>HubAdmin</username> <ip>127.0.0.1</ip> <pluginid>1</pluginid> <objectid>33</objectid> <acl></acl> <action>generate</action> </row> </content> </entry> <entry xmlns="http://www.w3.org/2005/Atom"> <title type="text">Item 3</title> <id>urn:uuid:3</id> <updated>2008-10-01T20:22:37.171Z</updated> <author> <name>Hub</name> </author> <summary type="text">Atom Feed entry 3</summary> <content type="application/xml"> <row xmlns="http://www.ibm.com/xmlns/atom/content/datarow/1.0"> <recordId>1</recordId> <unixtimestamp>1222892518765</unixtimestamp> <executiontime>31</executiontime> <timestamp>Wed+Oct+01+16%3A21%3A58+EDT+2008</timestamp> <username>HubAdmin</username> <ip>127.0.0.1</ip> <pluginid>1</pluginid> <objectid>33</objectid> <acl>%5B%7B%22acl%22%3A%22public%22%7D%5D</acl> <action>create</action> </row> </content> </entry> Data is stored in datarow format, similar to relational database feeds. The Atom feed will contain the 500 most recent tracking records. Use one of the other formats described below to get the complete set of records. The child elements of Feed are: title The title of the entry. link A link to the data feed. updated The current date. 16 MashupHub API Reference id The entry ID. subtitle MashupHub tracking branding The element <entry> is a child of <feed>. A <feed> element might have multiple <entry> children. The children of the <entry> element are: title The title of the entry. id A generated ID author The author element has a child named “name” which contains the name of the data generator. summary The data row number The entry element has a child element called content. The child elements of the content element contain the tracking information for action. This format is as follows: <row xmlns="http://www.ibm.com/xmlns/atom/content/datarow/1.0"> <recordId>3</recordId> <unixtimestamp>1222892527953</unixtimestamp> <executiontime>32</executiontime> <timestamp>Wed+Oct+01+16%3A22%3A07+EDT+2008</timestamp> <username>HubAdmin</username> <ip>127.0.0.1</ip> <pluginid>1</pluginid> <objectid>33</objectid> <acl>%5B%7B%22acl%22%3A%22private%22%7D%5D</acl> <action>update</action> </row> The child elements are: recordId The unique ID for the given row of data. objectid The object ID. pluginid The ID of the plugin used to create the object. ip The IP address of the user who accessed the feed. username The username of the user who accessed the feed. timestamp The time the feed was accessed in MashupHub date format. executiontime The time taken to serve the feed in milliseconds. acl Access control list. The permission currently assigned to the feed. This element will be empty for generate records. The value is a JavaScipt Object Notation (JSON) serialization of the permission information. Possible values are: v [{"acl":"public"}] Public permission. v [{"acl":"private"}] Chapter 4. Metrics API 17 Private permission v [{"acl":"custom", ...[Custom ACL encoding]}] Custom permission with an Access Control List (ACL). In the JSON string. "...[Custom ACL encoding]" will be the ACL. For example, [{"acl":"custom"}, {"ANONYMOUS" :{"read":1,"edit":1}, "REGISTERED":{"read":1,"edit":1}}, {"HubAdmin":{"read":1,"edit":1}}] action The action that was tracked, Possible values are: v Generate Feed data has been generated in response to a client reading a feed URL or a widget or mashup page has been returned in response to a client reading the <downloadURL> for one of these objects. v Create An object in the catalog has been created. v Update An object has been updated, either in its definition or its access control. v Delete An object has been deleted from the catalog. This action will only be found in the CSV representation of the tracking information that is saved when the object is deleted from the catalog. For CSV information, see the “CSV” section. Additional data types The tracking API also allows the data to be exported in CSV and json formats by appending /format/ to the API call. CSV Calling the REST service with the parameter /format/csv yields a returned document in common delimited value format: recordId,cid,unixtimestamp,executiontime,timestamp,username,ip,pluginid, objectid,acl,action 3,-1,1222892527953,32,Wed+Oct+01+16%3A22%3A07+EDT+2008,HubAdmin,127.0.0.1,1,33, %5B%7B%22acl%22%3A%22private%22%7D%5D,update 2,-1,1222892521500,47,Wed+Oct+01+16%3A22%3A01+EDT+2008,HubAdmin,127.0.0.1,1,33, ,generate1,-1,1222892518765,31,Wed+Oct+01+16%3A21%3A58+EDT+2008,HubAdmin, 127.0.0.1,1,33,%5B%7B%22acl%22%3A%22public%22%7D%5D,create Where the tracked elements are separated by commas on the first line. Each additional line contains the data associated with those elements. JSON Calling the REST service with the parameter /format/json yields a returned json document: 18 MashupHub API Reference [ { "recordId": 3, "cid": "-1", "unixtimestamp": 1222892527953, "executiontime": 32, "timestamp": "Wed+Oct+01+16%3A22%3A07+EDT+2008", "username": "HubAdmin", "ip": "127.0.0.1", "pluginid": 1, "objectid": 33, "acl": "%5B%7B%22acl%22%3A%22private%22%7D%5D", "action": "update" }, { "recordId": 2, "cid": "-1", "unixtimestamp": 1222892521500, "executiontime": 47, "timestamp": "Wed+Oct+01+16%3A22%3A01+EDT+2008", "username": "HubAdmin", "ip": "127.0.0.1", "pluginid": 1, "objectid": 33, "acl": "", "action": "generate" }, { "recordId": 1, "cid": "-1", "unixtimestamp": 1222892518765, "executiontime": 31, "timestamp": "Wed+Oct+01+16%3A21%3A58+EDT+2008", "username": "HubAdmin", "ip": "127.0.0.1", "pluginid": 1, "objectid": 33, "acl": "%5B%7B%22acl%22%3A%22public%22%7D%5D", "action": "create" } ] Where the tracked elements are formatted in a standard json format: element: value The document is composed of a set of such json object representations. Clear tracking data service Old tracking data can be pruned from the set of records maintained by MashupHub. This is important to conserve space in the MashupHub database. The removal of old data is requested either from the MashupHub administration user interface or through a REST service. The prune tracking data service is invoked by issuing a REST call to https://yourhostandport//mashuphub/client/tracking/prune passing a date. All tracking entries older than that date will be removed. The format of the data is a string in the format mm-dd-yyyy. If the prune operation is successful, the service will return the following: Chapter 4. Metrics API 19 {"code":600,"result":"Tracked data successfully cleared."} If the operation is not successful, one of the following will be returned: {"code":601,"result":"Please provide a valid date in the format specified."} {"code":602,"result":"An error occurred while attempting to clear the data, ensure all information is correct and try again."} 20 MashupHub API Reference Chapter 5. Feed API The feed API is comprised of the feed formats that are produced by all of the feed generators that are deployed in the server. The URIs of the feeds are defined by their catalog entries and can be obtained by using the Search API or the Catalog API. See the InfoSphere MashupHub User and Administrator Guide for descriptions and examples of feed formats for all the data sources supported by the MashupHub system plug-ins. © Copyright IBM Corp. 2007, 2008 21 22 MashupHub API Reference Chapter 6. Plugin API The plug-in API allows developers to write components that extend the ability of MashupHub to store, search, and retrieve catalog entries (feeds, widgets, etc.). Plug-ins can show editors that let users define or upload new entries; show forms that collect user parameters for feeds; generate feeds given zero or more parameters; allow clients to download opaque entries (feeds, pages, etc.); and define custom handlers for APP queries. The complete API JavaDoc is available in MashupHub at http://yourhostandport/ mashuphub/client/doc/javadoc/index.html. The information in this reference document provides conceptual and overview information and defines important plug-in packaging and installation requirements. The fundamental plug-in components are the generator and the editor. The generator plug-in class is called to generate an instance of a feed from some source. A very basic example is given below. The main work is done in the generateFeed method. package myplugin; import com.ibm.mashuphub.model.RequestData; import com.ibm.mashuphub.model.dataobject.Entry; import com.ibm.mashuphub.model.dataobject.FeedContent; import com.ibm.mashuphub.plugin.BaseGeneratorPlugin; public class MyGenerator extends BaseGeneratorPlugin { public FeedContent generateFeed(RequestData rdata, Entry entry) { // generate the feed here and return a FeedContent object. } } The editor provided the user interface to define the feed, or process a widget or other object. It is invoked when a user selects the object from the New Feed or Upload Widget selections lists in the user interface. The editor can be simple, using a Java Server Page or emitting raw HTML, or can be more sophisticated and provide a rich user interface. The outline of a basic editor is shown below. package myplugin; import java.util.Hashtable; import com.ibm.mashuphub.HubConstants; import com.ibm.mashuphub.helper.PluginHelper; import com.ibm.mashuphub.model.RequestData; import com.ibm.mashuphub.model.ViewBean; import com.ibm.mashuphub.model.dataobject.Entry; import com.ibm.mashuphub.model.dataobject.Parameter; import com.ibm.mashuphub.model.exception.HubException; import com.ibm.mashuphub.model.table.ParametersTable; import com.ibm.mashuphub.plugin.BaseEditorPlugin; import com.ibm.mashuphub.ui.FormViewBean; import com.ibm.mashuphub.ui.FrameViewBean; import com.ibm.mashuphub.ui.JSONAJAXResponseViewBean; public class MyEditor extends BaseEditorPlugin { public ViewBean renderEditor(RequestData rdata, Entry entry) { // create the UI via a helper object called a ViewBean } public ViewBean saveParam(RequestData rdata, Entry entry) { © Copyright IBM Corp. 2007, 2008 23 // Save any default URL parameter values } } The main method for displaying the editor’s page in the MashupHub user interface is renderEditor. The other public method, is used to save default parameter values for the new feed. MashupHub prompts the user for these values. The plugin model also provides javascript APIs for use by the plug-in’s javascript code running in the user’s Web browser. This allows the plug-in to participate in the page flow that is common to all plug-ins in the New Feed and Upload Widget user interfaces. Most plugins will only need the editor and generator components. The collection component is used when the plug-in has one of the following requirements. v Search on more than the common metadata v Support creation or modification of the feed through the Catalog API v Support upload or replacement of new widget type through the Catalog API A collection component implements methods for OpenSearch and each of the Atom Publishing Protocol (APP) actions. Plug-in packaging The MashupHub framework automatically installs third-party plug-ins at Web application startup. It searches for ZIP files in a special <WebApplication>/WEBINF/plugins folder. <WebApplication> is a directory where the MashupHub Web application is installed. For example,C:\Program Files\IBM Mashup Center\Hub\installedApps\Mashup Hub.ear\META-INF\plugins. Note that the plugins directory does not initially exist and must be created. Plug-in resources are distributed among various directories by MashupHub as part of the plugin installation procedure. After installation, compiled plug-in Java classes are located in WEB-INF/classes and JARs in WEB-INF/lib. Plugins must be packed into a ZIP file. The archive must contain the following file structure (subfolders): v /client/plugins/PLUGIN_DIR (the Java version uses the plug-in class package name as PLUGIN_DIR; i.e. com.ibm.mashuphub.plugin.excel) - contains files for browsers, like images, JavaScript files and so on. v /server/plugins/PLUGIN_DIR - contains files used by the plug-in to render itself (HTML files, JSP pages). Additional folders for plug-in files can be included. v /server/plugins/PLUGIN_DIR/nls – contains the ui.properties file and any user interface files the plug-in might need for internationalization. v /WEB-INF/classes - contains the plug-in’s Java classes. This can be a hierarchy of folders. The classes will be copied to <WebApplication>/WEB-INF/classes. Other option is to pack the plug-in’s classes into a JAR file and put it into /WEB-INF/lib directory (see the next point). v /WEB-INF/lib - contains JAR files used by the plug-in (third-party). Note: MashupHub will not install a new plugin that has a class conflict with system libraries. It is the plug-in developer’s responsibility to ensure version consistency. 24 MashupHub API Reference As an example, suppose you were deploying a plug-in called ″feed″. The JSP templates, message catalogs, XML documents, and other server side resources would be located in a subfolder of <WebApplication>/server/plugins/ where the subfolder name matches the full package name of the plug-in , for example com.myco.plugin.feed. |--server/ |--plugins/ |--com.myco.plugin.feed/ |--nls/ | |--ui.properties | |--feed.jsp |--package.xml The files in the client-side directory define resources accessible by the client, but not used on the server, such as images, style sheets, JavaScript files, and so on. These resources are located in WebContent/client/plugins/, again under a subfolder matching the full plug-in package name. |--client/ |--plugins/ |--com.myco.plugin.feed/ |--icons/ When the MashupHub server starts it compares the list of files in the <WebApplication>/WEB-INF/plugins folder and list of installed plug-in names to determine which ZIP files (″new″ plug-in) should be unpacked and processed. If the framework locates a new ZIP, it performs the following actions: 1. Copies content of the ZIP file to the <WebApplication> directory. 2. Inserts the package metadata into the MashupHub database. 3. Invokes the install() method on the EditorPlugin class provided by the plug-in. System plug-ins are preinstalled and are not present in the <WebApplication>/WEBINF/plugins folder. Server-side Package metadata Each plug-in must provide a package.xml file. MashupHub refers to these files for metadata when installing new plug-ins. The following is an example: <plugin> <name>Feed Registration</name> <category>departmental</category> <editor>FeedEditorPlugin</editor> <generator>FeedGeneratorPlugin</generator> <collection>FeedCollectionPlugin</collection> <collectionName>Feed</collectionName> <description>Register an existing RSS or Atom feed</description> <author>MyCo</author> <version>1.0.0</version> <objectType>feed</objectType> <icon32path>/plugins/myplugin/icons/btn32_excel.gif</icon32path> </plugin> The child elements of <plugin> are the following: name The translatable, human readable name of the plug-in. This field is required. The maximum length is 32 characters. Chapter 6. Plugin API 25 description The long description of the plug-in. This field is required. The maximum length is 255 characters. author The author of the plug-in. This field is optional. If not specified, it defaults to “Unknown.” The maximum length is 60 characters. version The version of the plug-in. This field is optional. If not specified, it defaults to 1.0.0. The maximum length is 20 characters. collectionName The APP collection to which the entries of this plug-in belong. This field is optional. If not specified, it defaults to feeds. The maximum length is 32 characters. editor The name of the class used by the server to create and edit the catalog entries. This field is required. The maximum length is 32 characters. generator The name of the class used to generate the feeds or send opaque catalog entries. If not specified, no generator is available for the plug-in at runtime. The maximum length is 32 characters. collection The name of the class used to provide content for APP requests. This field is optional. If not specified, its APP requests will be handled by the default feeds collection plug-in. The maximum length is 32 characters. objectType The name of a type to which the entries of this plug-in belong. This value is used to distinguish the entries of the different types that are handled by the catalog. This field is optional. If not specified, defaults to feed. The maximum length is 20 characters. In addition, two user interface strings used by MashupHub to identify this plugin must be provided in a file named ui.properties. Here is an example: plugin.uiname = Comma Separated Value File plugin.description = Create a feed from Comma Separated Value file The properties defined in this file are: plugin.uiname The name of the feed source or object type to be displayed in MashupHub’s selection lists for new feeds or new widgets. plugin.description A one line description of what the plugin does. This may be used by MashupHub to further describe the plugin. icon32path A file path, starting under the client directory in the plug-in zip file, to a image file suitable for display in a Web browser. This field is required. The image should be 32 pixels in height and will be associated with entries created by this plug-in. Plug-in Interfaces The Java implementation for a server-side plug-in consists of a set of classes implementing one or more interfaces. To simplify plug-in’s creation, MashupHub 26 MashupHub API Reference provides a set of predefined base classes. As the metadata file indicates, a plug-in can provide up to three classes to be used by the MashupHub framework: 1. A generator: a class that returns an Atom feed or a file for download. 2. An editor: a class that supports the creation of a new feed or upload of an existing file for storage in MashupHub. 3. A collection: a class that customizes the handling of APP commands and processing of OpenSearch queries. The inheritance tree for all defined interfaces is the following: The Plugin interface defines methods for accessing plug-in metadata as well as IDs connecting the server-side plug-in instance to its client-side JavaScript. Plugin The Plugin interface defines methods for accessing plug-in metadata as well as IDs connecting the server-side plug-in instance to its client-side JavaScript. EditorPlugin The EditorPlugin interface defines methods invoked by the MashupHub framework to render a user interface for creating or editing catalog entries. GeneratorPlugin The GeneratorPlugin interface responds to client requests to generate feeds or download files. If a plug-in writer wishes to use a generator, the writer must at least implement the first of the following methods. Chapter 6. Plugin API 27 CollectionPlugin The CollectionPlugin interface defines methods invoked by the MashupHub framework in response to APP commands and OpenSearch queries. A plug-in writer should implement this interface to handle new types of resources. The CollectionPlugin defines the structure of CRUD+F methods for Atom Entries. CRUD+F is an abbreviation for “create, retrieve, update, delete + find″. Each method accepts a specialized ″context″ that provides information and assists in manipulating Atom Entries. public CollectionMetaInfo getMetaInfo(); The getMetaInfo method is called on the CollectionPlugin to discover the list of possible search types (variants of possible OpenSearch queries), list of acceptable <atom:categories> and the APP collection title: interface CollectionMetaInfo { String getRequestName(); String[] getSearchTypes(); public String[] getSortings(); String getTitle(); String[] getCategories(); } RequestName The unique name which may be used to identify the collection in a request (the string should not contain characters which have a special meaning in a URL). SearchTypes The list of unique strings, each of which denotes a specific type of search that will be performed when the string is included as part of the searchType parameter on an OpenSearch request (the list of all OpenSearch query roles will be formed by the rule: <CollectionName> + "-" + SearchType[i], for example if there is a <CollectionName>widgets</ CollectionName> in the plugin.xml and getSearchTypes() return {″″, ″popular″, ″top″, ″recent″} then there would be following query roles defined: ″widgets″, ″widgets-popular″, ″widgets-top″, ″widgets-recent″). Sortings The list of sorting options by which results can be sorted, if any. Title Human readable title of the collection (might be null). Categories The list of categories that acceptable entry should be categorized. An Entry in the collection should be assigned to a single category. public void create(CreateContext context); The create method is called on the CollectionPlugin when MashupHub has identified the target collection and plug-in for newly posted entry. The CollectionPlugin is supposed to obtain the input entry from the context, store it and update the Entry document (or report an error if the operation fails). public void update(UpdateContext context); The update method is called on the CollectionPlugin when MashupHub has identified target collection and plug-in for the Entry to update. The CollectionPlugin should obtain the input Entry from the context, store it and return the updated Entry document (or report an error if operation fails). 28 MashupHub API Reference public void delete(DeleteContext context); The delete method is called on the CollectionPlugin when MashupHub has identified the target collection and plug-in for the Entry to delete. The CollectionPlugin should obtain the Entry id from the context and remove the Entry from the collection, which implies that it should be deleted from the catalog (or report an error if operation fails). public void findById(FindByIdContext context); The findById method is called on the CollectionPlugin when MashupHub has identified the target collection and plug-in from which to retrieve an individual Entry. The CollectionPlugin should obtain the entry id from context and return the designated Entry document (or report an error if operation fails). public void find(FindContext context); The find method is called on the CollectionPlugin when MashupHub has identified the target collection and plug-in for a normal OpenSearch request. The CollectionPlugin should obtain the search type and query from the context and perform the query, or report an error if operation fails. public void download(DownloadContext context); The download method is called when there is a request for some artifact which is referenced from an Atom Entry, but retrieved with an extra request by using the downloadURL in the Atom Entry. The CollectionPlugin is expected to write out the binary content of the artifact to the stream. (This is used to download widget zip files, etc.) Plug-in base classes The inheritance tree for all defined base classes is the following: Chapter 6. Plugin API 29 BasePlugin The BasePlugin class implements methods for accessing plug-in metadata as well as IDs connecting the server-side plug-in instance to its client-side JavaScript. All methods are public and all instance variables are private such that subclasses must use the interface defined by the methods to access plug-in related data. All plug-in classes are descendants of BasePlugin. BaseEditorPlugin The abstract BaseEditorPlugin class defines methods invoked by the MashupHub framework to render a user interface for creating or editing catalog entries. public Object renderScript(RequestData rdata, Entry entry) The framework invokes the renderScript method once when the user begins editing an entry using the plug-in. When invoked, code in this method should build an Object containing JavaScript code. The JavaScript code should attach all methods and variables needed on the client to the client-side plug-in instance. The default implementation of this method creates a response containing markup for an HTML <script>. Within this script tag, the method places JavaScript code instantiating an instance of the client-side class hub.managers.Plugin. For example, to attach a no-op method foobar to the client-side plug-in, overridden renderScript method might invoke the default implementation (using super.renderScript) and define the following code: String s = this.getClientMe(); s += ".foobar = function() { // do nothing };”; return s; abstract public Object renderEditor(RequestData rdata, Entry entry) The framework invokes the renderEditor method immediately after renderScript. The request data gives specifics about how the plug-in was invoked and the entry provides details about the catalog entry under editing. This method must return an Object containing HTML to be emitted by the MashupHub framework to the client. If the object is a ViewBean then the framework will process it. Otherwise, it will output the object’s toString value. Note that the plug-in is free to create the HTML string in any way it chooses: building it from scratch in the code, rendering a JSP, using the provided ViewBean classes, using some other template library, etc. The RESTful URL invoking renderEditor on a plug-in is http:// serverNameAndPort/mashuphub/client/plugin/editor/entryid/${entryid}/ pluginid/${pluginid} where ${entryid} is the integer ID for the entry to edit and ${pluginid} is the integer ID of the editor to use. public Object handleAjax(RequestData rdata, Entry entry) The handleAjax method is invoked by the client after the initial plug-in screen render by renderEditor. The request data gives specifics about how the plug-in was invoked and the entry provides details about the catalog entry under editing. This method must return an Object containing JSON, HTML, XML, etc. data expected by the client. If the object is a ViewBean or an AjaxContent then the framework will process it. Otherwise, it will output the object’s toString value. 30 MashupHub API Reference Again, the plug-in is free to create the response string in any manner it chooses. The RESTful URL invoking handleAjax on a plug-in is http://serverNameAndPort/ mashuphub/client/plugin/ajax/entryid/${entryid}/pluginid/${pluginid} where ${entryid} is the integer ID for the entry to edit and ${pluginid} is the integer ID of the editor to use. protected Object respondClient(String method, String action, int code, String text, String[] stringArray, String transport, String encoding) The respondClient implementation prepares a JSON response with the appropriate syntax for the client with all data needed by the RPC mechanism (transport, method, data, encoding) to form. The default implementation instantiates and returns a JSONAJAXResponseViewBean to specify what client-side method should be asynchronously invoked when the response from the server is available. public void install() The install method runs after MashupHub unpackages the plug-in. When invoked, code in this method should use the available APIs to add sample entries to the catalog. public void uninstall() The uninstall method runs before MashupHub removes the plug-in. When invoked, code in this method should use the available APIs to remove any configuration details from the database. BaseGeneratorPlugin The abstract BaseGeneratorPlugin class responds to client requests to generate feeds or download files. If a plug-in writer wishes to use a generator, the writer must at least implement the first of the following methods. abstract public FeedContent generateFeed(RequestData rdata, Entry entry) The generateFeed method runs when a client requests the data (not metadata) from a catalog entry. The request data gives specifics about how the plug-in was invoked and the entry provides details about the catalog entry in question. The code in this method should return a FeedContent object consisting of the following fields: feed XML content of a generated feed. timeToLive Time To Live (TTL) value determining how long the server (and potentially the client) should cache the feed. Specified in seconds relative to the current time. A value of 0 means the feed should not be cached. A value of -1 means the feed should be cached indefinitely. mimeType Specifies MIME type of the response. The default value is ‘application/xml’. headers HTTP headers to be put into the PE33 response can be set as name/value pairs (for instance, widget plugins use Content-Disposition header to specify the file name). Chapter 6. Plugin API 31 The RESTful URL invoking generateFeed on a plug-in is http://serverNameAnd Port/mashuphub/client/plugin/generate/entryid/${entryid}/pluginid/ {pluginid} where {entryid} is the integer ID for the entry to generate and {pluginid} is the integer ID of the generator to use. public String getCacheKey(Entry entry, Map<String,String> parameters) The getCacheKey method is called by the framework before generateFeed to determine if the generated feed data is already cached. The entry variable provides details about the entry for which the feed is being generated. Parameters is a mapping of name/value pairs specified in the URL used to generate the feed data. The return value should be a string uniquely identifying a feed to be generated for the given entry with the given parameters. The default implementation of this method builds a key basing on the following data: v Entry ID v Parameters specified for the entry (ID and update timestamp) v Parameters from the request URL (name and value) v Resources specified for the entry (ID and update timestamp) The BaseWidgetGeneratorPlugin overrides the getCacheKey method to preclude caching of ZIP files (it returns null value). public String renderEditor(RequestData rdata, Entry entry) The client can invoke the renderEditor method instead of generateFeed to collect parameters for feed generation. If the plug-in supports custom feed parameters, it can use this opportunity to render a user interface to collect the parameters from the user. The method parameters and return value are the same as in renderEditor on the EditorPlugin interface. The default implementation of this method looks for parameters associated with this entry. If the method finds the parameters, it renders a set of text boxes, possibly with default values, allowing the user to input custom parameters and submitting the values back to the RESTful URL for generateFeed. If no custom parameters are supported, this method simply calls generateFeed. The RESTful URL invoking GeneratorPlugin.renderEditor on a plug-in is http://serverNameAndPort/mashuphub/client/plugin/params/entryid/${entryid}/ pluginid/${pluginid} where ${entryid} is the integer ID for the entry to generate and ${pluginid} is the integer ID of the generator to use. protected static int getMaxNumberOfEntriesParam(RequestData rdata) This method returns the maximum number of entries to be included into the feed. This value can be specified as a parameter in the feed generation URL. If the parameter’s value is less or equal to 0 or is missing, Integer.MAX_VALUE value is returned. BaseCollectionPlugin The BaseCollectionPlugin class is a base abstract class implementing the CollectionPlugin interface. Custom collection plug-ins derive from this class, although the recommended approach is to derive from it indirectly, through the CommonCollectionPlugin. 32 MashupHub API Reference Implementers should create public default constructor and call the BaseCollectionPlugin(String...) constructor specifying a set of possible OpenSearch methods. CommonCollectionPlugin The CommonCollectionPlugin class is a subclass of BaseCollectionPlug that provides additional utility methods to make it easier to create a collection plug-in component. Most collection plug-in components can be implemented by extending this class. It is the recommended starting point for collection plug-in development. BaseWidgetEditorPlugin The BaseWidgetEditorPlugin class implements methods handling the client requests to upload widgets (widget packages). public ViewBean renderEditor(RequestData rdata, Entry entry) The default implementation of this method renders an upload form that allows uploading a widget package. public ViewBean handleUpload(RequestData rdata, Entry entry) This method called when the user submits the upload form. The widgets package is stored as a binary object. BaseWidgetGeneratorPlugin The BaseWidgetGeneratorPlugin class extends abstract BaseGeneratorClass providing a base implementation of the generateFeed method that just reads the widget’s ZIP file from the DB and sends it to the client. Additionally, it overrides the getCacheKey method to preclude caching of ZIP files (it returns null value). Plug-in ViewBeans The ViewBean abstract base class supports the rendering of a single JSP file as a response from renderEditor or handleAjax. The ContainerViewBean class supports the composition of a response by rendering multiple ViewBeans. MashupHub provides a set of subclasses of ContainerViewBean that render typical plug-in user interface components such as forms and panels. Plug-ins should use the existing subclasses whenever possible. When creating custom components, plug-ins must subclass ContainerViewBean since it provides important ID information supporting the wizard workflow on the client (see below). Library Considerations MashupHub provides a set of class libraries for a number of shared components, some of which are open source packages. A plug-in that uses one of these libraries must use the one already provided by MashupHub. The open source packages and their release numbers are given below. Apache Abdera 0.3.0 Apache Axiom 1.2.5 Apache Axis 1.4 (includes saaj.jar 1.2 and jaxrpc.jar 1.1) Apache Commons Codec 1.3 Apache Commons HttpClient 3.0.1 Chapter 6. Plugin API 33 Apache Apache Apache Apache Apache Derby Client Library 10.2 Geronimo Activation 1.0.2 Jakarta Commons Logging 1.0.4 Jakarta Java Caching System 1.2.7.9.2 Jakarta POI 3.1 Apache Log4J 1.2.12 Apache WS-Commons Axiom 1.2.1 WSDL4J 1.6 Apache XML-APIs 1.3 Apache XML-Security 1.4.1 Concurrent 1.3.4 Dojo Toolkit 1.2 Jaxen 1.1.1 JDom 1.0 MashupHub will log an error and not install a plug-in that has a class conflict with any classes in these libraries. Client-side Wizard workflow The MashupHub framework shows the HTML emitted by the EditorPlugin::renderEditor and EditorPlugin::handleAjax as a series of screens in a wizard-like interface. The forward flow of the wizard always proceeds as follows: 1. If a plug-in ID or entry ID is specified, skip to step 3. 2. Show the chooser page allowing the user to select the type of entry they wish to create (for example, feed, Excel, XML, WSDL, and so forth). 3. Show the first screen of the plug-in produced by EditorPlugin:renderEditor. 4. Show screens 2 through N of the plug-in produced by EditorPlugin:handleAjax. 5. Show the save page allowing the user to specify metadata. The wizard also supports a backward flow by showing previously hidden screens. No server requests are generated when moving backward. After moving backward, the wizard can move forward through the screens without server requests if no changes to prior screen have been made. A plug-in using the standard ViewBean classes does not need to be aware of the existence of the wizard, as long as it uses Plugin::getClientId to properly distinguish its HTML element IDs. The ViewBean classes wrap all emitted plug-in HTML in <div> tags with a unique identifier per screen. The client-side plug-in classes described below rely on this ID to determine the active screen from screens hidden by the wizard. The FormViewBean base class also links the Next, Previous, Cancel, and Finish buttons on screens to proper client-side actions to support backward and forward navigation in the wizard. 34 MashupHub API Reference Plug-in Base Classes The MashupHub framework constructs a client-side plug-in object whenever EditorPlugin::renderEditor is first invoked on the server. The client-instance exists for the duration of editing, that is, until one of the following occurs: v The user closes the tab containing the wizard v The user cancels the wizard v The user leaves the wizard from the landing page hub.managers.Plugin The hub.managers.Plugin base class provides some basic utility functions. A plug-in typically does not override them, but rather uses them in its own JavaScript code attached to the class during server-side rendering. function done(params) The done method completes or cancels the plug-in editor. The method looks at the action attribute of the given params object to determine what action to take. If the value of action is the string save, the save page is shown. If the value is cancel, the plug-in editor ends after prompting for confirmation and the user returns to an appropriate page. function showEditor(html) The showEditor method shows another screen in the plug-in editor. The html is the screen to render. The wizard will place the new screen after the current screen and will show the new screen immediately. This method is typically called in a response from the server. function next(func) The next method requests that the wizard show the next screen. If the wizard already has a valid cached copy the next screen, it shows that screen and hides the current one. If the next screen is not cached or is no longer valid, it invokes the provided function. Typically, the provided function generates a request to EditorPlugin::handleAjax on the server to submit some data and fetch the HTML of the next screen. function previous() The previous method requests that the wizard show the previous screen. This method always hides the current screen and shows the previous one. No request to the server is ever generated. function getScreenState(screen, index) The getScreenState method returns an object that MashupHub can use to compare whether the state of this screen has changed since the user last visited it. If not implemented (i.e., raises a Error), then MashupHub uses its own logic to save state, namely getting values from all named elements in the first form on the screen. Override this method only if form field checks will not work for this plug-in. The screen parameter contains the DOM node for the screen whose state is needed. The index parameter is the index of the screen, including screens shown before the plug-in’s first screen. function getObjectID() The getObjectID method returns the MashupHub Object ID for the object, such as ″feed″, being edited. Chapter 6. Plugin API 35 function getObjectId() The getPluginId method returns the MashupHub Plugin ID for the plug-in of the currently running editor. function showMessage(msg, typ) The showMessage method displays a message in a pop-up window. The message content is contained in the msg parameter. The typ parameter indicated the type of the message, namely ″I″ for information, ″W″ for warning and ″E″ for error. hub.managers.InvokePlugin The hub.managers.InvokePlugin class inherits all of the methods from hub.managers.Plugin and defines one additional public method supporting communication with a server-side InvokePlugin instance. Again, a plug-in typically uses this method in its own JavaScript instead of overriding it. function invokeServer(method, data, transport) The invokeServer method executes a method on a server-side instance of InvokePlugin. The method parameter is the string name of the method to invoke. The data parameter is any object which can be expressed in JSON format. The transport parameter is either the string xhr (the default, if nothing is specified) or iframe. The XHR transport should be used in most cases, but Iframe transport is necessary when uploading files to the server. The response from the server is not returned synchronously by this method. Instead, the server-side InvokePlugin uses a JSONAJAXResponseViewBean to specify what client-side method should be asynchronously invoked when the response from the server is available. Developing plug-ins Plug-ins can be developed using any Java development environment. MashupHub provides a Java Archive (JAR), mhubapi-1.0.jar. that contains all the interfaces and classes needed to compile a plug-in implementation. The JAR can be found at http://yourhostandport/mashuphub/client/doc/api/mhubapi-1.0.jar. Javascript functions that constitute the client-side API are, in the default installation, in the deployed MashupHub Web application at C:\Program Files\IBM Mashup Center\Hub\installedApps\Mashup Hub.ear \mashuphub-enterprise.war\client\scripts\hub\managers\ Javadoc for the plug-in classes are found in the MashupHub image at the URL http://yourhostandport/mashuphub/client/doc/javadoc/index.html. A sample plug-in implementation can be found in the deployed MashupHub at C:\Program Files\IBM Mashup Center\Hub\installedApps\Mashup Hub.ear \mashuphub-enterprise.war\ client\doc\pluginsamples\ (in the default installation). Installing a new plugin and making it active in MashupHub involves an administrator task. The MashupHub administrator must place the plugin zip file in the <WebApplication>/WEB-INF/plugins folder. <WebApplication> is the directory where MashupHub Web application is installed. In the default install it is 36 MashupHub API Reference at C:\Program Files\IBM Mashup Center\Hub\installedApps\Mashup Hub.ear\META-INF\plugins. Note that the plugins directory does not initially exist and must be created. The plugin is identified by the name of its zip file. The file name must be the same as its java package name, such as com.myco.myplugin.zip. The administrator must restart the MashupHub Web application to activate the new plugin. When the plug-in’s zip file is removed from <WebApplication>/WEB-INF/plugins and MashupHub is restarted, the plug-in will be uninstalled, all of its files will be removed and catalog entries defined using this plugin will be deleted. System plugins cannot be uninstalled. When installing, certain notes apply: v The install will fail if any class in the new plug-in is already loaded by any existing plug-in. This is in addition to the restriction on libraries described above in the Library considerations section. v Class conflicts cannot be detected until the plug-ins are loaded. Therefore, plug-ins should be installed one at a time with a restart of MashupHub occurring after each one. v To upgrade a plug-in, place a newer version of the plugin package in the <WebApplication>/WEB-INF/plugins directory. MashupHub will check the time stamp of the file to determine if the zip file is newer. Chapter 6. Plugin API 37 38 MashupHub API Reference Appendix. Sample Plug-in The following simple plug-in creates feeds from data the user provides as a URL parameter. The purpose is to illustrate the use of the Plug-in API and to show how to integrate into the flow of control implemented by the New Feed user interface. Feed editor component package hellodemo; import java.util.Hashtable; import import import import import import import import import import import import com.ibm.mashuphub.HubConstants; com.ibm.mashuphub.helper.PluginHelper; com.ibm.mashuphub.model.RequestData; com.ibm.mashuphub.model.ViewBean; com.ibm.mashuphub.model.dataobject.Entry; com.ibm.mashuphub.model.dataobject.Parameter; com.ibm.mashuphub.model.exception.HubException; com.ibm.mashuphub.model.table.ParametersTable; com.ibm.mashuphub.plugin.BaseEditorPlugin; com.ibm.mashuphub.ui.FormViewBean; com.ibm.mashuphub.ui.FrameViewBean; com.ibm.mashuphub.ui.JSONAJAXResponseViewBean; public class HelloEditor extends BaseEditorPlugin { @Override public ViewBean renderEditor(RequestData rdata, Entry entry) { String pluginId = this.getId(); HelloViewBean hello = new HelloViewBean(); hello.setEntry(entry); FormViewBean form = new FormViewBean(); form.setSuffix("hello"); form.addComponent(hello); form.setLabel("Submit"); form.setOnsubmit(PluginHelper.getClientMe(pluginId, entry.getObjectId()) +".invokeServer('saveParam', " + PluginHelper.getClientId(pluginId, entry.getObjectId()) + "_" + form.getSuffix() + ",'iframe');"); form.setEntry(entry); FrameViewBean frame = new FrameViewBean(); frame.addComponent(form); frame.setLabel(entry.getTitle()); frame.setTitle("Hello World Feed"); frame.setEntry(entry); return frame; } public ViewBean saveParam(RequestData rdata, Entry entry) { JSONAJAXResponseViewBean ajaxViewBean = new JSONAJAXResponseViewBean(); ajaxViewBean.setMethod(JSONAJAXResponseViewBean.METHOD_DONE); ajaxViewBean.setCode(String.valueOf(HubConstants.MESSAGE_CONTENT)); ajaxViewBean.setAction(JSONAJAXResponseViewBean.ACTION_MESSAGE; if(JSONAJAXResponseViewBean.TRANSPORT_IFRAME.equals(rdata.getParameter (JSONAJAXResponseViewBean.PARAM_TRANSPORT))) { ajaxViewBean.setTransport(JSONAJAXResponseViewBean.TRANSPORT_IFRAME); } © Copyright IBM Corp. 2007, 2008 39 Hashtable<String, String> rparms = new Hashtable<String, String>(rdata.getAllParameters()); ParametersTable parmtable = new ParametersTable(); try { parmtable.setParameter(entry.getObjectId(), "hellotext", "string", rparms.get("hellotext"), entry.getCreatorId(), "Hello text value.", rparms.get("prompt") != null ? Parameter.TRUE : Parameter.FALSE, 0, Parameter.FALSE, "Hello Text"); entry.generateURL(rdata.getBaseUrl(),this.getId()); entry.publish(); } catch (HubException ex) { ajaxViewBean.setText(ex.getLocalizedMessage()); ajaxViewBean.setCode(String.valueOf(HubConstants.ERROR_PLUGIN_METHOD)); return ajaxViewBean; } ajaxViewBean.setText("Parameters Saved"); return ajaxViewBean; } } Editor component ViewBeans class package hellodemo; import com.ibm.mashuphub.model.ViewBean; public class HelloViewBean extends ViewBean { static final String copyright() { return com.ibm.mashuphub.Copyright.IBM_COPYRIGHT; } private String suffix = "hello"; /* (non-Javadoc) * @see com.ibm.mashuphub.model.ViewBean#getJSPPath() */ @Override public String getJSPPath() { return "/server/plugins/hellodemo/hello.jsp"; } public String getSuffix() { return suffix; } public void setSuffix(String suffix) { this.suffix = suffix; } } Feed editor Java server page <br/> <label for='hellotext'><span class='required'>*</span>Hello Input Text</label> <div class="rightCol"> <input name='hellotext' value='Hello, World!' maxlength='2048' type=TEXT title="Hello Input Text" /> <input name='prompt' type=CHECKBOX> </div> <br/><br/> 40 MashupHub API Reference Feed generator component package hellodemo; import import import import com.ibm.mashuphub.model.RequestData; com.ibm.mashuphub.model.dataobject.Entry; com.ibm.mashuphub.model.dataobject.FeedContent; com.ibm.mashuphub.plugin.BaseGeneratorPlugin; public class HelloGenerator extends BaseGeneratorPlugin { @Override public FeedContent generateFeed(RequestData rdata, Entry entry) { return new FeedContent(AtomGenerator.generateAtomDocument(rdata, entry).toString().getBytes()); } } Feed generator implementation class package hellodemo; import java.util.Date; import org.apache.abdera.Abdera; import org.apache.abdera.model.Entry; import org.apache.abdera.model.Feed; import com.ibm.mashuphub.model.RequestData; public class AtomGenerator { static final String copyright() { return com.ibm.mashuphub.Copyright.IBM_COPYRIGHT; } public static Feed generateAtomDocument(RequestData rdata, com.ibm.mashuphub.model.dataobject.Entry entry) { // Some example values String user = "User Name"; String title = "Mashup Hub Hello World Feed"; String subtitle = "Mashup Hub Prototype"; String url = "http://www.ibm.com/feed.atom"; String hellotext = "Hello, World!"; Date updated = new Date(); if (entry != null) { hellotext = entry.getParameters().get("hellotext").getDefaultValue(); } // If hellotext parameter was set in request, use that if (rdata.getParameter("hellotext") != null) { hellotext = rdata.getParameter("hellotext"); } // Create Abdera feed Abdera abdera = new Abdera(); Feed feed = abdera.getFactory().newFeed(); feed.setId(url); feed.setTitle(title); feed.addLink(url, "self").setMimeType("application/atom+xml"); feed.setUpdated(updated); feed.setSubtitle(subtitle); feed.setGenerator(null,null,"Mashup Hub Feed Generator"); Appendix. Sample Plug-in 41 // Create Abdera entry Entry e = abdera.getFactory().newEntry(); e.setTitle(hellotext); e.setId("urn:uuid:1"); e.setUpdated(updated); e.addAuthor(user); e.setSummary("Atom Feed Entry 1"); // Add entry and return feed feed.addEntry(e); return feed; } } 42 MashupHub API Reference Accessibility This product is currently not accessible. © Copyright IBM Corp. 2007, 2008 43 44 MashupHub API Reference Notices This information was developed for products and services offered in the U.S.A. IBM may not offer the products, services, or features discussed in this document in other countries. Consult your local IBM representative for information on the products and services currently available in your area. Any reference to an IBM product, program, or service is not intended to state or imply that only that IBM product, program, or service may be used. Any functionally equivalent product, program, or service that does not infringe any IBM intellectual property right may be used instead. However, it is the user’s responsibility to evaluate and verify the operation of any non-IBM product, program, or service. IBM may have patents or pending patent applications covering subject matter described in this document. The furnishing of this document does not grant you any license to these patents. You can send license inquiries, in writing, to: IBM Director of Licensing IBM Corporation North Castle Drive Armonk, NY 10504-1785 U.S.A. For license inquiries regarding double-byte (DBCS) information, contact the IBM Intellectual Property Department in your country or send inquiries, in writing, to: IBM World Trade Asia Corporation Licensing 2-31 Roppongi 3-chome, Minato-ku Tokyo 106-0032, Japan The following paragraph does not apply to the United Kingdom or any other country where such provisions are inconsistent with local law: INTERNATIONAL BUSINESS MACHINES CORPORATION PROVIDES THIS PUBLICATION ″AS IS″ WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Some states do not allow disclaimer of express or implied warranties in certain transactions, therefore, this statement may not apply to you. This information could include technical inaccuracies or typographical errors. Changes are periodically made to the information herein; these changes will be incorporated in new editions of the publication. IBM may make improvements and/or changes in the product(s) and/or the program(s) described in this publication at any time without notice. Any references in this information to non-IBM Web sites are provided for convenience only and do not in any manner serve as an endorsement of those Web sites. The materials at those Web sites are not part of the materials for this IBM product and use of those Web sites is at your own risk. IBM may use or distribute any of the information you supply in any way it believes appropriate without incurring any obligation to you. © Copyright IBM Corp. 2007, 2008 45 Licensees of this program who wish to have information about it for the purpose of enabling: (i) the exchange of information between independently created programs and other programs (including this one) and (ii) the mutual use of the information which has been exchanged, should contact: IBM Corporation D53/G3 555 Bailey Avenue San Jose, CA 95141 U.S.A. Such information may be available, subject to appropriate terms and conditions, including in some cases, payment of a fee. The licensed program described in this document and all licensed material available for it are provided by IBM under terms of the IBM Customer Agreement, IBM International Program License Agreement or any equivalent agreement between us. All statements regarding IBM’s future direction or intent are subject to change or withdrawal without notice, and represent goals and objectives only. This information contains examples of data and reports used in daily business operations. To illustrate them as completely as possible, the examples include the names of individuals, companies, brands, and products. All of these names are fictitious and any similarity to the names and addresses used by an actual business enterprise is entirely coincidental. COPYRIGHT LICENSE: This information contains sample application programs in source language, which illustrate programming techniques on various operating platforms. You may copy, modify, and distribute these sample programs in any form without payment to IBM, for the purposes of developing, using, marketing or distributing application programs conforming to the application programming interface for the operating platform for which the sample programs are written. These examples have not been thoroughly tested under all conditions. IBM, therefore, cannot guarantee or imply reliability, serviceability, or function of these programs. If you are viewing this information softcopy, the photographs and color illustrations may not appear. Trademarks The following terms are trademarks of International Business Machines Corporation in the United States, other countries, or both: InfoSphere Adobe, Acrobat, Portable Document Format (PDF), PostScript, and all Adobe-based trademarks are either registered trademarks or trademarks of Adobe Systems Incorporated in the United States, other countries, or both. Intel, Intel logo, Intel Inside, Intel Inside logo, Intel Centrino, Intel Centrino logo, Celeron, Intel Xeon, Intel SpeedStep, Itanium, and Pentium are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States and other countries. 46 MashupHub API Reference Microsoft, and Windows are trademarks of Microsoft Corporation in the United States, other countries, or both. Java and all Java-based trademarks are trademarks of Sun Microsystems, Inc. in the United States, other countries, or both. Linux is a registered trademark of Linus Torvalds in the United States, other countries, or both. UNIX is a registered trademark of The Open Group in the United States and other countries. Other company, product, or service names may be trademarks or service marks of others. Notices 47 48 MashupHub API Reference Printed in USA