1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef INCLUDED_TDOC_URI_HXX 29 #define INCLUDED_TDOC_URI_HXX 30 31 #include "rtl/ustring.hxx" 32 33 namespace tdoc_ucp { 34 35 //========================================================================= 36 37 #define TDOC_URL_SCHEME "vnd.sun.star.tdoc" 38 #define TDOC_URL_SCHEME_LENGTH 17 39 40 //========================================================================= 41 42 class Uri 43 { 44 enum State { UNKNOWN, INVALID, VALID }; 45 46 mutable ::rtl::OUString m_aUri; 47 mutable ::rtl::OUString m_aParentUri; 48 mutable ::rtl::OUString m_aPath; 49 mutable ::rtl::OUString m_aDocId; 50 mutable ::rtl::OUString m_aInternalPath; 51 mutable ::rtl::OUString m_aName; 52 mutable ::rtl::OUString m_aDecodedName; 53 mutable State m_eState; 54 55 private: 56 void init() const; 57 58 public: 59 Uri() : m_eState( UNKNOWN ) {} 60 Uri( const ::rtl::OUString & rUri ) 61 : m_aUri( rUri ), m_eState( UNKNOWN ) {} 62 63 bool operator== ( const Uri & rOther ) const 64 { init(); return m_aUri == rOther.m_aUri; } 65 66 bool operator!= ( const Uri & rOther ) const 67 { return !operator==( rOther ); } 68 69 sal_Bool isValid() const 70 { init(); return m_eState == VALID; } 71 72 const ::rtl::OUString & getUri() const 73 { init(); return m_aUri; } 74 75 inline void setUri( const ::rtl::OUString & rUri ); 76 77 const ::rtl::OUString & getParentUri() const 78 { init(); return m_aParentUri; } 79 80 const ::rtl::OUString & getPath() const 81 { init(); return m_aPath; } 82 83 const ::rtl::OUString & getDocumentId() const 84 { init(); return m_aDocId; } 85 86 const ::rtl::OUString & getInternalPath() const 87 { init(); return m_aInternalPath; } 88 89 const ::rtl::OUString & getName() const 90 { init(); return m_aName; } 91 92 const ::rtl::OUString & getDecodedName() const 93 { init(); return m_aDecodedName; } 94 95 inline sal_Bool isRoot() const; 96 97 inline sal_Bool isDocument() const; 98 99 inline sal_Bool isFolder() const; 100 }; 101 102 inline void Uri::setUri( const ::rtl::OUString & rUri ) 103 { 104 m_eState = UNKNOWN; 105 m_aUri = rUri; 106 m_aParentUri = m_aDocId = m_aInternalPath = m_aPath = m_aName 107 = m_aDecodedName = rtl::OUString(); 108 } 109 110 inline sal_Bool Uri::isRoot() const 111 { 112 init(); 113 return ( m_aPath.getLength() == 1 ); 114 } 115 116 inline sal_Bool Uri::isDocument() const 117 { 118 init(); 119 return ( ( m_aDocId.getLength() > 0 ) /* not root */ 120 && ( m_aPath.copy( m_aDocId.getLength() + 1 ).getLength() < 2 ) ); 121 } 122 123 inline sal_Bool Uri::isFolder() const 124 { 125 init(); 126 return ( m_aPath.lastIndexOf( '/' ) == m_aPath.getLength() - 1 ); 127 } 128 129 } // namespace tdoc_ucp 130 131 #endif /* !INCLUDED_TDOC_URI_HXX */ 132