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 18 19 public class SAXONPreview extends StyleElement { 20 21 int previewModeNameCode = -1; 22 String 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 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 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 | Popular Tags |