KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xalan > transformer > MsgMgr


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 /*
17  * $Id: MsgMgr.java,v 1.16 2004/02/16 20:41:30 minchau Exp $
18  */

19 package org.apache.xalan.transformer;
20
21 import javax.xml.transform.ErrorListener JavaDoc;
22 import javax.xml.transform.SourceLocator JavaDoc;
23 import javax.xml.transform.TransformerException JavaDoc;
24
25 import org.apache.xalan.res.XSLMessages;
26
27 import org.w3c.dom.Node JavaDoc;
28
29 /**
30  * This class will manage error messages, warning messages, and other types of
31  * message events.
32  */

33 public class MsgMgr
34 {
35
36   /**
37    * Create a message manager object.
38    *
39    * @param transformer non transformer instance
40    */

41   public MsgMgr(TransformerImpl transformer)
42   {
43     m_transformer = transformer;
44   }
45
46   /** Transformer instance */
47   private TransformerImpl m_transformer;
48
49   /**
50    * Warn the user of a problem.
51    * This is public for access by extensions.
52    *
53    * @param msg The message text to issue
54    * @param terminate Flag indicating whether to terminate this process
55    * @throws XSLProcessorException thrown if the active ProblemListener and XPathContext decide
56    * the error condition is severe enough to halt processing.
57    *
58    * @throws TransformerException
59    */

60   public void message(SourceLocator JavaDoc srcLctr, String JavaDoc msg, boolean terminate) throws TransformerException JavaDoc
61   {
62
63     ErrorListener JavaDoc errHandler = m_transformer.getErrorListener();
64
65     if (null != errHandler)
66     {
67       errHandler.warning(new TransformerException JavaDoc(msg, srcLctr));
68     }
69     else
70     {
71       if (terminate)
72         throw new TransformerException JavaDoc(msg, srcLctr);
73       else
74         System.out.println(msg);
75     }
76   }
77
78   /**
79    * Warn the user of a problem.
80    *
81    * @param msg Message text to issue
82    * @throws XSLProcessorException thrown if the active ProblemListener and XPathContext decide
83    * the error condition is severe enough to halt processing.
84    *
85    * @throws TransformerException
86    * @xsl.usage internal
87    */

88   public void warn(SourceLocator JavaDoc srcLctr, String JavaDoc msg) throws TransformerException JavaDoc
89   {
90     warn(srcLctr, null, null, msg, null);
91   }
92
93   /**
94    * Warn the user of a problem.
95    *
96    * @param msg Message text to issue
97    * @param args Arguments to pass to the message
98    * @throws XSLProcessorException thrown if the active ProblemListener and XPathContext decide
99    * the error condition is severe enough to halt processing.
100    *
101    * @throws TransformerException
102    * @xsl.usage internal
103    */

104   public void warn(SourceLocator JavaDoc srcLctr, String JavaDoc msg, Object JavaDoc[] args) throws TransformerException JavaDoc
105   {
106     warn(srcLctr, null, null, msg, args);
107   }
108
109   /**
110    * Warn the user of a problem.
111    *
112    *
113    * @param styleNode Stylesheet node
114    * @param sourceNode Source tree node
115    * @param msg Message text to issue
116    * @throws XSLProcessorException thrown if the active ProblemListener and XPathContext decide
117    * the error condition is severe enough to halt processing.
118    *
119    * @throws TransformerException
120    * @xsl.usage internal
121    */

122   public void warn(SourceLocator JavaDoc srcLctr, Node JavaDoc styleNode, Node JavaDoc sourceNode, String JavaDoc msg)
123           throws TransformerException JavaDoc
124   {
125     warn(srcLctr, styleNode, sourceNode, msg, null);
126   }
127
128   /**
129    * Warn the user of a problem.
130    *
131    * @param styleNode Stylesheet node
132    * @param sourceNode Source tree node
133    * @param msg Message text to issue
134    * @param args Arguments to pass to the message
135    * @throws XSLProcessorException thrown if the active ProblemListener and XPathContext decide
136    * the error condition is severe enough to halt processing.
137    *
138    * @throws TransformerException
139    * @xsl.usage internal
140    */

141   public void warn(SourceLocator JavaDoc srcLctr, Node JavaDoc styleNode, Node JavaDoc sourceNode, String JavaDoc msg, Object JavaDoc args[])
142           throws TransformerException JavaDoc
143   {
144
145     String JavaDoc formattedMsg = XSLMessages.createWarning(msg, args);
146     ErrorListener JavaDoc errHandler = m_transformer.getErrorListener();
147
148     if (null != errHandler)
149       errHandler.warning(new TransformerException JavaDoc(formattedMsg, srcLctr));
150     else
151       System.out.println(formattedMsg);
152   }
153
154   /* This method is not properly i18nized. We need to use the following method
155    * Tell the user of an error, and probably throw an
156    * exception.
157    *
158    * @param msg Message text to issue
159    * @throws XSLProcessorException thrown if the active ProblemListener and XPathContext decide
160    * the error condition is severe enough to halt processing.
161    *
162    * @throws TransformerException
163    *
164   public void error(SourceLocator srcLctr, String msg) throws TransformerException
165   {
166
167     // Locator locator = m_stylesheetLocatorStack.isEmpty()
168     // ? null :
169     // ((Locator)m_stylesheetLocatorStack.peek());
170     // Locator locator = null;
171     ErrorListener errHandler = m_transformer.getErrorListener();
172
173     if (null != errHandler)
174       errHandler.fatalError(new TransformerException(msg, srcLctr));
175     else
176       throw new TransformerException(msg, srcLctr);
177   }
178
179  * @xsl.usage internal
180  */

181
182   /**
183    * Tell the user of an error, and probably throw an
184    * exception.
185    *
186    * @param msg Message text to issue
187    * @throws XSLProcessorException thrown if the active ProblemListener and XPathContext decide
188    * the error condition is severe enough to halt processing.
189    *
190    * @throws TransformerException
191    * @xsl.usage internal
192    */

193   public void error(SourceLocator JavaDoc srcLctr, String JavaDoc msg) throws TransformerException JavaDoc
194   {
195     error(srcLctr, null, null, msg, null);
196   }
197
198   /**
199    * Tell the user of an error, and probably throw an
200    * exception.
201    *
202    * @param msg Message text to issue
203    * @param args Arguments to be passed to the message
204    * @throws XSLProcessorException thrown if the active ProblemListener and XPathContext decide
205    * the error condition is severe enough to halt processing.
206    *
207    * @throws TransformerException
208    * @xsl.usage internal
209    */

210   public void error(SourceLocator JavaDoc srcLctr, String JavaDoc msg, Object JavaDoc[] args) throws TransformerException JavaDoc
211   {
212     error(srcLctr, null, null, msg, args);
213   }
214
215   /**
216    * Tell the user of an error, and probably throw an
217    * exception.
218    *
219    * @param msg Message text to issue
220    * @param e Exception to throw
221    * @throws XSLProcessorException thrown if the active ProblemListener and XPathContext decide
222    * the error condition is severe enough to halt processing.
223    *
224    * @throws TransformerException
225    * @xsl.usage internal
226    */

227   public void error(SourceLocator JavaDoc srcLctr, String JavaDoc msg, Exception JavaDoc e) throws TransformerException JavaDoc
228   {
229     error(srcLctr, msg, null, e);
230   }
231
232   /**
233    * Tell the user of an error, and probably throw an
234    * exception.
235    *
236    * @param msg Message text to issue
237    * @param args Arguments to use in message
238    * @param e Exception to throw
239    * @throws XSLProcessorException thrown if the active ProblemListener and XPathContext decide
240    * the error condition is severe enough to halt processing.
241    *
242    * @throws TransformerException
243    * @xsl.usage internal
244    */

245   public void error(SourceLocator JavaDoc srcLctr, String JavaDoc msg, Object JavaDoc args[], Exception JavaDoc e) throws TransformerException JavaDoc
246   {
247
248     //msg = (null == msg) ? XSLTErrorResources.ER_PROCESSOR_ERROR : msg;
249
String JavaDoc formattedMsg = XSLMessages.createMessage(msg, args);
250
251     // Locator locator = m_stylesheetLocatorStack.isEmpty()
252
// ? null :
253
// ((Locator)m_stylesheetLocatorStack.peek());
254
// Locator locator = null;
255
ErrorListener JavaDoc errHandler = m_transformer.getErrorListener();
256
257     if (null != errHandler)
258       errHandler.fatalError(new TransformerException JavaDoc(formattedMsg, srcLctr));
259     else
260       throw new TransformerException JavaDoc(formattedMsg, srcLctr);
261   }
262
263   /**
264    * Tell the user of an error, and probably throw an
265    * exception.
266    *
267    * @param styleNode Stylesheet node
268    * @param sourceNode Source tree node
269    * @param msg Message text to issue
270    * @throws XSLProcessorException thrown if the active ProblemListener and XPathContext decide
271    * the error condition is severe enough to halt processing.
272    *
273    * @throws TransformerException
274    * @xsl.usage internal
275    */

276   public void error(SourceLocator JavaDoc srcLctr, Node JavaDoc styleNode, Node JavaDoc sourceNode, String JavaDoc msg)
277           throws TransformerException JavaDoc
278   {
279     error(srcLctr, styleNode, sourceNode, msg, null);
280   }
281
282   /**
283    * Tell the user of an error, and probably throw an
284    * exception.
285    *
286    * @param styleNode Stylesheet node
287    * @param sourceNode Source tree node
288    * @param msg Message text to issue
289    * @param args Arguments to use in message
290    * @throws XSLProcessorException thrown if the active ProblemListener and XPathContext decide
291    * the error condition is severe enough to halt processing.
292    *
293    * @throws TransformerException
294    * @xsl.usage internal
295    */

296   public void error(SourceLocator JavaDoc srcLctr, Node JavaDoc styleNode, Node JavaDoc sourceNode, String JavaDoc msg, Object JavaDoc args[])
297           throws TransformerException JavaDoc
298   {
299
300     String JavaDoc formattedMsg = XSLMessages.createMessage(msg, args);
301
302     // Locator locator = m_stylesheetLocatorStack.isEmpty()
303
// ? null :
304
// ((Locator)m_stylesheetLocatorStack.peek());
305
// Locator locator = null;
306
ErrorListener JavaDoc errHandler = m_transformer.getErrorListener();
307
308     if (null != errHandler)
309       errHandler.fatalError(new TransformerException JavaDoc(formattedMsg, srcLctr));
310     else
311       throw new TransformerException JavaDoc(formattedMsg, srcLctr);
312   }
313 }
314
Popular Tags