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.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            public void setAssetEntryId(long assetEntryId) {
044                    _assetEntryId = assetEntryId;
045            }
046    
047            public void setClassName(String className) {
048                    _className = className;
049            }
050    
051            public void setClassPK(long classPK) {
052                    _classPK = classPK;
053            }
054    
055            @Override
056            protected void cleanUp() {
057                    _assetEntryId = 0;
058                    _className = StringPool.BLANK;
059                    _classPK = 0;
060            }
061    
062            @Override
063            protected String getPage() {
064                    return _PAGE;
065            }
066    
067            @Override
068            protected void setAttributes(HttpServletRequest request) {
069                    if ((_assetEntryId <= 0) && (_classPK > 0)) {
070                            try {
071                                    AssetEntry assetEntry = AssetEntryLocalServiceUtil.fetchEntry(
072                                            _className, _classPK);
073    
074                                    if (assetEntry != null) {
075                                            _assetEntryId = assetEntry.getEntryId();
076                                    }
077                            }
078                            catch (SystemException se) {
079                            }
080                    }
081    
082                    request.setAttribute(
083                            "liferay-ui:asset-links:assetEntryId",
084                            String.valueOf(_assetEntryId));
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    }