• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  * $Id$
20  */
21 
22 /*
23  *
24  * XSLTestfileInfo.java
25  *
26  */
27 package org.apache.qetest.xsl;
28 
29 import java.util.Properties;
30 import java.util.StringTokenizer;
31 
32 import org.apache.qetest.TestfileInfo;
33 
34 /**
35  * Simple data-holding class specifying info about one 'testfile'.
36  * <p>Convenience class for XSL Processor testing, includes
37  * additional fields and overrides some methods to change order
38  * of initializer strings.</p>
39  * <ul>Fields read in new order:
40  * <li>inputName - xsl stylesheet</li>
41  * <li>xmlName - xml data file <b>new</b></li>
42  * <li>outputName - for results of transform</li>
43  * <li>goldName</li>
44  * <li>description</li>
45  * <li>author</li>
46  * <li>options</li>
47  * </ul>
48  * @author Shane Curcuru
49  * @version $Id$
50  */
51 public class XSLTestfileInfo extends TestfileInfo
52 {
53 
54     /** Name of the input XML data file. */
55     public String xmlName = null;
56 
57     /** NEEDSDOC Field XMLNAME          */
58     public static final String XMLNAME = "xmlName";
59 
60     /** No-arg constructor leaves everything null. */
XSLTestfileInfo()61     public XSLTestfileInfo(){}
62 
63     /**
64      * Initialize members from name=value pairs in Properties block.
65      * Default value for each field is null.
66      * @param Properties block to initialize from
67      *
68      * NEEDSDOC @param p
69      */
XSLTestfileInfo(Properties p)70     public XSLTestfileInfo(Properties p)
71     {
72         load(p);
73     }
74 
75     /**
76      * Pass in a StringTokenizer-default-delimited string to initialize members.
77      * <p>Members are read in order: inputName <i>xmlName</i> outputName goldName
78      * author description options...
79      * default value for each field is null</p>
80      * @param String to initialize from
81      *
82      * NEEDSDOC @param inputStr
83      */
XSLTestfileInfo(String inputStr)84     public XSLTestfileInfo(String inputStr)
85     {
86 
87         StringTokenizer st = new StringTokenizer(inputStr);
88 
89         load(st, null);
90     }
91 
92     /**
93      * Pass in a StringTokenizer-default-delimited string to initialize members.
94      * <p>Members are read in order: inputName <i>xmlName</i> outputName goldName
95      * author description options...
96      * default value for each field is user-specified String</p>
97      * @param String to initialize from
98      * @param String to use as default for any un-specified value
99      *
100      * NEEDSDOC @param inputStr
101      * NEEDSDOC @param defaultVal
102      */
XSLTestfileInfo(String inputStr, String defaultVal)103     public XSLTestfileInfo(String inputStr, String defaultVal)
104     {
105 
106         StringTokenizer st = new StringTokenizer(inputStr);
107 
108         load(st, defaultVal);
109     }
110 
111     /**
112      * Pass in a specified-delimited string to initialize members.
113      * <p>Members are read in order: inputName <i>xmlName</i> outputName goldName
114      * author description options...
115      * default value for each field is user-specified String</p>
116      * @param String to initialize from
117      * @param String to use as default for any un-specified value
118      * @param String to use as separator for StringTokenizer
119      *
120      * NEEDSDOC @param inputStr
121      * NEEDSDOC @param defaultVal
122      * NEEDSDOC @param separator
123      */
XSLTestfileInfo(String inputStr, String defaultVal, String separator)124     public XSLTestfileInfo(String inputStr, String defaultVal,
125                            String separator)
126     {
127 
128         StringTokenizer st = new StringTokenizer(inputStr, separator);
129 
130         load(st, defaultVal);
131     }
132 
133     /**
134      * Worker method to initialize members.
135      *
136      * NEEDSDOC @param st
137      * NEEDSDOC @param defaultVal
138      */
load(StringTokenizer st, String defaultVal)139     public void load(StringTokenizer st, String defaultVal)
140     {
141 
142         // Fill in as many items as are available; default the value otherwise
143         // Note that order is important!
144         if (st.hasMoreTokens())
145             inputName = st.nextToken();
146         else
147             inputName = defaultVal;
148 
149         // Override from base class: put the xmlName next
150         if (st.hasMoreTokens())
151             xmlName = st.nextToken();
152         else
153             xmlName = defaultVal;
154 
155         if (st.hasMoreTokens())
156             outputName = st.nextToken();
157         else
158             outputName = defaultVal;
159 
160         if (st.hasMoreTokens())
161             goldName = st.nextToken();
162         else
163             goldName = defaultVal;
164 
165         if (st.hasMoreTokens())
166             author = st.nextToken();
167         else
168             author = defaultVal;
169 
170         if (st.hasMoreTokens())
171             description = st.nextToken();
172         else
173             description = defaultVal;
174 
175         if (st.hasMoreTokens())
176         {
177             options = st.nextToken();
178 
179             // For now, simply glom all additional tokens into the options, until the end of string
180             // Leave separated with a single space char for readability
181             while (st.hasMoreTokens())
182             {
183                 options += " " + st.nextToken();
184             }
185         }
186         else
187             options = defaultVal;
188     }
189 
190     /**
191      * Initialize members from name=value pairs in Properties block.
192      * Default value for each field is null.
193      * @param Properties block to initialize from
194      *
195      * NEEDSDOC @param p
196      */
load(Properties p)197     public void load(Properties p)
198     {
199 
200         inputName = p.getProperty(INPUTNAME);
201         xmlName = p.getProperty(XMLNAME);  // Override from base class
202         outputName = p.getProperty(OUTPUTNAME);
203         goldName = p.getProperty(GOLDNAME);
204         author = p.getProperty(AUTHOR);
205         description = p.getProperty(DESCRIPTION);
206         options = p.getProperty(OPTIONS);
207     }
208 
209     /**
210      * Cheap-o debugging: return tab-delimited String of all our values.
211      *
212      * NEEDSDOC ($objectName$) @return
213      */
dump()214     public String dump()
215     {
216 
217         return (inputName + '\t' + xmlName  // Override from base class
218                 + '\t' + outputName + '\t' + goldName + '\t' + author + '\t'
219                 + description + '\t' + options);
220     }
221 }
222