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/InitiateMultipartUploadResult.h>
19 #include <alibabacloud/oss/model/Owner.h>
20 #include <external/tinyxml2/tinyxml2.h>
21 #include "utils/Utils.h"
22 using namespace AlibabaCloud::OSS;
23 using namespace tinyxml2;
24
InitiateMultipartUploadResult()25 InitiateMultipartUploadResult::InitiateMultipartUploadResult() :
26 OssResult()
27 {
28 }
29
InitiateMultipartUploadResult(const std::string & result)30 InitiateMultipartUploadResult::InitiateMultipartUploadResult(const std::string& result):
31 InitiateMultipartUploadResult()
32 {
33 *this = result;
34 }
35
InitiateMultipartUploadResult(const std::shared_ptr<std::iostream> & result)36 InitiateMultipartUploadResult::InitiateMultipartUploadResult(const std::shared_ptr<std::iostream>& result):
37 InitiateMultipartUploadResult()
38 {
39 std::istreambuf_iterator<char> isb(*result.get()), end;
40 std::string str(isb, end);
41 *this = str;
42 }
43
operator =(const std::string & result)44 InitiateMultipartUploadResult& InitiateMultipartUploadResult::operator =(
45 const std::string& result)
46 {
47 XMLDocument doc;
48 XMLError xml_err;
49 if ((xml_err = doc.Parse(result.c_str(), result.size())) == XML_SUCCESS) {
50 XMLElement* root =doc.RootElement();
51 if (root && !std::strncmp("InitiateMultipartUploadResult", root->Name(), 29)) {
52 XMLElement *node;
53
54 node = root->FirstChildElement("EncodingType");
55 if (node && node->GetText()) encodingType_ = node->GetText();
56
57 //Detect encode type
58 bool useUrlDecode = !ToLower(encodingType_.c_str()).compare(0, 3, "url", 3);
59
60 node = root->FirstChildElement("Bucket");
61 if (node && node->GetText()) bucket_ = node->GetText();
62
63 node = root->FirstChildElement("Key");
64 if (node && node->GetText()) key_ = useUrlDecode ? UrlDecode(node->GetText()) : node->GetText();
65
66 node = root->FirstChildElement("UploadId");
67 if (node && node->GetText()) uploadId_ = node->GetText();
68
69 parseDone_ = true;
70 }
71 }
72 return *this;
73 }
74