Fixed update instance
[framework/osp/social.git] / src / FSclUrl.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 /**
18  * @file                FSclUrl.cpp
19  * @brief               This is the implementation for Url class.
20  *
21  * This file contains definitions of @e Url class.
22  */
23
24 #include <FSclUrl.h>
25 #include <FApp_AppInfo.h>
26 #include <FBaseSysLog.h>
27 #include "FScl_UrlImpl.h"
28
29 using namespace Tizen::App;
30 using namespace Tizen::Base;
31
32 namespace Tizen { namespace Social
33 {
34
35 Url::Url(void)
36 {
37         __pUrlImpl = new (std::nothrow) _UrlImpl();
38         SysTryReturnVoidResult(NID_SCL, __pUrlImpl != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
39 }
40
41 Url::Url(UrlType type, const String& url)
42 {
43         __pUrlImpl = new (std::nothrow) _UrlImpl(type, url);
44         SysTryReturnVoidResult(NID_SCL, __pUrlImpl != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
45 }
46
47 Url::Url(const Url& rhs)
48 {
49         __pUrlImpl = new (std::nothrow) _UrlImpl(*rhs.__pUrlImpl);
50         SysTryReturnVoidResult(NID_SCL, __pUrlImpl != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
51 }
52
53 Url::~Url(void)
54 {
55         delete __pUrlImpl;
56 }
57
58 Url&
59 Url::operator =(const Url& rhs)
60 {
61         if (this == &rhs)
62         {
63                 return *this;
64         }
65
66         *__pUrlImpl = *rhs.__pUrlImpl;
67
68         return *this;
69 }
70
71 bool
72 Url::operator ==(const Url& rhs) const
73 {
74         return *__pUrlImpl == *rhs.__pUrlImpl;
75 }
76
77 bool
78 Url::operator !=(const Url& rhs) const
79 {
80         return !(*this == rhs);
81 }
82
83 bool
84 Url::Equals(const Object& rhs) const
85 {
86         const Url* pUrl = dynamic_cast<const Url*>(&rhs);
87
88         if (pUrl == null)
89         {
90                 return false;
91         }
92
93         return __pUrlImpl->Equals(*pUrl->__pUrlImpl);
94 }
95
96 int
97 Url::GetHashCode(void) const
98 {
99         return __pUrlImpl->GetHashCode();
100 }
101
102 UrlType
103 Url::GetType(void) const
104 {
105         UrlType type =  __pUrlImpl->GetType();
106
107         if (type == URL_TYPE_CUSTOM  && (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat()))
108         {
109                 type =  URL_TYPE_OTHER;
110         }
111
112         return type;
113 }
114
115 String
116 Url::GetUrl(void) const
117 {
118         String url = __pUrlImpl->GetUrl();
119
120         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
121         {
122                 if (url.GetLength() > MAX_URL_LENGTH)
123                 {
124                         url.SetLength(MAX_URL_LENGTH);
125                 }
126         }
127
128         return url;
129 }
130
131 void
132 Url::SetType(UrlType type)
133 {
134         __pUrlImpl->SetType(type);
135 }
136
137 result
138 Url::SetUrl(const String& url)
139 {
140         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
141         {
142                 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));
143         }
144
145         return __pUrlImpl->SetUrl(url);
146 }
147
148 String
149 Url::GetLabel(void) const
150 {
151         return __pUrlImpl->GetLabel();
152 }
153
154 void
155 Url::SetLabel(const String& label)
156 {
157         __pUrlImpl->SetLabel(label);
158 }
159
160 }} // Tizen::Social