xref: /aoo42x/main/ucb/source/ucp/tdoc/tdoc_uri.hxx (revision 6df1ea1f)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef INCLUDED_TDOC_URI_HXX
25 #define INCLUDED_TDOC_URI_HXX
26 
27 #include "rtl/ustring.hxx"
28 
29 namespace tdoc_ucp {
30 
31 //=========================================================================
32 
33 #define TDOC_URL_SCHEME          "vnd.sun.star.tdoc"
34 #define TDOC_URL_SCHEME_LENGTH   17
35 
36 //=========================================================================
37 
38 class Uri
39 {
40     enum State { UNKNOWN, INVALID, VALID };
41 
42 	mutable ::rtl::OUString m_aUri;
43 	mutable ::rtl::OUString m_aParentUri;
44 	mutable ::rtl::OUString m_aPath;
45     mutable ::rtl::OUString m_aDocId;
46     mutable ::rtl::OUString m_aInternalPath;
47 	mutable ::rtl::OUString m_aName;
48     mutable ::rtl::OUString m_aDecodedName;
49     mutable State           m_eState;
50 
51 private:
52 	void init() const;
53 
54 public:
Uri()55     Uri() : m_eState( UNKNOWN ) {}
Uri(const::rtl::OUString & rUri)56     Uri( const ::rtl::OUString & rUri )
57     : m_aUri( rUri ), m_eState( UNKNOWN ) {}
58 
operator ==(const Uri & rOther) const59     bool operator== ( const Uri & rOther ) const
60     { init(); return m_aUri == rOther.m_aUri; }
61 
operator !=(const Uri & rOther) const62     bool operator!= ( const Uri & rOther ) const
63     { return !operator==( rOther ); }
64 
isValid() const65     sal_Bool isValid() const
66     { init(); return m_eState == VALID; }
67 
getUri() const68 	const ::rtl::OUString & getUri() const
69 	{ init(); return m_aUri; }
70 
71     inline void setUri( const ::rtl::OUString & rUri );
72 
getParentUri() const73 	const ::rtl::OUString & getParentUri() const
74 	{ init(); return m_aParentUri; }
75 
getPath() const76 	const ::rtl::OUString & getPath() const
77 	{ init(); return m_aPath; }
78 
getDocumentId() const79     const ::rtl::OUString & getDocumentId() const
80     { init(); return m_aDocId; }
81 
getInternalPath() const82     const ::rtl::OUString & getInternalPath() const
83     { init(); return m_aInternalPath; }
84 
getName() const85 	const ::rtl::OUString & getName() const
86 	{ init(); return m_aName; }
87 
getDecodedName() const88     const ::rtl::OUString & getDecodedName() const
89     { init(); return m_aDecodedName; }
90 
91     inline sal_Bool isRoot() const;
92 
93     inline sal_Bool isDocument() const;
94 
95     inline sal_Bool isFolder() const;
96 };
97 
setUri(const::rtl::OUString & rUri)98 inline void Uri::setUri( const ::rtl::OUString & rUri )
99 {
100     m_eState = UNKNOWN;
101     m_aUri = rUri;
102     m_aParentUri = m_aDocId = m_aInternalPath = m_aPath = m_aName
103         = m_aDecodedName = rtl::OUString();
104 }
105 
isRoot() const106 inline sal_Bool Uri::isRoot() const
107 {
108     init();
109     return ( m_aPath.getLength() == 1 );
110 }
111 
isDocument() const112 inline sal_Bool Uri::isDocument() const
113 {
114     init();
115     return ( ( m_aDocId.getLength() > 0 ) /* not root */
116              && ( m_aPath.copy( m_aDocId.getLength() + 1 ).getLength() < 2 ) );
117 }
118 
isFolder() const119 inline sal_Bool Uri::isFolder() const
120 {
121     init();
122     return ( m_aPath.lastIndexOf( '/' ) == m_aPath.getLength() - 1 );
123 }
124 
125 } // namespace tdoc_ucp
126 
127 #endif /* !INCLUDED_TDOC_URI_HXX */
128