Add PDFDocFactory
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 562f89c..0725747 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -260,6 +260,7 @@
poppler/Parser.cc
poppler/PDFDoc.cc
poppler/PDFDocEncoding.cc
+ poppler/PDFDocFactory.cc
poppler/PopplerCache.cc
poppler/ProfileData.cc
poppler/PreScanOutputDev.cc
@@ -406,6 +407,7 @@
poppler/PDFDoc.h
poppler/PDFDocBuilder.h
poppler/PDFDocEncoding.h
+ poppler/PDFDocFactory.h
poppler/PopplerCache.h
poppler/ProfileData.h
poppler/PreScanOutputDev.h
diff --git a/poppler/Makefile.am b/poppler/Makefile.am
index 6717734..5dd8082 100644
--- a/poppler/Makefile.am
+++ b/poppler/Makefile.am
@@ -223,6 +223,7 @@
PDFDoc.h \
PDFDocBuilder.h \
PDFDocEncoding.h \
+ PDFDocFactory.h \
PopplerCache.h \
ProfileData.h \
PreScanOutputDev.h \
@@ -299,6 +300,7 @@
Parser.cc \
PDFDoc.cc \
PDFDocEncoding.cc \
+ PDFDocFactory.cc \
PopplerCache.cc \
ProfileData.cc \
PreScanOutputDev.cc \
diff --git a/poppler/PDFDocFactory.cc b/poppler/PDFDocFactory.cc
new file mode 100644
index 0000000..d8b5fcc
--- /dev/null
+++ b/poppler/PDFDocFactory.cc
@@ -0,0 +1,71 @@
+//========================================================================
+//
+// PDFDocFactory.cc
+//
+// This file is licensed under the GPLv2 or later
+//
+// Copyright 2010 Hib Eris <hib@hiberis.nl>
+//
+//========================================================================
+
+#include <config.h>
+
+#include "PDFDocFactory.h"
+
+#include "goo/GooList.h"
+#include "goo/GooString.h"
+#include "PDFDoc.h"
+#include "LocalPDFDocBuilder.h"
+#include "StdinPDFDocBuilder.h"
+#if ENABLE_LIBCURL
+#include "CurlPDFDocBuilder.h"
+#endif
+#include "ErrorCodes.h"
+
+//------------------------------------------------------------------------
+// PDFDocFactory
+//------------------------------------------------------------------------
+
+PDFDocFactory::PDFDocFactory(GooList *pdfDocBuilders)
+{
+ if (pdfDocBuilders) {
+ builders = pdfDocBuilders;
+ } else {
+ builders = new GooList();
+ }
+#if ENABLE_LIBCURL
+ builders->insert(0, new CurlPDFDocBuilder());
+#endif
+ builders->insert(0, new StdinPDFDocBuilder());
+ builders->insert(0, new LocalPDFDocBuilder());
+}
+
+PDFDocFactory::~PDFDocFactory()
+{
+ if (builders) {
+ deleteGooList(builders, PDFDocBuilder);
+ }
+}
+
+PDFDoc *
+PDFDocFactory::createPDFDoc(GooString* uri, GooString *ownerPassword,
+ GooString *userPassword, void *guiDataA)
+{
+ for (int i = builders->getLength() - 1; i >= 0 ; i--) {
+ PDFDocBuilder *builder = (PDFDocBuilder *) builders->get(i);
+ if (builder->supports(uri)) {
+ return builder->buildPDFDoc(uri, ownerPassword, userPassword, guiDataA);
+ }
+ }
+
+ error(-1, "Cannot handle URI '%s'.", uri->getCString());
+ GooString *fileName = new GooString(uri);
+ return PDFDoc::ErrorPDFDoc(errOpenFile, fileName);
+}
+
+void PDFDocFactory::registerPDFDocBuilder(PDFDocBuilder *pdfDocBuilder)
+{
+ builders->append(pdfDocBuilder);
+}
+
+
diff --git a/poppler/PDFDocFactory.h b/poppler/PDFDocFactory.h
new file mode 100644
index 0000000..00ee359
--- /dev/null
+++ b/poppler/PDFDocFactory.h
@@ -0,0 +1,42 @@
+//========================================================================
+//
+// PDFDocFactory.h
+//
+// This file is licensed under the GPLv2 or later
+//
+// Copyright 2010 Hib Eris <hib@hiberis.nl>
+//
+//========================================================================
+
+#ifndef PDFDOCFACTORY_H
+#define PDFDOCFACTORY_H
+
+#include "PDFDoc.h"
+
+class GooList;
+class GooString;
+class PDFDocBuilder;
+
+//------------------------------------------------------------------------
+// PDFDocFactory
+//------------------------------------------------------------------------
+
+class PDFDocFactory {
+
+public:
+
+ PDFDocFactory(GooList *pdfDocBuilders = NULL);
+ ~PDFDocFactory();
+
+ PDFDoc *createPDFDoc(GooString* uri, GooString *ownerPassword = NULL,
+ GooString *userPassword = NULL, void *guiDataA = NULL);
+
+ void registerPDFDocBuilder(PDFDocBuilder *pdfDocBuilder);
+
+private:
+
+ GooList *builders;
+
+};
+
+#endif /* PDFDOCFACTORY_H */