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/DeleteObjectVersionsResult.h>
18 #include <external/tinyxml2/tinyxml2.h>
19 #include "utils/Utils.h"
20
21 using namespace AlibabaCloud::OSS;
22 using namespace tinyxml2;
23
24
DeleteObjectVersionsResult()25 DeleteObjectVersionsResult::DeleteObjectVersionsResult() :
26 OssResult(),
27 quiet_(false),
28 deletedObjects_()
29 {
30 }
31
DeleteObjectVersionsResult(const std::string & result)32 DeleteObjectVersionsResult::DeleteObjectVersionsResult(const std::string& result) :
33 DeleteObjectVersionsResult()
34 {
35 *this = result;
36 }
37
DeleteObjectVersionsResult(const std::shared_ptr<std::iostream> & result)38 DeleteObjectVersionsResult::DeleteObjectVersionsResult(const std::shared_ptr<std::iostream>& result) :
39 DeleteObjectVersionsResult()
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 DeleteObjectVersionsResult& DeleteObjectVersionsResult::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 DeletedObject object;
71
72 sub_node = node->FirstChildElement("Key");
73 if (sub_node && sub_node->GetText()) {
74 object.setKey(useUrlDecode ? UrlDecode(sub_node->GetText()) : sub_node->GetText());
75 }
76
77 sub_node = node->FirstChildElement("VersionId");
78 if (sub_node && sub_node->GetText()) {
79 object.setVersionId(sub_node->GetText());
80 }
81
82 sub_node = node->FirstChildElement("DeleteMarker");
83 if (sub_node && sub_node->GetText()) {
84 object.setDeleteMarker(!std::strncmp("true", sub_node->GetText(), 4));
85 }
86
87 sub_node = node->FirstChildElement("DeleteMarkerVersionId");
88 if (sub_node && sub_node->GetText()) {
89 object.setDeleteMarkerVersionId(sub_node->GetText());
90 }
91 deletedObjects_.push_back(object);
92 }
93 }
94 parseDone_ = true;
95 }
96 return *this;
97 }
98
Quiet() const99 bool DeleteObjectVersionsResult::Quiet() const
100 {
101 return quiet_;
102 }
103
DeletedObjects() const104 const DeletedObjectList& DeleteObjectVersionsResult::DeletedObjects() const
105 {
106 return deletedObjects_;
107 }
108
109
110
111