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