1 /**
2  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  * SPDX-License-Identifier: Apache-2.0.
4  */
5 
6 #include <aws/s3control/model/S3ObjectMetadata.h>
7 #include <aws/core/utils/xml/XmlSerializer.h>
8 #include <aws/core/utils/StringUtils.h>
9 #include <aws/core/utils/memory/stl/AWSStringStream.h>
10 
11 #include <utility>
12 
13 using namespace Aws::Utils::Xml;
14 using namespace Aws::Utils;
15 
16 namespace Aws
17 {
18 namespace S3Control
19 {
20 namespace Model
21 {
22 
S3ObjectMetadata()23 S3ObjectMetadata::S3ObjectMetadata() :
24     m_cacheControlHasBeenSet(false),
25     m_contentDispositionHasBeenSet(false),
26     m_contentEncodingHasBeenSet(false),
27     m_contentLanguageHasBeenSet(false),
28     m_userMetadataHasBeenSet(false),
29     m_contentLength(0),
30     m_contentLengthHasBeenSet(false),
31     m_contentMD5HasBeenSet(false),
32     m_contentTypeHasBeenSet(false),
33     m_httpExpiresDateHasBeenSet(false),
34     m_requesterCharged(false),
35     m_requesterChargedHasBeenSet(false),
36     m_sSEAlgorithm(S3SSEAlgorithm::NOT_SET),
37     m_sSEAlgorithmHasBeenSet(false)
38 {
39 }
40 
S3ObjectMetadata(const XmlNode & xmlNode)41 S3ObjectMetadata::S3ObjectMetadata(const XmlNode& xmlNode) :
42     m_cacheControlHasBeenSet(false),
43     m_contentDispositionHasBeenSet(false),
44     m_contentEncodingHasBeenSet(false),
45     m_contentLanguageHasBeenSet(false),
46     m_userMetadataHasBeenSet(false),
47     m_contentLength(0),
48     m_contentLengthHasBeenSet(false),
49     m_contentMD5HasBeenSet(false),
50     m_contentTypeHasBeenSet(false),
51     m_httpExpiresDateHasBeenSet(false),
52     m_requesterCharged(false),
53     m_requesterChargedHasBeenSet(false),
54     m_sSEAlgorithm(S3SSEAlgorithm::NOT_SET),
55     m_sSEAlgorithmHasBeenSet(false)
56 {
57   *this = xmlNode;
58 }
59 
operator =(const XmlNode & xmlNode)60 S3ObjectMetadata& S3ObjectMetadata::operator =(const XmlNode& xmlNode)
61 {
62   XmlNode resultNode = xmlNode;
63 
64   if(!resultNode.IsNull())
65   {
66     XmlNode cacheControlNode = resultNode.FirstChild("CacheControl");
67     if(!cacheControlNode.IsNull())
68     {
69       m_cacheControl = Aws::Utils::Xml::DecodeEscapedXmlText(cacheControlNode.GetText());
70       m_cacheControlHasBeenSet = true;
71     }
72     XmlNode contentDispositionNode = resultNode.FirstChild("ContentDisposition");
73     if(!contentDispositionNode.IsNull())
74     {
75       m_contentDisposition = Aws::Utils::Xml::DecodeEscapedXmlText(contentDispositionNode.GetText());
76       m_contentDispositionHasBeenSet = true;
77     }
78     XmlNode contentEncodingNode = resultNode.FirstChild("ContentEncoding");
79     if(!contentEncodingNode.IsNull())
80     {
81       m_contentEncoding = Aws::Utils::Xml::DecodeEscapedXmlText(contentEncodingNode.GetText());
82       m_contentEncodingHasBeenSet = true;
83     }
84     XmlNode contentLanguageNode = resultNode.FirstChild("ContentLanguage");
85     if(!contentLanguageNode.IsNull())
86     {
87       m_contentLanguage = Aws::Utils::Xml::DecodeEscapedXmlText(contentLanguageNode.GetText());
88       m_contentLanguageHasBeenSet = true;
89     }
90     XmlNode userMetadataNode = resultNode.FirstChild("UserMetadata");
91 
92     if(!userMetadataNode.IsNull())
93     {
94       XmlNode userMetadataEntry = userMetadataNode.FirstChild("entry");
95       while(!userMetadataEntry.IsNull())
96       {
97         XmlNode keyNode = userMetadataEntry.FirstChild("key");
98         XmlNode valueNode = userMetadataEntry.FirstChild("value");
99         m_userMetadata[keyNode.GetText()] =
100             valueNode.GetText();
101         userMetadataEntry = userMetadataEntry.NextNode("entry");
102       }
103 
104       m_userMetadataHasBeenSet = true;
105     }
106     XmlNode contentLengthNode = resultNode.FirstChild("ContentLength");
107     if(!contentLengthNode.IsNull())
108     {
109       m_contentLength = StringUtils::ConvertToInt64(StringUtils::Trim(Aws::Utils::Xml::DecodeEscapedXmlText(contentLengthNode.GetText()).c_str()).c_str());
110       m_contentLengthHasBeenSet = true;
111     }
112     XmlNode contentMD5Node = resultNode.FirstChild("ContentMD5");
113     if(!contentMD5Node.IsNull())
114     {
115       m_contentMD5 = Aws::Utils::Xml::DecodeEscapedXmlText(contentMD5Node.GetText());
116       m_contentMD5HasBeenSet = true;
117     }
118     XmlNode contentTypeNode = resultNode.FirstChild("ContentType");
119     if(!contentTypeNode.IsNull())
120     {
121       m_contentType = Aws::Utils::Xml::DecodeEscapedXmlText(contentTypeNode.GetText());
122       m_contentTypeHasBeenSet = true;
123     }
124     XmlNode httpExpiresDateNode = resultNode.FirstChild("HttpExpiresDate");
125     if(!httpExpiresDateNode.IsNull())
126     {
127       m_httpExpiresDate = DateTime(StringUtils::Trim(Aws::Utils::Xml::DecodeEscapedXmlText(httpExpiresDateNode.GetText()).c_str()).c_str(), DateFormat::ISO_8601);
128       m_httpExpiresDateHasBeenSet = true;
129     }
130     XmlNode requesterChargedNode = resultNode.FirstChild("RequesterCharged");
131     if(!requesterChargedNode.IsNull())
132     {
133       m_requesterCharged = StringUtils::ConvertToBool(StringUtils::Trim(Aws::Utils::Xml::DecodeEscapedXmlText(requesterChargedNode.GetText()).c_str()).c_str());
134       m_requesterChargedHasBeenSet = true;
135     }
136     XmlNode sSEAlgorithmNode = resultNode.FirstChild("SSEAlgorithm");
137     if(!sSEAlgorithmNode.IsNull())
138     {
139       m_sSEAlgorithm = S3SSEAlgorithmMapper::GetS3SSEAlgorithmForName(StringUtils::Trim(Aws::Utils::Xml::DecodeEscapedXmlText(sSEAlgorithmNode.GetText()).c_str()).c_str());
140       m_sSEAlgorithmHasBeenSet = true;
141     }
142   }
143 
144   return *this;
145 }
146 
AddToNode(XmlNode & parentNode) const147 void S3ObjectMetadata::AddToNode(XmlNode& parentNode) const
148 {
149   Aws::StringStream ss;
150   if(m_cacheControlHasBeenSet)
151   {
152    XmlNode cacheControlNode = parentNode.CreateChildElement("CacheControl");
153    cacheControlNode.SetText(m_cacheControl);
154   }
155 
156   if(m_contentDispositionHasBeenSet)
157   {
158    XmlNode contentDispositionNode = parentNode.CreateChildElement("ContentDisposition");
159    contentDispositionNode.SetText(m_contentDisposition);
160   }
161 
162   if(m_contentEncodingHasBeenSet)
163   {
164    XmlNode contentEncodingNode = parentNode.CreateChildElement("ContentEncoding");
165    contentEncodingNode.SetText(m_contentEncoding);
166   }
167 
168   if(m_contentLanguageHasBeenSet)
169   {
170    XmlNode contentLanguageNode = parentNode.CreateChildElement("ContentLanguage");
171    contentLanguageNode.SetText(m_contentLanguage);
172   }
173 
174   if(m_userMetadataHasBeenSet)
175   {
176   }
177 
178   if(m_contentLengthHasBeenSet)
179   {
180    XmlNode contentLengthNode = parentNode.CreateChildElement("ContentLength");
181    ss << m_contentLength;
182    contentLengthNode.SetText(ss.str());
183    ss.str("");
184   }
185 
186   if(m_contentMD5HasBeenSet)
187   {
188    XmlNode contentMD5Node = parentNode.CreateChildElement("ContentMD5");
189    contentMD5Node.SetText(m_contentMD5);
190   }
191 
192   if(m_contentTypeHasBeenSet)
193   {
194    XmlNode contentTypeNode = parentNode.CreateChildElement("ContentType");
195    contentTypeNode.SetText(m_contentType);
196   }
197 
198   if(m_httpExpiresDateHasBeenSet)
199   {
200    XmlNode httpExpiresDateNode = parentNode.CreateChildElement("HttpExpiresDate");
201    httpExpiresDateNode.SetText(m_httpExpiresDate.ToGmtString(DateFormat::ISO_8601));
202   }
203 
204   if(m_requesterChargedHasBeenSet)
205   {
206    XmlNode requesterChargedNode = parentNode.CreateChildElement("RequesterCharged");
207    ss << std::boolalpha << m_requesterCharged;
208    requesterChargedNode.SetText(ss.str());
209    ss.str("");
210   }
211 
212   if(m_sSEAlgorithmHasBeenSet)
213   {
214    XmlNode sSEAlgorithmNode = parentNode.CreateChildElement("SSEAlgorithm");
215    sSEAlgorithmNode.SetText(S3SSEAlgorithmMapper::GetNameForS3SSEAlgorithm(m_sSEAlgorithm));
216   }
217 
218 }
219 
220 } // namespace Model
221 } // namespace S3Control
222 } // namespace Aws
223