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.utils;
 
 import  info.magnolia.cms.core.MgnlNodeType;
 import  info.magnolia.context.MgnlContext;
 import  info.magnolia.jcr.util.NodeUtil;
 import  info.magnolia.jcr.util.PropertyUtil;
 
 import java.util.Map;
 
 import javax.jcr.Node;
 
 
 

Author(s):
ADMIN
Version:
$Id: $
 
 public final class PlaylistIterateUtils
 {

    
Logger.
 
     private static Logger log = LoggerFactory.getLogger(PlaylistIterateUtils.class);
 
     private PlaylistIterateUtils()
     {
     }

    

Parameters:
obj
Returns:
 
     @SuppressWarnings("unchecked")
     public static Iterator<MediaNodeAndEntryPathiterate(final Node playlistNode)
     {
         if (playlistNode == null)
         {
             return IteratorUtils.emptyIterator();
         }
 
         try
         {
             if (playlistNode.hasNode("search"))
             {
                 Node searchNode = playlistNode.getNode("search");
 
                 Iterable<Nodenodes = NodeUtil.getNodes(searchNode, MgnlNodeType.NT_CONTENTNODE);
 
                 final Map<StringObjectmap = new HashMap<StringObject>();
                 for (Node node : nodes)
                 {
                     String paramName = PropertyUtil.getString(node"name");
                     Value[] jcrValues = node.getProperty("value").getValues();
                     String[] paramValues = new String[jcrValues.length];
                     for (int i = 0; i < jcrValues.lengthi++)
                     {
                        paramValues[i] = jcrValues[i].getString();
                    }
                    if (paramValues.length == 1)
                    {
                        map.put(paramNameparamValues[0]);
                    }
                    else if (paramValues.length > 1)
                    {
                        map.put(paramNameparamValues);
                    }
                }
                Property maxresultProperty = PropertyUtil.getPropertyOrNull(playlistNode"maxResults");
                int maxresults = maxresultProperty != null ? (intmaxresultProperty.getLong() : 0;
                AdvancedResult searchResult = MediaEl
                    .module()
                    .getSearch()
                    .search(
                        new CustomParamsRequest(MgnlContext.getWebContext().getRequest(), mapfalse),
                        null,
                        "/",
                        true,
                        .,
                        maxresults,
                        1);
                return Iterators.transform(
                    searchResult.getItems(),
                    new Function<AdvancedResultItemMediaNodeAndEntryPath>()
                    {

                        
                        public MediaNodeAndEntryPath apply(AdvancedResultItem from)
                        {
                            return new MediaNodeAndEntryPath(fromnull);
                        }
                    });
            }
            else
            {
                // playlistNode.getChildren(PlaylistConstants.PLAYLIST_ENTRY).iterator(),
                Iterable<Nodenodes = NodeUtil.getNodes(playlistNode.);
                return Iterators.transform(nodes.iterator(), new Function<NodeMediaNodeAndEntryPath>()
                {

                    
                    public MediaNodeAndEntryPath apply(Node playlistEntry)
                    {
                        String mediaUUID = PropertyUtil.getString(playlistEntry"media");
                        Node mediaNode = MediaEl.node(mediaUUID);
                        if (mediaNode == null)
                        {
                            .warn(
                                "Node {} referenced by entry {} of playlist {} does not exist in media repository",
                                new Object[]{
                                    mediaUUID,
                                    NodeUtil.getName(playlistEntry),
                                    NodeUtil.getPathIfPossible(playlistNode) });
                        }
                        return new MediaNodeAndEntryPath(mediaNode, NodeUtil
                            .getPathIfPossible(playlistEntry));
                    }
                });
            }
        }
        catch (RepositoryException e)
        {
            // should never happen
            return null;
        }
    }
    public static class MediaNodeAndEntryPath
    {
        private final Node mediaNode;
        private final String playlistEntryPath;

        
        public MediaNodeAndEntryPath(Node mediaNodeString playlistEntryPath)
        {
            this. = mediaNode;
            this. = playlistEntryPath;
        }

        
Returns the mediaNode.

Returns:
the mediaNode
        public Node getMediaNode()
        {
            return ;
        }

        
Returns the playlistEntryPath.

Returns:
the playlistEntryPath
        public String getPlaylistEntryPath()
        {
            return ;
        }
    }
    // freemarker.ext.servlet.IncludePage.CustomParamsRequest
    private static final class CustomParamsRequest extends HttpServletRequestWrapper
    {
        private final HashMap paramsMap;
        private CustomParamsRequest(HttpServletRequest requestMap paramMapboolean inheritParams)
        {
            super(request);
             = inheritParams ? new HashMap(request.getParameterMap()) : new HashMap();
            for (Iterator it = paramMap.entrySet().iterator(); it.hasNext();)
            {
                Map.Entry entry = (Map.Entryit.next();
                String name = String.valueOf(entry.getKey());
                Object value = entry.getValue();
                final String[] valueArray;
                if (value == null)
                {
                    // Null values are explicitly added (so, among other
                    // things, we can hide inherited param values).
                    valueArray = new String[]{null };
                }
                else if (value instanceof String[])
                {
                    // String[] arrays are just passed through
                    valueArray = (String[]) value;
                }
                else if (value instanceof Collection)
                {
                    // Collections are converted to String[], with
                    // String.valueOf() used on elements
                    Collection col = (Collectionvalue;
                    valueArray = new String[col.size()];
                    int i = 0;
                    for (Iterator it2 = col.iterator(); it2.hasNext();)
                    {
                        valueArray[i++] = String.valueOf(it2.next());
                    }
                }
                else if (value.getClass().isArray())
                {
                    // Other array types are too converted to String[], with
                    // String.valueOf() used on elements
                    int len = Array.getLength(value);
                    valueArray = new String[len];
                    for (int i = 0; i < len; ++i)
                    {
                        valueArray[i] = String.valueOf(Array.get(valuei));
                    }
                }
                else
                {
                    // All other values (including strings) are converted to a
                    // single-element String[], with String.valueOf applied to
                    // the value.
                    valueArray = new String[]{String.valueOf(value) };
                }
                String[] existingParams = (String[]) .get(name);
                int el = existingParams == null ? 0 : existingParams.length;
                if (el == 0)
                {
                    // No original params, just put our array
                    .put(namevalueArray);
                }
                else
                {
                    int vl = valueArray.length;
                    if (vl > 0)
                    {
                        // Both original params and new params, prepend our
                        // params to original params
                        String[] newValueArray = new String[el + vl];
                        System.arraycopy(valueArray, 0, newValueArray, 0, vl);
                        System.arraycopy(existingParams, 0, newValueArrayvlel);
                        .put(namenewValueArray);
                    }
                }
            }
        }
        @Override
        public String[] getParameterValues(String name)
        {
            String[] value = ((String[]) .get(name));
            return value != null ? (String[]) value.clone() : null;
        }
        @Override
        public String getParameter(String name)
        {
            String[] values = (String[]) .get(name);
            return values != null && values.length > 0 ? values[0] : null;
        }
        @Override
        public Enumeration getParameterNames()
        {
            return Collections.enumeration(.keySet());
        }
        @Override
        public Map getParameterMap()
        {
            HashMap clone = (HashMap.clone();
            for (Iterator it = clone.entrySet().iterator(); it.hasNext();)
            {
                Map.Entry entry = (Map.Entryit.next();
                entry.setValue(((String[]) entry.getValue()).clone());
            }
            return Collections.unmodifiableMap(clone);
        }
    }
New to GrepCode? Check out our FAQ X