1 package com.icl.saxon.trace; 2 3 import com.icl.saxon.style.StyleElement; 4 import com.icl.saxon.Context; 5 import com.icl.saxon.Mode; 6 import com.icl.saxon.NodeHandler; 7 import com.icl.saxon.om.NodeInfo; 8 import com.icl.saxon.om.Navigator; 9 10 13 14 public class SimpleTraceListener implements TraceListener { 15 16 String indent = ""; 17 18 21 22 public void open() { 23 System.err.println("<trace>"); 24 } 25 26 29 30 public void close() { 31 System.err.println("</trace>"); 32 } 33 34 35 36 39 public void toplevel(NodeInfo element) 40 { 41 StyleElement e = (StyleElement)element; 42 System.err.println("<Top-level element=\"" + e.getDisplayName() + "\" line=\"" + e.getLineNumber() + 43 "\" file=\"" + e.getSystemId() + "\" precedence=\"" + e.getPrecedence() +"\"/>"); 44 } 45 46 49 public void enterSource(NodeHandler handler, Context context) 50 { 51 NodeInfo curr = context.getContextNodeInfo(); 52 System.err.println(indent + "<Source node=\"" + Navigator.getPath(curr) 53 + "\" line=\"" + curr.getLineNumber() 54 + "\" mode=\"" + getModeName(context) + "\">"); 55 indent += " "; 56 } 57 58 61 public void leaveSource(NodeHandler handler, Context context) 62 { 63 indent = indent.substring(0, indent.length() - 1); 64 System.err.println(indent + "</Source><!-- " + 65 Navigator.getPath(context.getContextNodeInfo()) + " -->"); 66 } 67 68 71 public void enter(NodeInfo element, Context context) 72 { 73 if (element.getNodeType()==NodeInfo.ELEMENT) { 74 System.err.println(indent + "<Instruction element=\"" + element.getDisplayName() + "\" line=\"" + element.getLineNumber() + "\">"); 75 indent += " "; 76 } 77 } 78 79 82 public void leave(NodeInfo element, Context context) 83 { 84 if (element.getNodeType()==NodeInfo.ELEMENT) { 85 indent = indent.substring(0, indent.length() - 1); 86 System.err.println(indent + "</Instruction> <!-- " + 87 element.getDisplayName() + " -->"); 88 } 89 } 90 91 String getModeName(Context context) 92 { 93 Mode mode = context.getMode(); 94 if (mode==null) return "#none"; 95 int nameCode = mode.getNameCode(); 96 if (nameCode==-1) { 97 return "#default"; 98 } else { 99 return context.getController().getNamePool().getDisplayName(nameCode); 100 } 101 } 102 } 103 | Popular Tags |