1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package org.openoffice.xmerge.converter.xml; 25 26 import java.io.IOException; 27 28 import org.xml.sax.SAXException; 29 import org.xml.sax.SAXParseException; 30 31 import org.openoffice.xmerge.util.Resources; 32 33 /** 34 * Used by OfficeDocument to encapsulate exceptions. It will add 35 * more details to the message string if it is of type 36 * <code>SAXParseException</code>. 37 * 38 * @author Herbie Ong 39 */ 40 41 public final class OfficeDocumentException extends IOException { 42 43 StringBuffer message = null; 44 45 46 /** 47 * Constructor, capturing additional information from the 48 * <code>SAXException</code>. 49 * 50 * @param e The <code>SAXException</code>. 51 */ OfficeDocumentException(SAXException e)52 public OfficeDocumentException(SAXException e) { 53 super(e.toString()); 54 message = new StringBuffer(); 55 if (e instanceof SAXParseException) { 56 String msgParseError = 57 Resources.getInstance().getString("PARSE_ERROR"); 58 String msgLine = 59 Resources.getInstance().getString("LINE"); 60 String msgColumn = 61 Resources.getInstance().getString("COLUMN"); 62 String msgPublicId = 63 Resources.getInstance().getString("PUBLIC_ID"); 64 String msgSystemId = 65 Resources.getInstance().getString("SYSTEM_ID"); 66 SAXParseException spe = (SAXParseException) e; 67 message.append(msgParseError); 68 message.append(": "); 69 message.append(msgLine); 70 message.append(": "); 71 message.append(spe.getLineNumber()); 72 message.append(", "); 73 message.append(msgColumn); 74 message.append(": "); 75 message.append(spe.getColumnNumber()); 76 message.append(", "); 77 message.append(msgSystemId); 78 message.append(": "); 79 message.append(spe.getSystemId()); 80 message.append(", "); 81 message.append(msgPublicId); 82 message.append(": "); 83 message.append(spe.getPublicId()); 84 message.append("\n"); 85 } 86 87 // if there exists an embedded exception 88 Exception ex = e.getException(); 89 if (ex != null) { 90 message.append(ex.getMessage()); 91 } 92 } 93 94 95 /** 96 * Constructor, creates exception with provided message. 97 * 98 * @param s Message value for the exception. 99 */ OfficeDocumentException(String s)100 public OfficeDocumentException(String s) { 101 super(s); 102 } 103 104 105 /** 106 * Constructor, creates exception with the message 107 * corresponding to the message value of the provided 108 * exception. 109 * 110 * @param e The Exception. 111 */ OfficeDocumentException(Exception e)112 public OfficeDocumentException(Exception e) { 113 super(e.getMessage()); 114 } 115 116 117 /** 118 * Returns the message value for the <code>Exception</code>. 119 * 120 * @return The message value for the <code>Exception</code>. 121 */ getMessage()122 public String getMessage() { 123 return message.toString() + super.getMessage(); 124 } 125 } 126 127