KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejen > EjenIncludeNode


1 //
2
// Ejen (code generation system)
3
// Copyright (C) 2001, 2002 François Wolff (ejen@noos.fr).
4
//
5
// This file is part of Ejen.
6
//
7
// Ejen is free software; you can redistribute it and/or modify
8
// it under the terms of the GNU General Public License as published by
9
// the Free Software Foundation; either version 2 of the License, or
10
// (at your option) any later version.
11
//
12
// Ejen is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
// GNU General Public License for more details.
16
//
17
// You should have received a copy of the GNU General Public License
18
// along with Ejen; if not, write to the Free Software
19
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
//
21
package org.ejen;
22
23 import org.apache.xalan.transformer.TransformerImpl;
24 import org.apache.xalan.templates.StylesheetRoot;
25
26 /**
27  * Include node class.
28  * <p>
29  * An include node allows to include a stylesheet into another stylesheet
30  * (filter, template, import or even include).
31  * <p>
32  * <table class="usage">
33  * <tr><th class="usage">Usage (ant build file)</th></tr>
34  * <tr><td class="usage"><pre><code>
35  * &lt;?xml version="1.0" encoding="UTF-8"?&gt;
36  *
37  * &lt;project name="generate" default="build"&gt;
38  *
39  * &lt;taskdef name="ejen" classname="org.ejen.EjenTask"/&gt;
40  *
41  * &lt;target name="build"&gt;
42  * &lt;{@link org.ejen.EjenTask ejen} ...&gt;
43  * ...
44  * &lt;{@link org.ejen.EjenFilterNode filter} ...&gt;
45  * ...
46  * <b>&lt;include {@link org.ejen.EjenStylesheetNode#setFile(String) file}="include.xml"&gt;</b>
47  * ...
48  * [&lt;{@link org.ejen.EjenImportNode import} .../&gt;]
49  * [&lt;include .../&gt;]
50  * [&lt;{@link org.ejen.EjenParamNode param} .../&gt;]
51  * ...
52  * <b>&lt;/include&gt;</b>
53  * ...
54  * &lt;/filter&gt;
55  * ...
56  * &lt;/ejen&gt;
57  * &lt;/target&gt;
58  *
59  * &lt;/project&gt;
60  * </code></pre></td></tr></table>
61  * <p>
62  * <b>Parent nodes</b>:
63  * <ul>
64  * <li>{@link org.ejen.EjenFilterNode filter}
65  * <li>{@link org.ejen.EjenTemplateNode template}
66  * <li>{@link org.ejen.EjenImportNode import}
67  * <li>include
68  * </ul>
69  * @author F. Wolff
70  * @version 1.0
71  */

72 public class EjenIncludeNode extends EjenStylesheetNode {
73
74     /**
75      * Returns the name of this EjenIncludeNode (always "include").
76      * @return the name of this EjenIncludeNode.
77      */

78     public String JavaDoc nodeName() {
79         return "include";
80     }
81     
82     /**
83      * Executes this EjenIncludeNode.
84      * @throws org.ejen.EjenException if something goes wrong...
85      */

86     public void process() {
87         super.process();
88         try {
89             TransformerImpl ti = (TransformerImpl) (getFromContext(CTX_TRANSFORMER_IMPL));
90
91             if (ti == null) {
92                 throw new EjenException(this,
93                         "no '" + CTX_TRANSFORMER_IMPL + "' in context");
94             }
95             StylesheetRoot sr = (StylesheetRoot) (getFromContext(CTX_STYLESHEET_ROOT,
96                     -1));
97
98             if (sr == null) {
99                 throw new EjenException(this,
100                         "no '" + CTX_STYLESHEET_ROOT + "' in context");
101             }
102             sr.setInclude(ti.getStylesheet());
103         } catch (EjenException e) {
104             throw e;
105         } catch (Exception JavaDoc e) {
106             throw new EjenException(this, "bad include", e);
107         }
108     }
109 }
110
Popular Tags