1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the  "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 /*
19  * $Id: ElemMessage.java 468643 2006-10-28 06:56:03Z minchau $
20  */
21 package org.apache.xalan.templates;
22 
23 import javax.xml.transform.TransformerException;
24 
25 import org.apache.xalan.res.XSLMessages;
26 import org.apache.xalan.res.XSLTErrorResources;
27 import org.apache.xalan.transformer.TransformerImpl;
28 
29 /**
30  * Implement xsl:message.
31  * <pre>
32  * <!ELEMENT xsl:message %template;>
33  * <!ATTLIST xsl:message
34  *   %space-att;
35  *   terminate (yes|no) "no"
36  * >
37  * </pre>
38  * @see <a href="http://www.w3.org/TR/xslt#message">message in XSLT Specification</a>
39  * @xsl.usage advanced
40  */
41 public class ElemMessage extends ElemTemplateElement
42 {
43     static final long serialVersionUID = 1530472462155060023L;
44 
45   /**
46    * If the terminate attribute has the value yes, then the
47    * XSLT transformer should terminate processing after sending
48    * the message. The default value is no.
49    * @serial
50    */
51   private boolean m_terminate = Constants.ATTRVAL_NO;  // default value
52 
53   /**
54    * Set the "terminate" attribute.
55    * If the terminate attribute has the value yes, then the
56    * XSLT transformer should terminate processing after sending
57    * the message. The default value is no.
58    *
59    * @param v Value to set for "terminate" attribute.
60    */
setTerminate(boolean v)61   public void setTerminate(boolean v)
62   {
63     m_terminate = v;
64   }
65 
66   /**
67    * Get the "terminate" attribute.
68    * If the terminate attribute has the value yes, then the
69    * XSLT transformer should terminate processing after sending
70    * the message. The default value is no.
71    *
72    * @return value of "terminate" attribute.
73    */
getTerminate()74   public boolean getTerminate()
75   {
76     return m_terminate;
77   }
78 
79   /**
80    * Get an int constant identifying the type of element.
81    * @see org.apache.xalan.templates.Constants
82    *
83    * @return The token ID for this element
84    */
getXSLToken()85   public int getXSLToken()
86   {
87     return Constants.ELEMNAME_MESSAGE;
88   }
89 
90   /**
91    * Return the node name.
92    *
93    * @return name of the element
94    */
getNodeName()95   public String getNodeName()
96   {
97     return Constants.ELEMNAME_MESSAGE_STRING;
98   }
99 
100   /**
101    * Send a message to diagnostics.
102    * The xsl:message instruction sends a message in a way that
103    * is dependent on the XSLT transformer. The content of the xsl:message
104    * instruction is a template. The xsl:message is instantiated by
105    * instantiating the content to create an XML fragment. This XML
106    * fragment is the content of the message.
107    *
108    * @param transformer non-null reference to the the current transform-time state.
109    *
110    * @throws TransformerException
111    */
execute( TransformerImpl transformer)112   public void execute(
113           TransformerImpl transformer)
114             throws TransformerException
115   {
116 
117     String data = transformer.transformToString(this);
118 
119     transformer.getMsgMgr().message(this, data, m_terminate);
120 
121     if(m_terminate)
122       transformer.getErrorListener().fatalError(new TransformerException(XSLMessages.createMessage(XSLTErrorResources.ER_STYLESHEET_DIRECTED_TERMINATION, null))); //"Stylesheet directed termination"));
123   }
124 }
125