1 | package org.greenstone.gsdl3.gs3build;
|
---|
2 |
|
---|
3 | import java.io.File;
|
---|
4 | import org.greenstone.gsdl3.util.GSFile;
|
---|
5 |
|
---|
6 | public class Create
|
---|
7 | {
|
---|
8 | String gsdl3_home = null;
|
---|
9 | String gsdl3_srchome = null;
|
---|
10 | String site = null;
|
---|
11 | String site_home = null;
|
---|
12 | String collection = null;
|
---|
13 |
|
---|
14 | public Create(String gsdl3_home, String gsdl3_srchome, String site,
|
---|
15 | String collection)
|
---|
16 | {
|
---|
17 | this.gsdl3_home = gsdl3_home;
|
---|
18 | this.gsdl3_srchome = gsdl3_srchome;
|
---|
19 | this.site = site;
|
---|
20 | this.site_home = GSFile.siteHome(gsdl3_home, site);
|
---|
21 | this.collection = collection;
|
---|
22 |
|
---|
23 | // check the site's collect directory
|
---|
24 | File site_collect = new File(GSFile.collectDir(this.site_home));
|
---|
25 | if (!site_collect.isDirectory()) {
|
---|
26 | System.err.println("Site's collect directory "+site_collect.getPath()+" doesn't exist. Please create it and try again");
|
---|
27 | System.exit(1);
|
---|
28 | }
|
---|
29 |
|
---|
30 |
|
---|
31 | }
|
---|
32 |
|
---|
33 | public void makeCollection() {
|
---|
34 |
|
---|
35 | String coll_home = GSFile.collectionBaseDir(this.site_home, this.collection);
|
---|
36 | File coll_dir_file = new File(coll_home);
|
---|
37 | if (coll_dir_file.exists()) {
|
---|
38 | System.err.println("Collection directory ("+coll_dir_file.getPath()+") already exists, not creating it.");
|
---|
39 | System.exit(1);
|
---|
40 | }
|
---|
41 | createDirectory(coll_dir_file);
|
---|
42 | createDirectory(new File(GSFile.collectionImportDir(coll_home)));
|
---|
43 | createDirectory(new File(GSFile.collectionEtcDir(coll_home)));
|
---|
44 |
|
---|
45 | File config_template = new File(gsdl3_srchome + File.separator+ "resources"+File.separator + "xml"+File.separator+"collectionConfig.xml");
|
---|
46 | if (!config_template.isFile()) {
|
---|
47 | System.err.println("Couldn't find the config file template "+config_template.getPath());
|
---|
48 | System.exit(1);
|
---|
49 | }
|
---|
50 |
|
---|
51 | File coll_config = new File(GSFile.collectionConfigFile(coll_home));
|
---|
52 | GSFile.copyFile(config_template, coll_config);
|
---|
53 |
|
---|
54 | System.err.println("New collection created in "+coll_home);
|
---|
55 | System.err.println("Put source documents into import, set the collection's configuration in etc/collectionConfig.xml, then run \"gs3-build.(sh|bat) "+ this.site+" "+this.collection+"\" to build the collection");
|
---|
56 | }
|
---|
57 |
|
---|
58 | protected void createDirectory(File dir) {
|
---|
59 | dir.mkdir();
|
---|
60 | if (!dir.isDirectory()) {
|
---|
61 | System.err.println("Couldn't create directory "+dir.getPath());
|
---|
62 | System.exit(1);
|
---|
63 | }
|
---|
64 | }
|
---|
65 |
|
---|
66 | public static void main(String args[])
|
---|
67 | {
|
---|
68 | String gsdl3_home = System.getProperty("GSDL3HOME");
|
---|
69 | String gsdl3_srchome = System.getProperty("GSDL3SRCHOME");
|
---|
70 | if (gsdl3_home == null) {
|
---|
71 | System.out.println("Error: Unable to locate GSDL3HOME");
|
---|
72 | System.exit(1);
|
---|
73 | }
|
---|
74 | if (gsdl3_srchome == null) {
|
---|
75 | System.out.println("Error: Unable to locate GSDL3SRCHOME");
|
---|
76 | System.exit(1);
|
---|
77 | }
|
---|
78 |
|
---|
79 | int a = 0;
|
---|
80 | String collection = null;
|
---|
81 | String site = null;
|
---|
82 |
|
---|
83 | while (a < args.length) {
|
---|
84 | if (args[a].equals("-collect")) {
|
---|
85 | if (a < args.length - 1 &&
|
---|
86 | args[a+1].charAt(0) != '-') {
|
---|
87 |
|
---|
88 | collection = args[a+1];
|
---|
89 | a ++;
|
---|
90 | }
|
---|
91 | } else if (args[a].equals("-site")) {
|
---|
92 | if (a < args.length - 1 &&
|
---|
93 | args[a+1].charAt(0) != '-') {
|
---|
94 |
|
---|
95 | site = args[a+1];
|
---|
96 | a ++;
|
---|
97 | }
|
---|
98 | }
|
---|
99 | a ++;
|
---|
100 | }
|
---|
101 |
|
---|
102 | if (site == null) {
|
---|
103 |
|
---|
104 | System.err.println("you must specify the site name");
|
---|
105 | System.exit(0);
|
---|
106 | }
|
---|
107 | if (collection == null) {
|
---|
108 | System.err.println("you must specify a collection");
|
---|
109 | System.exit(0);
|
---|
110 | }
|
---|
111 |
|
---|
112 | Create c = new Create(gsdl3_home, gsdl3_srchome, site, collection);
|
---|
113 | c.makeCollection();
|
---|
114 | return;
|
---|
115 | }
|
---|
116 | }
|
---|