|
@@ -1,16 +1,14 @@ |
1 |
1 |
|
/* |
2 |
2 |
|
* Copyright 2010 Daniel Kurka |
3 |
3 |
|
* |
4 |
|
- |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not |
5 |
|
- |
* use this file except in compliance with the License. You may obtain a copy of |
6 |
|
- |
* the License at |
|
4 |
+ |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
|
5 |
+ |
* in compliance with the License. You may obtain a copy of the License at |
7 |
6 |
|
* |
8 |
7 |
|
* http://www.apache.org/licenses/LICENSE-2.0 |
9 |
8 |
|
* |
10 |
|
- |
* Unless required by applicable law or agreed to in writing, software |
11 |
|
- |
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
12 |
|
- |
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
13 |
|
- |
* License for the specific language governing permissions and limitations under |
|
9 |
+ |
* Unless required by applicable law or agreed to in writing, software distributed under the License |
|
10 |
+ |
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
|
11 |
+ |
* or implied. See the License for the specific language governing permissions and limitations under |
14 |
12 |
|
* the License. |
15 |
13 |
|
*/ |
16 |
14 |
|
package com.googlecode.gwtphonegap.client.file.browser; |
|
@@ -27,127 +25,134 @@ |
27 |
25 |
|
import com.googlecode.gwtphonegap.client.file.browser.service.FileSystemController; |
28 |
26 |
|
import com.googlecode.gwtphonegap.collection.shared.LightArray; |
29 |
27 |
|
|
30 |
|
- |
|
31 |
28 |
|
public class DirectoryEntryBrowserImpl implements DirectoryEntry, EntryBase { |
32 |
29 |
|
|
33 |
|
- |
private final FileSystemController controller; |
|
30 |
+ |
private final FileSystemController controller; |
34 |
31 |
|
|
35 |
|
- |
private FileSystemEntryDTO dto; |
|
32 |
+ |
private FileSystemEntryDTO dto; |
36 |
33 |
|
|
37 |
|
- |
public DirectoryEntryBrowserImpl(FileSystemEntryDTO dto, FileSystemController controller) { |
38 |
|
- |
this.controller = controller; |
39 |
|
- |
this.dto = dto; |
40 |
|
- |
} |
41 |
|
- |
|
42 |
|
- |
@Override |
43 |
|
- |
public String getName() { |
44 |
|
- |
return dto.getName(); |
45 |
|
- |
} |
46 |
|
- |
|
47 |
|
- |
@Override |
48 |
|
- |
public String getFullPath() { |
49 |
|
- |
return dto.getFullPath(); |
50 |
|
- |
} |
51 |
|
- |
|
52 |
|
- |
@Override |
53 |
|
- |
public void getMetadata(FileCallback<Metadata, FileError> callback) { |
54 |
|
- |
controller.getMetaData(getFullPath(), callback); |
55 |
|
- |
|
56 |
|
- |
} |
57 |
|
- |
|
58 |
|
- |
@Override |
59 |
|
- |
public void moveTo(DirectoryEntry parent, String newName, FileCallback<DirectoryEntry, FileError> callback) { |
60 |
|
- |
controller.moveDirectory(getFullPath(), parent.getFullPath(), newName, callback); |
61 |
|
- |
} |
62 |
|
- |
|
63 |
|
- |
@Override |
64 |
|
- |
public void copyTo(DirectoryEntry parent, String newName, FileCallback<DirectoryEntry, FileError> callback) { |
65 |
|
- |
controller.copyDirectory(getFullPath(), parent.getFullPath(), newName, callback); |
66 |
|
- |
|
67 |
|
- |
} |
68 |
|
- |
|
69 |
|
- |
@Override |
70 |
|
- |
public String toURI() { |
71 |
|
- |
return controller.toURI(getFullPath()); |
72 |
|
- |
} |
73 |
|
- |
|
74 |
|
- |
@Override |
75 |
|
- |
public void remove(FileCallback<Boolean, FileError> callback) { |
76 |
|
- |
controller.removeDirectory(getFullPath(), callback); |
77 |
|
- |
|
78 |
|
- |
} |
79 |
|
- |
|
80 |
|
- |
@Override |
81 |
|
- |
public void getParent(FileCallback<DirectoryEntry, FileError> callback) { |
82 |
|
- |
|
83 |
|
- |
String fullPath = getFullPath(); |
84 |
|
- |
|
85 |
|
- |
controller.readParent(fullPath, callback); |
86 |
|
- |
|
87 |
|
- |
} |
88 |
|
- |
|
89 |
|
- |
@Override |
90 |
|
- |
public DirectoryReader createReader() { |
91 |
|
- |
return new DirectoryReader() { |
92 |
|
- |
|
93 |
|
- |
@Override |
94 |
|
- |
public void readEntries(final FileCallback<LightArray<EntryBase>, FileError> callback) { |
95 |
|
- |
controller.readDirectory(dto.getFullPath(), callback); |
96 |
|
- |
|
97 |
|
- |
} |
98 |
|
- |
}; |
99 |
|
- |
} |
100 |
|
- |
|
101 |
|
- |
@Override |
102 |
|
- |
public void getDirectory(String path, Flags flags, FileCallback<DirectoryEntry, FileError> callback) { |
103 |
|
- |
String absPath; |
104 |
|
- |
if (path.startsWith("/")) { |
105 |
|
- |
// absolute |
106 |
|
- |
absPath = path; |
107 |
|
- |
} else { |
108 |
|
- |
absPath = getFullPath() + "/" + path; |
109 |
|
- |
} |
110 |
|
- |
controller.getDirectory(absPath, flags, callback); |
111 |
|
- |
|
112 |
|
- |
} |
113 |
|
- |
|
114 |
|
- |
@Override |
115 |
|
- |
public void getFile(String path, Flags flags, FileCallback<FileEntry, FileError> callback) { |
116 |
|
- |
String absPath; |
117 |
|
- |
if (path.startsWith("/")) { |
118 |
|
- |
// absolute |
119 |
|
- |
absPath = path; |
120 |
|
- |
} else { |
121 |
|
- |
absPath = getFullPath() + "/" + path; |
122 |
|
- |
} |
123 |
|
- |
controller.getFile(absPath, flags, callback); |
124 |
|
- |
|
125 |
|
- |
} |
126 |
|
- |
|
127 |
|
- |
@Override |
128 |
|
- |
public void removeRecursively(FileCallback<Boolean, FileError> callback) { |
129 |
|
- |
controller.removeRecursively(getFullPath(), callback); |
130 |
|
- |
|
131 |
|
- |
} |
132 |
|
- |
|
133 |
|
- |
@Override |
134 |
|
- |
public boolean isFile() { |
135 |
|
- |
return false; |
136 |
|
- |
} |
137 |
|
- |
|
138 |
|
- |
@Override |
139 |
|
- |
public boolean isDirectory() { |
140 |
|
- |
return true; |
141 |
|
- |
} |
142 |
|
- |
|
143 |
|
- |
@Override |
144 |
|
- |
public FileEntry getAsFileEntry() { |
145 |
|
- |
throw new RuntimeException(); |
146 |
|
- |
} |
147 |
|
- |
|
148 |
|
- |
@Override |
149 |
|
- |
public DirectoryEntry getAsDirectoryEntry() { |
150 |
|
- |
return this; |
151 |
|
- |
} |
|
34 |
+ |
public DirectoryEntryBrowserImpl(FileSystemEntryDTO dto, FileSystemController controller) { |
|
35 |
+ |
this.controller = controller; |
|
36 |
+ |
this.dto = dto; |
|
37 |
+ |
} |
|
38 |
+ |
|
|
39 |
+ |
@Override |
|
40 |
+ |
public String getName() { |
|
41 |
+ |
return dto.getName(); |
|
42 |
+ |
} |
|
43 |
+ |
|
|
44 |
+ |
@Override |
|
45 |
+ |
public String getFullPath() { |
|
46 |
+ |
return dto.getFullPath(); |
|
47 |
+ |
} |
|
48 |
+ |
|
|
49 |
+ |
@Override |
|
50 |
+ |
public void getMetadata(FileCallback<Metadata, FileError> callback) { |
|
51 |
+ |
controller.getMetaData(getFullPath(), callback); |
|
52 |
+ |
|
|
53 |
+ |
} |
|
54 |
+ |
|
|
55 |
+ |
@Override |
|
56 |
+ |
public void moveTo(DirectoryEntry parent, String newName, |
|
57 |
+ |
FileCallback<DirectoryEntry, FileError> callback) { |
|
58 |
+ |
controller.moveDirectory(getFullPath(), parent.getFullPath(), newName, callback); |
|
59 |
+ |
} |
|
60 |
+ |
|
|
61 |
+ |
@Override |
|
62 |
+ |
public void copyTo(DirectoryEntry parent, String newName, |
|
63 |
+ |
FileCallback<DirectoryEntry, FileError> callback) { |
|
64 |
+ |
controller.copyDirectory(getFullPath(), parent.getFullPath(), newName, callback); |
|
65 |
+ |
|
|
66 |
+ |
} |
|
67 |
+ |
|
|
68 |
+ |
@Override |
|
69 |
+ |
public String toURI() { |
|
70 |
+ |
return controller.toURI(getFullPath()); |
|
71 |
+ |
} |
|
72 |
+ |
|
|
73 |
+ |
@Override |
|
74 |
+ |
public void remove(FileCallback<Boolean, FileError> callback) { |
|
75 |
+ |
controller.removeDirectory(getFullPath(), callback); |
|
76 |
+ |
|
|
77 |
+ |
} |
|
78 |
+ |
|
|
79 |
+ |
@Override |
|
80 |
+ |
public void getParent(FileCallback<DirectoryEntry, FileError> callback) { |
|
81 |
+ |
|
|
82 |
+ |
String fullPath = getFullPath(); |
|
83 |
+ |
|
|
84 |
+ |
controller.readParent(fullPath, callback); |
|
85 |
+ |
|
|
86 |
+ |
} |
|
87 |
+ |
|
|
88 |
+ |
@Override |
|
89 |
+ |
public DirectoryReader createReader() { |
|
90 |
+ |
return new DirectoryReader() { |
|
91 |
+ |
|
|
92 |
+ |
@Override |
|
93 |
+ |
public void readEntries(final FileCallback<LightArray<EntryBase>, FileError> callback) { |
|
94 |
+ |
controller.readDirectory(dto.getFullPath(), callback); |
|
95 |
+ |
|
|
96 |
+ |
} |
|
97 |
+ |
}; |
|
98 |
+ |
} |
|
99 |
+ |
|
|
100 |
+ |
@Override |
|
101 |
+ |
public void getDirectory(String path, Flags flags, |
|
102 |
+ |
FileCallback<DirectoryEntry, FileError> callback) { |
|
103 |
+ |
String absPath; |
|
104 |
+ |
if (path.startsWith("/")) { |
|
105 |
+ |
// absolute |
|
106 |
+ |
absPath = path; |
|
107 |
+ |
} else { |
|
108 |
+ |
absPath = getFullPath() + "/" + path; |
|
109 |
+ |
} |
|
110 |
+ |
controller.getDirectory(absPath, flags, callback); |
|
111 |
+ |
|
|
112 |
+ |
} |
|
113 |
+ |
|
|
114 |
+ |
@Override |
|
115 |
+ |
public void getFile(String path, Flags flags, FileCallback<FileEntry, FileError> callback) { |
|
116 |
+ |
String absPath; |
|
117 |
+ |
if (path.startsWith("/")) { |
|
118 |
+ |
// absolute |
|
119 |
+ |
absPath = path; |
|
120 |
+ |
} else { |
|
121 |
+ |
absPath = getFullPath() + "/" + path; |
|
122 |
+ |
} |
|
123 |
+ |
controller.getFile(absPath, flags, callback); |
|
124 |
+ |
|
|
125 |
+ |
} |
|
126 |
+ |
|
|
127 |
+ |
@Override |
|
128 |
+ |
public void removeRecursively(FileCallback<Boolean, FileError> callback) { |
|
129 |
+ |
controller.removeRecursively(getFullPath(), callback); |
|
130 |
+ |
|
|
131 |
+ |
} |
|
132 |
+ |
|
|
133 |
+ |
@Override |
|
134 |
+ |
public boolean isFile() { |
|
135 |
+ |
return false; |
|
136 |
+ |
} |
|
137 |
+ |
|
|
138 |
+ |
@Override |
|
139 |
+ |
public boolean isDirectory() { |
|
140 |
+ |
return true; |
|
141 |
+ |
} |
|
142 |
+ |
|
|
143 |
+ |
@Override |
|
144 |
+ |
public FileEntry getAsFileEntry() { |
|
145 |
+ |
throw new RuntimeException(); |
|
146 |
+ |
} |
|
147 |
+ |
|
|
148 |
+ |
@Override |
|
149 |
+ |
public DirectoryEntry getAsDirectoryEntry() { |
|
150 |
+ |
return this; |
|
151 |
+ |
} |
|
152 |
+ |
|
|
153 |
+ |
@Override |
|
154 |
+ |
public String toURL() { |
|
155 |
+ |
return controller.toURI(getFullPath()); |
|
156 |
+ |
} |
152 |
157 |
|
|
153 |
158 |
|
} |