001 /* 002 * Licensed under the Apache License, Version 2.0 (the "License"); 003 * you may not use this file except in compliance with the License. 004 * You may obtain a copy of the License at 005 * 006 * http://www.apache.org/licenses/LICENSE-2.0 007 * 008 * Unless required by applicable law or agreed to in writing, software 009 * distributed under the License is distributed on an "AS IS" BASIS, 010 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 011 * See the License for the specific language governing permissions and 012 * limitations under the License. 013 * 014 * See the NOTICE file distributed with this work for additional 015 * information regarding copyright ownership. 016 */ 017 018 package com.osbcp.cssparser; 019 020 /** 021 * An exception that is thrown when the CSS parser finds a character it shouldn't have. 022 * 023 * @author <a href="mailto:christoffer@christoffer.me">Christoffer Pettersson</a> 024 */ 025 026 public class IncorrectFormatException extends Exception { 027 028 private static final long serialVersionUID = 1L; 029 030 private ErrorCode errorCode; 031 032 /** 033 * Creates a new IncorrectFormatExeption with an error message; 034 * 035 * @param errorCode S unique error code associated with the error. 036 * @param message Error message describing the problem. 037 */ 038 039 IncorrectFormatException(final ErrorCode errorCode, final String message) { 040 super(message); 041 this.errorCode = errorCode; 042 } 043 044 /** 045 * Returns a unique error code associated with the error. 046 * 047 * @return A unique error code associated with the error. 048 */ 049 050 public ErrorCode getErrorCode() { 051 return errorCode; 052 } 053 054 /** 055 * List of unique error codes. 056 * 057 * @author <a href="mailto:christoffer@christoffer.me">Christoffer Pettersson</a> 058 */ 059 060 public enum ErrorCode { 061 062 /** 063 * When the parse founds a semicolon ; when reading the property name. 064 */ 065 FOUND_SEMICOLON_WHEN_READING_PROPERTY_NAME, 066 067 /** 068 * When the parse founds an end bracket } before the value's semicolon ; ending. 069 */ 070 FOUND_END_BRACKET_BEFORE_SEMICOLON, 071 072 /** 073 * When the parse founds a colon , before reading a real selector name. 074 */ 075 FOUND_COLON_WHEN_READING_SELECTOR_NAME; 076 077 } 078 079 }