Subversion Repositories XServices

Rev

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

Rev 116 Rev 147
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;
-
 
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;
-
 
39
import javax.xml.bind.annotation.XmlAccessorOrder;
-
 
40
import javax.xml.bind.annotation.XmlAccessorType;
20
import javax.xml.bind.annotation.XmlElement;
41
import javax.xml.bind.annotation.XmlElement;
21
import javax.xml.bind.annotation.XmlRootElement;
42
import javax.xml.bind.annotation.XmlRootElement;
-
 
43
import javax.xml.bind.annotation.XmlType;
-
 
44
 
-
 
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
24
 *
48
 *
25
 */
49
 */
26
 
50
 
27
 
51
 
28
 
52
 
29
@XmlRootElement
53
@XmlRootElement
-
 
54
@XmlType(propOrder={"name", "path", "filesize", "owner", "lastModifiedDate", "createdDate", "lastAccessDate", "mimeType", 
-
 
55
					"readonly", "hidden", "directory", "symbolicLink", "archive", "system", "downloadUrl"})
-
 
56
@XmlAccessorType(XmlAccessType.PROPERTY)
30
public class FileInfoType
57
public class FileInfoType
31
{
58
{
32
  private String name;
59
  private String name;
33
  private String path;
60
  private String path;
34
  private long filesize;
61
  private long filesize;
-
 
62
  private boolean isReadonly;
35
  private boolean canWrite;
63
  private boolean isHidden;
36
  private boolean isDirectory;
64
  private boolean isDirectory;
-
 
65
  private boolean isSymbolicLink;
-
 
66
  private boolean isArchive;
-
 
67
  private boolean isSystem;
-
 
68
  private GregorianCalendar lastModifiedDate;
-
 
69
  private GregorianCalendar createdDate;
-
 
70
  private GregorianCalendar lastAccessDate;
-
 
71
  private String owner;
-
 
72
  private String mimeType;
-
 
73
  private URI downloadUrl;
-
 
74
  
37
 
75
 
38
  public FileInfoType()
76
  public FileInfoType()
39
  {
77
  {
40
  }
78
  }
41
 
79
  
42
  public FileInfoType(File file)
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
-
 
100
		// or default to octet-stream
-
 
101
		if(!isDirectory) {
-
 
102
			this.mimeType = Files.probeContentType(p);
-
 
103
			if(this.mimeType==null) mimeType = "application/octet-stream";
-
 
104
		} else {
-
 
105
			this.mimeType = null;
43
  {
106
		}
-
 
107
		
-
 
108
		// Set the file/ directory owner
44
    this.name = file.getName();
109
		this.owner = Files.getOwner(p).getName();
-
 
110
		
-
 
111
		//Dos specific Attributes
-
 
112
		DosFileAttributeView dosView = Files.getFileAttributeView(p, DosFileAttributeView.class);
-
 
113
		if(dosView != null) {
45
    this.path = file.getAbsolutePath().replace('\\', '/');
114
			DosFileAttributes dos = dosView.readAttributes();
-
 
115
			this.isReadonly = dos.isReadOnly();
46
    this.canWrite = file.canWrite();
116
			this.isHidden = dos.isHidden();
47
    this.filesize = file.length();
117
			this.isArchive = dos.isArchive();
48
    this.isDirectory = file.isDirectory();
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);
-
 
133
	  try {
-
 
134
		this.downloadUrl = URI.create(downloadURL+URLEncoder.encode(this.path, "UTF-8"));
-
 
135
	} catch (UnsupportedEncodingException e) {
-
 
136
		// TODO Auto-generated catch block
-
 
137
		e.printStackTrace();
-
 
138
	}
49
  }
139
  }
-
 
140
 
-
 
141
/**
-
 
142
 * @return the name
50
 
143
 */
51
  @XmlElement(name="name")
144
  @XmlElement(name="name")
52
  public String getName()
-
 
53
  {
145
public String getName() {
54
    return this.name;
146
	return name;
-
 
147
}
55
  }
148
 
56
 
149
/**
57
  public void setName(String name)
150
 * @return the path
-
 
151
 */
-
 
152
	@XmlElement(name = "path")
58
  {
153
public String getPath() {
-
 
154
	return path;
-
 
155
}
-
 
156
 
59
    this.name = name;
157
/**
60
  }
158
 * @return the filesize
61
 
-
 
62
  @XmlElement(name="path")
159
 */
63
  public String getPath()
160
@XmlElement(name="filesize")
-
 
161
public long getFilesize() {
64
  {
162
	return filesize;
65
    return this.path;
163
}
-
 
164
 
-
 
165
/**
66
  }
166
 * @return the isReadonly
67
 
167
 */
-
 
168
@XmlElement(name="isReadonly")
-
 
169
public boolean isReadonly() {
-
 
170
	return isReadonly;
68
  public void setPath(String path)
171
}
69
  {
172
 
70
    this.path = path;
-
 
71
  }
173
/**
72
 
174
 * @return the isHidden
-
 
175
 */
73
  @XmlElement(name="size")
176
@XmlElement(name="isHidden")
74
  public long getFilesize()
177
public boolean isHidden() {
-
 
178
	return isHidden;
75
  {
179
}
-
 
180
 
76
    return this.filesize;
181
/**
-
 
182
 * @return the isDirectory
-
 
183
 */
-
 
184
@XmlElement(name="isDirectory")
77
  }
185
public boolean isDirectory() {
78
 
186
	return isDirectory;
79
  public void setFilesize(long filesize)
-
 
80
  {
187
}
81
    this.filesize = filesize;
188
 
-
 
189
/**
-
 
190
 * @return the isSymbolicLink
-
 
191
 */
82
  }
192
@XmlElement(name="isSymbolicLink")
83
 
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")
-
 
209
public boolean isSystem() {
-
 
210
	return isSystem;
-
 
211
}
-
 
212
 
-
 
213
/**
-
 
214
 * @return the lastModifiedDate
84
  @XmlElement(name="isWritable")
215
 */
-
 
216
@XmlElement(name="lastModifiedDate")
-
 
217
public GregorianCalendar getLastModifiedDate() {
-
 
218
	return lastModifiedDate;
-
 
219
}
-
 
220
 
-
 
221
/**
85
  public boolean isCanWrite()
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")
-
 
241
public String getOwner() {
-
 
242
	return owner;
-
 
243
}
-
 
244
 
-
 
245
/**
-
 
246
 * @return the mimeType
86
  {
247
 */
-
 
248
@XmlElement(name="mimeType")
-
 
249
public String getMimeType() {
-
 
250
	return mimeType;
-
 
251
}
-
 
252
 
-
 
253
/**
87
    return this.canWrite;
254
 * @return the downloadUrl
88
  }
255
 */
89
 
256
@XmlElement(name="downloadUrl")
90
  @XmlElement(name="isDirectory")
257
public URI getDownloadUrl() {
91
  public boolean isDirectory()
258
	return downloadUrl;
92
  {
259
}
93
    return this.isDirectory;
260
  
94
  }
261
  
95
}
262
}
96
 
263
 
97
Generated by GNU Enscript 1.6.5.90.
264
Generated by GNU Enscript 1.6.5.90.
98
 
265
 
99
 
266