Subversion Repositories XServices

Rev

Rev 116 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 116 Rev 147
Line 15... Line 15...
15
 */
15
 */
Line 16... Line 16...
16
 
16
 
Line 17... Line 17...
17
package net.brutex.xservices.types;
17
package net.brutex.xservices.types;
-
 
18
 
-
 
19
import java.io.File;
-
 
20
import java.io.IOException;
-
 
21
import java.io.UnsupportedEncodingException;
-
 
22
import java.net.URI;
-
 
23
import java.net.URLEncoder;
-
 
24
import java.nio.file.FileSystems;
-
 
25
import java.nio.file.Files;
-
 
26
import java.nio.file.LinkOption;
-
 
27
import java.nio.file.Path;
-
 
28
import java.nio.file.attribute.BasicFileAttributeView;
-
 
29
import java.nio.file.attribute.BasicFileAttributes;
-
 
30
import java.nio.file.attribute.DosFileAttributeView;
-
 
31
import java.nio.file.attribute.DosFileAttributes;
-
 
32
import java.nio.file.attribute.FileTime;
-
 
33
import java.nio.file.attribute.PosixFileAttributeView;
-
 
34
import java.nio.file.attribute.PosixFileAttributes;
-
 
35
import java.nio.file.attribute.UserPrincipal;
-
 
36
import java.util.GregorianCalendar;
-
 
37
 
-
 
38
import javax.xml.bind.annotation.XmlAccessType;
18
 
39
import javax.xml.bind.annotation.XmlAccessorOrder;
19
import java.io.File;
40
import javax.xml.bind.annotation.XmlAccessorType;
-
 
41
import javax.xml.bind.annotation.XmlElement;
-
 
42
import javax.xml.bind.annotation.XmlRootElement;
-
 
43
import javax.xml.bind.annotation.XmlType;
20
import javax.xml.bind.annotation.XmlElement;
44
 
21
import javax.xml.bind.annotation.XmlRootElement;
45
import com.sun.xml.bind.XmlAccessorFactory;
22
/**
46
/**
23
 * @author Brian Rosenberger, bru(at)brutex.de
47
 * @author Brian Rosenberger, bru(at)brutex.de
Line 24... Line 48...
24
 *
48
 *
-
 
49
 */
-
 
50
 
-
 
51
 
25
 */
52
 
26
 
53
@XmlRootElement
27
 
54
@XmlType(propOrder={"name", "path", "filesize", "owner", "lastModifiedDate", "createdDate", "lastAccessDate", "mimeType", 
28
 
55
					"readonly", "hidden", "directory", "symbolicLink", "archive", "system", "downloadUrl"})
29
@XmlRootElement
56
@XmlAccessorType(XmlAccessType.PROPERTY)
-
 
57
public class FileInfoType
30
public class FileInfoType
58
{
31
{
59
  private String name;
-
 
60
  private String path;
-
 
61
  private long filesize;
-
 
62
  private boolean isReadonly;
-
 
63
  private boolean isHidden;
-
 
64
  private boolean isDirectory;
-
 
65
  private boolean isSymbolicLink;
-
 
66
  private boolean isArchive;
-
 
67
  private boolean isSystem;
-
 
68
  private GregorianCalendar lastModifiedDate;
-
 
69
  private GregorianCalendar createdDate;
Line 32... Line 70...
32
  private String name;
70
  private GregorianCalendar lastAccessDate;
33
  private String path;
71
  private String owner;
34
  private long filesize;
72
  private String mimeType;
35
  private boolean canWrite;
73
  private URI downloadUrl;
36
  private boolean isDirectory;
74
  
-
 
75
 
-
 
76
  public FileInfoType()
-
 
77
  {
-
 
78
  }
-
 
79
  
-
 
80
  public FileInfoType(Path p) throws IOException {
-
 
81
	  	this.name = p.getFileName().toString();
-
 
82
	    this.path = p.toAbsolutePath().toString().replace('\\', '/');
-
 
83
 
-
 
84
	  
-
 
85
		BasicFileAttributeView basicView = Files.getFileAttributeView(p, BasicFileAttributeView.class);
-
 
86
		BasicFileAttributes basic;
-
 
87
		basic = basicView.readAttributes();
-
 
88
		
-
 
89
		this.isDirectory = basic.isDirectory();
-
 
90
		this.isSymbolicLink = basic.isSymbolicLink();
-
 
91
		this.filesize = basic.size();
-
 
92
		this.lastModifiedDate = (GregorianCalendar) GregorianCalendar.getInstance();
-
 
93
		this.lastModifiedDate.setTimeInMillis(basic.lastModifiedTime().toMillis());
-
 
94
		this.createdDate = (GregorianCalendar) GregorianCalendar.getInstance();
-
 
95
		this.createdDate.setTimeInMillis(basic.creationTime().toMillis());
-
 
96
		this.lastAccessDate = (GregorianCalendar) GregorianCalendar.getInstance();
-
 
97
		this.lastAccessDate.setTimeInMillis(basic.lastAccessTime().toMillis());
-
 
98
		
-
 
99
		// Try to set the Mime Type for that file
37
 
100
		// or default to octet-stream
-
 
101
		if(!isDirectory) {
-
 
102
			this.mimeType = Files.probeContentType(p);
38
  public FileInfoType()
103
			if(this.mimeType==null) mimeType = "application/octet-stream";
-
 
104
		} else {
-
 
105
			this.mimeType = null;
-
 
106
		}
-
 
107
		
39
  {
108
		// Set the file/ directory owner
-
 
109
		this.owner = Files.getOwner(p).getName();
40
  }
110
		
41
 
111
		//Dos specific Attributes
42
  public FileInfoType(File file)
112
		DosFileAttributeView dosView = Files.getFileAttributeView(p, DosFileAttributeView.class);
-
 
113
		if(dosView != null) {
-
 
114
			DosFileAttributes dos = dosView.readAttributes();
-
 
115
			this.isReadonly = dos.isReadOnly();
-
 
116
			this.isHidden = dos.isHidden();
-
 
117
			this.isArchive = dos.isArchive();
-
 
118
			this.isSystem = dos.isSystem();
-
 
119
		}
-
 
120
		
-
 
121
		//POSIX specific Attributes
-
 
122
		PosixFileAttributeView posixView = Files.getFileAttributeView(p, PosixFileAttributeView.class);
-
 
123
		if(posixView != null) {
-
 
124
			PosixFileAttributes posix = posixView.readAttributes();
-
 
125
			//TODO: Unix specific file attributes
-
 
126
		}
-
 
127
		
-
 
128
  }
-
 
129
 
-
 
130
  
-
 
131
  public FileInfoType(Path file, URI downloadURL) throws IOException {
-
 
132
	  this(file);
43
  {
133
	  try {
Line -... Line 134...
-
 
134
		this.downloadUrl = URI.create(downloadURL+URLEncoder.encode(this.path, "UTF-8"));
-
 
135
	} catch (UnsupportedEncodingException e) {
-
 
136
		// TODO Auto-generated catch block
44
    this.name = file.getName();
137
		e.printStackTrace();
45
    this.path = file.getAbsolutePath().replace('\\', '/');
138
	}
46
    this.canWrite = file.canWrite();
-
 
47
    this.filesize = file.length();
139
  }
48
    this.isDirectory = file.isDirectory();
140
 
Line -... Line 141...
-
 
141
/**
49
  }
142
 * @return the name
50
 
143
 */
51
  @XmlElement(name="name")
144
  @XmlElement(name="name")
-
 
145
public String getName() {
-
 
146
	return name;
52
  public String getName()
147
}
Line -... Line 148...
-
 
148
 
-
 
149
/**
-
 
150
 * @return the path
53
  {
151
 */
54
    return this.name;
152
	@XmlElement(name = "path")
55
  }
-
 
56
 
153
public String getPath() {
57
  public void setName(String name)
154
	return path;
Line -... Line 155...
-
 
155
}
58
  {
156
 
59
    this.name = name;
157
/**
-
 
158
 * @return the filesize
-
 
159
 */
60
  }
160
@XmlElement(name="filesize")
61
 
161
public long getFilesize() {
Line -... Line 162...
-
 
162
	return filesize;
-
 
163
}
-
 
164
 
62
  @XmlElement(name="path")
165
/**
63
  public String getPath()
166
 * @return the isReadonly
64
  {
-
 
65
    return this.path;
167
 */
66
  }
168
@XmlElement(name="isReadonly")
Line -... Line 169...
-
 
169
public boolean isReadonly() {
67
 
170
	return isReadonly;
68
  public void setPath(String path)
171
}
-
 
172
 
69
  {
173
/**
-
 
174
 * @return the isHidden
70
    this.path = path;
175
 */
Line -... Line 176...
-
 
176
@XmlElement(name="isHidden")
-
 
177
public boolean isHidden() {
-
 
178
	return isHidden;
71
  }
179
}
72
 
180
 
73
  @XmlElement(name="size")
-
 
74
  public long getFilesize()
181
/**
75
  {
182
 * @return the isDirectory
Line -... Line 183...
-
 
183
 */
-
 
184
@XmlElement(name="isDirectory")
-
 
185
public boolean isDirectory() {
76
    return this.filesize;
186
	return isDirectory;
77
  }
187
}
-
 
188
 
-
 
189
/**
-
 
190
 * @return the isSymbolicLink
-
 
191
 */
-
 
192
@XmlElement(name="isSymbolicLink")
-
 
193
public boolean isSymbolicLink() {
-
 
194
	return isSymbolicLink;
-
 
195
}
-
 
196
 
-
 
197
/**
-
 
198
 * @return the isArchive
-
 
199
 */
-
 
200
@XmlElement(name="isArchive")
-
 
201
public boolean isArchive() {
-
 
202
	return isArchive;
-
 
203
}
-
 
204
 
-
 
205
/**
-
 
206
 * @return the isSystem
-
 
207
 */
-
 
208
@XmlElement(name="isSystem")
78
 
209
public boolean isSystem() {
-
 
210
	return isSystem;
-
 
211
}
-
 
212
 
-
 
213
/**
-
 
214
 * @return the lastModifiedDate
-
 
215
 */
79
  public void setFilesize(long filesize)
216
@XmlElement(name="lastModifiedDate")
-
 
217
public GregorianCalendar getLastModifiedDate() {
-
 
218
	return lastModifiedDate;
-
 
219
}
-
 
220
 
-
 
221
/**
-
 
222
 * @return the createdDate
-
 
223
 */
-
 
224
@XmlElement(name="createdDate")
-
 
225
public GregorianCalendar getCreatedDate() {
-
 
226
	return createdDate;
-
 
227
}
-
 
228
 
-
 
229
/**
-
 
230
 * @return the lastAccessDate
-
 
231
 */
-
 
232
@XmlElement(name="lastAccessDate")
-
 
233
public GregorianCalendar getLastAccessDate() {
-
 
234
	return lastAccessDate;
-
 
235
}
-
 
236
 
-
 
237
/**
-
 
238
 * @return the owner
-
 
239
 */
-
 
240
@XmlElement(name="owner")
80
  {
241
public String getOwner() {
-
 
242
	return owner;
-
 
243
}
-
 
244
 
-
 
245
/**
-
 
246
 * @return the mimeType
-
 
247
 */
81
    this.filesize = filesize;
248
@XmlElement(name="mimeType")
82
  }
249
public String getMimeType() {