14c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson/* 24c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * Licensed to the Apache Software Foundation (ASF) under one 34c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * or more contributor license agreements. See the NOTICE file 44c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * distributed with this work for additional information 54c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * regarding copyright ownership. The ASF licenses this file 64c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * to you under the Apache License, Version 2.0 (the "License"); 74c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * you may not use this file except in compliance with the License. 84c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * You may obtain a copy of the License at 94c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * 104c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * http://www.apache.org/licenses/LICENSE-2.0 114c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * 124c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * Unless required by applicable law or agreed to in writing, software 134c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * distributed under the License is distributed on an "AS IS" BASIS, 144c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 154c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * See the License for the specific language governing permissions and 164c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * limitations under the License. 174c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson */ 184c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson/* 194c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * $Id: ElemMessage.java 468643 2006-10-28 06:56:03Z minchau $ 204c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson */ 214c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilsonpackage org.apache.xalan.templates; 224c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson 234c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilsonimport javax.xml.transform.TransformerException; 244c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson 254c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilsonimport org.apache.xalan.res.XSLMessages; 264c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilsonimport org.apache.xalan.res.XSLTErrorResources; 274c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilsonimport org.apache.xalan.transformer.TransformerImpl; 284c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson 294c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson/** 304c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * Implement xsl:message. 314c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * <pre> 324c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * <!ELEMENT xsl:message %template;> 334c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * <!ATTLIST xsl:message 344c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * %space-att; 354c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * terminate (yes|no) "no" 364c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * > 374c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * </pre> 384c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * @see <a href="http://www.w3.org/TR/xslt#message">message in XSLT Specification</a> 394c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * @xsl.usage advanced 404c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson */ 414c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilsonpublic class ElemMessage extends ElemTemplateElement 424c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson{ 434c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson static final long serialVersionUID = 1530472462155060023L; 444c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson 454c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson /** 464c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * If the terminate attribute has the value yes, then the 474c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * XSLT transformer should terminate processing after sending 484c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * the message. The default value is no. 494c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * @serial 504c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson */ 514c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson private boolean m_terminate = Constants.ATTRVAL_NO; // default value 524c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson 534c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson /** 544c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * Set the "terminate" attribute. 554c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * If the terminate attribute has the value yes, then the 564c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * XSLT transformer should terminate processing after sending 574c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * the message. The default value is no. 584c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * 594c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * @param v Value to set for "terminate" attribute. 604c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson */ 614c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson public void setTerminate(boolean v) 624c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson { 634c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson m_terminate = v; 644c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson } 654c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson 664c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson /** 674c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * Get the "terminate" attribute. 684c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * If the terminate attribute has the value yes, then the 694c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * XSLT transformer should terminate processing after sending 704c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * the message. The default value is no. 714c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * 724c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * @return value of "terminate" attribute. 734c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson */ 744c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson public boolean getTerminate() 754c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson { 764c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson return m_terminate; 774c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson } 784c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson 794c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson /** 804c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * Get an int constant identifying the type of element. 814c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * @see org.apache.xalan.templates.Constants 824c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * 834c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * @return The token ID for this element 844c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson */ 854c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson public int getXSLToken() 864c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson { 874c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson return Constants.ELEMNAME_MESSAGE; 884c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson } 894c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson 904c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson /** 914c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * Return the node name. 924c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * 934c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * @return name of the element 944c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson */ 954c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson public String getNodeName() 964c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson { 974c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson return Constants.ELEMNAME_MESSAGE_STRING; 984c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson } 994c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson 1004c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson /** 1014c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * Send a message to diagnostics. 1024c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * The xsl:message instruction sends a message in a way that 1034c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * is dependent on the XSLT transformer. The content of the xsl:message 1044c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * instruction is a template. The xsl:message is instantiated by 1054c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * instantiating the content to create an XML fragment. This XML 1064c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * fragment is the content of the message. 1074c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * 1084c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * @param transformer non-null reference to the the current transform-time state. 1094c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * 1104c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * @throws TransformerException 1114c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson */ 1124c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson public void execute( 1134c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson TransformerImpl transformer) 1144c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson throws TransformerException 1154c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson { 1164c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson 1174c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson String data = transformer.transformToString(this); 1184c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson 1194c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson transformer.getMsgMgr().message(this, data, m_terminate); 1204c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson 1214c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson if(m_terminate) 1224c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson transformer.getErrorListener().fatalError(new TransformerException(XSLMessages.createMessage(XSLTErrorResources.ER_STYLESHEET_DIRECTED_TERMINATION, null))); //"Stylesheet directed termination")); 1234c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson } 1244c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson} 125