All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.nwalsh.saxon.UnwrapLinks Maven / Gradle / Ivy

Go to download

These are Java extensions for use with the DocBook XML stylesheets and the Saxon XSLT engine.

The newest version!
// UnwrapLinks.java - Saxon extension for unwrapping nested links

package com.nwalsh.saxon;

import javax.xml.transform.TransformerException;
import com.icl.saxon.Controller;
import com.icl.saxon.expr.Value;
import com.icl.saxon.expr.FragmentValue;
import com.icl.saxon.expr.NodeSetValue;
import com.icl.saxon.om.NamePool;
import com.icl.saxon.Context;
import com.icl.saxon.functions.Extensions;
import com.nwalsh.saxon.UnwrapLinksEmitter;

/**
 * 

Saxon extension for unwrapping nested links

* *

$Id: UnwrapLinks.java 8098 2008-08-03 13:27:07Z mzjn $

* *

Copyright (C) 2000, 2002 Norman Walsh.

* *

This class provides a * Saxon 6.* * implementation of a link unwrapper.

* *

Change Log:

*
*
1.0
*

Initial release.

*
* * @author Norman Walsh * [email protected] * * @version $Id: UnwrapLinks.java 8098 2008-08-03 13:27:07Z mzjn $ * */ public class UnwrapLinks { /** True if the stylesheet is producing formatting objects */ private static boolean foStylesheet = false; /** *

Constructor for UnwrapLinks

* *

All of the methods are static, so the constructor does nothing.

*/ public UnwrapLinks() { } /** *

Find the string value of a stylesheet variable or parameter

* *

Returns the string value of varName in the current * context. Returns the empty string if the variable is * not defined.

* * @param context The current stylesheet context * @param varName The name of the variable (without the dollar sign) * * @return The string value of the variable */ protected static String getVariable(Context context, String varName) { Value variable = null; String varString = null; try { variable = Extensions.evaluate(context, "$" + varName); varString = variable.asString(); return varString; } catch (TransformerException te) { System.out.println("Undefined variable: " + varName); return ""; } catch (IllegalArgumentException iae) { System.out.println("Undefined variable: " + varName); return ""; } } /** *

Setup the parameters associated with unwrapping links

* * @param context The current stylesheet context * */ private static void setupUnwrapLinks(Context context) { // Get the stylesheet type String varString = getVariable(context, "stylesheet.result.type"); foStylesheet = (varString.equals("fo")); } /** *

Unwrap links

* * @param context The current stylesheet context. * @param rtf_ns The result tree fragment of the verbatim environment. * * @return The modified result tree fragment. */ public static NodeSetValue unwrapLinks (Context context, NodeSetValue rtf_ns) { FragmentValue rtf = (FragmentValue) rtf_ns; boolean tryAgain = true; setupUnwrapLinks(context); try { Controller controller = context.getController(); NamePool namePool = controller.getNamePool(); while (tryAgain) { UnwrapLinksEmitter ulEmitter = new UnwrapLinksEmitter(controller, namePool, foStylesheet); rtf.replay(ulEmitter); tryAgain = ulEmitter.tryAgain(); rtf = (FragmentValue) ulEmitter.getResultTreeFragment(); } return rtf; } catch (TransformerException e) { // This "can't" happen. System.out.println("Transformer Exception in unwrapLinks"); return rtf; } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy