/**
* Process one sunlet
*/
public void run() {
XMLSerializer compiler = null;
Element sunletConf = (Element)this.loadedSunlet[1];
SourceParameters p = (SourceParameters)loadedSunlet[2];
try {
// Determine the resource to load
// If the sunLet is customizable and has no customization info
// the customization resource is loaded, otherwise the resource
Resource resource = null;
boolean showCustomizePage = p.getParameterAsBoolean(Constants.PARAMETER_CUSTOMIZE, false);
if (showCustomizePage == true) {
final String value = XMLUtil.getValueOf(sunletConf, "customization/@uri", null);
if (value == null) {
this.logger.error("The sunLet '"+this.sunletID+"' is customizable but has no customization info.");
}
resource = new Resource(this.resolver, value);
}
if (resource == null) {
resource = new Resource(this.resolver, XMLUtil.getValueOf(sunletConf, "resource/@uri"));
}
boolean handlesSizable = XMLUtil.getValueAsBooleanOf(sunletConf, "configuration/handlesSizable", false);
if (handlesSizable == false && p.getParameter("size", "max").equals("max") == false) {
// do nothing here
loadedSunlet[0] = new byte[0];
} else {
compiler = (XMLSerializer)this.manager.lookup(XMLSerializer.ROLE);
compiler.startDocument();
XMLConsumer nextConsumer = compiler;
NodeList transformations = XMLUtil.selectNodeList(sunletConf,
"transformation/stylesheet");
Transformer xslT = null;
ArrayList transformers = new ArrayList();
ComponentSelector selector = null;
Request request = ObjectModelHelper.getRequest(this.objectModel);
try {
if (transformations != null && transformations.getLength() > 0) {
selector = (ComponentSelector) this.manager.lookup(Transformer.ROLE + "Selector");
nextConsumer = new IncludeXMLConsumer(nextConsumer);
for(int k = transformations.getLength()-1; k >=0; k--) {
xslT = (Transformer)selector.select("xslt");
transformers.add(xslT);
xslT.setup(resolver,
objectModel,
XMLUtil.getValueOfNode(transformations.item(k)),
new Parameters());
xslT.setConsumer(nextConsumer);
nextConsumer = xslT;
}
nextConsumer.startDocument();
}
switch (resource.getResourceType()) {
case ResourceConnector.RESOURCE_TYPE_CLASS: {
Sunlet theSunlet;
try {
Class loaderClass = Class.forName(resource.getResourceIdentifier());
theSunlet = (Sunlet)loaderClass.newInstance();
} catch (ClassNotFoundException cnfException) {
throw new ProcessingException("getSunlet: Class not found: " + resource.getResourceIdentifier(), cnfException);
} catch (IllegalAccessException iaException) {
throw new ProcessingException("getSunlet: Illegal Access: " + resource.getResourceIdentifier(), iaException);
} catch (InstantiationException iException) {
throw new ProcessingException("getSunlet: Instantion exception: " + resource.getResourceIdentifier(), iException);
}
theSunlet.init(objectModel, p);
theSunlet.execute(nextConsumer, nextConsumer, objectModel, p);
break;
}
default: {
boolean includeFragment = true;
boolean handlesParameters = XMLUtil.getValueAsBooleanOf(sunletConf, "configuration/handlesParameters", true);
String size = p.getParameter("size", "max");
if (resource.getResourceType() == ResourceConnector.RESOURCE_TYPE_FILE) {
// files have no possibility to evaluate minimized, so if they are not maximized
// they will be neglected
includeFragment = size.equals("max");
} else {
includeFragment = size.equals("max");
if (includeFragment == false) {
if (this.logger.isWarnEnabled() == true) {
this.logger.warn("Minimized sunlet '"+sunletID+"' not handled correctly.");
}
}
}
if ( includeFragment == true) {
String res;
if (resource.getResourceType() == ResourceConnector.RESOURCE_TYPE_URI) {
if (this.response != null) {
res = this.response.encodeURL(resource.getResourceIdentifier());
} else {
res = resource.getResourceIdentifier();
}
} else {
res = resource.getResourceIdentifier();
}
if (this.logger.isDebugEnabled() == true) {
this.logger.debug("sunSpot Loading sunlet " + sunletID);
}
// add the parameters to the request attributes
Map info = new HashMap(3);
SessionContextImpl.sunLetInfo.set(info);
info.put(Constants.SUNLETINFO_PARAMETERS, p);
info.put(Constants.SUNLETINFO_PORTALURI, request.getRequestURI());
info.put(Constants.SUNLETINFO_STATUSPROFILE, loadedSunlet[7]);
this.resourceConnector.streamXML(resource.getResourceType(), null,
res, (handlesParameters == true ? p : null),
new IncludeXMLConsumer(nextConsumer), null);
if (this.logger.isDebugEnabled() == true) {
this.logger.debug("sunSpot: Loaded sunlet " + sunletID);
}
}
}
}
if (xslT != null) {
xslT.endDocument();
xslT = null;
}
} finally {
SessionContextImpl.sunLetInfo.set(null);
if (selector != null) {
for(int i=0; i<transformers.size(); i++) {
selector.release((Component)transformers.get(i));
}
this.manager.release((Component)selector);
}
}
transformers.clear();
nextConsumer = null;
compiler.endDocument();
loadedSunlet[0] = compiler.getSAXFragment();
}
} catch (Exception local) {
// this exception is ignored and an error message is included
// later on when the sunlet is processed