mirror of
https://github.com/qpdf/qpdf.git
synced 2024-05-29 08:20:53 +00:00
QPDFJob: move placeholder json to a separate source file
This commit is contained in:
parent
edef2cd330
commit
9013b7ca91
|
@ -80,7 +80,6 @@ class QPDFJob
|
||||||
void initializeFromArgv(int argc, char* argv[],
|
void initializeFromArgv(int argc, char* argv[],
|
||||||
char const* progname_env = nullptr);
|
char const* progname_env = nullptr);
|
||||||
|
|
||||||
// QXXXQ
|
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
void initializeFromJson(std::string const& json);
|
void initializeFromJson(std::string const& json);
|
||||||
|
|
||||||
|
@ -323,6 +322,11 @@ class QPDFJob
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
static std::string json_out_schema_v1();
|
static std::string json_out_schema_v1();
|
||||||
|
|
||||||
|
// Provide a string that is the help information for the version 1
|
||||||
|
// of JSON format for QPDFJob.
|
||||||
|
QPDF_DLL
|
||||||
|
static std::string json_job_schema_v1();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct RotationSpec
|
struct RotationSpec
|
||||||
{
|
{
|
||||||
|
|
|
@ -33,6 +33,8 @@
|
||||||
#include <qpdf/QPDFWriter.hh>
|
#include <qpdf/QPDFWriter.hh>
|
||||||
#include <qpdf/QIntC.hh>
|
#include <qpdf/QIntC.hh>
|
||||||
|
|
||||||
|
#include <qpdf/auto_job_schema.hh> // JOB_SCHEMA_DATA
|
||||||
|
|
||||||
QPDFJob::ConfigError::ConfigError(std::string const& msg) :
|
QPDFJob::ConfigError::ConfigError(std::string const& msg) :
|
||||||
std::runtime_error(msg)
|
std::runtime_error(msg)
|
||||||
{
|
{
|
||||||
|
@ -478,6 +480,12 @@ QPDFJob::config()
|
||||||
return std::shared_ptr<Config>(new Config(*this));
|
return std::shared_ptr<Config>(new Config(*this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string
|
||||||
|
QPDFJob::json_job_schema_v1()
|
||||||
|
{
|
||||||
|
return JOB_SCHEMA_DATA;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
QPDFJob::parseRotationParameter(std::string const& parameter)
|
QPDFJob::parseRotationParameter(std::string const& parameter)
|
||||||
{
|
{
|
||||||
|
|
|
@ -16,10 +16,6 @@
|
||||||
#include <qpdf/QPDFArgParser.hh>
|
#include <qpdf/QPDFArgParser.hh>
|
||||||
#include <qpdf/QPDFJob.hh>
|
#include <qpdf/QPDFJob.hh>
|
||||||
#include <qpdf/QIntC.hh>
|
#include <qpdf/QIntC.hh>
|
||||||
#include <qpdf/JSONHandler.hh>
|
|
||||||
|
|
||||||
#include <qpdf/auto_job_schema.hh>
|
|
||||||
static JSON JOB_SCHEMA = JSON::parse(JOB_SCHEMA_DATA);
|
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
@ -468,7 +464,7 @@ ArgParser::argEndCopyAttachment()
|
||||||
void
|
void
|
||||||
ArgParser::argJobJsonHelp()
|
ArgParser::argJobJsonHelp()
|
||||||
{
|
{
|
||||||
std::cout << JOB_SCHEMA_DATA << std::endl;
|
std::cout << QPDFJob::json_job_schema_v1() << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -504,94 +500,3 @@ QPDFJob::initializeFromArgv(int argc, char* argv[], char const* progname_env)
|
||||||
QPDFArgParser::bindBare(&QPDFJob::checkConfiguration, this));
|
QPDFArgParser::bindBare(&QPDFJob::checkConfiguration, this));
|
||||||
ap.parseOptions();
|
ap.parseOptions();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
QPDFJob::initializeFromJson(std::string const& json)
|
|
||||||
{
|
|
||||||
std::list<std::string> errors;
|
|
||||||
JSON j = JSON::parse(json);
|
|
||||||
if (! j.checkSchema(JOB_SCHEMA, JSON::f_optional, errors))
|
|
||||||
{
|
|
||||||
std::ostringstream msg;
|
|
||||||
msg << this->m->message_prefix
|
|
||||||
<< ": job json has errors:";
|
|
||||||
for (auto const& error: errors)
|
|
||||||
{
|
|
||||||
msg << std::endl << " " << error;
|
|
||||||
}
|
|
||||||
throw std::runtime_error(msg.str());
|
|
||||||
}
|
|
||||||
|
|
||||||
JSONHandler jh;
|
|
||||||
{
|
|
||||||
jh.addDictHandlers(
|
|
||||||
[](std::string const&){},
|
|
||||||
[](std::string const&){});
|
|
||||||
|
|
||||||
auto input = std::make_shared<JSONHandler>();
|
|
||||||
auto input_file = std::make_shared<JSONHandler>();
|
|
||||||
auto input_file_name = std::make_shared<JSONHandler>();
|
|
||||||
auto output = std::make_shared<JSONHandler>();
|
|
||||||
auto output_file = std::make_shared<JSONHandler>();
|
|
||||||
auto output_file_name = std::make_shared<JSONHandler>();
|
|
||||||
auto output_options = std::make_shared<JSONHandler>();
|
|
||||||
auto output_options_qdf = std::make_shared<JSONHandler>();
|
|
||||||
|
|
||||||
input->addDictHandlers(
|
|
||||||
[](std::string const&){},
|
|
||||||
[](std::string const&){});
|
|
||||||
input_file->addDictHandlers(
|
|
||||||
[](std::string const&){},
|
|
||||||
[](std::string const&){});
|
|
||||||
output->addDictHandlers(
|
|
||||||
[](std::string const&){},
|
|
||||||
[](std::string const&){});
|
|
||||||
output_file->addDictHandlers(
|
|
||||||
[](std::string const&){},
|
|
||||||
[](std::string const&){});
|
|
||||||
output_options->addDictHandlers(
|
|
||||||
[](std::string const&){},
|
|
||||||
[](std::string const&){});
|
|
||||||
|
|
||||||
jh.addDictKeyHandler("input", input);
|
|
||||||
input->addDictKeyHandler("file", input_file);
|
|
||||||
input_file->addDictKeyHandler("name", input_file_name);
|
|
||||||
jh.addDictKeyHandler("output", output);
|
|
||||||
output->addDictKeyHandler("file", output_file);
|
|
||||||
output_file->addDictKeyHandler("name", output_file_name);
|
|
||||||
output->addDictKeyHandler("options", output_options);
|
|
||||||
output_options->addDictKeyHandler("qdf", output_options_qdf);
|
|
||||||
|
|
||||||
input_file_name->addStringHandler(
|
|
||||||
[this](std::string const&, std::string const& v) {
|
|
||||||
config()->inputFile(v.c_str());
|
|
||||||
});
|
|
||||||
output_file_name->addStringHandler(
|
|
||||||
[this](std::string const&, std::string const& v) {
|
|
||||||
config()->outputFile(v.c_str());
|
|
||||||
});
|
|
||||||
output_options_qdf->addBoolHandler(
|
|
||||||
[this](std::string const&, bool v) {
|
|
||||||
// QXXXQ require v to be true
|
|
||||||
config()->qdf();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// {
|
|
||||||
// "input": {
|
|
||||||
// "file": {
|
|
||||||
// "name": "/home/ejb/source/examples/pdf/minimal.pdf"
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
// "output": {
|
|
||||||
// "file": {
|
|
||||||
// "name": "/tmp/a.pdf"
|
|
||||||
// },
|
|
||||||
// "options": {
|
|
||||||
// "qdf": true
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
jh.handle(".", j);
|
|
||||||
}
|
|
||||||
|
|
99
libqpdf/QPDFJob_json.cc
Normal file
99
libqpdf/QPDFJob_json.cc
Normal file
|
@ -0,0 +1,99 @@
|
||||||
|
#include <qpdf/QPDFJob.hh>
|
||||||
|
#include <qpdf/JSONHandler.hh>
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
static JSON JOB_SCHEMA = JSON::parse(QPDFJob::json_job_schema_v1().c_str());
|
||||||
|
|
||||||
|
void
|
||||||
|
QPDFJob::initializeFromJson(std::string const& json)
|
||||||
|
{
|
||||||
|
std::list<std::string> errors;
|
||||||
|
JSON j = JSON::parse(json);
|
||||||
|
if (! j.checkSchema(JOB_SCHEMA, JSON::f_optional, errors))
|
||||||
|
{
|
||||||
|
std::ostringstream msg;
|
||||||
|
msg << this->m->message_prefix
|
||||||
|
<< ": job json has errors:";
|
||||||
|
for (auto const& error: errors)
|
||||||
|
{
|
||||||
|
msg << std::endl << " " << error;
|
||||||
|
}
|
||||||
|
throw std::runtime_error(msg.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
JSONHandler jh;
|
||||||
|
{
|
||||||
|
jh.addDictHandlers(
|
||||||
|
[](std::string const&){},
|
||||||
|
[](std::string const&){});
|
||||||
|
|
||||||
|
auto input = std::make_shared<JSONHandler>();
|
||||||
|
auto input_file = std::make_shared<JSONHandler>();
|
||||||
|
auto input_file_name = std::make_shared<JSONHandler>();
|
||||||
|
auto output = std::make_shared<JSONHandler>();
|
||||||
|
auto output_file = std::make_shared<JSONHandler>();
|
||||||
|
auto output_file_name = std::make_shared<JSONHandler>();
|
||||||
|
auto output_options = std::make_shared<JSONHandler>();
|
||||||
|
auto output_options_qdf = std::make_shared<JSONHandler>();
|
||||||
|
|
||||||
|
input->addDictHandlers(
|
||||||
|
[](std::string const&){},
|
||||||
|
[](std::string const&){});
|
||||||
|
input_file->addDictHandlers(
|
||||||
|
[](std::string const&){},
|
||||||
|
[](std::string const&){});
|
||||||
|
output->addDictHandlers(
|
||||||
|
[](std::string const&){},
|
||||||
|
[](std::string const&){});
|
||||||
|
output_file->addDictHandlers(
|
||||||
|
[](std::string const&){},
|
||||||
|
[](std::string const&){});
|
||||||
|
output_options->addDictHandlers(
|
||||||
|
[](std::string const&){},
|
||||||
|
[](std::string const&){});
|
||||||
|
|
||||||
|
jh.addDictKeyHandler("input", input);
|
||||||
|
input->addDictKeyHandler("file", input_file);
|
||||||
|
input_file->addDictKeyHandler("name", input_file_name);
|
||||||
|
jh.addDictKeyHandler("output", output);
|
||||||
|
output->addDictKeyHandler("file", output_file);
|
||||||
|
output_file->addDictKeyHandler("name", output_file_name);
|
||||||
|
output->addDictKeyHandler("options", output_options);
|
||||||
|
output_options->addDictKeyHandler("qdf", output_options_qdf);
|
||||||
|
|
||||||
|
input_file_name->addStringHandler(
|
||||||
|
[this](std::string const&, std::string const& v) {
|
||||||
|
config()->inputFile(v.c_str());
|
||||||
|
});
|
||||||
|
output_file_name->addStringHandler(
|
||||||
|
[this](std::string const&, std::string const& v) {
|
||||||
|
config()->outputFile(v.c_str());
|
||||||
|
});
|
||||||
|
output_options_qdf->addBoolHandler(
|
||||||
|
[this](std::string const&, bool v) {
|
||||||
|
// QXXXQ require v to be true
|
||||||
|
config()->qdf();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// {
|
||||||
|
// "input": {
|
||||||
|
// "file": {
|
||||||
|
// "name": "/home/ejb/source/examples/pdf/minimal.pdf"
|
||||||
|
// }
|
||||||
|
// },
|
||||||
|
// "output": {
|
||||||
|
// "file": {
|
||||||
|
// "name": "/tmp/a.pdf"
|
||||||
|
// },
|
||||||
|
// "options": {
|
||||||
|
// "qdf": true
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
jh.handle(".", j);
|
||||||
|
}
|
|
@ -74,6 +74,7 @@ SRCS_libqpdf = \
|
||||||
libqpdf/QPDFJob.cc \
|
libqpdf/QPDFJob.cc \
|
||||||
libqpdf/QPDFJob_argv.cc \
|
libqpdf/QPDFJob_argv.cc \
|
||||||
libqpdf/QPDFJob_config.cc \
|
libqpdf/QPDFJob_config.cc \
|
||||||
|
libqpdf/QPDFJob_json.cc \
|
||||||
libqpdf/QPDFMatrix.cc \
|
libqpdf/QPDFMatrix.cc \
|
||||||
libqpdf/QPDFNameTreeObjectHelper.cc \
|
libqpdf/QPDFNameTreeObjectHelper.cc \
|
||||||
libqpdf/QPDFNumberTreeObjectHelper.cc \
|
libqpdf/QPDFNumberTreeObjectHelper.cc \
|
||||||
|
|
Loading…
Reference in New Issue
Block a user