source: trunk/greenstone3-extensions/gs3build/src/org/greenstone/gsdl3/gs3build/collection/GS2CollectionCfg.java@ 12188

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

Initial revision

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