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