1 package org.apache.maven.doxia.parser; 2 3 /* 4 * Licensed to the Apache Software Foundation (ASF) under one 5 * or more contributor license agreements. See the NOTICE file 6 * distributed with this work for additional information 7 * regarding copyright ownership. The ASF licenses this file 8 * to you under the Apache License, Version 2.0 (the 9 * "License"); you may not use this file except in compliance 10 * with the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, 15 * software distributed under the License is distributed on an 16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 * KIND, either express or implied. See the License for the 18 * specific language governing permissions and limitations 19 * under the License. 20 */ 21 22 /** 23 * Encapsulate a Doxia parse error. 24 * 25 * @author <a href="mailto:jason@maven.org">Jason van Zyl</a> 26 * @since 1.0 27 */ 28 public class ParseException 29 extends Exception 30 { 31 /** serialVersionUID */ 32 static final long serialVersionUID = 295967936746221567L; 33 34 /** The file that caused the ParseException. */ 35 private String fileName; 36 37 /** Line number where the parse exception occurred. */ 38 private int lineNumber; 39 40 /** Column number where the parse exception occurred. */ 41 private int columnNumber; 42 43 /** 44 * Construct a new <code>ParseException</code> with the specified detail message. 45 * <br> 46 * <b>Note</b>: no line or column number will be used. 47 * 48 * @param message The detailed message. 49 * This can later be retrieved by the <code>Throwable.getMessage()</code> method. 50 */ 51 public ParseException( String message ) 52 { 53 this( null, message, null, -1, -1 ); 54 } 55 56 /** 57 * Construct a new <code>ParseException</code> with the specified detail message and cause. 58 * <br> 59 * <b>Note</b>: no line or column number will be used. 60 * 61 * @param message The detailed message. 62 * This can later be retrieved by the <code>Throwable.getMessage()</code> method. 63 * @param e the cause. This can be retrieved later by the <code>Throwable.getCause()</code> method. 64 * (A null value is permitted, and indicates that the cause is nonexistent or unknown.) 65 */ 66 public ParseException( String message, Exception e ) 67 { 68 this( e, message, null, -1, -1 ); 69 } 70 71 /** 72 * Construct a new <code>ParseException</code> with the specified detail message, 73 * line number and column number. 74 * 75 * @param message The detailed message. 76 * This can later be retrieved by the <code>Throwable.getMessage()</code> method. 77 * @param line The line number where the parsing failed. 78 * This can later be retrieved by the getLineNumber() method. 79 * @param column The column number where the parsing failed. 80 * This can later be retrieved by the getColumnNumber() method. 81 * @since 1.1 82 */ 83 public ParseException( String message, int line, int column ) 84 { 85 this( null, message, null, line, column ); 86 } 87 88 /** 89 * Construct a new <code>ParseException</code> with the specified detail message and cause, 90 * line number and column number. 91 * 92 * @param message The detailed message. 93 * This can later be retrieved by the <code>Throwable.getMessage()</code> method. 94 * @param e the cause. This can be retrieved later by the <code>Throwable.getCause()</code> method. 95 * (A null value is permitted, and indicates that the cause is nonexistent or unknown.) 96 * @param line The line number where the parsing failed. 97 * This can later be retrieved by the getLineNumber() method. 98 * @param column The column number where the parsing failed. 99 * This can later be retrieved by the getColumnNumber() method. 100 * @since 1.1 101 */ 102 public ParseException( String message, Exception e, int line, int column ) 103 { 104 this( e, message, null, line, column ); 105 } 106 107 /** 108 * Constructs a new exception with the specified cause. The error message is 109 * (cause == null ? null : cause.toString() ). 110 * 111 * @param e the cause. This can be retrieved later by the <code>Throwable.getCause()</code> method. 112 * (A null value is permitted, and indicates that the cause is nonexistent or unknown.) 113 * @deprecated Using {@link #ParseException(Exception, int, int)} to specify the line and column number. 114 */ 115 public ParseException( Exception e ) 116 { 117 this( e, null, null, -1, -1 ); 118 } 119 120 /** 121 * Constructs a new exception with the specified cause, line number and column number. The error message is 122 * (cause == null ? null : cause.toString() ). 123 * 124 * @param e the cause. This can be retrieved later by the <code>Throwable.getCause()</code> method. 125 * (A null value is permitted, and indicates that the cause is nonexistent or unknown.) 126 * @param line The line number where the parsing failed. 127 * This can later be retrieved by the getLineNumber() method. 128 * @param column The column number where the parsing failed. 129 * This can later be retrieved by the getColumnNumber() method. 130 * @since 1.1 131 */ 132 public ParseException( Exception e, int line, int column ) 133 { 134 this( e, null, null, line, column ); 135 } 136 137 /** 138 * Construct a new <code>ParseException</code> with the specified cause, 139 * filename and linenumber. 140 * 141 * @param e the cause. This can be retrieved later by the <code>Throwable.getCause()</code> method. 142 * (A null value is permitted, and indicates that the cause is nonexistent or unknown.) 143 * @param file Name of a file that couldn't be parsed. 144 * This can later be retrieved by the getFileName() method. 145 * @param line The line number where the parsing failed. 146 * This can later be retrieved by the getLineNumber() method. 147 * @deprecated Using {@link #ParseException(Exception, String, int, int)} to specify the column number. 148 */ 149 public ParseException( Exception e, String file, int line ) 150 { 151 this( e, null, file, line, -1 ); 152 } 153 154 /** 155 * Construct a new <code>ParseException</code> with the specified cause, 156 * filename, line number and column number. 157 * 158 * @param e the cause. This can be retrieved later by the <code>Throwable.getCause()</code> method. 159 * (A null value is permitted, and indicates that the cause is nonexistent or unknown.) 160 * @param file Name of a file that couldn't be parsed. 161 * This can later be retrieved by the getFileName() method. 162 * @param line The line number where the parsing failed. 163 * This can later be retrieved by the getLineNumber() method. 164 * @param column The column number where the parsing failed. 165 * This can later be retrieved by the getColumnNumber() method. 166 */ 167 public ParseException( Exception e, String file, int line, int column ) 168 { 169 this( e, null, file, line, column ); 170 } 171 172 /** 173 * Construct a new <code>ParseException</code> with the specified cause, detail message, 174 * filename, line number and column number. 175 * 176 * @param e the cause. This can be retrieved later by the <code>Throwable.getCause()</code> method. 177 * (A null value is permitted, and indicates that the cause is nonexistent or unknown.) 178 * @param message The detailed message. 179 * This can later be retrieved by the <code>Throwable.getMessage()</code> method. 180 * @param file Name of a file that couldn't be parsed. 181 * This can later be retrieved by the getFileName() method. 182 * @param line The line number where the parsing failed. 183 * This can later be retrieved by the getLineNumber() method. 184 * @param column The column number where the parsing failed. 185 * This can later be retrieved by the getColumnNumber() method. 186 * @since 1.1 187 */ 188 public ParseException( Exception e, String message, String file, int line, int column ) 189 { 190 super( ( message == null ) ? ( ( e == null ) ? null : e.getMessage() ) : message, e ); 191 192 this.fileName = file; 193 this.lineNumber = line; 194 this.columnNumber = column; 195 } 196 197 /** 198 * <p>Getter for the field <code>fileName</code>.</p> 199 * 200 * @return the file name that caused the <code>ParseException</code>. 201 */ 202 public String getFileName() 203 { 204 return fileName; 205 } 206 207 /** 208 * <p>Getter for the field <code>lineNumber</code>.</p> 209 * 210 * @return the line number where the <code>ParseException</code> occurred. 211 */ 212 public int getLineNumber() 213 { 214 return lineNumber; 215 } 216 217 /** 218 * <p>Getter for the field <code>columnNumber</code>.</p> 219 * 220 * @return the column number where the <code>ParseException</code> occurred. 221 * @since 1.1 222 */ 223 public int getColumnNumber() 224 { 225 return columnNumber; 226 } 227 }