With the google sites API we can build client application that can access, publish and modify content within a Google site
In this post I show some functionalities of Google sites Java library that allow to :
- Create a site
- Insert web pages into a site
All these action are done by an istance of SitesService :
SitesService client = new SitesService("mySite");
Create a site
This feature is only available to Google Apps domains. To create a site we must execute :
SiteEntry entry = new SiteEntry():
entry.setTitile(new PlainTextContruct("title of the site"));
entry.setSummary(new PlainTextConstruct("summary of the site"));
Theme theme = new Theme();
theme.setValue("theme of the site");
entry.setTheme(theme);
client.insert(new URL(getSiteFeedUrl(), entry));
where the method "getSiteFeedUrl()" return the url's related of site feed of "domain", composed as follows: "http://sites.google.com/feeds/site/" + domain + "/"
where "domain" is the name of your domain. If the site is hosted on a Google account we have to put "site" instead of domain.
We can use a site feed to :
- list the Google sites that a user owns
- list the Google sites that a user has viewing permission for
- to modify the name of an existing site
- to create and/or copy an entire site
At page creation we can choose a large variety of themes, the same themes that we can select during the manual creation of a Google Site from the Url http://sites.google.com.
Insert web pages
Now we show how to insert web pages into the sites that we have created.
WebPageEntry pageEntry = new WebPageEntry();
pageEntry.setTitle(new PlainTextConstruct("title of the page"));
XmlBlob blob = new XmlBlob();
blob.setBlob("HTML content of the page");
pageEntry.setContent(new XhtmlTextConstruct(blob));
client.insert(new URL(getContentSiteFeedUrl("siteName")), pageEntry);
where the method "getContentSiteFeedUrl("siteName")" return the url's related of content feed of the webspace name of "siteName". With the content feed we can lists a Site's latest content. The url's feed is the follow: "http://sites.google.com/feeds/site/" + domain + "/" + siteName + "/".
In this example I chose to create a "webpage", but there are other kinds of pages that I can create :
- FileCabinetPageEntry
- AnnouncementsPageEntry
- ListPageEntry
With Google Sites API you can create a web application that offers a service to create in a simple way a Google site, to the users of a given Google apps domain. You can find the references to the Google API to the following link : http://code.google.com/intl/it-IT/labs/.