18 package org.turro.wd.entities;
21 import java.text.ParseException;
22 import java.util.ArrayList;
23 import java.util.List;
24 import java.util.logging.Level;
25 import java.util.logging.Logger;
26 import org.turro.string.Strings;
27 import org.turro.attach.db.AttachPU;
28 import org.turro.attach.entity.AttachContent;
29 import org.turro.attach.entity.Attachment;
30 import org.turro.attach.search.AttachHeadlessResults;
31 import org.turro.attach.version.AttachVersionMap;
32 import org.turro.attach.zul.AttachmentUtil;
33 import org.turro.elephant.context.ElephantContext;
34 import org.turro.wd.common.entities.ServerFile;
35 import org.turro.wd.common.entities.WdFormats;
44 String user, String comment,
boolean lock,
boolean validated) {
45 InputStream is =
null;
60 byte[] buffer =
new byte[102400];
61 is =
new FileInputStream(file);
62 ByteArrayOutputStream baos =
new ByteArrayOutputStream();
64 while ((r = is.read(buffer)) != -1) {
65 baos.write(buffer, 0, r);
73 return new AttachPU().saveObject(attachment);
74 }
catch (ParseException ex) {
76 }
catch (IOException ex) {
80 if(is !=
null) is.close();
81 }
catch (IOException ex) {
88 public static File
convertToFile(String path, String fileName, String user,
boolean forEditing) {
92 if(attachment.
isLocked())
return null;
95 attachment =
new AttachPU().saveObject(attachment);
98 File tempFile = File.createTempFile(
AttachWd.class.getName(),
null);
99 FileOutputStream outputStream =
new FileOutputStream(tempFile);
102 for(
int data = inputStream.read(); data != -1; data = inputStream.read()) {
103 outputStream.write((
byte)data);
106 outputStream.close();
110 }
catch (IOException ex) {
119 FileOutputStream outputStream =
new FileOutputStream(file);
122 for(
int data = inputStream.read(); data != -1; data = inputStream.read()) {
123 outputStream.write((
byte)data);
126 outputStream.flush();
127 outputStream.close();
130 }
catch (IOException ex) {
140 return new ArrayList<String>(results.
getPathList(path));
172 return avm.isEmpty() ? null : avm.get(fileName).first();
175 public static Object
unlockFile(String path, String fileName, String user) {
177 if(attachment !=
null && attachment.
isLocked()) {
183 attachment =
new AttachPU().saveObject(attachment);
186 if(attachment !=
null) {
void setFileContent(byte[] fileContent)
void setOwner(String owner)
void setLockCommit(Date lockCommit)
void setShowKey(String showKey)
void setOnlyOwner(boolean onlyOwner)
void setModification(Date modification)
void setLockDate(Date lockDate)
void setFileSize(long fileSize)
void setLocker(String locker)
void setFileContentType(String fileContentType)
void setLockComment(String lockComment)
void setValidated(boolean validated)
void setComment(String comment)
void setFileName(String fileName)
AttachContent getAttachContent()
String getFileContentType()
void setPath(String path)
void setAttachContent(AttachContent attachContent)
void setLocked(boolean locked)
void setCkExactPath(boolean ckExactPath)
void setAttachValue(String attachValue)
java.util.List< Attachment > getAttachmentList()
void setAttachPath(String attachPath)
java.util.Set< String > getPathList(String currPath)
void addAttachment(Attachment attachment)
Set< Attachment > getVersionedAttachments()
static Attachment withContent(Attachment attachment)
static String logMsg(String msg)
void setFileSize(long fileSize)
void setFileContentType(String fileContentType)
void setLocker(String locker)
void setOwner(String owner)
void setModification(Date modification)
void setLocked(boolean locked)
void setFileName(String fileName)
void setPath(String path)
static List< String > queryFolders(String path, String user)
static List< ServerFile > queryAttachments(String path, String user)
static File convertToFile(String path, String fileName, String user, boolean forEditing)
static Attachment queryVersionedAttachment(String path, String fileName, String user)
static Attachment saveFromFile(File file, String fileName, String fileDate, String path, String user, String comment, boolean lock, boolean validated)
static void writeToFile(Attachment attachment, File file)
static Object unlockFile(String path, String fileName, String user)
static List< ServerFile > queryVersionedAttachments(String path, String user)