001    /**
002     * Copyright (c) 2000-2013 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            @Override
033            public String getAssetViewURL(
034                    LiferayPortletRequest liferayPortletRequest,
035                    LiferayPortletResponse liferayPortletResponse, AssetEntry assetEntry) {
036    
037                    PortletURL viewURL = liferayPortletResponse.createRenderURL();
038    
039                    viewURL.setParameter("struts_action", "/asset_publisher/view_content");
040    
041                    String currentURL = PortalUtil.getCurrentURL(liferayPortletRequest);
042    
043                    viewURL.setParameter("redirect", currentURL);
044    
045                    viewURL.setParameter(
046                            "assetEntryId", String.valueOf(assetEntry.getEntryId()));
047    
048                    AssetRendererFactory assetRendererFactory =
049                            assetEntry.getAssetRendererFactory();
050    
051                    AssetRenderer assetRenderer = assetEntry.getAssetRenderer();
052    
053                    viewURL.setParameter("type", assetRendererFactory.getType());
054    
055                    if (Validator.isNotNull(assetRenderer.getUrlTitle())) {
056                            viewURL.setParameter("urlTitle", assetRenderer.getUrlTitle());
057                    }
058    
059                    return viewURL.toString();
060            }
061    
062    }