001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the "License");
007 * you may not use this file except in compliance with the License.
008 * You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018 /*
019 * $Id: MsgMgr.java 468645 2006-10-28 06:57:24Z minchau $
020 */
021 package org.apache.xalan.transformer;
022
023 import javax.xml.transform.ErrorListener;
024 import javax.xml.transform.SourceLocator;
025 import javax.xml.transform.TransformerException;
026
027 import org.apache.xalan.res.XSLMessages;
028
029 import org.w3c.dom.Node;
030
031 /**
032 * This class will manage error messages, warning messages, and other types of
033 * message events.
034 */
035 public class MsgMgr
036 {
037
038 /**
039 * Create a message manager object.
040 *
041 * @param transformer non transformer instance
042 */
043 public MsgMgr(TransformerImpl transformer)
044 {
045 m_transformer = transformer;
046 }
047
048 /** Transformer instance */
049 private TransformerImpl m_transformer;
050
051 /**
052 * Warn the user of a problem.
053 * This is public for access by extensions.
054 *
055 * @param msg The message text to issue
056 * @param terminate Flag indicating whether to terminate this process
057 * @throws XSLProcessorException thrown if the active ProblemListener and XPathContext decide
058 * the error condition is severe enough to halt processing.
059 *
060 * @throws TransformerException
061 */
062 public void message(SourceLocator srcLctr, String msg, boolean terminate) throws TransformerException
063 {
064
065 ErrorListener errHandler = m_transformer.getErrorListener();
066
067 if (null != errHandler)
068 {
069 errHandler.warning(new TransformerException(msg, srcLctr));
070 }
071 else
072 {
073 if (terminate)
074 throw new TransformerException(msg, srcLctr);
075 else
076 System.out.println(msg);
077 }
078 }
079
080 /**
081 * Warn the user of a problem.
082 *
083 * @param msg Message text to issue
084 * @throws XSLProcessorException thrown if the active ProblemListener and XPathContext decide
085 * the error condition is severe enough to halt processing.
086 *
087 * @throws TransformerException
088 * @xsl.usage internal
089 */
090 public void warn(SourceLocator srcLctr, String msg) throws TransformerException
091 {
092 warn(srcLctr, null, null, msg, null);
093 }
094
095 /**
096 * Warn the user of a problem.
097 *
098 * @param msg Message text to issue
099 * @param args Arguments to pass to the message
100 * @throws XSLProcessorException thrown if the active ProblemListener and XPathContext decide
101 * the error condition is severe enough to halt processing.
102 *
103 * @throws TransformerException
104 * @xsl.usage internal
105 */
106 public void warn(SourceLocator srcLctr, String msg, Object[] args) throws TransformerException
107 {
108 warn(srcLctr, null, null, msg, args);
109 }
110
111 /**
112 * Warn the user of a problem.
113 *
114 *
115 * @param styleNode Stylesheet node
116 * @param sourceNode Source tree node
117 * @param msg Message text to issue
118 * @throws XSLProcessorException thrown if the active ProblemListener and XPathContext decide
119 * the error condition is severe enough to halt processing.
120 *
121 * @throws TransformerException
122 * @xsl.usage internal
123 */
124 public void warn(SourceLocator srcLctr, Node styleNode, Node sourceNode, String msg)
125 throws TransformerException
126 {
127 warn(srcLctr, styleNode, sourceNode, msg, null);
128 }
129
130 /**
131 * Warn the user of a problem.
132 *
133 * @param styleNode Stylesheet node
134 * @param sourceNode Source tree node
135 * @param msg Message text to issue
136 * @param args Arguments to pass to the message
137 * @throws XSLProcessorException thrown if the active ProblemListener and XPathContext decide
138 * the error condition is severe enough to halt processing.
139 *
140 * @throws TransformerException
141 * @xsl.usage internal
142 */
143 public void warn(SourceLocator srcLctr, Node styleNode, Node sourceNode, String msg, Object args[])
144 throws TransformerException
145 {
146
147 String formattedMsg = XSLMessages.createWarning(msg, args);
148 ErrorListener errHandler = m_transformer.getErrorListener();
149
150 if (null != errHandler)
151 errHandler.warning(new TransformerException(formattedMsg, srcLctr));
152 else
153 System.out.println(formattedMsg);
154 }
155
156 /* This method is not properly i18nized. We need to use the following method
157 * Tell the user of an error, and probably throw an
158 * exception.
159 *
160 * @param msg Message text to issue
161 * @throws XSLProcessorException thrown if the active ProblemListener and XPathContext decide
162 * the error condition is severe enough to halt processing.
163 *
164 * @throws TransformerException
165 *
166 public void error(SourceLocator srcLctr, String msg) throws TransformerException
167 {
168
169 // Locator locator = m_stylesheetLocatorStack.isEmpty()
170 // ? null :
171 // ((Locator)m_stylesheetLocatorStack.peek());
172 // Locator locator = null;
173 ErrorListener errHandler = m_transformer.getErrorListener();
174
175 if (null != errHandler)
176 errHandler.fatalError(new TransformerException(msg, srcLctr));
177 else
178 throw new TransformerException(msg, srcLctr);
179 }
180
181 * @xsl.usage internal
182 */
183
184 /**
185 * Tell the user of an error, and probably throw an
186 * exception.
187 *
188 * @param msg Message text to issue
189 * @throws XSLProcessorException thrown if the active ProblemListener and XPathContext decide
190 * the error condition is severe enough to halt processing.
191 *
192 * @throws TransformerException
193 * @xsl.usage internal
194 */
195 public void error(SourceLocator srcLctr, String msg) throws TransformerException
196 {
197 error(srcLctr, null, null, msg, null);
198 }
199
200 /**
201 * Tell the user of an error, and probably throw an
202 * exception.
203 *
204 * @param msg Message text to issue
205 * @param args Arguments to be passed to the message
206 * @throws XSLProcessorException thrown if the active ProblemListener and XPathContext decide
207 * the error condition is severe enough to halt processing.
208 *
209 * @throws TransformerException
210 * @xsl.usage internal
211 */
212 public void error(SourceLocator srcLctr, String msg, Object[] args) throws TransformerException
213 {
214 error(srcLctr, null, null, msg, args);
215 }
216
217 /**
218 * Tell the user of an error, and probably throw an
219 * exception.
220 *
221 * @param msg Message text to issue
222 * @param e Exception to throw
223 * @throws XSLProcessorException thrown if the active ProblemListener and XPathContext decide
224 * the error condition is severe enough to halt processing.
225 *
226 * @throws TransformerException
227 * @xsl.usage internal
228 */
229 public void error(SourceLocator srcLctr, String msg, Exception e) throws TransformerException
230 {
231 error(srcLctr, msg, null, e);
232 }
233
234 /**
235 * Tell the user of an error, and probably throw an
236 * exception.
237 *
238 * @param msg Message text to issue
239 * @param args Arguments to use in message
240 * @param e Exception to throw
241 * @throws XSLProcessorException thrown if the active ProblemListener and XPathContext decide
242 * the error condition is severe enough to halt processing.
243 *
244 * @throws TransformerException
245 * @xsl.usage internal
246 */
247 public void error(SourceLocator srcLctr, String msg, Object args[], Exception e) throws TransformerException
248 {
249
250 //msg = (null == msg) ? XSLTErrorResources.ER_PROCESSOR_ERROR : msg;
251 String formattedMsg = XSLMessages.createMessage(msg, args);
252
253 // Locator locator = m_stylesheetLocatorStack.isEmpty()
254 // ? null :
255 // ((Locator)m_stylesheetLocatorStack.peek());
256 // Locator locator = null;
257 ErrorListener errHandler = m_transformer.getErrorListener();
258
259 if (null != errHandler)
260 errHandler.fatalError(new TransformerException(formattedMsg, srcLctr));
261 else
262 throw new TransformerException(formattedMsg, srcLctr);
263 }
264
265 /**
266 * Tell the user of an error, and probably throw an
267 * exception.
268 *
269 * @param styleNode Stylesheet node
270 * @param sourceNode Source tree node
271 * @param msg Message text to issue
272 * @throws XSLProcessorException thrown if the active ProblemListener and XPathContext decide
273 * the error condition is severe enough to halt processing.
274 *
275 * @throws TransformerException
276 * @xsl.usage internal
277 */
278 public void error(SourceLocator srcLctr, Node styleNode, Node sourceNode, String msg)
279 throws TransformerException
280 {
281 error(srcLctr, styleNode, sourceNode, msg, null);
282 }
283
284 /**
285 * Tell the user of an error, and probably throw an
286 * exception.
287 *
288 * @param styleNode Stylesheet node
289 * @param sourceNode Source tree node
290 * @param msg Message text to issue
291 * @param args Arguments to use in message
292 * @throws XSLProcessorException thrown if the active ProblemListener and XPathContext decide
293 * the error condition is severe enough to halt processing.
294 *
295 * @throws TransformerException
296 * @xsl.usage internal
297 */
298 public void error(SourceLocator srcLctr, Node styleNode, Node sourceNode, String msg, Object args[])
299 throws TransformerException
300 {
301
302 String formattedMsg = XSLMessages.createMessage(msg, args);
303
304 // Locator locator = m_stylesheetLocatorStack.isEmpty()
305 // ? null :
306 // ((Locator)m_stylesheetLocatorStack.peek());
307 // Locator locator = null;
308 ErrorListener errHandler = m_transformer.getErrorListener();
309
310 if (null != errHandler)
311 errHandler.fatalError(new TransformerException(formattedMsg, srcLctr));
312 else
313 throw new TransformerException(formattedMsg, srcLctr);
314 }
315 }