1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. *
  5. * Copyright (c) 1999 The Apache Software Foundation. All rights
  6. * reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. *
  20. * 3. The end-user documentation included with the redistribution,
  21. * if any, must include the following acknowledgment:
  22. * "This product includes software developed by the
  23. * Apache Software Foundation (http://www.apache.org/)."
  24. * Alternately, this acknowledgment may appear in the software itself,
  25. * if and wherever such third-party acknowledgments normally appear.
  26. *
  27. * 4. The names "Xalan" and "Apache Software Foundation" must
  28. * not be used to endorse or promote products derived from this
  29. * software without prior written permission. For written
  30. * permission, please contact apache@apache.org.
  31. *
  32. * 5. Products derived from this software may not be called "Apache",
  33. * nor may "Apache" appear in their name, without prior written
  34. * permission of the Apache Software Foundation.
  35. *
  36. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  37. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  38. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  39. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  40. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  42. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  43. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  44. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  45. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  46. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  47. * SUCH DAMAGE.
  48. * ====================================================================
  49. *
  50. * This software consists of voluntary contributions made by many
  51. * individuals on behalf of the Apache Software Foundation and was
  52. * originally based on software copyright (c) 1999, Lotus
  53. * Development Corporation., http://www.lotus.com. For more
  54. * information on the Apache Software Foundation, please see
  55. * <http://www.apache.org/>.
  56. */
  57. package org.apache.xalan.templates;
  58. //import org.w3c.dom.Node;
  59. //import org.w3c.dom.DOMException;
  60. import org.apache.xml.dtm.DTM;
  61. import javax.xml.transform.TransformerException;
  62. import org.apache.xalan.res.XSLTErrorResources;
  63. import org.apache.xalan.transformer.TransformerImpl;
  64. import org.apache.xml.utils.QName;
  65. /**
  66. * <meta name="usage" content="advanced"/>
  67. * Implement xsl:apply-imports.
  68. * <pre>
  69. * <!ELEMENT xsl:apply-imports EMPTY>
  70. * </pre>
  71. * @see <a href="http://www.w3.org/TR/xslt#apply-imports">apply-imports in XSLT Specification</a>
  72. */
  73. public class ElemApplyImport extends ElemTemplateElement
  74. {
  75. /**
  76. * Get an int constant identifying the type of element.
  77. * @see org.apache.xalan.templates.Constants
  78. *
  79. * @return Token ID for xsl:apply-imports element types
  80. */
  81. public int getXSLToken()
  82. {
  83. return Constants.ELEMNAME_APPLY_IMPORTS;
  84. }
  85. /**
  86. * Return the node name.
  87. *
  88. * @return Element name
  89. */
  90. public String getNodeName()
  91. {
  92. return Constants.ELEMNAME_APPLY_IMPORTS_STRING;
  93. }
  94. /**
  95. * Execute the xsl:apply-imports transformation.
  96. *
  97. * @param transformer non-null reference to the the current transform-time state.
  98. * @param sourceNode non-null reference to the <a href="http://www.w3.org/TR/xslt#dt-current-node">current source node</a>.
  99. * @param mode reference, which may be null, to the <a href="http://www.w3.org/TR/xslt#modes">current mode</a>.
  100. *
  101. * @throws TransformerException
  102. */
  103. public void execute(
  104. TransformerImpl transformer)
  105. throws TransformerException
  106. {
  107. if (transformer.currentTemplateRuleIsNull())
  108. {
  109. transformer.getMsgMgr().error(this,
  110. XSLTErrorResources.ER_NO_APPLY_IMPORT_IN_FOR_EACH); //"xsl:apply-imports not allowed in a xsl:for-each");
  111. }
  112. if (TransformerImpl.S_DEBUG)
  113. transformer.getTraceManager().fireTraceEvent(this);
  114. int sourceNode = transformer.getXPathContext().getCurrentNode();
  115. if (DTM.NULL != sourceNode)
  116. {
  117. // This will have to change to current template, (which will have
  118. // to be the top of a current template stack).
  119. transformer.applyTemplateToNode(this, null, sourceNode);
  120. }
  121. else // if(null == sourceNode)
  122. {
  123. transformer.getMsgMgr().error(this,
  124. XSLTErrorResources.ER_NULL_SOURCENODE_APPLYIMPORTS); //"sourceNode is null in xsl:apply-imports!");
  125. }
  126. if (TransformerImpl.S_DEBUG)
  127. transformer.getTraceManager().fireTraceEndEvent(this);
  128. }
  129. /**
  130. * Add a child to the child list.
  131. * <!ELEMENT xsl:apply-imports EMPTY>
  132. *
  133. * @param newChild New element to append to this element's children list
  134. *
  135. * @return null, xsl:apply-Imports cannot have children
  136. */
  137. public ElemTemplateElement appendChild(ElemTemplateElement newChild)
  138. {
  139. error(XSLTErrorResources.ER_CANNOT_ADD,
  140. new Object[]{ newChild.getNodeName(),
  141. this.getNodeName() }); //"Can not add " +((ElemTemplateElement)newChild).m_elemName +
  142. //" to " + this.m_elemName);
  143. return null;
  144. }
  145. }