Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   * This library is part of OpenCms -
   * the Open Source Content Management System
   * Copyright (c) Alkacon Software GmbH (
   * This library is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation; either
  * version 2.1 of the License, or (at your option) any later version.
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * Lesser General Public License for more details.
  * For further information about Alkacon Software GmbH, please see the
  * company website:
  * For further information about OpenCms, please see the
  * project website:
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 package org.opencms.editors.codemirror;
 import java.util.List;
Provides helper methods for the usage of the CodeMirror editor that can be used for syntax highlighting of text based files.

 public class CmsCodeMirror extends CmsSimpleEditor {

Syntax highlight type name: CSS.
     public static final String HIGHLIGHT_TYPE_CSS = "css";

Syntax highlight type name: HTML.
     public static final String HIGHLIGHT_TYPE_HTML = "html";

Syntax highlight type name: JavaScript.
     public static final String HIGHLIGHT_TYPE_JAVASCRIPT = "js";

Syntax highlight type name: JSP.
     public static final String HIGHLIGHT_TYPE_JSP = "jsp";

Syntax highlight type name: XML.
     public static final String HIGHLIGHT_TYPE_XML = "xml";

Possible type suffix names.
     protected static final String[] HIGHLIGHT_TYPES = {

Possible type suffix names as list.
     protected static final List<StringHIGHLIGHT_TYPES_LIST = Arrays.asList();

Sub path fragment to the editor resources.
     protected static final String SUBPATH_CODEMIRROR = "editors/codemirror/";

Path to the editor resources.
     protected static final String VFS_PATH_EDITOR =  + ;

Path to the editor distribution resources.
     protected static final String VFS_PATH_EDITOR_DIST =  + "dist/";

Public constructor.

jsp an initialized JSP action element
     public CmsCodeMirror(CmsJspActionElement jsp) {

Returns the editor language to use according to the current users workplace settings.

the editor language to use
     public String getEditorLanguage() {
        String testLocale = getLocale().toString();
        if (getCms().existsResource( + "js/lang-" + testLocale + ".js")) {
            return testLocale;
        return ..toString();

    public String getEditorResourceUri() {
        return getSkinUri() + ;

Returns the syntax highlighting type for the currently edited resource.

the syntax highlighting type
    public String getHighlightMode() {
        // read edited resource
        CmsResource resource = null;
        try {
            resource = getCms().readResource(getParamResource());
        } catch (CmsException e) {
            // ignore
        if (resource != null) {
            // determine resource type
            int type = resource.getTypeId();
            if (CmsResourceTypeJsp.isJspTypeId(type)) {
                // JSP file
                return ;
            if (CmsResourceTypeXmlContent.isXmlContent(resource) || CmsResourceTypeXmlPage.isXmlPage(resource)) {
                // XML content file or XML page file
                return ;
            // all other files will be matched according to their suffix
            int dotIndex = getParamResource().lastIndexOf('.');
            if (dotIndex != -1) {
                String suffix = getParamResource().substring(dotIndex + 1);
                if (CmsStringUtil.isNotEmpty(suffix)) {
                    // there is a suffix, determine matching syntax highlighting
                    int typeIndex = .indexOf(suffix.toLowerCase());
                    if (typeIndex != -1) {
                        return .get(typeIndex);
        // return HTML type as default
        return ;

    protected void initMessages() {
        // TODO: Auto-generated method stub
New to GrepCode? Check out our FAQ X