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