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