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.portlet.asset.model.AssetEntry;
019    import com.liferay.portlet.asset.service.AssetEntryLocalServiceUtil;
020    
021    import javax.servlet.http.HttpServletRequest;
022    
023    /**
024     * @author Juan Fern??ndez
025     * @author Shuyang Zhou
026     */
027    public class InputAssetLinksTag extends AssetLinksTag {
028    
029            @Override
030            protected String getPage() {
031                    return _PAGE;
032            }
033    
034            @Override
035            protected void setAttributes(HttpServletRequest request) {
036                    long assetEntryId = getAssetEntryId();
037                    String className = getClassName();
038                    long classPK = getClassPK();
039    
040                    if ((assetEntryId <= 0) && (classPK > 0)) {
041                            try {
042                                    AssetEntry assetEntry = AssetEntryLocalServiceUtil.fetchEntry(
043                                            className, classPK);
044    
045                                    if (assetEntry != null) {
046                                            assetEntryId = assetEntry.getEntryId();
047                                    }
048                            }
049                            catch (SystemException se) {
050                            }
051                    }
052    
053                    request.setAttribute(
054                            "liferay-ui:input-asset-links:assetEntryId",
055                            String.valueOf(assetEntryId));
056                    request.setAttribute(
057                            "liferay-ui:input-asset-links:className", className);
058            }
059    
060            private static final String _PAGE =
061                    "/html/taglib/ui/input_asset_links/page.jsp";
062    
063    }