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/S3Location.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 | S3Location::S3Location() : |
34 | m_bucketNameHasBeenSet(false), |
35 | m_prefixHasBeenSet(false), |
36 | m_encryptionHasBeenSet(false), |
37 | m_cannedACL(ObjectCannedACL::NOT_SET), |
38 | m_cannedACLHasBeenSet(false), |
39 | m_accessControlListHasBeenSet(false), |
40 | m_taggingHasBeenSet(false), |
41 | m_userMetadataHasBeenSet(false), |
42 | m_storageClass(StorageClass::NOT_SET), |
43 | m_storageClassHasBeenSet(false) |
44 | { |
45 | } |
46 | |
47 | S3Location::S3Location(const XmlNode& xmlNode) : |
48 | m_bucketNameHasBeenSet(false), |
49 | m_prefixHasBeenSet(false), |
50 | m_encryptionHasBeenSet(false), |
51 | m_cannedACL(ObjectCannedACL::NOT_SET), |
52 | m_cannedACLHasBeenSet(false), |
53 | m_accessControlListHasBeenSet(false), |
54 | m_taggingHasBeenSet(false), |
55 | m_userMetadataHasBeenSet(false), |
56 | m_storageClass(StorageClass::NOT_SET), |
57 | m_storageClassHasBeenSet(false) |
58 | { |
59 | *this = xmlNode; |
60 | } |
61 | |
62 | S3Location& S3Location::operator =(const XmlNode& xmlNode) |
63 | { |
64 | XmlNode resultNode = xmlNode; |
65 | |
66 | if(!resultNode.IsNull()) |
67 | { |
68 | XmlNode bucketNameNode = resultNode.FirstChild("BucketName" ); |
69 | if(!bucketNameNode.IsNull()) |
70 | { |
71 | m_bucketName = Aws::Utils::Xml::DecodeEscapedXmlText(bucketNameNode.GetText()); |
72 | m_bucketNameHasBeenSet = true; |
73 | } |
74 | XmlNode prefixNode = resultNode.FirstChild("Prefix" ); |
75 | if(!prefixNode.IsNull()) |
76 | { |
77 | m_prefix = Aws::Utils::Xml::DecodeEscapedXmlText(prefixNode.GetText()); |
78 | m_prefixHasBeenSet = true; |
79 | } |
80 | XmlNode encryptionNode = resultNode.FirstChild("Encryption" ); |
81 | if(!encryptionNode.IsNull()) |
82 | { |
83 | m_encryption = encryptionNode; |
84 | m_encryptionHasBeenSet = true; |
85 | } |
86 | XmlNode cannedACLNode = resultNode.FirstChild("CannedACL" ); |
87 | if(!cannedACLNode.IsNull()) |
88 | { |
89 | m_cannedACL = ObjectCannedACLMapper::GetObjectCannedACLForName(StringUtils::Trim(Aws::Utils::Xml::DecodeEscapedXmlText(cannedACLNode.GetText()).c_str()).c_str()); |
90 | m_cannedACLHasBeenSet = true; |
91 | } |
92 | XmlNode accessControlListNode = resultNode.FirstChild("AccessControlList" ); |
93 | if(!accessControlListNode.IsNull()) |
94 | { |
95 | XmlNode accessControlListMember = accessControlListNode.FirstChild("Grant" ); |
96 | while(!accessControlListMember.IsNull()) |
97 | { |
98 | m_accessControlList.push_back(accessControlListMember); |
99 | accessControlListMember = accessControlListMember.NextNode("Grant" ); |
100 | } |
101 | |
102 | m_accessControlListHasBeenSet = true; |
103 | } |
104 | XmlNode taggingNode = resultNode.FirstChild("Tagging" ); |
105 | if(!taggingNode.IsNull()) |
106 | { |
107 | m_tagging = taggingNode; |
108 | m_taggingHasBeenSet = true; |
109 | } |
110 | XmlNode userMetadataNode = resultNode.FirstChild("UserMetadata" ); |
111 | if(!userMetadataNode.IsNull()) |
112 | { |
113 | XmlNode userMetadataMember = userMetadataNode.FirstChild("MetadataEntry" ); |
114 | while(!userMetadataMember.IsNull()) |
115 | { |
116 | m_userMetadata.push_back(userMetadataMember); |
117 | userMetadataMember = userMetadataMember.NextNode("MetadataEntry" ); |
118 | } |
119 | |
120 | m_userMetadataHasBeenSet = true; |
121 | } |
122 | XmlNode storageClassNode = resultNode.FirstChild("StorageClass" ); |
123 | if(!storageClassNode.IsNull()) |
124 | { |
125 | m_storageClass = StorageClassMapper::GetStorageClassForName(StringUtils::Trim(Aws::Utils::Xml::DecodeEscapedXmlText(storageClassNode.GetText()).c_str()).c_str()); |
126 | m_storageClassHasBeenSet = true; |
127 | } |
128 | } |
129 | |
130 | return *this; |
131 | } |
132 | |
133 | void S3Location::AddToNode(XmlNode& parentNode) const |
134 | { |
135 | Aws::StringStream ss; |
136 | if(m_bucketNameHasBeenSet) |
137 | { |
138 | XmlNode bucketNameNode = parentNode.CreateChildElement("BucketName" ); |
139 | bucketNameNode.SetText(m_bucketName); |
140 | } |
141 | |
142 | if(m_prefixHasBeenSet) |
143 | { |
144 | XmlNode prefixNode = parentNode.CreateChildElement("Prefix" ); |
145 | prefixNode.SetText(m_prefix); |
146 | } |
147 | |
148 | if(m_encryptionHasBeenSet) |
149 | { |
150 | XmlNode encryptionNode = parentNode.CreateChildElement("Encryption" ); |
151 | m_encryption.AddToNode(encryptionNode); |
152 | } |
153 | |
154 | if(m_cannedACLHasBeenSet) |
155 | { |
156 | XmlNode cannedACLNode = parentNode.CreateChildElement("CannedACL" ); |
157 | cannedACLNode.SetText(ObjectCannedACLMapper::GetNameForObjectCannedACL(m_cannedACL)); |
158 | } |
159 | |
160 | if(m_accessControlListHasBeenSet) |
161 | { |
162 | XmlNode accessControlListParentNode = parentNode.CreateChildElement("AccessControlList" ); |
163 | for(const auto& item : m_accessControlList) |
164 | { |
165 | XmlNode accessControlListNode = accessControlListParentNode.CreateChildElement("Grant" ); |
166 | item.AddToNode(accessControlListNode); |
167 | } |
168 | } |
169 | |
170 | if(m_taggingHasBeenSet) |
171 | { |
172 | XmlNode taggingNode = parentNode.CreateChildElement("Tagging" ); |
173 | m_tagging.AddToNode(taggingNode); |
174 | } |
175 | |
176 | if(m_userMetadataHasBeenSet) |
177 | { |
178 | XmlNode userMetadataParentNode = parentNode.CreateChildElement("UserMetadata" ); |
179 | for(const auto& item : m_userMetadata) |
180 | { |
181 | XmlNode userMetadataNode = userMetadataParentNode.CreateChildElement("MetadataEntry" ); |
182 | item.AddToNode(userMetadataNode); |
183 | } |
184 | } |
185 | |
186 | if(m_storageClassHasBeenSet) |
187 | { |
188 | XmlNode storageClassNode = parentNode.CreateChildElement("StorageClass" ); |
189 | storageClassNode.SetText(StorageClassMapper::GetNameForStorageClass(m_storageClass)); |
190 | } |
191 | |
192 | } |
193 | |
194 | } // namespace Model |
195 | } // namespace S3 |
196 | } // namespace Aws |
197 | |