KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xalan > templates > ElemMessage


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: ElemMessage.java,v 1.17 2004/02/16 20:32:33 minchau Exp $
18  */

19 package org.apache.xalan.templates;
20
21 import javax.xml.transform.TransformerException JavaDoc;
22
23 import org.apache.xalan.res.XSLMessages;
24 import org.apache.xalan.res.XSLTErrorResources;
25 import org.apache.xalan.transformer.TransformerImpl;
26
27 /**
28  * Implement xsl:message.
29  * <pre>
30  * <!ELEMENT xsl:message %template;>
31  * <!ATTLIST xsl:message
32  * %space-att;
33  * terminate (yes|no) "no"
34  * >
35  * </pre>
36  * @see <a HREF="http://www.w3.org/TR/xslt#message">message in XSLT Specification</a>
37  * @xsl.usage advanced
38  */

39 public class ElemMessage extends ElemTemplateElement
40 {
41
42   /**
43    * If the terminate attribute has the value yes, then the
44    * XSLT transformer should terminate processing after sending
45    * the message. The default value is no.
46    * @serial
47    */

48   private boolean m_terminate = Constants.ATTRVAL_NO; // default value
49

50   /**
51    * Set the "terminate" attribute.
52    * If the terminate attribute has the value yes, then the
53    * XSLT transformer should terminate processing after sending
54    * the message. The default value is no.
55    *
56    * @param v Value to set for "terminate" attribute.
57    */

58   public void setTerminate(boolean v)
59   {
60     m_terminate = v;
61   }
62
63   /**
64    * Get the "terminate" attribute.
65    * If the terminate attribute has the value yes, then the
66    * XSLT transformer should terminate processing after sending
67    * the message. The default value is no.
68    *
69    * @return value of "terminate" attribute.
70    */

71   public boolean getTerminate()
72   {
73     return m_terminate;
74   }
75
76   /**
77    * Get an int constant identifying the type of element.
78    * @see org.apache.xalan.templates.Constants
79    *
80    * @return The token ID for this element
81    */

82   public int getXSLToken()
83   {
84     return Constants.ELEMNAME_MESSAGE;
85   }
86
87   /**
88    * Return the node name.
89    *
90    * @return name of the element
91    */

92   public String JavaDoc getNodeName()
93   {
94     return Constants.ELEMNAME_MESSAGE_STRING;
95   }
96
97   /**
98    * Send a message to diagnostics.
99    * The xsl:message instruction sends a message in a way that
100    * is dependent on the XSLT transformer. The content of the xsl:message
101    * instruction is a template. The xsl:message is instantiated by
102    * instantiating the content to create an XML fragment. This XML
103    * fragment is the content of the message.
104    *
105    * @param transformer non-null reference to the the current transform-time state.
106    * @param sourceNode non-null reference to the <a HREF="http://www.w3.org/TR/xslt#dt-current-node">current source node</a>.
107    * @param mode reference, which may be null, to the <a HREF="http://www.w3.org/TR/xslt#modes">current mode</a>.
108    *
109    * @throws TransformerException
110    */

111   public void execute(
112           TransformerImpl transformer)
113             throws TransformerException JavaDoc
114   {
115
116     if (TransformerImpl.S_DEBUG)
117       transformer.getTraceManager().fireTraceEvent(this);
118
119     String JavaDoc data = transformer.transformToString(this);
120
121     transformer.getMsgMgr().message(this, data, m_terminate);
122     
123     if(m_terminate)
124       transformer.getErrorListener().fatalError(new TransformerException JavaDoc(XSLMessages.createMessage(XSLTErrorResources.ER_STYLESHEET_DIRECTED_TERMINATION, null))); //"Stylesheet directed termination"));
125

126     if (TransformerImpl.S_DEBUG)
127       transformer.getTraceManager().fireTraceEndEvent(this);
128   }
129 }
130
Popular Tags