1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 // explicitly packageless 20 21 import org.apache.qetest.CheckService; 22 import org.apache.qetest.Logger; 23 import org.apache.qetest.xsl.StylesheetDatalet; 24 import org.apache.qetest.xsl.TestableExtension; 25 import org.apache.qetest.xsl.XHTFileCheckService; 26 27 import org.w3c.dom.Node; 28 import org.w3c.dom.NodeList; 29 30 import java.io.File; 31 import java.util.Hashtable; 32 33 /** 34 * Extension for testing xml-xalan/samples/extensions. 35 */ 36 public class javaBugzilla3722 extends TestableExtension 37 { 38 static Hashtable counters = new Hashtable (); 39 40 static private Logger extnLogger = null; 41 42 /** Extension method from Bugzilla3722. */ dumpConfig(NodeList conf)43 public String dumpConfig(NodeList conf) 44 { 45 counter++; 46 if (conf != null) 47 { 48 for (int i=0; i<conf.getLength(); i++) 49 { 50 Node node = conf.item(i); 51 if (node!=null) 52 { 53 if (node.hasChildNodes()) 54 { 55 // getLogger().debug("<" + node.getNodeName() + ">"); 56 try 57 { 58 // Below line throws DTMDOMException on CVS code 21-Sep-01 59 NodeList subList = node.getChildNodes(); 60 this.dumpConfig(subList); 61 } 62 catch (Exception e) 63 { 64 if (extnLogger == null) 65 { 66 e.printStackTrace(); 67 throw new RuntimeException("FATAL ERROR: javaBugzilla3722 has no logger; " + e.toString()); 68 } 69 else 70 { 71 extnLogger.logThrowable(Logger.ERRORMSG, e, "dumpConfig threw:"); 72 extnLogger.checkFail("dumpConfig threw unexpected exception"); 73 } 74 } 75 } else 76 { 77 // Output info about the node for later debugging 78 counters.put(node.getNodeName(), node.getNodeValue()); 79 } 80 } 81 } 82 } 83 return "dumpConfig.count=" + counter; 84 } 85 86 //// Implementations of TestableExtension 87 /** Plain counter of number of times called. */ 88 private static int counter = 0; 89 90 91 /** 92 * Perform and log any pre-transformation info. 93 * @return true if OK; false if any fatal error occoured 94 * @param datalet Datalet of current stylesheet test 95 */ preCheck(Logger logger, StylesheetDatalet datalet)96 public static boolean preCheck(Logger logger, StylesheetDatalet datalet) 97 { 98 logger.logMsg(Logger.INFOMSG, "javaBugzilla3722.preCheck; counter=" + counter); 99 extnLogger = logger; 100 return true; 101 } 102 103 104 /** 105 * Perform and log any post-transformation info. 106 * 107 * The extension should validate that it's extension was 108 * properly called; we also validate output file. 109 * 110 * @param logger Logger to dump any info to 111 * @param datalet Datalet of current stylesheet test 112 */ postCheck(Logger logger, StylesheetDatalet datalet)113 public static void postCheck(Logger logger, StylesheetDatalet datalet) 114 { 115 // Dump out our hashtable for user analysis 116 logger.logHashtable(Logger.STATUSMSG, counters, "javaBugzilla3722.postCheck() counters"); 117 118 // Verify that we've been called at least once 119 //@todo update to verify specific number of calls and hash entries 120 if (counter > 0) 121 logger.checkPass("javaBugzilla3722 has been called " + counter + " times"); 122 else 123 logger.checkFail("javaBugzilla3722 has not been called"); 124 125 // We also validate the output file the normal way 126 CheckService fileChecker = (CheckService)datalet.options.get("fileCheckerImpl"); 127 // Supply default value 128 if (null == fileChecker) 129 fileChecker = new XHTFileCheckService(); 130 fileChecker.check(logger, 131 new File(datalet.outputName), 132 new File(datalet.goldName), 133 "Extension test of " + datalet.getDescription()); 134 } 135 136 137 /** 138 * Description of what this extension does. 139 * @return String description of extension 140 */ getDescription()141 public static String getDescription() 142 { 143 return "Reproduce Bugzilla # 3722"; 144 } 145 } 146