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

Last change on this file since 10259 was 10259, checked in by mdewsnip, 19 years ago

Created a new "remote" directory for classes related to using a remote Greenstone server.

  • Property svn:keywords set to Author Date Id Revision
File size: 13.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.LocalLibraryServer;
40import org.greenstone.gatherer.remote.RemoteGreenstoneServer;
41import org.greenstone.gatherer.util.Utility;
42import org.greenstone.gatherer.util.ZipTools;
43import org.w3c.dom.*;
44import org.xml.sax.*;
45
46/** 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.
47 * @author John Thompson, Greenstone Digital Library, University of Waikato
48 * @version 2.3d
49 */
50public class CollectionDesignManager {
51 /** 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. */
52 static public CDMChangeListener change_listener;
53 /** These listeners listen to changes in the Design mode so as to allow incremental building */
54 static public DesignChangeListener all_change_listener;
55 static public DesignChangeListener buildcol_change_listener;
56 static public DesignChangeListener collect_cfg_change_listener;
57 /** A list of classifiers to use at build time. */
58 static public ClassifierManager classifier_manager;
59 /** The CollectionConfiguration object on which this CDM will be based. */
60 static public CollectionConfiguration collect_config;
61 /** A manager of collection level metadata. */
62 static public CollectionMetaManager collectionmeta_manager;
63 /** A list of formating strings to use at build time. */
64 static public FormatManager format_manager;
65 /** The manager in charge of displaying this manager and the controls for other managers. */
66 static public GeneralManager general_manager;
67 /** List of indexes to be built, and the default index. */
68 static public IndexManager index_manager;
69 /** Contains instructions dealing with the collection language. */
70 static public LanguageManager language_manager;
71 /** A simple manager for the visual review of metadata sets. */
72 static public MetadataSetView metadataset_view;
73 /** A list of plugins to use at build time. */
74 static public PluginManager plugin_manager;
75 /** The manager in charge of all aspects of searchtypes. We also ask this manager whether we are MG or MGPP enabled. */
76 static public SearchTypeManager searchtype_manager;
77 /** Contains: A list of subcollections, (defined on metadatadata), a list of which subcollection indexes to build and the default subcollection index. */
78 static public SubcollectionManager subcollection_manager;
79
80 static public SubcollectionIndexManager subcollectionindex_manager;
81 /** 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. */
82 static public SuperCollectionManager supercollection_manager; // Just cause I could ;p
83 /** The text translation manager. */
84 static public TranslationView translation_view;
85 /** These mark what needs to happen when building a collection where ONLY design options have been changed.
86 The build requirements of the higher numbers must include doing everything from the lower numbers. */
87 static final public int ALL = 3;
88 static final public int BUILDCOL = 2;
89 static final public int UPDATE_COLLECT_CFG = 1;
90 static final public int NOTHING = 0;
91 static private int rebuildTypeRequired = NOTHING; //Rebuild type required if only design options have changed
92 static protected boolean update_collect_cfg_required = false;
93
94 /** 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.
95 * @param collect_config_file the File representing a collection configuration file either in its text (G2) or xml (G3) form
96 */
97 public CollectionDesignManager(File collect_config_file) {
98 DebugStream.println("Initializaing CollectionDesignModule.");
99 change_listener = new CDMChangeListener();
100 all_change_listener = new DesignChangeListener(ALL);
101 buildcol_change_listener = new DesignChangeListener(BUILDCOL);
102 collect_cfg_change_listener = new DesignChangeListener(UPDATE_COLLECT_CFG);
103 // Parse the collection configuration
104 collect_config = new CollectionConfiguration(collect_config_file);
105 if (DebugStream.isDebuggingEnabled()) {
106 collect_config.display();
107 }
108 loadDesignDetails();
109 DebugStream.println("CollectionDesignModule loaded.");
110 }
111
112 /** Reloads the various managers to ensure they have built themselves from the latest details available in the collection configuration class
113 * @see org.greenstone.gatherer.cdm.ClassifierManager
114 * @see org.greenstone.gatherer.cdm.CollectionMetaManager
115 * @see org.greenstone.gatherer.cdm.FormatManager
116 * @see org.greenstone.gatherer.cdm.GeneralManager
117 * @see org.greenstone.gatherer.cdm.IndexManager
118 * @see org.greenstone.gatherer.cdm.LanguageManager
119 * @see org.greenstone.gatherer.cdm.MetadataSetView
120 * @see org.greenstone.gatherer.cdm.PluginManager
121 * @see org.greenstone.gatherer.cdm.SearchTypeManager
122 * @see org.greenstone.gatherer.cdm.SubcollectionIndexManager
123 * @see org.greenstone.gatherer.cdm.SubcollectionManager
124 * @see org.greenstone.gatherer.cdm.SuperCollectionManager
125 * @see org.greenstone.gatherer.cdm.TranslationView
126 */
127 private void loadDesignDetails() {
128 // Create the command information managers, registering the config file with each as necessary
129 language_manager = new LanguageManager(collect_config.getLanguages());
130 collectionmeta_manager = new CollectionMetaManager();
131 classifier_manager = new ClassifierManager();
132 general_manager = new GeneralManager();
133
134 searchtype_manager = new SearchTypeManager(collect_config.getSearchType());
135 if(searchtype_manager.isMGPPEnabled()) {
136 index_manager = new IndexManager(collect_config.getMGPPIndexes());
137 }
138 else {
139 index_manager = new IndexManager(collect_config.getMGIndexes());
140 }
141
142 metadataset_view = new MetadataSetView();
143 plugin_manager = new PluginManager();
144 plugin_manager.placeSeparator();
145 subcollection_manager = new SubcollectionManager();
146 subcollectionindex_manager = new SubcollectionIndexManager(collect_config.getSubIndexes());
147 supercollection_manager = new SuperCollectionManager(collect_config.getSuperCollection());
148 translation_view = new TranslationView();
149 format_manager = new FormatManager(); // Parse formats at the very end, given that they depend upon several other managers to appear properly.
150 }
151
152 /** This method deconstructs each of the managers, causing them to dispose of their controls.
153 */
154 public void destroy() {
155 // Remove visual the component from its parent.
156 if(general_manager.getParent() != null) {
157 general_manager.getParent().remove(general_manager);
158 }
159 // Remove references from persistant listeners.
160 classifier_manager.destroy();
161 classifier_manager = null;
162 format_manager.destroy();
163 format_manager = null;
164 general_manager.destroy();
165 general_manager = null;
166 index_manager.destroy();
167 index_manager = null;
168 language_manager.destroy();
169 language_manager = null;
170 metadataset_view.destroy();
171 metadataset_view = null;
172 plugin_manager.destroy();
173 plugin_manager = null;
174 subcollection_manager.destroy();
175 subcollection_manager = null;
176 supercollection_manager.destroy();
177 supercollection_manager = null;
178 translation_view.destroy();
179 translation_view = null;
180 }
181
182 /** Display the GUI interface for the CollectionDesignManager in the centre of the indicated panel.
183 * @param target the JPanel you wish to display the gui on
184 */
185 public void display(JPanel target) {
186 target.add(general_manager, BorderLayout.CENTER);
187 }
188 /** 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.
189 */
190 public void gainFocus() {
191 general_manager.gainFocus();
192 }
193
194 /** Called when the detail mode has changed which in turn may cause several design elements to be available/hidden
195 * @param mode the new mode as an int
196 */
197 public void modeChanged(int mode) {
198 plugin_manager.modeChanged(mode);
199 subcollection_manager.modeChanged(mode);
200 }
201
202 /** The cdm is considered to be ready if the collect.cfg file was found and parsed and the collection title is not error.
203 * @return true if the collection is ready, false otherwise
204 */
205 public boolean ready() {
206 return collect_config.ready();
207 }
208
209 /** Ensure that saving will actually work. This can return false if there is a collection filename clash for instance. */
210 public boolean canSave() {
211 return (general_manager == null || general_manager.canSave());
212 }
213
214
215 /** Cause the current collection configuration to be written out to disk.
216 */
217 public void save() {
218 System.err.println("Config file saved. The level of processing needed is: " + CollectionDesignManager.getRebuildTypeRequired()); //debug
219 // Release collection as necessary
220 String collection_name = Gatherer.c_man.getCollection().getName();
221 boolean collection_released = false;
222
223 if (update_collect_cfg_required && Gatherer.c_man.built() && LocalLibraryServer.isRunning() == true) {
224 // Release the collection
225 LocalLibraryServer.releaseCollection(collection_name);
226 collection_released = true;
227 }
228
229 general_manager.loseFocus();
230 collect_config.save();
231
232 if (update_collect_cfg_required && Gatherer.c_man.built() && Gatherer.isGsdlRemote) {
233 //If the GLI is running as an applet, and Format Features or Cross-Collection Searching have changed,
234 //upload etc/collect.cfg to the server to immediately reflect these changes.
235 ZipTools.zipup(Gatherer.getCollectDirectoryPath(), collection_name, Utility.CONFIG_FILE, null, "", "");
236 RemoteGreenstoneServer.upload_url_zip(collection_name, "etc", "", null);
237 }
238
239 // Read collection
240 if (collection_released) {
241 // Now re-add collection to server to force format commands to be processed
242 LocalLibraryServer.addCollection(collection_name);
243 }
244
245 if (update_collect_cfg_required) {
246 // Unset formats changed
247 update_collect_cfg_required = false;
248 }
249 }
250
251
252 static public Document XMLStringToDOM(StringBuffer xml, String form)
253 {
254 Document document = null;
255
256 // If something has gone horribly wrong then xml will be empty.
257 if(xml.length() > 0) {
258 try {
259 // Then read the xml from the piped input stream.
260 StringReader xml_sr = new StringReader(xml.toString());
261 InputSource source = new InputSource(xml_sr);
262 DOMParser parser = new DOMParser();
263 parser.parse(source);
264 document = parser.getDocument();
265 }
266 catch (Exception error) {
267 System.err.println("Failed when trying to parse XML stream ");
268 error.printStackTrace();
269 }
270 }
271 else {
272 //DebugStream.println("Zero length argument xml detected for: " + form);
273 String[] margs = new String[1];
274 margs[0] = form;
275 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CDM.PlugInManager.PlugIn_XML_Parse_Failed", margs), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE); // !! TO DO: This is bad -- this function is used for more than just plugins
276 }
277
278 return document;
279 }
280
281 public static int getRebuildTypeRequired() {
282 return rebuildTypeRequired;
283 }
284 public static void resetRebuildTypeRequired() {
285 setRebuildTypeRequired(NOTHING);
286 }
287 public static void setRebuildTypeRequired(int number) {
288 rebuildTypeRequired = number;
289 }
290
291 /**
292 * What exactly does this do?
293 */
294 private class CDMChangeListener
295 implements ActionListener, DocumentListener {
296
297 /** Gives notification that an event has happened */
298 public void actionPerformed(ActionEvent event) {
299 Gatherer.c_man.getCollection().setSaved(false);
300 }
301
302 /** Gives notification that an attribute or set of attributes changed. */
303 public void changedUpdate(DocumentEvent e) {
304 Gatherer.c_man.getCollection().setSaved(false);
305 }
306
307 /** Gives notification that there was an insert into the document. */
308 public void insertUpdate(DocumentEvent e) {
309 Gatherer.c_man.getCollection().setSaved(false);
310 }
311
312 /** Gives notification that a portion of the document has been removed. */
313 public void removeUpdate(DocumentEvent e) {
314 Gatherer.c_man.getCollection().setSaved(false);
315 }
316 }
317}
Note: See TracBrowser for help on using the repository browser.