1*ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ef39d40dSAndrew Rist  * distributed with this work for additional information
6*ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9*ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*ef39d40dSAndrew Rist  *
11*ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*ef39d40dSAndrew Rist  *
13*ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15*ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18*ef39d40dSAndrew Rist  * under the License.
19*ef39d40dSAndrew Rist  *
20*ef39d40dSAndrew Rist  *************************************************************/
21*ef39d40dSAndrew Rist 
22*ef39d40dSAndrew Rist 
23cdf0e10cSrcweir package helper;
24cdf0e10cSrcweir 
25cdf0e10cSrcweir import java.io.BufferedReader;
26cdf0e10cSrcweir import java.io.File;
27cdf0e10cSrcweir import java.io.FileReader;
28cdf0e10cSrcweir import java.io.InputStream;
29cdf0e10cSrcweir import java.io.InputStreamReader;
30cdf0e10cSrcweir 
31cdf0e10cSrcweir import java.util.ArrayList;
32cdf0e10cSrcweir import java.util.Collections;
33cdf0e10cSrcweir import java.util.StringTokenizer;
34cdf0e10cSrcweir 
35cdf0e10cSrcweir import share.DescEntry;
36cdf0e10cSrcweir import share.DescGetter;
37cdf0e10cSrcweir 
38cdf0e10cSrcweir /**
39cdf0e10cSrcweir  * This is the Office-API specific DescGetter<br>
40cdf0e10cSrcweir  * <br>
41cdf0e10cSrcweir  * Examples:<br><br>
42cdf0e10cSrcweir  * -o sw.SwXBodyText<br>
43cdf0e10cSrcweir  * runs the module test of <B>Sw.SwXBodyText</B><br>
44cdf0e10cSrcweir  * <br>
45cdf0e10cSrcweir  * -o sw.SwXBodyText::com::sun::star::text::Text<br>
46cdf0e10cSrcweir  * runs only the interface test <B>com.sun.star.textText</B> of the module <B>Sw.SwXBodyText</B><br>
47cdf0e10cSrcweir  * <br>
48cdf0e10cSrcweir  * -o sw.SwXBodyText::com::sun::star::text::Text,com::sun::star::text::XSimpleText<br>
49cdf0e10cSrcweir  * runs only the interfaces test <B>com.sun.star.textText</B> and <B>com.sun.star.text.XSimpleText</B> of the module <B>Sw.SwXBodyText</B><br>
50cdf0e10cSrcweir  * <br>
51cdf0e10cSrcweir  * -p sw<br>
52cdf0e10cSrcweir  * runs all modules of the project <B>sw</B><br>
53cdf0e10cSrcweir  * <br>
54cdf0e10cSrcweir  * -p listall<br>
55cdf0e10cSrcweir  * lists all known module tests<br>
56cdf0e10cSrcweir  * <br>
57cdf0e10cSrcweir  * -sce SCENARIO_FILE<br>
58cdf0e10cSrcweir  * A scenario file is a property file which could cotain <B>-o</B> and <B>-p</B> properties<br>
59cdf0e10cSrcweir  * <br>
60cdf0e10cSrcweir  * -sce sw.SwXBodyText,sw.SwXBookmark<br>
61cdf0e10cSrcweir  * runs the module test of <B>Sw.SwXBodyText</B> and <B>sw.SwXBookmark</B><br>
62cdf0e10cSrcweir  */
63cdf0e10cSrcweir public class APIDescGetter extends DescGetter
64cdf0e10cSrcweir {
65cdf0e10cSrcweir 
66cdf0e10cSrcweir     private static String fullJob = null;
67cdf0e10cSrcweir 
68cdf0e10cSrcweir     /*
69cdf0e10cSrcweir      * gets the needed information about a StarOffice component
70cdf0e10cSrcweir      * @param descPath Path to the ComponentDescription
71cdf0e10cSrcweir      * @param entry contains the entry name, e.g. sw.SwXBodyText
72cdf0e10cSrcweir      * @param debug if true some debug information is displayed on standard out
73cdf0e10cSrcweir      */
getDescriptionFor(String job, String descPath, boolean debug)74cdf0e10cSrcweir     public DescEntry[] getDescriptionFor(String job, String descPath,
75cdf0e10cSrcweir             boolean debug)
76cdf0e10cSrcweir     {
77cdf0e10cSrcweir 
78cdf0e10cSrcweir         if (job.startsWith("-o"))
79cdf0e10cSrcweir         {
80cdf0e10cSrcweir             job = job.substring(3, job.length()).trim();
81cdf0e10cSrcweir 
82cdf0e10cSrcweir             if (job.indexOf(".") < 0)
83cdf0e10cSrcweir             {
84cdf0e10cSrcweir                 return null;
85cdf0e10cSrcweir             }
86cdf0e10cSrcweir 
87cdf0e10cSrcweir             // special in case several Interfaces are given comma separated
88cdf0e10cSrcweir             if (job.indexOf(",") < 0)
89cdf0e10cSrcweir             {
90cdf0e10cSrcweir                 DescEntry entry = getDescriptionForSingleJob(job, descPath,
91cdf0e10cSrcweir                         debug);
92cdf0e10cSrcweir 
93cdf0e10cSrcweir                 if (entry != null)
94cdf0e10cSrcweir                 {
95cdf0e10cSrcweir                     return new DescEntry[]
96cdf0e10cSrcweir                             {
97cdf0e10cSrcweir                                 entry
98cdf0e10cSrcweir                             };
99cdf0e10cSrcweir                 }
100cdf0e10cSrcweir                 else
101cdf0e10cSrcweir                 {
102cdf0e10cSrcweir                     return null;
103cdf0e10cSrcweir                 }
104cdf0e10cSrcweir             }
105cdf0e10cSrcweir             else
106cdf0e10cSrcweir             {
107cdf0e10cSrcweir                 ArrayList subs = getSubInterfaces(job);
108cdf0e10cSrcweir                 String partjob = job.substring(0, job.indexOf(",")).trim();
109cdf0e10cSrcweir                 DescEntry entry = getDescriptionForSingleJob(partjob, descPath,
110cdf0e10cSrcweir                         debug);
111cdf0e10cSrcweir 
112cdf0e10cSrcweir                 if (entry != null)
113cdf0e10cSrcweir                 {
114cdf0e10cSrcweir                     for (int i = 0; i < entry.SubEntryCount; i++)
115cdf0e10cSrcweir                     {
116cdf0e10cSrcweir                         String subEntry = entry.SubEntries[i].longName;
117cdf0e10cSrcweir                         int cpLength = entry.longName.length();
118cdf0e10cSrcweir                         subEntry = subEntry.substring(cpLength + 2,
119cdf0e10cSrcweir                                 subEntry.length());
120cdf0e10cSrcweir 
121cdf0e10cSrcweir                         if (subs.contains(subEntry))
122cdf0e10cSrcweir                         {
123cdf0e10cSrcweir                             entry.SubEntries[i].isToTest = true;
124cdf0e10cSrcweir                         }
125cdf0e10cSrcweir                     }
126cdf0e10cSrcweir 
127cdf0e10cSrcweir                     return new DescEntry[]
128cdf0e10cSrcweir                             {
129cdf0e10cSrcweir                                 entry
130cdf0e10cSrcweir                             };
131cdf0e10cSrcweir                 }
132cdf0e10cSrcweir                 else
133cdf0e10cSrcweir                 {
134cdf0e10cSrcweir                     return null;
135cdf0e10cSrcweir                 }
136cdf0e10cSrcweir             }
137cdf0e10cSrcweir         }
138cdf0e10cSrcweir 
139cdf0e10cSrcweir         if (job.startsWith("-p"))
140cdf0e10cSrcweir         {
141cdf0e10cSrcweir             job = job.substring(3, job.length()).trim();
142cdf0e10cSrcweir 
143cdf0e10cSrcweir             String[] scenario = createScenario(descPath, job, debug);
144cdf0e10cSrcweir             if (scenario == null)
145cdf0e10cSrcweir             {
146cdf0e10cSrcweir                 return null;
147cdf0e10cSrcweir             }
148cdf0e10cSrcweir             DescEntry[] entries = new DescEntry[scenario.length];
149cdf0e10cSrcweir             for (int i = 0; i < scenario.length; i++)
150cdf0e10cSrcweir             {
151cdf0e10cSrcweir                 entries[i] = getDescriptionForSingleJob(
152cdf0e10cSrcweir                         scenario[i].substring(3).trim(), descPath, debug);
153cdf0e10cSrcweir             }
154cdf0e10cSrcweir             if (job.equals("listall"))
155cdf0e10cSrcweir             {
156cdf0e10cSrcweir                 util.dbg.printArray(scenario);
157cdf0e10cSrcweir                 System.exit(0);
158cdf0e10cSrcweir             }
159cdf0e10cSrcweir             return entries;
160cdf0e10cSrcweir         }
161cdf0e10cSrcweir 
162cdf0e10cSrcweir         if (job.startsWith("-sce"))
163cdf0e10cSrcweir         {
164cdf0e10cSrcweir             job = job.substring(5, job.length()).trim();
165cdf0e10cSrcweir 
166cdf0e10cSrcweir             File sceFile = new File(job);
167cdf0e10cSrcweir             if (sceFile.exists())
168cdf0e10cSrcweir             {
169cdf0e10cSrcweir                 return getScenario(job, descPath, debug);
170cdf0e10cSrcweir             }
171cdf0e10cSrcweir             else
172cdf0e10cSrcweir             {
173cdf0e10cSrcweir                 //look the scenarion like this? :
174cdf0e10cSrcweir                 // sw.SwXBodyText,sw.SwXTextCursor
175cdf0e10cSrcweir                 ArrayList subs = getSubObjects(job);
176cdf0e10cSrcweir                 DescEntry[] entries = new DescEntry[subs.size()];
177cdf0e10cSrcweir 
178cdf0e10cSrcweir                 for (int i = 0; i < subs.size(); i++)
179cdf0e10cSrcweir                 {
180cdf0e10cSrcweir                     entries[i] = getDescriptionForSingleJob(
181cdf0e10cSrcweir                             (String) subs.get(i), descPath, debug);
182cdf0e10cSrcweir                 }
183cdf0e10cSrcweir                 return entries;
184cdf0e10cSrcweir             }
185cdf0e10cSrcweir         }
186cdf0e10cSrcweir         else
187cdf0e10cSrcweir         {
188cdf0e10cSrcweir             return null;
189cdf0e10cSrcweir         }
190cdf0e10cSrcweir     }
191cdf0e10cSrcweir 
getDescriptionForSingleJob(String job, String descPath, boolean debug)192cdf0e10cSrcweir     protected DescEntry getDescriptionForSingleJob(String job, String descPath,
193cdf0e10cSrcweir             boolean debug)
194cdf0e10cSrcweir     {
195cdf0e10cSrcweir         boolean isSingleInterface = job.indexOf("::") > 0;
196cdf0e10cSrcweir         fullJob = job;
197cdf0e10cSrcweir 
198cdf0e10cSrcweir         if (isSingleInterface)
199cdf0e10cSrcweir         {
200cdf0e10cSrcweir             job = job.substring(0, job.indexOf("::"));
201cdf0e10cSrcweir         }
202cdf0e10cSrcweir 
203cdf0e10cSrcweir         if (job.startsWith("bugs"))
204cdf0e10cSrcweir         {
205cdf0e10cSrcweir             DescEntry Entry = new DescEntry();
206cdf0e10cSrcweir             Entry.entryName = job;
207cdf0e10cSrcweir             Entry.longName = job;
208cdf0e10cSrcweir             Entry.EntryType = "bugdoc";
209cdf0e10cSrcweir             Entry.isOptional = false;
210cdf0e10cSrcweir             Entry.isToTest = true;
211cdf0e10cSrcweir             Entry.SubEntryCount = 0;
212cdf0e10cSrcweir             Entry.hasErrorMsg = false;
213cdf0e10cSrcweir             Entry.State = "non possible";
214cdf0e10cSrcweir 
215cdf0e10cSrcweir             return Entry;
216cdf0e10cSrcweir         }
217cdf0e10cSrcweir 
218cdf0e10cSrcweir         DescEntry entry = null;
219cdf0e10cSrcweir 
220cdf0e10cSrcweir         if (descPath != null)
221cdf0e10cSrcweir         {
222cdf0e10cSrcweir             if (debug)
223cdf0e10cSrcweir             {
224cdf0e10cSrcweir                 System.out.println("## reading from File " + descPath);
225cdf0e10cSrcweir             }
226cdf0e10cSrcweir 
227cdf0e10cSrcweir             entry = getFromDirectory(descPath, job, debug);
228cdf0e10cSrcweir         }
229cdf0e10cSrcweir         else
230cdf0e10cSrcweir         {
231cdf0e10cSrcweir             if (debug)
232cdf0e10cSrcweir             {
233cdf0e10cSrcweir                 System.out.println("## reading from jar");
234cdf0e10cSrcweir             }
235cdf0e10cSrcweir 
236cdf0e10cSrcweir             entry = getFromClassPath(job, debug);
237cdf0e10cSrcweir         }
238cdf0e10cSrcweir 
239cdf0e10cSrcweir         boolean foundInterface = false;
240cdf0e10cSrcweir 
241cdf0e10cSrcweir         if (isSingleInterface && (entry != null))
242cdf0e10cSrcweir         {
243cdf0e10cSrcweir             for (int i = 0; i < entry.SubEntryCount; i++)
244cdf0e10cSrcweir             {
245cdf0e10cSrcweir                 if (!(entry.SubEntries[i].longName).equals(fullJob))
246cdf0e10cSrcweir                 {
247cdf0e10cSrcweir                     entry.SubEntries[i].isToTest = false;
248cdf0e10cSrcweir                 }
249cdf0e10cSrcweir                 else
250cdf0e10cSrcweir                 {
251cdf0e10cSrcweir                     foundInterface = true;
252cdf0e10cSrcweir                     entry.SubEntries[i].isToTest = true;
253cdf0e10cSrcweir                 }
254cdf0e10cSrcweir             }
255cdf0e10cSrcweir         }
256cdf0e10cSrcweir 
257cdf0e10cSrcweir         if (isSingleInterface && !foundInterface || entry == null)
258cdf0e10cSrcweir         {
259cdf0e10cSrcweir             return setErrorDescription(entry,
260cdf0e10cSrcweir                     "couldn't find a description for test '" + fullJob + "'");
261cdf0e10cSrcweir         }
262cdf0e10cSrcweir 
263cdf0e10cSrcweir         return entry;
264cdf0e10cSrcweir     }
265cdf0e10cSrcweir 
getSubEntries(BufferedReader cvsFile, DescEntry parent, boolean debug)266cdf0e10cSrcweir     protected static DescEntry[] getSubEntries(BufferedReader cvsFile,
267cdf0e10cSrcweir             DescEntry parent, boolean debug)
268cdf0e10cSrcweir     {
269cdf0e10cSrcweir         String line = "";
270cdf0e10cSrcweir         String old_ifc_name = "";
271cdf0e10cSrcweir         ArrayList ifc_names = new ArrayList();
272cdf0e10cSrcweir         ArrayList meth_names = new ArrayList();
273cdf0e10cSrcweir         DescEntry ifcDesc = null;
274cdf0e10cSrcweir 
275cdf0e10cSrcweir         while (line != null)
276cdf0e10cSrcweir         {
277cdf0e10cSrcweir             try
278cdf0e10cSrcweir             {
279cdf0e10cSrcweir                 line = cvsFile.readLine();
280cdf0e10cSrcweir                 if (line == null)
281cdf0e10cSrcweir                 {
282cdf0e10cSrcweir                     continue;
283cdf0e10cSrcweir                 }
284cdf0e10cSrcweir                 if (line.startsWith("#"))
285cdf0e10cSrcweir                 {
286cdf0e10cSrcweir                     continue;
287cdf0e10cSrcweir                 }
288cdf0e10cSrcweir                 if (line.length() <= 0)
289cdf0e10cSrcweir                 {
290cdf0e10cSrcweir                     continue;
291cdf0e10cSrcweir                 }
292cdf0e10cSrcweir // TODO Probleme here
293cdf0e10cSrcweir                 // int nFirstSemicolon = line.indexOf(";");
294cdf0e10cSrcweir                 // int nLastSemicolon = line.lastIndexOf(";");
295cdf0e10cSrcweir 
296cdf0e10cSrcweir                 String unknown;
297cdf0e10cSrcweir                 String ifc_name = ""; //  = line.substring(line.indexOf(";") + 2, line.lastIndexOf(";") - 1);
298cdf0e10cSrcweir                 String meth_name = ""; //  = line.substring(line.lastIndexOf(";") + 2, line.length() - 1);
299cdf0e10cSrcweir                 StringTokenizer aToken = new StringTokenizer(line, ";");
300cdf0e10cSrcweir                 if (aToken.countTokens() < 3)
301cdf0e10cSrcweir                 {
302cdf0e10cSrcweir                     System.out.println("Wrong format: Line '" + line + "' is not supported.");
303cdf0e10cSrcweir                     continue;
304cdf0e10cSrcweir                 }
305cdf0e10cSrcweir                 if (aToken.hasMoreTokens())
306cdf0e10cSrcweir                 {
307cdf0e10cSrcweir                     unknown = StringHelper.removeQuoteIfExists(aToken.nextToken());
308cdf0e10cSrcweir                 }
309cdf0e10cSrcweir                 if (aToken.hasMoreTokens())
310cdf0e10cSrcweir                 {
311cdf0e10cSrcweir                     ifc_name = StringHelper.removeQuoteIfExists(aToken.nextToken());
312cdf0e10cSrcweir                 }
313cdf0e10cSrcweir                 if (aToken.hasMoreTokens())
314cdf0e10cSrcweir                 {
315cdf0e10cSrcweir                     meth_name = StringHelper.removeQuoteIfExists(aToken.nextToken());
316cdf0e10cSrcweir                 }
317cdf0e10cSrcweir 
318cdf0e10cSrcweir                 // String ifc_name = line.substring(line.indexOf(";") + 2, line.lastIndexOf(";") - 1);
319cdf0e10cSrcweir                 // String meth_name = line.substring(line.lastIndexOf(";") + 2, line.length() - 1);
320cdf0e10cSrcweir 
321cdf0e10cSrcweir                 DescEntry methDesc = createDescEntry(meth_name, ifc_name, parent);
322cdf0e10cSrcweir 
323cdf0e10cSrcweir                 if (!ifc_name.equals(old_ifc_name))
324cdf0e10cSrcweir                 {
325cdf0e10cSrcweir                     if (ifcDesc != null)
326cdf0e10cSrcweir                     {
327cdf0e10cSrcweir                         ifcDesc.SubEntries = getDescArray(meth_names.toArray());
328cdf0e10cSrcweir                         ifcDesc.SubEntryCount = meth_names.size();
329cdf0e10cSrcweir 
330cdf0e10cSrcweir                         //mark service/interface as optional if all methods/properties are optional
331cdf0e10cSrcweir                         boolean allOptional = true;
332cdf0e10cSrcweir 
333cdf0e10cSrcweir                         for (int k = 0; k < ifcDesc.SubEntryCount; k++)
334cdf0e10cSrcweir                         {
335cdf0e10cSrcweir                             if (!ifcDesc.SubEntries[k].isOptional)
336cdf0e10cSrcweir                             {
337cdf0e10cSrcweir                                 allOptional = false;
338cdf0e10cSrcweir                             }
339cdf0e10cSrcweir                         }
340cdf0e10cSrcweir 
341cdf0e10cSrcweir                         if (!ifcDesc.isOptional && allOptional)
342cdf0e10cSrcweir                         {
343cdf0e10cSrcweir                             ifcDesc.isOptional = allOptional;
344cdf0e10cSrcweir                         }
345cdf0e10cSrcweir 
346cdf0e10cSrcweir                         meth_names.clear();
347cdf0e10cSrcweir                         ifc_names.add(ifcDesc);
348cdf0e10cSrcweir                     }
349cdf0e10cSrcweir 
350cdf0e10cSrcweir                     ifcDesc = new DescEntry();
351cdf0e10cSrcweir                     ifcDesc.isToTest = true;
352cdf0e10cSrcweir                     old_ifc_name = ifc_name;
353cdf0e10cSrcweir 
354cdf0e10cSrcweir                     if (ifc_name.indexOf("#optional") > 0)
355cdf0e10cSrcweir                     {
356cdf0e10cSrcweir                         ifcDesc.isOptional = true;
357cdf0e10cSrcweir                         ifc_name = ifc_name.substring(0, ifc_name.indexOf("#"));
358cdf0e10cSrcweir                     }
359cdf0e10cSrcweir 
360cdf0e10cSrcweir                     String className = createClassName(ifc_name);
361cdf0e10cSrcweir 
362cdf0e10cSrcweir                     ifcDesc.EntryType = entryType;
363cdf0e10cSrcweir                     ifcDesc.entryName = "ifc" + className;
364cdf0e10cSrcweir                     ifcDesc.longName = parent.entryName + "::" + ifc_name;
365cdf0e10cSrcweir                 }
366cdf0e10cSrcweir                 meth_names.add(methDesc);
367cdf0e10cSrcweir 
368cdf0e10cSrcweir             }
369cdf0e10cSrcweir             catch (java.io.IOException ioe)
370cdf0e10cSrcweir             {
371cdf0e10cSrcweir                 parent.hasErrorMsg = true;
372cdf0e10cSrcweir                 parent.ErrorMsg = "IOException while reading the description";
373cdf0e10cSrcweir 
374cdf0e10cSrcweir                 return null;
375cdf0e10cSrcweir             }
376cdf0e10cSrcweir         }
377cdf0e10cSrcweir 
378cdf0e10cSrcweir         ifcDesc.SubEntries = getDescArray(meth_names.toArray());
379cdf0e10cSrcweir         ifcDesc.SubEntryCount = meth_names.size();
380cdf0e10cSrcweir 
381cdf0e10cSrcweir         //mark service/interface as optional if all methods/properties are optional
382cdf0e10cSrcweir         boolean allOptional = true;
383cdf0e10cSrcweir 
384cdf0e10cSrcweir         for (int k = 0; k < ifcDesc.SubEntryCount; k++)
385cdf0e10cSrcweir         {
386cdf0e10cSrcweir             if (!ifcDesc.SubEntries[k].isOptional)
387cdf0e10cSrcweir             {
388cdf0e10cSrcweir                 allOptional = false;
389cdf0e10cSrcweir             }
390cdf0e10cSrcweir         }
391cdf0e10cSrcweir 
392cdf0e10cSrcweir         if (!ifcDesc.isOptional && allOptional)
393cdf0e10cSrcweir         {
394cdf0e10cSrcweir             ifcDesc.isOptional = allOptional;
395cdf0e10cSrcweir         }
396cdf0e10cSrcweir 
397cdf0e10cSrcweir         ifc_names.add(ifcDesc);
398cdf0e10cSrcweir 
399cdf0e10cSrcweir         return getDescArray(makeArray(ifc_names));
400cdf0e10cSrcweir     }
createClassName(String _ifc_name)401cdf0e10cSrcweir     private static String createClassName(String _ifc_name)
402cdf0e10cSrcweir     {
403cdf0e10cSrcweir         StringTokenizer st = new StringTokenizer(_ifc_name, ":");
404cdf0e10cSrcweir         String className = "";
405cdf0e10cSrcweir 
406cdf0e10cSrcweir         int count = 3;
407cdf0e10cSrcweir 
408cdf0e10cSrcweir         if (_ifc_name.startsWith("drafts"))
409cdf0e10cSrcweir         {
410cdf0e10cSrcweir             count = 4;
411cdf0e10cSrcweir         }
412cdf0e10cSrcweir 
413cdf0e10cSrcweir         for (int i = 0; st.hasMoreTokens(); i++)
414cdf0e10cSrcweir         {
415cdf0e10cSrcweir             String token = st.nextToken();
416cdf0e10cSrcweir 
417cdf0e10cSrcweir             // skipping (drafts.)com.sun.star
418cdf0e10cSrcweir             if (i >= count)
419cdf0e10cSrcweir             {
420cdf0e10cSrcweir                 if (!st.hasMoreTokens())
421cdf0e10cSrcweir                 {
422cdf0e10cSrcweir                     // inserting '_' before the last token
423cdf0e10cSrcweir                     token = "_" + token;
424cdf0e10cSrcweir                 }
425cdf0e10cSrcweir 
426cdf0e10cSrcweir                 className += ("." + token);
427cdf0e10cSrcweir             }
428cdf0e10cSrcweir         }
429cdf0e10cSrcweir         return className;
430cdf0e10cSrcweir     }
431cdf0e10cSrcweir 
432cdf0e10cSrcweir     private static String entryType;
433cdf0e10cSrcweir 
createDescEntry(String meth_name, String ifc_name, DescEntry parent)434cdf0e10cSrcweir     private static DescEntry createDescEntry(String meth_name, String ifc_name, DescEntry parent)
435cdf0e10cSrcweir     {
436cdf0e10cSrcweir         entryType = "service";
437cdf0e10cSrcweir         DescEntry methDesc = new DescEntry();
438cdf0e10cSrcweir 
439cdf0e10cSrcweir         if (meth_name.indexOf("#optional") > 0)
440cdf0e10cSrcweir         {
441cdf0e10cSrcweir             methDesc.isOptional = true;
442cdf0e10cSrcweir             meth_name = meth_name.substring(0, meth_name.indexOf("#"));
443cdf0e10cSrcweir         }
444cdf0e10cSrcweir 
445cdf0e10cSrcweir         if (meth_name.endsWith("()"))
446cdf0e10cSrcweir         {
447cdf0e10cSrcweir             methDesc.EntryType = "method";
448cdf0e10cSrcweir             entryType = "interface";
449cdf0e10cSrcweir         }
450cdf0e10cSrcweir         else
451cdf0e10cSrcweir         {
452cdf0e10cSrcweir             methDesc.EntryType = "property";
453cdf0e10cSrcweir             entryType = "service";
454cdf0e10cSrcweir         }
455cdf0e10cSrcweir 
456cdf0e10cSrcweir         methDesc.entryName = meth_name;
457cdf0e10cSrcweir         methDesc.isToTest = true;
458cdf0e10cSrcweir 
459cdf0e10cSrcweir 
460cdf0e10cSrcweir         String withoutHash = ifc_name;
461cdf0e10cSrcweir 
462cdf0e10cSrcweir         if (ifc_name.indexOf("#optional") > 0)
463cdf0e10cSrcweir         {
464cdf0e10cSrcweir             withoutHash = ifc_name.substring(0, ifc_name.indexOf("#"));
465cdf0e10cSrcweir         }
466cdf0e10cSrcweir 
467cdf0e10cSrcweir         methDesc.longName = parent.entryName + "::" + withoutHash + "::" + meth_name;
468cdf0e10cSrcweir 
469cdf0e10cSrcweir         return methDesc;
470cdf0e10cSrcweir     }
471cdf0e10cSrcweir 
createIfcName(String ifc_name, ArrayList meth_names, DescEntry ifcDesc)472cdf0e10cSrcweir     private static void createIfcName(String ifc_name, ArrayList meth_names, DescEntry ifcDesc)
473cdf0e10cSrcweir     {
474cdf0e10cSrcweir     }
475cdf0e10cSrcweir 
476cdf0e10cSrcweir     /**
477cdf0e10cSrcweir      * This method ensures that XComponent will be the last in the list of interfaces
478cdf0e10cSrcweir      */
makeArray(ArrayList entries)479cdf0e10cSrcweir     protected static Object[] makeArray(ArrayList entries)
480cdf0e10cSrcweir     {
481cdf0e10cSrcweir         Object[] entriesArray = entries.toArray();
482cdf0e10cSrcweir         ArrayList returnArray = new ArrayList();
483cdf0e10cSrcweir         Object addAtEnd = null;
484cdf0e10cSrcweir 
485cdf0e10cSrcweir         for (int k = 0; k < entriesArray.length; k++)
486cdf0e10cSrcweir         {
487cdf0e10cSrcweir             DescEntry entry = (DescEntry) entriesArray[k];
488cdf0e10cSrcweir 
489cdf0e10cSrcweir             if (entry.entryName.equals("ifc.lang._XComponent"))
490cdf0e10cSrcweir             {
491cdf0e10cSrcweir                 addAtEnd = entry;
492cdf0e10cSrcweir             }
493cdf0e10cSrcweir             else
494cdf0e10cSrcweir             {
495cdf0e10cSrcweir                 returnArray.add(entry);
496cdf0e10cSrcweir             }
497cdf0e10cSrcweir         }
498cdf0e10cSrcweir 
499cdf0e10cSrcweir         if (addAtEnd != null)
500cdf0e10cSrcweir         {
501cdf0e10cSrcweir             returnArray.add(addAtEnd);
502cdf0e10cSrcweir         }
503cdf0e10cSrcweir 
504cdf0e10cSrcweir         return returnArray.toArray();
505cdf0e10cSrcweir     }
506cdf0e10cSrcweir 
setErrorDescription(DescEntry entry, String ErrorMsg)507cdf0e10cSrcweir     protected static DescEntry setErrorDescription(DescEntry entry,
508cdf0e10cSrcweir             String ErrorMsg)
509cdf0e10cSrcweir     {
510cdf0e10cSrcweir         if (entry == null)
511cdf0e10cSrcweir         {
512cdf0e10cSrcweir             entry = new DescEntry();
513cdf0e10cSrcweir         }
514cdf0e10cSrcweir         entry.hasErrorMsg = true;
515cdf0e10cSrcweir         entry.ErrorMsg = "Error while getting description for test '" +
516cdf0e10cSrcweir                 fullJob + "' as an API test: " + ErrorMsg;
517cdf0e10cSrcweir 
518cdf0e10cSrcweir         return entry;
519cdf0e10cSrcweir     }
520cdf0e10cSrcweir 
getDescArray(Object[] list)521cdf0e10cSrcweir     protected static DescEntry[] getDescArray(Object[] list)
522cdf0e10cSrcweir     {
523cdf0e10cSrcweir         DescEntry[] entries = new DescEntry[list.length];
524cdf0e10cSrcweir 
525cdf0e10cSrcweir         for (int i = 0; i < list.length; i++)
526cdf0e10cSrcweir         {
527cdf0e10cSrcweir             entries[i] = (DescEntry) list[i];
528cdf0e10cSrcweir         }
529cdf0e10cSrcweir 
530cdf0e10cSrcweir         return entries;
531cdf0e10cSrcweir     }
532cdf0e10cSrcweir 
getFromClassPath(String aEntry, boolean debug)533cdf0e10cSrcweir     protected DescEntry getFromClassPath(String aEntry, boolean debug)
534cdf0e10cSrcweir     {
535cdf0e10cSrcweir         int dotindex = aEntry.indexOf('.');
536cdf0e10cSrcweir 
537cdf0e10cSrcweir         if (dotindex == -1)
538cdf0e10cSrcweir         {
539cdf0e10cSrcweir             return null;
540cdf0e10cSrcweir         }
541cdf0e10cSrcweir 
542cdf0e10cSrcweir         String module = null;
543cdf0e10cSrcweir         String shortName = null;
544cdf0e10cSrcweir 
545cdf0e10cSrcweir         if (aEntry.indexOf(".uno") == -1)
546cdf0e10cSrcweir         {
547cdf0e10cSrcweir             module = aEntry.substring(0, aEntry.indexOf('.'));
548cdf0e10cSrcweir             shortName = aEntry.substring(aEntry.indexOf('.') + 1);
549cdf0e10cSrcweir         }
550cdf0e10cSrcweir         else
551cdf0e10cSrcweir         {
552cdf0e10cSrcweir             module = aEntry.substring(0, aEntry.lastIndexOf('.'));
553cdf0e10cSrcweir             shortName = aEntry.substring(aEntry.lastIndexOf('.') + 1);
554cdf0e10cSrcweir         }
555cdf0e10cSrcweir 
556cdf0e10cSrcweir         DescEntry theEntry = new DescEntry();
557cdf0e10cSrcweir         theEntry.entryName = aEntry;
558cdf0e10cSrcweir         theEntry.longName = aEntry;
559cdf0e10cSrcweir         theEntry.isOptional = false;
560cdf0e10cSrcweir         theEntry.EntryType = "component";
561cdf0e10cSrcweir         theEntry.isToTest = true;
562cdf0e10cSrcweir 
563cdf0e10cSrcweir         BufferedReader csvFile = null;
564cdf0e10cSrcweir 
565cdf0e10cSrcweir         java.net.URL url = this.getClass().getResource("/objdsc/" + module);
566cdf0e10cSrcweir 
567cdf0e10cSrcweir         if (url == null)
568cdf0e10cSrcweir         {
569cdf0e10cSrcweir             return setErrorDescription(theEntry,
570cdf0e10cSrcweir                     "couldn't find module '" + module + "'");
571cdf0e10cSrcweir         }
572cdf0e10cSrcweir 
573cdf0e10cSrcweir         try
574cdf0e10cSrcweir         {
575cdf0e10cSrcweir             java.net.URLConnection con = url.openConnection();
576cdf0e10cSrcweir 
577cdf0e10cSrcweir             String sEndsWithCSVName = "." + shortName.trim() + ".csv";
578cdf0e10cSrcweir             if (con instanceof java.net.JarURLConnection)
579cdf0e10cSrcweir             {
580cdf0e10cSrcweir                 // get Jar file from connection
581cdf0e10cSrcweir                 java.util.jar.JarFile f = ((java.net.JarURLConnection) con).getJarFile();
582cdf0e10cSrcweir 
583cdf0e10cSrcweir                 // Enumerate over all entries
584cdf0e10cSrcweir                 java.util.Enumeration e = f.entries();
585cdf0e10cSrcweir 
586cdf0e10cSrcweir                 String sStartModule = "/" + module + "/";
587cdf0e10cSrcweir                 while (e.hasMoreElements())
588cdf0e10cSrcweir                 {
589cdf0e10cSrcweir 
590cdf0e10cSrcweir                     String entry = e.nextElement().toString();
591cdf0e10cSrcweir 
592cdf0e10cSrcweir //                    if (debug) {
593cdf0e10cSrcweir //                        System.out.println("### Read from connetion: " + entry);
594cdf0e10cSrcweir //                    }
595cdf0e10cSrcweir 
596cdf0e10cSrcweir                     if ((entry.lastIndexOf(sStartModule) != -1) &&
597cdf0e10cSrcweir                             entry.endsWith(sEndsWithCSVName))
598cdf0e10cSrcweir                     {
599cdf0e10cSrcweir                         InputStream input = this.getClass().getResourceAsStream("/" + entry);
600cdf0e10cSrcweir                         csvFile = new BufferedReader(new InputStreamReader(input));
601cdf0e10cSrcweir                         break;
602cdf0e10cSrcweir                     }
603cdf0e10cSrcweir                 }
604cdf0e10cSrcweir             }
605cdf0e10cSrcweir             else
606cdf0e10cSrcweir             {
607cdf0e10cSrcweir                 InputStream in = con.getInputStream();
608cdf0e10cSrcweir                 java.io.BufferedReader buf = new java.io.BufferedReader(new InputStreamReader(in));
609cdf0e10cSrcweir                 boolean found = false;
610cdf0e10cSrcweir 
611cdf0e10cSrcweir                 while (buf.ready() && !found)
612cdf0e10cSrcweir                 {
613cdf0e10cSrcweir                     String entry = buf.readLine();
614cdf0e10cSrcweir 
615cdf0e10cSrcweir                     if (entry.endsWith(sEndsWithCSVName))
616cdf0e10cSrcweir                     {
617cdf0e10cSrcweir                         System.out.println("FOUND  ####");
618cdf0e10cSrcweir                         InputStream input = this.getClass().getResourceAsStream("/objdsc/" +
619cdf0e10cSrcweir                                 module +
620cdf0e10cSrcweir                                 "/" +
621cdf0e10cSrcweir                                 entry);
622cdf0e10cSrcweir                         csvFile = new BufferedReader(
623cdf0e10cSrcweir                                 new InputStreamReader(input));
624cdf0e10cSrcweir                         found = true;
625cdf0e10cSrcweir                     }
626cdf0e10cSrcweir                 }
627cdf0e10cSrcweir 
628cdf0e10cSrcweir                 buf.close();
629cdf0e10cSrcweir             }
630cdf0e10cSrcweir         }
631cdf0e10cSrcweir         catch (java.io.IOException e)
632cdf0e10cSrcweir         {
633cdf0e10cSrcweir             e.printStackTrace();
634cdf0e10cSrcweir         }
635cdf0e10cSrcweir 
636cdf0e10cSrcweir         if (csvFile == null)
637cdf0e10cSrcweir         {
638cdf0e10cSrcweir             return setErrorDescription(theEntry,
639cdf0e10cSrcweir                     "couldn't find component '" +
640cdf0e10cSrcweir                     theEntry.entryName + "'");
641cdf0e10cSrcweir         }
642cdf0e10cSrcweir 
643cdf0e10cSrcweir         DescEntry[] subEntries = getSubEntries(csvFile, theEntry, debug);
644cdf0e10cSrcweir 
645cdf0e10cSrcweir         theEntry.SubEntryCount = subEntries.length;
646cdf0e10cSrcweir         theEntry.SubEntries = subEntries;
647cdf0e10cSrcweir 
648cdf0e10cSrcweir         return theEntry;
649cdf0e10cSrcweir     }
650cdf0e10cSrcweir 
getFromDirectory(String descPath, String entry, boolean debug)651cdf0e10cSrcweir     protected static DescEntry getFromDirectory(String descPath, String entry,
652cdf0e10cSrcweir             boolean debug)
653cdf0e10cSrcweir     {
654cdf0e10cSrcweir         int dotindex = entry.indexOf('.');
655cdf0e10cSrcweir 
656cdf0e10cSrcweir         if (dotindex == -1)
657cdf0e10cSrcweir         {
658cdf0e10cSrcweir             return null;
659cdf0e10cSrcweir         }
660cdf0e10cSrcweir 
661cdf0e10cSrcweir         String fs = System.getProperty("file.separator");
662cdf0e10cSrcweir         String module = null;
663cdf0e10cSrcweir         String shortName = null;
664cdf0e10cSrcweir 
665cdf0e10cSrcweir         if (entry.indexOf(".uno") == -1)
666cdf0e10cSrcweir         {
667cdf0e10cSrcweir             module = entry.substring(0, entry.indexOf('.'));
668cdf0e10cSrcweir             shortName = entry.substring(entry.indexOf('.') + 1);
669cdf0e10cSrcweir         }
670cdf0e10cSrcweir         else
671cdf0e10cSrcweir         {
672cdf0e10cSrcweir             module = entry.substring(0, entry.lastIndexOf('.'));
673cdf0e10cSrcweir             shortName = entry.substring(entry.lastIndexOf('.') + 1);
674cdf0e10cSrcweir         }
675cdf0e10cSrcweir 
676cdf0e10cSrcweir         DescEntry aEntry = new DescEntry();
677cdf0e10cSrcweir         aEntry.entryName = entry;
678cdf0e10cSrcweir         aEntry.longName = entry;
679cdf0e10cSrcweir         aEntry.isOptional = false;
680cdf0e10cSrcweir         aEntry.EntryType = "component";
681cdf0e10cSrcweir         aEntry.isToTest = true;
682cdf0e10cSrcweir 
683cdf0e10cSrcweir         if (debug)
684cdf0e10cSrcweir         {
685cdf0e10cSrcweir             System.out.println("Parsing Description Path: " + descPath);
686cdf0e10cSrcweir             System.out.println("Searching module: " + module);
687cdf0e10cSrcweir             System.out.println("For the Component " + shortName);
688cdf0e10cSrcweir         }
689cdf0e10cSrcweir 
690cdf0e10cSrcweir         File modPath = new File(descPath + fs + module);
691cdf0e10cSrcweir 
692cdf0e10cSrcweir         if (!modPath.exists())
693cdf0e10cSrcweir         {
694cdf0e10cSrcweir             return setErrorDescription(aEntry,
695cdf0e10cSrcweir                     "couldn't find module '" + module + "'");
696cdf0e10cSrcweir         }
697cdf0e10cSrcweir 
698cdf0e10cSrcweir         String[] files = modPath.list();
699cdf0e10cSrcweir         String found = "none";
700cdf0e10cSrcweir 
701cdf0e10cSrcweir         for (int i = 0; i < files.length; i++)
702cdf0e10cSrcweir         {
703cdf0e10cSrcweir             if (files[i].endsWith("." + shortName + ".csv"))
704cdf0e10cSrcweir             {
705cdf0e10cSrcweir                 found = files[i];
706cdf0e10cSrcweir                 System.out.println("found " + found);
707cdf0e10cSrcweir                 break;
708cdf0e10cSrcweir             }
709cdf0e10cSrcweir         }
710cdf0e10cSrcweir 
711cdf0e10cSrcweir         if (found.equals("none"))
712cdf0e10cSrcweir         {
713cdf0e10cSrcweir             return setErrorDescription(aEntry,
714cdf0e10cSrcweir                     "couldn't find component '" + entry + "'");
715cdf0e10cSrcweir         }
716cdf0e10cSrcweir 
717cdf0e10cSrcweir         String aUrl = descPath + fs + module + fs + found;
718cdf0e10cSrcweir 
719cdf0e10cSrcweir         BufferedReader csvFile = null;
720cdf0e10cSrcweir 
721cdf0e10cSrcweir         try
722cdf0e10cSrcweir         {
723cdf0e10cSrcweir             csvFile = new BufferedReader(new FileReader(aUrl));
724cdf0e10cSrcweir         }
725cdf0e10cSrcweir         catch (java.io.FileNotFoundException fnfe)
726cdf0e10cSrcweir         {
727cdf0e10cSrcweir             return setErrorDescription(aEntry, "couldn't find file '" + aUrl + "'");
728cdf0e10cSrcweir         }
729cdf0e10cSrcweir 
730cdf0e10cSrcweir         DescEntry[] subEntries = getSubEntries(csvFile, aEntry, debug);
731cdf0e10cSrcweir 
732cdf0e10cSrcweir         aEntry.SubEntryCount = subEntries.length;
733cdf0e10cSrcweir         aEntry.SubEntries = subEntries;
734cdf0e10cSrcweir 
735cdf0e10cSrcweir         return aEntry;
736cdf0e10cSrcweir     }
737cdf0e10cSrcweir 
getSubInterfaces(String job)738cdf0e10cSrcweir     protected ArrayList getSubInterfaces(String job)
739cdf0e10cSrcweir     {
740cdf0e10cSrcweir         ArrayList namesList = new ArrayList();
741cdf0e10cSrcweir         StringTokenizer st = new StringTokenizer(job, ",");
742cdf0e10cSrcweir 
743cdf0e10cSrcweir         for (int i = 0; st.hasMoreTokens(); i++)
744cdf0e10cSrcweir         {
745cdf0e10cSrcweir             String token = st.nextToken();
746cdf0e10cSrcweir 
747cdf0e10cSrcweir             if (token.indexOf(".") < 0)
748cdf0e10cSrcweir             {
749cdf0e10cSrcweir                 namesList.add(token);
750cdf0e10cSrcweir             }
751cdf0e10cSrcweir         }
752cdf0e10cSrcweir 
753cdf0e10cSrcweir         return namesList;
754cdf0e10cSrcweir     }
755cdf0e10cSrcweir 
getSubObjects(String job)756cdf0e10cSrcweir     protected ArrayList getSubObjects(String job)
757cdf0e10cSrcweir     {
758cdf0e10cSrcweir         ArrayList namesList = new ArrayList();
759cdf0e10cSrcweir         StringTokenizer st = new StringTokenizer(job, ",");
760cdf0e10cSrcweir 
761cdf0e10cSrcweir         for (int i = 0; st.hasMoreTokens(); i++)
762cdf0e10cSrcweir         {
763cdf0e10cSrcweir             namesList.add(st.nextToken());
764cdf0e10cSrcweir         }
765cdf0e10cSrcweir 
766cdf0e10cSrcweir         return namesList;
767cdf0e10cSrcweir     }
768cdf0e10cSrcweir 
createScenario(String descPath, String job, boolean debug)769cdf0e10cSrcweir     protected String[] createScenario(String descPath, String job,
770cdf0e10cSrcweir             boolean debug)
771cdf0e10cSrcweir     {
772cdf0e10cSrcweir         String[] scenario = null;
773cdf0e10cSrcweir 
774cdf0e10cSrcweir         if (descPath != null)
775cdf0e10cSrcweir         {
776cdf0e10cSrcweir             if (debug)
777cdf0e10cSrcweir             {
778cdf0e10cSrcweir                 System.out.println("## reading from File " + descPath);
779cdf0e10cSrcweir             }
780cdf0e10cSrcweir 
781cdf0e10cSrcweir             scenario = getScenarioFromDirectory(descPath, job, debug);
782cdf0e10cSrcweir         }
783cdf0e10cSrcweir         else
784cdf0e10cSrcweir         {
785cdf0e10cSrcweir             if (debug)
786cdf0e10cSrcweir             {
787cdf0e10cSrcweir                 System.out.println("## reading from jar");
788cdf0e10cSrcweir             }
789cdf0e10cSrcweir 
790cdf0e10cSrcweir             scenario = getScenarioFromClassPath(job, debug);
791cdf0e10cSrcweir         }
792cdf0e10cSrcweir 
793cdf0e10cSrcweir         return scenario;
794cdf0e10cSrcweir     }
795cdf0e10cSrcweir 
getScenarioFromDirectory(String descPath, String job, boolean debug)796cdf0e10cSrcweir     protected String[] getScenarioFromDirectory(String descPath, String job,
797cdf0e10cSrcweir             boolean debug)
798cdf0e10cSrcweir     {
799cdf0e10cSrcweir         String[] modules = null;
800cdf0e10cSrcweir         ArrayList componentList = new ArrayList();
801cdf0e10cSrcweir 
802cdf0e10cSrcweir         if (!job.equals("unknown") && !job.equals("listall"))
803cdf0e10cSrcweir         {
804cdf0e10cSrcweir             modules = new String[]
805cdf0e10cSrcweir                     {
806cdf0e10cSrcweir                         job
807cdf0e10cSrcweir                     };
808cdf0e10cSrcweir         }
809cdf0e10cSrcweir         else
810cdf0e10cSrcweir         {
811cdf0e10cSrcweir             File dirs = new File(descPath);
812cdf0e10cSrcweir 
813cdf0e10cSrcweir             if (!dirs.exists())
814cdf0e10cSrcweir             {
815cdf0e10cSrcweir                 modules = null;
816cdf0e10cSrcweir             }
817cdf0e10cSrcweir             else
818cdf0e10cSrcweir             {
819cdf0e10cSrcweir                 modules = dirs.list();
820cdf0e10cSrcweir             }
821cdf0e10cSrcweir         }
822cdf0e10cSrcweir 
823cdf0e10cSrcweir         for (int i = 0; i < modules.length; i++)
824cdf0e10cSrcweir         {
825cdf0e10cSrcweir             if (!isUnusedModule(modules[i]))
826cdf0e10cSrcweir             {
827cdf0e10cSrcweir                 File moduleDir = new File(descPath + System.getProperty("file.separator") + modules[i]);
828cdf0e10cSrcweir                 if (moduleDir.exists())
829cdf0e10cSrcweir                 {
830cdf0e10cSrcweir                     String[] components = moduleDir.list();
831cdf0e10cSrcweir                     for (int j = 0; j < components.length; j++)
832cdf0e10cSrcweir                     {
833cdf0e10cSrcweir                         if (components[j].endsWith(".csv"))
834cdf0e10cSrcweir                         {
835cdf0e10cSrcweir                             String toAdd = getComponentForString(components[j], modules[i]);
836cdf0e10cSrcweir                             toAdd = "-o " + modules[i] + "." + toAdd;
837cdf0e10cSrcweir                             componentList.add(toAdd);
838cdf0e10cSrcweir                         }
839cdf0e10cSrcweir                     }
840cdf0e10cSrcweir                 }
841cdf0e10cSrcweir             }
842cdf0e10cSrcweir         }
843cdf0e10cSrcweir 
844cdf0e10cSrcweir         String[] scenario = new String[componentList.size()];
845cdf0e10cSrcweir         Collections.sort(componentList);
846cdf0e10cSrcweir 
847cdf0e10cSrcweir         for (int i = 0; i < componentList.size(); i++)
848cdf0e10cSrcweir         {
849cdf0e10cSrcweir             scenario[i] = (String) componentList.get(i);
850cdf0e10cSrcweir         }
851cdf0e10cSrcweir 
852cdf0e10cSrcweir         return scenario;
853cdf0e10cSrcweir 
854cdf0e10cSrcweir     }
855cdf0e10cSrcweir 
getScenarioFromClassPath(String job, boolean debug)856cdf0e10cSrcweir     protected String[] getScenarioFromClassPath(String job, boolean debug)
857cdf0e10cSrcweir     {
858cdf0e10cSrcweir         String subdir = "/";
859cdf0e10cSrcweir 
860cdf0e10cSrcweir         if (!job.equals("unknown") && !job.equals("listall"))
861cdf0e10cSrcweir         {
862cdf0e10cSrcweir             subdir += job;
863cdf0e10cSrcweir         }
864cdf0e10cSrcweir 
865cdf0e10cSrcweir         java.net.URL url = this.getClass().getResource("/objdsc" + subdir);
866cdf0e10cSrcweir 
867cdf0e10cSrcweir         if (url == null)
868cdf0e10cSrcweir         {
869cdf0e10cSrcweir             return null;
870cdf0e10cSrcweir         }
871cdf0e10cSrcweir 
872cdf0e10cSrcweir         ArrayList scenarioList = new ArrayList();
873cdf0e10cSrcweir 
874cdf0e10cSrcweir         try
875cdf0e10cSrcweir         {
876cdf0e10cSrcweir             java.net.URLConnection con = url.openConnection();
877cdf0e10cSrcweir 
878cdf0e10cSrcweir             if (con instanceof java.net.JarURLConnection)
879cdf0e10cSrcweir             {
880cdf0e10cSrcweir                 // get Jar file from connection
881cdf0e10cSrcweir                 java.util.jar.JarFile f = ((java.net.JarURLConnection) con).getJarFile();
882cdf0e10cSrcweir 
883cdf0e10cSrcweir                 // Enumerate over all entries
884cdf0e10cSrcweir                 java.util.Enumeration e = f.entries();
885cdf0e10cSrcweir 
886cdf0e10cSrcweir                 while (e.hasMoreElements())
887cdf0e10cSrcweir                 {
888cdf0e10cSrcweir                     String entry = e.nextElement().toString();
889cdf0e10cSrcweir 
890cdf0e10cSrcweir                     if (entry.startsWith("objdsc" + subdir) &&
891cdf0e10cSrcweir                             (entry.indexOf("CVS") < 0) &&
892cdf0e10cSrcweir                             !entry.endsWith("/"))
893cdf0e10cSrcweir                     {
894cdf0e10cSrcweir                         int startMod = entry.indexOf("/");
895cdf0e10cSrcweir                         int endMod = entry.lastIndexOf("/");
896cdf0e10cSrcweir                         String module = entry.substring(startMod + 1, endMod);
897cdf0e10cSrcweir                         String component = getComponentForString(
898cdf0e10cSrcweir                                 entry.substring(endMod + 1,
899cdf0e10cSrcweir                                 entry.length()),
900cdf0e10cSrcweir                                 module);
901cdf0e10cSrcweir 
902cdf0e10cSrcweir                         if (!isUnusedModule(module))
903cdf0e10cSrcweir                         {
904cdf0e10cSrcweir                             scenarioList.add("-o " + module + "." +
905cdf0e10cSrcweir                                     component);
906cdf0e10cSrcweir                         }
907cdf0e10cSrcweir                     }
908cdf0e10cSrcweir                 }
909cdf0e10cSrcweir             }
910cdf0e10cSrcweir         }
911cdf0e10cSrcweir         catch (java.io.IOException e)
912cdf0e10cSrcweir         {
913cdf0e10cSrcweir             e.printStackTrace();
914cdf0e10cSrcweir         }
915cdf0e10cSrcweir 
916cdf0e10cSrcweir         String[] scenario = new String[scenarioList.size()];
917cdf0e10cSrcweir         Collections.sort(scenarioList);
918cdf0e10cSrcweir 
919cdf0e10cSrcweir         for (int i = 0; i < scenarioList.size(); i++)
920cdf0e10cSrcweir         {
921cdf0e10cSrcweir             scenario[i] = (String) scenarioList.get(i);
922cdf0e10cSrcweir         }
923cdf0e10cSrcweir 
924cdf0e10cSrcweir         return scenario;
925cdf0e10cSrcweir     }
926cdf0e10cSrcweir 
getComponentForString(String full, String module)927cdf0e10cSrcweir     protected String getComponentForString(String full, String module)
928cdf0e10cSrcweir     {
929cdf0e10cSrcweir         String component = "";
930cdf0e10cSrcweir 
931cdf0e10cSrcweir 
932cdf0e10cSrcweir         //cutting .csv
933cdf0e10cSrcweir         full = full.substring(0, full.length() - 4);
934cdf0e10cSrcweir 
935cdf0e10cSrcweir         //cutting component
936cdf0e10cSrcweir         int lastdot = full.lastIndexOf(".");
937cdf0e10cSrcweir         component = full.substring(lastdot + 1, full.length());
938cdf0e10cSrcweir 
939cdf0e10cSrcweir         if (module.equals("file") || module.equals("xmloff"))
940cdf0e10cSrcweir         {
941cdf0e10cSrcweir             String withoutComponent = full.substring(0, lastdot);
942cdf0e10cSrcweir             int preLastDot = withoutComponent.lastIndexOf(".");
943cdf0e10cSrcweir             component = withoutComponent.substring(preLastDot + 1,
944cdf0e10cSrcweir                     withoutComponent.length()) +
945cdf0e10cSrcweir                     "." + component;
946cdf0e10cSrcweir         }
947cdf0e10cSrcweir 
948cdf0e10cSrcweir         return component;
949cdf0e10cSrcweir     }
950cdf0e10cSrcweir 
isUnusedModule(String moduleName)951cdf0e10cSrcweir     protected boolean isUnusedModule(String moduleName)
952cdf0e10cSrcweir     {
953cdf0e10cSrcweir         ArrayList removed = new ArrayList();
954cdf0e10cSrcweir         removed.add("acceptor");
955cdf0e10cSrcweir         removed.add("brdgfctr");
956cdf0e10cSrcweir         removed.add("connectr");
957cdf0e10cSrcweir         removed.add("corefl");
958cdf0e10cSrcweir         removed.add("cpld");
959cdf0e10cSrcweir         removed.add("defreg");
960cdf0e10cSrcweir         removed.add("dynamicloader");
961cdf0e10cSrcweir         removed.add("impreg");
962cdf0e10cSrcweir         removed.add("insp");
963cdf0e10cSrcweir         removed.add("inv");
964cdf0e10cSrcweir         removed.add("invadp");
965cdf0e10cSrcweir         removed.add("javaloader");
966cdf0e10cSrcweir         removed.add("jen");
967cdf0e10cSrcweir         removed.add("namingservice");
968cdf0e10cSrcweir         removed.add("proxyfac");
969cdf0e10cSrcweir         removed.add("rdbtdp");
970cdf0e10cSrcweir         removed.add("remotebridge");
971cdf0e10cSrcweir         removed.add("simreg");
972cdf0e10cSrcweir         removed.add("smgr");
973cdf0e10cSrcweir         removed.add("stm");
974cdf0e10cSrcweir         removed.add("tcv");
975cdf0e10cSrcweir         removed.add("tdmgr");
976cdf0e10cSrcweir         removed.add("ucprmt");
977cdf0e10cSrcweir         removed.add("uuresolver");
978cdf0e10cSrcweir 
979cdf0e10cSrcweir         return removed.contains(moduleName);
980cdf0e10cSrcweir     }
981cdf0e10cSrcweir }
982