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/Object.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
23using namespace Aws::Utils::Xml;
24using namespace Aws::Utils;
25
26namespace Aws
27{
28namespace S3
29{
30namespace Model
31{
32
33Object::Object() :
34 m_keyHasBeenSet(false),
35 m_lastModifiedHasBeenSet(false),
36 m_eTagHasBeenSet(false),
37 m_size(0),
38 m_sizeHasBeenSet(false),
39 m_storageClass(ObjectStorageClass::NOT_SET),
40 m_storageClassHasBeenSet(false),
41 m_ownerHasBeenSet(false)
42{
43}
44
45Object::Object(const XmlNode& xmlNode) :
46 m_keyHasBeenSet(false),
47 m_lastModifiedHasBeenSet(false),
48 m_eTagHasBeenSet(false),
49 m_size(0),
50 m_sizeHasBeenSet(false),
51 m_storageClass(ObjectStorageClass::NOT_SET),
52 m_storageClassHasBeenSet(false),
53 m_ownerHasBeenSet(false)
54{
55 *this = xmlNode;
56}
57
58Object& Object::operator =(const XmlNode& xmlNode)
59{
60 XmlNode resultNode = xmlNode;
61
62 if(!resultNode.IsNull())
63 {
64 XmlNode keyNode = resultNode.FirstChild("Key");
65 if(!keyNode.IsNull())
66 {
67 m_key = Aws::Utils::Xml::DecodeEscapedXmlText(keyNode.GetText());
68 m_keyHasBeenSet = true;
69 }
70 XmlNode lastModifiedNode = resultNode.FirstChild("LastModified");
71 if(!lastModifiedNode.IsNull())
72 {
73 m_lastModified = DateTime(StringUtils::Trim(Aws::Utils::Xml::DecodeEscapedXmlText(lastModifiedNode.GetText()).c_str()).c_str(), DateFormat::ISO_8601);
74 m_lastModifiedHasBeenSet = true;
75 }
76 XmlNode eTagNode = resultNode.FirstChild("ETag");
77 if(!eTagNode.IsNull())
78 {
79 m_eTag = Aws::Utils::Xml::DecodeEscapedXmlText(eTagNode.GetText());
80 m_eTagHasBeenSet = true;
81 }
82 XmlNode sizeNode = resultNode.FirstChild("Size");
83 if(!sizeNode.IsNull())
84 {
85 m_size = StringUtils::ConvertToInt64(StringUtils::Trim(Aws::Utils::Xml::DecodeEscapedXmlText(sizeNode.GetText()).c_str()).c_str());
86 m_sizeHasBeenSet = true;
87 }
88 XmlNode storageClassNode = resultNode.FirstChild("StorageClass");
89 if(!storageClassNode.IsNull())
90 {
91 m_storageClass = ObjectStorageClassMapper::GetObjectStorageClassForName(StringUtils::Trim(Aws::Utils::Xml::DecodeEscapedXmlText(storageClassNode.GetText()).c_str()).c_str());
92 m_storageClassHasBeenSet = true;
93 }
94 XmlNode ownerNode = resultNode.FirstChild("Owner");
95 if(!ownerNode.IsNull())
96 {
97 m_owner = ownerNode;
98 m_ownerHasBeenSet = true;
99 }
100 }
101
102 return *this;
103}
104
105void Object::AddToNode(XmlNode& parentNode) const
106{
107 Aws::StringStream ss;
108 if(m_keyHasBeenSet)
109 {
110 XmlNode keyNode = parentNode.CreateChildElement("Key");
111 keyNode.SetText(m_key);
112 }
113
114 if(m_lastModifiedHasBeenSet)
115 {
116 XmlNode lastModifiedNode = parentNode.CreateChildElement("LastModified");
117 lastModifiedNode.SetText(m_lastModified.ToGmtString(DateFormat::ISO_8601));
118 }
119
120 if(m_eTagHasBeenSet)
121 {
122 XmlNode eTagNode = parentNode.CreateChildElement("ETag");
123 eTagNode.SetText(m_eTag);
124 }
125
126 if(m_sizeHasBeenSet)
127 {
128 XmlNode sizeNode = parentNode.CreateChildElement("Size");
129 ss << m_size;
130 sizeNode.SetText(ss.str());
131 ss.str("");
132 }
133
134 if(m_storageClassHasBeenSet)
135 {
136 XmlNode storageClassNode = parentNode.CreateChildElement("StorageClass");
137 storageClassNode.SetText(ObjectStorageClassMapper::GetNameForObjectStorageClass(m_storageClass));
138 }
139
140 if(m_ownerHasBeenSet)
141 {
142 XmlNode ownerNode = parentNode.CreateChildElement("Owner");
143 m_owner.AddToNode(ownerNode);
144 }
145
146}
147
148} // namespace Model
149} // namespace S3
150} // namespace Aws
151