curcuru 01/08/08 06:30:59 Added: test/tests/extensions/java javaRedir1.java javaRedir1.xml javaRedir1.xsl javaSample3.java javaSample3.xml javaSample3.xsl javaSample4.java javaSample4.xml javaSample4.xsl test/tests/extensions/javascript javascriptSample5.xml javascriptSample5.xsl Log: Various new Extensions tests, java and javascript Revision Changes Path 1.1 xml-xalan/test/tests/extensions/java/javaRedir1.java Index: javaRedir1.java =================================================================== /* * Covered by The Apache Software License, Version 1.1 * See xml-xalan/java/License */ // explicitly packageless import org.apache.qetest.CheckService; import org.apache.qetest.Logger; import org.apache.qetest.xsl.StylesheetDatalet; import org.apache.qetest.xsl.TestableExtension; import org.apache.qetest.xsl.XHTFileCheckService; import java.io.File; import java.util.Hashtable; /** * Extension for testing xml-xalan/samples/extensions. */ public class javaRedir1 extends TestableExtension { /** Note: no actual extension methods here; this class just does validation. */ //// Implementations of TestableExtension /** Copied from javaRedir1.xml[/doc/foo/@file]. */ public static final String REDIR_NAME = "javaRedir1a-from-build-extensions.out"; /** * Perform and log any pre-transformation info. * @return true if OK; false if any fatal error occoured * @param datalet Datalet of current stylesheet test */ public static boolean preCheck(Logger logger, StylesheetDatalet datalet) { logger.logMsg(Logger.TRACEMSG, "javaRedir1.preCheck"); return true; } /** * Perform and log any post-transformation info. * * The extension should validate that it's extension was * properly called; we also validate output file(s). * * @param logger Logger to dump any info to * @param datalet Datalet of current stylesheet test */ public static void postCheck(Logger logger, StylesheetDatalet datalet) { logger.logMsg(Logger.TRACEMSG, "javaRedir1.postCheck"); // First, validate the normal output file the normal way CheckService fileChecker = (CheckService)datalet.options.get("fileCheckerImpl"); // Supply default value if (null == fileChecker) fileChecker = new XHTFileCheckService(); if (Logger.PASS_RESULT != fileChecker.check(logger, new File(datalet.outputName), new File(datalet.goldName), "Extension test of " + datalet.getDescription()) ) { // Log a custom element with all the file refs first // Closely related to viewResults.xsl select='fileref" //@todo check that these links are valid when base // paths are either relative or absolute! Hashtable attrs = new Hashtable(); attrs.put("idref", (new File(datalet.inputName)).getName()); attrs.put("inputName", datalet.inputName); attrs.put("xmlName", datalet.xmlName); attrs.put("outputName", datalet.outputName); attrs.put("goldName", datalet.goldName); logger.logElement(Logger.STATUSMSG, "fileref", attrs, "Extension test file references"); } // Now, also validate the redirected output! // Calculate location of gold redir file String goldRedir = (new File(datalet.goldName)).getParent() + File.separator + REDIR_NAME; // Calculate location of actual redir file String outRedir = (new File(datalet.outputName)).getParent() + File.separator + REDIR_NAME; // Then check just with actual file name to the constructed // gold name; don't bother with extra logging fileChecker.check(logger, new File(outRedir), new File(goldRedir), "Redir-Extension test of " + datalet.getDescription()); } /** * Description of what this extension does. * @return String description of extension */ public static String getDescription() { return "No extension methods - just validation"; } } 1.1 xml-xalan/test/tests/extensions/java/javaRedir1.xml Index: javaRedir1.xml =================================================================== <?xml version="1.0"?> <doc> <foo file="javaRedir1a-from-build-extensions.out"> Testing Redirect extension: <bar>A foo subelement text node</bar> </foo> <main> Everything else </main> </doc> 1.1 xml-xalan/test/tests/extensions/java/javaRedir1.xsl Index: javaRedir1.xsl =================================================================== <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:lxslt="http://xml.apache.org/xslt" xmlns:redirect="org.apache.xalan.lib.Redirect" extension-element-prefixes="redirect"> <!-- Copied from xml-xalan/java/samples/extensions/1-redir.xsl --> <lxslt:component prefix="redirect" elements="write open close" functions=""> <lxslt:script lang="javaclass" src="org.apache.xalan.lib.Redirect"/> </lxslt:component> <xsl:template match="/"> <standard-out> Standard output: <xsl:apply-templates/> </standard-out> </xsl:template> <!-- not redirected --> <xsl:template match="doc/main"> <main> -- look in <xsl:value-of select="/doc/foo/@file"/> for the redirected output -- <xsl:apply-templates/> </main> </xsl:template> <!-- redirected --> <xsl:template match="doc/foo"> <!-- get redirect file name from XML input --> <redirect:write select="@file"> <foo-out> <xsl:apply-templates/> </foo-out> </redirect:write> </xsl:template> <!-- redirected (from the xsl:apply-templates above. I.e., bar is in /doc/foo --> <xsl:template match="bar"> <foobar-out> <xsl:apply-templates/> </foobar-out> </xsl:template> </xsl:stylesheet> 1.1 xml-xalan/test/tests/extensions/java/javaSample3.java Index: javaSample3.java =================================================================== /* * Covered by The Apache Software License, Version 1.1 * See xml-xalan/java/License */ // explicitly packageless import org.apache.qetest.CheckService; import org.apache.qetest.Logger; import org.apache.qetest.xsl.StylesheetDatalet; import org.apache.qetest.xsl.TestableExtension; import org.apache.qetest.xsl.XHTFileCheckService; import java.io.File; import java.util.Calendar; import java.util.Date; import java.util.Hashtable; /** * Extension for testing xml-xalan/samples/extensions. */ public class javaSample3 extends TestableExtension { /** Extension method called from stylesheet. */ public static Date getDate(String year, String month, String day) { // Bump up counter for later validation in postCheck counter++; Calendar c = Calendar.getInstance(); // Convert each argument to int. c.set(Integer.parseInt(year),Integer.parseInt(month),Integer.parseInt(day)); return c.getTime(); } //// Implementations of TestableExtension /** Simple counter of number of times called. */ private static int counter = 0; /** * Perform and log any pre-transformation info. * @return true if OK; false if any fatal error occoured * @param datalet Datalet of current stylesheet test */ public static boolean preCheck(Logger logger, StylesheetDatalet datalet) { logger.logMsg(Logger.INFOMSG, "javaSample3.preCheck; counter=" + counter); return true; } /** * Perform and log any post-transformation info. * * The extension should validate that it's extension was * properly called; we also validate output file. * * @param logger Logger to dump any info to * @param datalet Datalet of current stylesheet test */ public static void postCheck(Logger logger, StylesheetDatalet datalet) { // Verify that we've been called at least once if (counter > 0) logger.checkPass("javaSample3 has been called " + counter + " times"); else logger.checkFail("javaSample3 has not been called"); // We also validate the output file the normal way CheckService fileChecker = (CheckService)datalet.options.get("fileCheckerImpl"); // Supply default value if (null == fileChecker) fileChecker = new XHTFileCheckService(); if (Logger.PASS_RESULT != fileChecker.check(logger, new File(datalet.outputName), new File(datalet.goldName), "Extension test of " + datalet.getDescription()) ) { // Log a custom element with all the file refs first // Closely related to viewResults.xsl select='fileref" //@todo check that these links are valid when base // paths are either relative or absolute! Hashtable attrs = new Hashtable(); attrs.put("idref", (new File(datalet.inputName)).getName()); attrs.put("inputName", datalet.inputName); attrs.put("xmlName", datalet.xmlName); attrs.put("outputName", datalet.outputName); attrs.put("goldName", datalet.goldName); logger.logElement(Logger.STATUSMSG, "fileref", attrs, "Extension test file references"); } } /** * Description of what this extension does. * @return String description of extension */ public static String getDescription() { return "getDate() returns date for ints"; } } 1.1 xml-xalan/test/tests/extensions/java/javaSample3.xml Index: javaSample3.xml =================================================================== <?xml version="1.0"?> <doc> <!-- Copied from: java/samples/extensions/3-java-namespace.xml --> <date year="2001" month="5" day="27" format="EEEE, MMM dd, yyyy"/> </doc> 1.1 xml-xalan/test/tests/extensions/java/javaSample3.xsl Index: javaSample3.xsl =================================================================== <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:java="http://xml.apache.org/xslt/java" version="1.0"> <!-- Copied from: java/samples/extensions/3-java-namespace.xsl --> <xsl:output method="xml" indent="yes"/> <xsl:template match="/"> <out> <xsl:apply-templates select="/doc/date"/> </out> </xsl:template> <xsl:template match="date"> <xsl:variable name="year" select="string(@year)"/> <xsl:variable name="month" select="string(@month)"/> <xsl:variable name="day" select="string(@day)"/> <xsl:variable name="format" select="string(@format)"/> <xsl:variable name="formatter" select="java:java.text.SimpleDateFormat.new($format)"/> <xsl:variable name="date" select="java:javaSample3.getDate($year,$month,$day)"/> <p>Format: <xsl:value-of select="$format"/></p> <p>Date-xml: y:<xsl:value-of select="$year"/> m:<xsl:value-of select="$month"/> d:<xsl:value-of select="$day"/></p> <p>Date-ext: <xsl:value-of select="java:format($formatter, $date)"/></p> </xsl:template> </xsl:stylesheet> 1.1 xml-xalan/test/tests/extensions/java/javaSample4.java Index: javaSample4.java =================================================================== /* * Covered by The Apache Software License, Version 1.1 * See xml-xalan/java/License */ // explicitly packageless import org.apache.qetest.CheckService; import org.apache.qetest.Logger; import org.apache.qetest.xsl.StylesheetDatalet; import org.apache.qetest.xsl.TestableExtension; import org.apache.qetest.xsl.XHTFileCheckService; import java.io.File; import java.util.Hashtable; /** * Extension for testing xml-xalan/samples/extensions. */ public class javaSample4 extends TestableExtension { static Hashtable counters = new Hashtable (); /** Simple extension method to setup hashtable. */ public void init(org.apache.xalan.extensions.XSLProcessorContext context, org.w3c.dom.Element elem) { counter++; // every method call increments plain counter String name = elem.getAttribute("name"); String value = elem.getAttribute("value"); int val; try { val = Integer.parseInt (value); } catch (NumberFormatException e) { e.printStackTrace (); val = 0; } counters.put (name, new Integer (val)); } /** Simple extension method to get a value from the hashtable. */ public int read(String name) { counter++; // every method call increments plain counter Integer cval = (Integer)counters.get(name); return (cval == null) ? 0 : cval.intValue(); } /** Simple extension method to increment a value in the hashtable. */ public void incr(org.apache.xalan.extensions.XSLProcessorContext context, org.w3c.dom.Element elem) { counter++; // every method call increments plain counter String name = elem.getAttribute("name"); Integer cval = (Integer) counters.get(name); int nval = (cval == null) ? 0 : (cval.intValue () + 1); counters.put (name, new Integer (nval)); } //// Implementations of TestableExtension /** Plain counter of number of times called. */ private static int counter = 0; /** * Perform and log any pre-transformation info. * @return true if OK; false if any fatal error occoured * @param datalet Datalet of current stylesheet test */ public static boolean preCheck(Logger logger, StylesheetDatalet datalet) { logger.logMsg(Logger.INFOMSG, "javaSample4.preCheck; counter=" + counter); return true; } /** * Perform and log any post-transformation info. * * The extension should validate that it's extension was * properly called; we also validate output file. * * @param logger Logger to dump any info to * @param datalet Datalet of current stylesheet test */ public static void postCheck(Logger logger, StylesheetDatalet datalet) { // Dump out our hashtable for user analysis logger.logHashtable(Logger.STATUSMSG, counters, "javaSample4.postCheck() counters"); // Verify that we've been called at least once //@todo update to verify specific number of calls and hash entries if (counter > 0) logger.checkPass("javaSample4 has been called " + counter + " times"); else logger.checkFail("javaSample4 has not been called"); // We also validate the output file the normal way CheckService fileChecker = (CheckService)datalet.options.get("fileCheckerImpl"); // Supply default value if (null == fileChecker) fileChecker = new XHTFileCheckService(); if (Logger.PASS_RESULT != fileChecker.check(logger, new File(datalet.outputName), new File(datalet.goldName), "Extension test of " + datalet.getDescription()) ) { // Log a custom element with all the file refs first // Closely related to viewResults.xsl select='fileref" //@todo check that these links are valid when base // paths are either relative or absolute! Hashtable attrs = new Hashtable(); attrs.put("idref", (new File(datalet.inputName)).getName()); attrs.put("inputName", datalet.inputName); attrs.put("xmlName", datalet.xmlName); attrs.put("outputName", datalet.outputName); attrs.put("goldName", datalet.goldName); logger.logElement(Logger.STATUSMSG, "fileref", attrs, "Extension test file references"); } } /** * Description of what this extension does. * @return String description of extension */ public static String getDescription() { return "Simple hashtable lookup and counter"; } } 1.1 xml-xalan/test/tests/extensions/java/javaSample4.xml Index: javaSample4.xml =================================================================== <?xml version="1.0"?> <doc> <name first="Sanjiva" last="Weerawarana"/> <name first="Joseph" last="Kesselman"/> <name first="Stephen" last="Auriemma"/> <name first="Igor" last="Belakovskiy"/> <name first="David" last="Marston"/> <name first="David" last="Bertoni"/> <name first="Donald" last="Leslie"/> <name first="Emily" last="Farmer"/> <name first="Myriam" last="Midy"/> <name first="Paul" last="Dick"/> <name first="Scott" last="Boag"/> <name first="Shane" last="Curcuru"/> <name first="Marcia" last="Hoffman"/> <name first="Noah" last="Mendelsohn"/> <name first="Alex" last="Morrow"/> </doc> 1.1 xml-xalan/test/tests/extensions/java/javaSample4.xsl Index: javaSample4.xsl =================================================================== <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:lxslt="http://xml.apache.org/xslt" xmlns:counter="MyCounter" extension-element-prefixes="counter" version="1.0"> <lxslt:component prefix="counter" elements="init incr" functions="read"> <lxslt:script lang="javaclass" src="javaSample4"/> </lxslt:component> <xsl:template match="/"> <HTML> <H1>Java Example</H1> <counter:init name="index" value="1"/> <p>Here are the names in alphabetical order by last name:</p> <xsl:for-each select="doc/name"> <xsl:sort select="@last"/> <xsl:sort select="@first"/> <p> <xsl:text>[</xsl:text> <xsl:value-of select="counter:read('index')"/> <xsl:text>]. </xsl:text> <xsl:value-of select="@last"/> <xsl:text>, </xsl:text> <xsl:value-of select="@first"/> </p> <counter:incr name="index"/> </xsl:for-each> </HTML> </xsl:template> </xsl:stylesheet> 1.1 xml-xalan/test/tests/extensions/javascript/javascriptSample5.xml Index: javascriptSample5.xml =================================================================== <?xml version="1.0"?> <doc> <name first="Sanjiva" last="Weerawarana"/> <name first="Joseph" last="Kesselman"/> <name first="Stephen" last="Auriemma"/> <name first="Igor" last="Belakovskiy"/> <name first="David" last="Marston"/> <name first="David" last="Bertoni"/> <name first="Donald" last="Leslie"/> <name first="Emily" last="Farmer"/> <name first="Myriam" last="Midy"/> <name first="Paul" last="Dick"/> <name first="Scott" last="Boag"/> <name first="Shane" last="Curcuru"/> <name first="Marcia" last="Hoffman"/> <name first="Noah" last="Mendelsohn"/> <name first="Alex" last="Morrow"/> </doc> 1.1 xml-xalan/test/tests/extensions/javascript/javascriptSample5.xsl Index: javascriptSample5.xsl =================================================================== <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:lxslt="http://xml.apache.org/xslt" xmlns:counter="MyCounter" extension-element-prefixes="counter" version="1.0"> <!-- Copied from: java/samples/extensions/5-numlistJscript.xsl --> <lxslt:component prefix="counter" elements="init incr" functions="read"> <lxslt:script lang="javascript"> var counters = new Array(); function init (xslproc, elem) { name = elem.getAttribute ("name"); value = parseInt(elem.getAttribute ("value")); counters[name] = value; return null; } function read (name) { return "" + (counters[name]); } function incr (xslproc, elem) { name = elem.getAttribute ("name"); counters[name]++; return null; } </lxslt:script> </lxslt:component> <xsl:template match="/"> <HTML> <H1>JavaScript Example.</H1> <counter:init name="index" value="1"/> <p>Here are the names in alphabetical order by last name:</p> <xsl:for-each select="doc/name"> <xsl:sort select="@last"/> <xsl:sort select="@first"/> <p> <xsl:text>[</xsl:text> <xsl:value-of select="counter:read('index')"/> <xsl:text>]. </xsl:text> <xsl:value-of select="@last"/> <xsl:text>, </xsl:text> <xsl:value-of select="@first"/> </p> <counter:incr name="index"/> </xsl:for-each> </HTML> </xsl:template> </xsl:stylesheet> --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]