Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
SimpleMedia Module for Magnolia CMS ( Copyright(C) 2008-2013, Openmind S.r.l. 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 <>.
 import  info.magnolia.cms.beans.runtime.MultipartForm;
 import  info.magnolia.cms.core.Content;
 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

$Id: 4388 2013-10-19 20:58:07Z fgiust $
 public class MediaCustomSaveHandler implements FieldSaveHandler

     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() != .)
             Session hm = MgnlContext.getJCRSession(.);
                 Node media = hm.getNodeByIdentifier(value);
                 MediaTypeConfiguration mtc = Components
            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)
                else if (parentNode.hasNodeData(paramName))
New to GrepCode? Check out our FAQ X