001: /*
002: * Copyright 2004 Outerthought bvba and Schaubroeck nv
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.outerj.daisy.backupTool;
017:
018: import java.io.File;
019: import java.util.Properties;
020:
021: import org.outerj.daisy.backupTool.dbDump.DbDumper;
022: import org.outerj.daisy.backupTool.dbDump.DbDumperFactory;
023: import org.outerj.daisy.configutil.PropertyResolver;
024: import org.w3c.dom.Document;
025: import org.w3c.dom.Element;
026:
027: public class DaisyEntryLoader extends AbstractEntryLoader {
028: private static String XPATH_INDEX_DIR = "/targets/target[@path = '/daisy/repository/fullTextIndex']/configuration/indexDirectory";
029: private static String XPATH_BLOB_DIR = "/targets/target[@path = '/daisy/repository/blobstore']/configuration/directory";
030: private static String XPATH_PUBREQ_DIR = "/targets/target[@path = '/daisy/extensions/publisher/publisher']/configuration/publisherRequestDirectory";
031: private Properties resolveProps;
032:
033: public DaisyEntryLoader(File myConfigFile, File datadir)
034: throws Exception {
035: super (myConfigFile);
036: resolveProps = new Properties(System.getProperties());
037: resolveProps.setProperty("daisy.datadir", datadir
038: .getAbsolutePath());
039: }
040:
041: public void createEntries(BackupInstance buInstance)
042: throws Exception {
043:
044: Element dbConfigElement = BackupHelper
045: .getElementFromDom(configDocument,
046: "/targets/target[@path = '/daisy/datasource/datasource']/configuration");
047:
048: DbDumper dbDumper = DbDumperFactory.createDbDumper(BackupHelper
049: .getStringFromDom(dbConfigElement, "url"), BackupHelper
050: .getStringFromDom(dbConfigElement, "username"),
051: BackupHelper.getStringFromDom(dbConfigElement,
052: "password"));
053:
054: File indexStoreDir = new File(
055: resolve(BackupHelper.getStringFromDom(
056: this .configDocument, XPATH_INDEX_DIR)));
057: File blobStoreDir = new File(resolve(BackupHelper
058: .getStringFromDom(this .configDocument, XPATH_BLOB_DIR)));
059: File pubReqDir = new File(
060: resolve(BackupHelper.getStringFromDom(
061: this .configDocument, XPATH_PUBREQ_DIR)));
062: File confDir = new File(blobStoreDir.getParentFile(), "conf");
063: File serviceDir = new File(blobStoreDir.getParentFile(),
064: "service");
065:
066: buInstance.addEntry(createDbEntry(buInstance, dbDumper,
067: "daisy-dbDump.zip"));
068: buInstance.addEntry(createFileEntry(buInstance, indexStoreDir,
069: indexStoreDir, "daisy-indexstore.zip"));
070: buInstance.addEntry(createFileEntry(buInstance, blobStoreDir,
071: blobStoreDir, "daisy-blobstore.zip"));
072: buInstance.addEntry(createFileEntry(buInstance, pubReqDir,
073: pubReqDir, "daisy-pubreq.zip"));
074: buInstance.addEntry(createFileEntry(buInstance, confDir,
075: confDir, "daisy-conf.zip"));
076: buInstance.addEntry(createFileEntry(buInstance, serviceDir,
077: serviceDir, "daisy-service.zip"));
078: }
079:
080: private String resolve(String value) {
081: // to resolve property references such as ${daisy.datadir}
082: return PropertyResolver.resolveProperties(value, resolveProps);
083: }
084:
085: public void reloadEntries(BackupInstance buInstance,
086: boolean checkHashSums) throws Exception {
087: String[] entries = new String[] { "daisy-dbDump.zip",
088: "daisy-conf.zip" };
089: if (areFilesBackedUp(buInstance, entries, checkHashSums)) {
090: File oldConfFile = configFile;
091: File confTemp = new File(buInstance.getDirectory(),
092: "confTemp");
093: Document oldConfDocument = configDocument;
094:
095: BackupHelper.unzipToDirectory(new File(buInstance
096: .getDirectory(), "daisy-conf.zip"), confTemp);
097: configFile = new File(confTemp, "myconfig.xml");
098: configDocument = BackupHelper.parseFile(configFile);
099:
100: createEntries(buInstance);
101: BackupHelper.deleteFile(confTemp);
102: configFile = oldConfFile;
103: configDocument = oldConfDocument;
104: } else {
105: System.out
106: .println("Daisy backup files were not found. Skipping restore of daisy");
107: }
108: }
109: }
|