- Timestamp:
- 2006-09-01T13:51:34+12:00 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/greenstone/Classifiers.java
r12644 r12646 49 49 // A list of all the classifiers in the core Greenstone "perllib/classify" folder (arguments may not be loaded) 50 50 static private ArrayList core_greenstone_classifiers_list = null; 51 // The name of the loaded collection 52 static private String collection_name = null; 53 // A list of all the classifiers in the loaded collection's "perllib/classify" folder (arguments may not be loaded) 54 static private ArrayList collection_specific_classifiers_list = null; 51 55 52 56 53 57 static public Classifier getClassifier(String classifier_name, boolean arguments_required) 54 58 { 59 Classifier classifier = null; 60 boolean collection_specific = false; 61 62 // Check the collection-specific classifiers first 63 for (int i = 0; i < collection_specific_classifiers_list.size(); i++) { 64 Classifier collection_specific_classifier = (Classifier) collection_specific_classifiers_list.get(i); 65 if (collection_specific_classifier.getName().equals(classifier_name)) { 66 classifier = collection_specific_classifier; 67 collection_specific = true; 68 break; 69 } 70 } 71 72 // Try the core Greenstone classifiers if necessary 73 if (classifier == null) { 74 for (int i = 0; i < core_greenstone_classifiers_list.size(); i++) { 75 Classifier core_greenstone_classifier = (Classifier) core_greenstone_classifiers_list.get(i); 76 if (core_greenstone_classifier.getName().equals(classifier_name)) { 77 classifier = core_greenstone_classifier; 78 break; 79 } 80 } 81 } 82 83 // If we've found the classifier, load its arguments now, if required 84 if (classifier != null && arguments_required) { 85 if (classifier.getArguments().size() == 0) { 86 loadClassifierInfo(classifier, collection_specific); 87 } 88 else { 89 DebugStream.println("Already loaded arguments for " + classifier_name + "!"); 90 } 91 } 92 93 return classifier; 94 } 95 96 97 /** Returns a new list from merging the collection-specific and the core Greenstone classifiers. */ 98 static public ArrayList getClassifiersList() 99 { 100 ArrayList classifiers_list = new ArrayList(); 101 classifiers_list.addAll(collection_specific_classifiers_list); 102 103 // Add in the core Greenstone classifiers, taking care not to overwrite any collection-specific ones 55 104 for (int i = 0; i < core_greenstone_classifiers_list.size(); i++) { 56 Classifier classifier = (Classifier) core_greenstone_classifiers_list.get(i); 57 if (classifier.getName().equals(classifier_name)) { 58 if (arguments_required) { 59 if (classifier.getArguments().size() == 0) { 60 loadClassifierInfo(classifier); 61 } 62 else { 63 DebugStream.println("Already loaded arguments for " + classifier_name + "!"); 64 } 65 } 66 return classifier; 67 } 68 } 69 70 return null; 71 } 72 73 74 static public ArrayList getClassifiersList() 75 { 76 return core_greenstone_classifiers_list; 77 } 78 79 80 static private void loadClassifierInfo(Classifier classifier) 105 Classifier core_greenstone_classifier = (Classifier) core_greenstone_classifiers_list.get(i); 106 107 boolean found = false; 108 for (int j = 0; j < collection_specific_classifiers_list.size(); j++) { 109 Classifier collection_specific_classifier = (Classifier) collection_specific_classifiers_list.get(j); 110 if (core_greenstone_classifier.getName().equals(collection_specific_classifier.getName())) { 111 found = true; 112 break; 113 } 114 } 115 116 if (!found) { 117 classifiers_list.add(core_greenstone_classifier); 118 } 119 } 120 121 return classifiers_list; 122 } 123 124 125 static private void loadClassifierInfo(Classifier classifier, boolean collection_specific) 81 126 { 82 127 DebugStream.println("Loading arguments for " + classifier.getName() + "..."); … … 96 141 } 97 142 args.add(LocalGreenstone.getBinScriptDirectoryPath() + "classinfo.pl"); 143 if (collection_specific) { 144 args.add("-collection"); 145 args.add(collection_name); 146 } 98 147 args.add("-xml"); 99 148 args.add("-language"); … … 108 157 } 109 158 110 if (xml.length() > 0) { 111 parseClassifierInfoXML(classifier, xml.toString()); 112 } 113 else { 159 // Check the XML output was obtained successfully 160 if (xml == null || xml.length() == 0) { 114 161 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CDM.ClassifierManager.Classifier_XML_Parse_Failed", classifier.getName()), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE); 115 } 162 return; 163 } 164 165 parseClassifierInfoXML(classifier, xml.toString()); 116 166 } 117 167 catch (Exception exception) { … … 121 171 122 172 123 static public void loadClassifiersList( )173 static public void loadClassifiersList(String collection_name_arg) 124 174 { 125 175 DebugStream.println("In loadClassifiersList()..."); 176 177 // If we're getting the collection-specific classifiers, clear the old list no matter what 178 if (collection_name_arg != null) { 179 collection_name = collection_name_arg; 180 collection_specific_classifiers_list = new ArrayList(); 181 } 126 182 127 183 // Run classifierfo.pl to get the list of classifiers … … 139 195 } 140 196 args.add(LocalGreenstone.getBinScriptDirectoryPath() + "classinfo.pl"); 197 if (collection_name != null) { 198 args.add("-collection"); 199 args.add(collection_name); 200 } 141 201 args.add("-listall"); 142 202 args.add("-xml"); … … 149 209 } 150 210 151 if (xml.length() > 0) { 211 // Check the XML output was obtained successfully 212 if (xml == null || xml.length() == 0) { 213 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CDM.ClassifierManager.Classifier_List_XML_Parse_Failed"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE); 214 return; 215 } 216 217 if (collection_name != null) { 218 collection_specific_classifiers_list = parseClassifiersListXML(xml.toString()); 219 } 220 else { 152 221 core_greenstone_classifiers_list = parseClassifiersListXML(xml.toString()); 153 }154 else {155 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CDM.ClassifierManager.Classifier_List_XML_Parse_Failed"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);156 222 } 157 223 }
Note:
See TracChangeset
for help on using the changeset viewer.