001    /**
002     * Copyright (c) 2000-2010 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.wiki.asset;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.kernel.portlet.LiferayPortletRequest;
020    import com.liferay.portal.kernel.portlet.LiferayPortletResponse;
021    import com.liferay.portal.theme.ThemeDisplay;
022    import com.liferay.portlet.asset.model.AssetRenderer;
023    import com.liferay.portlet.asset.model.BaseAssetRendererFactory;
024    import com.liferay.portlet.wiki.NoSuchPageException;
025    import com.liferay.portlet.wiki.model.WikiPage;
026    import com.liferay.portlet.wiki.model.WikiPageResource;
027    import com.liferay.portlet.wiki.service.WikiPageLocalServiceUtil;
028    import com.liferay.portlet.wiki.service.WikiPageResourceLocalServiceUtil;
029    
030    import javax.portlet.PortletURL;
031    
032    /**
033     * @author Julio Camarero
034     * @author Juan Fernández
035     * @author Jorge Ferrer
036     */
037    public class WikiPageAssetRendererFactory extends BaseAssetRendererFactory {
038    
039            public static final String CLASS_NAME =  WikiPage.class.getName();
040    
041            public static final String TYPE = "wiki";
042    
043            public AssetRenderer getAssetRenderer(long classPK, int type)
044                    throws PortalException, SystemException {
045    
046                    WikiPage page = null;
047    
048                    try {
049                            page = WikiPageLocalServiceUtil.getWikiPage(classPK);
050                    }
051                    catch (NoSuchPageException nspe) {
052                            if (type == TYPE_LATEST_APPROVED) {
053                                    page = WikiPageLocalServiceUtil.getPage(classPK);
054                            }
055                            else {
056                                    WikiPageResource wikiPageResource =
057                                            WikiPageResourceLocalServiceUtil.getPageResource(
058                                                    classPK);
059    
060                                    page = WikiPageLocalServiceUtil.getPage(
061                                            wikiPageResource.getNodeId(),
062                                            wikiPageResource.getTitle(), null);
063                            }
064                    }
065    
066                    return new WikiPageAssetRenderer(page);
067            }
068    
069            public String getClassName() {
070                    return CLASS_NAME;
071            }
072    
073            public String getType() {
074                    return TYPE;
075            }
076    
077            public PortletURL getURLAdd(
078                    LiferayPortletRequest liferayPortletRequest,
079                    LiferayPortletResponse liferayPortletResponse) {
080    
081                    return null;
082            }
083    
084            protected String getIconPath(ThemeDisplay themeDisplay) {
085                    return themeDisplay.getPathThemeImages() + "/common/pages.png";
086            }
087    
088    }