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.taglib.ui;
016    
017    import com.liferay.portal.kernel.exception.SystemException;
018    import com.liferay.portal.kernel.util.StringPool;
019    import com.liferay.portlet.asset.model.AssetEntry;
020    import com.liferay.portlet.asset.service.AssetEntryLocalServiceUtil;
021    import com.liferay.taglib.util.IncludeTag;
022    
023    import javax.servlet.http.HttpServletRequest;
024    
025    /**
026     * @author Juan Fernández
027     * @author Shuyang Zhou
028     */
029    public class AssetLinksTag extends IncludeTag {
030    
031            public long getAssetEntryId() {
032                    return _assetEntryId;
033            }
034    
035            public String getClassName() {
036                    return _className;
037            }
038    
039            public long getClassPK() {
040                    return _classPK;
041            }
042    
043            @Override
044            protected String getPage() {
045                    return _PAGE;
046            }
047    
048            @Override
049            protected void setAttributes(HttpServletRequest request) {
050                    if ((_assetEntryId <= 0) && (_classPK > 0)) {
051                            try {
052                                    AssetEntry assetEntry = AssetEntryLocalServiceUtil.fetchEntry(
053                                            _className, _classPK);
054    
055                                    if (assetEntry != null) {
056                                            _assetEntryId = assetEntry.getEntryId();
057                                    }
058                            }
059                            catch (SystemException se) {
060                            }
061                    }
062    
063                    request.setAttribute(
064                            "liferay-ui:asset-links:assetEntryId",
065                            String.valueOf(_assetEntryId));
066            }
067    
068            public void setAssetEntryId(long assetEntryId) {
069                    _assetEntryId = assetEntryId;
070            }
071    
072            public void setClassName(String className) {
073                    _className = className;
074            }
075    
076            public void setClassPK(long classPK) {
077                    _classPK = classPK;
078            }
079    
080            @Override
081            protected void cleanUp() {
082                    _assetEntryId = 0;
083                    _className = StringPool.BLANK;
084                    _classPK = 0;
085            }
086    
087            private static final String _PAGE = "/html/taglib/ui/asset_links/page.jsp";
088    
089            private long _assetEntryId;
090            private String _className = StringPool.BLANK;
091            private long _classPK;
092    
093    }