ElemApplyImport.java revision 9f8118474e9513f7a5b7d2a05e4a0fb15d1a6569
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: ElemApplyImport.java 468643 2006-10-28 06:56:03Z minchau $
20 */
21package org.apache.xalan.templates;
22
23import javax.xml.transform.TransformerException;
24
25import org.apache.xalan.res.XSLTErrorResources;
26import org.apache.xalan.transformer.TransformerImpl;
27import org.apache.xml.dtm.DTM;
28
29/**
30 * Implement xsl:apply-imports.
31 * <pre>
32 * <!ELEMENT xsl:apply-imports EMPTY>
33 * </pre>
34 * @see <a href="http://www.w3.org/TR/xslt#apply-imports">apply-imports in XSLT Specification</a>
35 * @xsl.usage advanced
36 */
37public class ElemApplyImport extends ElemTemplateElement
38{
39    static final long serialVersionUID = 3764728663373024038L;
40
41  /**
42   * Get an int constant identifying the type of element.
43   * @see org.apache.xalan.templates.Constants
44   *
45   * @return Token ID for xsl:apply-imports element types
46   */
47  public int getXSLToken()
48  {
49    return Constants.ELEMNAME_APPLY_IMPORTS;
50  }
51
52  /**
53   * Return the node name.
54   *
55   * @return Element name
56   */
57  public String getNodeName()
58  {
59    return Constants.ELEMNAME_APPLY_IMPORTS_STRING;
60  }
61
62  /**
63   * Execute the xsl:apply-imports transformation.
64   *
65   * @param transformer non-null reference to the the current transform-time state.
66   *
67   * @throws TransformerException
68   */
69  public void execute(
70          TransformerImpl transformer)
71            throws TransformerException
72  {
73
74    if (transformer.currentTemplateRuleIsNull())
75    {
76      transformer.getMsgMgr().error(this,
77        XSLTErrorResources.ER_NO_APPLY_IMPORT_IN_FOR_EACH);  //"xsl:apply-imports not allowed in a xsl:for-each");
78    }
79
80    int sourceNode = transformer.getXPathContext().getCurrentNode();
81    if (DTM.NULL != sourceNode)
82    {
83      // supply the current templated (matched, not named)
84      ElemTemplate matchTemplate = transformer.getMatchedTemplate();
85      transformer.applyTemplateToNode(this, matchTemplate, sourceNode);
86    }
87    else  // if(null == sourceNode)
88    {
89      transformer.getMsgMgr().error(this,
90        XSLTErrorResources.ER_NULL_SOURCENODE_APPLYIMPORTS);  //"sourceNode is null in xsl:apply-imports!");
91    }
92  }
93
94  /**
95   * Add a child to the child list.
96   * <!ELEMENT xsl:apply-imports EMPTY>
97   *
98   * @param newChild New element to append to this element's children list
99   *
100   * @return null, xsl:apply-Imports cannot have children
101   */
102  public ElemTemplateElement appendChild(ElemTemplateElement newChild)
103  {
104
105    error(XSLTErrorResources.ER_CANNOT_ADD,
106          new Object[]{ newChild.getNodeName(),
107                        this.getNodeName() });  //"Can not add " +((ElemTemplateElement)newChild).m_elemName +
108
109    //" to " + this.m_elemName);
110    return null;
111  }
112}
113