xref: /aosp_15_r20/external/apache-xml/test/tests/extensions/java/javaRedir2.java (revision 1212f9a0ffdc28482b8821715d2222bf16dc14e2)
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 java.io.File;
28 import java.util.Hashtable;
29 
30 /**
31  * Extension for testing xml-xalan/samples/extensions.
32  */
33 public class javaRedir2 extends TestableExtension
34 {
35     /** Note: no actual extension methods here; this class just does validation.  */
36 
37     /** Copied from javaRedir2.xml[/doc/list/item].  */
38     public static final String APPEND_WRITE1_NAME = "javaRedir2a-write1.out";
39 
40     /** Copied from javaRedir2.xml[/doc/list/item].  */
41     public static final String APPEND_WRITE2_NAME = "javaRedir2a-write2.out";
42 
43     /**
44      * Perform and log any pre-transformation info.
45      * @return true if OK; false if any fatal error occoured
46      * @param datalet Datalet of current stylesheet test
47      */
preCheck(Logger logger, StylesheetDatalet datalet)48     public static boolean preCheck(Logger logger, StylesheetDatalet datalet)
49     {
50         logger.logMsg(Logger.TRACEMSG, "javaRedir2.preCheck");
51         return true;
52     }
53 
54 
55     /**
56      * Perform and log any post-transformation info.
57      *
58      * The extension should validate that it's extension was
59      * properly called; we also validate output file(s).
60      *
61      * @param logger Logger to dump any info to
62      * @param datalet Datalet of current stylesheet test
63      */
postCheck(Logger logger, StylesheetDatalet datalet)64     public static void postCheck(Logger logger, StylesheetDatalet datalet)
65     {
66         logger.logMsg(Logger.TRACEMSG, "javaRedir2.postCheck");
67 
68         // First, validate the normal output file the normal way
69         CheckService fileChecker = (CheckService)datalet.options.get("fileCheckerImpl");
70         // Supply default value
71         if (null == fileChecker)
72             fileChecker = new XHTFileCheckService();
73         fileChecker.check(logger,
74                           new File(datalet.outputName),
75                           new File(datalet.goldName),
76                           "Extension test of " + datalet.getDescription());
77 
78         // Now, also validate the redirected output from multiple files!
79         // REPEAT for inner redirected file
80         String goldRedir = (new File(datalet.goldName)).getParent()
81                            + File.separator + APPEND_WRITE1_NAME;
82         String outRedir = (new File(datalet.outputName)).getParent()
83                           + File.separator + APPEND_WRITE1_NAME;
84         fileChecker.check(logger,
85                           new File(outRedir),
86                           new File(goldRedir),
87                           "Redir-Append-Inner-Extension test of " + datalet.getDescription());
88 
89         // REPEAT for outer redirected file
90         goldRedir = (new File(datalet.goldName)).getParent()
91                            + File.separator + APPEND_WRITE2_NAME;
92         outRedir = (new File(datalet.outputName)).getParent()
93                           + File.separator + APPEND_WRITE2_NAME;
94         fileChecker.check(logger,
95                           new File(outRedir),
96                           new File(goldRedir),
97                           "Redir-AppendOuter-Extension test of " + datalet.getDescription());
98     }
99 
100 
101     /**
102      * Description of what this extension does.
103      * @return String description of extension
104      */
getDescription()105     public static String getDescription()
106     {
107         return "No extension methods - just validation";
108     }
109 }
110 
111