KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > jcr > impl > storage > filesystem > nodedata > FolderNodeContainer


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5
6 package org.exoplatform.services.jcr.impl.storage.filesystem.nodedata;
7
8
9 import javax.jcr.ItemExistsException;
10 import javax.jcr.RepositoryException;
11 import javax.jcr.Node;
12 import org.exoplatform.services.jcr.core.ItemLocation;
13 import org.exoplatform.services.jcr.core.NodeChange;
14 import org.exoplatform.services.jcr.core.NodeData;
15 import org.exoplatform.services.jcr.impl.core.NodeImpl;
16 import org.exoplatform.services.jcr.storage.Container;
17 import java.io.File JavaDoc;
18 import java.util.ArrayList JavaDoc;
19 import java.util.List JavaDoc;
20
21 /**
22  * Created by The eXo Platform SARL .
23  *
24  * @author <a HREF="mailto:geaz@users.sourceforge.net">Gennady Azarenkov</a>
25  * @version $Id: FolderNodeContainer.java,v 1.15 2004/11/02 18:34:16 geaz Exp $
26  */

27
28 public final class FolderNodeContainer extends BaseNodeContainer {
29
30
31   FolderNodeContainer(String JavaDoc jcrPath, File JavaDoc storage) {
32     super(jcrPath, "nt:folder", storage);
33   }
34
35
36   public NodeData getNodeByPath(String JavaDoc relPath) {
37
38     if (relPath.length() != 0)
39       return null;
40     else
41       return getRootNode();
42
43   }
44
45   public List JavaDoc getChildren(String JavaDoc relPath) {
46 // System.out.println("Folder children '" + relPath + "' " + storage+" "+containerPath);
47
// if (relPath.length() != 0)
48
// return null;
49

50     ArrayList JavaDoc list = new ArrayList JavaDoc();
51
52     File JavaDoc[] cFiles = storage.listFiles();
53     for (int i = 0; i < cFiles.length; i++){
54       try {
55          NodeContainer nodeContainer;
56         String JavaDoc path = new ItemLocation(containerPath, cFiles[i].getName()).getPath();
57 /*
58 // list.add(new NodeImpl(path));
59          if(cFiles[i].isDirectory())
60             nodeContainer = new FolderNodeContainer(path, cFiles[i]);
61          else
62             nodeContainer = new FileNodeContainer(path, cFiles[i]);
63
64          list.add(nodeContainer.getRootNode());
65 */

66          list.add(path);
67       } catch (Exception JavaDoc e) {
68         e.printStackTrace();
69       }
70     }
71     return list;
72   }
73
74   public void add(Node node) throws ItemExistsException, RepositoryException {
75     // just create container (file or folder)
76
// creates by resolver.create
77
}
78
79
80   public final void update(Node node) {
81     // NOOP
82
}
83
84   public final void delete(String JavaDoc absPath) {
85
86 // boolean result = storage.delete();
87
log.debug("FolderNode Container delete node:" + absPath);
88     deleteRecursively(storage);
89   }
90
91   final void deleteRecursively(File JavaDoc file) {
92
93     File JavaDoc[] children = file.listFiles();
94     if(children != null) {
95       for(int i=0; i<children.length; i++) {
96           log.debug("File :" + children[i]+" found for delete.");
97           deleteRecursively(children[i]);
98       }
99     }
100     System.out.println("File exists: " + file.exists());
101     System.out.println("File is file: " + file.isFile());
102     System.out.println("File deleted: " + file.delete());
103 /*
104     boolean result = file.delete();
105     log.debug("FolderNode Container deleted file:" + file + " result: "+result);
106     */

107 // file.deleteOnExit();
108

109   }
110
111 }
112
Popular Tags