KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icl > saxon > style > SAXONWhile


1 package com.icl.saxon.style;
2 import com.icl.saxon.tree.AttributeCollection;
3 import com.icl.saxon.*;
4 import com.icl.saxon.expr.*;
5 import javax.xml.transform.*;
6
7
8 /**
9 * Handler for saxon:while elements in stylesheet.<BR>
10 * The saxon:while element has a mandatory attribute test, a boolean expression.
11 * The content is output repeatedly so long as the test condition is true.
12 */

13
14 public class SAXONWhile extends StyleElement {
15
16     private Expression test;
17
18     /**
19     * Determine whether this node is an instruction.
20     * @return true - it is an instruction
21     */

22
23     public boolean isInstruction() {
24         return true;
25     }
26
27     /**
28     * Determine whether this type of element is allowed to contain a template-body
29     * @return true: yes, it may contain a template-body
30     */

31
32     public boolean mayContainTemplateBody() {
33         return true;
34     }
35
36     public void prepareAttributes() throws TransformerConfigurationException {
37
38         String JavaDoc testAtt=null;
39
40         StandardNames sn = getStandardNames();
41         AttributeCollection atts = getAttributeList();
42                 
43         for (int a=0; a<atts.getLength(); a++) {
44             int nc = atts.getNameCode(a);
45             int f = nc & 0xfffff;
46             if (f==sn.NAME) {
47                 //
48
} else if (f==sn.TEST) {
49                 testAtt = atts.getValue(a);
50             } else {
51                 checkUnknownAttribute(nc);
52             }
53         }
54         
55         if (testAtt==null) {
56             reportAbsence("test");
57             return;
58         }
59         test = makeExpression(testAtt);
60     }
61
62     public void validate() throws TransformerConfigurationException {
63         checkWithinTemplate();
64         //checkElementExtensions("saxon");
65
}
66
67     public void process(Context context) throws TransformerException
68     {
69         while (test.evaluateAsBoolean(context)) {
70             processChildren(context);
71         }
72     }
73
74 }
75
76 //
77
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
78
// you may not use this file except in compliance with the License. You may obtain a copy of the
79
// License at http://www.mozilla.org/MPL/
80
//
81
// Software distributed under the License is distributed on an "AS IS" basis,
82
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
83
// See the License for the specific language governing rights and limitations under the License.
84
//
85
// The Original Code is: all this file.
86
//
87
// The Initial Developer of the Original Code is
88
// Michael Kay of International Computers Limited (mhkay@iclway.co.uk).
89
//
90
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
91
//
92
// Contributor(s): none.
93
//
94
Popular Tags