001/**
002 *
003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved.
004 *
005 * This library is free software; you can redistribute it and/or
006 * modify it under the terms of the GNU Lesser General Public
007 * License as published by the Free Software Foundation; either 
008 * version 2.1 of the License, or (at your option) any later version.
009 * 
010 * This library is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013 * Lesser General Public License for more details.
014 * 
015 * You should have received a copy of the GNU Lesser General Public 
016 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
017 * 
018 **/
019package lucee.commons.io.res.type.s3;
020
021import java.io.IOException;
022import java.io.InputStream;
023import java.security.InvalidKeyException;
024import java.security.NoSuchAlgorithmException;
025
026import org.xml.sax.SAXException;
027
028public final class Content implements S3Info {
029        
030        
031        private String key;
032        private long lastModified;
033        private String eTag;
034        private long size;
035        private String storageClass;
036        private String ownerIdKey;
037        private String ownerDisplayName;
038        private String bucketName;
039        private final S3 s3;
040        private boolean truncated;
041        
042        /**
043         * @return the truncated
044         */
045        public boolean isTruncated() {
046                return truncated;
047        }
048        /**
049         * @return the bucketName
050         */
051        public String getBucketName() {
052                return bucketName;
053        }
054        /**
055         * @param bucketName the bucketName to set
056         */
057        public void setBucketName(String bucketName) {
058                this.bucketName = bucketName;
059        }
060        public Content(S3 s3) {
061                this.s3=s3;
062        }
063        /**
064         * @return the key
065         */
066        public String getKey() {
067                return key;
068        }
069        /**
070         * @param key the key to set
071         */
072        public void setKey(String key) {
073                this.key = key;
074        }
075        /**
076         * @return the lastModified
077         */
078        public long getLastModified() {
079                return lastModified;
080        }
081        /**
082         * @param lastModified the lastModified to set
083         */
084        public void setLastModified(long lastModified) {
085                this.lastModified = lastModified;
086        }
087        /**
088         * @return the eTag
089         */
090        public String getETag() {
091                return eTag;
092        }
093        /**
094         * @param tag the eTag to set
095         */
096        public void setETag(String tag) {
097                eTag = tag;
098        }
099        /**
100         * @return the size
101         */
102        public long getSize() {
103                return size;
104        }
105        /**
106         * @param size the size to set
107         */
108        public void setSize(long size) {
109                this.size = size;
110        }
111        /**
112         * @return the storageClass
113         */
114        public String getStorageClass() {
115                return storageClass;
116        }
117        /**
118         * @param storageClass the storageClass to set
119         */
120        public void setStorageClass(String storageClass) {
121                this.storageClass = storageClass;
122        }
123        /**
124         * @return the ownerIdKey
125         */
126        public String getOwnerIdKey() {
127                return ownerIdKey;
128        }
129        /**
130         * @param ownerIdKey the ownerIdKey to set
131         */
132        public void setOwnerIdKey(String ownerIdKey) {
133                this.ownerIdKey = ownerIdKey;
134        }
135        /**
136         * @return the ownerDisplayName
137         */
138        public String getOwnerDisplayName() {
139                return ownerDisplayName;
140        }
141        /**
142         * @param ownerDisplayName the ownerDisplayName to set
143         */
144        public void setOwnerDisplayName(String ownerDisplayName) {
145                this.ownerDisplayName = ownerDisplayName;
146        }
147        
148        public String getLink(int secondsValid) throws InvalidKeyException, NoSuchAlgorithmException, IOException {
149                return s3.getObjectLink(bucketName, key, secondsValid);
150        }
151        
152        public InputStream getInputStream() throws InvalidKeyException, NoSuchAlgorithmException, IOException, SAXException {
153                return s3.getInputStream(bucketName, key);
154        }
155        
156        
157        @Override
158        public String toString() {
159                return "eTag:"+eTag+";key:"+key+";ownerDisplayName:"+ownerDisplayName+";ownerIdKey:"+ownerIdKey+";size:"+size+";storageClass:"+storageClass+";";
160        }
161        
162        @Override
163        public boolean exists() {
164                return true;
165        }
166        
167        @Override
168        public boolean isDirectory() {
169                return getSize()==0 && getKey().endsWith("/");
170        }
171        
172        @Override
173        public boolean isFile() {
174                return getSize()>0 || !getKey().endsWith("/");
175        }
176        /**
177         * @param truncated the truncated to set
178         */
179        public void setTruncated(boolean truncated) {
180                this.truncated = truncated;
181        }
182        
183        
184}