source: main/trunk/gli/src/org/greenstone/gatherer/gui/ExportAsPrompt.java@ 28702

Last change on this file since 28702 was 28702, checked in by kjdon, 10 years ago

folder for export is now exported_colname_saveastype, eg exported_demo_MARCXML instead of exported_MARCXML. plugout options are all passed as one option: saveas_options, instead of individual options to export.pl

  • Property svn:keywords set to Author Date Id Revision
File size: 36.7 KB
Line 
1/**
2 *#########################################################################
3 *
4 * A component of the Gatherer application, part of the Greenstone digital
5 * library suite from the New Zealand Digital Library Project at the
6 * University of Waikato, New Zealand.
7 *
8 * <BR><BR>
9 *
10 * Author: John Thompson, Greenstone Digital Library, University of Waikato
11 *
12 * <BR><BR>
13 *
14 * Copyright (C) 1999 New Zealand Digital Library Project
15 *
16 * <BR><BR>
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
22 *
23 * <BR><BR>
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * <BR><BR>
31 *
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
35 *########################################################################
36 */
37package org.greenstone.gatherer.gui;
38
39import java.awt.*;
40import java.awt.event.*;
41import java.io.*;
42import java.util.ArrayList;
43import java.util.HashMap;
44import javax.swing.*;
45import javax.swing.event.*;
46
47import org.greenstone.gatherer.Configuration;
48import org.greenstone.gatherer.DebugStream;
49import org.greenstone.gatherer.Dictionary;
50import org.greenstone.gatherer.Gatherer;
51import org.greenstone.gatherer.collection.BasicCollectionConfiguration;
52import org.greenstone.gatherer.greenstone.LocalGreenstone;
53import org.greenstone.gatherer.shell.GShell;
54import org.greenstone.gatherer.shell.GShellEvent;
55import org.greenstone.gatherer.shell.GShellListener;
56import org.greenstone.gatherer.shell.GDefaultProgressMonitor;
57import org.greenstone.gatherer.util.ArrayTools;
58import org.greenstone.gatherer.util.CheckList;
59import org.greenstone.gatherer.util.CheckListEntry;
60import org.greenstone.gatherer.util.StaticStrings;
61import org.greenstone.gatherer.util.Utility;
62
63/** This class provides the functionality to export a set of current
64 * collections from the GSDLHOME/collect/ directory to various formats
65 * (hence ExportAs) using export.pl. The user chooses the collection from a
66 * list, where each entry also displays details about itself, confirms the
67 * delete of a collection by checking a checkbox then presses the ok button
68 * to actually delete the collection.
69 * Copied from WriteCDImagePrompt
70 * @author John Thompson, Greenstone Digital Library, University of Waikato
71 * @version 2.3
72 */
73public class ExportAsPrompt
74 extends ModalDialog
75 implements GShellListener {
76
77 static final private Dimension LABEL_SIZE = new Dimension(120, 25);
78
79 private OKButtonListener ok_button_listener;
80
81 private JLabel saveas_label = null;
82 private JComboBox saveas_combobox = null;
83
84 private ArrayList all_collections = null;
85 private BasicCollectionConfiguration selected_collection = null;
86 /** The list of collections to export */
87 private JList list = null;
88 /** The currently selected collection for deletion. */
89 private BasicCollectionConfiguration collection = null;
90 /** A reference to ourself so any inner-classes can dispose of us. */
91 private ExportAsPrompt prompt = null;
92 /** The close button, which exits the prompt without deleting anything. */
93 private JButton cancel_button = null;
94 /** The ok button which causes the selected collection to be deleted. */
95 private JButton ok_button = null;
96 /** The label above details. */
97 private JLabel details_label = null;
98 /** The label above the list. */
99 private JLabel list_label = null;
100 /** The text area used to display details about the collection selected. */
101 private JTextArea details_textarea = null;
102 /** The text area used to display instructions for the cd-rom/dvd export */
103 private JTextArea instructions_textarea;
104 /** A string array used to pass arguments to the phrase retrieval method. */
105 private JTextField title_field = null;
106 private JLabel title_label = null;
107 private String args[] = null;
108 private String cd_title = null;
109 /** whether the exporting was successful or not */
110 private boolean successful = false;
111 /** whether we are trying to export or not */
112 private boolean exporting = false;
113 /** the error message if any */
114 private StringBuffer error_message = null;
115 /** The size of the export prompt screen. */
116 public static final Dimension SIZE = new Dimension(500, 540);
117 private GDefaultProgressMonitor progress_monitor;
118
119 private JButton convert_xml_button1 = null;
120 private JButton convert_xml_button2 = null;
121 private JButton convert_xml_button3 = null;
122 private JButton folder_button = null;
123
124 private JPanel instructions_pane = null;
125
126 private JPanel convert_xml_pane1 = null;
127 private JPanel convert_xml_pane2 = null;
128 private JPanel mapping_xml_pane = null;
129
130 private JCheckBox convert_xml_checkbox1 = null;
131 private JCheckBox convert_xml_checkbox2 = null;
132 private JCheckBox mapping_xml_checkbox = null;
133
134 private JCheckBox output_single_checkbox = null;
135
136 private JTextField convert_xml_field1 = null;
137 private JTextField convert_xml_field2 = null;
138 private JTextField mapping_xml_field = null;
139
140
141 private File xsl_file1 = null;
142 private File xsl_file2 = null;
143 private File mapping_file = null;
144
145 private JPanel convert_xml_pane = null;
146
147 private HashMap plugoutMap = new HashMap();
148
149
150 /** Constructor.
151 * @see org.greenstone.gatherer.collection.ExportAsPrompt.CancelButtonListener
152 * @see org.greenstone.gatherer.collection.ExportAsPrompt.CollectionListListener
153 * @see org.greenstone.gatherer.collection.ExportAsPrompt.OKButtonListener
154 */
155 public ExportAsPrompt() {
156 super(Gatherer.g_man, true);
157 this.setComponentOrientation(Dictionary.getOrientation());
158 plugoutMap.clear();
159 plugoutMap.put("DSpace","dublin-core.xml");
160 plugoutMap.put("MARCXML","doc.xml");
161 plugoutMap.put("GreenstoneMETS","doctxt.xml,docmets.xml");
162 plugoutMap.put("FedoraMETS","doctxt.xml,docmets.xml");
163
164 // this is the order we want them to appear in the list
165 String [] saveas_formats = {"GreenstoneMETS", "FedoraMETS", "MARCXML", "DSpace"};
166 cancel_button = new GLIButton(Dictionary.get("General.Close"), Dictionary.get("General.Close_Tooltip"));
167
168 details_textarea = new JTextArea(Dictionary.get("DeleteCollectionPrompt.No_Collection"));
169 details_textarea.setEditable(false);
170 details_textarea.setComponentOrientation(Dictionary.getOrientation());
171
172 details_label = new JLabel(Dictionary.get("DeleteCollectionPrompt.Collection_Details"));
173 details_label.setComponentOrientation(Dictionary.getOrientation());
174
175 instructions_textarea = new JTextArea(Dictionary.get("ExportAsPrompt.Instructions"));
176 instructions_textarea.setCaretPosition(0);
177 instructions_textarea.setEditable(false);
178 instructions_textarea.setLineWrap(true);
179 instructions_textarea.setRows(4);
180 instructions_textarea.setWrapStyleWord(true);
181 instructions_textarea.setComponentOrientation(Dictionary.getOrientation());
182
183
184 saveas_label = new JLabel(Dictionary.get("ExportAsPrompt.SaveAs"));
185 saveas_label.setComponentOrientation(Dictionary.getOrientation());
186 //saveas_label.setPreferredSize(LABEL_SIZE);
187
188 saveas_combobox = new JComboBox(saveas_formats);
189 saveas_combobox.setOpaque(false);
190 saveas_combobox.setToolTipText(Dictionary.get("ExportAsPrompt.SaveAs_Tooltip"));
191 saveas_combobox.setComponentOrientation(Dictionary.getOrientation());
192
193 // Add xml conversion feature
194 convert_xml_button1 = new GLIButton(Dictionary.get("ExportAsPrompt.Browse"),Dictionary.get("ExportAsPrompt.Browse_Tooltip"));
195 convert_xml_button1.setEnabled(false);
196
197 convert_xml_button2 = new GLIButton(Dictionary.get("ExportAsPrompt.Browse"),Dictionary.get("ExportAsPrompt.Browse_Tooltip"));
198 convert_xml_button2.setEnabled(false);
199
200 convert_xml_button3 = new GLIButton(Dictionary.get("ExportAsPrompt.Browse"),Dictionary.get("ExportAsPrompt.Browse_Tooltip"));
201 convert_xml_button3.setEnabled(false);
202
203 convert_xml_checkbox1 = new JCheckBox();
204 convert_xml_checkbox1.setText(Dictionary.get("ExportAsPrompt.ApplyXSL","doc.xml"));
205 convert_xml_checkbox1.setToolTipText(Dictionary.get("ExportAsPrompt.ApplyXSL_Tooltip"));
206 convert_xml_checkbox1.setComponentOrientation(Dictionary.getOrientation());
207
208 convert_xml_checkbox2 = new JCheckBox();
209 convert_xml_checkbox2.setToolTipText(Dictionary.get("ExportAsPrompt.ApplyXSL_Tooltip"));
210 convert_xml_checkbox2.setComponentOrientation(Dictionary.getOrientation());
211
212 output_single_checkbox = new JCheckBox();
213 output_single_checkbox.setComponentOrientation(Dictionary.getOrientation());
214 output_single_checkbox.setText(Dictionary.get("ExportAsPrompt.MARCXMLGroup"));
215 output_single_checkbox.setToolTipText(Dictionary.get("ExportAsPrompt.MARCXMLGroup_Tooltip"));
216
217
218 mapping_xml_checkbox = new JCheckBox();
219 mapping_xml_checkbox.setComponentOrientation(Dictionary.getOrientation());
220 mapping_xml_checkbox.setText(Dictionary.get("ExportAsPrompt.MappingXML"));
221 mapping_xml_checkbox.setToolTipText(Dictionary.get("ExportAsPrompt.MappingXML_Tooltip"));
222
223 convert_xml_field1 = new JTextField();
224 convert_xml_field1.setComponentOrientation(Dictionary.getOrientation());
225 convert_xml_field1.setEnabled(false);
226
227 convert_xml_field2 = new JTextField();
228 convert_xml_field2.setComponentOrientation(Dictionary.getOrientation());
229 convert_xml_field2.setEnabled(false);
230
231 mapping_xml_field = new JTextField();
232 mapping_xml_field.setComponentOrientation(Dictionary.getOrientation());
233 mapping_xml_field.setEnabled(false);
234
235 convert_xml_pane1 = new JPanel(new BorderLayout());
236 convert_xml_pane1.setComponentOrientation(Dictionary.getOrientation());
237
238 convert_xml_pane2 = new JPanel(new BorderLayout());
239 convert_xml_pane2.setComponentOrientation(Dictionary.getOrientation());
240
241 mapping_xml_pane = new JPanel(new BorderLayout());
242 mapping_xml_pane.setComponentOrientation(Dictionary.getOrientation());
243
244 convert_xml_pane = new JPanel(new GridLayout(3,1));
245 convert_xml_pane.setComponentOrientation(Dictionary.getOrientation());
246
247 all_collections = new ArrayList();
248 //list = new CheckList(true);
249 list = new JList(getCollectionListModel());
250 list.setComponentOrientation(Dictionary.getOrientation());
251 list_label = new JLabel(Dictionary.get("DeleteCollectionPrompt.Collection_List"));
252 list_label.setComponentOrientation(Dictionary.getOrientation());
253
254 ok_button = new GLIButton(Dictionary.get("ExportAsPrompt.Export"), Dictionary.get("ExportAsPrompt.Export_Tooltip"));
255
256 title_field = new JTextField();
257 title_field.setComponentOrientation(Dictionary.getOrientation());
258 title_field.setToolTipText(Dictionary.get("ExportAsPrompt.Export_Name_Tooltip"));
259 title_label = new JLabel(Dictionary.get("ExportAsPrompt.Export_Name"));
260 title_label.setComponentOrientation(Dictionary.getOrientation());
261
262 folder_button = new GLIButton(Dictionary.get("ExportAsPrompt.Browse"),Dictionary.get("ExportAsPrompt.Browse_Tooltip"));
263 folder_button.addActionListener(new FolderButtonListener());
264
265
266 prompt = this;
267 setSize(SIZE);
268 setTitle(Dictionary.get("ExportAsPrompt.Title"));
269
270 setJMenuBar(new SimpleMenuBar("exporting"));
271 cancel_button.addActionListener(new CancelButtonListener());
272 list.addListSelectionListener(new CollectionListListener());
273 list.clearSelection();
274 list.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
275 ok_button_listener = new OKButtonListener();
276 ok_button.addActionListener(ok_button_listener);
277 ok_button.setEnabled(false);
278 //title.getDocument().addDocumentListener(new DocumentListener());
279
280 convert_xml_button1.addActionListener(new ConvertXMLButtonListener());
281 convert_xml_checkbox1.addActionListener(new ConvertXMLCheckboxListener());
282 mapping_xml_checkbox.addActionListener(new ConvertXMLCheckboxListener());
283 convert_xml_button3.addActionListener(new ConvertXMLButtonListener());
284
285 convert_xml_button2.addActionListener(new ConvertXMLButtonListener());
286 convert_xml_checkbox2.addActionListener(new ConvertXMLCheckboxListener());
287
288 saveas_combobox.addActionListener(new SaveasListener());
289
290 }
291
292 /** Destructor. */
293 public void destroy() {
294 saveas_label = null;
295 saveas_combobox = null;
296 all_collections.clear();
297 all_collections = null;
298 cancel_button = null;
299 details_textarea = null;
300 details_label = null;
301 list = null;
302 ok_button = null;
303 prompt = null;
304 selected_collection = null;
305 title_field = null;
306 title_label = null;
307 }
308
309 /** This method causes the modal prompt to be displayed.
310 * returns true if it has exported the collections that are currently selected */
311 public boolean display() {
312 JScrollPane scrol_tmp;
313 // Top pane
314 instructions_pane = new JPanel(new BorderLayout());
315 instructions_pane.setComponentOrientation(Dictionary.getOrientation());
316 instructions_pane.setBorder(BorderFactory.createEmptyBorder(0,0,5,5));
317 scrol_tmp = new JScrollPane(instructions_textarea);
318 scrol_tmp.setComponentOrientation(Dictionary.getOrientation());
319 instructions_pane.add(scrol_tmp, BorderLayout.CENTER);
320
321 title_label.setBorder(BorderFactory.createEmptyBorder(0,5,0,15));
322
323 JPanel title_pane = new JPanel(new BorderLayout());
324 title_pane.setComponentOrientation(Dictionary.getOrientation());
325 title_pane.add(title_label, BorderLayout.LINE_START);
326 title_pane.add(title_field, BorderLayout.CENTER);
327 title_pane.add(folder_button, BorderLayout.LINE_END);
328 //apply xsl pane
329
330 convert_xml_pane1.removeAll();
331 convert_xml_pane2.removeAll();
332 mapping_xml_pane.removeAll();
333 convert_xml_pane.removeAll();
334
335 convert_xml_pane1.add(convert_xml_checkbox1, BorderLayout.LINE_START);
336 convert_xml_pane1.add(convert_xml_field1, BorderLayout.CENTER);
337 convert_xml_pane1.add(convert_xml_button1, BorderLayout.LINE_END);
338
339 convert_xml_pane2.add(convert_xml_checkbox2, BorderLayout.LINE_START);
340 convert_xml_pane2.add(convert_xml_field2, BorderLayout.CENTER);
341 convert_xml_pane2.add(convert_xml_button2, BorderLayout.LINE_END);
342
343 mapping_xml_pane.add(mapping_xml_checkbox, BorderLayout.LINE_START);
344 mapping_xml_pane.add(mapping_xml_field, BorderLayout.CENTER);
345 mapping_xml_pane.add(convert_xml_button3, BorderLayout.LINE_END);
346
347 convert_xml_pane.add(convert_xml_pane1);
348
349 String saveas = (String)saveas_combobox.getSelectedItem();
350 // force the updating of which fields we are displaying
351 saveas_combobox.setSelectedIndex(0);
352
353 // Save as pane
354 JPanel saveas_pane = new JPanel(new BorderLayout());
355 saveas_pane.setComponentOrientation(Dictionary.getOrientation());
356 saveas_label.setBorder(BorderFactory.createEmptyBorder(0,5,0,15));
357 saveas_pane.add(saveas_label, BorderLayout.LINE_START);
358 saveas_pane.add(saveas_combobox, BorderLayout.CENTER);
359
360 JPanel tmp_pane = new JPanel(new BorderLayout());
361 tmp_pane.setComponentOrientation(Dictionary.getOrientation());
362 tmp_pane.add(saveas_pane, BorderLayout.NORTH);
363 tmp_pane.add(title_pane, BorderLayout.CENTER);
364
365 instructions_pane.add(tmp_pane, BorderLayout.NORTH);
366
367 instructions_pane.add(convert_xml_pane, BorderLayout.CENTER);
368
369 // Central pane
370 JPanel list_pane = new JPanel(new BorderLayout());
371 list_pane.setComponentOrientation(Dictionary.getOrientation());
372 list_pane.add(list_label, BorderLayout.NORTH);
373 scrol_tmp = new JScrollPane(list);
374 scrol_tmp.setComponentOrientation(Dictionary.getOrientation());
375 list_pane.add(scrol_tmp, BorderLayout.CENTER);
376 list_pane.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0));
377
378 JPanel details_pane = new JPanel(new BorderLayout());
379 details_pane.setComponentOrientation(Dictionary.getOrientation());
380 details_pane.add(details_label, BorderLayout.NORTH);
381 scrol_tmp = new JScrollPane(details_textarea);
382 scrol_tmp.setComponentOrientation(Dictionary.getOrientation());
383 details_pane.add(scrol_tmp, BorderLayout.CENTER);
384 details_pane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
385
386 JPanel central_pane = new JPanel(new GridLayout(2, 1));
387 central_pane.setComponentOrientation(Dictionary.getOrientation());
388 central_pane.add(list_pane);
389 central_pane.add(details_pane);
390 central_pane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
391
392 // Lower pane
393 JPanel button_pane = new JPanel(new GridLayout(1, 2));
394 button_pane.setComponentOrientation(Dictionary.getOrientation());
395 button_pane.add(ok_button);
396 button_pane.add(cancel_button);
397 button_pane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
398
399 JPanel lower_pane = new JPanel(new BorderLayout());
400 lower_pane.setComponentOrientation(Dictionary.getOrientation());
401 lower_pane.add(button_pane, BorderLayout.SOUTH);
402 lower_pane.setBorder(BorderFactory.createEmptyBorder(0, 5, 5, 5));
403
404 // Final.
405 JPanel content_pane = (JPanel)this.getContentPane();
406 content_pane.setComponentOrientation(Dictionary.getOrientation());
407 content_pane.setLayout(new BorderLayout());
408 content_pane.add(instructions_pane, BorderLayout.NORTH);
409 content_pane.add(central_pane, BorderLayout.CENTER);
410 content_pane.add(lower_pane, BorderLayout.SOUTH);
411
412 // Center and display.
413 Dimension screen_size = Configuration.screen_size;
414 this.setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2);
415 this.setVisible(true); // blocks until the dialog is killed
416 return true;
417
418 }
419
420
421 /** This method calls the builcol.pl scripts via a GShell so as to not lock up the processor.
422 * @see org.greenstone.gatherer.Configuration
423 * @see org.greenstone.gatherer.Gatherer
424 * @see org.greenstone.gatherer.collection.Collection
425 * @see org.greenstone.gatherer.gui.BuildOptions
426 * @see org.greenstone.gatherer.shell.GShell
427 * @see org.greenstone.gatherer.shell.GShellListener
428 * @see org.greenstone.gatherer.shell.GShellProgressMonitor
429 * @see org.greenstone.gatherer.util.Utility
430 */
431 public void exportAsCollections() {
432 DebugStream.println("ExportAsPrompt.exportAsCollections()");
433
434 if (selected_collection == null) return;
435
436 cd_title = title_field.getText();
437
438 String export_type = (String) saveas_combobox.getSelectedItem();
439
440 // Generate the export.pl command
441 ArrayList command_parts_list = new ArrayList();
442 if (!Gatherer.isGsdlRemote) {
443 command_parts_list.add(Configuration.perl_path);
444 command_parts_list.add("-S");
445 }
446 command_parts_list.add(LocalGreenstone.getBinScriptDirectoryPath() + "export.pl");
447 command_parts_list.add("-gli");
448 command_parts_list.add("-language");
449 command_parts_list.add(Configuration.getLanguage());
450 command_parts_list.add("-removeold");
451 command_parts_list.add("-saveas");
452 command_parts_list.add(export_type);
453 // we want to be able to export items from other collect directories too
454 String collectDir = Gatherer.getCollectDirectoryPath();
455
456 if(Gatherer.GS3) {
457 command_parts_list.add("-site");
458 command_parts_list.add(Configuration.site_name);
459 }
460
461 if(collectDir != Gatherer.getDefaultGSCollectDirectoryPath(true)) {
462 command_parts_list.add("-collectdir");
463 command_parts_list.add(collectDir);
464 }
465 command_parts_list.add("-exportdir");
466 String export_dir = LocalGreenstone.getTmpDirectoryPath();
467 if (cd_title.equals("")) {
468 export_dir += "exported_" + selected_collection.getShortName()+ "_" +export_type;
469 }
470 else {
471 File cd_file = new File(cd_title);
472 if (cd_file.isAbsolute())
473 export_dir = cd_title + File.separator + "exported_" + selected_collection.getShortName()+ "_"+ export_type;
474 else{
475 cd_title = cd_title.replaceAll("\\s+","");
476 cd_title = cd_title.replaceAll("\\\\+","/");
477 cd_title = cd_title.replaceAll("/+","/");
478 export_dir +=cd_title;
479 }
480 }
481
482 command_parts_list.add(export_dir);
483
484 // check the xslt/mapping file values.
485
486 // now we build up the saveas options
487 StringBuffer saveas_options = new StringBuffer();
488
489 if (export_type.equals("MARCXML")){
490 if (!convert_xml_field1.getText().equals("")) {
491 saveas_options.append("-xslt_file ");
492 saveas_options.append(convert_xml_field1.getText()+" ");
493 }
494 if (!mapping_xml_field.getText().equals("")) {
495 saveas_options.append("-mapping_file ");
496 saveas_options.append(mapping_xml_field.getText()+" ");
497 }
498 if (output_single_checkbox.isSelected()){
499 saveas_options.append("-group ");
500 }
501 }
502 else if (export_type.endsWith("METS")) {
503 if (!convert_xml_field1.getText().equals("")) {
504 saveas_options.append("-xslt_txt ");
505 saveas_options.append(convert_xml_field1.getText()+" ");
506 }
507 if (!convert_xml_field2.getText().equals("")) {
508 saveas_options.append("-xslt_mets ");
509 saveas_options.append(convert_xml_field2.getText()+" ");
510 }
511 }
512 else if (export_type.equals("DSpace")) {
513 if (!convert_xml_field1.getText().equals("")) {
514 saveas_options.append("-xslt_file ");
515 saveas_options.append(convert_xml_field1.getText()+" ");
516 }
517 }
518
519 if (saveas_options.length()>0) {
520 command_parts_list.add("-saveas_options");
521 command_parts_list.add(saveas_options.toString());
522 }
523
524 command_parts_list.add( selected_collection.getShortName());
525
526
527 DebugStream.print("export command = ");
528 for (int i = 0; i < command_parts_list.size(); i++) {
529 DebugStream.print(command_parts_list.get(i) + " ");
530 //System.err.print("'"+command_parts_list.get(i)+"'" + " ");
531 }
532 DebugStream.println("");
533
534 // Run the export.pl command
535 String[] command_parts = (String[]) command_parts_list.toArray(new String[0]);
536
537 progress_monitor = new GDefaultProgressMonitor();
538
539 GShell process = new GShell(command_parts, GShell.EXPORTAS, 3, this,progress_monitor , GShell.GSHELL_EXPORTAS);
540 process.start();
541 //process.run();
542 DebugStream.println("ExportAsPrompt.exportAsCollections().return");
543
544 }
545
546
547 public void cancelExporting(){
548 progress_monitor.setStop(true);
549 }
550
551
552 /** Shows an export complete prompt.
553 * @param success A <strong>boolean</strong> indicating if the collection was successfully deleted.
554 * @see org.greenstone.gatherer.collection.Collection
555 */
556 public void resultPrompt(boolean success, String extra) {
557 args = new String[2];
558
559 // coll name
560 args[0] = selected_collection.getName() + StaticStrings.SPACE_CHARACTER + StaticStrings.OPEN_PARENTHESIS_CHARACTER + selected_collection.getShortName() + StaticStrings.CLOSE_PARENTHESIS_CHARACTER;
561
562 String export_type = (String) saveas_combobox.getSelectedItem();
563 args[1] = LocalGreenstone.getTmpDirectoryPath();
564 if (cd_title.equals("")) {
565 args[1] += "exported_" + selected_collection.getShortName()+"_"+export_type;
566 }
567 else {
568 File cd_file = new File(cd_title);
569 if (cd_file.isAbsolute())
570 args[1] = cd_title + File.separator + "exported_" + selected_collection.getShortName()+"_"+export_type;
571 else{
572 cd_title = cd_title.replaceAll("\\s+","");
573 cd_title = cd_title.replaceAll("\\\\+","/");
574 cd_title = cd_title.replaceAll("/+","/");
575 args[1] +=cd_title;
576 }
577 }
578
579
580 String title;
581 String label;
582 String details;
583
584 if (success) {
585 String successMessage = "ExportAsPrompt.Successful_ExportOne";
586 title = Dictionary.get("ExportAsPrompt.Successful_Title");
587 label = Dictionary.get(successMessage, args);
588 details = Dictionary.get("ExportAsPrompt.Successful_Details", args);
589 } else {
590 String failedMessage = "ExportAsPrompt.Failed_ExportOne";
591 title = Dictionary.get("ExportAsPrompt.Failed_Title");
592 label = Dictionary.get(failedMessage, args);
593 details = Dictionary.get("ExportAsPrompt.Failed_Details", args);
594 }
595 SimpleResultDialog result_dialog = new SimpleResultDialog(this, title, label, details);
596 result_dialog.setVisible(true); // Blocks
597 result_dialog.dispose();
598 result_dialog = null;
599 }
600
601 /** Method to scan the collect directory retrieving and reloading each collection it finds, while building the list of known collections.
602 * @see org.greenstone.gatherer.Configuration
603 * @see org.greenstone.gatherer.Gatherer
604 * @see org.greenstone.gatherer.util.ArrayTools
605 * @see org.greenstone.gatherer.util.Utility
606 */
607 private ListModel getCollectionListModel() {
608 DefaultListModel model = new DefaultListModel();
609 // Start at the collect dir.
610 File collect_directory = new File(Gatherer.getCollectDirectoryPath());
611 String file_name = (Gatherer.GS3)? Utility.CONFIG_GS3_FILE : Utility.CONFIG_FILE;
612 if (collect_directory.exists()) {
613 // Now for each child directory see if it contains a .col file and
614 // if so try to load it..
615 File collections[] = collect_directory.listFiles();
616 ArrayTools.sort(collections);
617 for(int i = 0; collections != null && i < collections.length; i++) {
618 if(collections[i].isDirectory() && !collections[i].getName().equals(StaticStrings.MODEL_COLLECTION_NAME)) {
619 File config_file = new File(collections[i], file_name);
620 if (config_file.exists()) {
621 BasicCollectionConfiguration config = new BasicCollectionConfiguration(config_file);
622 model.addElement(config);
623 config = null;
624 }
625 }
626 }
627 }
628 return model;
629 // Otherwise the collect directory doesn't actually exist, so there ain't much we can do.
630 }
631
632
633 /** All implementation of GShellListener must include this method so the listener can be informed of messages from the GShell.
634 * @param event A <strong>GShellEvent</strong> that contains, amoung other things, the message.
635 */
636 public synchronized void message(GShellEvent event) {
637 // Ignore the messages from RecPlug with 'show_progress' set (used for progress bars)
638 String message = event.getMessage();
639 if (message.startsWith("export.pl>")) {
640 message = message.substring(13);
641 //DebugStream.println("message = "+event.getMessage());
642 error_message.append(message);
643 error_message.append("\n");
644 }
645 }
646
647 /** All implementation of GShellListener must include this method so the listener can be informed when a GShell begins its task. Implementation side-effect, not actually used.
648 * @param event A <strong>GShellEvent</strong> that contains details of the initial state of the <strong>GShell</strong> before task comencement.
649 */
650 public synchronized void processBegun(GShellEvent event) {
651 // We don't care.
652 }
653 /** All implementation of GShellListener must include this method so the listener can be informed when a GShell completes its task.
654 * @param event A <strong>GShellEvent</strong> that contains details of the final state of the <strong>GShell</strong> after task completion.
655 */
656 public synchronized void processComplete(GShellEvent event) {
657 successful = false;
658 if(event.getStatus() == GShell.OK) {
659 if(event.getType() == GShell.EXPORTAS) {
660 successful = true;
661 }
662 }
663 ok_button_listener.processComplete();
664 }
665
666 /** A button listener implementation, which listens for actions on the close button and disposes of the dialog when detected. */
667 private class CancelButtonListener
668 implements ActionListener {
669 /** Any implementation of ActionListener must include this method so we can be informed when the button is actioned.
670 * @param event An <strong>ActionEvent</strong> containing all the relevant information garnered from the event itself.
671 */
672 public void actionPerformed(ActionEvent event) {
673 prompt.dispose();
674 }
675 }
676
677 /** This private class listens for selection events in from the list and then displays the appropriate details for that collection.
678 */
679 private class CollectionListListener
680 implements ListSelectionListener
681 {
682 /** Any implementation of ListSelectionListener must include this method so we can be informed when the list selection changes.
683 * @param event a <strong>ListSelectionEvent</strong> containing all the relevant information garnered from the event itself
684 */
685 public void valueChanged(ListSelectionEvent event)
686 {
687 // Can only export when something is ticked
688 //ok_button.setEnabled(!list.isNothingTicked());
689
690 if (list.isSelectionEmpty()) {
691 details_textarea.setText(Dictionary.get("DeleteCollectionPrompt.No_Collection"));
692 ok_button.setEnabled(false);
693 }
694 else {
695 BasicCollectionConfiguration collection = (BasicCollectionConfiguration) list.getSelectedValue();
696 args = new String[3];
697 args[0] = collection.getCreator();
698 args[1] = collection.getMaintainer();
699 args[2] = collection.getDescription();
700 details_textarea.setText(Dictionary.get("DeleteCollectionPrompt.Details", args));
701 details_textarea.setCaretPosition(0);
702 ok_button.setEnabled(true);
703 }
704 }
705
706 }
707 /** The OK button listener implementation. */
708 private class OKButtonListener
709 implements ActionListener {
710 private Component glass_pane;
711 private MouseListener mouse_blocker_listener;
712 private ProgressDialog progress_dialog;
713
714 /** Any implementation of ActionListener must include this method so we can be informed when the button is actioned.
715 * @param event An <strong>ActionEvent</strong> containing all the relevant information garnered from the event itself.
716 * @see org.greenstone.gatherer.Configuration
717 * @see org.greenstone.gatherer.Gatherer
718 * @see org.greenstone.gatherer.util.Utility
719 */
720 public void actionPerformed(ActionEvent event) {
721 ///ystem.err.println("OK Clicked");
722 // Make sure there are some colls specified
723 selected_collection = (BasicCollectionConfiguration)list.getSelectedValue();
724 error_message = new StringBuffer();
725
726 // Set the cursor to hourglass
727 glass_pane = getGlassPane();
728 mouse_blocker_listener = new MouseAdapter() {};
729 glass_pane.addMouseListener(mouse_blocker_listener);
730 glass_pane.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
731 glass_pane.setVisible(true);
732
733 // Export the selected collection.
734 ///ystem.err.println("Exporting As for named collections");
735 exportAsCollections();
736
737 // Show progress dialog
738 ///ystem.err.println("Showing progress dialog");
739 progress_dialog = new ProgressDialog();
740 progress_dialog.setVisible(true);
741 }
742
743 public void processComplete() {
744 ///ystem.err.println("Process complete");
745 // Dispose of progress dialog
746
747
748 progress_dialog.setVisible(false);
749 progress_dialog.dispose();
750 progress_dialog = null;
751
752 // unset the cursor
753 glass_pane.setVisible(false);
754 glass_pane.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
755 glass_pane.removeMouseListener(mouse_blocker_listener);
756 glass_pane = null;
757 mouse_blocker_listener= null;
758
759 if (successful) {
760 resultPrompt(true, error_message.toString());
761 } else {
762 resultPrompt(false, error_message.toString());
763 }
764 error_message = null;
765
766 convert_xml_button1.setEnabled(false);
767 xsl_file1 = null;
768 convert_xml_field1.setText("");
769 convert_xml_checkbox1.setSelected(false);
770
771 convert_xml_button2.setEnabled(false);
772 xsl_file2 = null;
773 convert_xml_field2.setText("");
774 convert_xml_checkbox2.setSelected(false);
775
776 mapping_xml_checkbox.setSelected(false);
777 output_single_checkbox.setSelected(false);
778 convert_xml_button3.setEnabled(false);
779 mapping_xml_field.setText("");
780 mapping_file = null;
781
782 }
783
784 private class ProgressDialog
785 extends ModalDialog {
786
787 private Dimension size = new Dimension(400,110);
788
789 public ProgressDialog() {
790 super(Gatherer.g_man, Dictionary.get("ExportAsPrompt.Title"), true);
791 setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
792 setSize(size);
793 JPanel content_pane = (JPanel) getContentPane();
794 JLabel progress_label = new JLabel(Dictionary.get("ExportAsPrompt.Progress_Label"));
795
796 JProgressBar progress_bar = new JProgressBar();
797 progress_bar.setIndeterminate(true);
798 content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
799 GLIButton cancel_button = new GLIButton(Dictionary.get("ExportAsPrompt.Cancel"),Dictionary.get("ExportAsPrompt.Cancel_Tooltip"));
800 cancel_button.setMnemonic(KeyEvent.VK_C);
801
802 cancel_button.addActionListener(new ActionListener(){
803 public void actionPerformed(ActionEvent e){
804 cancelExporting();
805 }
806
807 });
808
809 JPanel cancel_panel = new JPanel(new FlowLayout(FlowLayout.CENTER,0,0));
810 cancel_panel.add(cancel_button);
811
812 content_pane.setLayout(new BorderLayout(0,5));
813 content_pane.add(progress_label, BorderLayout.NORTH);
814 content_pane.add(progress_bar, BorderLayout.CENTER);
815 content_pane.add(cancel_panel, BorderLayout.SOUTH);
816
817 // Position
818 Rectangle frame_bounds = Gatherer.g_man.getBounds();
819 setLocation(frame_bounds.x + (frame_bounds.width - size.width) / 2, frame_bounds.y + (frame_bounds.height - size.height) / 2);
820 }
821 }
822 }
823
824 private class ConvertXMLCheckboxListener implements ActionListener {
825 public void actionPerformed(ActionEvent event) {
826
827 convert_xml_button1.setEnabled(convert_xml_checkbox1.isSelected());
828 convert_xml_field1.setEnabled(convert_xml_checkbox1.isSelected());
829 convert_xml_button2.setEnabled(convert_xml_checkbox2.isSelected());
830 convert_xml_field2.setEnabled(convert_xml_checkbox2.isSelected());
831 convert_xml_button3.setEnabled(mapping_xml_checkbox.isSelected());
832 mapping_xml_field.setEnabled(mapping_xml_checkbox.isSelected());
833
834 }
835 }
836
837
838
839 private class SaveasListener implements ActionListener {
840
841 public void actionPerformed(ActionEvent event) {
842
843 convert_xml_checkbox1.setSelected(false);
844 convert_xml_checkbox2.setSelected(false);
845 mapping_xml_checkbox.setSelected(false);
846 output_single_checkbox.setSelected(false);
847
848 convert_xml_button1.setEnabled(false);
849 convert_xml_button2.setEnabled(false);
850 convert_xml_button3.setEnabled(false);
851
852 convert_xml_field1.setText("");
853 convert_xml_field2.setText("");
854 mapping_xml_field.setText("");
855
856 String saveas = (String)saveas_combobox.getSelectedItem();
857
858 if (convert_xml_pane.getComponentCount() > 1){
859 convert_xml_pane.remove(1);
860 if (convert_xml_pane.getComponentCount() > 1){
861 convert_xml_pane.remove(1);
862 }
863 }
864
865 if (!saveas.endsWith("METS")){
866
867 convert_xml_checkbox1.setText(Dictionary.get("ExportAsPrompt.ApplyXSL",(String)plugoutMap.get(saveas)));
868 if (saveas.equals("MARCXML")){
869 convert_xml_pane.add(mapping_xml_pane);
870 convert_xml_pane.add(output_single_checkbox);
871 }
872 }
873 else{
874 String[] docs = ((String)plugoutMap.get(saveas)).split(",");
875 convert_xml_checkbox1.setText(Dictionary.get("ExportAsPrompt.ApplyXSL",docs[0]));
876 convert_xml_checkbox2.setText(Dictionary.get("ExportAsPrompt.ApplyXSL",docs[1]));
877 convert_xml_pane.add(convert_xml_pane2);
878 }
879
880 convert_xml_pane.revalidate();
881 convert_xml_pane.repaint();
882 instructions_pane.revalidate();
883 instructions_pane.repaint();
884
885 }
886
887 }
888
889 private class ConvertXMLButtonListener implements ActionListener {
890 public void actionPerformed(ActionEvent event) {
891 JFileChooser chooser = new JFileChooser();
892 // Note: source for ExampleFileFilter can be found in FileChooserDemo,
893 // under the demo/jfc directory in the Java 2 SDK, Standard Edition.
894 javax.swing.filechooser.FileFilter filter = new javax.swing.filechooser.FileFilter(){
895 public boolean accept(File f){
896 return f.getPath().endsWith(".xsl")||f.isDirectory()||f.getPath().endsWith(".xml");
897 }
898
899 public String getDescription(){
900 return "XSL or XML file";
901 }
902 };
903
904 chooser.setFileFilter(filter);
905 int returnVal = chooser.showOpenDialog(prompt);
906
907 if(returnVal == JFileChooser.APPROVE_OPTION) {
908 if (event.getSource() == convert_xml_button1){
909
910 xsl_file1 = chooser.getSelectedFile();
911 convert_xml_field1.setText(xsl_file1.getPath());
912 }
913 else if (event.getSource() == convert_xml_button2){
914 xsl_file2 = chooser.getSelectedFile();
915 convert_xml_field2.setText(xsl_file2.getPath());
916
917 }
918 else {
919 mapping_file = chooser.getSelectedFile();
920 mapping_xml_field.setText(mapping_file.getPath());
921 }
922 }
923 }
924 }
925
926 private class FolderButtonListener implements ActionListener {
927 public void actionPerformed(ActionEvent event) {
928 JFileChooser chooser = new JFileChooser();
929 chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
930
931 int returnVal = chooser.showOpenDialog(prompt);
932
933 if(returnVal == JFileChooser.APPROVE_OPTION) {
934 File folder_name = chooser.getSelectedFile();
935 title_field.setText(folder_name.getPath());
936 }
937
938 }
939 }
940}
941
942
943
944
945
Note: See TracBrowser for help on using the repository browser.