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

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

Added index configuration

  • 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 System.out.println(Runtime.getRuntime().freeMemory());
76 }
77 else if (lineType.equals("buildtype")) {
78 if (this.hasMore()) {
79 String type = this.getEntry(true);
80 if (type != null) {
81 configurator.setBuildType(type);
82 }
83 }
84 }
85 else if (lineType.equals("indexes")) {
86 while (this.hasMore()) {
87 String index = this.getEntry(true);
88 if (index != null) {
89 System.out.println("Adding index " + index);
90 configurator.addIndex(index);
91 }
92 }
93 }
94 }
95 }
96 }
97
98 public GS2CollectionCfg(BuildManager manager, File file)
99 {
100 String documentText =
101 DocumentLoader.getAsString(file);
102
103 if (documentText == null) {
104 return;
105 }
106
107 this.buildManager = manager;
108
109 GS2CollectCfgHandler handler = new GS2CollectCfgHandler(documentText, file, this);
110 }
111
112 void addClassifier(ClassifierInterface classifier)
113 {
114 ClassifierManager manager = this.buildManager.getClassifierManager();
115
116 if (manager != null) {
117 manager.addClassifier(classifier);
118 }
119 }
120
121 void addIndex(String index)
122 {
123 if (this.indexer == null) {
124 this.setBuildType("mg");
125 }
126 this.indexer.configure(IndexerInterface.GS2_INDEX_LABEL, index);
127 System.out.println(Runtime.getRuntime().freeMemory());
128 }
129
130 void setBuildType(String type)
131 { if (type.equals("mgpp")) {
132 this.indexer = new MGPPIndexer();
133 }
134 else {
135 this.indexer = new MGIndexer();
136 }
137 this.buildManager.addIndexer(this.indexer);
138 }
139
140 public static GS2CollectionCfg getGS2CollectionCfg(BuildManager manager, File cfgFile)
141 { GS2CollectionCfg configurator = new GS2CollectionCfg(manager, cfgFile);
142 return configurator;
143 }
144
145 public static GS2CollectionCfg getGS2CollectionCfg(BuildManager manager, String etcDir)
146 {
147 File file = new File(etcDir, "collect.cfg");
148
149 if (!file.exists()) {
150 return null;
151 }
152
153 return getGS2CollectionCfg(manager, file);
154 }
155}
Note: See TracBrowser for help on using the repository browser.