001    /**
002     * Copyright (c) 2000-present 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.portal.kernel.editor.configuration;
016    
017    import com.liferay.portal.kernel.json.JSONArray;
018    import com.liferay.portal.kernel.json.JSONException;
019    import com.liferay.portal.kernel.json.JSONFactoryUtil;
020    import com.liferay.portal.kernel.json.JSONObject;
021    import com.liferay.portal.kernel.log.Log;
022    import com.liferay.portal.kernel.log.LogFactoryUtil;
023    
024    /**
025     * @author Brian Wing Shun Chan
026     */
027    public abstract class BaseEditorConfigContributor
028            implements EditorConfigContributor {
029    
030            protected JSONArray toJSONArray(String json) {
031                    try {
032                            return JSONFactoryUtil.createJSONArray(json);
033                    }
034                    catch (JSONException jsone) {
035                            _log.error("Unable to create a JSON array from: " + json, jsone);
036                    }
037    
038                    return JSONFactoryUtil.createJSONArray();
039            }
040    
041            protected JSONObject toJSONObject(String json) {
042                    try {
043                            return JSONFactoryUtil.createJSONObject(json);
044                    }
045                    catch (JSONException jsone) {
046                            _log.error("Unable to create a JSON object from: " + json, jsone);
047                    }
048    
049                    return JSONFactoryUtil.createJSONObject();
050            }
051    
052            private static final Log _log = LogFactoryUtil.getLog(
053                    BaseEditorConfigContributor.class);
054    
055    }