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.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                            if (BrowserSnifferUtil.isSafari(request) &&
054                                    BrowserSnifferUtil.isMobile(request)) {
055    
056                                    editorImpl = "simple";
057                            }
058                            else if (BrowserSnifferUtil.isSafari(request) &&
059                                             !editorImpl.contains("simple")) {
060    
061                                    editorImpl = "tinymce_simple";
062                            }
063                            else {
064                                    editorImpl = "simple";
065                            }
066                    }
067    
068                    if (Validator.isNull(editorImpl)) {
069                            editorImpl = _EDITOR_WYSIWYG_DEFAULT;
070                    }
071    
072                    return editorImpl;
073            }
074    
075            private static final String _EDITOR_WYSIWYG_DEFAULT = PropsUtil.get(
076                    PropsKeys.EDITOR_WYSIWYG_DEFAULT);
077    
078    }