source: trunk/gli/src/org/greenstone/gatherer/cdm/CollectionDesignManager.java@ 8250

Last change on this file since 8250 was 8250, checked in by mdewsnip, 20 years ago

Moved the download_url_zip and upload_url_zip functions from Utility into GathererApplet, since they depend on the Gatherer class.

  • Property svn:keywords set to Author Date Id Revision
File size: 12.9 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: John Thompson, Greenstone Digital Library, University of Waikato
9 *
10 * Copyright (C) 1999 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.cdm;
28
29import java.awt.*;
30import java.awt.event.*;
31import java.io.*;
32import javax.swing.*;
33import javax.swing.event.*;
34import org.apache.xerces.parsers.*;
35import org.greenstone.gatherer.Configuration;
36import org.greenstone.gatherer.DebugStream;
37import org.greenstone.gatherer.Dictionary;
38import org.greenstone.gatherer.Gatherer;
39import org.greenstone.gatherer.GathererApplet;
40import org.greenstone.gatherer.util.GSDLSiteConfig;
41import org.greenstone.gatherer.util.Utility;
42import org.w3c.dom.*;
43import org.xml.sax.*;
44
45/** This manager provides access to submanagers, which in turn provide tools for the designing of Greenstone collections via the information stored in etc/collect.cfg. This class acts as a hub for the managers that handle specific parts of the configuration such as classifiers, format strings and language settings.
46 * @author John Thompson, Greenstone Digital Library, University of Waikato
47 * @version 2.3d
48 */
49public class CollectionDesignManager {
50 /** This listener listens for any event on any of the components in any of the sub-views, and marks the collection as needing saving if any change occurs. */
51 static public CDMChangeListener change_listener;
52 /** A list of classifiers to use at build time. */
53 static public ClassifierManager classifier_manager;
54 /** The CollectionConfiguration object on which this CDM will be based. */
55 static public CollectionConfiguration collect_config;
56 /** A manager of collection level metadata. */
57 static public CollectionMetaManager collectionmeta_manager;
58 /** A list of formating strings to use at build time. */
59 static public FormatManager format_manager;
60 /** The manager in charge of displaying this manager and the controls for other managers. */
61 static public GeneralManager general_manager;
62 /** List of indexes to be built, and the default index. */
63 static public IndexManager index_manager;
64 /** Contains instructions dealing with the collection language. */
65 static public LanguageManager language_manager;
66 /** A simple manager for the visual review of metadata sets. */
67 static public MetadataSetView metadataset_view;
68 /** A list of plugins to use at build time. */
69 static public PlugInManager plugin_manager;
70 /** The manager in charge of all aspects of searchtypes. We also ask this manager whether we are MG or MGPP enabled. */
71 static public SearchTypeManager searchtype_manager;
72 /** Contains: A list of subcollections, (defined on metadatadata), a list of which subcollection indexes to build and the default subcollection index. */
73 static public SubcollectionManager subcollection_manager;
74
75 static public SubcollectionIndexManager subcollectionindex_manager;
76 /** A supercollection command allows a single search to be conducted across several collections. It is a very basic command and so avoids all the crazy model stuff that exists in most of the design managers. */
77 static public SuperCollectionManager supercollection_manager; // Just cause I could ;p
78 /** The text translation manager. */
79 static public TranslationView translation_view;
80 /** Constructor. Loads a certain collection configuration file, which is parsed into a DOM. This model is then registered with the command information managers, each of whom knows how to, and provides controls to, alter certain commands.
81 * @param collect_config_file the File representing a collection configuration file either in its text (G2) or xml (G3) form
82 */
83 public CollectionDesignManager(File collect_config_file) {
84 DebugStream.println("Initializaing CollectionDesignModule.");
85 change_listener = new CDMChangeListener();
86 // Parse the collection configuration
87 collect_config = new CollectionConfiguration(collect_config_file);
88 if (DebugStream.isDebuggingEnabled()) {
89 collect_config.display();
90 }
91 loadDesignDetails();
92 DebugStream.println("CollectionDesignModule loaded.");
93 }
94
95 /** Reloads the various managers to ensure they have built themselves from the latest details available in the collection configuration class
96 * @see org.greenstone.gatherer.cdm.ClassifierManager
97 * @see org.greenstone.gatherer.cdm.CollectionMetaManager
98 * @see org.greenstone.gatherer.cdm.FormatManager
99 * @see org.greenstone.gatherer.cdm.GeneralManager
100 * @see org.greenstone.gatherer.cdm.IndexManager
101 * @see org.greenstone.gatherer.cdm.LanguageManager
102 * @see org.greenstone.gatherer.cdm.MetadataSetView
103 * @see org.greenstone.gatherer.cdm.PlugInManager
104 * @see org.greenstone.gatherer.cdm.SearchTypeManager
105 * @see org.greenstone.gatherer.cdm.SubcollectionIndexManager
106 * @see org.greenstone.gatherer.cdm.SubcollectionManager
107 * @see org.greenstone.gatherer.cdm.SuperCollectionManager
108 * @see org.greenstone.gatherer.cdm.TranslationView
109 */
110 private void loadDesignDetails() {
111 // Create the command information managers, registering the config file with each as necessary
112 language_manager = new LanguageManager(collect_config.getLanguages());
113 collectionmeta_manager = new CollectionMetaManager();
114 classifier_manager = new ClassifierManager();
115 general_manager = new GeneralManager();
116
117 searchtype_manager = new SearchTypeManager(collect_config.getSearchType());
118 if(searchtype_manager.isMGPPEnabled()) {
119 index_manager = new IndexManager(collect_config.getMGPPIndexes());
120 }
121 else {
122 index_manager = new IndexManager(collect_config.getMGIndexes());
123 }
124
125 metadataset_view = new MetadataSetView();
126 plugin_manager = new PlugInManager();
127 plugin_manager.placeSeparator();
128 subcollection_manager = new SubcollectionManager();
129 subcollectionindex_manager = new SubcollectionIndexManager(collect_config.getSubIndexes());
130 supercollection_manager = new SuperCollectionManager(collect_config.getSuperCollection());
131 translation_view = new TranslationView();
132 format_manager = new FormatManager(); // Parse formats at the very end, given that they depend upon several other managers to appear properly.
133 }
134
135 /** This method deconstructs each of the managers, causing them to dispose of their controls.
136 */
137 public void destroy() {
138 // Remove visual the component from its parent.
139 if(general_manager.getParent() != null) {
140 general_manager.getParent().remove(general_manager);
141 }
142 // Remove references from persistant listeners.
143 classifier_manager.destroy();
144 classifier_manager = null;
145 format_manager.destroy();
146 format_manager = null;
147 general_manager.destroy();
148 general_manager = null;
149 index_manager.destroy();
150 index_manager = null;
151 language_manager.destroy();
152 language_manager = null;
153 metadataset_view.destroy();
154 metadataset_view = null;
155 plugin_manager.destroy();
156 plugin_manager = null;
157 subcollection_manager.destroy();
158 subcollection_manager = null;
159 supercollection_manager.destroy();
160 supercollection_manager = null;
161 translation_view.destroy();
162 translation_view = null;
163 }
164
165 /** Display the GUI interface for the CollectionDesignManager in the centre of the indicated panel.
166 * @param target the JPanel you wish to display the gui on
167 */
168 public void display(JPanel target) {
169 target.add(general_manager, BorderLayout.CENTER);
170 }
171 /** When the tab on the JTabbedPane that contains the GUI is selected, this method is called to ensure that the controls are all up to date, in terms of references to metadata etc.
172 */
173 public void gainFocus() {
174 general_manager.gainFocus();
175 }
176
177 /** Called when the detail mode has changed which in turn may cause several design elements to be available/hidden
178 * @param mode the new mode as an int
179 */
180 public void modeChanged(int mode) {
181 plugin_manager.modeChanged(mode);
182 subcollection_manager.modeChanged(mode);
183 }
184
185 /** The cdm is considered to be ready if the collect.cfg file was found and parsed and the collection title is not error.
186 * @return true if the collection is ready, false otherwise
187 */
188 public boolean ready() {
189 return collect_config.ready();
190 }
191
192 /** Ensure that saving will actually work. This can return false if there is a collection filename clash for instance. */
193 public boolean canSave() {
194 return (general_manager == null || general_manager.canSave());
195 }
196
197 /** Cause the current collection configuration to be written out to disk.
198 * @see org.greenstone.gatherer.cdm.ClassifierManager
199 * @see org.greenstone.gatherer.cdm.CollectionMetaManager
200 * @see org.greenstone.gatherer.cdm.FormatManager
201 * @see org.greenstone.gatherer.cdm.IndexManager
202 * @see org.greenstone.gatherer.cdm.LanguageManager
203 * @see org.greenstone.gatherer.cdm.MetadataSetView
204 * @see org.greenstone.gatherer.cdm.PlugInManager
205 * @see org.greenstone.gatherer.cdm.SubcollectionManager
206 */
207 public void save() {
208 // Release collection as necessary
209 ///ystem.err.println("Would have released collection if necessary.");
210 boolean collection_released = false;
211 String col_name = Gatherer.c_man.getCollection().getName();
212 boolean formats_changed = format_manager.formatsChanged();
213
214 if(formats_changed && Gatherer.c_man.built() && Configuration.exec_file != null) {
215 // Release the collection
216 Gatherer.self.configServer(GSDLSiteConfig.RELEASE_COMMAND + col_name);
217 // This is very important -- it ensures that the above command has finished
218 Gatherer.self.configServer("");
219 collection_released = true;
220 }
221
222 general_manager.loseFocus();
223 collect_config.save();
224
225 if (Gatherer.isGsdlRemote) {
226 if(formats_changed && Gatherer.c_man.built()) {
227 // upload etc/collect.cfg to server to reflect changes
228 Utility.zipup(col_name,Utility.CONFIG_FILE);
229 GathererApplet.upload_url_zip(col_name,"etc");
230 }
231 }
232
233 // Readd collection
234 ///ystem.err.println("Would have added collection if it had been released.");
235 if(collection_released) {
236 // Now re-add collection to server to force format commands to be processed
237 Gatherer.self.configServer(GSDLSiteConfig.ADD_COMMAND + col_name);
238 // This is very important -- it ensures that the above command has finished
239 Gatherer.self.configServer("");
240 }
241
242 if (formats_changed) {
243 // Unset formats changed
244 format_manager.setFormatsChanged(false);
245 }
246 }
247
248
249 static public Document XMLStringToDOM(StringBuffer xml, String form)
250 {
251 Document document = null;
252
253 // If something has gone horribly wrong then xml will be empty.
254 if(xml.length() > 0) {
255 try {
256 // Then read the xml from the piped input stream.
257 StringReader xml_sr = new StringReader(xml.toString());
258 InputSource source = new InputSource(xml_sr);
259 DOMParser parser = new DOMParser();
260 parser.parse(source);
261 document = parser.getDocument();
262 }
263 catch (Exception error) {
264 System.err.println("Failed when trying to parse XML stream ");
265 error.printStackTrace();
266 }
267 }
268 else {
269 //DebugStream.println("Zero length argument xml detected for: " + form);
270 String[] margs = new String[1];
271 margs[0] = form;
272 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CDM.PlugInManager.PlugIn_XML_Parse_Failed", margs), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
273 }
274
275 return document;
276 }
277
278
279 private class CDMChangeListener
280 implements ActionListener, DocumentListener {
281
282 public void actionPerformed(ActionEvent event) {
283 Gatherer.c_man.getCollection().setSaved(false);
284 }
285
286 /** Gives notification that an attribute or set of attributes changed. */
287 public void changedUpdate(DocumentEvent e) {
288 Gatherer.c_man.getCollection().setSaved(false);
289 }
290
291 /** Gives notification that there was an insert into the document. */
292 public void insertUpdate(DocumentEvent e) {
293 Gatherer.c_man.getCollection().setSaved(false);
294 }
295
296 /** Gives notification that a portion of the document has been removed. */
297 public void removeUpdate(DocumentEvent e) {
298 Gatherer.c_man.getCollection().setSaved(false);
299 }
300 }
301}
Note: See TracBrowser for help on using the repository browser.