[16895] MAGNOLIA-2272 Ability to choose a custom save handler per control/field
ul, #logmsg > ol { margin-left: 0; margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
-->
- Revision
- 16895
- Author
- fgiust
- Date
- 2008-07-17 21:06:25 +0200 (Thu, 17 Jul 2008)
Log Message
MAGNOLIA-2272 Ability to choose a custom save handler per control/field
Modified Paths
Added Paths
Diff
Added: magnolia/trunk/magnolia-module-admininterface/src/main/java/info/magnolia/module/admininterface/CustomSaveHandler.java (0 => 16895)
--- magnolia/trunk/magnolia-module-admininterface/src/main/java/info/magnolia/module/admininterface/CustomSaveHandler.java (rev 0)
+++ magnolia/trunk/magnolia-module-admininterface/src/main/java/info/magnolia/module/admininterface/CustomSaveHandler.java 2008-07-17 19:06:25 UTC (rev 16895)
@@ -0,0 +1,64 @@
+/**
+ * This file Copyright (c) 2003-2008 Magnolia International
+ * Ltd. (http://www.magnolia.info). All rights reserved.
+ *
+ *
+ * This file is dual-licensed under both the Magnolia
+ * Network Agreement and the GNU General Public License.
+ * You may elect to use one or the other of these licenses.
+ *
+ * This file is distributed in the hope that it will be
+ * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
+ * implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
+ * Redistribution, except as permitted by whichever of the GPL
+ * or MNA you select, is prohibited.
+ *
+ * 1. For the GPL license (GPL), you can redistribute and/or
+ * modify this file under the terms of the GNU General
+ * Public License, Version 3, as published by the Free Software
+ * Foundation. You should have received a copy of the GNU
+ * General Public License, Version 3 along with this program;
+ * if not, write to the Free Software Foundation, Inc., 51
+ * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * 2. For the Magnolia Network Agreement (MNA), this file
+ * and the accompanying materials are made available under the
+ * terms of the MNA which accompanies this distribution, and
+ * is available at http://www.magnolia.info/mna.html
+ *
+ * Any modifications to this file must keep this entire header
+ * intact.
+ *
+ */
+package info.magnolia.module.admininterface;
+
+import info.magnolia.cms.beans.runtime.MultipartForm;
+import info.magnolia.cms.core.Content;
+import info.magnolia.cms.security.AccessDeniedException;
+
+import javax.jcr.RepositoryException;
+
+
+/**
+ * Custom save handler interface. You can associate a specific implementation to a single dialog field by specifying the
+ * full class name in a property named "saveHandler"
+ * @author molaschi
+ * @version $Id$
+ */
+public interface CustomSaveHandler {
+
+ /**
+ * save a property
+ * @param parentNode in node
+ * @param configNode configuration
+ * @param name property name
+ * @param form form
+ * @param type type
+ * @param valueType value type
+ * @param isRichEditValue is rich edit?
+ * @param encoding encoding
+ */
+ void save(Content parentNode, Content configNode, String name, MultipartForm form, int type, int valueType,
+ int isRichEditValue, int encoding) throws RepositoryException, AccessDeniedException;
+}
Property changes on: magnolia/trunk/magnolia-module-admininterface/src/main/java/info/magnolia/module/admininterface/CustomSaveHandler.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Modified: magnolia/trunk/magnolia-module-admininterface/src/main/java/info/magnolia/module/admininterface/SaveHandlerImpl.java (16894 => 16895)
--- magnolia/trunk/magnolia-module-admininterface/src/main/java/info/magnolia/module/admininterface/SaveHandlerImpl.java 2008-07-17 16:32:53 UTC (rev 16894)
+++ magnolia/trunk/magnolia-module-admininterface/src/main/java/info/magnolia/module/admininterface/SaveHandlerImpl.java 2008-07-17 19:06:25 UTC (rev 16895)
@@ -33,12 +33,12 @@
*/
package info.magnolia.module.admininterface;
-import info.magnolia.cms.core.HierarchyManager;
import info.magnolia.cms.beans.config.ContentRepository;
import info.magnolia.cms.beans.runtime.Document;
import info.magnolia.cms.beans.runtime.FileProperties;
import info.magnolia.cms.beans.runtime.MultipartForm;
import info.magnolia.cms.core.Content;
+import info.magnolia.cms.core.HierarchyManager;
import info.magnolia.cms.core.ItemType;
import info.magnolia.cms.core.NodeData;
import info.magnolia.cms.core.Path;
@@ -53,21 +53,7 @@
import info.magnolia.cms.util.LinkUtil;
import info.magnolia.cms.util.NodeDataUtil;
import info.magnolia.context.MgnlContext;
-import org.apache.commons.codec.binary.Base64;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang.StringUtils;
-import org.apache.commons.lang.exception.NestableRuntimeException;
-import org.devlib.schmidt.imageinfo.ImageInfo;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import javax.jcr.Node;
-import javax.jcr.PathNotFoundException;
-import javax.jcr.PropertyType;
-import javax.jcr.RepositoryException;
-import javax.jcr.Value;
-import javax.jcr.ValueFactory;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -82,11 +68,30 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import javax.jcr.Node;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.ValueFactory;
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.exception.NestableRuntimeException;
+import org.devlib.schmidt.imageinfo.ImageInfo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
/**
+ * <p>
* This class handels the saving in the dialogs. It uses the mgnlSaveInfo parameters sendend from the browser to store
* the data in the node.The structure of the parameter is the following: <br>
- * <code>name, type, valueType, isRichEditValue, encoding</code> <p/> To find the consts see ControlImpl
+ * <code>name, type, valueType, isRichEditValue, encoding</code>
+ * </p>
+ * <p>To find the consts see ControlImpl</p>
* <table>
* <tr>
* <td>name</td>
@@ -109,6 +114,10 @@
* <td>base64, unix, none</td>
* </tr>
* </table>
+ * <p>
+ * You can specify a custom save handled (a class that implements info.magnolia.module.admininterface.CustomSaveHandler)
+ * by adding a "saveHandler" property to a dialog field configuration.
+ * </p>
* @author Vinzenz Wyser
* @version 2.0
*/
@@ -286,6 +295,43 @@
name = saveInfo;
}
+ // handing of custom save handler start
+ String customSaveHandler = this.getForm().getParameter(name + "_saveHandler");
+ if (!StringUtils.isEmpty(customSaveHandler)) {
+ try {
+ Class cshClazz = Class.forName(customSaveHandler);
+ if (!CustomSaveHandler.class.isAssignableFrom(cshClazz)) {
+ log.error("Class {} must implement CustomSaveHandler interface", cshClazz);
+ throw new ClassCastException("Class " + cshClazz + " must implement CustomSaveHandler interface");
+ }
+ else {
+ CustomSaveHandler csh = (CustomSaveHandler) cshClazz.newInstance();
+ HierarchyManager hm = MgnlContext.getSystemContext().getHierarchyManager(ContentRepository.CONFIG);
+ String configPath = this.getForm().getParameter(name + "_configNode");
+ csh.save(
+ node,
+ hm.getContent(configPath),
+ name,
+ getForm(),
+ type,
+ valueType,
+ isRichEditValue,
+ encoding);
+ }
+ }
+ catch (ClassNotFoundException e) {
+ log.error("Error loading class " + customSaveHandler, e);
+ }
+ catch (InstantiationException e) {
+ log.error("Error creating instance of class " + customSaveHandler, e);
+ }
+ catch (IllegalAccessException e) {
+ log.error("Illegal access to class " + customSaveHandler, e);
+ }
+ }
+ else
+ // handing of custom save handler end
+
if (type == PropertyType.BINARY) {
processBinary(node, name);
}
|