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/Part.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 | Part::Part() : |
34 | m_partNumber(0), |
35 | m_partNumberHasBeenSet(false), |
36 | m_lastModifiedHasBeenSet(false), |
37 | m_eTagHasBeenSet(false), |
38 | m_size(0), |
39 | m_sizeHasBeenSet(false) |
40 | { |
41 | } |
42 | |
43 | Part::Part(const XmlNode& xmlNode) : |
44 | m_partNumber(0), |
45 | m_partNumberHasBeenSet(false), |
46 | m_lastModifiedHasBeenSet(false), |
47 | m_eTagHasBeenSet(false), |
48 | m_size(0), |
49 | m_sizeHasBeenSet(false) |
50 | { |
51 | *this = xmlNode; |
52 | } |
53 | |
54 | Part& Part::operator =(const XmlNode& xmlNode) |
55 | { |
56 | XmlNode resultNode = xmlNode; |
57 | |
58 | if(!resultNode.IsNull()) |
59 | { |
60 | XmlNode partNumberNode = resultNode.FirstChild("PartNumber" ); |
61 | if(!partNumberNode.IsNull()) |
62 | { |
63 | m_partNumber = StringUtils::ConvertToInt32(StringUtils::Trim(Aws::Utils::Xml::DecodeEscapedXmlText(partNumberNode.GetText()).c_str()).c_str()); |
64 | m_partNumberHasBeenSet = true; |
65 | } |
66 | XmlNode lastModifiedNode = resultNode.FirstChild("LastModified" ); |
67 | if(!lastModifiedNode.IsNull()) |
68 | { |
69 | m_lastModified = DateTime(StringUtils::Trim(Aws::Utils::Xml::DecodeEscapedXmlText(lastModifiedNode.GetText()).c_str()).c_str(), DateFormat::ISO_8601); |
70 | m_lastModifiedHasBeenSet = true; |
71 | } |
72 | XmlNode eTagNode = resultNode.FirstChild("ETag" ); |
73 | if(!eTagNode.IsNull()) |
74 | { |
75 | m_eTag = Aws::Utils::Xml::DecodeEscapedXmlText(eTagNode.GetText()); |
76 | m_eTagHasBeenSet = true; |
77 | } |
78 | XmlNode sizeNode = resultNode.FirstChild("Size" ); |
79 | if(!sizeNode.IsNull()) |
80 | { |
81 | m_size = StringUtils::ConvertToInt64(StringUtils::Trim(Aws::Utils::Xml::DecodeEscapedXmlText(sizeNode.GetText()).c_str()).c_str()); |
82 | m_sizeHasBeenSet = true; |
83 | } |
84 | } |
85 | |
86 | return *this; |
87 | } |
88 | |
89 | void Part::AddToNode(XmlNode& parentNode) const |
90 | { |
91 | Aws::StringStream ss; |
92 | if(m_partNumberHasBeenSet) |
93 | { |
94 | XmlNode partNumberNode = parentNode.CreateChildElement("PartNumber" ); |
95 | ss << m_partNumber; |
96 | partNumberNode.SetText(ss.str()); |
97 | ss.str("" ); |
98 | } |
99 | |
100 | if(m_lastModifiedHasBeenSet) |
101 | { |
102 | XmlNode lastModifiedNode = parentNode.CreateChildElement("LastModified" ); |
103 | lastModifiedNode.SetText(m_lastModified.ToGmtString(DateFormat::ISO_8601)); |
104 | } |
105 | |
106 | if(m_eTagHasBeenSet) |
107 | { |
108 | XmlNode eTagNode = parentNode.CreateChildElement("ETag" ); |
109 | eTagNode.SetText(m_eTag); |
110 | } |
111 | |
112 | if(m_sizeHasBeenSet) |
113 | { |
114 | XmlNode sizeNode = parentNode.CreateChildElement("Size" ); |
115 | ss << m_size; |
116 | sizeNode.SetText(ss.str()); |
117 | ss.str("" ); |
118 | } |
119 | |
120 | } |
121 | |
122 | } // namespace Model |
123 | } // namespace S3 |
124 | } // namespace Aws |
125 | |