001: /**
002: * LibreSource
003: * Copyright (C) 2004-2008 Artenum SARL / INRIA
004: * http://www.libresource.org - contact@artenum.com
005: *
006: * This file is part of the LibreSource software,
007: * which can be used and distributed under license conditions.
008: * The license conditions are provided in the LICENSE.TXT file
009: * at the root path of the packaging that enclose this file.
010: * More information can be found at
011: * - http://dev.libresource.org/home/license
012: *
013: * Initial authors :
014: *
015: * Guillaume Bort / INRIA
016: * Francois Charoy / Universite Nancy 2
017: * Julien Forest / Artenum
018: * Claude Godart / Universite Henry Poincare
019: * Florent Jouille / INRIA
020: * Sebastien Jourdain / INRIA / Artenum
021: * Yves Lerumeur / Artenum
022: * Pascal Molli / Universite Henry Poincare
023: * Gerald Oster / INRIA
024: * Mariarosa Penzi / Artenum
025: * Gerard Sookahet / Artenum
026: * Raphael Tani / INRIA
027: *
028: * Contributors :
029: *
030: * Stephane Bagnier / Artenum
031: * Amadou Dia / Artenum-IUP Blois
032: * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
033: */package org.libresource.so6.core.engine;
034:
035: import org.libresource.so6.core.WsConnection;
036:
037: import java.io.File;
038:
039: import java.util.ArrayList;
040: import java.util.Iterator;
041:
042: /**
043: * @author molli
044: */
045: public class RefCopy {
046: private WsConnection ws;
047: private DBType dbt;
048:
049: public RefCopy(WsConnection ws) {
050: this .ws = ws;
051: dbt = new DBType(ws.getDBTypePath() + File.separator
052: + "refcopy.dbtype", ws.getLastBinExt());
053: }
054:
055: public void patch(String patchfile) throws Exception {
056: PatchFile pf = new PatchFile(patchfile);
057: pf.patch(ws.getRefCopyPath(), dbt);
058: }
059:
060: public DBType getDBType() {
061: return dbt;
062: }
063:
064: private static void walk(String dir, String root, ArrayList result) {
065: File f = new File(dir);
066:
067: if (f.isFile()) {
068: result.add(f.getPath().substring(root.length()).replaceAll(
069: "\\\\", "/"));
070: }
071:
072: if (f.isDirectory()) {
073: if (!(dir.equals(root))) {
074: result.add(f.getPath().substring(root.length())
075: .replaceAll("\\\\", "/"));
076: }
077:
078: String[] entries = f.list();
079:
080: for (int i = 0; i < entries.length; i++) {
081: walk(dir + File.separator + entries[i], root, result);
082: }
083: }
084: }
085:
086: public Iterator getElements() {
087: ArrayList v = new ArrayList();
088: walk(ws.getRefCopyPath() + "/", ws.getRefCopyPath() + "/", v);
089:
090: return v.iterator();
091: }
092:
093: public boolean exists(String path) {
094: File f = new File(ws.getRefCopyPath() + File.separator + path);
095:
096: return f.exists();
097: }
098:
099: public int getType(String path) {
100: return dbt.getType(path);
101: }
102:
103: public String getPath(String path) {
104: return ws.getRefCopyPath() + File.separator + path;
105: }
106:
107: public void build() {
108: }
109: }
|