BrightSide Workbench Full Report + Source Code
org.turro.wd.entities.AttachWd Class Reference

Static Public Member Functions

static Attachment saveFromFile (File file, String fileName, String fileDate, String path, String user, String comment, boolean lock, boolean validated)
 
static File convertToFile (String path, String fileName, String user, boolean forEditing)
 
static void writeToFile (Attachment attachment, File file)
 
static List< String > queryFolders (String path, String user)
 
static List< ServerFilequeryAttachments (String path, String user)
 
static List< ServerFilequeryVersionedAttachments (String path, String user)
 
static Attachment queryVersionedAttachment (String path, String fileName, String user)
 
static Object unlockFile (String path, String fileName, String user)
 

Detailed Description

Author
Lluis TurrĂ³ Cutiller lluis.nosp@m.@tur.nosp@m.ro.or.nosp@m.g

Definition at line 41 of file AttachWd.java.

Member Function Documentation

◆ convertToFile()

static File org.turro.wd.entities.AttachWd.convertToFile ( String  path,
String  fileName,
String  user,
boolean  forEditing 
)
static

Definition at line 88 of file AttachWd.java.

88  {
89  try {
90  Attachment attachment = queryVersionedAttachment(path, fileName, user);
91  if(forEditing) {
92  if(attachment.isLocked()) return null;
93  attachment.setLocked(true);
94  attachment.setLocker(user);
95  attachment = new AttachPU().saveObject(attachment);
96  }
97  attachment = AttachmentUtil.withContent(attachment);
98  File tempFile = File.createTempFile(AttachWd.class.getName(), null);
99  FileOutputStream outputStream = new FileOutputStream(tempFile);
100  try {
101  ByteArrayInputStream inputStream = new ByteArrayInputStream(attachment.getAttachContent().getFileContent());
102  for(int data = inputStream.read(); data != -1; data = inputStream.read()) {
103  outputStream.write((byte)data);
104  }
105  } finally {
106  outputStream.close();
107  }
108  tempFile.setLastModified(attachment.getModification().getTime());
109  return tempFile;
110  } catch (IOException ex) {
111  Logger.getLogger(AttachWd.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
112  }
113  return null;
114  }
static Attachment queryVersionedAttachment(String path, String fileName, String user)
Definition: AttachWd.java:163
Here is the call graph for this function:
Here is the caller graph for this function:

◆ queryAttachments()

static List<ServerFile> org.turro.wd.entities.AttachWd.queryAttachments ( String  path,
String  user 
)
static

Definition at line 143 of file AttachWd.java.

143  {
144  AttachHeadlessResults results = new AttachHeadlessResults();
145  results.setAttachValue("*");
146  results.setAttachPath(Strings.isEmpty(path) ? "/" : path);
147  results.setCkExactPath(true);
148  return new ServerFileAdapter(results.getAttachmentList());
149  }
Here is the call graph for this function:

◆ queryFolders()

static List<String> org.turro.wd.entities.AttachWd.queryFolders ( String  path,
String  user 
)
static

Definition at line 135 of file AttachWd.java.

135  {
136  AttachHeadlessResults results = new AttachHeadlessResults();
137  results.setAttachValue("*");
138  results.setAttachPath(path + "/_%");
139  results.setCkExactPath(false);
140  return new ArrayList<String>(results.getPathList(path));
141  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ queryVersionedAttachment()

static Attachment org.turro.wd.entities.AttachWd.queryVersionedAttachment ( String  path,
String  fileName,
String  user 
)
static

Definition at line 163 of file AttachWd.java.

163  {
164  AttachHeadlessResults results = new AttachHeadlessResults();
165  results.setAttachValue(fileName);
166  results.setAttachPath(Strings.isEmpty(path) ? "/" : path);
167  results.setCkExactPath(true);
168  AttachVersionMap avm = new AttachVersionMap();
169  for(Attachment a : results.getAttachmentList()) {
170  avm.addAttachment(a);
171  }
172  return avm.isEmpty() ? null : avm.get(fileName).first();
173  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ queryVersionedAttachments()

static List<ServerFile> org.turro.wd.entities.AttachWd.queryVersionedAttachments ( String  path,
String  user 
)
static

Definition at line 151 of file AttachWd.java.

151  {
152  AttachHeadlessResults results = new AttachHeadlessResults();
153  results.setAttachValue("*");
154  results.setAttachPath(Strings.isEmpty(path) ? "/" : path);
155  results.setCkExactPath(true);
156  AttachVersionMap avm = new AttachVersionMap();
157  for(Attachment a : results.getAttachmentList()) {
158  avm.addAttachment(a);
159  }
160  return new ServerFileAdapter(avm.getVersionedAttachments());
161  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ saveFromFile()

static Attachment org.turro.wd.entities.AttachWd.saveFromFile ( File  file,
String  fileName,
String  fileDate,
String  path,
String  user,
String  comment,
boolean  lock,
boolean  validated 
)
static

Definition at line 43 of file AttachWd.java.

44  {
45  InputStream is = null;
46  try {
47  Attachment attachment = new Attachment();
48  attachment.setFileName(fileName);
49  attachment.setModification(WdFormats.parse(fileDate));
50  attachment.setPath(path);
51  attachment.setOwner(user);
52  attachment.setOnlyOwner(false);
53  attachment.setComment(comment);
54  attachment.setShowKey(null);
55  if(lock) {
56  attachment.setLocked(true);
57  attachment.setLocker(user);
58  }
59  AttachContent ac = new AttachContent();
60  byte[] buffer = new byte[102400];
61  is = new FileInputStream(file);
62  ByteArrayOutputStream baos = new ByteArrayOutputStream();
63  int r;
64  while ((r = is.read(buffer)) != -1) {
65  baos.write(buffer, 0, r);
66  }
67  is.close();
68  ac.setFileContent(baos.toByteArray());
69  attachment.setAttachContent(ac);
70  attachment.setFileContentType(WdFormats.getContentType(file));
71  attachment.setFileSize(ac.getFileContent().length);
72  attachment.setValidated(validated);
73  return new AttachPU().saveObject(attachment);
74  } catch (ParseException ex) {
75  Logger.getLogger(AttachWd.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
76  } catch (IOException ex) {
77  Logger.getLogger(AttachWd.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
78  } finally {
79  try {
80  if(is != null) is.close();
81  } catch (IOException ex) {
82  Logger.getLogger(AttachWd.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
83  }
84  }
85  return null;
86  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ unlockFile()

static Object org.turro.wd.entities.AttachWd.unlockFile ( String  path,
String  fileName,
String  user 
)
static

Definition at line 175 of file AttachWd.java.

175  {
176  Attachment attachment = queryVersionedAttachment(path, fileName, user);
177  if(attachment != null && attachment.isLocked()) {
178  attachment.setLocked(false);
179  attachment.setLocker(null);
180  attachment.setLockComment(null);
181  attachment.setLockDate(null);
182  attachment.setLockCommit(null);
183  attachment = new AttachPU().saveObject(attachment);
184  }
185  ServerFile sf = new ServerFile();
186  if(attachment != null) {
187  sf.setFileContentType(attachment.getFileContentType());
188  sf.setFileName(attachment.getFileName());
189  sf.setFileSize(attachment.getFileSize());
190  sf.setLocked(attachment.isLocked());
191  sf.setLocker(attachment.getLocker());
192  sf.setModification(attachment.getModification());
193  sf.setOwner(attachment.getOwner());
194  sf.setPath(attachment.getPath());
195  }
196  return sf;
197  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeToFile()

static void org.turro.wd.entities.AttachWd.writeToFile ( Attachment  attachment,
File  file 
)
static

Definition at line 116 of file AttachWd.java.

116  {
117  try {
118  attachment = AttachmentUtil.withContent(attachment);
119  FileOutputStream outputStream = new FileOutputStream(file);
120  try {
121  ByteArrayInputStream inputStream = new ByteArrayInputStream(attachment.getAttachContent().getFileContent());
122  for(int data = inputStream.read(); data != -1; data = inputStream.read()) {
123  outputStream.write((byte)data);
124  }
125  } finally {
126  outputStream.flush();
127  outputStream.close();
128  }
129  file.setLastModified(attachment.getModification().getTime());
130  } catch (IOException ex) {
131  Logger.getLogger(AttachWd.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
132  }
133  }
Here is the call graph for this function:
Here is the caller graph for this function:

The documentation for this class was generated from the following file: