KickJava   Java API By Example, From Geeks To Geeks.

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


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: ElemApplyImport.java,v 1.14 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.XSLTErrorResources;
24 import org.apache.xalan.transformer.TransformerImpl;
25 import org.apache.xml.dtm.DTM;
26
27 /**
28  * Implement xsl:apply-imports.
29  * <pre>
30  * <!ELEMENT xsl:apply-imports EMPTY>
31  * </pre>
32  * @see <a HREF="http://www.w3.org/TR/xslt#apply-imports">apply-imports in XSLT Specification</a>
33  * @xsl.usage advanced
34  */

35 public class ElemApplyImport extends ElemTemplateElement
36 {
37
38   /**
39    * Get an int constant identifying the type of element.
40    * @see org.apache.xalan.templates.Constants
41    *
42    * @return Token ID for xsl:apply-imports element types
43    */

44   public int getXSLToken()
45   {
46     return Constants.ELEMNAME_APPLY_IMPORTS;
47   }
48
49   /**
50    * Return the node name.
51    *
52    * @return Element name
53    */

54   public String JavaDoc getNodeName()
55   {
56     return Constants.ELEMNAME_APPLY_IMPORTS_STRING;
57   }
58
59   /**
60    * Execute the xsl:apply-imports transformation.
61    *
62    * @param transformer non-null reference to the the current transform-time state.
63    * @param sourceNode non-null reference to the <a HREF="http://www.w3.org/TR/xslt#dt-current-node">current source node</a>.
64    * @param mode reference, which may be null, to the <a HREF="http://www.w3.org/TR/xslt#modes">current mode</a>.
65    *
66    * @throws TransformerException
67    */

68   public void execute(
69           TransformerImpl transformer)
70             throws TransformerException JavaDoc
71   {
72
73     if (transformer.currentTemplateRuleIsNull())
74     {
75       transformer.getMsgMgr().error(this,
76         XSLTErrorResources.ER_NO_APPLY_IMPORT_IN_FOR_EACH); //"xsl:apply-imports not allowed in a xsl:for-each");
77
}
78
79     if (TransformerImpl.S_DEBUG)
80       transformer.getTraceManager().fireTraceEvent(this);
81
82     int sourceNode = transformer.getXPathContext().getCurrentNode();
83     if (DTM.NULL != sourceNode)
84     {
85
86       // This will have to change to current template, (which will have
87
// to be the top of a current template stack).
88
transformer.applyTemplateToNode(this, null, sourceNode);
89     }
90     else // if(null == sourceNode)
91
{
92       transformer.getMsgMgr().error(this,
93         XSLTErrorResources.ER_NULL_SOURCENODE_APPLYIMPORTS); //"sourceNode is null in xsl:apply-imports!");
94
}
95     if (TransformerImpl.S_DEBUG)
96       transformer.getTraceManager().fireTraceEndEvent(this);
97   }
98
99   /**
100    * Add a child to the child list.
101    * <!ELEMENT xsl:apply-imports EMPTY>
102    *
103    * @param newChild New element to append to this element's children list
104    *
105    * @return null, xsl:apply-Imports cannot have children
106    */

107   public ElemTemplateElement appendChild(ElemTemplateElement newChild)
108   {
109
110     error(XSLTErrorResources.ER_CANNOT_ADD,
111           new Object JavaDoc[]{ newChild.getNodeName(),
112                         this.getNodeName() }); //"Can not add " +((ElemTemplateElement)newChild).m_elemName +
113

114     //" to " + this.m_elemName);
115
return null;
116   }
117 }
118
Popular Tags