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

Last change on this file since 12095 was 12095, checked in by kjdon, 18 years ago

not sure what I've changed or why

  • Property svn:keywords set to Author Date Id Revision
File size: 12.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: 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 /** A manager of general options */
66 static public GeneralManager general_manager;
67 /** List of indexes to be built, and the default index.
68 also handles build type and levels */
69 static public IndexingManager index_manager;
70 /** Contains instructions dealing with the collection language. */
71 static public LanguageManager language_manager;
72 /** Handling writing extra.dm file */
73 static public MacrosManager macros_manager;
74 /** A simple manager for the visual review of metadata sets. */
75 static public MetadataSetView metadataset_view;
76 /** A list of plugins to use at build time. */
77 static public PluginManager plugin_manager;
78 /** a manager of searching metadata such as index names*/
79 static public SearchMetadataManager searchmetadata_manager;
80 /** Contains: A list of subcollections, (defined on metadatadata), a list of which subcollection indexes to build and the default subcollection index. */
81 static public SubcollectionManager subcollection_manager;
82
83 static public SubcollectionIndexManager subcollectionindex_manager;
84 /** 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. */
85 static public SuperCollectionManager supercollection_manager; // Just cause I could ;p
86 /** The text translation manager. */
87 static public TranslationView translation_manager;
88 /** These mark what needs to happen when building a collection where ONLY design options have been changed.
89 The build requirements of the higher numbers must include doing everything from the lower numbers. */
90 static final public int ALL = 3;
91 static final public int BUILDCOL = 2;
92 static final public int UPDATE_COLLECT_CFG = 1;
93 static final public int NOTHING = 0;
94 static private int rebuildTypeRequired = NOTHING; //Rebuild type required if only design options have changed
95 static public boolean update_collect_cfg_required = false;
96
97 /** 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.
98 * @param collect_config_file the File representing a collection configuration file either in its text (G2) or xml (G3) form
99 */
100 public CollectionDesignManager(File collect_config_file) {
101 DebugStream.println("Initializaing CollectionDesignModule.");
102 change_listener = new CDMChangeListener();
103 all_change_listener = new DesignChangeListener(ALL);
104 buildcol_change_listener = new DesignChangeListener(BUILDCOL);
105 collect_cfg_change_listener = new DesignChangeListener(UPDATE_COLLECT_CFG);
106 // Parse the collection configuration
107 collect_config = new CollectionConfiguration(collect_config_file);
108 if (DebugStream.isDebuggingEnabled()) {
109 collect_config.display();
110 }
111 loadDesignDetails();
112 DebugStream.println("CollectionDesignModule loaded.");
113 }
114
115 /** Reloads the various managers to ensure they have built themselves from the latest details available in the collection configuration class
116 * @see org.greenstone.gatherer.cdm.ClassifierManager
117 * @see org.greenstone.gatherer.cdm.CollectionMetaManager
118 * @see org.greenstone.gatherer.cdm.FormatManager
119 * @see org.greenstone.gatherer.cdm.GeneralManager
120 * @see org.greenstone.gatherer.cdm.IndexManager
121 * @see org.greenstone.gatherer.cdm.LanguageManager
122 * @see org.greenstone.gatherer.cdm.MetadataSetView
123 * @see org.greenstone.gatherer.cdm.PluginManager
124 * @see org.greenstone.gatherer.cdm.SubcollectionIndexManager
125 * @see org.greenstone.gatherer.cdm.SubcollectionManager
126 * @see org.greenstone.gatherer.cdm.SuperCollectionManager
127 * @see org.greenstone.gatherer.cdm.TranslationView
128 */
129 private void loadDesignDetails() {
130 // Create the command information managers, registering the config file with each as necessary
131 language_manager = new LanguageManager(collect_config.getLanguages());
132 collectionmeta_manager = new CollectionMetaManager();
133 classifier_manager = new ClassifierManager();
134 general_manager = new GeneralManager();
135 macros_manager = new MacrosManager();
136 index_manager = new IndexingManager();
137 metadataset_view = new MetadataSetView();
138 plugin_manager = new PluginManager();
139 plugin_manager.placeSeparator();
140 subcollection_manager = new SubcollectionManager();
141 subcollectionindex_manager = new SubcollectionIndexManager(collect_config.getSubIndexes());
142 supercollection_manager = new SuperCollectionManager(collect_config.getSuperCollection());
143 searchmetadata_manager = new SearchMetadataManager();
144 translation_manager = new TranslationView();
145 format_manager = new FormatManager(); // Parse formats at the very end, given that they depend upon several other managers to appear properly.
146 }
147
148 /** This method deconstructs each of the managers, causing them to dispose of their controls.
149 */
150 public void destroy() {
151 // Remove references from persistant listeners.
152 classifier_manager.destroy();
153 classifier_manager = null;
154 searchmetadata_manager.destroy();
155 searchmetadata_manager = null;
156 format_manager.destroy();
157 format_manager = null;
158 general_manager.destroy();
159 general_manager = null;
160 index_manager.destroy();
161 index_manager = null;
162 language_manager.destroy();
163 language_manager = null;
164 metadataset_view.destroy();
165 metadataset_view = null;
166 plugin_manager.destroy();
167 plugin_manager = null;
168 subcollection_manager.destroy();
169 subcollection_manager = null;
170 supercollection_manager.destroy();
171 supercollection_manager = null;
172 translation_manager.destroy();
173 translation_manager = null;
174 }
175
176 /** Called when the detail mode has changed which in turn may cause several design elements to be available/hidden
177 * @param mode the new mode as an int
178 */
179 public void modeChanged(int mode) {
180 plugin_manager.modeChanged(mode);
181 classifier_manager.modeChanged(mode);
182 subcollection_manager.modeChanged(mode);
183 supercollection_manager.modeChanged(mode);
184 format_manager.modeChanged(mode);
185 index_manager.modeChanged(mode);
186 translation_manager.modeChanged(mode);
187 metadataset_view.modeChanged(mode);
188 general_manager.modeChanged(mode);
189 language_manager.modeChanged(mode);
190 searchmetadata_manager.modeChanged(mode);
191 }
192
193 /** The cdm is considered to be ready if the collect.cfg file was found and parsed and the collection title is not error.
194 * @return true if the collection is ready, false otherwise
195 */
196 public boolean ready() {
197 return collect_config.ready();
198 }
199
200
201 public void save() {
202 save(false);
203 }
204 /** Cause the current collection configuration to be written out to disk.
205 */
206 public void save(boolean force_save)
207 {
208 general_manager.loseFocus();
209 if (!update_collect_cfg_required && !force_save) {
210 DebugStream.println("Asked to save the config file, but don't need to");
211 return;
212 }
213
214 DebugStream.println("Saving the collection config file");
215 // Release collection as necessary
216 String collection_name = Gatherer.c_man.getCollection().getName();
217 boolean collection_released = false;
218
219 if (Gatherer.c_man.built() && LocalLibraryServer.isRunning() == true) {
220 // Release the collection
221 LocalLibraryServer.releaseCollection(collection_name);
222 collection_released = true;
223 }
224
225 collect_config.save();
226
227 // Read collection
228 if (collection_released) {
229 // Now re-add collection to server to force format commands to be processed
230 LocalLibraryServer.addCollection(collection_name);
231 }
232
233 // Unset formats changed
234 update_collect_cfg_required = false;
235
236 }
237
238
239 static public Document XMLStringToDOM(StringBuffer xml, String form)
240 {
241 Document document = null;
242
243 try {
244 // Read the xml from the piped input stream.
245 StringReader xml_sr = new StringReader(xml.toString());
246 InputSource source = new InputSource(xml_sr);
247 DOMParser parser = new DOMParser();
248 parser.parse(source);
249 document = parser.getDocument();
250 }
251 catch (Exception error) {
252 System.err.println("Failed when trying to parse XML stream ");
253 error.printStackTrace();
254 }
255
256 return document;
257 }
258
259 public static int getRebuildTypeRequired() {
260 return rebuildTypeRequired;
261 }
262 public static void resetRebuildTypeRequired() {
263 setRebuildTypeRequired(NOTHING);
264 }
265 public static void setRebuildTypeRequired(int number) {
266 rebuildTypeRequired = number;
267 }
268
269 /**
270 * What exactly does this do?
271 */
272 private class CDMChangeListener
273 implements ActionListener, DocumentListener {
274
275 /** Gives notification that an event has happened */
276 public void actionPerformed(ActionEvent event) {
277 Gatherer.c_man.getCollection().setSaved(false);
278 }
279
280 /** Gives notification that an attribute or set of attributes changed. */
281 public void changedUpdate(DocumentEvent e) {
282 Gatherer.c_man.getCollection().setSaved(false);
283 }
284
285 /** Gives notification that there was an insert into the document. */
286 public void insertUpdate(DocumentEvent e) {
287 Gatherer.c_man.getCollection().setSaved(false);
288 }
289
290 /** Gives notification that a portion of the document has been removed. */
291 public void removeUpdate(DocumentEvent e) {
292 Gatherer.c_man.getCollection().setSaved(false);
293 }
294 }
295}
Note: See TracBrowser for help on using the repository browser.