001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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 =
088                    "/html/taglib/ui/asset_links/page.jsp";
089    
090            private long _assetEntryId;
091            private String _className = StringPool.BLANK;
092            private long _classPK;
093    
094    }