fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / stoc / source / uriproc / UriReference.cxx
blob312203d78587138b9c19a404eff39879b248ef2f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "UriReference.hxx"
23 #include "osl/diagnose.h"
24 #include "osl/mutex.hxx"
25 #include "rtl/string.h"
26 #include "rtl/ustrbuf.hxx"
27 #include "rtl/ustring.hxx"
28 #include "sal/types.h"
30 using stoc::uriproc::UriReference;
32 UriReference::UriReference(
33 OUString const & scheme, bool bIsHierarchical, bool bHasAuthority,
34 OUString const & authority, OUString const & path,
35 bool bHasQuery, OUString const & query):
36 m_scheme(scheme),
37 m_authority(authority),
38 m_path(path),
39 m_query(query),
40 m_isHierarchical(bIsHierarchical),
41 m_hasAuthority(bHasAuthority),
42 m_hasQuery(bHasQuery),
43 m_hasFragment(false)
45 OSL_ASSERT(!scheme.isEmpty() || bIsHierarchical);
46 OSL_ASSERT(!bHasAuthority || bIsHierarchical);
47 OSL_ASSERT(authority.isEmpty() || bHasAuthority);
48 OSL_ASSERT(!bHasQuery || bIsHierarchical);
49 OSL_ASSERT(query.isEmpty() || bHasQuery);
52 UriReference::~UriReference() {}
54 OUString UriReference::getUriReference() throw (css::uno::RuntimeException)
56 osl::MutexGuard g(m_mutex);
57 OUStringBuffer buf;
58 if (!m_scheme.isEmpty()) {
59 buf.append(m_scheme);
60 buf.append(static_cast< sal_Unicode >(':'));
62 appendSchemeSpecificPart(buf);
63 if (m_hasFragment) {
64 buf.append(static_cast< sal_Unicode >('#'));
65 buf.append(m_fragment);
67 return buf.makeStringAndClear();
70 sal_Bool UriReference::isAbsolute() throw (css::uno::RuntimeException) {
71 return !m_scheme.isEmpty();
74 OUString UriReference::getScheme() throw (css::uno::RuntimeException) {
75 return m_scheme;
78 OUString UriReference::getSchemeSpecificPart()
79 throw (css::uno::RuntimeException)
81 osl::MutexGuard g(m_mutex);
82 OUStringBuffer buf;
83 appendSchemeSpecificPart(buf);
84 return buf.makeStringAndClear();
87 sal_Bool UriReference::isHierarchical() throw (css::uno::RuntimeException) {
88 osl::MutexGuard g(m_mutex);
89 return m_isHierarchical;
92 sal_Bool UriReference::hasAuthority() throw (css::uno::RuntimeException) {
93 osl::MutexGuard g(m_mutex);
94 return m_hasAuthority;
97 OUString UriReference::getAuthority() throw (css::uno::RuntimeException) {
98 osl::MutexGuard g(m_mutex);
99 return m_authority;
102 OUString UriReference::getPath() throw (css::uno::RuntimeException) {
103 osl::MutexGuard g(m_mutex);
104 return m_path;
107 sal_Bool UriReference::hasRelativePath() throw (css::uno::RuntimeException) {
108 osl::MutexGuard g(m_mutex);
109 return m_isHierarchical && !m_hasAuthority
110 && (m_path.isEmpty() || m_path[0] != '/');
113 sal_Int32 UriReference::getPathSegmentCount() throw (css::uno::RuntimeException)
115 osl::MutexGuard g(m_mutex);
116 if (!m_isHierarchical || m_path.isEmpty()) {
117 return 0;
118 } else {
119 sal_Int32 n = m_path[0] == '/' ? 0 : 1;
120 for (sal_Int32 i = 0;; ++i) {
121 i = m_path.indexOf('/', i);
122 if (i < 0) {
123 break;
125 ++n;
127 return n;
131 OUString UriReference::getPathSegment(sal_Int32 index)
132 throw (css::uno::RuntimeException)
134 osl::MutexGuard g(m_mutex);
135 if (m_isHierarchical && !m_path.isEmpty() && index >= 0) {
136 for (sal_Int32 i = m_path[0] == '/' ? 1 : 0;; ++i) {
137 if (index-- == 0) {
138 sal_Int32 j = m_path.indexOf('/', i);
139 return j < 0 ? m_path.copy(i) : m_path.copy(i, j - i);
141 i = m_path.indexOf('/', i);
142 if (i < 0) {
143 break;
147 return OUString();
150 sal_Bool UriReference::hasQuery() throw (css::uno::RuntimeException) {
151 osl::MutexGuard g(m_mutex);
152 return m_hasQuery;
155 OUString UriReference::getQuery() throw (css::uno::RuntimeException) {
156 osl::MutexGuard g(m_mutex);
157 return m_query;
160 sal_Bool UriReference::hasFragment() throw (css::uno::RuntimeException) {
161 osl::MutexGuard g(m_mutex);
162 return m_hasFragment;
165 OUString UriReference::getFragment() throw (css::uno::RuntimeException) {
166 osl::MutexGuard g(m_mutex);
167 return m_fragment;
170 void UriReference::setFragment(OUString const & fragment)
171 throw (css::uno::RuntimeException)
173 osl::MutexGuard g(m_mutex);
174 m_hasFragment = true;
175 m_fragment = fragment;
178 void UriReference::clearFragment() throw (css::uno::RuntimeException) {
179 osl::MutexGuard g(m_mutex);
180 m_hasFragment = false;
181 m_fragment = OUString();
184 void UriReference::appendSchemeSpecificPart(OUStringBuffer & buffer) const
186 if (m_hasAuthority) {
187 buffer.appendAscii(RTL_CONSTASCII_STRINGPARAM("//"));
188 buffer.append(m_authority);
190 buffer.append(m_path);
191 if (m_hasQuery) {
192 buffer.append(static_cast< sal_Unicode >('?'));
193 buffer.append(m_query);
197 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */