gui
[lbook_fbreader.git] / fbreader / src / formats / util / EntityFilesCollector.cpp
blob4739106786ff55ee8f1aad4171125f82e6247401
1 /*
2 * Copyright (C) 2004-2008 Geometer Plus <contact@geometerplus.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301, USA.
20 #include <ZLStringUtil.h>
21 #include <ZLibrary.h>
22 #include <ZLFile.h>
23 #include <ZLDir.h>
25 #include "EntityFilesCollector.h"
27 EntityFilesCollector *EntityFilesCollector::ourInstance = 0;
29 EntityFilesCollector &EntityFilesCollector::instance() {
30 if (ourInstance == 0) {
31 ourInstance = new EntityFilesCollector();
33 return *ourInstance;
36 const std::vector<std::string> &EntityFilesCollector::externalDTDs(const std::string &format) {
37 std::map<std::string,std::vector<std::string> >::const_iterator it = myCollections.find(format);
38 if (it != myCollections.end()) {
39 return it->second;
42 std::vector<std::string> &collection = myCollections[format];
44 std::string directoryName =
45 ZLibrary::ApplicationDirectory() + ZLibrary::FileNameDelimiter +
46 "formats" + ZLibrary::FileNameDelimiter + format;
47 shared_ptr<ZLDir> dtdPath = ZLFile(directoryName).directory();
48 if (!dtdPath.isNull()) {
49 std::vector<std::string> files;
50 dtdPath->collectFiles(files, false);
51 for (std::vector<std::string>::const_iterator it = files.begin(); it != files.end(); ++it) {
52 if (ZLStringUtil::stringEndsWith(*it, ".ent")) {
53 collection.push_back(dtdPath->itemPath(*it));
58 return collection;
61 EntityFilesCollector::EntityFilesCollector() {