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.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(ThemeDisplay themeDisplay, Field field) {
035                    Serializable fieldValue = field.getValue();
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    }