1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: filecoll.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 #include <tools/filecoll.hxx>
35 // NOT FULLY DEFINED SERVICES
36 #include <cosv/ploc_dir.hxx>
41 FileCollector::FileCollector( uintt i_nRoughNrOfFiles
)
44 if (i_nRoughNrOfFiles
> 0)
45 aFoundFiles
.reserve(i_nRoughNrOfFiles
);
49 FileCollector::AddFilesFrom( const char * i_sRootDir
,
50 const char * i_sFilter
,
51 E_SearchMode i_eSearchMode
)
53 uintt nSizeAtStart
= aFoundFiles
.size();
55 if (csv::no_str(i_sFilter
) OR
csv::no_str(i_sRootDir
))
57 Cout() << "Warning: The filter contains no files." << Endl();
61 csv::ploc::Directory
aDir(i_sRootDir
);
62 if (NOT aDir
.Exists())
64 Cerr() << "Warning: The path for the files to be parsed could not be found:\n"
70 Cout() << "." << Flush();
71 aDir
.GetContainedFiles(aFoundFiles
, i_sFilter
);
73 if (i_eSearchMode
== recursive
)
75 StreamStr
aPath(1020);
76 aPath
<< i_sRootDir
<< csv::ploc::Delimiter();
77 uintt nSubDirStart
= aPath
.tellp();
79 StringVector aSubDirs
;
80 aDir
.GetContainedDirectories(aSubDirs
);
82 for ( const_iterator iter
= aSubDirs
.begin();
83 iter
!= aSubDirs
.end();
86 aPath
.seekp(nSubDirStart
);
88 AddFilesFrom( aPath
.c_str(), i_sFilter
, i_eSearchMode
);
92 return aFoundFiles
.size() - nSizeAtStart
;
96 FileCollector::AddFile( const char * i_sFilePath
)
98 FILE * pFile
= fopen( i_sFilePath
, "r" );
101 Cerr() << "Warning: The path for the file to be parsed could not be found:\n"
108 aFoundFiles
.push_back(i_sFilePath
);
113 FileCollector::EraseAll()
115 csv::erase_container(aFoundFiles
);
118 FileCollector::const_iterator
119 FileCollector::Begin() const
121 return aFoundFiles
.begin();
124 FileCollector::const_iterator
125 FileCollector::End() const
127 return aFoundFiles
.end();
131 FileCollector::Size() const
133 return aFoundFiles
.size();