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/DeleteObjectsRequest.h>
19 #include <sstream>
20 #include "utils/Utils.h"
21 
22 using namespace AlibabaCloud::OSS;
23 
DeleteObjectsRequest(const std::string & bucket)24 DeleteObjectsRequest::DeleteObjectsRequest(const std::string &bucket) :
25     OssBucketRequest(bucket),
26     quiet_(false),
27     encodingType_(),
28     requestPayer_(RequestPayer::NotSet)
29 {
30     setFlags(Flags() | REQUEST_FLAG_CONTENTMD5);
31 }
32 
Quiet() const33 bool DeleteObjectsRequest::Quiet() const
34 {
35     return quiet_;
36 }
37 
EncodingType() const38 const std::string &DeleteObjectsRequest::EncodingType() const
39 {
40     return encodingType_;
41 }
42 
KeyList() const43 const std::list<std::string> &DeleteObjectsRequest::KeyList() const
44 {
45     return keyList_;
46 }
47 
setQuiet(bool quiet)48 void DeleteObjectsRequest::setQuiet(bool quiet)
49 {
50     quiet_ = quiet;
51 }
52 
setEncodingType(const std::string & value)53 void DeleteObjectsRequest::setEncodingType(const std::string &value)
54 {
55     encodingType_ = value;
56 }
57 
addKey(const std::string & key)58 void DeleteObjectsRequest::addKey(const std::string &key)
59 {
60     keyList_.push_back(key);
61 }
62 
setKeyList(const DeletedKeyList & keyList)63 void DeleteObjectsRequest::setKeyList(const DeletedKeyList &keyList)
64 {
65     keyList_ = keyList;
66 }
67 
clearKeyList()68 void DeleteObjectsRequest::clearKeyList()
69 {
70     keyList_.clear();
71 }
72 
setRequestPayer(RequestPayer value)73 void DeleteObjectsRequest::setRequestPayer(RequestPayer value)
74 {
75     requestPayer_ = value;
76 }
77 
payload() const78 std::string DeleteObjectsRequest::payload() const
79 {
80     std::stringstream ss;
81     ss << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl;
82     ss << "<Delete>" << std::endl;
83     ss << "  <Quiet>" << (quiet_ ? "true":"false") << "</Quiet>" << std::endl;
84     for (auto const &key : keyList_) {
85     ss << "  <Object>" << std::endl << "";
86     ss << "    <Key>" << XmlEscape(key) << "</Key>" << std::endl;
87     ss << "  </Object>" << std::endl;
88     }
89     ss << "</Delete>" << std::endl;
90     return ss.str();
91 }
92 
specialParameters() const93 ParameterCollection DeleteObjectsRequest::specialParameters() const
94 {
95     ParameterCollection parameters;
96     parameters["delete"] = "";
97     if (!encodingType_.empty()) {
98         parameters["encoding-type"] = encodingType_;
99     }
100     return parameters;
101 }
102 
specialHeaders() const103 HeaderCollection DeleteObjectsRequest::specialHeaders() const
104 {
105     HeaderCollection headers;
106     if (requestPayer_ == RequestPayer::Requester) {
107         headers["x-oss-request-payer"] = ToLower(ToRequestPayerName(RequestPayer::Requester));
108     }
109     return headers;
110 }
111