source: trunk/gli/src/org/greenstone/gatherer/gui/ExplodeMetadataPrompt.java@ 9104

Last change on this file since 9104 was 9104, checked in by kjdon, 19 years ago

first stab at exploding metadata

  • Property svn:keywords set to Author Date Id Revision
File size: 10.3 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 * Author: Katherine Don, Greenstone Digital Library, University of Waikato
9 *
10 * Copyright (C) 2005 New Zealand Digital Library Project
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 *########################################################################
26 */
27package org.greenstone.gatherer.gui;
28
29import java.awt.*;
30import java.awt.event.*;
31import javax.swing.*;
32import javax.swing.event.*;
33import javax.swing.text.*;
34import java.io.File;
35import java.util.ArrayList;
36
37import org.greenstone.gatherer.Dictionary;
38import org.greenstone.gatherer.Configuration;
39import org.greenstone.gatherer.Gatherer;
40import org.greenstone.gatherer.cdm.CollectionDesignManager;
41import org.greenstone.gatherer.gui.tree.DragTree;
42import org.greenstone.gatherer.metadata.MetadataXMLFileManager;
43import org.greenstone.gatherer.metadata.MetadataElement;
44import org.greenstone.gatherer.metadata.MetadataSet;
45import org.greenstone.gatherer.metadata.MetadataSetManager;
46import org.greenstone.gatherer.metadata.MetadataTools;
47import org.greenstone.gatherer.util.Utility;
48
49public class ExplodeMetadataPrompt
50
51 extends ModalDialog
52{
53 /** The size of this new collection dialog box. */
54 static private Dimension SIZE = new Dimension(600, 280);
55 static private Dimension COMBO_SIZE = new Dimension(100, 30);
56 private JDialog self;
57
58 private File metadata_file = null;
59 private String plugin_name = null;
60 private String encoding = null;
61
62 private GComboBox encoding_combo = null;
63 //private GComboBox metadata_set_combo = null;
64 private JTextField filename_field_box = null;
65
66 // private JButton explode_button = null;
67 // private JButton cancel_button = null;
68 public ExplodeMetadataPrompt(File source_file) {
69 super(Gatherer.g_man, true);
70 this.self = this;
71 this.metadata_file = source_file;
72
73 // check that we actually have an explodable file
74 plugin_name = CollectionDesignManager.plugin_manager.getExploderPlugin(source_file);
75 if (plugin_name==null) {
76 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("ExplodeMetadataPrompt.NotExplodable"), Dictionary.get("ExplodeMetadataPrompt.Title"), JOptionPane.ERROR_MESSAGE);
77 return;
78 }
79 setJMenuBar(new SimpleMenuBar("explodingmetadata"));
80 setSize(SIZE);
81 Dictionary.setText(this, "ExplodeMetadataPrompt.Title");
82
83 // Creation
84 JPanel content_pane = (JPanel) getContentPane();
85 content_pane.setOpaque(true);
86
87 JPanel middle_pane = new JPanel();
88 middle_pane.setLayout(new BorderLayout());
89
90 JPanel options_pane = new JPanel();
91 options_pane.setLayout(new BorderLayout());
92 options_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
93
94 JPanel labels_pane = new JPanel();
95 labels_pane.setBorder(BorderFactory.createEmptyBorder(0,0,0,5));
96 labels_pane.setLayout(new GridLayout(2,1, 5, 5));
97
98 JPanel values_pane = new JPanel();
99 values_pane.setLayout(new GridLayout(2,1, 5, 5));
100
101 JLabel encoding_label = new JLabel();
102 Dictionary.setText(encoding_label, "ExplodeMetadataPrompt.Encoding");
103
104 ArrayList encodings = new ArrayList();
105 encodings.add("iso_8859_1");
106 encodings.add("utf-8");
107
108 encoding_combo = new GComboBox(encodings);
109 Dictionary.setTooltip(encoding_combo, "ExplodeMetadataPrompt.Encoding_Tooltip");
110 encoding_combo.setPreferredSize(COMBO_SIZE);
111
112 //JLabel metadata_set_label = new JLabel();
113 ///Dictionary.setText(metadata_set_label, "ExplodeMetadataPrompt.MetadataSet");
114 //ArrayList metadata_sets = MetadataSetManager.getMetadataSets();
115 // remove the extracted metadata set
116// for (int i = metadata_sets.size() - 1; i >= 0; i--) {
117// if (((MetadataSet) metadata_sets.get(i)).getNamespace().equals(MetadataSetManager.EXTRACTED_METADATA_NAMESPACE)) {
118// metadata_sets.remove(i);
119// }
120// }
121// // add in none
122// metadata_sets.add(0, Dictionary.get("ExplodeMetadataPrompt.MetadataSet.None"));
123
124// metadata_set_combo = new GComboBox(metadata_sets);
125
126 //Dictionary.setTooltip(metadata_set_combo, "ExplodeMetadataPrompt.MetadataSet_Tooltip");
127
128 JLabel filename_field_label = new JLabel();
129 Dictionary.setText(filename_field_label, "ExplodeMetadataPrompt.FilenameField");
130 filename_field_box = new JTextField();
131 Dictionary.setTooltip(filename_field_box, "ExplodeMetadataPrompt.FilenameField_Tooltip");
132 JTextArea instructions_area = new JTextArea();
133 instructions_area.setEditable(false);
134 instructions_area.setLineWrap(true);
135 instructions_area.setRows(5);
136 instructions_area.setWrapStyleWord(true);
137 Dictionary.setText(instructions_area, "ExplodeMetadataPrompt.Instructions");
138
139 JPanel button_pane = new JPanel();
140 JButton explode_button = new GLIButton();
141 Dictionary.setBoth(explode_button, "ExplodeMetadataPrompt.Explode", "ExplodeMetadataPrompt.Explode_Tooltip");
142 JButton cancel_button = new GLIButton();
143 cancel_button.setMnemonic(KeyEvent.VK_C);
144 Dictionary.setBoth(cancel_button, "General.Cancel", "General.Cancel_Tooltip");
145
146 // Connection
147 cancel_button.addActionListener(new CancelListener());
148 explode_button.addActionListener(new ExplodeListener());
149
150 // Layout
151
152 labels_pane.add(encoding_label);
153 //labels_pane.add(metadata_set_label);
154 labels_pane.add(filename_field_label);
155
156 values_pane.add(encoding_combo);
157 //values_pane.add(metadata_set_combo);
158 values_pane.add(filename_field_box);
159
160 options_pane.add(labels_pane, BorderLayout.WEST);
161 options_pane.add(values_pane, BorderLayout.CENTER);
162
163 middle_pane.add(options_pane, BorderLayout.NORTH);
164
165 button_pane.setBorder(BorderFactory.createEmptyBorder(5,0,0,0));
166 button_pane.setLayout(new GridLayout(1,2));
167 button_pane.add(explode_button);
168 button_pane.add(cancel_button);
169
170 content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
171 content_pane.setLayout(new BorderLayout());
172 content_pane.add(instructions_area, BorderLayout.NORTH);
173 content_pane.add(middle_pane, BorderLayout.CENTER);
174 content_pane.add(button_pane, BorderLayout.SOUTH);
175
176 // Final dialog setup & positioning.
177 Dimension screen_size = Configuration.screen_size;
178 setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2);
179 setVisible(true);
180 }
181
182 public void destroy()
183 {
184
185
186
187 }
188
189 private class CancelListener
190 implements ActionListener {
191 public void actionPerformed(ActionEvent event) {
192 //cancelled = true;
193 self.dispose();
194 }
195 }
196
197 private class ExplodeListener
198 implements ActionListener {
199
200 public void actionPerformed(ActionEvent event) {
201 String encoding = (String)encoding_combo.getSelectedItem();
202 //Object selected_item = metadata_set_combo.getSelectedItem();
203 MetadataSet meta_set = null;
204// if (selected_item instanceof MetadataSet) {
205// meta_set = (MetadataSet)selected_item;
206// }
207
208 System.err.println("exploding the metadata, file "+metadata_file.getPath()+", plugin "+plugin_name+", encoding = "+encoding);
209 if (meta_set != null) {
210 System.err.println(", metadata set="+meta_set.toString());
211 }
212 String filename_field = filename_field_box.getText();
213 System.err.println("filename = "+filename_field);
214 // do the business
215 int exit_value = explodeMetadata(metadata_file, plugin_name, encoding, meta_set, filename_field);
216 //cancelled = false;
217 if (exit_value == 0) { // success
218 String new_dir = metadata_file.getPath();
219 // remove the extension to get the directory name
220 new_dir = new_dir.substring(0, new_dir.lastIndexOf('.'));
221 MetadataXMLFileManager.loadMetadataXMLFiles(new File(new_dir));
222 Gatherer.g_man.refreshCollectionTree(DragTree.COLLECTION_CONTENTS_CHANGED);
223
224 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("ExplodeMetadataPrompt.Success"), Dictionary.get("ExplodeMetadataPrompt.Title"), JOptionPane.INFORMATION_MESSAGE);
225 } else {
226 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("ExplodeMetadataPrompt.Error"), Dictionary.get("ExplodeMetadataPrompt.Title"), JOptionPane.ERROR_MESSAGE);
227 }
228 self.dispose();
229
230 }
231
232 public int explodeMetadata(File file, String plugin_name,
233 String encoding, MetadataSet meta_set,
234 String filename_field) {
235
236 String meta_set_namespace = "";
237 if (meta_set != null) {
238 meta_set_namespace = meta_set.getNamespace();
239 }
240 try {
241 if (Gatherer.isGsdlRemote) {
242 // what do we do here??
243 return -1;
244 }
245 else {
246 String command[] = null;
247
248
249 if (Utility.isWindows()) {
250 command = new String[11];
251 if(Configuration.perl_path != null) {
252 command[0] = Configuration.perl_path;
253 }
254 else {
255 command[0] = "Perl.exe";
256 }
257 command[1] = Configuration.gsdl_path + "bin" + File.separator + "script" + File.separator + "explode_metadata_database.pl";
258 command[2] = "-plugin";
259 command[3] = plugin_name;
260 command[4] = "-encoding";
261 command[5] = encoding;
262 command[6] = "-metadata_set";
263 command[7] = meta_set_namespace;
264 command[8] = "-filename_field";
265 command[9] = filename_field;
266 command[10] = file.getPath();
267 }
268 else {
269 command = new String[10];
270
271 command[0] = "explode_metadata_database.pl";
272 command[1] = "-plugin";
273 command[2] = plugin_name;
274 command[3] = "-encoding";
275 command[4] = encoding;
276 command[5] = "-metadata_set";
277 command[6] = meta_set_namespace;
278 command[7] = "-filename_field";
279 command[8] = filename_field;
280 command[9] = file.getPath();
281
282 }
283 Runtime runtime = Runtime.getRuntime();
284 Process process = runtime.exec(command);
285 process.waitFor();
286 return process.exitValue();
287
288 } // else local
289
290 }
291 catch (Exception error) {
292 error.printStackTrace();
293 return -1;
294 }
295
296 }
297 }
298}
Note: See TracBrowser for help on using the repository browser.