| 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/WebsiteConfiguration.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 | WebsiteConfiguration::WebsiteConfiguration() : |
| 34 | m_errorDocumentHasBeenSet(false), |
| 35 | m_indexDocumentHasBeenSet(false), |
| 36 | m_redirectAllRequestsToHasBeenSet(false), |
| 37 | m_routingRulesHasBeenSet(false) |
| 38 | { |
| 39 | } |
| 40 | |
| 41 | WebsiteConfiguration::WebsiteConfiguration(const XmlNode& xmlNode) : |
| 42 | m_errorDocumentHasBeenSet(false), |
| 43 | m_indexDocumentHasBeenSet(false), |
| 44 | m_redirectAllRequestsToHasBeenSet(false), |
| 45 | m_routingRulesHasBeenSet(false) |
| 46 | { |
| 47 | *this = xmlNode; |
| 48 | } |
| 49 | |
| 50 | WebsiteConfiguration& WebsiteConfiguration::operator =(const XmlNode& xmlNode) |
| 51 | { |
| 52 | XmlNode resultNode = xmlNode; |
| 53 | |
| 54 | if(!resultNode.IsNull()) |
| 55 | { |
| 56 | XmlNode errorDocumentNode = resultNode.FirstChild("ErrorDocument" ); |
| 57 | if(!errorDocumentNode.IsNull()) |
| 58 | { |
| 59 | m_errorDocument = errorDocumentNode; |
| 60 | m_errorDocumentHasBeenSet = true; |
| 61 | } |
| 62 | XmlNode indexDocumentNode = resultNode.FirstChild("IndexDocument" ); |
| 63 | if(!indexDocumentNode.IsNull()) |
| 64 | { |
| 65 | m_indexDocument = indexDocumentNode; |
| 66 | m_indexDocumentHasBeenSet = true; |
| 67 | } |
| 68 | XmlNode redirectAllRequestsToNode = resultNode.FirstChild("RedirectAllRequestsTo" ); |
| 69 | if(!redirectAllRequestsToNode.IsNull()) |
| 70 | { |
| 71 | m_redirectAllRequestsTo = redirectAllRequestsToNode; |
| 72 | m_redirectAllRequestsToHasBeenSet = true; |
| 73 | } |
| 74 | XmlNode routingRulesNode = resultNode.FirstChild("RoutingRules" ); |
| 75 | if(!routingRulesNode.IsNull()) |
| 76 | { |
| 77 | XmlNode routingRulesMember = routingRulesNode.FirstChild("RoutingRule" ); |
| 78 | while(!routingRulesMember.IsNull()) |
| 79 | { |
| 80 | m_routingRules.push_back(routingRulesMember); |
| 81 | routingRulesMember = routingRulesMember.NextNode("RoutingRule" ); |
| 82 | } |
| 83 | |
| 84 | m_routingRulesHasBeenSet = true; |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | return *this; |
| 89 | } |
| 90 | |
| 91 | void WebsiteConfiguration::AddToNode(XmlNode& parentNode) const |
| 92 | { |
| 93 | Aws::StringStream ss; |
| 94 | if(m_errorDocumentHasBeenSet) |
| 95 | { |
| 96 | XmlNode errorDocumentNode = parentNode.CreateChildElement("ErrorDocument" ); |
| 97 | m_errorDocument.AddToNode(errorDocumentNode); |
| 98 | } |
| 99 | |
| 100 | if(m_indexDocumentHasBeenSet) |
| 101 | { |
| 102 | XmlNode indexDocumentNode = parentNode.CreateChildElement("IndexDocument" ); |
| 103 | m_indexDocument.AddToNode(indexDocumentNode); |
| 104 | } |
| 105 | |
| 106 | if(m_redirectAllRequestsToHasBeenSet) |
| 107 | { |
| 108 | XmlNode redirectAllRequestsToNode = parentNode.CreateChildElement("RedirectAllRequestsTo" ); |
| 109 | m_redirectAllRequestsTo.AddToNode(redirectAllRequestsToNode); |
| 110 | } |
| 111 | |
| 112 | if(m_routingRulesHasBeenSet) |
| 113 | { |
| 114 | XmlNode routingRulesParentNode = parentNode.CreateChildElement("RoutingRules" ); |
| 115 | for(const auto& item : m_routingRules) |
| 116 | { |
| 117 | XmlNode routingRulesNode = routingRulesParentNode.CreateChildElement("RoutingRule" ); |
| 118 | item.AddToNode(routingRulesNode); |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | } |
| 123 | |
| 124 | } // namespace Model |
| 125 | } // namespace S3 |
| 126 | } // namespace Aws |
| 127 | |