Return-Path: <_www@dev.magnolia.info> Received: from dev.magnolia.info ([213.173.174.20] verified) by mail.obinary.com (CommuniGate Pro SMTP 5.1.10) with ESMTP id 14533706 for svn-list@magnolia.info; Thu, 17 Jul 2008 21:06:25 +0200 Received: by dev.magnolia.info (Postfix, from userid 70) id B8A0D6969BA; Thu, 17 Jul 2008 21:06:25 +0200 (CEST) MIME-Version: 1.0 X-Mailer: SVN::Notify 2.70: http://search.cpan.org/dist/SVN-Notify/ From: svn@magnolia.info Errors-To: svn@magnolia.info To: svn-list@magnolia.info Subject: [16895] MAGNOLIA-2272 Ability to choose a custom save handler per control/ field Reply-To: dev-list@magnolia.info Content-Type: text/html; charset=UTF-8 Message-Id: <20080717190625.B8A0D6969BA@dev.magnolia.info> Date: Thu, 17 Jul 2008 21:06:25 +0200 (CEST) Content-Transfer-Encoding: quoted-printable
MAGNOLIA-= 2272 Ability to choose a custom save handler per control/field
--- magnolia/trunk/magnolia-module-admininterface/sr=
c/main/java/info/magnolia/module/admininterface/CustomSaveHandler.java =
(rev 0)
+++ magnolia/trunk/magnolia-module-admininterface/src/main/java/info/magn=
olia/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 implement=
ation 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, Multi=
partForm form, int type, int valueType,
+ int isRichEditValue, int encoding) throws RepositoryException, A=
ccessDeniedException;
+}
Property changes on: magnolia/trunk/magnolia-mod=
ule-admininterface/src/main/java/info/magnolia/module/admininterface/Cust=
omSaveHandler.java
_______________________________________________=
____________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
--- magnolia/trunk/magnolia-module-admininterface/sr=
c/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/magn=
olia/module/admininterface/SaveHandlerImpl.java 2008-07-17 19:06:25 UTC (=
rev 16895)
@@ -33,12 +33,12 @@
*/
package info.magnolia.module.admininterface;
=20
-import info.magnolia.cms.core.HierarchyManager;
import info.magnolia.cms.beans.config.ContentRe=
pository;
import info.magnolia.cms.beans.runtime.Documen=
t;
import info.magnolia.cms.beans.runtime.FilePro=
perties;
import info.magnolia.cms.beans.runtime.Multipa=
rtForm;
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;
=20
-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;
=20
+import javax.jcr.Node;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.ValueFactory;
=20
+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 p=
arameter is the following: <br>
- * <code>name, type, valueType, isRichEditValue, encod=
ing</code> <p/> To find the consts see ControlImpl
+ * <code>name, type, valueType, isRichEditValue, encodi=
ng</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.m=
agnolia.module.admininterface.CustomSaveHandler)
+ * by adding a "saveHandler" property to a dialog field config=
uration.
+ * </p>
* @author Vinzenz Wyser
* @version 2.0
*/
@@ -286,6 +295,43 @@
name =3D saveInfo;
}
=20
+ // handing of custom save handler start
+ String customSaveHandler =3D this.getForm().getParameter(name + =
"_saveHandler");
+ if (!StringUtils.isEmpty(customSaveHandler)) {
+ try {
+ Class cshClazz =3D Class.forName(customSaveHandler);
+ if (!CustomSaveHandler.class.isAssignableFrom(cshClazz))=
{
+ log.error("Class {} must implement CustomSaveHa=
ndler interface", cshClazz);
+ throw new ClassCastException("Class " + cs=
hClazz + " must implement CustomSaveHandler interface");
+ }
+ else {
+ CustomSaveHandler csh =3D (CustomSaveHandler) cshCla=
zz.newInstance();
+ HierarchyManager hm =3D MgnlContext.getSystemContext=
().getHierarchyManager(ContentRepository.CONFIG);
+ String configPath =3D this.getForm().getParameter(na=
me + "_configNode");
+ csh.save(
+ node,
+ hm.getContent(configPath),
+ name,
+ getForm(),
+ type,
+ valueType,
+ isRichEditValue,
+ encoding);
+ }
+ }
+ catch (ClassNotFoundException e) {
+ log.error("Error loading class " + customSaveH=
andler, e);
+ }
+ catch (InstantiationException e) {
+ log.error("Error creating instance of class " =
+ customSaveHandler, e);
+ }
+ catch (IllegalAccessException e) {
+ log.error("Illegal access to class " + customS=
aveHandler, e);
+ }
+ }
+ else
+ // handing of custom save handler end
+
if (type =3D=3D PropertyType.BINARY) {
processBinary(node, name);
}