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 getEditorValue(
030                    HttpServletRequest request, String editorImpl) {
031    
032                    if (Validator.isNotNull(editorImpl)) {
033                            editorImpl = PropsUtil.get(editorImpl);
034                    }
035    
036                    if (!BrowserSnifferUtil.isRtf(request)) {
037                            if (BrowserSnifferUtil.isSafari(request) &&
038                                    BrowserSnifferUtil.isMobile(request)) {
039    
040                                    editorImpl = "simple";
041                            }
042                            else if (BrowserSnifferUtil.isSafari(request) &&
043                                             !editorImpl.contains("simple")) {
044    
045                                    editorImpl = "tinymce_simple";
046                            }
047                            else {
048                                    editorImpl = "simple";
049                            }
050                    }
051    
052                    if (Validator.isNull(editorImpl)) {
053                            editorImpl = _EDITOR_WYSIWYG_DEFAULT;
054                    }
055    
056                    return editorImpl;
057            }
058    
059            private static final String _EDITOR_WYSIWYG_DEFAULT = PropsUtil.get(
060                    PropsKeys.EDITOR_WYSIWYG_DEFAULT);
061    
062    }