1 /* 2 * Copyright 2017 LINE Corporation 3 * 4 * LINE Corporation licenses this file to you under the Apache License, 5 * version 2.0 (the "License"); you may not use this file except in compliance 6 * with the License. You may obtain a copy of the License at: 7 * 8 * https://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 * License for the specific language governing permissions and limitations 14 * under the License. 15 */ 16 package com.linecorp.centraldogma.common; 17 18 import static com.google.common.base.Strings.isNullOrEmpty; 19 20 import javax.annotation.Nullable; 21 22 import com.google.common.base.Ascii; 23 24 /** 25 * The markup language of a {@link Commit} message. 26 */ 27 public enum Markup { 28 /** 29 * Unknown markup language. 30 */ 31 UNKNOWN, 32 /** 33 * Plaintext. 34 */ 35 PLAINTEXT, 36 /** 37 * Markdown. 38 */ 39 MARKDOWN; 40 41 private final String nameLowercased; 42 43 Markup() { 44 nameLowercased = Ascii.toLowerCase(name()); 45 } 46 47 /** 48 * Returns the lower-cased name. 49 */ 50 public String nameLowercased() { 51 return nameLowercased; 52 } 53 54 /** 55 * Returns a {@link Markup} from the specified {@code value}. If none of markup is matched, 56 * this will return {@link #UNKNOWN}. 57 */ 58 public static Markup parse(@Nullable String value) { 59 if (isNullOrEmpty(value)) { 60 return UNKNOWN; 61 } 62 63 final String markup = Ascii.toUpperCase(value); 64 65 if ("PLAINTEXT".equalsIgnoreCase(markup)) { 66 return PLAINTEXT; 67 } 68 69 if ("MARKDOWN".equalsIgnoreCase(markup)) { 70 return MARKDOWN; 71 } 72 73 return UNKNOWN; 74 } 75 }