18 package org.turro.wd.files;
21 import java.io.FileOutputStream;
22 import java.io.IOException;
23 import java.io.OutputStream;
24 import java.text.ParseException;
25 import java.util.Date;
26 import java.util.logging.Level;
27 import java.util.logging.Logger;
28 import org.apache.pivot.io.FileSerializer;
29 import org.apache.pivot.serialization.BinarySerializer;
30 import org.apache.pivot.serialization.SerializationException;
31 import org.apache.pivot.web.GetQuery;
32 import org.apache.pivot.web.PostQuery;
33 import org.apache.pivot.web.QueryException;
34 import org.jdom.Element;
35 import org.turro.wd.entities.WdFormats;
36 import org.turro.wd.tree.SyncTask;
42 public class WorkFile implements Comparable<WorkFile> {
45 private String name, serverOwner, serverOwnerName, serverLocker;
46 private Date downModification;
47 private long serverSize;
49 private boolean serverLocked =
false;
52 return downModification;
56 this.downModification = downModification;
88 this.serverLocked = serverLocked;
96 this.serverLocker = serverLocker;
104 this.serverOwner = serverOwner;
108 return serverOwnerName;
112 this.serverOwnerName = serverOwnerName;
120 this.serverSize = serverSize;
151 public void readXML(Element root)
throws ParseException {
152 if(root.getAttributeValue(
"name") !=
null)
153 setName(root.getAttributeValue(
"name"));
157 Element el =
new Element(
"wfile");
158 el.setAttribute(
"name",
getName());
173 public void doUpload(String comment,
int commitAction) {
176 PostQuery postQuery =
new PostQuery(
178 parent.
getContext() +
"/pservice/upload",
false);
179 postQuery.getParameters().put(
"user", parent.
getUser());
181 postQuery.getParameters().put(
"fileName",
getName());
182 postQuery.getParameters().put(
"fileDate",
WdFormats.
format(file.lastModified()));
183 postQuery.getParameters().put(
"comment", comment);
184 postQuery.getParameters().put(
"lock",
186 postQuery.setSerializer(
new FileSerializer());
187 postQuery.setValue(file);
189 }
catch (ParseException ex) {
190 Logger.getLogger(
WorkFile.class.
getName()).log(Level.SEVERE,
null, ex);
191 }
catch (QueryException ex) {
192 Logger.getLogger(
WorkFile.class.
getName()).log(Level.SEVERE,
null, ex);
200 GetQuery getQuery =
new GetQuery(
202 parent.
getContext() +
"/pservice/download",
false);
203 getQuery.getParameters().put(
"user", parent.
getUser());
204 getQuery.getParameters().put(
"forEditing",
205 (updateAction ==
SyncTask.UPDATE_UPDATE_FOR_EDITING) ?
"true" :
"false");
207 getQuery.getParameters().put(
"fileName",
getName());
208 getQuery.setSerializer(
new FileSerializer());
209 File receivedFile = (File) getQuery.execute();
212 OutputStream os =
new FileOutputStream(saveFile);
213 ((FileSerializer) getQuery.getSerializer())
214 .writeObject(receivedFile, os);
216 saveFile.setLastModified(downModification.getTime());
217 }
catch (ParseException ex) {
218 Logger.getLogger(
WorkFile.class.
getName()).log(Level.SEVERE,
null, ex);
219 }
catch (IOException ex) {
220 Logger.getLogger(
WorkFile.class.
getName()).log(Level.SEVERE,
null, ex);
221 }
catch (SerializationException ex) {
222 Logger.getLogger(
WorkFile.class.
getName()).log(Level.SEVERE,
null, ex);
223 }
catch (QueryException ex) {
224 Logger.getLogger(
WorkFile.class.
getName()).log(Level.SEVERE,
null, ex);
230 GetQuery getQuery =
new GetQuery(
232 parent.
getContext() +
"/pservice/unlock",
false);
233 getQuery.getParameters().put(
"user", parent.
getUser());
235 getQuery.getParameters().put(
"fileName",
getName());
236 getQuery.setSerializer(
new BinarySerializer());
238 }
catch (QueryException ex) {
boolean isExistsOnServer()
void setName(String name)
void readXML(Element root)
void setDownModification(Date downModification)
void setServerLocked(boolean serverLocked)
void doDownload(int updateAction)
void setParent(Directory parent)
void setServerLocker(String serverLocker)
void setServerOwner(String serverOwner)
void doUpload(String comment, int commitAction)
String getServerOwnerName()
void setServerOwnerName(String serverOwnerName)
void writeXML(Element root)
void setServerSize(long serverSize)
Date getDownModification()
int compareTo(WorkFile o)
static final int UPDATE_DO_NOTHING