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 #ifndef INCLUDED_UCB_SOURCE_UCP_TDOC_TDOC_URI_HXX
21 #define INCLUDED_UCB_SOURCE_UCP_TDOC_TDOC_URI_HXX
22 
23 #include <rtl/ustring.hxx>
24 
25 namespace tdoc_ucp {
26 
27 
28 #define TDOC_URL_SCHEME "vnd.sun.star.tdoc"
29 #define TDOC_URL_SCHEME_LENGTH 17
30 
31 
32 class Uri
33 {
34  enum State { UNKNOWN, INVALID, VALID };
35 
36  mutable OUString m_aUri;
37  mutable OUString m_aParentUri;
38  mutable OUString m_aPath;
39  mutable OUString m_aDocId;
40  mutable OUString m_aName;
41  mutable OUString m_aDecodedName;
42  mutable State m_eState;
43 
44 private:
45  void init() const;
46 
47 public:
48  explicit Uri( const OUString & rUri )
49  : m_aUri( rUri ), m_eState( UNKNOWN ) {}
50 
51  bool operator== ( const Uri & rOther ) const
52  { init(); return m_aUri == rOther.m_aUri; }
53 
54  bool operator!= ( const Uri & rOther ) const
55  { return !operator==( rOther ); }
56 
57  bool isValid() const
58  { init(); return m_eState == VALID; }
59 
60  const OUString & getUri() const
61  { init(); return m_aUri; }
62 
63  inline void setUri( const OUString & rUri );
64 
65  const OUString & getParentUri() const
66  { init(); return m_aParentUri; }
67 
68  const OUString & getDocumentId() const
69  { init(); return m_aDocId; }
70 
71  const OUString & getName() const
72  { init(); return m_aName; }
73 
74  const OUString & getDecodedName() const
75  { init(); return m_aDecodedName; }
76 
77  inline bool isRoot() const;
78 
79  inline bool isDocument() const;
80 };
81 
82 inline void Uri::setUri( const OUString & rUri )
83 {
84  m_eState = UNKNOWN;
85  m_aUri = rUri;
86  m_aParentUri.clear();
87  m_aDocId.clear();
88  m_aPath.clear();
89  m_aName.clear();
90  m_aDecodedName.clear();
91 }
92 
93 inline bool Uri::isRoot() const
94 {
95  init();
96  return ( m_aPath.getLength() == 1 );
97 }
98 
99 inline bool Uri::isDocument() const
100 {
101  init();
102  return ( ( !m_aDocId.isEmpty() ) /* not root */
103  && ( m_aPath.copy( m_aDocId.getLength() + 1 ).getLength() < 2 ) );
104 }
105 
106 } // namespace tdoc_ucp
107 
108 #endif // INCLUDED_UCB_SOURCE_UCP_TDOC_TDOC_URI_HXX
109 
110 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool isDocument() const
Definition: tdoc_uri.hxx:99
OUString m_aDocId
Definition: tdoc_uri.hxx:39
bool isRoot() const
Definition: tdoc_uri.hxx:93
Uri(const OUString &rUri)
Definition: tdoc_uri.hxx:48
OUString m_aParentUri
Definition: tdoc_uri.hxx:37
bool operator!=(const Uri &rOther) const
Definition: tdoc_uri.hxx:54
const OUString & getName() const
Definition: tdoc_uri.hxx:71
State m_eState
Definition: tdoc_uri.hxx:42
const OUString & getDecodedName() const
Definition: tdoc_uri.hxx:74
void setUri(const OUString &rUri)
Definition: tdoc_uri.hxx:82
OUString m_aPath
Definition: tdoc_uri.hxx:38
OUString m_aName
Definition: tdoc_uri.hxx:40
const OUString & getDocumentId() const
Definition: tdoc_uri.hxx:68
void init() const
Definition: tdoc_uri.cxx:38
OUString m_aDecodedName
Definition: tdoc_uri.hxx:41
bool operator==(const Uri &rOther) const
Definition: tdoc_uri.hxx:51
const OUString & getParentUri() const
Definition: tdoc_uri.hxx:65
double getLength(const B2DPolygon &rCandidate)
bool isValid() const
Definition: tdoc_uri.hxx:57
OUString m_aUri
Definition: tdoc_uri.hxx:36
const OUString & getUri() const
Definition: tdoc_uri.hxx:60