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

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

package com.ksyun.ks3.service.response;

import com.ksyun.ks3.dto.Ks3ObjectSummary;
import com.ksyun.ks3.dto.ObjectListing;
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;

/**
 * @author lijunwei[[email protected]]  
 * 
 * @date 2014年10月16日 下午3:39:35
 * 
 * @description
 **/
public class ListObjectsResponse 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 ObjectListing();
		objs = new ArrayList();
		result.setCommonPrefixes(prefixs);
	}

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

	@Override
	public void endEle(String uri, String localName, String qName)
			throws SAXException {
		String tag = getTag();
		if ("Owner".equals(tag)) {
			obj.setOwner(owner);
		} else if ("Contents".equals(tag)) {
			obj.setBucketName(result.getBucketName());
			objs.add(obj);
		} else if ("ListBucketResult".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 ("Marker".equals(tag)) {
				result.setMarker(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 ("Type".equals(tag)) {
				obj.setType(s);
			} else if ("Prefix".equals(tag)) {
				prefixs.add(s);
			} else if ("NextMarker".equals(tag)) {
				result.setNextMarker(s);
			} else if("Encoding-Type".equals(tag)){
				result.setEncodingType(s);
			}
		}
	}

	@Override
	public void preHandle() {

	}

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




© 2015 - 2025 Weber Informatics LLC | Privacy Policy