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/ObjectVersion.h> |
17 | #include <aws/core/utils/xml/XmlSerializer.h> |
18 | #include <aws/core/utils/StringUtils.h> |
19 | #include <aws/core/utils/memory/stl/AWSStringStream.h> |
20 | |
21 | #include <utility> |
22 | |
23 | using namespace Aws::Utils::Xml; |
24 | using namespace Aws::Utils; |
25 | |
26 | namespace Aws |
27 | { |
28 | namespace S3 |
29 | { |
30 | namespace Model |
31 | { |
32 | |
33 | ObjectVersion::ObjectVersion() : |
34 | m_eTagHasBeenSet(false), |
35 | m_size(0), |
36 | m_sizeHasBeenSet(false), |
37 | m_storageClass(ObjectVersionStorageClass::NOT_SET), |
38 | m_storageClassHasBeenSet(false), |
39 | m_keyHasBeenSet(false), |
40 | m_versionIdHasBeenSet(false), |
41 | m_isLatest(false), |
42 | m_isLatestHasBeenSet(false), |
43 | m_lastModifiedHasBeenSet(false), |
44 | m_ownerHasBeenSet(false) |
45 | { |
46 | } |
47 | |
48 | ObjectVersion::ObjectVersion(const XmlNode& xmlNode) : |
49 | m_eTagHasBeenSet(false), |
50 | m_size(0), |
51 | m_sizeHasBeenSet(false), |
52 | m_storageClass(ObjectVersionStorageClass::NOT_SET), |
53 | m_storageClassHasBeenSet(false), |
54 | m_keyHasBeenSet(false), |
55 | m_versionIdHasBeenSet(false), |
56 | m_isLatest(false), |
57 | m_isLatestHasBeenSet(false), |
58 | m_lastModifiedHasBeenSet(false), |
59 | m_ownerHasBeenSet(false) |
60 | { |
61 | *this = xmlNode; |
62 | } |
63 | |
64 | ObjectVersion& ObjectVersion::operator =(const XmlNode& xmlNode) |
65 | { |
66 | XmlNode resultNode = xmlNode; |
67 | |
68 | if(!resultNode.IsNull()) |
69 | { |
70 | XmlNode eTagNode = resultNode.FirstChild("ETag" ); |
71 | if(!eTagNode.IsNull()) |
72 | { |
73 | m_eTag = Aws::Utils::Xml::DecodeEscapedXmlText(eTagNode.GetText()); |
74 | m_eTagHasBeenSet = true; |
75 | } |
76 | XmlNode sizeNode = resultNode.FirstChild("Size" ); |
77 | if(!sizeNode.IsNull()) |
78 | { |
79 | m_size = StringUtils::ConvertToInt64(StringUtils::Trim(Aws::Utils::Xml::DecodeEscapedXmlText(sizeNode.GetText()).c_str()).c_str()); |
80 | m_sizeHasBeenSet = true; |
81 | } |
82 | XmlNode storageClassNode = resultNode.FirstChild("StorageClass" ); |
83 | if(!storageClassNode.IsNull()) |
84 | { |
85 | m_storageClass = ObjectVersionStorageClassMapper::GetObjectVersionStorageClassForName(StringUtils::Trim(Aws::Utils::Xml::DecodeEscapedXmlText(storageClassNode.GetText()).c_str()).c_str()); |
86 | m_storageClassHasBeenSet = true; |
87 | } |
88 | XmlNode keyNode = resultNode.FirstChild("Key" ); |
89 | if(!keyNode.IsNull()) |
90 | { |
91 | m_key = Aws::Utils::Xml::DecodeEscapedXmlText(keyNode.GetText()); |
92 | m_keyHasBeenSet = true; |
93 | } |
94 | XmlNode versionIdNode = resultNode.FirstChild("VersionId" ); |
95 | if(!versionIdNode.IsNull()) |
96 | { |
97 | m_versionId = Aws::Utils::Xml::DecodeEscapedXmlText(versionIdNode.GetText()); |
98 | m_versionIdHasBeenSet = true; |
99 | } |
100 | XmlNode isLatestNode = resultNode.FirstChild("IsLatest" ); |
101 | if(!isLatestNode.IsNull()) |
102 | { |
103 | m_isLatest = StringUtils::ConvertToBool(StringUtils::Trim(Aws::Utils::Xml::DecodeEscapedXmlText(isLatestNode.GetText()).c_str()).c_str()); |
104 | m_isLatestHasBeenSet = true; |
105 | } |
106 | XmlNode lastModifiedNode = resultNode.FirstChild("LastModified" ); |
107 | if(!lastModifiedNode.IsNull()) |
108 | { |
109 | m_lastModified = DateTime(StringUtils::Trim(Aws::Utils::Xml::DecodeEscapedXmlText(lastModifiedNode.GetText()).c_str()).c_str(), DateFormat::ISO_8601); |
110 | m_lastModifiedHasBeenSet = true; |
111 | } |
112 | XmlNode ownerNode = resultNode.FirstChild("Owner" ); |
113 | if(!ownerNode.IsNull()) |
114 | { |
115 | m_owner = ownerNode; |
116 | m_ownerHasBeenSet = true; |
117 | } |
118 | } |
119 | |
120 | return *this; |
121 | } |
122 | |
123 | void ObjectVersion::AddToNode(XmlNode& parentNode) const |
124 | { |
125 | Aws::StringStream ss; |
126 | if(m_eTagHasBeenSet) |
127 | { |
128 | XmlNode eTagNode = parentNode.CreateChildElement("ETag" ); |
129 | eTagNode.SetText(m_eTag); |
130 | } |
131 | |
132 | if(m_sizeHasBeenSet) |
133 | { |
134 | XmlNode sizeNode = parentNode.CreateChildElement("Size" ); |
135 | ss << m_size; |
136 | sizeNode.SetText(ss.str()); |
137 | ss.str("" ); |
138 | } |
139 | |
140 | if(m_storageClassHasBeenSet) |
141 | { |
142 | XmlNode storageClassNode = parentNode.CreateChildElement("StorageClass" ); |
143 | storageClassNode.SetText(ObjectVersionStorageClassMapper::GetNameForObjectVersionStorageClass(m_storageClass)); |
144 | } |
145 | |
146 | if(m_keyHasBeenSet) |
147 | { |
148 | XmlNode keyNode = parentNode.CreateChildElement("Key" ); |
149 | keyNode.SetText(m_key); |
150 | } |
151 | |
152 | if(m_versionIdHasBeenSet) |
153 | { |
154 | XmlNode versionIdNode = parentNode.CreateChildElement("VersionId" ); |
155 | versionIdNode.SetText(m_versionId); |
156 | } |
157 | |
158 | if(m_isLatestHasBeenSet) |
159 | { |
160 | XmlNode isLatestNode = parentNode.CreateChildElement("IsLatest" ); |
161 | ss << std::boolalpha << m_isLatest; |
162 | isLatestNode.SetText(ss.str()); |
163 | ss.str("" ); |
164 | } |
165 | |
166 | if(m_lastModifiedHasBeenSet) |
167 | { |
168 | XmlNode lastModifiedNode = parentNode.CreateChildElement("LastModified" ); |
169 | lastModifiedNode.SetText(m_lastModified.ToGmtString(DateFormat::ISO_8601)); |
170 | } |
171 | |
172 | if(m_ownerHasBeenSet) |
173 | { |
174 | XmlNode ownerNode = parentNode.CreateChildElement("Owner" ); |
175 | m_owner.AddToNode(ownerNode); |
176 | } |
177 | |
178 | } |
179 | |
180 | } // namespace Model |
181 | } // namespace S3 |
182 | } // namespace Aws |
183 | |