LibreOffice Module xmerge (master) 1
OfficeDocumentException.java
Go to the documentation of this file.
1/*
2 * This file is part of the LibreOffice project.
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 *
8 * This file incorporates work covered by the following license notice:
9 *
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
17 */
18
19package org.openoffice.xmerge.converter.xml;
20
21import java.io.IOException;
22
23import org.xml.sax.SAXException;
24import org.xml.sax.SAXParseException;
25
27
34public final class OfficeDocumentException extends IOException {
35
41 public OfficeDocumentException(SAXException e) {
42 super(constructMessage(e));
43 if (e.getException() != null) {
44 initCause(e.getException());
45 } else {
46 initCause(e);
47 }
48 }
49
50 private static String constructMessage(SAXException e) {
51 StringBuffer message = new StringBuffer();
52 if (e instanceof SAXParseException) {
53 String msgParseError =
54 Resources.getInstance().getString("PARSE_ERROR");
55 String msgLine =
57 String msgColumn =
59 String msgPublicId =
60 Resources.getInstance().getString("PUBLIC_ID");
61 String msgSystemId =
62 Resources.getInstance().getString("SYSTEM_ID");
63 SAXParseException spe = (SAXParseException) e;
64 message.append(msgParseError);
65 message.append(": ");
66 message.append(msgLine);
67 message.append(": ");
68 message.append(spe.getLineNumber());
69 message.append(", ");
70 message.append(msgColumn);
71 message.append(": ");
72 message.append(spe.getColumnNumber());
73 message.append(", ");
74 message.append(msgSystemId);
75 message.append(": ");
76 message.append(spe.getSystemId());
77 message.append(", ");
78 message.append(msgPublicId);
79 message.append(": ");
80 message.append(spe.getPublicId());
81 message.append("\n");
82 }
83
84 // if there exists an embedded exception
85 Exception ex = e.getException();
86 if (ex != null) {
87 message.append(ex.getMessage());
88 }
89 return message.toString();
90 }
91
97 public OfficeDocumentException(String s) {
98 super(s);
99 }
100
107 public OfficeDocumentException(Exception e) {
108 super(e.getMessage());
109 initCause(e);
110 }
111
112}
Used by OfficeDocument to encapsulate exceptions.
OfficeDocumentException(Exception e)
Constructor, creates exception with the message corresponding to the message value of the provided ex...
OfficeDocumentException(String s)
Constructor, creates exception with provided message.
OfficeDocumentException(SAXException e)
Constructor, capturing additional information from the SAXException.
Provides a singleton resource class for converter messages.
Definition: Resources.java:38
static synchronized Resources getInstance()
This method returns the singleton instance of this class.
Definition: Resources.java:47
String getString(String key)
This method returns the corresponding String given the key.
Definition: Resources.java:71
@ Exception
Provides general purpose utilities.
Provides interfaces for converting between two Document formats, and supports a "merge" interface for...
Definition: Convert.java:19