18 package org.turro.wd.files;
21 import java.text.ParseException;
22 import java.util.Iterator;
23 import java.util.List;
24 import java.util.logging.Level;
25 import java.util.logging.Logger;
26 import org.apache.pivot.collections.ArrayList;
27 import org.apache.pivot.collections.Collection;
28 import org.apache.pivot.serialization.BinarySerializer;
29 import org.apache.pivot.web.GetQuery;
30 import org.apache.pivot.web.QueryException;
31 import org.jdom.Element;
32 import org.turro.pivot.dialog.ProgressSheet;
33 import org.turro.wd.entities.ServerFile;
39 public class Directory implements Comparable<Directory> {
42 private String serverPath, name;
45 private int nUpdates, nCommits, nFiles;
82 while (current !=
null) {
83 if (current.
getPath() !=
null) {
84 ap = current.
getPath() + (ap ==
null ?
"" :
"/" + ap);
104 this.serverPath = serverPath;
109 .replaceAll(
"\\|",
"-")
110 .replaceAll(
"\\<",
"-")
111 .replaceAll(
"\\>",
"-")
112 .replaceAll(
"\\:",
"-")
113 .replaceAll(
"\"",
"'")
114 .replaceAll(
"\\\\",
"-")
115 .replaceAll(
"\\/",
"-")
116 .replaceAll(
"\\*",
"-")
117 .replaceAll(
"\\&",
"i")
118 .replaceAll(
"\\%",
"-")
119 .replaceAll(
"\\?",
"-");
125 while (current !=
null) {
156 return port ==
null ? 80 :
new Integer(port);
196 wdir.
setName(name ==
null ?
"wdtmp" : name);
204 wfile.
setName(name ==
null ?
"wdtmp" : name);
222 nUpdates = nCommits = nFiles = 0;
225 nUpdates += d.nUpdates;
226 nCommits += d.nCommits;
231 if(wf.isDownloadable()) {
233 }
else if(wf.isUploadable()) {
239 protected void readXML(Element root)
throws ParseException {
240 if (root.getAttributeValue(
"name") !=
null) {
241 setName(root.getAttributeValue(
"name"));
243 if (root.getAttributeValue(
"serverPath") !=
null) {
244 setServerPath(decryptString(root.getAttributeValue(
"serverPath")));
247 for (Element el : (List<Element>) root.getChildren(
"wdir")) {
251 for (Element el : (List<Element>) root.getChildren(
"wfile")) {
260 el =
new Element(
"wdir");
261 el.setAttribute(
"name",
getName());
263 el.setAttribute(
"serverPath", encryptString(
getServerPath()));
282 if (dir !=
null && dir.exists()) {
283 Iterator<Directory> itd =
getDirs().iterator();
284 while (itd.hasNext()) {
285 if (!itd.next().checkExisting()) {
303 for (File file : dir.listFiles()) {
304 if(file.getName().startsWith(
".") ||
305 file.getName().endsWith(
"~") ||
310 if (file.isDirectory()) {
316 }
else if (file.isFile()) {
332 if (!
getDirs().containsDir(folder)) {
340 wf =
addFile(sf.getFileName());
361 GetQuery getQuery =
new GetQuery(
363 getContext() +
"/pservice/queryFolders",
false);
364 getQuery.getParameters().put(
"user",
getUser());
366 getQuery.setSerializer(
new BinarySerializer());
367 return (Collection<String>) getQuery.execute();
368 }
catch (QueryException ex) {
372 return new ArrayList<String>();
378 GetQuery getQuery =
new GetQuery(
380 getContext() +
"/pservice/queryFiles",
false);
381 getQuery.getParameters().put(
"user",
getUser());
383 getQuery.setSerializer(
new BinarySerializer());
384 return (Collection<ServerFile>) getQuery.execute();
385 }
catch (QueryException ex) {
389 return new ArrayList<ServerFile>();
392 private static String encryptString(String str) {
393 StringBuilder sb =
new StringBuilder();
394 for(
byte b : str.getBytes()) {
395 sb.append(String.format(
"%03d", b));
397 return sb.toString();
400 private static String decryptString(String str) {
401 byte[] b =
new byte[str.length() / 3];
402 for(
int i = 0; i < str.length(); i+=3) {
403 b[i / 3] =
new Byte(str.substring(i, i+3));
405 return new String(b);
static void nextProgress(String caption, String step, double inc)
Directory getDir(String dir)
Collection< String > doQueryFolders()
void writeXML(Element root)
Directory addDirectory(String name)
boolean isExistsOnServer()
int compareTo(Directory o)
void setFiles(WorkFileSet files)
WorkFile addFile(String name)
Collection< ServerFile > doQueryFiles()
boolean isWorkingDirectory()
void setDirs(DirectorySet dirs)
void setParent(Directory parent)
void setName(String name)
void readXML(Element root)
void setServerPath(String serverPath)
WorkFile getFile(String file)
void setName(String name)
void readXML(Element root)
void setDownModification(Date downModification)
void setServerLocked(boolean serverLocked)
void setParent(Directory parent)
void setServerLocker(String serverLocker)
void setServerOwner(String serverOwner)
void setServerSize(long serverSize)