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