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.portal.kernel.editor;
016    
017    import com.liferay.portal.kernel.servlet.BrowserSnifferUtil;
018    import com.liferay.portal.kernel.util.PropsKeys;
019    import com.liferay.portal.kernel.util.PropsUtil;
020    import com.liferay.portal.kernel.util.Validator;
021    
022    import javax.servlet.http.HttpServletRequest;
023    
024    /**
025     * @author Julio Camarero
026     */
027    public class EditorUtil {
028    
029            public static String getEditorMode(String langType) {
030                    String editorMode = "php";
031    
032                    if (langType.equals("css")) {
033                            editorMode = "css";
034                    }
035                    else if (langType.equals("xml") ||
036                                     langType.equals("xsl") ||
037                                     langType.equals("xsd")) {
038    
039                            editorMode = "xml";
040                    }
041    
042                    return editorMode;
043            }
044    
045            public static String getEditorValue(
046                    HttpServletRequest request, String editorImpl) {
047    
048                    if (Validator.isNotNull(editorImpl)) {
049                            editorImpl = PropsUtil.get(editorImpl);
050                    }
051    
052                    if (!BrowserSnifferUtil.isRtf(request)) {
053                            editorImpl = "simple";
054                    }
055    
056                    if (Validator.isNull(editorImpl)) {
057                            editorImpl = _EDITOR_WYSIWYG_DEFAULT;
058                    }
059    
060                    return editorImpl;
061            }
062    
063            private static final String _EDITOR_WYSIWYG_DEFAULT = PropsUtil.get(
064                    PropsKeys.EDITOR_WYSIWYG_DEFAULT);
065    
066    }