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.pages;
 
 import  info.magnolia.cms.exchange.ActivationManagerFactory;
 import  info.magnolia.cms.security.Permission;
 import  info.magnolia.jcr.util.MetaDataUtil;
 import  info.magnolia.jcr.util.NodeUtil;
 import  info.magnolia.jcr.util.PropertyUtil;
 import  info.magnolia.objectfactory.Components;
 import  info.magnolia.repository.RepositoryConstants;
 
 import java.util.Map;
 
 import javax.jcr.Node;
 
 
 

Author(s):
dschivo
Version:
$Id: MediaBeanBuilder.java 4402 2013-10-20 15:39:10Z fgiust $
 
 public class MediaBeanBuilder implements Function<NodeMediaBean>
 {

    
Logger.
 
     private Logger log = LoggerFactory.getLogger(getClass());

    
 
     public MediaBean apply(Node media)
     {
 
         String mediatype = PropertyUtil.getString(media"type");
         MediaTypeConfiguration mtc = Components.getComponent(MediaConfigurationManager.class).getTypes().get(mediatype);
         MediaBean mb = new MediaBean();
         try
         {
             if (mtc == null)
             {
                 .warn("Skipping media {} with invalid media type \"{}\""media.getPath(), mediatype);
                 return null;
             }
 
             mb.setContent(media);
             mb.setMetaData(MetaDataUtil.getMetaData(media));
             mb.setHandle(media.getPath());
             mb.setName(PropertyUtil.getString(media.));
             mb.setFilename(mtc.getHandler().getFilename(media));
             // backward compatibility
             if (StringUtils.isEmpty(mb.getName()) && !StringUtils.isEmpty(mb.getFilename()))
             {
                 int p = StringUtils.lastIndexOf(mb.getFilename(), '/');
                 mb.setName(p != -1 ? mb.getFilename().substring(p + 1) : mb.getFilename());
             }
             mb.setTitle(mtc.getHandler().getTitle(media));
             mb.setThumbnailUrl(mtc.getHandler().getThumbnailUrl(media));
             mb.setPreviewUrl(mtc.getHandler().getPreviewUrl(media));
             mb.setDescription(mtc.getHandler().getDescription(media));
             mb.setDialog(mtc.getDialog());
             mb.setUuid(media.getIdentifier());
             mb.setType(mediatype);
             mb.setIcon(mtc.getMenuIcon());
 
             mb.setWritable(NodeUtil.isGranted(media.getParent(), Permission.SET));
             mb.setCanPublish(!MediaEl.module().isSingleinstance()
                && mb.isWritable()
                && ActivationManagerFactory.getActivationManager().hasAnyActiveSubscriber());
            Map<StringAdvancedResultworkspacePaths = Components.getComponent(MediaUsedInManager.class).getUsedIn(
                media.getIdentifier());
            mb.setUsedInWebPages(workspacePaths.get(RepositoryConstants.WEBSITE));
            mb.setUsedInNodes(workspacePaths);
            int count = 0;
            for (AdvancedResult wp : workspacePaths.values())
            {
                count += wp.getTotalSize();
            }
            mb.setNumberOfReferences(count);
        }
        catch (RepositoryException ex)
        {
            .error("Exception caught"ex);
        }
        mb.setMediaInfo(mtc.getHandler().getMediaInfo(media));
        mb.setExternal(mtc.getHandler().isExternal(media));
        return mb;
    }
New to GrepCode? Check out our FAQ X