001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.assetpublisher.util;
016    
017    import com.liferay.portal.kernel.portlet.LiferayPortletRequest;
018    import com.liferay.portal.kernel.portlet.LiferayPortletResponse;
019    import com.liferay.portal.kernel.util.Validator;
020    import com.liferay.portal.util.PortalUtil;
021    import com.liferay.portlet.asset.model.AssetEntry;
022    import com.liferay.portlet.asset.model.AssetRenderer;
023    import com.liferay.portlet.asset.model.AssetRendererFactory;
024    
025    import javax.portlet.PortletURL;
026    
027    /**
028     * @author Juan Fernández
029     */
030    public class AssetPublisherHelperImpl implements AssetPublisherHelper {
031    
032            public String getAssetViewURL(
033                    LiferayPortletRequest liferayPortletRequest,
034                    LiferayPortletResponse liferayPortletResponse, AssetEntry assetEntry) {
035    
036                    PortletURL viewURL = liferayPortletResponse.createRenderURL();
037    
038                    viewURL.setParameter("struts_action", "/asset_publisher/view_content");
039    
040                    String currentURL = PortalUtil.getCurrentURL(liferayPortletRequest);
041    
042                    viewURL.setParameter("redirect", currentURL);
043    
044                    viewURL.setParameter(
045                            "assetEntryId", String.valueOf(assetEntry.getEntryId()));
046    
047                    AssetRendererFactory assetRendererFactory =
048                            assetEntry.getAssetRendererFactory();
049    
050                    AssetRenderer assetRenderer = assetEntry.getAssetRenderer();
051    
052                    viewURL.setParameter("type", assetRendererFactory.getType());
053    
054                    if (Validator.isNotNull(assetRenderer.getUrlTitle())) {
055                            viewURL.setParameter("urlTitle", assetRenderer.getUrlTitle());
056                    }
057    
058                    return viewURL.toString();
059            }
060    
061    }