summaryrefslogtreecommitdiff
path: root/Build/source/libs/poppler/poppler-src/poppler/PDFDocFactory.cc
blob: 1ec464772370d656b1a52e8921611d309c67f310 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//========================================================================
//
// PDFDocFactory.cc
//
// This file is licensed under the GPLv2 or later
//
// Copyright 2010 Hib Eris <hib@hiberis.nl>
// Copyright 2010 Albert Astals Cid <aacid@kde.org>
//
//========================================================================

#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(const 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(errInternal, -1, "Cannot handle URI '{0:t}'.", &uri);
  GooString *fileName = uri.copy();
  return PDFDoc::ErrorPDFDoc(errOpenFile, fileName);
}

void PDFDocFactory::registerPDFDocBuilder(PDFDocBuilder *pdfDocBuilder)
{
  builders->append(pdfDocBuilder);
}