merge the formfield patch from ooo-build
[ooovba.git] / store / source / stordir.cxx
blob0269e9cb51f15a2d89dca5d9082203e036116018
1 /*************************************************************************
3 * OpenOffice.org - a multi-platform office productivity suite
5 * $RCSfile: stordir.cxx,v $
7 * $Revision: 1.1.2.2 $
9 * last change: $Author: mhu $ $Date: 2008/10/17 16:30:17 $
11 * The Contents of this file are made available subject to
12 * the terms of GNU Lesser General Public License Version 2.1.
15 * GNU Lesser General Public License Version 2.1
16 * =============================================
17 * Copyright 2005 by Sun Microsystems, Inc.
18 * 901 San Antonio Road, Palo Alto, CA 94303, USA
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License version 2.1, as published by the Free Software Foundation.
24 * This library is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 * Lesser General Public License for more details.
29 * You should have received a copy of the GNU Lesser General Public
30 * License along with this library; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32 * MA 02111-1307 USA
34 ************************************************************************/
36 // MARKER(update_precomp.py): autogen include statement, do not remove
37 #include "precompiled_store.hxx"
39 #include "stordir.hxx"
41 #ifndef _SAL_TYPES_H_
42 #include <sal/types.h>
43 #endif
45 #ifndef _RTL_TEXTCVT_H_
46 #include <rtl/textcvt.h>
47 #endif
48 #ifndef _RTL_REF_HXX_
49 #include <rtl/ref.hxx>
50 #endif
52 #ifndef _OSL_MUTEX_HXX_
53 #include <osl/mutex.hxx>
54 #endif
56 #ifndef _STORE_TYPES_H_
57 #include "store/types.h"
58 #endif
59 #ifndef _STORE_OBJECT_HXX_
60 #include "object.hxx"
61 #endif
63 #ifndef _STORE_STORBASE_HXX_
64 #include "storbase.hxx"
65 #endif
66 #ifndef _STORE_STORDATA_HXX_
67 #include "stordata.hxx"
68 #endif
69 #ifndef _STORE_STORPAGE_HXX_
70 #include "storpage.hxx"
71 #endif
73 using namespace store;
75 /*========================================================================
77 * OStore... internals.
79 *======================================================================*/
81 * __store_convertTextToUnicode.
83 inline sal_Size __store_convertTextToUnicode (
84 rtl_TextToUnicodeConverter hConverter,
85 const sal_Char *pSrcBuffer, sal_Size nSrcLength,
86 sal_Unicode *pDstBuffer, sal_Size nDstLength)
88 sal_uInt32 nCvtInfo = 0;
89 sal_Size nCvtBytes = 0;
90 return rtl_convertTextToUnicode (
91 hConverter, 0,
92 pSrcBuffer, nSrcLength,
93 pDstBuffer, nDstLength,
94 OSTRING_TO_OUSTRING_CVTFLAGS,
95 &nCvtInfo, &nCvtBytes);
98 /*========================================================================
100 * OStoreDirectory_Impl implementation.
102 *======================================================================*/
103 const sal_uInt32 OStoreDirectory_Impl::m_nTypeId = sal_uInt32(0x89191107);
106 * OStoreDirectory_Impl.
108 OStoreDirectory_Impl::OStoreDirectory_Impl (void)
109 : m_xManager (),
110 m_aDescr (0, 0, 0),
111 m_nPath (0),
112 m_hTextCvt (NULL)
116 * ~OStoreDirectory_Impl.
118 OStoreDirectory_Impl::~OStoreDirectory_Impl (void)
120 if (m_xManager.is())
122 if (m_aDescr.m_nAddr != STORE_PAGE_NULL)
123 m_xManager->releasePage (m_aDescr, store_AccessReadOnly);
125 rtl_destroyTextToUnicodeConverter (m_hTextCvt);
129 * isKindOf.
131 sal_Bool SAL_CALL OStoreDirectory_Impl::isKindOf (sal_uInt32 nTypeId)
133 return (nTypeId == m_nTypeId);
137 * create.
139 storeError OStoreDirectory_Impl::create (
140 OStorePageManager *pManager,
141 rtl_String *pPath,
142 rtl_String *pName,
143 storeAccessMode eMode)
145 rtl::Reference<OStorePageManager> xManager (pManager);
146 if (!xManager.is())
147 return store_E_InvalidAccess;
149 if (!(pPath && pName))
150 return store_E_InvalidParameter;
152 OStoreDirectoryPageObject aPage;
153 storeError eErrCode = xManager->iget (
154 aPage, STORE_ATTRIB_ISDIR,
155 pPath, pName, eMode);
156 if (eErrCode != store_E_None)
157 return eErrCode;
159 if (!(aPage.attrib() & STORE_ATTRIB_ISDIR))
160 return store_E_NotDirectory;
162 inode_holder_type xNode (aPage.get());
163 eErrCode = xManager->acquirePage (xNode->m_aDescr, store_AccessReadOnly);
164 if (eErrCode != store_E_None)
165 return eErrCode;
167 // Evaluate iteration path.
168 m_nPath = aPage.path();
169 m_nPath = rtl_crc32 (m_nPath, "/", 1);
171 // Save page manager, and descriptor.
172 m_xManager = xManager;
173 m_aDescr = xNode->m_aDescr;
175 return store_E_None;
179 * iterate.
181 storeError OStoreDirectory_Impl::iterate (storeFindData &rFindData)
183 if (!m_xManager.is())
184 return store_E_InvalidAccess;
186 storeError eErrCode = store_E_NoMoreFiles;
187 if (!rFindData.m_nReserved)
188 return eErrCode;
190 // Acquire exclusive access.
191 osl::MutexGuard aGuard (*m_xManager);
193 // Check TextConverter.
194 if (m_hTextCvt == NULL)
195 m_hTextCvt = rtl_createTextToUnicodeConverter(RTL_TEXTENCODING_UTF8);
197 // Setup iteration key.
198 OStorePageKey aKey (rFindData.m_nReserved, m_nPath);
200 // Iterate.
201 for (;;)
203 OStorePageLink aLink;
204 eErrCode = m_xManager->iterate (aKey, aLink, rFindData.m_nAttrib);
205 if (!((eErrCode == store_E_None) && (aKey.m_nHigh == store::htonl(m_nPath))))
206 break;
208 if (!(rFindData.m_nAttrib & STORE_ATTRIB_ISLINK))
210 // Load page.
211 OStoreDirectoryPageObject aPage;
212 eErrCode = m_xManager->loadObjectAt (aPage, aLink.location());
213 if (eErrCode == store_E_None)
215 inode_holder_type xNode (aPage.get());
217 // Setup FindData.
218 sal_Char *p = xNode->m_aNameBlock.m_pData;
219 sal_Size n = rtl_str_getLength (p);
220 sal_Size k = rFindData.m_nLength;
222 n = __store_convertTextToUnicode (
223 m_hTextCvt, p, n,
224 rFindData.m_pszName, STORE_MAXIMUM_NAMESIZE - 1);
225 if (k > n)
227 k = (k - n) * sizeof(sal_Unicode);
228 memset (&rFindData.m_pszName[n], 0, k);
231 rFindData.m_nLength = n;
232 rFindData.m_nAttrib |= aPage.attrib();
233 rFindData.m_nSize = aPage.dataLength();
235 // Leave.
236 rFindData.m_nReserved = store::ntohl(aKey.m_nLow);
237 return store_E_None;
241 if (aKey.m_nLow == 0)
242 break;
243 aKey.m_nLow = store::htonl(store::ntohl(aKey.m_nLow) - 1);
246 // Finished.
247 memset (&rFindData, 0, sizeof (storeFindData));
248 return store_E_NoMoreFiles;