Changeset 6325
- Timestamp:
- 2003-12-19T14:54:25+13:00 (20 years ago)
- Location:
- trunk/gli/src/org/greenstone/gatherer
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/collection/Collection.java
r6204 r6325 309 309 count++; 310 310 } 311 for(int i = 0; i < node.getChildCount(); i++) {311 for(int i = 0; !file.getName().equals("CVS") && i < node.getChildCount(); i++) { 312 312 count = count + getCount(node.getChildAt(i), count_folders, count_files); 313 313 } -
trunk/gli/src/org/greenstone/gatherer/collection/CollectionManager.java
r6317 r6325 745 745 String args[]; 746 746 if(Utility.isWindows()) { 747 args = new String[ 6];747 args = new String[7]; 748 748 args[0] = Gatherer.config.perl_path; 749 749 args[1] = "-S"; 750 750 args[2] = Gatherer.config.getScriptPath() + "import.pl"; 751 args[3] = "-importdir"; 752 args[4] = collection_import; 753 args[5] = collection.getName(); 751 args[3] = "-gli"; 752 args[4] = "-importdir"; 753 args[5] = collection_import; 754 args[6] = collection.getName(); 754 755 } 755 756 else { 756 args = new String[ 4];757 args = new String[5]; 757 758 args[0] = Gatherer.config.getScriptPath() + "import.pl"; 758 args[1] = "-importdir"; 759 args[2] = collection_import; 760 args[3] = collection.getName(); 759 args[1] = "-gli"; 760 args[2] = "-importdir"; 761 args[3] = collection_import; 762 args[4] = collection.getName(); 761 763 } 762 764 collection_import = null; … … 1091 1093 } 1092 1094 WarningDialog collection_built_warning_dialog = new WarningDialog("warning.CollectionBuilt", false); 1095 collection_built_warning_dialog.setMessageOnly(true); // Not a warning 1093 1096 collection_built_warning_dialog.display(); 1094 1097 collection_built_warning_dialog.dispose(); -
trunk/gli/src/org/greenstone/gatherer/msm/GreenstoneArchiveParser.java
r6200 r6325 88 88 args[0] = document_directories[i].getName(); 89 89 args[1] = String.valueOf(count); 90 shell.fireMessage(GShell.IMPORT, shell.typeAsString(GShell.IMPORT) + "> " + Dictionary.get("GShell.Extracted", args), GShell.OK );90 shell.fireMessage(GShell.IMPORT, shell.typeAsString(GShell.IMPORT) + "> " + Dictionary.get("GShell.Extracted", args), GShell.OK, null); 91 91 args = null; 92 92 progress.increment(); -
trunk/gli/src/org/greenstone/gatherer/shell/GBasicProgressMonitor.java
r5581 r6325 49 49 import java.awt.Component; 50 50 import javax.swing.JProgressBar; 51 import org.greenstone.gatherer.shell.GShellEvent; 51 52 import org.greenstone.gatherer.shell.GShellProgressMonitor; 52 53 … … 91 92 } 92 93 /** The parse method is how more complex progress bars figure out how far they have progressed. However we don't. 93 * @param line A String representing the latest line of output from 94 * the external process we are monitoring. 94 * @param event a GShellEvent containing information from the GShell 95 95 */ 96 public void p arse(String line) {96 public void process(GShellEvent event) { 97 97 } 98 98 -
trunk/gli/src/org/greenstone/gatherer/shell/GBuildProgressMonitor.java
r6006 r6325 42 42 import org.greenstone.gatherer.cdm.CollectionDesignManager; 43 43 import org.greenstone.gatherer.shell.GImportProgressMonitor; 44 import org.greenstone.gatherer.shell.GShellEvent; 44 45 import org.greenstone.gatherer.shell.GShellProgressMonitor; 45 46 /** This implementation of <i>GShellProgressMonitor</i> is designed to parse and translate the progress of a buildcol.pl call. … … 150 151 151 152 /** This method is used to 'feed in' a line of text captured from the process. 152 * @param line A <strong>String</strong> of text captured from either standard out or standard error.153 */ 154 public void p arse(String raw_line) {155 String line = raw_line.toLowerCase();153 * @param event a GShellEvent containing information from the GShell 154 */ 155 public void process(GShellEvent event) { 156 String line = event.getMessage().toLowerCase(); 156 157 // We first check if we can parse, which depends on num_docs > 0 and num_indexes > 0. 157 158 if(num_docs > 0 && num_indexes > 0) { -
trunk/gli/src/org/greenstone/gatherer/shell/GImportProgressMonitor.java
r5593 r6325 43 43 import org.greenstone.gatherer.Gatherer; 44 44 import org.greenstone.gatherer.shell.GShellProgressMonitor; 45 import org.greenstone.gatherer.util.StaticStrings; 45 46 46 47 /** This implementation of <i>GShellProgressMonitor</i> is designed to parse and translate the progress of a import.pl call. … … 50 51 public class GImportProgressMonitor 51 52 implements GShellProgressMonitor { 53 /** Indicates if the progress bar is currently showing a string. */ 54 private boolean showing_string = false; 52 55 /** Indicates if the GUI has asked the process this object monitors to stop. */ 53 56 private boolean stop = false; 54 private int file_num = 0; 57 /** A count of the extracted files processed so far. */ 58 private int extracted_file_count; 59 /** The number of documents processed (or rejected) so far. */ 60 private int file_count; 61 /** The next value to be set for the progress bar - I use this rather than a compounding progress measure to try to limit rounding inaccuracies (nothing looks worse than the progress bar having to jump the last 10-15%) */ 62 private int next_progress_value; 55 63 /** The number of files expected to be scanned by this import process. */ 56 private int num_ files = 0;64 private int num_expected_docs; 57 65 /** This holds the number of documents actually processed by the import command, as garnered from the final block of text output. */ 58 private int num_docs = 0;66 private int num_docs; 59 67 /** The progress bar this monitor updates. */ 60 68 private JProgressBar progress_bar; 61 /** The maximum value for this progress bar. */ 62 static final private int MAX = 1000000; 69 /** */ 70 static final private String C = "c"; 71 /** */ 72 static final private String N = "n"; 73 /** */ 74 static final private String P = "p"; 75 /** The fixed portion of the progress bar used for the calculating of file size and other pre-import functions. */ 76 static final private int CALCULATION = 50000; 77 /** The fixed portion of the progress bar used for extracted metadata. */ 78 static final private int EXTRACTED = 200000; 63 79 /** The minimum value for this progress bar. */ 64 80 static final private int MIN = 0; 65 /** A String fragment which is used to determine if the current output process line is referring to the number of documents actually processed by the import script. */ 66 static final private String NUM_DOCS_PROCESSED = "processed and included in the collection"; 67 /** The Sentinel value is the String fragment an output process line must start with to be considered a milestone. In this case we are counting directories, so the fragment refers to a directory scan. */ 68 static final private String SENTINEL = "recplug - "; 81 /** The fixed portion of the progress bar used for processed documents. */ 82 static final private int PROCESSED = 750000; 83 /** The element name of a file detected message. */ 84 static final private String FILE = "File"; 85 /** The element name of a file processing message. */ 86 static final private String FILE_PROCESSING = "Processing"; 87 /** The element name of an import complete message. */ 88 static final private String IMPORT_COMPLETE = "ImportComplete"; 69 89 70 90 public GImportProgressMonitor() { 71 91 progress_bar = new JProgressBar(); 72 92 progress_bar.setIndeterminate(false); 73 progress_bar.setMaximum( MAX);93 progress_bar.setMaximum(CALCULATION + PROCESSED + EXTRACTED); 74 94 progress_bar.setMinimum(MIN); 75 95 progress_bar.setStringPainted(true); 76 96 progress_bar.setValue(MIN); 97 next_progress_value = CALCULATION; 77 98 } 78 99 … … 82 103 public void addProgressBar(JProgressBar progress_bar) { 83 104 this.progress_bar = progress_bar; 84 progress_bar.setMaximum( MAX);105 progress_bar.setMaximum(CALCULATION + PROCESSED + EXTRACTED); 85 106 progress_bar.setMinimum(MIN); 86 107 progress_bar.setValue(MIN); 108 next_progress_value = CALCULATION; 87 109 } 88 110 … … 120 142 /** Inform the progress bar that it should programatically increment progress by one step. This is only called during the metadata archive extraction so each step should be (1000000 / 5) / num_docs. */ 121 143 public void increment() { 122 if(num_docs > 0) { 123 progress_bar.setValue(progress_bar.getValue() + ((MAX / 5) / num_docs)); 144 extracted_file_count++; 145 // The current progress is calculated to be: 146 // The fixed calculation value plus the fixed processed value plus some portion of the fixed extracted value. This portion is the extracted_file_count over the total number of documents available. Note that this breaks badly for bibliographical files (for now). 147 progress_bar.setValue(CALCULATION + PROCESSED + ((EXTRACTED * extracted_file_count) / num_docs)); 148 } 149 150 /** This method is used to 'feed in' a line of text captured from the process. 151 * @param event the GShellEvent containing a message or other important shell information 152 */ 153 public void process(GShellEvent event) { 154 // We're into parsing output, so we don't need the 'calculating file size' etc string. 155 if(showing_string) { 156 progress_bar.setString(""); 157 showing_string = false; 124 158 } 125 // else { 126 // progress_bar.setIndeterminate(true); 127 // } 128 } 129 130 /** This method is used to 'feed in' a line of text captured from the process. 131 * @param line A <strong>String</strong> of text captured from either standard out or standard error. 132 * TODO Everthing. 133 */ 134 public void parse(String line_raw) { 135 progress_bar.setString(""); 136 String line = line_raw.toLowerCase(); 137 if (line.indexOf(SENTINEL) == 0) { 138 file_num = file_num + 1; 139 ///ystem.err.println("Done " + file_num + " of " + num_files + "..."); 140 if (num_files > 0) { 141 int base_val = MAX / 10; 142 progress_bar.setValue(((((7 * MAX) / 10) * file_num) / num_files) + base_val); 159 // Remove 'import.pl> ' bit 160 String line = event.getMessage(); 161 line = line.substring(line.indexOf(StaticStrings.GREATER_THAN_CHARACTER) + 1); 162 line = line.trim(); 163 ///ystem.err.println("message = " + line); 164 if(line.startsWith(StaticStrings.LESS_THAN_CHARACTER) && line.endsWith(StaticStrings.GREATER_THAN_CHARACTER)) { 165 line = line.substring(1, line.length() - 1); 166 // We may be reading a file. Remember we have to offset process as we recieve this message 'before' a document is processed. Hence the use of 'next_progress_value' 167 if(line.startsWith(FILE)) { 168 file_count++; 169 ///ystem.err.println("File #" + file_count); 170 // Set the next progress 171 progress_bar.setValue(next_progress_value); 172 // Now we calculate the next progress value 173 next_progress_value = CALCULATION + ((PROCESSED * file_count) / num_expected_docs); 143 174 } 144 } 145 else if (line.indexOf(NUM_DOCS_PROCESSED) != -1) { 146 num_docs = -1; 147 StringTokenizer tokenizer = new StringTokenizer(line); 148 while(num_docs == -1 && tokenizer.hasMoreTokens()) { 149 String pos_num_docs_str = tokenizer.nextToken(); 150 try { 151 num_docs = Integer.parseInt(pos_num_docs_str); 175 // Or we're being told what plugin is actually processing the file 176 else if(line.startsWith(FILE_PROCESSING)) { 177 // If we are at lower mode settings fire a new 'dumbed down' event 178 /** @todo */ 179 } 180 // Or the import complete element 181 else if(line.startsWith(IMPORT_COMPLETE)) { 182 // Set the next progress 183 progress_bar.setValue(next_progress_value); 184 // Determine the number of documents processed by using the 'p' attribute 185 StringTokenizer tokenizer = new StringTokenizer(line); 186 boolean found = false; 187 String token = tokenizer.nextToken(); // Drop the element name 188 while(tokenizer.hasMoreTokens() && !found) { 189 token = tokenizer.nextToken(); 190 if(token.startsWith(P)) { 191 found = true; 192 try { 193 String num_docs_string = token.substring(3, token.length() - 1); 194 num_docs = Integer.parseInt(num_docs_string); 195 } 196 catch(Exception exception) { 197 Gatherer.println("Exception in GImportProgressMonitor.process() - Expected"); 198 Gatherer.printStackTrace(exception); 199 } 200 } 152 201 } 153 catch (Exception error) { 154 } 202 tokenizer = null; 203 // If we are at lower mode settings fire a new 'dumbed down' event 204 /** @todo */ 155 205 } 156 ///ystem.err.println("Parsed num_docs to be " + num_docs); 206 207 208 // We also veto this event to prevent other classes handling it (we ensure progress monitors are called first). 209 event.veto(); 157 210 } 158 211 } … … 160 213 public void saving() { 161 214 progress_bar.setString(Dictionary.get("SaveProgressDialog.Title")); 162 progress_bar.setValue(MAX / (10 * 2));215 showing_string = true; 163 216 } 164 217 … … 171 224 172 225 /** This method resets this monitor to the start, reseting the process parsing and progress bar. 173 * TODO Everthing.174 226 */ 175 227 public void start() { 176 228 progress_bar.setString(Dictionary.get("FileActions.Calculating_Size")); 177 progress_bar.setValue(MAX / 10); 178 num_files = Gatherer.c_man.getCollection().getDocumentCount(); 179 ///ystem.err.println("Number of files: " + num_files); 180 file_num = 0; 229 showing_string = true; 230 extracted_file_count = 0; 231 file_count = 0; 232 next_progress_value = -1; 233 num_docs = -1; 234 num_expected_docs = Gatherer.c_man.getCollection().getCount(); 181 235 } 182 236 183 237 /** This method indicates the process is complete. 184 * TODO Everthing.185 238 */ 186 239 public void stop() { 187 progress_bar.setValue( MAX);240 progress_bar.setValue(CALCULATION + PROCESSED + EXTRACTED); 188 241 } 189 242 } -
trunk/gli/src/org/greenstone/gatherer/shell/GShell.java
r6182 r6325 145 145 /** Any threaded class must include this method to allow the thread body to be run. */ 146 146 public void run() { 147 if(progress != null) {148 progress.start();149 }150 147 // Determine if the user has asked for an outfile. 151 148 String out_name = null; … … 175 172 } 176 173 ///ystem.err.println("Command: " + command); 177 fireMessage(type, Dictionary.get("GShell.Command") + ": " + command, status );174 fireMessage(type, Dictionary.get("GShell.Command") + ": " + command, status, null); 178 175 179 176 Runtime rt = Runtime.getRuntime(); … … 196 193 String eline = eline_buffer.toString(); 197 194 ///atherer.println("* " + eline + " *"); 198 if(progress != null) { 199 progress.parse(eline); 200 } 201 if(bos != null) { 202 try { 203 bos.write(eline.getBytes(), 0, eline.length()); 204 } 205 catch(Exception error) { 206 Gatherer.printStackTrace(error); 207 } 208 } 209 fireMessage(type, typeAsString(type) + "> " + eline, status); 195 fireMessage(type, typeAsString(type) + "> " + eline, status, bos); 210 196 eline = null; 211 197 eline_buffer = new StringBuffer(); … … 224 210 String stdline = stdline_buffer.toString(); 225 211 ///atherer.println("+ " + stdline + " +"); 226 fireMessage(type, typeAsString(type) + "> " + stdline, status );212 fireMessage(type, typeAsString(type) + "> " + stdline, status, null); 227 213 stdline = null; 228 214 stdline_buffer = new StringBuffer(); … … 250 236 String eline = eline_buffer.toString(); 251 237 ///atherer.println("* " + eline + " *"); 252 if(progress != null) { 253 progress.parse(eline); 254 } 255 if(bos != null) { 256 try { 257 bos.write(eline.getBytes(), 0, eline.length()); 258 } 259 catch(Exception error) { 260 Gatherer.printStackTrace(error); 261 } 262 } 263 fireMessage(type, typeAsString(type) + "> " + eline, status); 238 fireMessage(type, typeAsString(type) + "> " + eline, status, bos); 264 239 eline = null; 265 240 eline_buffer = new StringBuffer(); … … 277 252 String stdline = stdline_buffer.toString(); 278 253 ///atherer.println("+ " + stdline + " +"); 279 fireMessage(type, typeAsString(type) + "> " + stdline, status );254 fireMessage(type, typeAsString(type) + "> " + stdline, status, null); 280 255 stdline = null; 281 256 stdline_buffer = new StringBuffer(); … … 291 266 String eline = eline_buffer.toString(); 292 267 ///atherer.println("Last bit of eline: " + eline); 293 if(progress != null) { 294 progress.parse(eline); 295 } 296 if(bos != null) { 297 try { 298 bos.write(eline.getBytes(), 0, eline.length()); 299 } 300 catch(Exception error) { 301 Gatherer.printStackTrace(error); 302 } 303 } 304 fireMessage(type, typeAsString(type) + "> " + eline, status); 268 fireMessage(type, typeAsString(type) + "> " + eline, status, bos); 305 269 eline = null; 306 270 } … … 309 273 String stdline = stdline_buffer.toString(); 310 274 ///atherer.println("Last bit of stdline: " + stdline); 311 fireMessage(type, typeAsString(type) + "> " + stdline, status );275 fireMessage(type, typeAsString(type) + "> " + stdline, status, null); 312 276 stdline = null; 313 277 } … … 319 283 if(prcs.exitValue() == 0) { 320 284 status = OK; 321 fireMessage(type, typeAsString(type) + "> " + Dictionary.get("GShell.Success"), status );285 fireMessage(type, typeAsString(type) + "> " + Dictionary.get("GShell.Success"), status, null); 322 286 } 323 287 else { 324 288 status = ERROR; 325 fireMessage(type, typeAsString(type) + "> " + Dictionary.get("GShell.Failure"), status );289 fireMessage(type, typeAsString(type) + "> " + Dictionary.get("GShell.Failure"), status, null); 326 290 } 327 291 } … … 336 300 } 337 301 // Exception 338 catch (Exception error) { 339 Gatherer.printStackTrace(error); 302 catch (Exception exception) { 303 Gatherer.println("Exception in GShell.run() - unexpected"); 304 Gatherer.printStackTrace(exception); 340 305 status = ERROR; 341 306 } 342 307 // If no error occured, and this was an import process we now extract any new metadata from the archive directory. 343 308 if(status == OK && type == IMPORT) { 344 fireMessage(type, typeAsString(type) + "> " + Dictionary.get("GShell.Parsing_Metadata_Start"), status );309 fireMessage(type, typeAsString(type) + "> " + Dictionary.get("GShell.Parsing_Metadata_Start"), status, null); 345 310 new GreenstoneArchiveParser(progress, this); 346 fireMessage(type, typeAsString(type) + "> " + Dictionary.get("GShell.Parsing_Metadata_Complete"), status); 347 } 348 // Tidy up. 349 if(progress != null) { 350 progress.stop(); 311 fireMessage(type, typeAsString(type) + "> " + Dictionary.get("GShell.Parsing_Metadata_Complete"), status, null); 351 312 } 352 313 // We're done. … … 368 329 * @param status An <strong>int</strong> specifying the current status of the process. 369 330 */ 370 public void fireMessage(int type, String message, int status ) {331 public void fireMessage(int type, String message, int status, BufferedOutputStream bos) { 371 332 GShellEvent event = new GShellEvent(this, 0, type, message, status); 372 Object[] concerned = listeners.getListenerList(); 373 for(int i = 0; i < concerned.length ; i++) { 374 if(concerned[i] == GShellListener.class) { 375 ((GShellListener)concerned[i+1]).message(event); 376 } 377 } 333 // If there is a progress monitor attached, pass the event to it first 334 if(progress != null) { 335 progress.process(event); 336 } 337 // If the event hasn't been vetoed, pass it on to other listeners 338 if(!event.isVetoed()) { 339 Object[] concerned = listeners.getListenerList(); 340 for(int i = 0; i < concerned.length ; i++) { 341 if(concerned[i] == GShellListener.class) { 342 ((GShellListener)concerned[i+1]).message(event); 343 } 344 } 345 concerned = null; 346 // And if we have a buffered output stream from error messages, send the message there 347 if(bos != null) { 348 try { 349 bos.write(message.getBytes(), 0, message.length()); 350 } 351 catch(Exception exception) { 352 Gatherer.println("Exception in GShell.fireMessage() - unexpected"); 353 Gatherer.printStackTrace(exception); 354 } 355 } 356 } 357 event = null; 378 358 } 379 359 … … 383 363 */ 384 364 protected void fireProcessBegun(int type, int status) { 365 // Start the progres monitor if available 366 if(progress != null) { 367 progress.start(); 368 } 369 // Fire an event 385 370 GShellEvent event = new GShellEvent(this, 0, type, "", status); 386 371 Object[] concerned = listeners.getListenerList(); … … 396 381 */ 397 382 protected void fireProcessComplete(int type, int status) { 383 // Tidy up by stopping the progress bar. 384 if(progress != null) { 385 progress.stop(); 386 } 387 // And firing off an event 398 388 GShellEvent event = new GShellEvent(this, 0, type, "", status); 399 389 Object[] concerned = listeners.getListenerList(); -
trunk/gli/src/org/greenstone/gatherer/shell/GShellEvent.java
r5581 r6325 51 51 public class GShellEvent 52 52 extends AWTEvent { 53 /** Allows some part of the program to prevent this message being processed by other parts. */ 54 private boolean vetoed = false; 53 55 /** The status of the process at the completion of event. */ 54 56 private int status = -1; … … 93 95 } 94 96 97 /** Determine if this event has been vetoed by some other part of the GLI 98 * @return true if the event has, and thus shouldn't be further processed, false otherwise. 99 */ 100 public boolean isVetoed() { 101 return vetoed; 102 } 103 95 104 public String toString() { 96 105 return "org.greenstone.gatherer.shell.GShellEvent[" + message + "," + status + "," + type + "]"; 97 106 } 107 108 /** Prevent this event being processed by other parts of the GLI. 109 */ 110 public void veto() { 111 vetoed = true; 112 } 98 113 } -
trunk/gli/src/org/greenstone/gatherer/shell/GShellProgressMonitor.java
r5581 r6325 50 50 import java.awt.Component; 51 51 import javax.swing.JProgressBar; 52 import org.greenstone.gatherer.shell.GShellEvent; 52 53 53 54 /** When implemented, this interface allows another class to monitor the progress of a <strong>GShell</strong> process. Specifically implementing classes should be designed to take the textual output from the process and then translate that message into some quanitive measure of progress which can then be shown on the progress bar. … … 78 79 79 80 /** This method is used to 'feed in' a line of text captured from the process. 80 * @param line A <strong>String</strong> of text captured from either standard out or standard error.81 * @param event a GShellEvent containing information from the GShell 81 82 */ 82 public void p arse(String line);83 public void process(GShellEvent event); 83 84 84 85 public void saving();
Note:
See TracChangeset
for help on using the changeset viewer.