Skeleton external class for components

Posted: 22 September 2009 in Components, External, Java, Pages, SitePublisher, Sites, Teamsite

package com.acme.components;

import com.interwoven.livesite.dom4j.Dom4jUtils;
import com.interwoven.livesite.file.FileDALIfc;
import com.interwoven.livesite.runtime.RequestContext;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.dom4j.Document;
import org.dom4j.Element;

public class Skeleton {

public Document getSiteMap(RequestContext context) {

// open and parse the sitemap as an XML document
FileDALIfc fileDal = context.getFileDAL();                                  // gives us the root directory of the workarea
String siteMapFilePath = context.getSite().getPath() + “/default.sitemap”;  // computes the path to the default.sitemap file
InputStream siteMapFileInputStream = fileDal.getStream(siteMapFilePath);    // opens the siteMapFile as a stream for reading
Document siteMapXMLDoc = Dom4jUtils.newDocument(siteMapFileInputStream);    // and creates an XML document from it

Document doc = Dom4jUtils.newDocument();
Element rootElement = doc.addElement(this.getClass().getCanonicalName() + “.getSiteMap”);

rootElement.add(siteMapXMLDoc.getRootElement());
return(doc);
}

public Document readRSSFeed(RequestContext context) {
Document doc = Dom4jUtils.newDocument();
Element rootElement = doc.addElement(this.getClass().getCanonicalName() + “.readRSSFeed”);
try {
String feedURLAsString = context.getParameterString(“feedURL”);
String proxyServer = context.getParameterString(“proxyServer”);
int proxyServerPort = Integer.valueOf(context.getParameterString(“proxyServerPort”));
URL feedURL = null;
try {
feedURL = new URL(“http”, proxyServer, proxyServerPort, feedURLAsString);
} catch (MalformedURLException ex) {
Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
}
Document feed = Dom4jUtils.newDocument(feedURL.openStream());
if (feed != null) {
rootElement.add(feed.getRootElement());
}
} catch (MalformedURLException ex) {
Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
} catch (Exception ex) {
Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
}
return (doc);
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s