return null;
}
// Get request object
Context context = ObjectModelHelper.getContext(objectModel);
// the absolute path where Cocoon resides
// String xxx = context.getRealPath("/");
// getLogger().error("=======> context real path ="+xxx);
//getLogger().error("=======> editfilename ="+parameters.getParameter("editfilename"));
// Get uri
String request_uri = request.getRequestURI();
String sitemap_uri = request.getSitemapURI();
String action = request.getParameter("action");
String save = request.getParameter("save");
getLogger().debug("**** request-uri=" + request_uri);
getLogger().debug("**** sitemap-uri=" + sitemap_uri);
getLogger().debug("**** action=" + action);
// prepare the return params
String xmlErrorFlag = "";
String xmlErrorMessage = "";
if ((save != null) && save.equals("Save")) {
// get the Document and copy it to the temporary file
getLogger().debug("**** saving ****");
Source source = resolver.resolve("cocoon:/saveedit");
getLogger().debug("======= URL:" + source.getSystemId());
String editFile = (String) session.getAttribute(
"org.apache.lenya.cms.editor.HTMLForm.editFile");
getLogger().debug("======= Saving to :" + editFile);
BufferedReader in = new BufferedReader(new InputStreamReader(source.getInputStream()));
// first, copy to a temporary string buffer (so we can get it back later, and more than once!)
StringBuffer trans = new StringBuffer();
String line;
while ((line = in.readLine()) != null) {
// we need this in order to let EditOnPro save the XHTML markup:
line = org.apache.lenya.util.StringUtil.replace(line, "<", "<");
line = org.apache.lenya.util.StringUtil.replace(line, ">", ">");
trans.append(line + "\n");
}
getLogger().debug("----- Contents of the StringBuffer (trans): " + trans.toString());
// check well-formedness
SAXParser parser = (SAXParser) this.manager.lookup(SAXParser.ROLE); // get the cocoon parser
try {
InputSource iS = new InputSource(new CharArrayReader(trans.toString().toCharArray()));
if (iS == null) {
getLogger().error("----- InputStream is null!");
} else {
//parser.setContentHandler(new AbstractXMLConsumer() { }); // the parser must have a content handler, it will not be used
parser.parse(iS, new org.xml.sax.helpers.DefaultHandler());
}
} catch (SAXException saxE) { // this is the exception we want to catch
xmlErrorFlag = "X"; // set the flag for signalling to the page's stylesheet (body.xsl)
xmlErrorMessage = saxE.getMessage(); // this will also be sent to the stylesheet
getLogger().debug("----- SAX-Exception (message): " + saxE.getMessage());
getLogger().debug("----- SAX-Exception (stacktrace): ", saxE.getException());
String tempFile = (String) session.getAttribute(
"org.apache.lenya.cms.editor.HTMLForm.tempFile");
if (tempFile != null) {
in.close();
HashMap actionMap = new HashMap();
actionMap.put("tempFile", tempFile);
actionMap.put("xmlErrorFlag", xmlErrorFlag);
actionMap.put("xmlErrorMessage", xmlErrorMessage);
return actionMap;
}
return null;
}catch (Exception e) { // something went wrong
getLogger().error("----- Exception occured: ", e);
return null;
}
// then, copy the string buffer to the temporary file
StringReader in2 = new StringReader(trans.toString());
BufferedWriter out = new BufferedWriter(new FileWriter(editFile));
int c;
while ((c = in2.read()) != -1) {
out.write((char) c);
}
in.close();
in2.close();
out.close();
return null;
} else if ((action != null) && action.equals("request")) {
getLogger().debug("**** request (do nothing) ****");
HashMap actionMap = new HashMap();
return actionMap;
} else { // we are not saving
// here comes the checkout, revision control aso.
boolean checkout = true;
if (checkout) {
String formeditorPath = context.getRealPath("formeditor");
String tempFile = formeditorPath + request.getRequestURI();
String lenyaPath = "lenya/pubs/ethz-mat/docs/ethz/mat/";
String editFile = context.getRealPath("/") + lenyaPath + request.getSitemapURI();
getLogger().debug("**** tempfile=" + tempFile);
getLogger().debug("**** editfile=" + editFile);
File tf = new File(tempFile);