View Javadoc

1   // %1117664848781:hoplugins.conv%
2   /*
3    * Created on 16.05.2005
4    *
5    */
6   package hoplugins.conv;
7   
8   import org.w3c.dom.Document;
9   
10  import java.io.File;
11  
12  import javax.swing.JOptionPane;
13  
14  
15  /***
16   * DOCUMENT ME!
17   *
18   * @author Thorsten Dietz
19   */
20  public class HTCoach extends HrfMaker {
21      //~ Constructors -------------------------------------------------------------------------------
22  
23      /***
24       * Creates a new HTCoach object.
25       */
26      protected HTCoach() {
27          type = "HTCF";
28      }
29  
30      //~ Methods ------------------------------------------------------------------------------------
31  
32      /***
33       * TODO Missing Method Documentation
34       *
35       * @param selectedFiles TODO Missing Method Parameter Documentation
36       * @param targetDir TODO Missing Method Parameter Documentation
37       */
38      protected void start(File[] selectedFiles, File targetDir) {
39          try {
40              String[] filter = null;
41              File[][] xmls = null;
42  
43              filter = getName(selectedFiles);
44              xmls = getFiles(filter, selectedFiles);
45  
46              for (int i = 0; i < xmls.length; i++) {
47                  if ((xmls[i][0] == null)
48                      || (xmls[i][1] == null)
49                      || (xmls[i][2] == null)
50                      || (xmls[i][3] == null)
51                      || (xmls[i][4] == null)
52                      || (xmls[i][5] == null)
53                      || (xmls[i][6] == null)) {
54                      handleException(null,
55                                      RSC.PROP_FILE_NOT_FOUND + " :" + filter
56                                      + RSC.HTFOREVER_EXTENSION[i]);
57                      return;
58                  }
59              } // for xml
60  
61              if (targetDir != null) {
62                  Document doc = null;
63  
64                  for (int i = 0; i < xmls.length; i++) {
65                      clearArrays();
66                      addBasics();
67                      doc = getDocument(xmls[i][1]);
68  
69                      analyzeClub(doc.getDocumentElement().getChildNodes());
70                      doc = getDocument(xmls[i][0]);
71  
72                      analyzeArena(doc.getDocumentElement().getChildNodes());
73                      doc = getDocument(xmls[i][5]);
74  
75                      analyzeTraining(doc.getDocumentElement().getChildNodes());
76                      doc = getDocument(xmls[i][2]);
77  
78                      analyzeEconomy(doc.getDocumentElement().getChildNodes());
79                      doc = getDocument(xmls[i][4]);
80  
81                      analyzeTeamDetails(doc.getDocumentElement().getChildNodes());
82                      doc = getDocument(xmls[i][3]);
83  
84                      initPlayersArray(doc.getDocumentElement().getChildNodes());
85  
86                      doc = getDocument(xmls[i][6]);
87                      analyzeWorldDetail(doc.getDocumentElement().getChildNodes());
88  
89                      writeHrf(filter[i], targetDir);
90                  }
91              }
92  
93              //           } // if ok-Button
94              JOptionPane.showMessageDialog(null, RSC.getProperty("finished"));
95          } catch (Exception e1) {
96              handleException(e1, RSC.PROP_DEFAULT_ERROR_MESSAGE);
97          }
98      }
99  
100     /***
101      * TODO Missing Method Documentation
102      *
103      * @param f TODO Missing Method Parameter Documentation
104      *
105      * @return TODO Missing Return Method Documentation
106      */
107     private static String[] getName(File[] f) {
108         String[] names = new String[f.length];
109         int index = f[0].getName().indexOf(".");
110 
111         for (int i = 0; i < names.length; i++) {
112             names[i] = f[i].getName().substring(f[i].getName().indexOf("_") + 1, index);
113         }
114 
115         return names;
116     }
117 
118     /***
119      * TODO Missing Method Documentation
120      *
121      * @param filter TODO Missing Method Parameter Documentation
122      * @param selectedFiles TODO Missing Method Parameter Documentation
123      *
124      * @return TODO Missing Return Method Documentation
125      */
126     private File[][] getFiles(String[] filter, File[] selectedFiles) {
127         File[][] xmls = new File[selectedFiles.length][7];
128         File dir = selectedFiles[0].getParentFile().getParentFile();
129 
130         for (int i = 0; i < selectedFiles.length; i++) {
131             xmls[i][0] = new File(dir.getPath() + File.separator + RSC.HTCOACH_EXTENSION[0]
132                                   + File.separator + RSC.HTCOACH_EXTENSION[0] + "_" + filter[i]
133                                   + ".xml");
134             xmls[i][1] = new File(dir.getPath() + File.separator + RSC.HTCOACH_EXTENSION[1]
135                                   + File.separator + RSC.HTCOACH_EXTENSION[1] + "_" + filter[i]
136                                   + ".xml");
137             xmls[i][2] = new File(dir.getPath() + File.separator + RSC.HTCOACH_EXTENSION[2]
138                                   + File.separator + RSC.HTCOACH_EXTENSION[2] + "_" + filter[i]
139                                   + ".xml");
140             xmls[i][3] = new File(dir.getPath() + File.separator + RSC.HTCOACH_EXTENSION[3]
141                                   + File.separator + RSC.HTCOACH_EXTENSION[3] + "_" + filter[i]
142                                   + ".xml");
143             xmls[i][4] = new File(dir.getPath() + File.separator + RSC.HTCOACH_EXTENSION[4]
144                                   + File.separator + RSC.HTCOACH_EXTENSION[4] + "_" + filter[i]
145                                   + ".xml");
146             xmls[i][5] = new File(dir.getPath() + File.separator + RSC.HTCOACH_EXTENSION[5]
147                                   + File.separator + RSC.HTCOACH_EXTENSION[5] + "_" + filter[i]
148                                   + ".xml");
149             xmls[i][6] = new File(dir.getPath() + File.separator + RSC.HTCOACH_EXTENSION[6]
150                                   + File.separator + RSC.HTCOACH_EXTENSION[6] + "_" + filter[i]
151                                   + ".xml");
152         }
153 
154         return xmls;
155     }
156 }