All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ksyun.ks3.service.response.ListObjectVersionsResponse Maven / Gradle / Ivy

package com.ksyun.ks3.service.response;

import com.ksyun.ks3.dto.Ks3ObjectSummary;
import com.ksyun.ks3.dto.ObjectVersionsListing;
import com.ksyun.ks3.dto.Owner;
import com.ksyun.ks3.utils.DateUtils;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;

import java.util.ArrayList;
import java.util.List;

public class ListObjectVersionsResponse extends
        Ks3WebServiceXmlResponse{
    private List objs = null;
    private Ks3ObjectSummary obj = null;
    private Owner owner = null;
    private List prefixs = new ArrayList();

    @Override
    public void startDocument() throws SAXException {
        result = new ObjectVersionsListing();
        objs = new ArrayList();
        result.setCommonPrefixes(prefixs);
    }

    @Override
    public void startEle(String uri, String localName, String qName,
                         Attributes attributes) throws SAXException {
        String tag = getTag();
        if ("Version".equals(tag)) {
            obj = new Ks3ObjectSummary();
        } else if ("Owner".equals(tag)) {
            owner = new Owner();
        } else if("DeleteMarker".equals(tag)) {
            obj = new Ks3ObjectSummary();
            obj.setDeleteMarker(true);
        }
    }

    @Override
    public void endEle(String uri, String localName, String qName)
            throws SAXException {
        String tag = getTag();
        if ("Owner".equals(tag)) {
            obj.setOwner(owner);
        } else if ("Version".equals(tag) || "DeleteMarker".equals(tag)) {
            obj.setBucketName(result.getBucketName());
            objs.add(obj);
        } else if ("ListVersionsResult".equals(tag)) {
            result.setObjectSummaries(objs);
        }
    }

    @Override
    public void string(String s) {
        String tag = getTag();
        if ("CommonPrefixes".equals(getTag(1))) {
            if ("Prefix".equals(tag)) {
                this.prefixs.add(s);
            }
        } else {
            if ("Name".equals(tag)) {
                result.setBucketName(s);
            } else if ("Prefix".equals(tag)) {
                result.setPrefix(s);
            } else if ("KeyMarker".equals(tag)) {
                result.setKeymarker(s);
            } else if ("VersionIdMarker".equals(tag)){
                result.setVersionIdMarker(s);
            }else if ("MaxKeys".equals(tag)) {
                result.setMaxKeys(Integer.parseInt(s));
            } else if ("Delimiter".equals(tag)) {
                result.setDelimiter(s);
            } else if ("IsTruncated".equals(tag)) {
                result.setTruncated("true".equals(s));
            } else if ("Key".equals(tag)) {
                obj.setKey(s);
            } else if ("LastModified".equals(tag)) {
                obj.setLastModified(DateUtils.convertStr2Date(s));
            } else if ("ETag".equals(tag)) {
                obj.setETag(s);
            } else if ("Size".equals(tag)) {
                obj.setSize(Long.parseLong(s));
            } else if ("ID".equals(tag)) {
                owner.setId(s);
            } else if ("DisplayName".equals(tag)) {
                owner.setDisplayName(s);
            } else if ("StorageClass".equals(tag)) {
                obj.setStorageClass(s);
            } else if ("Prefix".equals(tag)) {
                prefixs.add(s);
            } else if ("NextKeyMarker".equals(tag)) {
                result.setNextKeyMarker(s);
            } else if("Encoding-Type".equals(tag)){
                result.setEncodingType(s);
            } else if("NextVersionIdMarker".equals(tag)) {
                result.setNextVersionIdMarker(s);
            } else if("IsLatest".equals(tag)) {
                obj.setLatest(Boolean.parseBoolean(s));
            } else if("VersionId".equals(tag)) {
                obj.setVersionId(s);
            }
        }
    }

    @Override
    public void preHandle() {

    }

    public int[] expectedStatus() {
        return new int[] { 200 };
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy