| 1 |
|
| 2 |
|
| 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 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
public class UnwrapLinks { |
| 43 |
|
| 44 |
private static boolean foStylesheet = false; |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
public UnwrapLinks() { |
| 52 |
} |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 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 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
private static void setupUnwrapLinks(Context context) { |
| 90 |
|
| 91 |
String varString = getVariable(context, "stylesheet.result.type"); |
| 92 |
foStylesheet = (varString.equals("fo")); |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
public static NodeSetValue unwrapLinks (Context context, |
| 104 |
NodeSetValue rtf_ns) { |
| 105 |
|
| 106 |
FragmentValue rtf = (FragmentValue) rtf_ns; |
| 107 |
boolean tryAgain = true; |
| 108 |
|
| 109 |
setupUnwrapLinks(context); |
| 110 |
|
| 111 |
try { |
| 112 |
Controller controller = context.getController(); |
| 113 |
NamePool namePool = controller.getNamePool(); |
| 114 |
|
| 115 |
while (tryAgain) { |
| 116 |
UnwrapLinksEmitter ulEmitter = new UnwrapLinksEmitter(controller, |
| 117 |
namePool, |
| 118 |
foStylesheet); |
| 119 |
rtf.replay(ulEmitter); |
| 120 |
tryAgain = ulEmitter.tryAgain(); |
| 121 |
rtf = (FragmentValue) ulEmitter.getResultTreeFragment(); |
| 122 |
} |
| 123 |
|
| 124 |
return rtf; |
| 125 |
|
| 126 |
} catch (TransformerException e) { |
| 127 |
|
| 128 |
System.out.println("Transformer Exception in unwrapLinks"); |
| 129 |
return rtf; |
| 130 |
} |
| 131 |
} |
| 132 |
} |