summaryrefslogtreecommitdiff
path: root/src/FSclUrl.cpp
blob: 1d6f8fac3b4ab71164703c48dafdd32f235aae2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
//
// Open Service Platform
// Copyright (c) 2012 Samsung Electronics Co., Ltd.
//
// Licensed under the Apache License, Version 2.0 (the License);
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
/**
 * @file		FSclUrl.cpp
 * @brief		This is the implementation for Url class.
 *
 * This file contains definitions of @e Url class.
 */

#include <FSclUrl.h>
#include <FApp_AppInfo.h>
#include <FBaseSysLog.h>
#include "FScl_UrlImpl.h"

using namespace Tizen::App;
using namespace Tizen::Base;

namespace Tizen { namespace Social
{

Url::Url(void)
{
	__pUrlImpl = new (std::nothrow) _UrlImpl();
	SysTryReturnVoidResult(NID_SCL, __pUrlImpl != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
}

Url::Url(UrlType type, const String& url)
{
	__pUrlImpl = new (std::nothrow) _UrlImpl(type, url);
	SysTryReturnVoidResult(NID_SCL, __pUrlImpl != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
}

Url::Url(const Url& rhs)
{
	__pUrlImpl = new (std::nothrow) _UrlImpl(*rhs.__pUrlImpl);
	SysTryReturnVoidResult(NID_SCL, __pUrlImpl != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
}

Url::~Url(void)
{
	delete __pUrlImpl;
}

Url&
Url::operator =(const Url& rhs)
{
	if (this == &rhs)
	{
		return *this;
	}

	*__pUrlImpl = *rhs.__pUrlImpl;

	return *this;
}

bool
Url::operator ==(const Url& rhs) const
{
	return *__pUrlImpl == *rhs.__pUrlImpl;
}

bool
Url::operator !=(const Url& rhs) const
{
	return !(*this == rhs);
}

bool
Url::Equals(const Object& rhs) const
{
	const Url* pUrl = dynamic_cast<const Url*>(&rhs);

	if (pUrl == null)
	{
		return false;
	}

	return __pUrlImpl->Equals(*pUrl->__pUrlImpl);
}

int
Url::GetHashCode(void) const
{
	return __pUrlImpl->GetHashCode();
}

UrlType
Url::GetType(void) const
{
	UrlType type =  __pUrlImpl->GetType();

	if (type == URL_TYPE_CUSTOM  && (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat()))
	{
		type =  URL_TYPE_OTHER;
	}

	return type;
}

String
Url::GetUrl(void) const
{
	String url = __pUrlImpl->GetUrl();

	if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
	{
		if (url.GetLength() > MAX_URL_LENGTH)
		{
			url.SetLength(MAX_URL_LENGTH);
		}
	}

	return url;
}

void
Url::SetType(UrlType type)
{
	__pUrlImpl->SetType(type);
}

result
Url::SetUrl(const String& url)
{
	if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
	{
		SysTryReturn(NID_SCL, url.GetLength() <= MAX_URL_LENGTH, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The length of the url exceeds MAX_URL_LENGTH", GetErrorMessage(E_INVALID_ARG));
	}

	return __pUrlImpl->SetUrl(url);
}

String
Url::GetLabel(void) const
{
	return __pUrlImpl->GetLabel();
}

void
Url::SetLabel(const String& label)
{
	__pUrlImpl->SetLabel(label);
}

}} // Tizen::Social