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/UploadPartCopyResult.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 
25 static const std::string EMPTY;
26 
UploadPartCopyResult()27 UploadPartCopyResult::UploadPartCopyResult() :
28     OssObjectResult()
29 {
30 }
31 
UploadPartCopyResult(const std::string & result)32 UploadPartCopyResult::UploadPartCopyResult(const std::string& result):
33     UploadPartCopyResult()
34 {
35     *this = result;
36 
37 }
38 
UploadPartCopyResult(const std::shared_ptr<std::iostream> & result,const HeaderCollection & headers)39 UploadPartCopyResult::UploadPartCopyResult(const std::shared_ptr<std::iostream>& result,
40     const HeaderCollection &headers):
41     OssObjectResult(headers)
42 {
43     if (headers.find("x-oss-copy-source-version-id") != headers.end()) {
44         sourceVersionId_ = headers.at("x-oss-copy-source-version-id");
45     }
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 UploadPartCopyResult& UploadPartCopyResult::operator =(
53     const std::string& result)
54 {
55     XMLDocument doc;
56     XMLError xml_err;
57     if ((xml_err = doc.Parse(result.c_str(), result.size())) == XML_SUCCESS) {
58         XMLElement* root =doc.RootElement();
59         if (root && !std::strncmp("CopyPartResult", root->Name(), 14)) {
60             XMLElement *node;
61 
62             node = root->FirstChildElement("LastModified");
63             if (node && node->GetText()) {
64                 lastModified_ = node->GetText();
65             }
66 
67             node = root->FirstChildElement("ETag");
68             if (node && node->GetText()) {
69                 eTag_ = TrimQuotes(node->GetText());
70             }
71             parseDone_ = true;
72 		}
73     }
74     return *this;
75 }
76 
LastModified() const77 const std::string& UploadPartCopyResult::LastModified() const
78 {
79     return lastModified_;
80 }
ETag() const81 const std::string& UploadPartCopyResult::ETag() const
82 {
83     return eTag_;
84 }
85