Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
SimpleMedia Module for Magnolia CMS (http://www.openmindlab.com/lab/products/media.html) Copyright(C) 2008-2013, Openmind S.r.l. http://www.openmindonline.it This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
 
 
 package net.sourceforge.openutils.mgnlmedia.media.save;
 
 import  info.magnolia.cms.beans.runtime.MultipartForm;
 import  info.magnolia.cms.core.Content;
 import  info.magnolia.cms.security.AccessDeniedException;
 import  info.magnolia.cms.util.NodeDataUtil;
 import  info.magnolia.context.MgnlContext;
 import  info.magnolia.module.admininterface.FieldSaveHandler;
 import  info.magnolia.objectfactory.Components;
 
 import javax.jcr.Node;
 
 
FieldSaveHandler implementation that calls the onSavingPropertyMedia method on the handler of target media type when a media is associated to a page

Author(s):
molaschi
Version:
$Id: MediaCustomSaveHandler.java 4388 2013-10-19 20:58:07Z fgiust $
 
 @SuppressWarnings("deprecation")
 public class MediaCustomSaveHandler implements FieldSaveHandler
 {

    
Logger.
 
     private Logger log = LoggerFactory.getLogger(MediaCustomSaveHandler.class);

    
 
     public void save(Content parentNode, Content configNodeString name, MultipartForm formint typeint valueType,
         int isRichEditValueint encodingthrows RepositoryException, AccessDeniedException
     {
         HttpServletRequest request = MgnlContext.getWebContext().getRequest();
         String value = request.getParameter(name);
 
         if (StringUtils.isBlank(value))
         {
             for (String property : new String[]{namename + "_width"name + "_height" })
             {
                 if (parentNode.hasNodeData(property))
                 {
                     if (parentNode.getNodeData(property).getType() != .)
                     {
                         parentNode.deleteNodeData(property);
                     }
                 }
             }
 
             return;
         }
         else
         {
 
             Session hm = MgnlContext.getJCRSession(.);
 
             try
             {
                 Node media = hm.getNodeByIdentifier(value);
 
                 MediaTypeConfiguration mtc = Components
                     .getComponent(MediaConfigurationManager.class)
                     .getMediaTypeConfigurationFromMedia(media);
                 mtc.getHandler().onSavingPropertyMedia(
                     media,
                    parentNode.getJCRNode(),
                    configNode.getJCRNode(),
                    name,
                    request,
                    form,
                    type,
                    valueType,
                    isRichEditValue,
                    encoding);
            }
            catch (ItemNotFoundException e)
            {
                .warn("Missing media {} referenced in node {}"valueparentNode.getHandle());
            }
            boolean resizing = NodeDataUtil.getBoolean(configNode"resizing"false);
            for (String dimKey : new String[]{"width""height" })
            {
                String paramName = name + '_' + dimKey;
                long dimValue = NumberUtils.toLong(request.getParameter(paramName), -1);
                if (resizing && dimValue >= 0)
                {
                    NodeDataUtil.getOrCreateAndSet(parentNodeparamNamedimValue);
                }
                else if (parentNode.hasNodeData(paramName))
                {
                    parentNode.deleteNodeData(paramName);
                }
            }
        }
    }
New to GrepCode? Check out our FAQ X