PDFDocFactory.cc 1.89 KB
Newer Older
Hib Eris's avatar
Hib Eris committed
1 2 3 4 5 6 7
//========================================================================
//
// PDFDocFactory.cc
//
// This file is licensed under the GPLv2 or later
//
// Copyright 2010 Hib Eris <hib@hiberis.nl>
8
// Copyright 2010 Albert Astals Cid <aacid@kde.org>
9
// Copyright 2017 Adrian Johnson <ajohnson@redneon.com>
Hib Eris's avatar
Hib Eris committed
10 11 12 13 14 15 16 17 18 19 20 21
//
//========================================================================

#include <config.h>

#include "PDFDocFactory.h"

#include "goo/GooList.h"
#include "goo/GooString.h"
#include "PDFDoc.h"
#include "LocalPDFDocBuilder.h"
#include "StdinPDFDocBuilder.h"
22
#ifdef ENABLE_LIBCURL
Hib Eris's avatar
Hib Eris committed
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
#include "CurlPDFDocBuilder.h"
#endif
#include "ErrorCodes.h"

//------------------------------------------------------------------------
// PDFDocFactory
//------------------------------------------------------------------------

PDFDocFactory::PDFDocFactory(GooList *pdfDocBuilders)
{
  if (pdfDocBuilders) {
    builders = pdfDocBuilders;
  } else {
    builders = new GooList();
  }
38
#ifdef ENABLE_LIBCURL
Hib Eris's avatar
Hib Eris committed
39 40 41 42 43 44 45 46 47 48 49 50 51 52
  builders->insert(0, new CurlPDFDocBuilder());
#endif
  builders->insert(0, new StdinPDFDocBuilder());
  builders->insert(0, new LocalPDFDocBuilder());
}

PDFDocFactory::~PDFDocFactory()
{
  if (builders) {
    deleteGooList(builders, PDFDocBuilder);
  }
}

PDFDoc *
53
PDFDocFactory::createPDFDoc(const GooString &uri, GooString *ownerPassword,
Hib Eris's avatar
Hib Eris committed
54 55 56 57 58 59 60 61 62
                                    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);
    }
  }

63
  error(errInternal, -1, "Cannot handle URI '{0:t}'.", &uri);
64
  GooString *fileName = uri.copy();
Hib Eris's avatar
Hib Eris committed
65 66 67 68 69 70 71 72 73
  return PDFDoc::ErrorPDFDoc(errOpenFile, fileName);
}

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