SourceParameters pars = new SourceParameters();
pars.setSingleParameterValue("profile", "sunlet-base");
pars.setSingleParameterValue("application", (String)this.request.getAttribute(org.apache.cocoon.sunshine.sunrise.Constants.REQUEST_ATTRIBUTE_APPLICATION_NAME));
pars.setSingleParameterValue("handler", (String)this.request.getAttribute(org.apache.cocoon.sunshine.sunrise.Constants.REQUEST_ATTRIBUTE_HANDLER_NAME));
Resource saveResource = (Resource)configuration.get(Constants.CONF_SUNLETBASE_SAVE_RESOURCE);
if (saveResource == null) {
throw new ProcessingException("sunSpot: No save resource defined for type sunlet-base.");
} else {
this.getResourceConnector().saveXML(saveResource.getResourceType(),null,
saveResource.getResourceIdentifier(),pars,
sunletsFragment);
// now the hardest part, clean up the whole cache
this.cleanUpCache(null, null, configuration);
}
}
} finally {
this.getSunShineComponent().stopWritingTransaction(context);
}
}
// general commands
if (command != null && command.equals("cleancache") == true) {
this.cleanUpCache(null, null, configuration);
}
String state = this.request.getParameter(SunSpot.REQ_PARAMETER_STATE);
if (state == null) {
state = (String)context.getAttribute(ATTRIBUTE_ADMIN_STATE, Constants.STATE_MAIN);
}
// now start producing xml:
AttributesImpl attr = new AttributesImpl();
consumer.startElement("", Constants.ELEMENT_ADMINCONF, Constants.ELEMENT_ADMINCONF, attr);
context.setAttribute(ATTRIBUTE_ADMIN_STATE, state);
consumer.startElement("", Constants.ELEMENT_STATE, Constants.ELEMENT_STATE, attr);
consumer.characters(state.toCharArray(), 0, state.length());
consumer.endElement("", Constants.ELEMENT_STATE, Constants.ELEMENT_STATE);
if (state.equals(Constants.STATE_MAIN) == true) {
DocumentFragment rolesDF = this.getSunRise().getRoles();
Node roles = null;
if (rolesDF != null) roles = XMLUtil.getSingleNode(rolesDF, "roles");
IncludeXMLConsumer.includeNode(roles, consumer, consumer);
}
if (state.equals(Constants.STATE_MAIN_ROLE) == true) {
DocumentFragment rolesDF = this.getSunRise().getRoles();
Node roles = null;
if (rolesDF != null) roles = XMLUtil.getSingleNode(rolesDF, "roles");
IncludeXMLConsumer.includeNode(roles, consumer, consumer);
String role = this.request.getParameter(SunSpot.REQ_PARAMETER_ROLE);
if (role == null) {
role = (String)context.getAttribute(ATTRIBUTE_ADMIN_ROLE);
}
context.setAttribute(ATTRIBUTE_ADMIN_ROLE, role);
if (role != null) {
this.sendStartElementEvent(consumer, "roleusers");
this.sendStartElementEvent(consumer, "name");
this.sendTextEvent(consumer, role);
this.sendEndElementEvent(consumer, "name");
DocumentFragment userDF = this.getSunRise().getUsers(role, null);
Node users = null;
if (userDF != null) users = XMLUtil.getSingleNode(userDF, "users");
IncludeXMLConsumer.includeNode(users, consumer, consumer);
this.sendEndElementEvent(consumer, "roleusers");
}
}
if (state.equals(Constants.STATE_GLOBAL) == true) {
profileID = this.getProfileID(SunSpot.BUILDTYPE_VALUE_GLOBAL, null, null, true);
Map profile = this.retrieveProfile(profileID);
if (profile == null) {
this.createProfile(context, SunSpot.BUILDTYPE_VALUE_GLOBAL, null, null, true);
profile = this.retrieveProfile(profileID);
}
this.showPortal(consumer, true, context, profile, profileID);
}
if (state.equals(Constants.STATE_ROLE) == true) {
String role = this.request.getParameter(SunSpot.REQ_PARAMETER_ROLE);
if (role == null) {
role = (String)context.getAttribute(ATTRIBUTE_ADMIN_ROLE);
}
context.setAttribute(ATTRIBUTE_ADMIN_ROLE, role);
if (role != null) {
consumer.startElement("", Constants.ELEMENT_ROLE, Constants.ELEMENT_ROLE, attr);
consumer.characters(role.toCharArray(), 0, role.length());
consumer.endElement("", Constants.ELEMENT_ROLE, Constants.ELEMENT_ROLE);
profileID = this.getProfileID(SunSpot.BUILDTYPE_VALUE_ROLE, role, null, true);
Map profile = this.retrieveProfile(profileID);
if (profile == null) {
this.createProfile(context, SunSpot.BUILDTYPE_VALUE_ROLE, role, null, true);
profile = this.retrieveProfile(profileID);
}
this.showPortal(consumer, true, context, profile, profileID);
}
}
if (state.equals(Constants.STATE_USER) == true) {
String role = this.request.getParameter(SunSpot.REQ_PARAMETER_ROLE);
String id = this.request.getParameter(SunSpot.REQ_PARAMETER_ID);
if (role == null) {
role = (String)context.getAttribute(ATTRIBUTE_ADMIN_ROLE);
}
if (id == null) {
id = (String)context.getAttribute(ATTRIBUTE_ADMIN_ID);
}
context.setAttribute(ATTRIBUTE_ADMIN_ID, id);
context.setAttribute(ATTRIBUTE_ADMIN_ROLE, role);
if (role != null && id != null) {
consumer.startElement("", Constants.ELEMENT_ROLE, Constants.ELEMENT_ROLE, attr);
consumer.characters(role.toCharArray(), 0, role.length());
consumer.endElement("", Constants.ELEMENT_ROLE, Constants.ELEMENT_ROLE);
consumer.startElement("", Constants.ELEMENT_ID, Constants.ELEMENT_ID, attr);
consumer.characters(id.toCharArray(), 0, id.length());
consumer.endElement("", Constants.ELEMENT_ID, Constants.ELEMENT_ID);
profileID = this.getProfileID(SunSpot.BUILDTYPE_VALUE_ID, role, id, true);
Map profile = this.retrieveProfile(profileID);
if (profile == null) {
this.createProfile(context, SunSpot.BUILDTYPE_VALUE_ID, role, id, true);
profile = this.retrieveProfile(profileID);
}
this.showPortal(consumer, true, context, profile, profileID);
}
}
// one sunlet
if (state.equals(Constants.STATE_SUNLET) == true) {
if (sunletsFragment != null && sunletID != null) {
Node sunlet = XMLUtil.getSingleNode(sunletsFragment, "sunlets-profile/sunlets/sunlet[@id='"+sunletID+"']");
if (sunlet != null) {
IncludeXMLConsumer.includeNode(sunlet, consumer, consumer);
}
} else {
state = Constants.STATE_SUNLETS;
}
}
if (state.equals(Constants.STATE_SUNLETS) == true) {
consumer.startElement("", Constants.ELEMENT_SUNLETS, Constants.ELEMENT_SUNLETS, attr);
// load the base sunlets profile
if (sunletsFragment == null) {
SourceParameters pars = new SourceParameters();
pars.setSingleParameterValue("application", (String)this.request.getAttribute(org.apache.cocoon.sunshine.sunrise.Constants.REQUEST_ATTRIBUTE_APPLICATION_NAME));
Resource res = (Resource)configuration.get(Constants.CONF_SUNLETBASE_RESOURCE);
if (res == null) {
throw new ProcessingException("No configuration for sunSpot-sunlet base profile found.");
}
sunletsFragment = this.loadXML(res.getResourceType(), null,
res.getResourceIdentifier(), pars,
"Error during loading of sunLet base.");
context.setAttribute(ATTRIBUTE_ADMIN_SUNLETS, sunletsFragment);
}
IncludeXMLConsumer.includeNode(XMLUtil.selectSingleNode(sunletsFragment,
"sunlets-profile"), consumer, consumer);