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.playlist.pages;
 
 import  info.magnolia.jcr.util.MetaDataUtil;
 import  info.magnolia.jcr.util.NodeUtil;
 import  info.magnolia.jcr.util.PropertyUtil;
 import  info.magnolia.module.ModuleRegistry;
 import  info.magnolia.objectfactory.Components;
 
 import java.util.List;
 import java.util.Map;
 
 import javax.jcr.Node;
 
 

Author(s):
dschivo
 
 public class PlaylistView extends MessagesTemplatedMVCHandler
 {

    
Logger.
 
     private Logger log = LoggerFactory.getLogger(PlaylistView.class);
 
     private String path;
 
     private PlaylistBean playlist;
 
     private String title;
 
     private String description;
 
     private String mediaHandle;
 
     private boolean success;
 
     private static final String VIEW_XSPF = "-xspf";

    
JSON response to ajax calls (eg: saving playlist title and description)
 
     private static final String VIEW_EXTJS = "-extjs";
 
     private String locale;
 
     private boolean xml;
 
     private List<NodemediaContentList;
 
     private List<MediaBeanmediaBeans;

    
 
    public PlaylistView(String nameHttpServletRequest requestHttpServletResponse response)
    {
        super(namerequestresponse);
    }

    
Sets the path.

Parameters:
path the path to set
    public void setPath(String path)
    {
        this. = path;
    }

    
Returns the playlist.

Returns:
the playlist
    public PlaylistBean getPlaylist()
    {
        return ;
    }

    
Sets the title.

Parameters:
title the title to set
    public void setTitle(String title)
    {
        this. = title;
    }

    
Sets the description.

Parameters:
description the description to set
    public void setDescription(String description)
    {
        this. = description;
    }

    
Returns the mediaHandle.

Returns:
the mediaHandle
    public String getMediaHandle()
    {
        return ;
    }

    
Sets the mediaHandle.

Parameters:
mediaHandle the mediaHandle to set
    public void setMediaHandle(String mediaHandle)
    {
        this. = mediaHandle;
    }

    
Returns the success.

Returns:
the success
    public boolean isSuccess()
    {
        return ;
    }

    
    @Override
    public String show()
    {
        if (StringUtils.isNotBlank())
        {
            Node node = NodeUtilsExt.getNodeByIdOrPath(.);
            if (node != null)
            {
                try
                {
                     = new PlaylistBean();
                    .setUuid(node.getIdentifier());
                    .setHandle(NodeUtil.getPathIfPossible(node));
                    .setTitle(PropertyUtil.getString(node"title"));
                    .setDescription(PropertyUtil.getString(node"description"));
                    List<PlaylistEntryBeanentries = new ArrayList<PlaylistEntryBean>();
                    for (Iterator<MediaNodeAndEntryPathiterator = PlaylistIterateUtils.iterate(node); iterator
                        .hasNext();)
                    {
                        MediaNodeAndEntryPath item = iterator.next();
                        Node media = item.getMediaNode();
                        if (media == null)
                        {
                            continue;
                        }
                        PlaylistEntryBean entry = new PlaylistEntryBean();
                        entry.setHandle(item.getPlaylistEntryPath());
                        entry.setMedia(NodeUtil.getNodeIdentifierIfPossible(media));
                        entry.setMediaHandle(NodeUtil.getPathIfPossible(media));
                        MediaTypeConfiguration typeConf = Components
                            .getComponent(MediaConfigurationManager.class)
                            .getMediaTypeConfigurationFromMedia(media);
                        if (typeConf != null)
                        {
                            entry.setMediaDialog(typeConf.getDialog());
                        }
                        entry.setThumbnail(MediaEl.thumbnail(media));
                        entry.setType(PropertyUtil.getString(media"type"));
                        entry.setTitle(PropertyUtil.getString(media"title"));
                        entry.setDescription(PropertyUtil.getString(media"description"));
                        entry.setTags(PropertyUtil.getString(media"tags"));
                        entries.add(entry);
                    }
                    .setEntries(entries);
                    .setSearchBased(node.hasNode("search"));
                }
                catch (RepositoryException e)
                {
                    // should never happen
                }
            }
            else
            {
                .warn("Node {} does not exist in playlist repository");
            }
        }
        return VIEW_SHOW;
    }
    public String save()
    {
         = false;
        Node node = NodeUtilsExt.getNodeByIdOrPath(.);
        if (node != null)
        {
            try
            {
                node.setProperty("title");
                node.setProperty("description");
                if (MediaEl.module().isSingleinstance())
                {
                    MetaDataUtil.getMetaData(node).setActivated();
                }
                node.getSession().save();
                 = true;
            }
            catch (RepositoryException e)
            {
            }
        }
        return ;
    }
    public String saveMedia()
    {
         = false;
        Node node = NodeUtilsExt.getNodeByIdOrPath(.);
        if (node != null)
        {
            try
            {
                node.setProperty("title");
                node.setProperty("description");
                if (MediaEl.module().isSingleinstance())
                {
                    MetaDataUtil.getMetaData(node).setActivated();
                }
                node.getSession().save();
                 = true;
            }
            catch (RepositoryException e)
            {
            }
        }
        return ;
    }
    public String xspf() throws IOException
    {
        String viewName = this.show();
        if (this.getPlaylist() == null)
        {
            this..sendError(404);
            return viewName;
        }
        else
        {
            // Set mediaContent
             = new ArrayList<Node>();
            for (PlaylistEntryBean plb : this.getPlaylist().getEntries())
            {
                try
                {
                    .add(NodeUtil.getNodeByIdentifier(.plb.getMedia()));
                }
                catch (RepositoryException e)
                {
                    .error("Error retrieving media {}"e);
                }
            }
            // Get locale
            if (StringUtils.isEmpty())
            {
                 = Locale.getDefault().toString();
            }
            if ()
            {
                this..setContentType("text/xml");
            }
            else
            {
                this..setContentType("application/xspf+xml");
            }
        }
        return ;
    }
    public String mediaFolder()
    {
        Node folder = NodeUtilsExt.getNodeByIdOrPath(.);
        if (folder != null)
        {
            try
            {
                Iterable<Nodenodes = NodeUtil.getNodes(folder.);
                 = new ArrayList<MediaBean>();
                for (Node node : nodes)
                {
                    MediaBean bean = new MediaBeanBuilder().apply(node);
                    .add(bean);
                }
            }
            catch (RepositoryException e)
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        return "-mediaFolder";
    }

    
Returns the locale.

Returns:
the locale
    public String getLocale()
    {
        return ;
    }

    
Sets the locale.

Parameters:
locale the locale to set
    public void setLocale(String locale)
    {
        this. = locale;
    }

    
Returns the mediaContentList.

Returns:
the mediaContentList
    public List<NodegetMediaContentList()
    {
        return ;
    }

    
Sets the mediaContentList.

Parameters:
mediaContentList the mediaContentList to set
    public void setMediaContentList(List<NodemediaContentList)
    {
        this. = mediaContentList;
    }

    
Returns the mediaBeans.

Returns:
the mediaBeans
    public List<MediaBeangetMediaBeans()
    {
        return ;
    }

    
Sets the xml.

Parameters:
xml the xml to set
    public void setXml(boolean xml)
    {
        this. = xml;
    }
    public String playlistTitle()
    {
        return .getTitle();
    }
    public String playlistLocation()
    {
        return "/playlists" + .getHandle() + ".xspf?locale=" + ;
    }
    public Map<StringObjectplaylistMetas()
    {
        Map<StringObjectmetas = new LinkedHashMap<StringObject>();
        metas.put("media:locale");
        metas.put("media:playlist-id".getUuid());
        return metas;
    }
    public void writePlaylistTrackExtension(Node mediaPrintWriter writer)
    {
        MediaModule module = (MediaModule) Components.getComponent(ModuleRegistry.class).getModuleInstance(
            .);
        for (Object item : module.getPlaylistTrackExtensionContributors())
        {
            PlaylistTrackExtensionContributor contributor = (PlaylistTrackExtensionContributoritem;
            contributor.addMediaAttributes(mediawriter);
        }
    }
New to GrepCode? Check out our FAQ X