Subversion Repositories XServices

Rev

Rev 147 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 147 Rev 182
1
/*
1
/*
2
 *   Copyright 2013 Brian Rosenberger (Brutex Network)
2
 *   Copyright 2013 Brian Rosenberger (Brutex Network)
3
 *
3
 *
4
 *   Licensed under the Apache License, Version 2.0 (the "License");
4
 *   Licensed under the Apache License, Version 2.0 (the "License");
5
 *   you may not use this file except in compliance with the License.
5
 *   you may not use this file except in compliance with the License.
6
 *   You may obtain a copy of the License at
6
 *   You may obtain a copy of the License at
7
 *
7
 *
8
 *       http://www.apache.org/licenses/LICENSE-2.0
8
 *       http://www.apache.org/licenses/LICENSE-2.0
9
 *
9
 *
10
 *   Unless required by applicable law or agreed to in writing, software
10
 *   Unless required by applicable law or agreed to in writing, software
11
 *   distributed under the License is distributed on an "AS IS" BASIS,
11
 *   distributed under the License is distributed on an "AS IS" BASIS,
12
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 *   See the License for the specific language governing permissions and
13
 *   See the License for the specific language governing permissions and
14
 *   limitations under the License.
14
 *   limitations under the License.
15
 */
15
 */
16
 
16
 
17
package net.brutex.xservices.types;
17
package net.brutex.xservices.types;
18
 
18
 
19
import java.io.File;
19
import java.io.File;
20
import java.io.IOException;
20
import java.io.IOException;
21
import java.io.UnsupportedEncodingException;
21
import java.io.UnsupportedEncodingException;
22
import java.net.URI;
22
import java.net.URI;
23
import java.net.URLEncoder;
23
import java.net.URLEncoder;
24
import java.nio.file.FileSystems;
24
import java.nio.file.FileSystems;
25
import java.nio.file.Files;
25
import java.nio.file.Files;
26
import java.nio.file.LinkOption;
26
import java.nio.file.LinkOption;
27
import java.nio.file.Path;
27
import java.nio.file.Path;
28
import java.nio.file.attribute.BasicFileAttributeView;
28
import java.nio.file.attribute.BasicFileAttributeView;
29
import java.nio.file.attribute.BasicFileAttributes;
29
import java.nio.file.attribute.BasicFileAttributes;
30
import java.nio.file.attribute.DosFileAttributeView;
30
import java.nio.file.attribute.DosFileAttributeView;
31
import java.nio.file.attribute.DosFileAttributes;
31
import java.nio.file.attribute.DosFileAttributes;
32
import java.nio.file.attribute.FileTime;
32
import java.nio.file.attribute.FileTime;
33
import java.nio.file.attribute.PosixFileAttributeView;
33
import java.nio.file.attribute.PosixFileAttributeView;
34
import java.nio.file.attribute.PosixFileAttributes;
34
import java.nio.file.attribute.PosixFileAttributes;
35
import java.nio.file.attribute.UserPrincipal;
35
import java.nio.file.attribute.UserPrincipal;
36
import java.util.GregorianCalendar;
36
import java.util.GregorianCalendar;
37
 
37
 
38
import javax.xml.bind.annotation.XmlAccessType;
38
import javax.xml.bind.annotation.XmlAccessType;
39
import javax.xml.bind.annotation.XmlAccessorOrder;
39
import javax.xml.bind.annotation.XmlAccessorOrder;
40
import javax.xml.bind.annotation.XmlAccessorType;
40
import javax.xml.bind.annotation.XmlAccessorType;
41
import javax.xml.bind.annotation.XmlElement;
41
import javax.xml.bind.annotation.XmlElement;
42
import javax.xml.bind.annotation.XmlRootElement;
42
import javax.xml.bind.annotation.XmlRootElement;
43
import javax.xml.bind.annotation.XmlType;
43
import javax.xml.bind.annotation.XmlType;
44
 
-
 
45
import com.sun.xml.bind.XmlAccessorFactory;
-
 
46
/**
44
/**
47
 * @author Brian Rosenberger, bru(at)brutex.de
45
 * @author Brian Rosenberger, bru(at)brutex.de
48
 *
46
 *
49
 */
47
 */
50
 
48
 
51
 
49
 
52
 
50
 
53
@XmlRootElement
51
@XmlRootElement
54
@XmlType(propOrder={"name", "path", "filesize", "owner", "lastModifiedDate", "createdDate", "lastAccessDate", "mimeType", 
52
@XmlType(propOrder={"name", "path", "filesize", "owner", "lastModifiedDate", "createdDate", "lastAccessDate", "mimeType", 
55
					"readonly", "hidden", "directory", "symbolicLink", "archive", "system", "downloadUrl"})
53
					"readonly", "hidden", "directory", "symbolicLink", "archive", "system", "downloadUrl"})
56
@XmlAccessorType(XmlAccessType.PROPERTY)
54
@XmlAccessorType(XmlAccessType.PROPERTY)
57
public class FileInfoType
55
public class FileInfoType
58
{
56
{
59
  private String name;
57
  private String name;
60
  private String path;
58
  private String path;
61
  private long filesize;
59
  private long filesize;
62
  private boolean isReadonly;
60
  private boolean isReadonly;
63
  private boolean isHidden;
61
  private boolean isHidden;
64
  private boolean isDirectory;
62
  private boolean isDirectory;
65
  private boolean isSymbolicLink;
63
  private boolean isSymbolicLink;
66
  private boolean isArchive;
64
  private boolean isArchive;
67
  private boolean isSystem;
65
  private boolean isSystem;
68
  private GregorianCalendar lastModifiedDate;
66
  private GregorianCalendar lastModifiedDate;
69
  private GregorianCalendar createdDate;
67
  private GregorianCalendar createdDate;
70
  private GregorianCalendar lastAccessDate;
68
  private GregorianCalendar lastAccessDate;
71
  private String owner;
69
  private String owner;
72
  private String mimeType;
70
  private String mimeType;
73
  private URI downloadUrl;
71
  private URI downloadUrl;
74
  
72
  
75
 
73
 
76
  public FileInfoType()
74
  public FileInfoType()
77
  {
75
  {
78
  }
76
  }
79
  
77
  
80
  public FileInfoType(Path p) throws IOException {
78
  public FileInfoType(Path p) throws IOException {
81
	  	this.name = p.getFileName().toString();
79
	  	this.name = p.getFileName().toString();
82
	    this.path = p.toAbsolutePath().toString().replace('\\', '/');
80
	    this.path = p.toAbsolutePath().toString().replace('\\', '/');
83
 
81
 
84
	  
82
	  
85
		BasicFileAttributeView basicView = Files.getFileAttributeView(p, BasicFileAttributeView.class);
83
		BasicFileAttributeView basicView = Files.getFileAttributeView(p, BasicFileAttributeView.class);
86
		BasicFileAttributes basic;
84
		BasicFileAttributes basic;
87
		basic = basicView.readAttributes();
85
		basic = basicView.readAttributes();
88
		
86
		
89
		this.isDirectory = basic.isDirectory();
87
		this.isDirectory = basic.isDirectory();
90
		this.isSymbolicLink = basic.isSymbolicLink();
88
		this.isSymbolicLink = basic.isSymbolicLink();
91
		this.filesize = basic.size();
89
		this.filesize = basic.size();
92
		this.lastModifiedDate = (GregorianCalendar) GregorianCalendar.getInstance();
90
		this.lastModifiedDate = (GregorianCalendar) GregorianCalendar.getInstance();
93
		this.lastModifiedDate.setTimeInMillis(basic.lastModifiedTime().toMillis());
91
		this.lastModifiedDate.setTimeInMillis(basic.lastModifiedTime().toMillis());
94
		this.createdDate = (GregorianCalendar) GregorianCalendar.getInstance();
92
		this.createdDate = (GregorianCalendar) GregorianCalendar.getInstance();
95
		this.createdDate.setTimeInMillis(basic.creationTime().toMillis());
93
		this.createdDate.setTimeInMillis(basic.creationTime().toMillis());
96
		this.lastAccessDate = (GregorianCalendar) GregorianCalendar.getInstance();
94
		this.lastAccessDate = (GregorianCalendar) GregorianCalendar.getInstance();
97
		this.lastAccessDate.setTimeInMillis(basic.lastAccessTime().toMillis());
95
		this.lastAccessDate.setTimeInMillis(basic.lastAccessTime().toMillis());
98
		
96
		
99
		// Try to set the Mime Type for that file
97
		// Try to set the Mime Type for that file
100
		// or default to octet-stream
98
		// or default to octet-stream
101
		if(!isDirectory) {
99
		if(!isDirectory) {
102
			this.mimeType = Files.probeContentType(p);
100
			this.mimeType = Files.probeContentType(p);
103
			if(this.mimeType==null) mimeType = "application/octet-stream";
101
			if(this.mimeType==null) mimeType = "application/octet-stream";
104
		} else {
102
		} else {
105
			this.mimeType = null;
103
			this.mimeType = null;
106
		}
104
		}
107
		
105
		
108
		// Set the file/ directory owner
106
		// Set the file/ directory owner
109
		this.owner = Files.getOwner(p).getName();
107
		this.owner = Files.getOwner(p).getName();
110
		
108
		
111
		//Dos specific Attributes
109
		//Dos specific Attributes
112
		DosFileAttributeView dosView = Files.getFileAttributeView(p, DosFileAttributeView.class);
110
		DosFileAttributeView dosView = Files.getFileAttributeView(p, DosFileAttributeView.class);
113
		if(dosView != null) {
111
		if(dosView != null) {
114
			DosFileAttributes dos = dosView.readAttributes();
112
			DosFileAttributes dos = dosView.readAttributes();
115
			this.isReadonly = dos.isReadOnly();
113
			this.isReadonly = dos.isReadOnly();
116
			this.isHidden = dos.isHidden();
114
			this.isHidden = dos.isHidden();
117
			this.isArchive = dos.isArchive();
115
			this.isArchive = dos.isArchive();
118
			this.isSystem = dos.isSystem();
116
			this.isSystem = dos.isSystem();
119
		}
117
		}
120
		
118
		
121
		//POSIX specific Attributes
119
		//POSIX specific Attributes
122
		PosixFileAttributeView posixView = Files.getFileAttributeView(p, PosixFileAttributeView.class);
120
		PosixFileAttributeView posixView = Files.getFileAttributeView(p, PosixFileAttributeView.class);
123
		if(posixView != null) {
121
		if(posixView != null) {
124
			PosixFileAttributes posix = posixView.readAttributes();
122
			PosixFileAttributes posix = posixView.readAttributes();
125
			//TODO: Unix specific file attributes
123
			//TODO: Unix specific file attributes
126
		}
124
		}
127
		
125
		
128
  }
126
  }
129
 
127
 
130
  
128
  
131
  public FileInfoType(Path file, URI downloadURL) throws IOException {
129
  public FileInfoType(Path file, URI downloadURL) throws IOException {
132
	  this(file);
130
	  this(file);
133
	  try {
131
	  try {
134
		this.downloadUrl = URI.create(downloadURL+URLEncoder.encode(this.path, "UTF-8"));
132
		this.downloadUrl = URI.create(downloadURL+URLEncoder.encode(this.path, "UTF-8"));
135
	} catch (UnsupportedEncodingException e) {
133
	} catch (UnsupportedEncodingException e) {
136
		// TODO Auto-generated catch block
134
		// TODO Auto-generated catch block
137
		e.printStackTrace();
135
		e.printStackTrace();
138
	}
136
	}
139
  }
137
  }
140
 
138
 
141
/**
139
/**
142
 * @return the name
140
 * @return the name
143
 */
141
 */
144
  @XmlElement(name="name")
142
  @XmlElement(name="name")
145
public String getName() {
143
public String getName() {
146
	return name;
144
	return name;
147
}
145
}
148
 
146
 
149
/**
147
/**
150
 * @return the path
148
 * @return the path
151
 */
149
 */
152
	@XmlElement(name = "path")
150
	@XmlElement(name = "path")
153
public String getPath() {
151
public String getPath() {
154
	return path;
152
	return path;
155
}
153
}
156
 
154
 
157
/**
155
/**
158
 * @return the filesize
156
 * @return the filesize
159
 */
157
 */
160
@XmlElement(name="filesize")
158
@XmlElement(name="filesize")
161
public long getFilesize() {
159
public long getFilesize() {
162
	return filesize;
160
	return filesize;
163
}
161
}
164
 
162
 
165
/**
163
/**
166
 * @return the isReadonly
164
 * @return the isReadonly
167
 */
165
 */
168
@XmlElement(name="isReadonly")
166
@XmlElement(name="isReadonly")
169
public boolean isReadonly() {
167
public boolean isReadonly() {
170
	return isReadonly;
168
	return isReadonly;
171
}
169
}
172
 
170
 
173
/**
171
/**
174
 * @return the isHidden
172
 * @return the isHidden
175
 */
173
 */
176
@XmlElement(name="isHidden")
174
@XmlElement(name="isHidden")
177
public boolean isHidden() {
175
public boolean isHidden() {
178
	return isHidden;
176
	return isHidden;
179
}
177
}
180
 
178
 
181
/**
179
/**
182
 * @return the isDirectory
180
 * @return the isDirectory
183
 */
181
 */
184
@XmlElement(name="isDirectory")
182
@XmlElement(name="isDirectory")
185
public boolean isDirectory() {
183
public boolean isDirectory() {
186
	return isDirectory;
184
	return isDirectory;
187
}
185
}
188
 
186
 
189
/**
187
/**
190
 * @return the isSymbolicLink
188
 * @return the isSymbolicLink
191
 */
189
 */
192
@XmlElement(name="isSymbolicLink")
190
@XmlElement(name="isSymbolicLink")
193
public boolean isSymbolicLink() {
191
public boolean isSymbolicLink() {
194
	return isSymbolicLink;
192
	return isSymbolicLink;
195
}
193
}
196
 
194
 
197
/**
195
/**
198
 * @return the isArchive
196
 * @return the isArchive
199
 */
197
 */
200
@XmlElement(name="isArchive")
198
@XmlElement(name="isArchive")
201
public boolean isArchive() {
199
public boolean isArchive() {
202
	return isArchive;
200
	return isArchive;
203
}
201
}
204
 
202
 
205
/**
203
/**
206
 * @return the isSystem
204
 * @return the isSystem
207
 */
205
 */
208
@XmlElement(name="isSystem")
206
@XmlElement(name="isSystem")
209
public boolean isSystem() {
207
public boolean isSystem() {
210
	return isSystem;
208
	return isSystem;
211
}
209
}
212
 
210
 
213
/**
211
/**
214
 * @return the lastModifiedDate
212
 * @return the lastModifiedDate
215
 */
213
 */
216
@XmlElement(name="lastModifiedDate")
214
@XmlElement(name="lastModifiedDate")
217
public GregorianCalendar getLastModifiedDate() {
215
public GregorianCalendar getLastModifiedDate() {
218
	return lastModifiedDate;
216
	return lastModifiedDate;
219
}
217
}
220
 
218
 
221
/**
219
/**
222
 * @return the createdDate
220
 * @return the createdDate
223
 */
221
 */
224
@XmlElement(name="createdDate")
222
@XmlElement(name="createdDate")
225
public GregorianCalendar getCreatedDate() {
223
public GregorianCalendar getCreatedDate() {
226
	return createdDate;
224
	return createdDate;
227
}
225
}
228
 
226
 
229
/**
227
/**
230
 * @return the lastAccessDate
228
 * @return the lastAccessDate
231
 */
229
 */
232
@XmlElement(name="lastAccessDate")
230
@XmlElement(name="lastAccessDate")
233
public GregorianCalendar getLastAccessDate() {
231
public GregorianCalendar getLastAccessDate() {
234
	return lastAccessDate;
232
	return lastAccessDate;
235
}
233
}
236
 
234
 
237
/**
235
/**
238
 * @return the owner
236
 * @return the owner
239
 */
237
 */
240
@XmlElement(name="owner")
238
@XmlElement(name="owner")
241
public String getOwner() {
239
public String getOwner() {
242
	return owner;
240
	return owner;
243
}
241
}
244
 
242
 
245
/**
243
/**
246
 * @return the mimeType
244
 * @return the mimeType
247
 */
245
 */
248
@XmlElement(name="mimeType")
246
@XmlElement(name="mimeType")
249
public String getMimeType() {
247
public String getMimeType() {
250
	return mimeType;
248
	return mimeType;
251
}
249
}
252
 
250
 
253
/**
251
/**
254
 * @return the downloadUrl
252
 * @return the downloadUrl
255
 */
253
 */
256
@XmlElement(name="downloadUrl")
254
@XmlElement(name="downloadUrl")
257
public URI getDownloadUrl() {
255
public URI getDownloadUrl() {
258
	return downloadUrl;
256
	return downloadUrl;
259
}
257
}
260
  
258
  
261
  
259
  
262
}
260
}
263
 
261
 
264
Generated by GNU Enscript 1.6.5.90.
262
Generated by GNU Enscript 1.6.5.90.
265
 
263
 
266
 
264