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 #include <alibabacloud/oss/model/DeleteObjectsResult.h>
18 #include <external/tinyxml2/tinyxml2.h>
19 #include "utils/Utils.h"
20
21 using namespace AlibabaCloud::OSS;
22 using namespace tinyxml2;
23
24
DeleteObjectsResult()25 DeleteObjectsResult::DeleteObjectsResult() :
26 OssResult(),
27 quiet_(false),
28 keyList_()
29 {
30 }
31
DeleteObjectsResult(const std::string & result)32 DeleteObjectsResult::DeleteObjectsResult(const std::string& result) :
33 DeleteObjectsResult()
34 {
35 *this = result;
36 }
37
DeleteObjectsResult(const std::shared_ptr<std::iostream> & result)38 DeleteObjectsResult::DeleteObjectsResult(const std::shared_ptr<std::iostream>& result) :
39 DeleteObjectsResult()
40 {
41 std::istreambuf_iterator<char> isb(*result.get()), end;
42 std::string str(isb, end);
43 *this = str;
44 }
45
operator =(const std::string & result)46 DeleteObjectsResult& DeleteObjectsResult::operator =(const std::string& result)
47 {
48 if (result.empty()) {
49 quiet_ = true;
50 parseDone_ = true;
51 return *this;
52 }
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("DeleteResult", root->Name(), 12)) {
59 XMLElement *node;
60 std::string encodeType;
61 node = root->FirstChildElement("EncodingType");
62 if (node && node->GetText()) encodeType = node->GetText();
63
64 bool useUrlDecode = !ToLower(encodeType.c_str()).compare(0, 3, "url", 3);
65
66 //Deleted
67 node = root->FirstChildElement("Deleted");
68 for (; node; node = node->NextSiblingElement("Deleted")) {
69 XMLElement *sub_node;
70 sub_node = node->FirstChildElement("Key");
71 if (sub_node && sub_node->GetText()) keyList_.push_back(useUrlDecode?UrlDecode(sub_node->GetText()):sub_node->GetText());
72 }
73 }
74 parseDone_ = true;
75 }
76 return *this;
77 }
78
Quiet() const79 bool DeleteObjectsResult::Quiet() const
80 {
81 return quiet_;
82 }
83
keyList() const84 const std::list<std::string>& DeleteObjectsResult::keyList() const
85 {
86 return keyList_;
87 }
88
89