Google Mashup Editor (GME) applications give you powerful features for reading, writing, and displaying data. Data in GME applications is always stored as a Google Data (better known as GData) feed. GData is a data protocol based on Atom and the Atom publishing protocol (APP). Data not natively stored in the GData format, such as data from RSS feeds, are automatically converted to GData by GME through an XSL transformation. This ensures that all data is read, written, and manipulated in the same common format, which makes it easy to operate on different types of data from different sources with GME modules.
GData's extensibility gives you the flexibility to create your own feeds containing the data you want to store. By extending the feed with custom elements or using elements already available in GData, you can create structured data feeds that are easy to manipulate using XPath, a regular expression-based language that allows you find elements in GData feeds. To learn more about how to use XPath, see the Introduction to XPath.
There are many data sources available for use in your GME applications. Some sources allow you to read and write, while others are read-only.
Each GME application provides two built-in data feeds that allow users to read and write data specific to the application or to the user.
${app} The ${app} feed is specific to the GME application instance. Initially, the feed is empty. All users of your application can
read data from and, if you enable it, write data to the ${app} feed. When you write to
the ${app} feed, you can specify a path one level deep, called a stripe. For example, if
you want to have two application-wide data stores for your Google Maps mashup
(one for markers and one for a customer list), you can create the ${app}/markers stripe and the ${app}/customers stripe and use them separately in your application. For more about writing data to a feed, see
Writing Data.
${user}Each user of your application has access to a separate ${user} feed. Users can read and write data to their own personal feeds, but users don't have access to anyone else's feed. Initially, this feed is empty. Your application must
provide a way for users to add data. When you write to
the ${user} feed, you can specify a path one level deep, called a stripe. For example, if
you want to have two user-specific data stores for your Google Maps mashup
(one for the user's locations and one for the user's profile information), you
can create the ${user}/locations stripe and the ${user}/profile stripe and use them separately in your application. For details on writing data to a feed, see Writing Data.
You can use any RSS or Atom feed as a data feed for GME modules. External RSS and non-GData Atom feeds are read-only. RSS feeds are automatically converted to GData (Atom) feeds through an XSL transformation. Custom extension elements are preserved during the transformation and can be accessed in the same way as Atom elements, through XPath queries.
An ideal way to see how RSS feeds are transformed is to view them in GME's handy feed browser. Click the "Feed Browser" tab and select "Remote Feed" from the drop-down menu. Type the URL to the RSS feed and pull the feed up in the browser. You'll see all the elements available in the feed.
In addition to ${app} and ${user}, GME provides several other built-in feeds:
<gm:data> tag. To read data in your GME application, you must include a module tag, such as a list, that accepts a data source in its data attribute. You'll probably want to include a template tag that references the data elements you want to read. If you don't include a template, GME uses a built-in template named "default".
In the following example, a list module reads entries from Digg and displays the
title of each entry by referencing its atom:title element.
<gm:page title="myApp"> <gm:list id="myList" data="http://www.digg.com/rss/index.xml" template="myListTemplate"/> <gm:template id="myListTemplate">
<div repeat="true">
<gm:text ref="atom:title"/>
</div>
</gm:template> </gm:page>
In the gm:template tag, we specify how the data will look when displayed.
The template must have one repeating element in order to display multiple entries.
In this case, we set the <div> element to repeat by adding
the repeat attribute to the <div> tag and setting it to true.
This creates a div for every entry in the feed. You can use the repeat attribute
in any HTML element in a gm:template tag. For example if you want to create a
table with a repeating row, you can put the repeat attribute in the <tr> or
<tbody> HTML element.
Within the <div> we specify a <gm:text>
tag and have it refer to atom:title in the feed. The value
of the ref attribute is actually an XPath query to the element in the feed.
The title of each entry is specified by the XPath query atom:title.
For more on XPath, see the Introduction to XPath section.
In addition to defining your own templates, GME supplies built-in templates you can use for displaying data. To use a built-in template, you specify it by name in the template attribute; for example:
<gm:list id="myList" data="http://digg.com/rss/index.xml" template="default" />
The built-in templates are as follows:
simple, which displays the first data element and a pair of edit buttons. task, suitable for a task list.blog, which shows the headlines from a blog feed or similar information.base, useful for displaying product queries from Google Base. contact, best used for displaying contacts.default, a minimal template that shows headlines in a bulleted list.debug, which displays every element of the feed. To write data to a feed in your GME application, you must include the following three tags:
gm:create
tag to add new data or a gm:editButtons
tag to edit and delete data.In the example below, a list module reads data from the ${app}/foo stripe. The list module
also displays a create button below the list and edit and delete buttons next
to each item in the list.
<gm:page title="myApp">
<!-- Here we create the list to display the data we save in
the $app/foo feed -->
<gm:list id="myList" data="${app}/foo" template="myListTemplate"/>
<!-- Here we create the template that contains edit
and delete buttons. We also specify a create button to add
data to the feed. -->
<gm:template id="myListTemplate">
<table>
<tbody repeat="true">
<tr>
<td><gm:text ref="atom:title"/></td>
<td><gm:editButtons /></td>
</tr>
</tbody>
</table>
<gm:create label="Create new entry"/>
</gm:template>
</gm:page>
The template allows the user to read and write an element using the same control -- gm:text, in this case. To add the ability to edit an entry,
all we need is a gm:editButtons tag somewhere in the repeating element.
In this case, we've added it right next to the text we display.
The gm:editButtons tag adds two buttons to the HTML element
that contains it: one for editing the entry and one for deleting the entry.
When an entry is deleted, it's removed from the
data store and can no longer be accessed.
By default, the edit buttons are image buttons. You can have them displayed as textual buttons by adding text="true" to the
editButtons tag.
To create a new entry in the feed, we place a gm:create tag
outside the repeating element. When the user clicks the create button, a new
row appears and the user can enter data. That data
is saved to the feed according to the reference attribute for that item.
In the example above, a new entry is created and the data entered by the user is saved into the atom:title element of the newly created entry. Again, atom:title is just an XPath query to an element in the feed. If you're using the ${app} or ${user} feeds and you create an XPath query to an element that is not currently in the feed, that
element is created for you.
The ${app} and ${user} feeds are extensible XML documents, so you can add any elements you want. To add elements that aren't defined by the atom: or gd: namespaces, use the gmd: namespace. For example if you want to store a time element in
the feed, you can reference it with the query gmd:time, and
any data you store will appear in the feed as the gmd:time element.
GME provides various features you can use to work with feed data, such as reading, writing, searching and so on. In order to optimize performance of your applications, not all features are available for all feeds. The following matrix shows which features you can use on which feeds:
| Feed | Read | Write | Paging | Search |
|---|---|---|---|---|
${app} and ${user} |
Yes | Yes | Yes | |
| External RSS/Atom feeds | Yes | Yes | ||
${members} |
Yes | Yes | ||
${base} |
Yes | Yes | Yes | |
${test} |
Yes | Yes |
For information on which feeds and elements can be used for filtering, see the filtering document.
When you publish a GME application, you can control access to the feeds that belong to it. For each application, you have access control over these built-in feeds: ${app}, ${user}, and ${members}. For the ${app} feed, you can specify separate access settings for members and for non-members; the ${user} and ${members} feeds are available to members only.
For members, you can specify editable, read-only, or no access for each feed. For non-members, you can specify read-only or no access for the ${app} feed.
The following table summarizes these access options:
| Feed | Access options for members | Access options for non-members |
|---|---|---|
${app} |
Editable, Read-only, No access | No access, Read-only |
${user} |
Editable, Read-only, No access | none |
${members} |
Editable, Read-only, No access | none |
(Default setting is in bold) |
||
To specify access settings for feeds, click the Published Apps tab on the right side of the Editor screen, then click an application to select it. Use the drop-down menus on the right to select access settings.
You can also use this page to manage membership in your application. Click the Members tab to see the membership controls. To add a member, type the new member's Google Account name in the box, then click Add. To remove a member, click to select the member, then click the trash can next to the name.
Some applications require a hierarchy of data, in which each element at an outer level contains specific data at a secondary level. One example of this kind of application is a task list. In a task list, you often have a list of
projects, each of which contains a list of tasks. In order to associate projects to lists
of data, you can reference the feed of the parent list by id in the data attribute of
the child list. As with all built-in feeds, you reference the feed using the
feed variable substitution method (that is, ${feed_name}), as in the following example.
<gm:page title="hierarchy">
<h1> Projects </h1>
<gm:list id="Projects" data="${app}/ProjectData" template="myTemplate"/> <h1> Project tasks </h1>
<gm:list id="tasks" data="${Projects}/taskData" template="myTemplate">
<gm:handleEvent src="Projects" />
</gm:list> <gm:template id="myTemplate">
<table>
<tbody repeat="true">
<tr>
<td><gm:text ref="atom:title"/></td>
<td><gm:template type="img"/></td>
</tr>
</tbody>
</table>
<gm:create label="Create new entry"/>
</gm:template> </gm:page>
GME applications use a small subset of XPath, a search and query language that allows you to refer to tags and attributes in an XML document. You use XPath to access namespaces, elements, and attribute names and values from data feeds, and you use XPath syntax in your applications to refer to feed elements for reading and writing. Here are the forms of XPath syntax you can use in Google Mashup applications:
"ns:elemName/ns:elemName2...."You can use
"ns:elemName[@attr='val']/ns:elemName2[@attr2='val2']/...."
"ns:elemName[@attr='val']/ns:elemName2/...."
text() and @attr expressions for text and attribute selection at the end of the XPath:
"ns:elemName/ns:elemName2/text()"You can see examples of XPath syntax in most GME sample applications. Note that GME supports only the subset of XPath described here, not the full specification. For more information on XPath, see this Introduction to XPath on the Web.
"ns:elemName/ns:elemName2/@attr2"
"ns:elemName[@attr='val']/ns:elemName2/@attr1"