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/CopyObjectResult.h>
19 #include <external/tinyxml2/tinyxml2.h>
20 #include "utils/Utils.h"
21
22 using namespace AlibabaCloud::OSS;
23 using namespace tinyxml2;
24
CopyObjectResult()25 CopyObjectResult::CopyObjectResult() :
26 OssObjectResult()
27 {
28 }
29
CopyObjectResult(const std::string & data)30 CopyObjectResult::CopyObjectResult(const std::string& data):
31 CopyObjectResult()
32 {
33 *this = data;
34 }
35
CopyObjectResult(const std::shared_ptr<std::iostream> & data)36 CopyObjectResult::CopyObjectResult(const std::shared_ptr<std::iostream>& data):
37 CopyObjectResult()
38 {
39 std::istreambuf_iterator<char> isb(*data.get()), end;
40 std::string str(isb, end);
41 *this = str;
42 }
43
CopyObjectResult(const HeaderCollection & headers,const std::shared_ptr<std::iostream> & data)44 CopyObjectResult::CopyObjectResult(const HeaderCollection& headers, const std::shared_ptr<std::iostream>& data):
45 OssObjectResult(headers)
46 {
47 if (headers.find("x-oss-copy-source-version-id") != headers.end()) {
48 sourceVersionId_ = headers.at("x-oss-copy-source-version-id");
49 }
50
51 std::istreambuf_iterator<char> isb(*data.get()), end;
52 std::string str(isb, end);
53 *this = str;
54 }
55
operator =(const std::string & data)56 CopyObjectResult& CopyObjectResult::operator =(const std::string& data)
57 {
58 XMLDocument doc;
59 XMLError xml_err;
60 if ((xml_err = doc.Parse(data.c_str(), data.size())) == XML_SUCCESS) {
61 XMLElement* root = doc.RootElement();
62 if (root && !std::strncmp("CopyObjectResult", root->Name(), strlen("CopyObjectResult"))) {
63 XMLElement *node;
64 node = root->FirstChildElement("LastModified");
65 if (node && node->GetText()) {
66 lastModified_ = node->GetText();
67 }
68
69 node = root->FirstChildElement("ETag");
70 if (node && node->GetText()) {
71 etag_ = TrimQuotes(node->GetText());
72 }
73
74 //TODO check the result and the parse flag;
75 parseDone_ = true;
76 }
77 }
78 return *this;
79 }
80
81