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/CSVInput.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
33CSVInput::CSVInput() :
34 m_fileHeaderInfo(FileHeaderInfo::NOT_SET),
35 m_fileHeaderInfoHasBeenSet(false),
36 m_commentsHasBeenSet(false),
37 m_quoteEscapeCharacterHasBeenSet(false),
38 m_recordDelimiterHasBeenSet(false),
39 m_fieldDelimiterHasBeenSet(false),
40 m_quoteCharacterHasBeenSet(false),
41 m_allowQuotedRecordDelimiter(false),
42 m_allowQuotedRecordDelimiterHasBeenSet(false)
43{
44}
45
46CSVInput::CSVInput(const XmlNode& xmlNode) :
47 m_fileHeaderInfo(FileHeaderInfo::NOT_SET),
48 m_fileHeaderInfoHasBeenSet(false),
49 m_commentsHasBeenSet(false),
50 m_quoteEscapeCharacterHasBeenSet(false),
51 m_recordDelimiterHasBeenSet(false),
52 m_fieldDelimiterHasBeenSet(false),
53 m_quoteCharacterHasBeenSet(false),
54 m_allowQuotedRecordDelimiter(false),
55 m_allowQuotedRecordDelimiterHasBeenSet(false)
56{
57 *this = xmlNode;
58}
59
60CSVInput& CSVInput::operator =(const XmlNode& xmlNode)
61{
62 XmlNode resultNode = xmlNode;
63
64 if(!resultNode.IsNull())
65 {
66 XmlNode fileHeaderInfoNode = resultNode.FirstChild("FileHeaderInfo");
67 if(!fileHeaderInfoNode.IsNull())
68 {
69 m_fileHeaderInfo = FileHeaderInfoMapper::GetFileHeaderInfoForName(StringUtils::Trim(Aws::Utils::Xml::DecodeEscapedXmlText(fileHeaderInfoNode.GetText()).c_str()).c_str());
70 m_fileHeaderInfoHasBeenSet = true;
71 }
72 XmlNode commentsNode = resultNode.FirstChild("Comments");
73 if(!commentsNode.IsNull())
74 {
75 m_comments = Aws::Utils::Xml::DecodeEscapedXmlText(commentsNode.GetText());
76 m_commentsHasBeenSet = true;
77 }
78 XmlNode quoteEscapeCharacterNode = resultNode.FirstChild("QuoteEscapeCharacter");
79 if(!quoteEscapeCharacterNode.IsNull())
80 {
81 m_quoteEscapeCharacter = Aws::Utils::Xml::DecodeEscapedXmlText(quoteEscapeCharacterNode.GetText());
82 m_quoteEscapeCharacterHasBeenSet = true;
83 }
84 XmlNode recordDelimiterNode = resultNode.FirstChild("RecordDelimiter");
85 if(!recordDelimiterNode.IsNull())
86 {
87 m_recordDelimiter = Aws::Utils::Xml::DecodeEscapedXmlText(recordDelimiterNode.GetText());
88 m_recordDelimiterHasBeenSet = true;
89 }
90 XmlNode fieldDelimiterNode = resultNode.FirstChild("FieldDelimiter");
91 if(!fieldDelimiterNode.IsNull())
92 {
93 m_fieldDelimiter = Aws::Utils::Xml::DecodeEscapedXmlText(fieldDelimiterNode.GetText());
94 m_fieldDelimiterHasBeenSet = true;
95 }
96 XmlNode quoteCharacterNode = resultNode.FirstChild("QuoteCharacter");
97 if(!quoteCharacterNode.IsNull())
98 {
99 m_quoteCharacter = Aws::Utils::Xml::DecodeEscapedXmlText(quoteCharacterNode.GetText());
100 m_quoteCharacterHasBeenSet = true;
101 }
102 XmlNode allowQuotedRecordDelimiterNode = resultNode.FirstChild("AllowQuotedRecordDelimiter");
103 if(!allowQuotedRecordDelimiterNode.IsNull())
104 {
105 m_allowQuotedRecordDelimiter = StringUtils::ConvertToBool(StringUtils::Trim(Aws::Utils::Xml::DecodeEscapedXmlText(allowQuotedRecordDelimiterNode.GetText()).c_str()).c_str());
106 m_allowQuotedRecordDelimiterHasBeenSet = true;
107 }
108 }
109
110 return *this;
111}
112
113void CSVInput::AddToNode(XmlNode& parentNode) const
114{
115 Aws::StringStream ss;
116 if(m_fileHeaderInfoHasBeenSet)
117 {
118 XmlNode fileHeaderInfoNode = parentNode.CreateChildElement("FileHeaderInfo");
119 fileHeaderInfoNode.SetText(FileHeaderInfoMapper::GetNameForFileHeaderInfo(m_fileHeaderInfo));
120 }
121
122 if(m_commentsHasBeenSet)
123 {
124 XmlNode commentsNode = parentNode.CreateChildElement("Comments");
125 commentsNode.SetText(m_comments);
126 }
127
128 if(m_quoteEscapeCharacterHasBeenSet)
129 {
130 XmlNode quoteEscapeCharacterNode = parentNode.CreateChildElement("QuoteEscapeCharacter");
131 quoteEscapeCharacterNode.SetText(m_quoteEscapeCharacter);
132 }
133
134 if(m_recordDelimiterHasBeenSet)
135 {
136 XmlNode recordDelimiterNode = parentNode.CreateChildElement("RecordDelimiter");
137 recordDelimiterNode.SetText(m_recordDelimiter);
138 }
139
140 if(m_fieldDelimiterHasBeenSet)
141 {
142 XmlNode fieldDelimiterNode = parentNode.CreateChildElement("FieldDelimiter");
143 fieldDelimiterNode.SetText(m_fieldDelimiter);
144 }
145
146 if(m_quoteCharacterHasBeenSet)
147 {
148 XmlNode quoteCharacterNode = parentNode.CreateChildElement("QuoteCharacter");
149 quoteCharacterNode.SetText(m_quoteCharacter);
150 }
151
152 if(m_allowQuotedRecordDelimiterHasBeenSet)
153 {
154 XmlNode allowQuotedRecordDelimiterNode = parentNode.CreateChildElement("AllowQuotedRecordDelimiter");
155 ss << std::boolalpha << m_allowQuotedRecordDelimiter;
156 allowQuotedRecordDelimiterNode.SetText(ss.str());
157 ss.str("");
158 }
159
160}
161
162} // namespace Model
163} // namespace S3
164} // namespace Aws
165