1 package net.sf.saxon.instruct; 2 import net.sf.saxon.event.SequenceReceiver; 3 import net.sf.saxon.expr.ExpressionTool; 4 import net.sf.saxon.expr.StaticContext; 5 import net.sf.saxon.expr.StaticProperty; 6 import net.sf.saxon.expr.XPathContext; 7 import net.sf.saxon.om.NamePool; 8 import net.sf.saxon.pattern.NodeKindTest; 9 import net.sf.saxon.style.StandardNames; 10 import net.sf.saxon.trans.DynamicError; 11 import net.sf.saxon.trans.XPathException; 12 import net.sf.saxon.type.ItemType; 13 14 import java.io.PrintStream ; 15 16 17 20 21 public final class Comment extends SimpleNodeConstructor { 22 23 26 27 public Comment() {} 28 29 33 34 public int getInstructionNameCode() { 35 return StandardNames.XSL_COMMENT; 36 } 37 38 public ItemType getItemType() { 39 return NodeKindTest.COMMENT; 40 } 41 42 public int getCardinality() { 43 return StaticProperty.EXACTLY_ONE; 44 } 45 46 public void localTypeCheck(StaticContext env, ItemType contextItemType) {} 47 48 49 55 56 public TailCall processLeavingTail(XPathContext context) throws XPathException { 57 String comment = expandChildren(context).toString(); 58 comment = checkContent(comment, context); 59 SequenceReceiver out = context.getReceiver(); 60 out.comment(comment, locationId, 0); 61 return null; 62 } 63 64 73 74 protected String checkContent(String comment, XPathContext context) throws DynamicError { 75 while(true) { 76 int hh = comment.indexOf("--"); 77 if (hh < 0) break; 78 if (isXSLT(context)) { 79 comment = comment.substring(0, hh+1) + ' ' + comment.substring(hh+1); 80 } else { 81 DynamicError err = new DynamicError("Invalid characters (--) in comment", this); 82 err.setErrorCode("XQDY0072"); 83 err.setXPathContext(context); 84 throw DynamicError.makeDynamicError(dynamicError(this, err, context)); 85 } 86 } 87 if (comment.length()>0 && comment.charAt(comment.length()-1)=='-') { 88 if (isXSLT(context)) { 89 comment = comment + ' '; 90 } else { 91 DynamicError err = new DynamicError("Comment cannot end in '-'", this); 92 err.setErrorCode("XQDY0072"); 93 err.setXPathContext(context); 94 throw DynamicError.makeDynamicError(dynamicError(this, err, context)); 95 } 96 } 97 return comment; 98 } 99 100 public void display(int level, NamePool pool, PrintStream out) { 101 out.println(ExpressionTool.indent(level) + "comment"); 102 super.display(level+1, pool, out); 103 } 104 105 } 106 | Popular Tags |