Add winery source code
[vfc/nfvo/wfengine.git] / winery / org.eclipse.winery.repository / src / main / java / org / eclipse / winery / repository / datatypes / FileMeta.java
1 /*******************************************************************************
2  * Copyright (c) 2012-2013 University of Stuttgart.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * and the Apache License 2.0 which both accompany this distribution,
6  * and are available at http://www.eclipse.org/legal/epl-v10.html
7  * and http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Contributors:
10  *     Oliver Kopp - initial API and implementation
11  *******************************************************************************/
12 package org.eclipse.winery.repository.datatypes;
13
14 import java.io.IOException;
15
16 import javax.xml.bind.annotation.XmlRootElement;
17
18 import org.apache.commons.io.FilenameUtils;
19 import org.eclipse.winery.common.RepositoryFileReference;
20 import org.eclipse.winery.repository.Constants;
21 import org.eclipse.winery.repository.Prefs;
22 import org.eclipse.winery.repository.Utils;
23 import org.eclipse.winery.repository.backend.Repository;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26
27 /**
28  * based on
29  * https://github.com/blueimp/jQuery-File-Upload/wiki/Google-App-Engine-Java
30  * 
31  * The getters are named according to the requirements of the template in
32  * jquery-file-upload-full.jsp
33  */
34 @XmlRootElement
35 public class FileMeta {
36         
37         private static final Logger logger = LoggerFactory.getLogger(FileMeta.class);
38         
39         String name;
40         long size;
41         String url;
42         String deleteUrl;
43         String deleteType = "DELETE";
44         String thumbnailUrl;
45         
46         
47         public String getName() {
48                 return this.name;
49         }
50         
51         public long getSize() {
52                 return this.size;
53         }
54         
55         public String getUrl() {
56                 return this.url;
57         }
58         
59         public String getDeleteUrl() {
60                 return this.deleteUrl;
61         }
62         
63         public String getDeleteType() {
64                 return this.deleteType;
65         }
66         
67         public String getThumbnailUrl() {
68                 return this.thumbnailUrl;
69         }
70         
71         public FileMeta(String filename, long size, String url, String thumbnailUrl) {
72                 this.name = filename;
73                 this.size = size;
74                 this.url = url;
75                 this.thumbnailUrl = thumbnailUrl;
76                 this.deleteUrl = url;
77         }
78         
79         public FileMeta(RepositoryFileReference ref) {
80                 this.name = ref.getFileName();
81                 try {
82                         this.size = Repository.INSTANCE.getSize(ref);
83                 } catch (IOException e) {
84                         FileMeta.logger.error(e.getMessage(), e);
85                         this.size = 0;
86                 }
87                 this.url = Utils.getAbsoluteURL(ref);
88                 this.deleteUrl = this.url;
89                 this.thumbnailUrl = Prefs.INSTANCE.getResourcePath() + Constants.PATH_MIMETYPEIMAGES + FilenameUtils.getExtension(this.name) + Constants.SUFFIX_MIMETYPEIMAGES;
90         }
91         
92         /**
93          * @param ref the reference to get information from
94          * @param URLprefix the string which should be prepended the actual URL.
95          *            Including the "/"
96          */
97         public FileMeta(RepositoryFileReference ref, String URLprefix) {
98                 this(ref);
99                 this.url = URLprefix + this.url;
100         }
101         
102         /**
103          * The constructor is used for JAX-B only. Therefore, the warning "unused"
104          * is suppressed
105          */
106         @SuppressWarnings("unused")
107         private FileMeta() {
108         }
109         
110 }