KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.icl.saxon.style;
2 import com.icl.saxon.tree.AttributeCollection;
3 import com.icl.saxon.*;
4 import com.icl.saxon.om.NamespaceException;
5 import com.icl.saxon.handlers.*;
6 import com.icl.saxon.expr.*;
7 import javax.xml.transform.*;
8
9 import java.io.*;
10 import java.util.*;
11
12 /**
13 * Handler for saxon:preview elements in stylesheet. <BR>
14 * Attributes: <br>
15 * mode identifies the mode in which preview templates will be called. <br>
16 * elements is a space-separated list of element names which are eligible for preview processing.
17 */

18
19 public class SAXONPreview extends StyleElement {
20
21     int previewModeNameCode = -1;
22     String JavaDoc elements = null;
23
24     
25     public void prepareAttributes() throws TransformerConfigurationException {
26
27         StandardNames sn = getStandardNames();
28         AttributeCollection atts = getAttributeList();
29         
30         for (int a=0; a<atts.getLength(); a++) {
31             int nc = atts.getNameCode(a);
32             int f = nc & 0xfffff;
33             if (f==sn.MODE) {
34                 String JavaDoc previewMode = atts.getValue(a);
35                 try {
36                     previewModeNameCode = makeNameCode(previewMode, false);
37                 } catch (NamespaceException err) {
38                     compileError(err.getMessage());
39                 }
40             } else if (f==sn.ELEMENTS) {
41                 elements = atts.getValue(a);
42             } else {
43                 checkUnknownAttribute(nc);
44             }
45         }
46
47         if (previewModeNameCode==-1) {
48             reportAbsence("mode");
49         }
50         if (elements==null) {
51             reportAbsence("elements");
52         }
53     }
54
55     public void validate() throws TransformerConfigurationException {
56         checkTopLevel();
57     }
58
59     public void preprocess() throws TransformerConfigurationException
60     {
61         XSLStyleSheet sheet = getPrincipalStyleSheet();
62         PreviewManager pm = sheet.getPreviewManager();
63         if (pm==null) {
64             pm = new PreviewManager();
65             sheet.setPreviewManager(pm);
66         }
67         pm.setPreviewMode(previewModeNameCode);
68
69         StringTokenizer st = new StringTokenizer(elements);
70         while (st.hasMoreTokens()) {
71             String JavaDoc elementName = st.nextToken();
72             try {
73                 pm.setPreviewElement(makeNameCode(elementName, true) & 0xfffff);
74             } catch (NamespaceException err) {
75                 compileError(err.getMessage());
76             }
77         }
78     }
79
80     public void process(Context context) throws TransformerException {}
81
82 }
83
84 //
85
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
86
// you may not use this file except in compliance with the License. You may obtain a copy of the
87
// License at http://www.mozilla.org/MPL/
88
//
89
// Software distributed under the License is distributed on an "AS IS" basis,
90
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
91
// See the License for the specific language governing rights and limitations under the License.
92
//
93
// The Original Code is: all this file.
94
//
95
// The Initial Developer of the Original Code is
96
// Michael Kay of International Computers Limited (mhkay@iclway.co.uk).
97
//
98
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
99
//
100
// Contributor(s): none.
101
//
102
Popular Tags