1 3 package com.nwalsh.saxon; 4 5 import java.util.Stack ; 6 import java.util.StringTokenizer ; 7 import org.xml.sax.*; 8 import org.w3c.dom.*; 9 import javax.xml.transform.TransformerException ; 10 import com.icl.saxon.Controller; 11 import com.icl.saxon.expr.*; 12 import com.icl.saxon.om.*; 13 import com.icl.saxon.pattern.*; 14 import com.icl.saxon.Context; 15 import com.icl.saxon.tree.*; 16 import com.icl.saxon.functions.Extensions; 17 import com.nwalsh.saxon.UnwrapLinksEmitter; 18 19 42 public class UnwrapLinks { 43 44 private static boolean foStylesheet = false; 45 46 51 public UnwrapLinks() { 52 } 53 54 66 protected static String getVariable(Context context, String varName) { 67 Value variable = null; 68 String varString = null; 69 70 try { 71 variable = Extensions.evaluate(context, "$" + varName); 72 varString = variable.asString(); 73 return varString; 74 } catch (TransformerException te) { 75 System.out.println("Undefined variable: " + varName); 76 return ""; 77 } catch (IllegalArgumentException iae) { 78 System.out.println("Undefined variable: " + varName); 79 return ""; 80 } 81 } 82 83 89 private static void setupUnwrapLinks(Context context) { 90 String varString = getVariable(context, "stylesheet.result.type"); 92 foStylesheet = (varString.equals("fo")); 93 } 94 95 102 public static NodeSetValue unwrapLinks (Context context, 103 NodeSetValue rtf_ns) { 104 105 FragmentValue rtf = (FragmentValue) rtf_ns; 106 boolean tryAgain = true; 107 108 setupUnwrapLinks(context); 109 110 try { 111 Controller controller = context.getController(); 112 NamePool namePool = controller.getNamePool(); 113 114 while (tryAgain) { 115 UnwrapLinksEmitter ulEmitter = new UnwrapLinksEmitter(controller, 116 namePool, 117 foStylesheet); 118 rtf.replay(ulEmitter); 119 tryAgain = ulEmitter.tryAgain(); 120 rtf = (FragmentValue) ulEmitter.getResultTreeFragment(); 121 } 122 123 return rtf; 124 125 } catch (TransformerException e) { 126 System.out.println("Transformer Exception in unwrapLinks"); 128 return rtf; 129 } 130 } 131 } 132 | Popular Tags |