View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements. See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache license, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License. You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the license for the specific language governing permissions and
15   * limitations under the license.
16   */
17  package org.apache.logging.log4j.core.util;
18  
19  import java.util.ArrayList;
20  import java.util.List;
21  
22  /**
23   *
24   */
25  public enum ExtensionLanguageMapping {
26      JS("js", "JavaScript"), JAVASCRIPT("javascript", "JavaScript"), GVY("gvy", "Groovy"),
27      GROOVY("groovy", "Groovy"), BSH("bsh", "beanshell"), BEANSHELL("beanshell", "beanshell"),
28      JY("jy", "jython"), JYTHON("jython", "jython"), FTL("ftl", "freemarker"),
29      FREEMARKER("freemarker", "freemarker"), VM("vm", "velocity"), VELOCITY("velocity", "velocity"),
30      AWK("awk", "awk"), EJS("ejs", "ejs"), TCL("tcl", "tcl"), HS("hs", "jaskell"), JELLY("jelly", "jelly"),
31      JEP("jep", "jep"), JEXL("jexl", "jexl"), JEXL2("jexl2", "jexl2"),
32      RB("rb", "ruby"), RUBY("ruby", "ruby"), JUDO("judo", "judo"), JUDI("judi", "judo"), SCALA("scala", "scala"),
33      CLJ("clj", "Clojure");
34  
35  
36      private final String extension;
37      private final String language;
38  
39      ExtensionLanguageMapping(final String extension, final String language) {
40          this.extension = extension;
41          this.language = language;
42      }
43  
44      public String getExtension() {
45          return this.extension;
46      }
47  
48      public String getLanguage() {
49          return this.language;
50      }
51  
52      public static ExtensionLanguageMapping getByExtension(final String extension) {
53          for (final ExtensionLanguageMapping mapping : values()) {
54              if (mapping.extension.equals(extension)) {
55                  return mapping;
56              }
57          }
58          return null;
59      }
60  
61      public static List<ExtensionLanguageMapping> getByLanguage(final String language) {
62          final List<ExtensionLanguageMapping> list = new ArrayList<>();
63          for (final ExtensionLanguageMapping mapping : values()) {
64              if (mapping.language.equals(language)) {
65                  list.add(mapping);
66              }
67          }
68          return list;
69      }
70  
71  }