You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by mi...@apache.org on 2003/11/28 19:46:57 UTC
cvs commit: cocoon-lenya/src/java/org/apache/lenya/cms/cocoon/acting HTMLFormSaveAction.java
michi 2003/11/28 10:46:57
Modified: src/webapp/lenya usecase.xmap
src/java/org/apache/lenya/cms/cocoon/acting
HTMLFormSaveAction.java
Log:
validation added
Revision Changes Path
1.146 +1 -0 cocoon-lenya/src/webapp/lenya/usecase.xmap
Index: usecase.xmap
===================================================================
RCS file: /home/cvs/cocoon-lenya/src/webapp/lenya/usecase.xmap,v
retrieving revision 1.145
retrieving revision 1.146
diff -u -r1.145 -r1.146
--- usecase.xmap 27 Nov 2003 14:46:45 -0000 1.145
+++ usecase.xmap 28 Nov 2003 18:46:57 -0000 1.146
@@ -364,6 +364,7 @@
<map:match pattern="*/authoring/**.html">
<map:act type="save">
<map:parameter name="file" value="pubs/{1}/work/editor/authoring/{page-envelope:document-path}"/>
+ <map:parameter name="schema" value="pubs/{1}/config/doctypes/schemas/{request-param:form}.rng"/>
<!-- Continue editing: Insert, Delete, etc. -->
<map:generate src="pubs/{../1}/work/editor/authoring/{page-envelope:document-path}"/>
1.24 +43 -16 cocoon-lenya/src/java/org/apache/lenya/cms/cocoon/acting/HTMLFormSaveAction.java
Index: HTMLFormSaveAction.java
===================================================================
RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/cocoon/acting/HTMLFormSaveAction.java,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- HTMLFormSaveAction.java 9 Nov 2003 01:37:17 -0000 1.23
+++ HTMLFormSaveAction.java 28 Nov 2003 18:46:57 -0000 1.24
@@ -102,9 +102,11 @@
*
* @exception ConfigurationException if an error occurs
*/
+/*
public void configure(Configuration conf) throws ConfigurationException {
super.configure(conf);
}
+*/
/**
* Save data to temporary file
@@ -122,11 +124,16 @@
public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String source, Parameters parameters) throws Exception {
File sitemap = new File(new URL(resolver.resolveURI("").getURI()).getFile());
File file = new File(sitemap.getAbsolutePath() + File.separator + parameters.getParameter("file"));
+ File schema = new File(sitemap.getAbsolutePath() + File.separator + parameters.getParameter("schema"));
+
Request request = ObjectModelHelper.getRequest(objectModel);
+
+
if(request.getParameter("cancel") != null) {
- getLogger().info(".act(): Cancel editing");
+ getLogger().warn(".act(): Editing has been canceled");
+ // FIXME: document needs to be restored from original document
return null;
} else {
if(file.isFile()) {
@@ -166,7 +173,7 @@
} else {
String xupdateModifications = null;
if (pname.indexOf("xupdate:update") > 0) {
- log.error(".act(): UPDATE Node: " + pname);
+ log.debug(".act(): UPDATE Node: " + pname);
if (pname.indexOf("<![CDATA[") > 0) {
xupdateModifications = updateCDATA(request, pname);
} else {
@@ -192,7 +199,7 @@
}
if (xupdateModifications != null) {
- log.error(".act(): MODIFICATIONS: " + xupdateModifications);
+ log.debug(".act(): MODIFICATIONS: " + xupdateModifications);
xq.setQString(xupdateModifications);
xq.execute(document);
} else {
@@ -212,10 +219,23 @@
serializer.asDOMSerializer().serialize((Document) document);
log.error(".act(): XUpdate Result: \n"+writer.toString());
*/
+
DocumentHelper.writeDocument(document, file);
+ if (schema.isFile()) {
+ String message = validateDocument(schema, file);
+ if (message != null) {
+ log.error("Validation failed: " + message);
+ HashMap hmap = new HashMap();
+ hmap.put("message", message);
+ return hmap;
+ }
+ } else {
+ log.warn("No such schema: " + schema.getAbsolutePath());
+ }
+
if(request.getParameter("save") != null) {
- getLogger().error(".act(): Save");
+ getLogger().info(".act(): Save");
return null;
} else {
return new HashMap();
@@ -253,10 +273,10 @@
if (attributes != null) {
for (int i = 0;i < attributes.getLength();i++) {
org.w3c.dom.Attr attribute = (org.w3c.dom.Attr)attributes.item(i);
- log.error(".getAttributes(): " + attribute.getName() + " " + attribute.getValue());
+ log.debug(".getAttributes(): " + attribute.getName() + " " + attribute.getValue());
if (!attribute.getName().equals("tagID")) {
String namespace = attribute.getNamespaceURI();
- log.error(".getAttributes(): Namespace: " + namespace);
+ log.debug(".getAttributes(): Namespace: " + namespace);
String namespaceAttribute = "";
if (namespace != null) {
namespaceAttribute = " namespace=\"" + namespace + "\"";
@@ -270,7 +290,7 @@
} else {
xupdateString = "";
}
- log.error(".getAttributes(): " + xupdateString);
+ log.debug(".getAttributes(): " + xupdateString);
return new XUpdateAttributes(xupdateString, tagID);
}
@@ -282,7 +302,7 @@
// FIXME: Lexus seems to have trouble with mixed content. As Workaround we insert-after new and remove original
Node nodeToCopy = selectionNodeList.item(0);
String namespace = nodeToCopy.getNamespaceURI();
- log.error(".update(): Update Node (namespace): " + namespace);
+ log.debug(".update(): Update Node (namespace): " + namespace);
String namespaceAttribute = "";
if (namespace != null) {
namespaceAttribute = " namespace=\"" + namespace + "\"";
@@ -290,11 +310,11 @@
// WARNING: getAttributes adds the attribute tagID with value "temp"
XUpdateAttributes xa = getAttributes(nodeToCopy);
String xupdateInsertAfter = "<xupdate:insert-after select=\"" + select + " \"><xupdate:element name=\"" + new XPath(select).getNameWithoutPredicates() + "\"" + namespaceAttribute + ">" + xa.xupdateAttrExpr + request.getParameter(pname) + "</xupdate:element></xupdate:insert-after>";
- log.error(".update(): Update Node (insert-after): " + xupdateInsertAfter);
+ log.debug(".update(): Update Node (insert-after): " + xupdateInsertAfter);
String xupdateRemove = "<xupdate:remove select=\"" + select + " \"/>";
- log.error(".update(): Update Node (remove): " + xupdateRemove);
+ log.debug(".update(): Update Node (remove): " + xupdateRemove);
String xupdateUpdateAttribute = "<xupdate:update select=\"" + new XPath(select).removePredicates(select) + "[@tagID='temp']/@tagID" + " \">" + xa.tagID + "</xupdate:update>";
- log.error(".update(): Update Node (update tagID attribute): " + xupdateUpdateAttribute);
+ log.debug(".update(): Update Node (update tagID attribute): " + xupdateUpdateAttribute);
return "<?xml version=\"1.0\"?><xupdate:modifications xmlns:xupdate=\"http://www.xmldb.org/xupdate\">" + xupdateInsertAfter + xupdateRemove + xupdateUpdateAttribute + "</xupdate:modifications>";
/*
@@ -315,7 +335,7 @@
* xupdate:append
*/
private String append(String pname) {
- log.error(".append() APPEND Node: " + pname);
+ log.debug(".append() APPEND Node: " + pname);
return "<?xml version=\"1.0\"?><xupdate:modifications xmlns:xupdate=\"http://www.xmldb.org/xupdate\">" + pname + "</xupdate:modifications>";
}
@@ -323,7 +343,7 @@
* xupdate:insert-before
*/
private String insertBefore(String pname) {
- log.error(".insertBefore() INSERT-BEFORE Node: " + pname);
+ log.debug(".insertBefore() INSERT-BEFORE Node: " + pname);
return "<?xml version=\"1.0\"?><xupdate:modifications xmlns:xupdate=\"http://www.xmldb.org/xupdate\">" + pname + "</xupdate:modifications>";
}
@@ -331,7 +351,7 @@
* xupdate:insert-after
*/
private String insertAfter(String pname) {
- log.error(".insertAfter() INSERT-AFTER Node: " + pname);
+ log.debug(".insertAfter() INSERT-AFTER Node: " + pname);
return "<?xml version=\"1.0\"?><xupdate:modifications xmlns:xupdate=\"http://www.xmldb.org/xupdate\">" + pname + "</xupdate:modifications>";
}
@@ -339,7 +359,14 @@
* xupdate:remove
*/
private String remove(String pname) {
- log.error(".remove() REMOVE Node: " + pname);
+ log.debug(".remove() REMOVE Node: " + pname);
return "<?xml version=\"1.0\"?><xupdate:modifications xmlns:xupdate=\"http://www.xmldb.org/xupdate\">" + pname + "</xupdate:modifications>";
+ }
+
+ /**
+ * Validate Document
+ */
+ private String validateDocument(File schema, File file) {
+ return null;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: lenya-cvs-unsubscribe@cocoon.apache.org
For additional commands, e-mail: lenya-cvs-help@cocoon.apache.org