// This software code is made available "AS IS" without warranties of any // kind. You may copy, display, modify and redistribute the software // code either by itself or as incorporated into your code; provided that // you do not remove any proprietary notices. Your use of this software // code is at your own risk and you waive any claim against Amazon // Digital Services, Inc. or its affiliates with respect to your use of // this software code. (c) 2006 Amazon Digital Services, Inc. or its // affiliates. using System; using System.Collections; using System.Net; using System.Text; using System.Xml; namespace Extf.Net.S3 { public class ListBucketResponse : Response { /// /// The name of the bucket being listed. Null if the request fails. /// private string name; public string Name { get { return name; } } /// /// The prefix echoed back from the request. Null if the request fails. /// private string prefix; public string Prefix { get { return prefix; } } /// /// The marker echoed back from the request. Null if the request fails. /// private string marker; public string Marker { get { return marker; } } /// /// The delimiter echoed back from the request. Null if not specified in /// the request or it fails. /// private string delimiter; public string Delimiter { get { return delimiter; } } /// /// The maxKeys echoed back from the request if specified. 0 if the request fails. /// private int maxKeys; public int MaxKeys { get { return maxKeys; } } /// /// Indicates if there are more results to the list. True if the current /// list results have been truncated. The value will be false if the request /// fails. /// private bool isTruncated; public bool IsTruncated { get { return isTruncated; } } /// /// Indicates what to use as a marker for subsequent list requests in the event /// that the results are truncated. Present only when a delimiter is specified. /// Null if the requests fails. /// private string nextMarker; public string NextMarker { get { return nextMarker; } } /// /// A list of ListEntry objects representing the objects in the given bucket. /// Null if the request fails. /// private ArrayList entries; public ArrayList Entries { get { return entries; } } /// /// A list of CommonPrefixEntry objects representing the common prefixes of the /// keys that matched up to the delimiter. Null if the request fails. /// private ArrayList commonPrefixEntries; public ArrayList CommonPrefixEntries { get { return commonPrefixEntries; } } public ListBucketResponse(WebRequest request) : base(request) { entries = new ArrayList(); commonPrefixEntries = new ArrayList(); string rawBucketXML = Utils.slurpInputStreamAsString(response.GetResponseStream()); XmlDocument doc = new XmlDocument(); doc.LoadXml( rawBucketXML ); foreach (XmlNode node in doc.ChildNodes) { if (node.Name.Equals("ListBucketResult")) { foreach (XmlNode child in node.ChildNodes) { if (child.Name.Equals("Contents")) { entries.Add( new ListEntry(child) ); } else if (child.Name.Equals("CommonPrefixes")) { commonPrefixEntries.Add(new CommonPrefixEntry(child)); } else if (child.Name.Equals("Name")) { name = Utils.getXmlChildText( child ); } else if (child.Name.Equals("Prefix")) { prefix = Utils.getXmlChildText(child); } else if (child.Name.Equals("Marker")) { marker = Utils.getXmlChildText(child); } else if (child.Name.Equals("Delimiter")) { delimiter = Utils.getXmlChildText(child); } else if (child.Name.Equals("MaxKeys")) { maxKeys = int.Parse(Utils.getXmlChildText(child)); } else if (child.Name.Equals("IsTruncated")) { isTruncated = bool.Parse( Utils.getXmlChildText(child) ); } else if (child.Name.Equals("NextMarker")) { nextMarker = Utils.getXmlChildText(child); } } } } } } }