LibreOffice Module ucb (master)  1
tdoc_uri.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #pragma once
21 
22 #include <rtl/ustring.hxx>
23 
24 namespace tdoc_ucp {
25 
26 
27 #define TDOC_URL_SCHEME "vnd.sun.star.tdoc"
28 #define TDOC_URL_SCHEME_LENGTH 17
29 
30 
31 class Uri
32 {
33  enum State { UNKNOWN, INVALID, VALID };
34 
35  mutable OUString m_aUri;
36  mutable OUString m_aParentUri;
37  mutable OUString m_aPath;
38  mutable OUString m_aDocId;
39  mutable OUString m_aName;
40  mutable OUString m_aDecodedName;
41  mutable State m_eState;
42 
43 private:
44  void init() const;
45 
46 public:
47  explicit Uri( const OUString & rUri )
48  : m_aUri( rUri ), m_eState( UNKNOWN ) {}
49 
50  bool operator== ( const Uri & rOther ) const
51  { init(); return m_aUri == rOther.m_aUri; }
52 
53  bool operator!= ( const Uri & rOther ) const
54  { return !operator==( rOther ); }
55 
56  bool isValid() const
57  { init(); return m_eState == VALID; }
58 
59  const OUString & getUri() const
60  { init(); return m_aUri; }
61 
62  inline void setUri( const OUString & rUri );
63 
64  const OUString & getParentUri() const
65  { init(); return m_aParentUri; }
66 
67  const OUString & getDocumentId() const
68  { init(); return m_aDocId; }
69 
70  const OUString & getName() const
71  { init(); return m_aName; }
72 
73  const OUString & getDecodedName() const
74  { init(); return m_aDecodedName; }
75 
76  inline bool isRoot() const;
77 
78  inline bool isDocument() const;
79 };
80 
81 inline void Uri::setUri( const OUString & rUri )
82 {
83  m_eState = UNKNOWN;
84  m_aUri = rUri;
85  m_aParentUri.clear();
86  m_aDocId.clear();
87  m_aPath.clear();
88  m_aName.clear();
89  m_aDecodedName.clear();
90 }
91 
92 inline bool Uri::isRoot() const
93 {
94  init();
95  return ( m_aPath.getLength() == 1 );
96 }
97 
98 inline bool Uri::isDocument() const
99 {
100  init();
101  return ( ( !m_aDocId.isEmpty() ) /* not root */
102  && ( m_aPath.copy( m_aDocId.getLength() + 1 ).getLength() < 2 ) );
103 }
104 
105 } // namespace tdoc_ucp
106 
107 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool isDocument() const
Definition: tdoc_uri.hxx:98
OUString m_aDocId
Definition: tdoc_uri.hxx:38
bool isRoot() const
Definition: tdoc_uri.hxx:92
Uri(const OUString &rUri)
Definition: tdoc_uri.hxx:47
OUString m_aParentUri
Definition: tdoc_uri.hxx:36
bool operator!=(const Uri &rOther) const
Definition: tdoc_uri.hxx:53
const OUString & getName() const
Definition: tdoc_uri.hxx:70
State m_eState
Definition: tdoc_uri.hxx:41
const OUString & getDecodedName() const
Definition: tdoc_uri.hxx:73
void setUri(const OUString &rUri)
Definition: tdoc_uri.hxx:81
OUString m_aPath
Definition: tdoc_uri.hxx:37
OUString m_aName
Definition: tdoc_uri.hxx:39
const OUString & getDocumentId() const
Definition: tdoc_uri.hxx:67
void init() const
Definition: tdoc_uri.cxx:37
OUString m_aDecodedName
Definition: tdoc_uri.hxx:40
bool operator==(const Uri &rOther) const
Definition: tdoc_uri.hxx:50
const OUString & getParentUri() const
Definition: tdoc_uri.hxx:64
double getLength(const B2DPolygon &rCandidate)
bool isValid() const
Definition: tdoc_uri.hxx:56
OUString m_aUri
Definition: tdoc_uri.hxx:35
const OUString & getUri() const
Definition: tdoc_uri.hxx:59