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 41 : class Uri
35 : {
36 : enum State { UNKNOWN, INVALID, VALID };
37 :
38 : mutable ::rtl::OUString m_aUri;
39 : mutable ::rtl::OUString m_aParentUri;
40 : mutable ::rtl::OUString m_aPath;
41 : mutable ::rtl::OUString m_aDocId;
42 : mutable ::rtl::OUString m_aInternalPath;
43 : mutable ::rtl::OUString m_aName;
44 : mutable ::rtl::OUString m_aDecodedName;
45 : mutable State m_eState;
46 :
47 : private:
48 : void init() const;
49 :
50 : public:
51 : Uri() : m_eState( UNKNOWN ) {}
52 41 : Uri( const ::rtl::OUString & rUri )
53 41 : : 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 3 : sal_Bool isValid() const
62 3 : { init(); return m_eState == VALID; }
63 :
64 13 : const ::rtl::OUString & getUri() const
65 13 : { init(); return m_aUri; }
66 :
67 : inline void setUri( const ::rtl::OUString & rUri );
68 :
69 5 : const ::rtl::OUString & getParentUri() const
70 5 : { init(); return m_aParentUri; }
71 :
72 : const ::rtl::OUString & getPath() const
73 : { init(); return m_aPath; }
74 :
75 13 : const ::rtl::OUString & getDocumentId() const
76 13 : { init(); return m_aDocId; }
77 :
78 : const ::rtl::OUString & getInternalPath() const
79 : { init(); return m_aInternalPath; }
80 :
81 0 : const ::rtl::OUString & getName() const
82 0 : { init(); return m_aName; }
83 :
84 0 : const ::rtl::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 ::rtl::OUString & rUri )
95 : {
96 0 : m_eState = UNKNOWN;
97 0 : m_aUri = rUri;
98 : m_aParentUri = m_aDocId = m_aInternalPath = m_aPath = m_aName
99 0 : = m_aDecodedName = rtl::OUString();
100 0 : }
101 :
102 15 : inline sal_Bool Uri::isRoot() const
103 : {
104 15 : init();
105 15 : return ( m_aPath.getLength() == 1 );
106 : }
107 :
108 25 : inline sal_Bool Uri::isDocument() const
109 : {
110 25 : init();
111 25 : return ( ( !m_aDocId.isEmpty() ) /* not root */
112 50 : && ( 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.lastIndexOf( '/' ) == m_aPath.getLength() - 1 );
119 : }
120 :
121 : } // namespace tdoc_ucp
122 :
123 : #endif /* !INCLUDED_TDOC_URI_HXX */
124 :
125 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|