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 com.icl.saxon.output.*; 6 import javax.xml.transform.*; 7 import javax.xml.transform.stream.StreamResult ; 8 9 import java.io.*; 10 import java.util.*; 11 12 15 16 public class XSLMessage extends StyleElement { 17 18 boolean terminate = false; 19 20 24 25 public boolean isInstruction() { 26 return true; 27 } 28 29 33 34 public boolean mayContainTemplateBody() { 35 return true; 36 } 37 38 public void prepareAttributes() throws TransformerConfigurationException { 39 40 String terminateAtt = null; 41 StandardNames sn = getStandardNames(); 42 AttributeCollection atts = getAttributeList(); 43 44 for (int a=0; a<atts.getLength(); a++) { 45 int nc = atts.getNameCode(a); 46 int f = nc & 0xfffff; 47 if (f==sn.TERMINATE) { 48 terminateAtt = atts.getValue(a); 49 } else { 50 checkUnknownAttribute(nc); 51 } 52 } 53 54 if (terminateAtt!=null) { 55 if (terminateAtt.equals("yes")) { 56 terminate = true; 57 } else if (terminateAtt.equals("no")) { 58 terminate = false; 59 } else { 60 styleError("terminate must be \"yes\" or \"no\""); 61 } 62 } 63 } 64 65 public void validate() throws TransformerConfigurationException { 66 checkWithinTemplate(); 67 } 68 69 public void process(Context context) throws TransformerException 70 { 71 Controller c = context.getController(); 72 Emitter emitter = c.getMessageEmitter(); 73 if (emitter==null) { 74 emitter = c.makeMessageEmitter(); 75 } 76 if (emitter.getWriter()==null) { 77 emitter.setWriter(new OutputStreamWriter(System.err)); 78 } 79 80 Outputter old = c.getOutputter(); 81 Properties props = new Properties(); 82 props.put(OutputKeys.OMIT_XML_DECLARATION, "yes"); 83 c.changeOutputDestination(props, emitter); 84 85 processChildren(context); 86 87 c.resetOutputDestination(old); 88 89 if (terminate) { 90 throw new TerminationException("Processing terminated by xsl:message at line " + getLineNumber()); 91 } 92 } 93 94 } 95 | Popular Tags |