01: /*
02: * TransferDirectory.java
03: *
04: * Created on July 9, 2002, 11:15 AM
05: */
06:
07: package com.sun.portal.ffj.util;
08:
09: import java.io.File;
10:
11: import java.util.Vector;
12:
13: /**
14: *
15: * @author yabob
16: */
17: public class TransferClassDirectory extends Transfer {
18:
19: // null subdirectory is taken to mean "root".
20: // null root is taken to mean the root of the current filesystem.
21:
22: public TransferClassDirectory(String root, String sub) {
23: m_Root = root;
24: if (m_Root != null && m_Root.equals("")) {
25: m_Root = null;
26: }
27: m_Sub = sub;
28: }
29:
30: public void addType(String ext) {
31: if (!ext.startsWith(".")) {
32: ext = "." + ext;
33: }
34: m_Ext.add(ext);
35: }
36:
37: public void transfer(File wsroot, String wsdir, File psfs) {
38: File target = new File(psfs, "WEB-INF/classes");
39: copyDir(m_Root == null ? wsroot : new File(m_Root), m_Sub,
40: target);
41: }
42:
43: // Actual recursive descent for file transfer - we have to pass along both the root
44: // and the current subdirectory because we do not create the root part of the file in
45: // the target directory.
46:
47: private void copyDir(File root, String subdir, File target) {
48:
49: // Get the list of files and directories.
50:
51: File f[] = null;
52: if (subdir == null) {
53: f = root.listFiles();
54: } else {
55: File cf = new File(root, subdir);
56: f = cf.listFiles();
57: }
58:
59: if (f == null) {
60: return;
61: }
62:
63: for (int i = 0; i < f.length; ++i) {
64:
65: // Get the name and the new subdirectory or filename relative to root
66:
67: String nm = f[i].getName();
68: String newsub = subdir == null ? nm : subdir
69: + File.separator + nm;
70:
71: // If it's a directory, recursively descend from our same root and
72: // the extended directory.
73:
74: if (f[i].isDirectory()) {
75: copyDir(root, newsub, target);
76: continue;
77: }
78:
79: // An actual file. Look through our extensions, and copy it if it's
80: // one of the ones we're interested in.
81:
82: for (int j = 0; j < m_Ext.size(); ++j) {
83: if (nm.endsWith((String) m_Ext.elementAt(j))) {
84: copy(f[i], new File(target, newsub));
85: break;
86: }
87: }
88: }
89: }
90:
91: private String m_Root;
92: private String m_Sub;
93: private Vector m_Ext = new Vector();
94: }
|