1 /*
2 * Copyright 2009-2017 Alibaba Cloud 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 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17
18 #include <alibabacloud/oss/model/GetObjectTaggingResult.h>
19 #include <external/tinyxml2/tinyxml2.h>
20 #include "utils/Utils.h"
21 using namespace AlibabaCloud::OSS;
22 using namespace tinyxml2;
23
GetObjectTaggingResult()24 GetObjectTaggingResult::GetObjectTaggingResult() :
25 OssObjectResult()
26 {
27 }
28
GetObjectTaggingResult(const std::string & result)29 GetObjectTaggingResult::GetObjectTaggingResult(const std::string& result):
30 GetObjectTaggingResult()
31 {
32 *this = result;
33 }
34
GetObjectTaggingResult(const std::shared_ptr<std::iostream> & result)35 GetObjectTaggingResult::GetObjectTaggingResult(const std::shared_ptr<std::iostream>& result):
36 GetObjectTaggingResult()
37 {
38 std::istreambuf_iterator<char> isb(*result.get()), end;
39 std::string str(isb, end);
40 *this = str;
41 }
42
GetObjectTaggingResult(const HeaderCollection & headers,const std::shared_ptr<std::iostream> & result)43 GetObjectTaggingResult::GetObjectTaggingResult(const HeaderCollection& headers,
44 const std::shared_ptr<std::iostream>& result):
45 OssObjectResult(headers)
46 {
47 std::istreambuf_iterator<char> isb(*result.get()), end;
48 std::string str(isb, end);
49 *this = str;
50 }
51
operator =(const std::string & result)52 GetObjectTaggingResult& GetObjectTaggingResult::operator =(const std::string& result)
53 {
54 XMLDocument doc;
55 XMLError xml_err;
56 if ((xml_err = doc.Parse(result.c_str(), result.size())) == XML_SUCCESS) {
57 XMLElement* root =doc.RootElement();
58 if (root && !std::strncmp("Tagging", root->Name(), 7)) {
59 XMLElement* tagSet_node = root->FirstChildElement("TagSet");
60 if (tagSet_node) {
61 XMLElement *tag_node = tagSet_node->FirstChildElement("Tag");
62 for (; tag_node; tag_node = tag_node->NextSiblingElement("Tag")) {
63 XMLElement *subNode;
64 Tag tag;
65 //Key
66 subNode = tag_node->FirstChildElement("Key");
67 if (subNode && subNode->GetText()) {
68 tag.setKey(subNode->GetText());
69 }
70 //Value
71 subNode = tag_node->FirstChildElement("Value");
72 if (subNode && subNode->GetText()) {
73 tag.setValue(subNode->GetText());
74 }
75 tagging_.addTag(tag);
76 }
77 }
78 //TODO check the result and the parse flag;
79 parseDone_ = true;
80 }
81 }
82 return *this;
83 }
84
85