1/*
2* Copyright 2010-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3*
4* Licensed under the Apache License, Version 2.0 (the "License").
5* You may not use this file except in compliance with the License.
6* A copy of the License is located at
7*
8* http://aws.amazon.com/apache2.0
9*
10* or in the "license" file accompanying this file. This file is distributed
11* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12* express or implied. See the License for the specific language governing
13* permissions and limitations under the License.
14*/
15
16#include <aws/s3/model/ListPartsResult.h>
17#include <aws/core/utils/xml/XmlSerializer.h>
18#include <aws/core/AmazonWebServiceResult.h>
19#include <aws/core/utils/StringUtils.h>
20#include <aws/core/utils/memory/stl/AWSStringStream.h>
21
22#include <utility>
23
24using namespace Aws::S3::Model;
25using namespace Aws::Utils::Xml;
26using namespace Aws::Utils;
27using namespace Aws;
28
29ListPartsResult::ListPartsResult() :
30 m_partNumberMarker(0),
31 m_nextPartNumberMarker(0),
32 m_maxParts(0),
33 m_isTruncated(false),
34 m_storageClass(StorageClass::NOT_SET),
35 m_requestCharged(RequestCharged::NOT_SET)
36{
37}
38
39ListPartsResult::ListPartsResult(const Aws::AmazonWebServiceResult<XmlDocument>& result) :
40 m_partNumberMarker(0),
41 m_nextPartNumberMarker(0),
42 m_maxParts(0),
43 m_isTruncated(false),
44 m_storageClass(StorageClass::NOT_SET),
45 m_requestCharged(RequestCharged::NOT_SET)
46{
47 *this = result;
48}
49
50ListPartsResult& ListPartsResult::operator =(const Aws::AmazonWebServiceResult<XmlDocument>& result)
51{
52 const XmlDocument& xmlDocument = result.GetPayload();
53 XmlNode resultNode = xmlDocument.GetRootElement();
54
55 if(!resultNode.IsNull())
56 {
57 XmlNode bucketNode = resultNode.FirstChild("Bucket");
58 if(!bucketNode.IsNull())
59 {
60 m_bucket = Aws::Utils::Xml::DecodeEscapedXmlText(bucketNode.GetText());
61 }
62 XmlNode keyNode = resultNode.FirstChild("Key");
63 if(!keyNode.IsNull())
64 {
65 m_key = Aws::Utils::Xml::DecodeEscapedXmlText(keyNode.GetText());
66 }
67 XmlNode uploadIdNode = resultNode.FirstChild("UploadId");
68 if(!uploadIdNode.IsNull())
69 {
70 m_uploadId = Aws::Utils::Xml::DecodeEscapedXmlText(uploadIdNode.GetText());
71 }
72 XmlNode partNumberMarkerNode = resultNode.FirstChild("PartNumberMarker");
73 if(!partNumberMarkerNode.IsNull())
74 {
75 m_partNumberMarker = StringUtils::ConvertToInt32(StringUtils::Trim(Aws::Utils::Xml::DecodeEscapedXmlText(partNumberMarkerNode.GetText()).c_str()).c_str());
76 }
77 XmlNode nextPartNumberMarkerNode = resultNode.FirstChild("NextPartNumberMarker");
78 if(!nextPartNumberMarkerNode.IsNull())
79 {
80 m_nextPartNumberMarker = StringUtils::ConvertToInt32(StringUtils::Trim(Aws::Utils::Xml::DecodeEscapedXmlText(nextPartNumberMarkerNode.GetText()).c_str()).c_str());
81 }
82 XmlNode maxPartsNode = resultNode.FirstChild("MaxParts");
83 if(!maxPartsNode.IsNull())
84 {
85 m_maxParts = StringUtils::ConvertToInt32(StringUtils::Trim(Aws::Utils::Xml::DecodeEscapedXmlText(maxPartsNode.GetText()).c_str()).c_str());
86 }
87 XmlNode isTruncatedNode = resultNode.FirstChild("IsTruncated");
88 if(!isTruncatedNode.IsNull())
89 {
90 m_isTruncated = StringUtils::ConvertToBool(StringUtils::Trim(Aws::Utils::Xml::DecodeEscapedXmlText(isTruncatedNode.GetText()).c_str()).c_str());
91 }
92 XmlNode partsNode = resultNode.FirstChild("Part");
93 if(!partsNode.IsNull())
94 {
95 XmlNode partMember = partsNode;
96 while(!partMember.IsNull())
97 {
98 m_parts.push_back(partMember);
99 partMember = partMember.NextNode("Part");
100 }
101
102 }
103 XmlNode initiatorNode = resultNode.FirstChild("Initiator");
104 if(!initiatorNode.IsNull())
105 {
106 m_initiator = initiatorNode;
107 }
108 XmlNode ownerNode = resultNode.FirstChild("Owner");
109 if(!ownerNode.IsNull())
110 {
111 m_owner = ownerNode;
112 }
113 XmlNode storageClassNode = resultNode.FirstChild("StorageClass");
114 if(!storageClassNode.IsNull())
115 {
116 m_storageClass = StorageClassMapper::GetStorageClassForName(StringUtils::Trim(Aws::Utils::Xml::DecodeEscapedXmlText(storageClassNode.GetText()).c_str()).c_str());
117 }
118 }
119
120 const auto& headers = result.GetHeaderValueCollection();
121 const auto& abortDateIter = headers.find("x-amz-abort-date");
122 if(abortDateIter != headers.end())
123 {
124 m_abortDate = DateTime(abortDateIter->second, DateFormat::RFC822);
125 }
126
127 const auto& abortRuleIdIter = headers.find("x-amz-abort-rule-id");
128 if(abortRuleIdIter != headers.end())
129 {
130 m_abortRuleId = abortRuleIdIter->second;
131 }
132
133 const auto& requestChargedIter = headers.find("x-amz-request-charged");
134 if(requestChargedIter != headers.end())
135 {
136 m_requestCharged = RequestChargedMapper::GetRequestChargedForName(requestChargedIter->second);
137 }
138
139 return *this;
140}
141