source: trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/collection/GS2CollectionCfg.java@ 6743

Last change on this file since 6743 was 6743, checked in by cs025, 20 years ago

Fixed constructor calls to MGIndexer/MGPPIndexer.

  • Property svn:keywords set to Author Date Id Revision
File size: 3.9 KB
Line 
1package org.greenstone.gsdl3.gs3build.collection;
2
3import java.io.File;
4
5import java.util.List;
6import java.util.ArrayList;
7import java.util.Iterator;
8
9import org.greenstone.gsdl3.gs3build.doctypes.DocumentLoader;
10import org.greenstone.gsdl3.gs3build.util.XMLTools;
11import org.greenstone.gsdl3.gs3build.util.GS2TextFileHandler;
12
13import org.greenstone.gsdl3.gs3build.classifier.ClassifierInterface;
14import org.greenstone.gsdl3.gs3build.classifier.ClassifierManager;
15
16import org.greenstone.gsdl3.gs3build.indexers.*;
17
18import org.greenstone.gsdl3.gs3build.BuildManager;
19
20public class GS2CollectionCfg
21{
22 BuildManager buildManager;
23 IndexerInterface indexer;
24
25 class GS2CollectCfgHandler extends GS2TextFileHandler
26 {
27
28 GS2CollectCfgHandler(String content, File collectFile, GS2CollectionCfg configurator)
29 { super(content);
30
31 while (this.hasMoreLines()) {
32 String lineType;
33
34 this.getLine();
35
36 lineType = this.getEntry(true);
37 if (lineType == null || lineType.length() == 0) {
38 continue;
39 }
40
41 if (lineType.equals("classify"))
42 {
43 String classType = this.getEntry(true);
44 if (classType == null || classType.length() == 0) {
45 continue;
46 }
47 classType = "GS2" + classType + "Classifier";
48
49 List paramList = new ArrayList();
50
51 // read in the parameters - to allow for better abstraction of other parts,
52 // the handling of this is a bit 'odd', specifically modifying any file
53 // references here before passing them on...
54 String parameter = null;
55 String lastParam = null;
56 while (this.hasMore())
57 { String param = this.getEntry(true);
58
59 if (param != null && param.length() > 0)
60 { // expand any hfile references...
61 if (lastParam != null && lastParam.equals("-hfile")) {
62 param = collectFile.getParent() + File.separator + param;
63 }
64
65 paramList.add(param);
66 }
67
68 lastParam = param;
69 }
70
71 ClassifierInterface classifier = ClassifierManager.loadClassifier(classType, paramList);
72 if (classifier != null) {
73 configurator.addClassifier(classifier);
74 }
75 else {
76 }
77 }
78 else if (lineType.equals("buildtype")) {
79 if (this.hasMore()) {
80 String type = this.getEntry(true);
81 if (type != null) {
82 configurator.setBuildType(type);
83 }
84 }
85 }
86 else if (lineType.equals("indexes")) {
87 while (this.hasMore()) {
88 String index = this.getEntry(true);
89 if (index != null) {
90 System.out.println("Adding index " + index);
91 configurator.addIndex(index);
92 }
93 }
94 }
95 }
96 }
97 }
98
99 public GS2CollectionCfg(BuildManager manager, File file)
100 {
101 String documentText =
102 DocumentLoader.getAsString(file);
103
104 if (documentText == null) {
105 return;
106 }
107
108 this.buildManager = manager;
109
110 GS2CollectCfgHandler handler = new GS2CollectCfgHandler(documentText, file, this);
111 }
112
113 void addClassifier(ClassifierInterface classifier)
114 {
115 ClassifierManager manager = this.buildManager.getClassifierManager();
116
117 if (manager != null) {
118 manager.addClassifier(classifier);
119 }
120 else {
121 System.out.println("Unable to install due to missing manager");
122 }
123 }
124
125 void addIndex(String index)
126 {
127 if (this.indexer == null) {
128 this.setBuildType("mg");
129 }
130 this.indexer.configure(IndexerInterface.GS2_INDEX_LABEL, index);
131 }
132
133 void setBuildType(String type)
134 { if (type.equals("mgpp")) {
135 this.indexer = new MGPPIndexer("mgpp");
136 }
137 else {
138 this.indexer = new MGIndexer("mg");
139 }
140 this.buildManager.addIndexer(this.indexer);
141 }
142
143 public static GS2CollectionCfg getGS2CollectionCfg(BuildManager manager, File cfgFile)
144 { GS2CollectionCfg configurator = new GS2CollectionCfg(manager, cfgFile);
145 return configurator;
146 }
147
148 public static GS2CollectionCfg getGS2CollectionCfg(BuildManager manager, String etcDir)
149 {
150 File file = new File(etcDir, "collect.cfg");
151
152 if (!file.exists()) {
153 return null;
154 }
155
156 return getGS2CollectionCfg(manager, file);
157 }
158}
Note: See TracBrowser for help on using the repository browser.