KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > backupTool > DaisyEntryLoader


1 /*
2  * Copyright 2004 Outerthought bvba and Schaubroeck nv
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.outerj.daisy.backupTool;
17
18 import java.io.File JavaDoc;
19 import java.util.Properties JavaDoc;
20
21 import org.outerj.daisy.backupTool.dbDump.DbDumper;
22 import org.outerj.daisy.backupTool.dbDump.DbDumperFactory;
23 import org.outerj.daisy.configutil.PropertyResolver;
24 import org.w3c.dom.Document JavaDoc;
25 import org.w3c.dom.Element JavaDoc;
26
27 public class DaisyEntryLoader extends AbstractEntryLoader {
28     private static String JavaDoc XPATH_INDEX_DIR = "/targets/target[@path = '/daisy/repository/fullTextIndex']/configuration/indexDirectory";
29     private static String JavaDoc XPATH_BLOB_DIR = "/targets/target[@path = '/daisy/repository/blobstore']/configuration/directory";
30     private static String JavaDoc XPATH_PUBREQ_DIR = "/targets/target[@path = '/daisy/extensions/publisher/publisher']/configuration/publisherRequestDirectory";
31     private Properties JavaDoc resolveProps;
32
33     public DaisyEntryLoader(File JavaDoc myConfigFile, File JavaDoc datadir) throws Exception JavaDoc {
34         super(myConfigFile);
35         resolveProps = new Properties JavaDoc(System.getProperties());
36         resolveProps.setProperty("daisy.datadir", datadir.getAbsolutePath());
37     }
38
39     public void createEntries(BackupInstance buInstance) throws Exception JavaDoc {
40
41         Element JavaDoc dbConfigElement = BackupHelper.getElementFromDom(configDocument, "/targets/target[@path = '/daisy/datasource/datasource']/configuration");
42
43         DbDumper dbDumper = DbDumperFactory.createDbDumper(BackupHelper.getStringFromDom(dbConfigElement, "url"), BackupHelper.getStringFromDom(
44                 dbConfigElement, "username"), BackupHelper.getStringFromDom(dbConfigElement, "password"));
45
46         File JavaDoc indexStoreDir = new File JavaDoc(resolve(BackupHelper.getStringFromDom(this.configDocument, XPATH_INDEX_DIR)));
47         File JavaDoc blobStoreDir = new File JavaDoc(resolve(BackupHelper.getStringFromDom(this.configDocument, XPATH_BLOB_DIR)));
48         File JavaDoc pubReqDir = new File JavaDoc(resolve(BackupHelper.getStringFromDom(this.configDocument, XPATH_PUBREQ_DIR)));
49         File JavaDoc confDir = new File JavaDoc(blobStoreDir.getParentFile(), "conf");
50         
51
52         buInstance.addEntry(createDbEntry(buInstance, dbDumper, "daisy-dbDump.zip"));
53         buInstance.addEntry(createFileEntry(buInstance, indexStoreDir, indexStoreDir, "daisy-indexstore.zip"));
54         buInstance.addEntry(createFileEntry(buInstance, blobStoreDir, blobStoreDir, "daisy-blobstore.zip"));
55         buInstance.addEntry(createFileEntry(buInstance, pubReqDir, pubReqDir, "daisy-pubreq.zip"));
56         buInstance.addEntry(createFileEntry(buInstance, confDir, confDir, "daisy-conf.zip"));
57     }
58
59     private String JavaDoc resolve(String JavaDoc value) {
60         // to resolve property references such as ${daisy.datadir}
61
return PropertyResolver.resolveProperties(value, resolveProps);
62     }
63
64     public void reloadEntries(BackupInstance buInstance) throws Exception JavaDoc {
65         String JavaDoc[] entries = new String JavaDoc[] { "daisy-dbDump.zip", "daisy-conf.zip" };
66         if (areFilesBackedUp(buInstance, entries)) {
67             File JavaDoc oldConfFile = configFile;
68             File JavaDoc confTemp = new File JavaDoc(buInstance.getDirectory(), "confTemp");
69             Document JavaDoc oldConfDocument = configDocument;
70
71             BackupHelper.unzipToDirectory(new File JavaDoc(buInstance.getDirectory(), "daisy-conf.zip"), confTemp);
72             configFile = new File JavaDoc(confTemp, "myconfig.xml");
73             configDocument = BackupHelper.parseFile(configFile);
74
75             createEntries(buInstance);
76             BackupHelper.deleteFile(confTemp);
77             configFile = oldConfFile;
78             configDocument = oldConfDocument;
79         } else {
80             System.out.println("Daisy backup files were not found. Skipping restore of daisy");
81         }
82     }
83 }
84
Popular Tags