1 | package org.greenstone.gsdl3.gs3build.collection;
|
---|
2 |
|
---|
3 | import java.io.File;
|
---|
4 |
|
---|
5 | import java.util.List;
|
---|
6 | import java.util.ArrayList;
|
---|
7 | import java.util.Iterator;
|
---|
8 |
|
---|
9 | import org.greenstone.gsdl3.gs3build.doctypes.DocumentLoader;
|
---|
10 | import org.greenstone.gsdl3.gs3build.util.XMLTools;
|
---|
11 | import org.greenstone.gsdl3.gs3build.util.GS2TextFileHandler;
|
---|
12 |
|
---|
13 | import org.greenstone.gsdl3.gs3build.classifier.ClassifierInterface;
|
---|
14 | import org.greenstone.gsdl3.gs3build.classifier.ClassifierManager;
|
---|
15 |
|
---|
16 | import org.greenstone.gsdl3.gs3build.BuildManager;
|
---|
17 |
|
---|
18 | public class GS2CollectionCfg
|
---|
19 | {
|
---|
20 | BuildManager buildManager;
|
---|
21 |
|
---|
22 | class GS2CollectCfgHandler extends GS2TextFileHandler
|
---|
23 | {
|
---|
24 |
|
---|
25 | GS2CollectCfgHandler(String content, File collectFile, GS2CollectionCfg configurator)
|
---|
26 | { super(content);
|
---|
27 |
|
---|
28 | while (this.hasMoreLines()) {
|
---|
29 | String lineType;
|
---|
30 |
|
---|
31 | this.getLine();
|
---|
32 |
|
---|
33 | lineType = this.getEntry(true);
|
---|
34 | if (lineType == null || lineType.length() == 0) {
|
---|
35 | continue;
|
---|
36 | }
|
---|
37 |
|
---|
38 | if (lineType.equals("classify"))
|
---|
39 | {
|
---|
40 | String classType = this.getEntry(true);
|
---|
41 | if (classType == null || classType.length() == 0) {
|
---|
42 | continue;
|
---|
43 | }
|
---|
44 | classType = "GS2" + classType + "Classifier";
|
---|
45 |
|
---|
46 | List paramList = new ArrayList();
|
---|
47 |
|
---|
48 | // read in the parameters - to allow for better abstraction of other parts,
|
---|
49 | // the handling of this is a bit 'odd', specifically modifying any file
|
---|
50 | // references here before passing them on...
|
---|
51 | String parameter = null;
|
---|
52 | String lastParam = null;
|
---|
53 | while (this.hasMore())
|
---|
54 | { String param = this.getEntry(true);
|
---|
55 |
|
---|
56 | if (param != null && param.length() > 0)
|
---|
57 | { // expand any hfile references...
|
---|
58 | if (lastParam != null && lastParam.equals("-hfile")) {
|
---|
59 | param = collectFile.getParent() + File.separator + param;
|
---|
60 | }
|
---|
61 |
|
---|
62 | paramList.add(param);
|
---|
63 | }
|
---|
64 |
|
---|
65 | lastParam = param;
|
---|
66 | }
|
---|
67 |
|
---|
68 | ClassifierInterface classifier = ClassifierManager.loadClassifier(classType, paramList);
|
---|
69 | if (classifier != null) {
|
---|
70 | configurator.addClassifier(classifier);
|
---|
71 | }
|
---|
72 | }
|
---|
73 | }
|
---|
74 | }
|
---|
75 | }
|
---|
76 |
|
---|
77 | public GS2CollectionCfg(BuildManager manager, File file)
|
---|
78 | {
|
---|
79 | String documentText =
|
---|
80 | DocumentLoader.getAsString(file);
|
---|
81 |
|
---|
82 | if (documentText == null) {
|
---|
83 | return;
|
---|
84 | }
|
---|
85 |
|
---|
86 | this.buildManager = manager;
|
---|
87 |
|
---|
88 | GS2CollectCfgHandler handler = new GS2CollectCfgHandler(documentText, file, this);
|
---|
89 | }
|
---|
90 |
|
---|
91 | void addClassifier(ClassifierInterface classifier)
|
---|
92 | {
|
---|
93 | ClassifierManager manager = this.buildManager.getClassifierManager();
|
---|
94 |
|
---|
95 | if (manager != null) {
|
---|
96 | manager.addClassifier(classifier);
|
---|
97 | }
|
---|
98 | }
|
---|
99 |
|
---|
100 | public static GS2CollectionCfg getGS2CollectionCfg(BuildManager manager, File cfgFile)
|
---|
101 | { GS2CollectionCfg configurator = new GS2CollectionCfg(manager, cfgFile);
|
---|
102 | return configurator;
|
---|
103 | }
|
---|
104 |
|
---|
105 | public static GS2CollectionCfg getGS2CollectionCfg(BuildManager manager, String etcDir)
|
---|
106 | {
|
---|
107 | File file = new File(etcDir, "collect.cfg");
|
---|
108 |
|
---|
109 | if (!file.exists()) {
|
---|
110 | return null;
|
---|
111 | }
|
---|
112 |
|
---|
113 | return getGS2CollectionCfg(manager, file);
|
---|
114 | }
|
---|
115 | }
|
---|