sitemapParentPath = sitemapParentPath.substring(5); // Remove "file:" protocol
getLogger().debug(".act(): PARENT PATH OF SITEMAP: " + sitemapParentPath);
// Get request object
Request request = ObjectModelHelper.getRequest(objectModel);
if (request == null) {
getLogger().error("No request object");
return null;
}
// Get parameters
String parentid = request.getParameter("parentid");
if (parentid == null) {
getLogger().warn("No parentid parameter defined! It might be necessary to specify a parentid request parameter.");
}
String childid = request.getParameter("childid");
if (childid == null) {
getLogger().error("No childid parameter defined! Please specify childid as request parameter.");
throw new Exception("No childname defined!");
}
String childname = request.getParameter("childname");
if (childname == null) {
getLogger().error("No childname defined! Please specify childname as request parameter which is being used as label within a sitetree or topic map.");
throw new Exception("No childname defined!");
}
String childtype = request.getParameter("childtype");
if (childtype == null) {
getLogger().error("No childtype defined! Please specify childtype as request parameter with value either \"branch\" or \"leaf\".");
throw new Exception("No childname defined!");
}
short childType;
if (childtype.equals("branch")) {
childType = ParentChildCreatorInterface.BRANCH_NODE;
} else if (childtype.equals("leaf")) {
childType = ParentChildCreatorInterface.LEAF_NODE;
} else {
getLogger().error("No such child type: " + childtype);
return null;
}
String doctype = request.getParameter("doctype");
if (doctype == null) {
getLogger().warn("No doctype defined! Please specify doctype as request parameter, which is being used to resolve the creator within doctypes.xconf. Otherwise the DefaultCreator class is being used (see below)!");
}
String language = request.getParameter("language");
if (!validate(parentid, childid, childname, childtype, doctype)) {
getLogger().error("Exception: Validation of parameters failed");
return null;
}
// Get session
Session session = request.getSession(true);
if (session == null) {
getLogger().error("No session object");
return null;
}
// Get creator
ParentChildCreatorInterface creator = null;
String absoluteDoctypesPath = sitemapParentPath + doctypesPath;
Document doctypesDoc = new SAXReader().read("file:" + absoluteDoctypesPath +
"doctypes.xconf");
Attribute creator_src = (Attribute) doctypesDoc.selectSingleNode("/doctypes/doc[@type='" +
doctype + "']/creator/@src");
if (creator_src != null) {
getLogger().info(".act(): Creator found for \"" + doctype + "\": " +
creator_src.getName() + " " + creator_src.getPath() + " " + creator_src.getValue());
// now get the constructor that accepts the configuration
Class creatorClass = Class.forName(creator_src.getValue());
creator = (ParentChildCreatorInterface) creatorClass.newInstance();
} else {
getLogger().warn("No creator found for \"" + doctype +
"\". DefaultBranchCreator will be taken.");
creator = new org.apache.lenya.cms.authoring.DefaultBranchCreator();
}
getLogger().debug(".act(): Creator : " + creator.getClass().getName());
// Init creator
// "Read" the configuration from the DOM node
DefaultConfigurationBuilder defaultConfigBuilder = new DefaultConfigurationBuilder();
Configuration[] docTypeConfigs = defaultConfigBuilder.buildFromFile(absoluteDoctypesPath +
"doctypes.xconf").getChildren();
Configuration doctypeConf = null;
for (int i = 0; i < docTypeConfigs.length; i++) {
String typeName = docTypeConfigs[i].getAttribute("type");
if (typeName.equals(doctype)) {
doctypeConf = docTypeConfigs[i].getChild("creator", false);
}
}
creator.init(doctypeConf);
// Transaction should actually be started here!
String treefilename = sitemapParentPath + treeAuthoringPath;
getLogger().debug(".act(): Filename of tree: " + treefilename);
if (!new File(treefilename).exists()) {
getLogger().warn("No sitetree or topic map: " + treefilename);
} else {
if (!updateTree(childtype, childType, childid, childname, parentid, doctype, creator, treefilename)) return null;
}
// Transaction should actually be finished here!
// Create actual document
// grab all the parameters from session, request params and
// sitemap params
HashMap allParameters = new HashMap();
String[] names = parameters.getNames();
for (int i = 0; i < names.length; i++) {
String name = names[i];
String value = null;
try {
value = parameters.getParameter(name);
} catch (ParameterException pe) {
value = null;
}
allParameters.put(name, value);
}
Enumeration requestParameters = request.getParameterNames();
while (requestParameters.hasMoreElements()) {
String requestParameterName = (String) requestParameters.nextElement();
if (allParameters.containsKey(requestParameterName)) {
// we do not allow name clashes
throw new ProcessingException("Name clash in request parameter " +
"and sitemap parameter: " + requestParameterName);
}
allParameters.put(requestParameterName, request.getParameter(requestParameterName));
}
Enumeration sessionAttributeNames = session.getAttributeNames();
while (sessionAttributeNames.hasMoreElements()) {