Datasets:

Modalities:
Text
Formats:
json
Languages:
code
Size:
< 1K
Tags:
code
Libraries:
Datasets
pandas
License:
File size: 17,865 Bytes
eb67da4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
/**
 * <a href="http://www.openolat.org">
 * OpenOLAT - Online Learning and Training</a><br>
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License"); <br>
 * you may not use this file except in compliance with the License.<br>
 * You may obtain a copy of the License at the
 * <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a>
 * <p>
 * Unless required by applicable law or agreed to in writing,<br>
 * software distributed under the License is distributed on an "AS IS" BASIS, <br>
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
 * See the License for the specific language governing permissions and <br>
 * limitations under the License.
 * <p>
 * Initial code contributed and copyrighted by<br>
 * frentix GmbH, http://www.frentix.com
 * <p>
 */
package org.olat.modules.webFeed.manager;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;

import org.olat.core.commons.services.image.ImageService;
import org.olat.core.gui.components.form.flexible.elements.FileElement;
import org.olat.core.id.OLATResourceable;
import org.apache.logging.log4j.Logger;
import org.olat.core.logging.Tracing;
import org.olat.core.util.CodeHelper;
import org.olat.core.util.FileUtils;
import org.olat.core.util.Formatter;
import org.olat.core.util.StringHelper;
import org.olat.core.util.vfs.LocalFileImpl;
import org.olat.core.util.vfs.LocalFolderImpl;
import org.olat.core.util.vfs.VFSContainer;
import org.olat.core.util.vfs.VFSItem;
import org.olat.core.util.vfs.VFSLeaf;
import org.olat.core.util.vfs.VFSManager;
import org.olat.core.util.vfs.filters.VFSItemMetaFilter;
import org.olat.core.util.vfs.filters.VFSSystemItemFilter;
import org.olat.core.util.xml.XStreamHelper;
import org.olat.fileresource.FileResourceManager;
import org.olat.modules.webFeed.Enclosure;
import org.olat.modules.webFeed.Feed;
import org.olat.modules.webFeed.Item;
import org.olat.modules.webFeed.model.EnclosureImpl;
import org.olat.modules.webFeed.model.FeedImpl;
import org.olat.modules.webFeed.model.ItemImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.thoughtworks.xstream.XStream;

/**
 * This class helps to store data like images and videos in the file systems
 * and handles the storage of Feeds and Items as XML as well.
 *
 * The structure of the files of a feed is:
 * resource
 *   feed
 *   __feed.xml
 *   __/items
 *   ____/item
 *   ______item.xml
 *   ______/media
 *   ________image.jpg
 *   ____/item
 *   ______...
 *
 * Initial date: 22.05.2017<br>
 * @author uhensler, [email protected], http://www.frentix.com
 *
 */
@Service
public class FeedFileStorge {

	private static final Logger log = Tracing.createLoggerFor(FeedFileStorge.class);

	private static final String MEDIA_DIR = "media";
	private static final String ITEMS_DIR = "items";
	public static final String FEED_FILE_NAME = "feed.xml";
	public static final String ITEM_FILE_NAME = "item.xml";

	// same as in repository metadata image upload
	private static final int PICTUREWIDTH = 570;

	private FileResourceManager fileResourceManager;
	private final XStream xstream;

	@Autowired
	private ImageService imageHelper;

	public FeedFileStorge() {
		fileResourceManager = FileResourceManager.getInstance();
		xstream = XStreamHelper.createXStreamInstance();
		XStreamHelper.allowDefaultPackage(xstream);
		xstream.alias("feed", FeedImpl.class);
		xstream.aliasField("type", FeedImpl.class, "resourceableType");
		xstream.omitField(FeedImpl.class, "id");
		xstream.omitField(FeedImpl.class, "itemIds");
		xstream.omitField(FeedImpl.class, "key");
		xstream.omitField(FeedImpl.class, "wrappers");
		xstream.alias("item", ItemImpl.class);
		xstream.omitField(ItemImpl.class, "key");
		xstream.omitField(ItemImpl.class, "feed");
		xstream.alias("enclosure", Enclosure.class, EnclosureImpl.class);
		xstream.ignoreUnknownElements();
	}

	/**
	 * Get the resource (root) container of the feed.
	 *
	 * @param ores
	 * @return
	 */
	public LocalFolderImpl getResourceContainer(OLATResourceable ores) {
		return fileResourceManager.getFileResourceRootImpl(ores);
	}
	
	public VFSContainer getOrCreateResourceMediaContainer(OLATResourceable ores) {
		VFSContainer mediaContainer = null;

		if (ores != null) {
			VFSContainer resourceDir = getResourceContainer(ores);
			mediaContainer = (VFSContainer) resourceDir.resolve(MEDIA_DIR);
			if (mediaContainer == null) {
				mediaContainer = resourceDir.createChildContainer(MEDIA_DIR);
			}
		}

		return mediaContainer;
	}

	/**
	 * Get the top most folder of a feed.
	 * The container is created if it does not exist.
	 *
	 * @param ores
	 * @return the container or null
	 */
	public VFSContainer getOrCreateFeedContainer(OLATResourceable ores) {
		VFSContainer feedContainer = null;

		if (ores != null) {
			VFSContainer resourceDir = getResourceContainer(ores);
			String feedContainerName = FeedManager.getInstance().getFeedKind(ores);
			feedContainer = (VFSContainer) resourceDir.resolve(feedContainerName);
			if (feedContainer == null) {
				feedContainer = resourceDir.createChildContainer(feedContainerName);
			}
		}

		return feedContainer;
	}

	/**
	 * Get the media container of a feed.
	 * The container is created if it does not exist.
	 *
	 * @param ores
	 * @return the container or null
	 */
	public VFSContainer getOrCreateFeedMediaContainer(OLATResourceable ores) {
		VFSContainer mediaContainer = null;

		if (ores != null) {
			VFSContainer feedContainer = getOrCreateFeedContainer(ores);
			mediaContainer = (VFSContainer) feedContainer.resolve(MEDIA_DIR);
			if (mediaContainer == null) {
				mediaContainer = feedContainer.createChildContainer(MEDIA_DIR);
			}
		}

		return mediaContainer;
	}

	/**
	 * Get the items container of a feed.
	 * The container is created if it does not exist.
	 *
	 * @param ores
	 * @return the container or null
	 */
	public VFSContainer getOrCreateFeedItemsContainer(OLATResourceable ores) {
		VFSContainer itemsContainer = null;

		if (ores != null) {
			VFSContainer feedContainer = getOrCreateFeedContainer(ores);
			itemsContainer = (VFSContainer) feedContainer.resolve(ITEMS_DIR);
			if (itemsContainer == null) {
				itemsContainer = feedContainer.createChildContainer(ITEMS_DIR);
			}
		}

		return itemsContainer;
	}

	/**
	 * Get the container of an item.
	 * The container is created if it does not exist.
	 *
	 * @param ores
	 * @return the container or null
	 */
	public VFSContainer getOrCreateItemContainer(Item item) {
		VFSContainer itemContainer = null;

		if (item != null) {
			Feed feed = item.getFeed();
			String guid = item.getGuid();
			itemContainer = getOrCreateItemContainer(feed, guid);
		}

		return itemContainer;
	}

	/**
	 * Delete the container of the item.
	 *
	 * @param item
	 */
	public void deleteItemContainer(Item item) {
		VFSContainer itemContainer = getOrCreateItemContainer(item);
		if (itemContainer != null) {
			itemContainer.delete();
		}
	}


	/**
	 * Get the container for the guid of an item.
	 * The container is created if it does not exist.

	 * @param feed
	 * @param guid
	 * @return
	 */
	public VFSContainer getOrCreateItemContainer(Feed feed, String guid) {
		VFSContainer itemContainer = null;

		if (feed != null && StringHelper.containsNonWhitespace(guid)) {
			VFSContainer feedContainer = getOrCreateFeedItemsContainer(feed);
			itemContainer = (VFSContainer) feedContainer.resolve(guid);
			if (itemContainer == null) {
				itemContainer = feedContainer.createChildContainer(guid);
			}
		}

		return itemContainer;
	}

	/**
	 * Get the media container of an item.
	 * The container is created if it does not exist.
	 *
	 * @param ores
	 * @return the container or null
	 */
	public VFSContainer getOrCreateItemMediaContainer(Item item) {
		VFSContainer mediaContainer = null;

		if (item != null) {
			VFSContainer itemContainer = getOrCreateItemContainer(item);
			if (itemContainer != null) {
				mediaContainer = (VFSContainer) itemContainer.resolve(MEDIA_DIR);
				if (mediaContainer == null) {
					mediaContainer = itemContainer.createChildContainer(MEDIA_DIR);
				}
			}
		}

		return mediaContainer;
	}

	/**
	 * Save the feed as XML into the feed container.
	 *
	 * @param feed
	 */
	public void saveFeedAsXML(Feed feed) {
		VFSContainer feedContainer = getOrCreateFeedContainer(feed);
		if (feedContainer != null) {
			VFSLeaf leaf = (VFSLeaf) feedContainer.resolve(FEED_FILE_NAME);
			if (leaf == null) {
				leaf = feedContainer.createChildLeaf(FEED_FILE_NAME);
			}
			XStreamHelper.writeObject(xstream, leaf, feed);
		}
	}

	/**
	 * Load the XML file of the feed from the feed container and convert it to
	 * a feed.
	 *
	 * @param ores
	 * @return the feed or null
	 */
	public Feed loadFeedFromXML(OLATResourceable ores) {
		Feed feed = null;

		VFSContainer feedContainer = getOrCreateFeedContainer(ores);
		if (feedContainer != null) {
			VFSLeaf leaf = (VFSLeaf) feedContainer.resolve(FEED_FILE_NAME);
			if (leaf != null) {
				feed = (FeedImpl) XStreamHelper.readObject(xstream, leaf);
				shorteningFeedToLengthOfDbAttribues(feed);
			}
		} else {
			log.warn("Feed XML-File could not be found on file system. Feed container: " + feedContainer);
		}

		return feed;
	}

	private void shorteningFeedToLengthOfDbAttribues(Feed feed) {
		if (feed.getAuthor() != null && feed.getAuthor().length() > 255) {
			feed.setAuthor(feed.getAuthor().substring(0, 255));
		}
		if (feed.getTitle() != null && feed.getTitle().length() > 1024) {
			feed.setTitle(feed.getTitle().substring(0, 1024));
		}
		if (feed.getDescription() != null && feed.getDescription().length() > 4000) {
			feed.setDescription(feed.getDescription().substring(0, 4000));
		}
		if (feed.getImageName() != null && feed.getImageName().length() > 1024) {
			feed.setImageName(null);
		}
		if (feed.getExternalFeedUrl() != null && feed.getExternalFeedUrl().length() > 4000) {
			feed.setExternalFeedUrl(null);
		}
		if (feed.getExternalImageURL() != null && feed.getExternalImageURL().length() > 4000) {
			feed.setExternalImageURL(null);
		}
	}

	/**
	 * Load the XML file of the feed from a Path and convert it to
	 * a feed.
	 *
	 * @param feedDir the directory which contains the feed file
	 * @return the feed or null
	 */
	public Feed loadFeedFromXML(Path feedDir) {
		Feed feed = null;

		if (feedDir != null) {
			Path feedPath = feedDir.resolve(FeedFileStorge.FEED_FILE_NAME);
			try (InputStream in = Files.newInputStream(feedPath);
					BufferedInputStream bis = new BufferedInputStream(in, FileUtils.BSIZE)) {
				feed = (FeedImpl) XStreamHelper.readObject(xstream, bis);
			} catch (IOException e) {
				log.warn("Feed XML-File could not be found on file system. Feed path: " + feedPath, e);
			}
		}

		return feed;
	}

	/**
	 * Delete the XML file of the feed from the feed container
	 *
	 * @param feed
	 */
	public void deleteFeedXML(Feed feed) {
		VFSContainer feedContainer = getOrCreateFeedContainer(feed);
		if (feedContainer != null) {
			VFSLeaf leaf = (VFSLeaf) feedContainer.resolve(FEED_FILE_NAME);
			if (leaf != null) {
				leaf.delete();
			}
		}
	}

	/**
	 * Save the item as XML into the item container.
	 *
	 * @param item
	 */
	public void saveItemAsXML(Item item) {
		VFSContainer itemContainer = getOrCreateItemContainer(item);
		if (itemContainer != null) {
			VFSLeaf leaf = (VFSLeaf) itemContainer.resolve(ITEM_FILE_NAME);
			if (leaf == null) {
				leaf = itemContainer.createChildLeaf(ITEM_FILE_NAME);
			}
			XStreamHelper.writeObject(xstream, leaf, item);
		}
	}

	/**
	 * Load the XML file of the item from the item container and convert it to
	 * an item.
	 *
	 * @param feed
	 * @param guid
	 * @return
	 */
	Item loadItemFromXML(VFSContainer itemContainer) {
		Item item = null;

		if (itemContainer != null) {
			VFSLeaf leaf = (VFSLeaf) itemContainer.resolve(ITEM_FILE_NAME);
			if (leaf != null) {
				try {
					item = (ItemImpl) XStreamHelper.readObject(xstream, leaf);
				} catch (Exception e) {
					log.warn("Item XML-File could not be read. Item container: " + leaf);
				}
			}
		}

		return item;
	}

	/**
	 * Load the XML file of all items of a feed and convert them to items.
	 *
	 * @param ores
	 * @return
	 */
	public List<Item> loadItemsFromXML(OLATResourceable ores) {
		List<Item> items = new ArrayList<>();

		VFSContainer itemsContainer = getOrCreateFeedItemsContainer(ores);
		if (itemsContainer != null) {
			List<VFSItem>  itemContainers = itemsContainer.getItems(new VFSItemMetaFilter());
			if (itemContainers != null && !itemContainers.isEmpty()) {
				for (VFSItem itemContainer : itemContainers) {
					Item item = loadItemFromXML((VFSContainer) itemContainer);
					if (item != null) {
						shorteningItemToLengthOfDbAttributes(item);
						items.add(item);
					}
				}
			}
		}

		return items;
	}

	private void shorteningItemToLengthOfDbAttributes(Item item) {
		if (item.getAuthor() != null && item.getAuthor().length() > 255) {
			item.setAuthor(item.getAuthor().substring(0, 255));
		}
		if (item.getExternalLink() != null && item.getExternalLink().length() > 4000) {
			item.setExternalLink(null);
		}
		if (item.getTitle() != null && item.getTitle().length() > 1024) {
			item.setTitle(item.getTitle().substring(0, 1024));
		}
	}

	/**
	 * Delete the XML file of the item from the item container
	 *
	 * @param item
	 */
	public void deleteItemXML(Item item) {
		VFSContainer itemContainer = getOrCreateItemContainer(item);
		if (itemContainer != null) {
			VFSLeaf leaf = (VFSLeaf) itemContainer.resolve(ITEM_FILE_NAME);
			if (leaf != null) {
				leaf.delete();
			}
		}
	}

	/**
	 * Save the media element of the feed. If already a file is in the media
	 * container, that file is previously deleted. If the media is null, this
	 * method will do nothing. It does not delete the existing media.
	 *
	 * @param feed
	 * @param media
	 * @return the file name which is save for the file system
	 */
	public String saveFeedMedia(Feed feed, FileElement media) {
		String saveFileName = null;

		if (media != null) {
			VFSContainer feedMediaContainer = getOrCreateFeedMediaContainer(feed);
			if (feedMediaContainer != null) {
				deleteFeedMedia(feed);
				VFSLeaf imageLeaf = media.moveUploadFileTo(feedMediaContainer);
				// Resize to same dimension box as with repo meta image
				VFSLeaf tmpImage = feedMediaContainer.createChildLeaf(Long.toString(CodeHelper.getRAMUniqueID()));
				imageHelper.scaleImage(imageLeaf, tmpImage, PICTUREWIDTH, PICTUREWIDTH, false);
				imageLeaf.delete();
				imageLeaf = tmpImage;
				// Make file system save
				saveFileName = Formatter.makeStringFilesystemSave(media.getUploadFileName());
				imageLeaf.rename(saveFileName);
			}
		}

		return saveFileName;
	}

	/**
	 * Save a file as the media element of the feed. If already a file is in
	 * the media container, that file is previously deleted.
	 *
	 * @param feed
	 * @param media
	 * @return the file name which is save for the file system
	 */
	public String saveFeedMedia(Feed feed, VFSLeaf media) {
		String saveFileName = null;

		VFSContainer feedMediaContainer = getOrCreateFeedMediaContainer(feed);
		if (feedMediaContainer != null) {
			deleteFeedMedia(feed);
			if (media != null) {
				VFSManager.copyContent(media, feedMediaContainer.createChildLeaf(media.getName()), true);
				saveFileName = media.getName();
			}
		}

		return saveFileName;
	}

	/**
	 * Load the the media element of the feed.
	 *
	 * @param feed
	 * @return the media alement or null
	 */
	public VFSLeaf loadFeedMedia(Feed feed) {
		VFSLeaf mediaFile = null;

		if (feed != null) {
			String feedImage = feed.getImageName();
			if (feedImage != null) {
				mediaFile = (VFSLeaf) getOrCreateFeedMediaContainer(feed).resolve(feedImage);
			}
		}

		return mediaFile;
	}

	/**
	 * Delete the the media of the feed.
	 *
	 * @param feed
	 */
	public void deleteFeedMedia(Feed feed) {
		VFSContainer feedMediaContainer = getOrCreateFeedMediaContainer(feed);
		if (feedMediaContainer != null) {
			for (VFSItem fileItem : feedMediaContainer.getItems(new VFSSystemItemFilter())) {
				fileItem.delete();
			}
		}
	}

	/**
	 * Save a file (video/audio/image) to the media container of the item.
	 * <p>
	 * If the media is null, this method will do nothing. It does not delete the
	 * existing media files.
	 *
	 * @param item
	 * @param media
	 * @return the file name which is save for the file system
	 */
	public String saveItemMedia(Item item, FileElement media) {
		String saveFileName = null;

		if (media != null) {
			VFSContainer itemMediaContainer = getOrCreateItemMediaContainer(item);
			if (itemMediaContainer != null) {
				media.moveUploadFileTo(itemMediaContainer);
				saveFileName = media.getUploadFileName();
			}
		}

		return saveFileName;
	}

	/**
	 * Load the media file of the item.
	 *
	 * @param item
	 * @return
	 */
	public File loadItemMedia(Item item) {
		File file = null;

		Enclosure enclosure = item.getEnclosure();
		VFSContainer mediaDir = getOrCreateItemMediaContainer(item);
		if (mediaDir != null && enclosure != null) {
			VFSLeaf mediaFile = (VFSLeaf) mediaDir.resolve(enclosure.getFileName());
			if (mediaFile instanceof LocalFileImpl) {
				file = ((LocalFileImpl) mediaFile).getBasefile();
			}
		}

		return file;
	}

	/**
	 * Delete a file from the media container of an item.
	 *
	 * @param item
	 * @param fileName
	 */
	public void deleteItemMedia(Item item, String fileName) {
		if (fileName != null) {
			VFSContainer itemContainer = getOrCreateItemMediaContainer(item);
			if (itemContainer != null) {
				VFSLeaf leaf = (VFSLeaf) itemContainer.resolve(fileName);
				if (leaf != null) {
					leaf.delete();
				}
			}
		}
	}

}