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.portlet.dynamicdatamapping.storage;
016    
017    import com.liferay.portal.kernel.json.JSONException;
018    import com.liferay.portal.kernel.json.JSONFactoryUtil;
019    import com.liferay.portal.kernel.json.JSONObject;
020    import com.liferay.portal.kernel.log.Log;
021    import com.liferay.portal.kernel.log.LogFactoryUtil;
022    import com.liferay.portal.kernel.util.StringPool;
023    import com.liferay.portal.kernel.util.Validator;
024    import com.liferay.portal.theme.ThemeDisplay;
025    
026    import java.io.Serializable;
027    
028    /**
029     * @author Bruno Basto
030     */
031    public class FileUploadFieldRenderer extends BaseFieldRenderer {
032    
033            @Override
034            protected String doRender(
035                    ThemeDisplay themeDisplay, Serializable fieldValue) {
036    
037                    if (Validator.isNull(fieldValue) ||
038                            fieldValue.equals(JSONFactoryUtil.getNullJSON())) {
039    
040                            return StringPool.BLANK;
041                    }
042    
043                    JSONObject fieldValueJSONObject = null;
044    
045                    try {
046                            fieldValueJSONObject = JSONFactoryUtil.createJSONObject(
047                                    String.valueOf(fieldValue));
048                    }
049                    catch (JSONException jsone) {
050                            if (_log.isDebugEnabled()) {
051                                    _log.debug("Unable to parse JSON", jsone);
052                            }
053    
054                            return StringPool.BLANK;
055                    }
056    
057                    return fieldValueJSONObject.getString("name");
058            }
059    
060            private static Log _log = LogFactoryUtil.getLog(
061                    FileUploadFieldRenderer.class);
062    
063    }