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/LifecycleRule.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 | LifecycleRule::LifecycleRule() : |
34 | m_expirationHasBeenSet(false), |
35 | m_iDHasBeenSet(false), |
36 | m_filterHasBeenSet(false), |
37 | m_status(ExpirationStatus::NOT_SET), |
38 | m_statusHasBeenSet(false), |
39 | m_transitionsHasBeenSet(false), |
40 | m_noncurrentVersionTransitionsHasBeenSet(false), |
41 | m_noncurrentVersionExpirationHasBeenSet(false), |
42 | m_abortIncompleteMultipartUploadHasBeenSet(false) |
43 | { |
44 | } |
45 | |
46 | LifecycleRule::LifecycleRule(const XmlNode& xmlNode) : |
47 | m_expirationHasBeenSet(false), |
48 | m_iDHasBeenSet(false), |
49 | m_filterHasBeenSet(false), |
50 | m_status(ExpirationStatus::NOT_SET), |
51 | m_statusHasBeenSet(false), |
52 | m_transitionsHasBeenSet(false), |
53 | m_noncurrentVersionTransitionsHasBeenSet(false), |
54 | m_noncurrentVersionExpirationHasBeenSet(false), |
55 | m_abortIncompleteMultipartUploadHasBeenSet(false) |
56 | { |
57 | *this = xmlNode; |
58 | } |
59 | |
60 | LifecycleRule& LifecycleRule::operator =(const XmlNode& xmlNode) |
61 | { |
62 | XmlNode resultNode = xmlNode; |
63 | |
64 | if(!resultNode.IsNull()) |
65 | { |
66 | XmlNode expirationNode = resultNode.FirstChild("Expiration" ); |
67 | if(!expirationNode.IsNull()) |
68 | { |
69 | m_expiration = expirationNode; |
70 | m_expirationHasBeenSet = true; |
71 | } |
72 | XmlNode iDNode = resultNode.FirstChild("ID" ); |
73 | if(!iDNode.IsNull()) |
74 | { |
75 | m_iD = Aws::Utils::Xml::DecodeEscapedXmlText(iDNode.GetText()); |
76 | m_iDHasBeenSet = true; |
77 | } |
78 | XmlNode filterNode = resultNode.FirstChild("Filter" ); |
79 | if(!filterNode.IsNull()) |
80 | { |
81 | m_filter = filterNode; |
82 | m_filterHasBeenSet = true; |
83 | } |
84 | XmlNode statusNode = resultNode.FirstChild("Status" ); |
85 | if(!statusNode.IsNull()) |
86 | { |
87 | m_status = ExpirationStatusMapper::GetExpirationStatusForName(StringUtils::Trim(Aws::Utils::Xml::DecodeEscapedXmlText(statusNode.GetText()).c_str()).c_str()); |
88 | m_statusHasBeenSet = true; |
89 | } |
90 | XmlNode transitionsNode = resultNode.FirstChild("Transition" ); |
91 | if(!transitionsNode.IsNull()) |
92 | { |
93 | XmlNode transitionMember = transitionsNode; |
94 | while(!transitionMember.IsNull()) |
95 | { |
96 | m_transitions.push_back(transitionMember); |
97 | transitionMember = transitionMember.NextNode("Transition" ); |
98 | } |
99 | |
100 | m_transitionsHasBeenSet = true; |
101 | } |
102 | XmlNode noncurrentVersionTransitionsNode = resultNode.FirstChild("NoncurrentVersionTransition" ); |
103 | if(!noncurrentVersionTransitionsNode.IsNull()) |
104 | { |
105 | XmlNode noncurrentVersionTransitionMember = noncurrentVersionTransitionsNode; |
106 | while(!noncurrentVersionTransitionMember.IsNull()) |
107 | { |
108 | m_noncurrentVersionTransitions.push_back(noncurrentVersionTransitionMember); |
109 | noncurrentVersionTransitionMember = noncurrentVersionTransitionMember.NextNode("NoncurrentVersionTransition" ); |
110 | } |
111 | |
112 | m_noncurrentVersionTransitionsHasBeenSet = true; |
113 | } |
114 | XmlNode noncurrentVersionExpirationNode = resultNode.FirstChild("NoncurrentVersionExpiration" ); |
115 | if(!noncurrentVersionExpirationNode.IsNull()) |
116 | { |
117 | m_noncurrentVersionExpiration = noncurrentVersionExpirationNode; |
118 | m_noncurrentVersionExpirationHasBeenSet = true; |
119 | } |
120 | XmlNode abortIncompleteMultipartUploadNode = resultNode.FirstChild("AbortIncompleteMultipartUpload" ); |
121 | if(!abortIncompleteMultipartUploadNode.IsNull()) |
122 | { |
123 | m_abortIncompleteMultipartUpload = abortIncompleteMultipartUploadNode; |
124 | m_abortIncompleteMultipartUploadHasBeenSet = true; |
125 | } |
126 | } |
127 | |
128 | return *this; |
129 | } |
130 | |
131 | void LifecycleRule::AddToNode(XmlNode& parentNode) const |
132 | { |
133 | Aws::StringStream ss; |
134 | if(m_expirationHasBeenSet) |
135 | { |
136 | XmlNode expirationNode = parentNode.CreateChildElement("Expiration" ); |
137 | m_expiration.AddToNode(expirationNode); |
138 | } |
139 | |
140 | if(m_iDHasBeenSet) |
141 | { |
142 | XmlNode iDNode = parentNode.CreateChildElement("ID" ); |
143 | iDNode.SetText(m_iD); |
144 | } |
145 | |
146 | if(m_filterHasBeenSet) |
147 | { |
148 | XmlNode filterNode = parentNode.CreateChildElement("Filter" ); |
149 | m_filter.AddToNode(filterNode); |
150 | } |
151 | |
152 | if(m_statusHasBeenSet) |
153 | { |
154 | XmlNode statusNode = parentNode.CreateChildElement("Status" ); |
155 | statusNode.SetText(ExpirationStatusMapper::GetNameForExpirationStatus(m_status)); |
156 | } |
157 | |
158 | if(m_transitionsHasBeenSet) |
159 | { |
160 | for(const auto& item : m_transitions) |
161 | { |
162 | XmlNode transitionsNode = parentNode.CreateChildElement("Transition" ); |
163 | item.AddToNode(transitionsNode); |
164 | } |
165 | } |
166 | |
167 | if(m_noncurrentVersionTransitionsHasBeenSet) |
168 | { |
169 | for(const auto& item : m_noncurrentVersionTransitions) |
170 | { |
171 | XmlNode noncurrentVersionTransitionsNode = parentNode.CreateChildElement("NoncurrentVersionTransition" ); |
172 | item.AddToNode(noncurrentVersionTransitionsNode); |
173 | } |
174 | } |
175 | |
176 | if(m_noncurrentVersionExpirationHasBeenSet) |
177 | { |
178 | XmlNode noncurrentVersionExpirationNode = parentNode.CreateChildElement("NoncurrentVersionExpiration" ); |
179 | m_noncurrentVersionExpiration.AddToNode(noncurrentVersionExpirationNode); |
180 | } |
181 | |
182 | if(m_abortIncompleteMultipartUploadHasBeenSet) |
183 | { |
184 | XmlNode abortIncompleteMultipartUploadNode = parentNode.CreateChildElement("AbortIncompleteMultipartUpload" ); |
185 | m_abortIncompleteMultipartUpload.AddToNode(abortIncompleteMultipartUploadNode); |
186 | } |
187 | |
188 | } |
189 | |
190 | } // namespace Model |
191 | } // namespace S3 |
192 | } // namespace Aws |
193 | |