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/Redirect.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
33Redirect::Redirect() :
34 m_hostNameHasBeenSet(false),
35 m_httpRedirectCodeHasBeenSet(false),
36 m_protocol(Protocol::NOT_SET),
37 m_protocolHasBeenSet(false),
38 m_replaceKeyPrefixWithHasBeenSet(false),
39 m_replaceKeyWithHasBeenSet(false)
40{
41}
42
43Redirect::Redirect(const XmlNode& xmlNode) :
44 m_hostNameHasBeenSet(false),
45 m_httpRedirectCodeHasBeenSet(false),
46 m_protocol(Protocol::NOT_SET),
47 m_protocolHasBeenSet(false),
48 m_replaceKeyPrefixWithHasBeenSet(false),
49 m_replaceKeyWithHasBeenSet(false)
50{
51 *this = xmlNode;
52}
53
54Redirect& Redirect::operator =(const XmlNode& xmlNode)
55{
56 XmlNode resultNode = xmlNode;
57
58 if(!resultNode.IsNull())
59 {
60 XmlNode hostNameNode = resultNode.FirstChild("HostName");
61 if(!hostNameNode.IsNull())
62 {
63 m_hostName = Aws::Utils::Xml::DecodeEscapedXmlText(hostNameNode.GetText());
64 m_hostNameHasBeenSet = true;
65 }
66 XmlNode httpRedirectCodeNode = resultNode.FirstChild("HttpRedirectCode");
67 if(!httpRedirectCodeNode.IsNull())
68 {
69 m_httpRedirectCode = Aws::Utils::Xml::DecodeEscapedXmlText(httpRedirectCodeNode.GetText());
70 m_httpRedirectCodeHasBeenSet = true;
71 }
72 XmlNode protocolNode = resultNode.FirstChild("Protocol");
73 if(!protocolNode.IsNull())
74 {
75 m_protocol = ProtocolMapper::GetProtocolForName(StringUtils::Trim(Aws::Utils::Xml::DecodeEscapedXmlText(protocolNode.GetText()).c_str()).c_str());
76 m_protocolHasBeenSet = true;
77 }
78 XmlNode replaceKeyPrefixWithNode = resultNode.FirstChild("ReplaceKeyPrefixWith");
79 if(!replaceKeyPrefixWithNode.IsNull())
80 {
81 m_replaceKeyPrefixWith = Aws::Utils::Xml::DecodeEscapedXmlText(replaceKeyPrefixWithNode.GetText());
82 m_replaceKeyPrefixWithHasBeenSet = true;
83 }
84 XmlNode replaceKeyWithNode = resultNode.FirstChild("ReplaceKeyWith");
85 if(!replaceKeyWithNode.IsNull())
86 {
87 m_replaceKeyWith = Aws::Utils::Xml::DecodeEscapedXmlText(replaceKeyWithNode.GetText());
88 m_replaceKeyWithHasBeenSet = true;
89 }
90 }
91
92 return *this;
93}
94
95void Redirect::AddToNode(XmlNode& parentNode) const
96{
97 Aws::StringStream ss;
98 if(m_hostNameHasBeenSet)
99 {
100 XmlNode hostNameNode = parentNode.CreateChildElement("HostName");
101 hostNameNode.SetText(m_hostName);
102 }
103
104 if(m_httpRedirectCodeHasBeenSet)
105 {
106 XmlNode httpRedirectCodeNode = parentNode.CreateChildElement("HttpRedirectCode");
107 httpRedirectCodeNode.SetText(m_httpRedirectCode);
108 }
109
110 if(m_protocolHasBeenSet)
111 {
112 XmlNode protocolNode = parentNode.CreateChildElement("Protocol");
113 protocolNode.SetText(ProtocolMapper::GetNameForProtocol(m_protocol));
114 }
115
116 if(m_replaceKeyPrefixWithHasBeenSet)
117 {
118 XmlNode replaceKeyPrefixWithNode = parentNode.CreateChildElement("ReplaceKeyPrefixWith");
119 replaceKeyPrefixWithNode.SetText(m_replaceKeyPrefixWith);
120 }
121
122 if(m_replaceKeyWithHasBeenSet)
123 {
124 XmlNode replaceKeyWithNode = parentNode.CreateChildElement("ReplaceKeyWith");
125 replaceKeyWithNode.SetText(m_replaceKeyWith);
126 }
127
128}
129
130} // namespace Model
131} // namespace S3
132} // namespace Aws
133