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

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

Made Gatherer.configServer static.

  • Property svn:keywords set to Author Date Id Revision
File size: 12.2 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
198 /** Cause the current collection configuration to be written out to disk.
199 */
200 public void save() {
201 // Release collection as necessary
202 boolean collection_released = false;
203 String col_name = Gatherer.c_man.getCollection().getName();
204 boolean formats_changed = format_manager.formatsChanged();
205
206 if (formats_changed && Gatherer.c_man.built() && Configuration.exec_file != null) {
207 // Release the collection
208 Gatherer.configServer(GSDLSiteConfig.RELEASE_COMMAND + col_name);
209 // This is very important -- it ensures that the above command has finished
210 Gatherer.configServer("");
211 collection_released = true;
212 }
213
214 general_manager.loseFocus();
215 collect_config.save();
216
217 if (Gatherer.isGsdlRemote) {
218 if (formats_changed && Gatherer.c_man.built()) {
219 // upload etc/collect.cfg to server to reflect changes
220 Utility.zipup(col_name,Utility.CONFIG_FILE);
221 GathererApplet.upload_url_zip(col_name,"etc");
222 }
223 }
224
225 // Readd collection
226 if (collection_released) {
227 // Now re-add collection to server to force format commands to be processed
228 Gatherer.configServer(GSDLSiteConfig.ADD_COMMAND + col_name);
229 // This is very important -- it ensures that the above command has finished
230 Gatherer.configServer("");
231 }
232
233 if (formats_changed) {
234 // Unset formats changed
235 format_manager.setFormatsChanged(false);
236 }
237 }
238
239
240 static public Document XMLStringToDOM(StringBuffer xml, String form)
241 {
242 Document document = null;
243
244 // If something has gone horribly wrong then xml will be empty.
245 if(xml.length() > 0) {
246 try {
247 // Then read the xml from the piped input stream.
248 StringReader xml_sr = new StringReader(xml.toString());
249 InputSource source = new InputSource(xml_sr);
250 DOMParser parser = new DOMParser();
251 parser.parse(source);
252 document = parser.getDocument();
253 }
254 catch (Exception error) {
255 System.err.println("Failed when trying to parse XML stream ");
256 error.printStackTrace();
257 }
258 }
259 else {
260 //DebugStream.println("Zero length argument xml detected for: " + form);
261 String[] margs = new String[1];
262 margs[0] = form;
263 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CDM.PlugInManager.PlugIn_XML_Parse_Failed", margs), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
264 }
265
266 return document;
267 }
268
269
270 private class CDMChangeListener
271 implements ActionListener, DocumentListener {
272
273 public void actionPerformed(ActionEvent event) {
274 Gatherer.c_man.getCollection().setSaved(false);
275 }
276
277 /** Gives notification that an attribute or set of attributes changed. */
278 public void changedUpdate(DocumentEvent e) {
279 Gatherer.c_man.getCollection().setSaved(false);
280 }
281
282 /** Gives notification that there was an insert into the document. */
283 public void insertUpdate(DocumentEvent e) {
284 Gatherer.c_man.getCollection().setSaved(false);
285 }
286
287 /** Gives notification that a portion of the document has been removed. */
288 public void removeUpdate(DocumentEvent e) {
289 Gatherer.c_man.getCollection().setSaved(false);
290 }
291 }
292}
Note: See TracBrowser for help on using the repository browser.