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.net.MalformedURLException;
023import java.security.InvalidKeyException;
024import java.security.NoSuchAlgorithmException;
025
026import lucee.runtime.type.dt.DateTime;
027
028import org.xml.sax.SAXException;
029
030public final class Bucket implements S3Info {
031
032        private final S3 s3;
033        private String name;
034        private DateTime creation;
035        private String ownerIdKey;
036        private String ownerDisplayName;
037        
038        public Bucket(S3 s3) {
039                this.s3 = s3;
040        }
041
042        /**
043         * @return the ownerIdKey
044         */
045        public String getOwnerIdKey() {
046                return ownerIdKey;
047        }
048
049        /**
050         * @param ownerIdKey the ownerIdKey to set
051         */
052        public void setOwnerIdKey(String ownerIdKey) {
053                this.ownerIdKey = ownerIdKey;
054        }
055
056        /**
057         * @return the ownerDisplayName
058         */
059        public String getOwnerDisplayName() {
060                return ownerDisplayName;
061        }
062
063        /**
064         * @param ownerDisplayName the ownerDisplayName to set
065         */
066        public void setOwnerDisplayName(String ownerDisplayName) {
067                this.ownerDisplayName = ownerDisplayName;
068        }
069
070        /**
071         * @return the name
072         */
073        public String getName() {
074                return name;
075        }
076
077        /**
078         * @return the creation
079         */
080        public DateTime getCreation() {
081                return creation;
082        }
083
084        /**
085         * @param name the name to set
086         */
087        public void setName(String name) {
088                this.name = name;
089        }
090
091        /**
092         * @param creation the creation to set
093         */
094        public void setCreation(DateTime creation) {
095                this.creation = creation;
096        }
097        
098        public Content[] listContent(String prefix,String marker,int maxKeys) throws InvalidKeyException, MalformedURLException, NoSuchAlgorithmException, IOException, SAXException {
099                return s3.listContents(name, prefix, marker, maxKeys);
100        }
101        
102        @Override
103        public String toString() {
104                return "name:"+name+";creation:"+creation+";ownerDisplayName:"+ownerDisplayName+";ownerIdKey:"+ownerIdKey;
105        }
106
107        @Override
108        public long getLastModified() {
109                return getCreation().getTime();
110        }
111
112        @Override
113        public long getSize() {
114                return 0;
115        }
116
117        @Override
118        public boolean exists() {
119                return true;
120        }
121
122        @Override
123        public boolean isDirectory() {
124                return true;
125        }
126
127        @Override
128        public boolean isFile() {
129                return false;
130        }
131}