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.configuration;
 
 import  info.magnolia.cms.beans.config.URI2RepositoryManager;
 import  info.magnolia.cms.beans.config.URI2RepositoryMapping;
 import  info.magnolia.jcr.util.NodeUtil;
 import  info.magnolia.jcr.util.PropertyUtil;
 
 import java.util.List;
 import java.util.Map;
 
 import  javax.inject.Inject;
 import  javax.inject.Singleton;
 import javax.jcr.Node;
 
 
ObservedManager that keeps that media types configuration.
Each media type is defined under the mediatypes contentnode in /modules/media.
I.e.
/modules/media/mediatypes/pdf
  • label = pdf file
  • handler = info.acme.PdfTypeHandler
  • menuIcon = .resources/pdf/icons/pdf16.gif
  • extensions = pdf

Author(s):
molaschi
 
 @Singleton
 {
 
     private Logger log = LoggerFactory.getLogger(MediaConfigurationManager.class);
 
 
     @Inject
     private URI2RepositoryManager uri2RepositoryManager;

    
 
     @Override
     protected void onClear()
     {
         .clear();
     }

    
 
     @Override
     @SuppressWarnings("unchecked")
     protected void onRegister(Node node)
     {
 
         try
         {
             for (Iterator<Nodeiter = NodeUtil.getNodes(node, NodeUtil.EXCLUDE_META_DATA_FILTER).iterator(); iter
                 .hasNext();)
             {
                 Node typeNode = iter.next();
 
                 if (!PropertyUtil.getBoolean(typeNode"enabled"true))
                 {
                     continue;
                 }
 
                try
                {
                    MediaTypeConfiguration conf = (MediaTypeConfiguration) NodeUtilsExt.toBean(
                        typeNode,
                        true,
                        MediaTypeConfiguration.class);
                    if (conf.getHandler() != null)
                    {
                        conf.getHandler().init(typeNode);
                    }
                    else
                    {
                        .error("Missing handler for media type {}"typeNode.getName());
                        continue;
                    }
                    .put(typeNode.getName(), conf);
                }
                catch (Throwable e)
                {
                    .error("Error getting media type configuration for {}", NodeUtil.getPathIfPossible(typeNode), e);
                }
            }
        }
        catch (RepositoryException e)
        {
            .error("Error getting nodes for {}", NodeUtil.getPathIfPossible(node), e);
        }
    }

    
Get the media type from a file extension

Parameters:
extension file extension
Returns:
media type
    {
        if (extension == null)
        {
            return null;
        }
        String lowerCasedExtension = extension.toLowerCase();
        for (Map.Entry<StringMediaTypeConfigurationentry : getTypes().entrySet())
        {
            MediaTypeConfiguration value = entry.getValue();
            List<StringextensionsList = value.getExtensionsList();
            if (extensionsList != null && extensionsList.contains(lowerCasedExtension))
            {
                return entry.getValue();
            }
        }
        return null;
    }

    
Get all media type map

Returns:
media type map
    {
        return ;
    }

    
Get the type configuration for a media

Parameters:
media media
Returns:
type configuration
    {
        try
        {
            if (!StringUtils.equals(media.getPrimaryNodeType().getName(), ))
            {
                return null;
            }
        }
        catch (RepositoryException e)
        {
            .error("Error getting item type on node {} module media", NodeUtil.getPathIfPossible(media), e);
            return null;
        }
        return .get(PropertyUtil.getString(media"type"));
    }

    
Get uri mapping for repo

Returns:
uri mapping for repo
    @Override
    public String getURIMappingPrefix()
    {
        Collection<URI2RepositoryMapping> mappings = .getMappings();
        for (URI2RepositoryMapping mapping : mappings)
        {
            if (mapping.getRepository().equals(.))
            {
                return mapping.getURIPrefix();
            }
        }
        return .;
    }
New to GrepCode? Check out our FAQ X