You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2004/06/29 12:22:32 UTC
cvs commit: cocoon-lenya/src/java/org/apache/lenya/cms/cocoon/acting HTMLFormSaveAction.java
andreas 2004/06/29 03:22:31
Modified: src/java/org/apache/lenya/cms/cocoon/acting
HTMLFormSaveAction.java
Log:
- code formatting
- replaced log4j by Avalon logging
Revision Changes Path
1.50 +446 -549 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.49
retrieving revision 1.50
diff -u -r1.49 -r1.50
--- HTMLFormSaveAction.java 1 Jun 2004 17:36:00 -0000 1.49
+++ HTMLFormSaveAction.java 29 Jun 2004 10:22:31 -0000 1.50
@@ -58,612 +58,506 @@
import org.xmldb.xupdate.lexus.XUpdateQueryImpl;
/**
- * FIXME: org.apache.xpath.compiler.XPathParser seems to have problems when
- * namespaces are not declared within the root element. Unfortunately the XSLTs
- * (during Cocoon transformation) are moving the namespaces to the elements which use them!
- * One hack might be to parse the tree for namespaces (Node.getNamespaceURI), collect them
- * and add them to the document root element, before sending it through the
- * org.apache.xpath.compiler.XPathParser (called by XPathAPI)
- *
+ * FIXME: org.apache.xpath.compiler.XPathParser seems to have problems when
+ * namespaces are not declared within the root element. Unfortunately the XSLTs
+ * (during Cocoon transformation) are moving the namespaces to the elements
+ * which use them! One hack might be to parse the tree for namespaces
+ * (Node.getNamespaceURI), collect them and add them to the document root
+ * element, before sending it through the org.apache.xpath.compiler.XPathParser
+ * (called by XPathAPI)
+ *
* FIXME: There seems to be another problem with default namespaces
- *
- * WARNING: Internet Explorer sends X and Y coordinates for image buttons. These have to
- * be treated differently. Mozilla does not send these coordinates.
+ *
+ * WARNING: Internet Explorer sends X and Y coordinates for image buttons. These
+ * have to be treated differently. Mozilla does not send these coordinates.
*/
-public class HTMLFormSaveAction
- extends AbstractConfigurableAction
- implements ThreadSafe {
- Category log = Category.getInstance(HTMLFormSaveAction.class);
+public class HTMLFormSaveAction extends AbstractConfigurableAction implements ThreadSafe {
class XUpdateAttributes {
public String xupdateAttrExpr = "";
- public String tagID = "";
+ public String tagID = "";
- public XUpdateAttributes(String xupdateAttrExpr, String tagID) {
- this.xupdateAttrExpr = xupdateAttrExpr;
- this.tagID = tagID;
- }
-}
-
-/**
- * Save data to temporary file
- *
- * @param redirector a <code>Redirector</code> value
- * @param resolver a <code>SourceResolver</code> value
- * @param objectModel a <code>Map</code> value
- * @param source a <code>String</code> value
- * @param parameters a <code>Parameters</code> value
- *
- * @return a <code>Map</code> value
- *
- * @exception Exception if an error occurs
- */
-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
+ public XUpdateAttributes(String xupdateAttrExpr, String tagID) {
+ this.xupdateAttrExpr = xupdateAttrExpr;
+ this.tagID = tagID;
+ }
+ }
+
+ /**
+ * Save data to temporary file
+ *
+ * @param redirector a <code>Redirector</code> value
+ * @param resolver a <code>SourceResolver</code> value
+ * @param objectModel a <code>Map</code> value
+ * @param source a <code>String</code> value
+ * @param parameters a <code>Parameters</code> value
+ *
+ * @return a <code>Map</code> value
+ *
+ * @exception Exception if an error occurs
+ */
+ 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
+ File schema = new File(sitemap.getAbsolutePath() + File.separator
+ parameters.getParameter("schema"));
- File unnumberTagsXSL =
- new File(
- sitemap.getAbsolutePath()
- + File.separator
+ File unnumberTagsXSL = new File(sitemap.getAbsolutePath() + File.separator
+ parameters.getParameter("unnumberTagsXSL"));
- File numberTagsXSL =
- new File(
- sitemap.getAbsolutePath()
- + File.separator
+ File numberTagsXSL = new File(sitemap.getAbsolutePath() + File.separator
+ parameters.getParameter("numberTagsXSL"));
- Request request = ObjectModelHelper.getRequest(objectModel);
+ Request request = ObjectModelHelper.getRequest(objectModel);
- if (request.getParameter("cancel") != null) {
- log.warn(".act(): Editing has been canceled");
- file.delete();
- return null;
- } else {
- if (file.isFile()) {
- log.debug(
- ".act(): Save modifications to " + file.getAbsolutePath());
-
- try {
- Document document = null;
- DocumentBuilderFactory parserFactory =
- DocumentBuilderFactory.newInstance();
- parserFactory.setValidating(false);
- parserFactory.setNamespaceAware(true);
- parserFactory.setIgnoringElementContentWhitespace(true);
- DocumentBuilder builder =
- parserFactory.newDocumentBuilder();
- document = builder.parse(file.getAbsolutePath());
- System.setProperty(
- "org.xmldb.common.xml.queries.XPathQueryFactory",
- "org.xmldb.common.xml.queries.xalan2.XPathQueryFactoryImpl");
-
- XPathQuery xpath =
- XPathQueryFactory.newInstance().newXPathQuery();
- XUpdateQuery xq = new XUpdateQueryImpl();
-
- String editSelect = null;
- Enumeration params = request.getParameterNames();
- while (params.hasMoreElements()) {
- String pname = (String) params.nextElement();
- log.debug(
- "Parameter: "
- + pname
- + " ("
- + request.getParameter(pname)
- + ")");
-
- // Extract the xpath to edit
- if (editSelect == null
- && pname.indexOf("edit[") >= 0
- && pname.endsWith("].x")) {
- editSelect = pname.substring(5, pname.length() - 3);
- log.debug("Edit: " + editSelect);
- }
+ if (request.getParameter("cancel") != null) {
+ getLogger().warn(".act(): Editing has been canceled");
+ file.delete();
+ return null;
+ } else {
+ if (file.isFile()) {
+ getLogger().debug(".act(): Save modifications to " + file.getAbsolutePath());
- // Make sure we are dealing with an xupdate statement, else skip
- if (pname.indexOf("<xupdate:") == 0) {
- String select =
- pname.substring(pname.indexOf("select") + 8);
- select = select.substring(0, select.indexOf("\""));
- log.debug(".act() Select Node: " + select);
-
- // Check if node exists
- xpath.setQString(select);
- XObject result = xpath.execute(document);
- NodeList selectionNodeList = result.nodeset();
- if (selectionNodeList.getLength() == 0) {
- log.debug(
- ".act(): Node does not exist (might have been deleted during update): "
- + select);
- } else {
- String xupdateModifications = null;
- // now check for the different xupdate statements, and handle appropriately
- if (pname.indexOf("xupdate:update-parent") > 0) {
- log.debug("UPDATE PARENT Node: " + pname);
- // CDATA updates need to be handled seperately
- if (pname.indexOf("<![CDATA[") > 0) {
- xupdateModifications =
- updateCDATA(request, pname, true);
- } else {
- xupdateModifications =
- update(
- request,
- pname,
- select,
- selectionNodeList,
- true);
- }
- } else if (pname.indexOf("xupdate:update") > 0) {
- log.debug("UPDATE Node: " + pname);
- // CDATA updates need to be handled seperately
- if (pname.indexOf("<![CDATA[") > 0) {
- xupdateModifications =
- updateCDATA(request, pname, false);
- } else {
- xupdateModifications =
- update(
- request,
- pname,
- select,
- selectionNodeList,
- false);
- }
- } else if (
- pname.indexOf("xupdate:append") > 0
- && pname.endsWith(">.x")) {
- xupdateModifications =
- append(
- pname.substring(
- 0,
+ try {
+ Document document = null;
+ DocumentBuilderFactory parserFactory = DocumentBuilderFactory.newInstance();
+ parserFactory.setValidating(false);
+ parserFactory.setNamespaceAware(true);
+ parserFactory.setIgnoringElementContentWhitespace(true);
+ DocumentBuilder builder = parserFactory.newDocumentBuilder();
+ document = builder.parse(file.getAbsolutePath());
+ System.setProperty("org.xmldb.common.xml.queries.XPathQueryFactory",
+ "org.xmldb.common.xml.queries.xalan2.XPathQueryFactoryImpl");
+
+ XPathQuery xpath = XPathQueryFactory.newInstance().newXPathQuery();
+ XUpdateQuery xq = new XUpdateQueryImpl();
+
+ String editSelect = null;
+ Enumeration params = request.getParameterNames();
+ while (params.hasMoreElements()) {
+ String pname = (String) params.nextElement();
+ getLogger().debug("Parameter: " + pname + " ("
+ + request.getParameter(pname) + ")");
+
+ // Extract the xpath to edit
+ if (editSelect == null && pname.indexOf("edit[") >= 0
+ && pname.endsWith("].x")) {
+ editSelect = pname.substring(5, pname.length() - 3);
+ getLogger().debug("Edit: " + editSelect);
+ }
+
+ // Make sure we are dealing with an xupdate statement,
+ // else skip
+ if (pname.indexOf("<xupdate:") == 0) {
+ String select = pname.substring(pname.indexOf("select") + 8);
+ select = select.substring(0, select.indexOf("\""));
+ getLogger().debug(".act() Select Node: " + select);
+
+ // Check if node exists
+ xpath.setQString(select);
+ XObject result = xpath.execute(document);
+ NodeList selectionNodeList = result.nodeset();
+ if (selectionNodeList.getLength() == 0) {
+ getLogger()
+ .debug(".act(): Node does not exist (might have been deleted during update): "
+ + select);
+ } else {
+ String xupdateModifications = null;
+ // now check for the different xupdate
+ // statements, and handle appropriately
+ if (pname.indexOf("xupdate:update-parent") > 0) {
+ getLogger().debug("UPDATE PARENT Node: " + pname);
+ // CDATA updates need to be handled
+ // seperately
+ if (pname.indexOf("<![CDATA[") > 0) {
+ xupdateModifications = updateCDATA(request, pname, true);
+ } else {
+ xupdateModifications = update(request,
+ pname,
+ select,
+ selectionNodeList,
+ true);
+ }
+ } else if (pname.indexOf("xupdate:update") > 0) {
+ getLogger().debug("UPDATE Node: " + pname);
+ // CDATA updates need to be handled
+ // seperately
+ if (pname.indexOf("<![CDATA[") > 0) {
+ xupdateModifications = updateCDATA(request, pname, false);
+ } else {
+ xupdateModifications = update(request,
+ pname,
+ select,
+ selectionNodeList,
+ false);
+ }
+ } else if (pname.indexOf("xupdate:append") > 0
+ && pname.endsWith(">.x")) {
+ xupdateModifications = append(pname.substring(0,
pname.length() - 2));
- // insert-before: in case of select/option
- } else if (
- pname.indexOf("xupdate:insert-before") > 0
- && pname.endsWith("/>")) {
- if (!request
- .getParameter(pname)
- .equals("null")) {
- xupdateModifications =
- insertBefore(
- request.getParameter(pname));
- }
- // insert-before: in case of image
- } else if (
- pname.indexOf("xupdate:insert-before") > 0
- && pname.endsWith(">.x")) {
- xupdateModifications =
- insertBefore(
- pname.substring(
- 0,
+ // insert-before: in case of select/option
+ } else if (pname.indexOf("xupdate:insert-before") > 0
+ && pname.endsWith("/>")) {
+ if (!request.getParameter(pname).equals("null")) {
+ xupdateModifications = insertBefore(request
+ .getParameter(pname));
+ }
+ // insert-before: in case of image
+ } else if (pname.indexOf("xupdate:insert-before") > 0
+ && pname.endsWith(">.x")) {
+ xupdateModifications = insertBefore(pname.substring(0, pname
+ .length() - 2));
+ // insert-after: in case of select/option
+ } else if (pname.indexOf("xupdate:insert-after") > 0
+ && pname.endsWith("/>")) {
+ if (!request.getParameter(pname).equals("null")) {
+ xupdateModifications = insertAfter(request
+ .getParameter(pname));
+ }
+ // insert-after: in case of image
+ } else if (pname.indexOf("xupdate:insert-after") > 0
+ && pname.endsWith(">.x")) {
+ xupdateModifications = insertAfter(pname.substring(0, pname
+ .length() - 2));
+ } else if (pname.indexOf("xupdate:remove") > 0
+ && pname.endsWith("/>.x")) {
+ xupdateModifications = remove(pname.substring(0,
pname.length() - 2));
- // insert-after: in case of select/option
- } else if (
- pname.indexOf("xupdate:insert-after") > 0
- && pname.endsWith("/>")) {
- if (!request
- .getParameter(pname)
- .equals("null")) {
- xupdateModifications =
- insertAfter(
- request.getParameter(pname));
+ } else if (pname.endsWith(">.y")) {
+ getLogger().debug("Don't handle this: " + pname);
+ } else {
+ getLogger().debug("Don't handle this either: " + pname);
}
- // insert-after: in case of image
- } else if (
- pname.indexOf("xupdate:insert-after") > 0
- && pname.endsWith(">.x")) {
- xupdateModifications =
- insertAfter(
- pname.substring(
- 0,
- pname.length() - 2));
- } else if (
- pname.indexOf("xupdate:remove") > 0
- && pname.endsWith("/>.x")) {
- xupdateModifications =
- remove(
- pname.substring(
- 0,
- pname.length() - 2));
- } else if (pname.endsWith(">.y")) {
- log.debug("Don't handle this: " + pname);
- } else {
- log.debug("Don't handle this either: " + pname);
- }
- // Get hidden namespaces
- String namespaces = request.getParameter("namespaces");
+ // Get hidden namespaces
+ String namespaces = request.getParameter("namespaces");
- // Add XML declaration
- // NOTE: select/option is generating parameter which should be considered as null
- if (xupdateModifications != null) {
- xupdateModifications = "<?xml version=\"1.0\"?>" + addHiddenNamespaces(namespaces, xupdateModifications);
- }
+ // Add XML declaration
+ // NOTE: select/option is generating parameter
+ // which should be considered as null
+ if (xupdateModifications != null) {
+ xupdateModifications = "<?xml version=\"1.0\"?>"
+ + addHiddenNamespaces(namespaces, xupdateModifications);
+ }
- // now run the assembled xupdate query
- if (xupdateModifications != null) {
- log.info("Execute XUpdate Modifications: " + xupdateModifications);
- xq.setQString(xupdateModifications);
- xq.execute(document);
- } else {
- log.debug("Parameter did not match any xupdate command: " + pname);
+ // now run the assembled xupdate query
+ if (xupdateModifications != null) {
+ getLogger().info("Execute XUpdate Modifications: "
+ + xupdateModifications);
+ xq.setQString(xupdateModifications);
+ xq.execute(document);
+ } else {
+ getLogger()
+ .debug("Parameter did not match any xupdate command: "
+ + pname);
+ }
}
}
}
- }
- // Uncomment this for debugging
- /*
- java.io.StringWriter writer = new java.io.StringWriter();
- org.apache.xml.serialize.OutputFormat OutFormat = new org.apache.xml.serialize.OutputFormat("xml", "UTF-8", true);
- org.apache.xml.serialize.XMLSerializer serializer = new org.apache.xml.serialize.XMLSerializer(writer, OutFormat);
- serializer.asDOMSerializer().serialize((Document) document);
- log.error(".act(): XUpdate Result: \n"+writer.toString());
- */
-
-
- // validate against relax ng after the updates
- if (schema.isFile()) {
- DocumentHelper.writeDocument(document, new File(file.getCanonicalPath() + ".validate"));
- String message =
- validateDocument(schema, new File(file.getCanonicalPath() + ".validate"), unnumberTagsXSL);
- if (message != null) {
- log.error("RELAX NG Validation failed: " + message);
+ // Uncomment this for debugging
+ /*
+ * java.io.StringWriter writer = new java.io.StringWriter();
+ * org.apache.xml.serialize.OutputFormat OutFormat = new
+ * org.apache.xml.serialize.OutputFormat("xml", "UTF-8",
+ * true); org.apache.xml.serialize.XMLSerializer serializer =
+ * new org.apache.xml.serialize.XMLSerializer(writer,
+ * OutFormat);
+ * serializer.asDOMSerializer().serialize((Document)
+ * document); log.error(".act(): XUpdate Result:
+ * \n"+writer.toString());
+ */
+
+ // validate against relax ng after the updates
+ if (schema.isFile()) {
+ DocumentHelper.writeDocument(document, new File(file.getCanonicalPath()
+ + ".validate"));
+ String message = validateDocument(schema, new File(file.getCanonicalPath()
+ + ".validate"), unnumberTagsXSL);
+ if (message != null) {
+ getLogger().error("RELAX NG Validation failed: " + message);
+ HashMap hmap = new HashMap();
+ hmap.put("message", "RELAX NG Validation failed: " + message);
+ return hmap;
+ }
+ } else {
+ getLogger().warn("No such schema: " + schema.getAbsolutePath());
+ }
+
+ Document renumberedDocument = renumberDocument(document,
+ unnumberTagsXSL,
+ numberTagsXSL);
+ DocumentHelper.writeDocument(renumberedDocument, file);
+
+ // check to see if we save and exit
+ if (request.getParameter("save") != null) {
+ getLogger().info(".act(): Save");
+ return null;
+ } else {
+ /*
+ * We don't exit
+ */
HashMap hmap = new HashMap();
- hmap.put(
- "message",
- "RELAX NG Validation failed: " + message);
+ if (editSelect != null) {
+ hmap.put("editSelect", editSelect);
+ }
return hmap;
}
- } else {
- log.warn("No such schema: " + schema.getAbsolutePath());
- }
-
- Document renumberedDocument = renumberDocument(document, unnumberTagsXSL, numberTagsXSL);
- DocumentHelper.writeDocument(renumberedDocument, file);
-
- // check to see if we save and exit
- if (request.getParameter("save") != null) {
- log.info(".act(): Save");
- return null;
- } else {
- /* We don't exit
- */
+ } catch (NullPointerException e) {
+ getLogger().error("NullPointerException", e);
HashMap hmap = new HashMap();
- if (editSelect != null) {
- hmap.put("editSelect", editSelect);
+ hmap.put("message", "NullPointerException");
+ return hmap;
+ } catch (Exception e) {
+ getLogger().error("Exception: " + e.getMessage(), e);
+ HashMap hmap = new HashMap();
+ if (e.getMessage() != null) {
+ hmap.put("message", e.getMessage());
+ } else {
+ hmap.put("message", "No message (" + e.getClass().getName() + ")");
}
return hmap;
}
- } catch (NullPointerException e) {
- log.error("NullPointerException", e);
- HashMap hmap = new HashMap();
- hmap.put("message", "NullPointerException");
- return hmap;
- } catch (Exception e) {
- log.error( "Exception: " + e.getMessage(), e);
+ } else {
+ getLogger().error("No such file: " + file.getAbsolutePath());
HashMap hmap = new HashMap();
- if (e.getMessage() != null) {
- hmap.put("message", e.getMessage());
- } else {
- hmap.put(
- "message",
- "No message (" + e.getClass().getName() + ")");
- }
+ hmap.put("message", "No such file: " + file.getAbsolutePath());
return hmap;
}
- } else {
- log.error("No such file: " + file.getAbsolutePath());
- HashMap hmap = new HashMap();
- hmap.put("message", "No such file: " + file.getAbsolutePath());
- return hmap;
}
}
-}
-/**
- * Get attributes from original node
- *
- * @param node Original node
- */
-private XUpdateAttributes getAttributes(Node node) {
+ /**
+ * Get attributes from original node
+ *
+ * @param node Original node
+ */
+ private XUpdateAttributes getAttributes(Node node) {
- String xupdateString = "";
- String tagID = "";
- org.w3c.dom.NamedNodeMap attributes = node.getAttributes();
- if (attributes != null) {
- for (int i = 0; i < attributes.getLength(); i++) {
- org.w3c.dom.Attr attribute =
- (org.w3c.dom.Attr) attributes.item(i);
- log.debug(
- ".getAttributes(): "
- + attribute.getName()
- + " "
- + attribute.getValue());
- if (!attribute.getName().equals("tagID")) {
- String namespace = attribute.getNamespaceURI();
- log.debug(".getAttributes(): Namespace: " + namespace);
- String namespaceAttribute = "";
- if (namespace != null) {
- namespaceAttribute = " namespace=\"" + namespace + "\"";
+ String xupdateString = "";
+ String tagID = "";
+ org.w3c.dom.NamedNodeMap attributes = node.getAttributes();
+ if (attributes != null) {
+ for (int i = 0; i < attributes.getLength(); i++) {
+ org.w3c.dom.Attr attribute = (org.w3c.dom.Attr) attributes.item(i);
+ getLogger().debug(".getAttributes(): " + attribute.getName() + " "
+ + attribute.getValue());
+ if (!attribute.getName().equals("tagID")) {
+ String namespace = attribute.getNamespaceURI();
+ getLogger().debug(".getAttributes(): Namespace: " + namespace);
+ String namespaceAttribute = "";
+ if (namespace != null) {
+ namespaceAttribute = " namespace=\"" + namespace + "\"";
+ }
+ xupdateString = xupdateString + "<xupdate:attribute name=\""
+ + attribute.getName() + "\"" + namespaceAttribute + ">"
+ + attribute.getValue() + "</xupdate:attribute>";
+ } else {
+ xupdateString = xupdateString
+ + "<xupdate:attribute name=\"tagID\">temp</xupdate:attribute>";
+ tagID = attribute.getValue();
}
- xupdateString =
- xupdateString
- + "<xupdate:attribute name=\""
- + attribute.getName()
- + "\""
- + namespaceAttribute
- + ">"
- + attribute.getValue()
- + "</xupdate:attribute>";
- } else {
- xupdateString =
- xupdateString
- + "<xupdate:attribute name=\"tagID\">temp</xupdate:attribute>";
- tagID = attribute.getValue();
}
+ } else {
+ xupdateString = "";
}
- } else {
- xupdateString = "";
- }
- log.debug("Attributes: " + xupdateString);
+ getLogger().debug("Attributes: " + xupdateString);
- return new XUpdateAttributes(xupdateString, tagID);
-}
+ return new XUpdateAttributes(xupdateString, tagID);
+ }
-/**
- * Get attributes from actual update
- *
- * @param update The actual update
- */
-private XUpdateAttributes getAttributes(String update, String tagID) {
- log.debug(update);
+ /**
+ * Get attributes from actual update
+ *
+ * @param update The actual update
+ */
+ private XUpdateAttributes getAttributes(String update, String tagID) {
+ getLogger().debug(update);
- String xupdateString = "<xupdate:attribute name=\"tagID\">temp</xupdate:attribute>";
+ String xupdateString = "<xupdate:attribute name=\"tagID\">temp</xupdate:attribute>";
- String[] attributes = update.substring(0, update.indexOf(">")).split(" ");
- for (int i = 1; i < attributes.length; i++) {
- // TODO: beware of white spaces
- int index = attributes[i].indexOf("=");
- if (index > 0) {
- String name = attributes[i].substring(0, index);
- String value = attributes[i].substring(index + 2, attributes[i].length() - 1);
- if (name.indexOf("xmlns") < 0) {
- xupdateString = xupdateString + "<xupdate:attribute name=\"" + name + "\">" + value + "</xupdate:attribute>";
+ String[] attributes = update.substring(0, update.indexOf(">")).split(" ");
+ for (int i = 1; i < attributes.length; i++) {
+ // TODO: beware of white spaces
+ int index = attributes[i].indexOf("=");
+ if (index > 0) {
+ String name = attributes[i].substring(0, index);
+ String value = attributes[i].substring(index + 2, attributes[i].length() - 1);
+ if (name.indexOf("xmlns") < 0) {
+ xupdateString = xupdateString + "<xupdate:attribute name=\"" + name + "\">"
+ + value + "</xupdate:attribute>";
+ }
}
}
+
+ getLogger().debug("Attributes: " + xupdateString);
+
+ return new XUpdateAttributes(xupdateString, tagID);
}
- log.debug("Attributes: " + xupdateString);
+ /**
+ * xupdate:update
+ *
+ * @param parent If true then parent element is part of update and
+ * attributes need to be updated resp. added or deleted
+ */
+ private String update(Request request, String pname, String select, NodeList selectionNodeList,
+ boolean parent) {
+ getLogger().debug("Update node: " + select);
+
+ Node nodeToCopy = selectionNodeList.item(0);
+ // deal with attribute values here..
+ if (nodeToCopy.getNodeType() == Node.ATTRIBUTE_NODE) {
+ getLogger().debug("Update attribute: " + select);
+
+ String xupdateUpdate = pname + request.getParameter(pname) + "</xupdate:update>";
+ return "<xupdate:modifications xmlns:xupdate=\"http://www.xmldb.org/xupdate\">"
+ + xupdateUpdate + "</xupdate:modifications>";
+ /*
+ * And deal with mixed content here.. NOTE: Lexus has trouble with
+ * mixed content. As Workaround we insert-after the new node, remove
+ * the original node and replace the temporary tagID by the original
+ * tagID.
+ */
+ } else {
+ getLogger().debug("Update element: " + select);
- return new XUpdateAttributes(xupdateString, tagID);
-}
+ String namespace = nodeToCopy.getNamespaceURI();
+ String namespaceAttribute = "";
+ if (namespace != null) {
+ namespaceAttribute = " namespace=\"" + namespace + "\"";
+ }
+ // NOTE: getAttributes adds the attribute tagID with value "temp",
+ // which will be replaced further down
+ XUpdateAttributes xa = getAttributes(nodeToCopy);
+ String xupdateInsertAfter = null;
+ if (parent) {
+ xa = getAttributes(request.getParameter(pname), xa.tagID);
+ xupdateInsertAfter = "<xupdate:insert-after select=\"" + select
+ + " \"><xupdate:element name=\""
+ + new XPath(select).getNameWithoutPredicates() + "\"" + namespaceAttribute
+ + ">" + xa.xupdateAttrExpr + removeParent(request.getParameter(pname))
+ + "</xupdate:element></xupdate:insert-after>";
+ } else {
+ xupdateInsertAfter = "<xupdate:insert-after select=\"" + select
+ + " \"><xupdate:element name=\""
+ + new XPath(select).getNameWithoutPredicates() + "\"" + namespaceAttribute
+ + ">" + xa.xupdateAttrExpr + request.getParameter(pname)
+ + "</xupdate:element></xupdate:insert-after>";
+ }
+ getLogger().debug(".update(): Update Node (insert-after): " + xupdateInsertAfter);
-/**
- * xupdate:update
- *
- * @param parent If true then parent element is part of update and attributes need to be updated resp. added or deleted
- */
-private String update(
- Request request,
- String pname,
- String select,
- NodeList selectionNodeList,
- boolean parent) {
- log.debug("Update node: " + select);
-
- Node nodeToCopy = selectionNodeList.item(0);
- // deal with attribute values here..
- if (nodeToCopy.getNodeType() == Node.ATTRIBUTE_NODE) {
- log.debug("Update attribute: " + select);
+ String xupdateRemove = "<xupdate:remove select=\"" + select + " \"/>";
+ getLogger().debug(".update(): Update Node (remove): " + xupdateRemove);
- String xupdateUpdate =
- pname + request.getParameter(pname) + "</xupdate:update>";
- return "<xupdate:modifications xmlns:xupdate=\"http://www.xmldb.org/xupdate\">"
- + xupdateUpdate
- + "</xupdate:modifications>";
- /* And deal with mixed content here..
- * NOTE: Lexus has trouble with mixed content. As Workaround we
- * insert-after the new node, remove the original node and replace the
- * temporary tagID by the original tagID.
- */
- } else {
- log.debug("Update element: " + select);
-
- String namespace = nodeToCopy.getNamespaceURI();
- String namespaceAttribute = "";
- if (namespace != null) {
- namespaceAttribute = " namespace=\"" + namespace + "\"";
- }
- // NOTE: getAttributes adds the attribute tagID with value "temp", which will be replaced further down
- XUpdateAttributes xa = getAttributes(nodeToCopy);
- String xupdateInsertAfter = null;
- if (parent) {
- xa = getAttributes(request.getParameter(pname), xa.tagID);
- xupdateInsertAfter =
- "<xupdate:insert-after select=\""
- + select
- + " \"><xupdate:element name=\""
- + new XPath(select).getNameWithoutPredicates()
- + "\""
- + namespaceAttribute
- + ">"
- + xa.xupdateAttrExpr
- + removeParent(request.getParameter(pname))
- + "</xupdate:element></xupdate:insert-after>";
- } else {
- xupdateInsertAfter =
- "<xupdate:insert-after select=\""
- + select
- + " \"><xupdate:element name=\""
- + new XPath(select).getNameWithoutPredicates()
- + "\""
- + namespaceAttribute
- + ">"
- + xa.xupdateAttrExpr
- + request.getParameter(pname)
- + "</xupdate:element></xupdate:insert-after>";
+ String xupdateUpdateAttribute = "<xupdate:update select=\""
+ + new XPath(select).removePredicates(select) + "[@tagID='temp']/@tagID"
+ + " \">" + xa.tagID + "</xupdate:update>";
+ getLogger().debug(".update(): Update Node (update tagID attribute): "
+ + xupdateUpdateAttribute);
+
+ return "<xupdate:modifications xmlns:xupdate=\"http://www.xmldb.org/xupdate\">"
+ + xupdateInsertAfter + xupdateRemove + xupdateUpdateAttribute
+ + "</xupdate:modifications>";
}
- log.debug(
- ".update(): Update Node (insert-after): " + xupdateInsertAfter);
-
- String xupdateRemove =
- "<xupdate:remove select=\"" + select + " \"/>";
- 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.debug(
- ".update(): Update Node (update tagID attribute): "
- + xupdateUpdateAttribute);
+ }
+ /**
+ * xupdate:update CDATA
+ *
+ * @param parent if true then attributes of parent will also be updated
+ */
+ private String updateCDATA(Request request, String pname, boolean parent) {
+ String xupdateUpdate = pname + request.getParameter(pname) + "]]></xupdate:update>";
return "<xupdate:modifications xmlns:xupdate=\"http://www.xmldb.org/xupdate\">"
- + xupdateInsertAfter
- + xupdateRemove
- + xupdateUpdateAttribute
- + "</xupdate:modifications>";
- }
-}
-
-/**
- * xupdate:update CDATA
- *
- * @param parent if true then attributes of parent will also be updated
- */
-private String updateCDATA(Request request, String pname, boolean parent) {
- String xupdateUpdate =
- pname + request.getParameter(pname) + "]]></xupdate:update>";
- return "<xupdate:modifications xmlns:xupdate=\"http://www.xmldb.org/xupdate\">"
- + xupdateUpdate
- + "</xupdate:modifications>";
-}
+ + xupdateUpdate + "</xupdate:modifications>";
+ }
-/**
- * xupdate:append
- */
-private String append(String pname) {
- log.debug(".append() APPEND Node: " + pname);
- return "<xupdate:modifications xmlns:xupdate=\"http://www.xmldb.org/xupdate\">"
- + pname
- + "</xupdate:modifications>";
-}
+ /**
+ * xupdate:append
+ */
+ private String append(String pname) {
+ getLogger().debug(".append() APPEND Node: " + pname);
+ return "<xupdate:modifications xmlns:xupdate=\"http://www.xmldb.org/xupdate\">" + pname
+ + "</xupdate:modifications>";
+ }
-/**
- * xupdate:insert-before
- */
-private String insertBefore(String pname) {
- log.debug(".insertBefore() INSERT-BEFORE Node: " + pname);
- return "<xupdate:modifications xmlns:xupdate=\"http://www.xmldb.org/xupdate\">"
- + pname
- + "</xupdate:modifications>";
-}
+ /**
+ * xupdate:insert-before
+ */
+ private String insertBefore(String pname) {
+ getLogger().debug(".insertBefore() INSERT-BEFORE Node: " + pname);
+ return "<xupdate:modifications xmlns:xupdate=\"http://www.xmldb.org/xupdate\">" + pname
+ + "</xupdate:modifications>";
+ }
-/**
- * xupdate:insert-after
- */
-private String insertAfter(String pname) {
- log.debug(".insertAfter() INSERT-AFTER Node: " + pname);
- return "<xupdate:modifications xmlns:xupdate=\"http://www.xmldb.org/xupdate\">"
- + pname
- + "</xupdate:modifications>";
-}
+ /**
+ * xupdate:insert-after
+ */
+ private String insertAfter(String pname) {
+ getLogger().debug(".insertAfter() INSERT-AFTER Node: " + pname);
+ return "<xupdate:modifications xmlns:xupdate=\"http://www.xmldb.org/xupdate\">" + pname
+ + "</xupdate:modifications>";
+ }
-/**
- * xupdate:remove
- */
-private String remove(String pname) {
- log.debug(".remove() REMOVE Node: " + pname);
- return "<xupdate:modifications xmlns:xupdate=\"http://www.xmldb.org/xupdate\">"
- + pname
- + "</xupdate:modifications>";
-}
+ /**
+ * xupdate:remove
+ */
+ private String remove(String pname) {
+ getLogger().debug(".remove() REMOVE Node: " + pname);
+ return "<xupdate:modifications xmlns:xupdate=\"http://www.xmldb.org/xupdate\">" + pname
+ + "</xupdate:modifications>";
+ }
-/**
- * Validate document
- */
-private String validateDocument(
- File schema,
- File file,
- File unnumberTagsXSL) {
- try {
- // Remove tagIDs
- TransformerFactory tf = TransformerFactory.newInstance();
- Transformer t =
- tf.newTransformer(new StreamSource(unnumberTagsXSL));
- t.transform(
- new StreamSource(file),
- new StreamResult(
- new File(file.getAbsolutePath() + ".unnumber")));
-
- // Validate
- return RelaxNG.validate(
- schema,
- new File(file.getAbsolutePath() + ".unnumber"));
- } catch (Exception e) {
- log.error(e);
- return "" + e;
+ /**
+ * Validate document
+ */
+ private String validateDocument(File schema, File file, File unnumberTagsXSL) {
+ try {
+ // Remove tagIDs
+ TransformerFactory tf = TransformerFactory.newInstance();
+ Transformer t = tf.newTransformer(new StreamSource(unnumberTagsXSL));
+ t.transform(new StreamSource(file), new StreamResult(new File(file.getAbsolutePath()
+ + ".unnumber")));
+
+ // Validate
+ return RelaxNG.validate(schema, new File(file.getAbsolutePath() + ".unnumber"));
+ } catch (Exception e) {
+ getLogger().error("Validating failed:", e);
+ return "" + e;
}
}
-/**
- * Renumber document
- */
-private Document renumberDocument(
- Document doc,
- File unnumberTagsXSL,
- File numberTagsXSL) {
-
- try {
- DocumentBuilderFactory parserFactory = DocumentBuilderFactory.newInstance();
- parserFactory.setValidating(false);
- parserFactory.setNamespaceAware(true);
- parserFactory.setIgnoringElementContentWhitespace(true);
- DocumentBuilder builder = parserFactory.newDocumentBuilder();
-
- TransformerFactory tf = TransformerFactory.newInstance();
-
- // Remove tagIDs
- Transformer ut =
- tf.newTransformer(new StreamSource(unnumberTagsXSL));
- Document unnumberedDocument = builder.newDocument();
- ut.transform(
- new DOMSource(doc),
- new DOMResult(unnumberedDocument));
-
- // Add tagIDs
- Transformer nt =
- tf.newTransformer(new StreamSource(numberTagsXSL));
- Document renumberedDocument = builder.newDocument();
- nt.transform(
- new DOMSource(unnumberedDocument),
- new DOMResult(renumberedDocument));
-
- return renumberedDocument;
- } catch (Exception e) {
- log.error("" + e);
- }
+ /**
+ * Renumber document
+ */
+ private Document renumberDocument(Document doc, File unnumberTagsXSL, File numberTagsXSL) {
- return null;
+ try {
+ DocumentBuilderFactory parserFactory = DocumentBuilderFactory.newInstance();
+ parserFactory.setValidating(false);
+ parserFactory.setNamespaceAware(true);
+ parserFactory.setIgnoringElementContentWhitespace(true);
+ DocumentBuilder builder = parserFactory.newDocumentBuilder();
+
+ TransformerFactory tf = TransformerFactory.newInstance();
+
+ // Remove tagIDs
+ Transformer ut = tf.newTransformer(new StreamSource(unnumberTagsXSL));
+ Document unnumberedDocument = builder.newDocument();
+ ut.transform(new DOMSource(doc), new DOMResult(unnumberedDocument));
+
+ // Add tagIDs
+ Transformer nt = tf.newTransformer(new StreamSource(numberTagsXSL));
+ Document renumberedDocument = builder.newDocument();
+ nt.transform(new DOMSource(unnumberedDocument), new DOMResult(renumberedDocument));
+
+ return renumberedDocument;
+ } catch (Exception e) {
+ getLogger().error("" + e);
+ }
+
+ return null;
}
/**
@@ -671,9 +565,11 @@
*/
private String removeParent(String xmlSnippet) {
String xmlSnippetWithoutParent = xmlSnippet;
- xmlSnippetWithoutParent = xmlSnippetWithoutParent.substring(xmlSnippetWithoutParent.indexOf(">") + 1);
+ xmlSnippetWithoutParent = xmlSnippetWithoutParent.substring(xmlSnippetWithoutParent
+ .indexOf(">") + 1);
xmlSnippetWithoutParent = StringUtils.reverse(xmlSnippetWithoutParent);
- xmlSnippetWithoutParent = xmlSnippetWithoutParent.substring(xmlSnippetWithoutParent.indexOf("<") + 1);
+ xmlSnippetWithoutParent = xmlSnippetWithoutParent.substring(xmlSnippetWithoutParent
+ .indexOf("<") + 1);
xmlSnippetWithoutParent = StringUtils.reverse(xmlSnippetWithoutParent);
return xmlSnippetWithoutParent;
}
@@ -682,10 +578,10 @@
* Add namespaces to xupdate
*/
private String addHiddenNamespaces(String namespaces, String xupdateModifications) {
- log.debug("Namespaces: " + namespaces);
+ getLogger().debug("Namespaces: " + namespaces);
- if (namespaces == null) {
- log.debug("No additional namespaces");
+ if (namespaces == null) {
+ getLogger().debug("No additional namespaces");
return xupdateModifications;
}
@@ -695,11 +591,12 @@
if ((ns.indexOf(namespace[i]) < 0) && (xupdateModifications.indexOf(namespace[i]) < 0)) {
ns = ns + " " + namespace[i];
} else {
- log.debug("Redundant namespace: " + namespace[i]);
+ getLogger().debug("Redundant namespace: " + namespace[i]);
}
}
int endOfFirstNode = xupdateModifications.indexOf(">");
- return xupdateModifications.substring(0, endOfFirstNode) + " " + ns + xupdateModifications.substring(endOfFirstNode);
+ return xupdateModifications.substring(0, endOfFirstNode) + " " + ns
+ + xupdateModifications.substring(endOfFirstNode);
}
-}
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: lenya-cvs-unsubscribe@cocoon.apache.org
For additional commands, e-mail: lenya-cvs-help@cocoon.apache.org
Re: Avalon Logging: Re: cvs commit: cocoon-lenya/src/java/org/apache/lenya/cms/cocoon/acting
HTMLFormSaveAction.java
Posted by Andreas Hartmann <an...@apache.org>.
Michael Wechner wrote:
> Andreas Hartmann wrote:
>
>> Michael Wechner wrote:
>>
>>> Is the Avalon logging the API which hides log4j and logkit?
>>
>>
>>
>> There various implementations for the Avalon Logger interface,
>> for instance LogKitLogger, Log4jLogger, JDK14Logger.
>
>
>
> where are they being configured?
Actually I have no idea.
Maybe you have to ask on the cocoon-dev list.
-- Andreas
---------------------------------------------------------------------
To unsubscribe, e-mail: lenya-dev-unsubscribe@cocoon.apache.org
For additional commands, e-mail: lenya-dev-help@cocoon.apache.org
Re: Avalon Logging: Re: cvs commit: cocoon-lenya/src/java/org/apache/lenya/cms/cocoon/acting
HTMLFormSaveAction.java
Posted by Michael Wechner <mi...@wyona.com>.
Andreas Hartmann wrote:
> Michael Wechner wrote:
>
>> Is the Avalon logging the API which hides log4j and logkit?
>
>
> There various implementations for the Avalon Logger interface,
> for instance LogKitLogger, Log4jLogger, JDK14Logger.
where are they being configured?
Thanks
Michi
>
>
> -- Andreas
>
>> andreas@apache.org wrote:
>>
>>> andreas 2004/06/29 03:22:31
>>>
>>> Modified: src/java/org/apache/lenya/cms/cocoon/acting
>>> HTMLFormSaveAction.java
>>> Log:
>>> - code formatting
>>> - replaced log4j by Avalon logging
>>>
>>> Revision Changes Path
>>> 1.50 +446 -549
>>> cocoon-lenya/src/java/org/apache/lenya/cms/cocoon/acting/HTMLFormSaveAction.java
>>>
>>>
>>> Index: HTMLFormSaveAction.java
>>> ===================================================================
>>>
>>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: lenya-dev-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: lenya-dev-help@cocoon.apache.org
>
>
--
Michael Wechner
Wyona Inc. - Open Source Content Management - Apache Lenya
http://www.wyona.com http://cocoon.apache.org/lenya/
michael.wechner@wyona.com michi@apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: lenya-dev-unsubscribe@cocoon.apache.org
For additional commands, e-mail: lenya-dev-help@cocoon.apache.org
Re: Avalon Logging: Re: cvs commit: cocoon-lenya/src/java/org/apache/lenya/cms/cocoon/acting
HTMLFormSaveAction.java
Posted by Andreas Hartmann <an...@apache.org>.
Michael Wechner wrote:
> Is the Avalon logging the API which hides log4j and logkit?
There various implementations for the Avalon Logger interface,
for instance LogKitLogger, Log4jLogger, JDK14Logger.
-- Andreas
> andreas@apache.org wrote:
>
>> andreas 2004/06/29 03:22:31
>>
>> Modified: src/java/org/apache/lenya/cms/cocoon/acting
>> HTMLFormSaveAction.java
>> Log:
>> - code formatting
>> - replaced log4j by Avalon logging
>>
>> Revision Changes Path
>> 1.50 +446 -549
>> cocoon-lenya/src/java/org/apache/lenya/cms/cocoon/acting/HTMLFormSaveAction.java
>>
>>
>> Index: HTMLFormSaveAction.java
>> ===================================================================
>>
>>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: lenya-dev-unsubscribe@cocoon.apache.org
For additional commands, e-mail: lenya-dev-help@cocoon.apache.org
Avalon Logging: Re: cvs commit: cocoon-lenya/src/java/org/apache/lenya/cms/cocoon/acting
HTMLFormSaveAction.java
Posted by Michael Wechner <mi...@wyona.com>.
Is the Avalon logging the API which hides log4j and logkit?
andreas@apache.org wrote:
>andreas 2004/06/29 03:22:31
>
> Modified: src/java/org/apache/lenya/cms/cocoon/acting
> HTMLFormSaveAction.java
> Log:
> - code formatting
> - replaced log4j by Avalon logging
>
> Revision Changes Path
> 1.50 +446 -549 cocoon-lenya/src/java/org/apache/lenya/cms/cocoon/acting/HTMLFormSaveAction.java
>
> Index: HTMLFormSaveAction.java
> ===================================================================
>
>
--
Michael Wechner
Wyona Inc. - Open Source Content Management - Apache Lenya
http://www.wyona.com http://cocoon.apache.org/lenya/
michael.wechner@wyona.com michi@apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: lenya-dev-unsubscribe@cocoon.apache.org
For additional commands, e-mail: lenya-dev-help@cocoon.apache.org