Commit 9013b7ca919c13b03488056dff55ffbf5215f008
1 parent
edef2cd3
QPDFJob: move placeholder json to a separate source file
Showing
5 changed files
with
114 additions
and
97 deletions
include/qpdf/QPDFJob.hh
| @@ -80,7 +80,6 @@ class QPDFJob | @@ -80,7 +80,6 @@ class QPDFJob | ||
| 80 | void initializeFromArgv(int argc, char* argv[], | 80 | void initializeFromArgv(int argc, char* argv[], |
| 81 | char const* progname_env = nullptr); | 81 | char const* progname_env = nullptr); |
| 82 | 82 | ||
| 83 | - // QXXXQ | ||
| 84 | QPDF_DLL | 83 | QPDF_DLL |
| 85 | void initializeFromJson(std::string const& json); | 84 | void initializeFromJson(std::string const& json); |
| 86 | 85 | ||
| @@ -323,6 +322,11 @@ class QPDFJob | @@ -323,6 +322,11 @@ class QPDFJob | ||
| 323 | QPDF_DLL | 322 | QPDF_DLL |
| 324 | static std::string json_out_schema_v1(); | 323 | static std::string json_out_schema_v1(); |
| 325 | 324 | ||
| 325 | + // Provide a string that is the help information for the version 1 | ||
| 326 | + // of JSON format for QPDFJob. | ||
| 327 | + QPDF_DLL | ||
| 328 | + static std::string json_job_schema_v1(); | ||
| 329 | + | ||
| 326 | private: | 330 | private: |
| 327 | struct RotationSpec | 331 | struct RotationSpec |
| 328 | { | 332 | { |
libqpdf/QPDFJob.cc
| @@ -33,6 +33,8 @@ | @@ -33,6 +33,8 @@ | ||
| 33 | #include <qpdf/QPDFWriter.hh> | 33 | #include <qpdf/QPDFWriter.hh> |
| 34 | #include <qpdf/QIntC.hh> | 34 | #include <qpdf/QIntC.hh> |
| 35 | 35 | ||
| 36 | +#include <qpdf/auto_job_schema.hh> // JOB_SCHEMA_DATA | ||
| 37 | + | ||
| 36 | QPDFJob::ConfigError::ConfigError(std::string const& msg) : | 38 | QPDFJob::ConfigError::ConfigError(std::string const& msg) : |
| 37 | std::runtime_error(msg) | 39 | std::runtime_error(msg) |
| 38 | { | 40 | { |
| @@ -478,6 +480,12 @@ QPDFJob::config() | @@ -478,6 +480,12 @@ QPDFJob::config() | ||
| 478 | return std::shared_ptr<Config>(new Config(*this)); | 480 | return std::shared_ptr<Config>(new Config(*this)); |
| 479 | } | 481 | } |
| 480 | 482 | ||
| 483 | +std::string | ||
| 484 | +QPDFJob::json_job_schema_v1() | ||
| 485 | +{ | ||
| 486 | + return JOB_SCHEMA_DATA; | ||
| 487 | +} | ||
| 488 | + | ||
| 481 | void | 489 | void |
| 482 | QPDFJob::parseRotationParameter(std::string const& parameter) | 490 | QPDFJob::parseRotationParameter(std::string const& parameter) |
| 483 | { | 491 | { |
libqpdf/QPDFJob_argv.cc
| @@ -16,10 +16,6 @@ | @@ -16,10 +16,6 @@ | ||
| 16 | #include <qpdf/QPDFArgParser.hh> | 16 | #include <qpdf/QPDFArgParser.hh> |
| 17 | #include <qpdf/QPDFJob.hh> | 17 | #include <qpdf/QPDFJob.hh> |
| 18 | #include <qpdf/QIntC.hh> | 18 | #include <qpdf/QIntC.hh> |
| 19 | -#include <qpdf/JSONHandler.hh> | ||
| 20 | - | ||
| 21 | -#include <qpdf/auto_job_schema.hh> | ||
| 22 | -static JSON JOB_SCHEMA = JSON::parse(JOB_SCHEMA_DATA); | ||
| 23 | 19 | ||
| 24 | namespace | 20 | namespace |
| 25 | { | 21 | { |
| @@ -468,7 +464,7 @@ ArgParser::argEndCopyAttachment() | @@ -468,7 +464,7 @@ ArgParser::argEndCopyAttachment() | ||
| 468 | void | 464 | void |
| 469 | ArgParser::argJobJsonHelp() | 465 | ArgParser::argJobJsonHelp() |
| 470 | { | 466 | { |
| 471 | - std::cout << JOB_SCHEMA_DATA << std::endl; | 467 | + std::cout << QPDFJob::json_job_schema_v1() << std::endl; |
| 472 | } | 468 | } |
| 473 | 469 | ||
| 474 | void | 470 | void |
| @@ -504,94 +500,3 @@ QPDFJob::initializeFromArgv(int argc, char* argv[], char const* progname_env) | @@ -504,94 +500,3 @@ QPDFJob::initializeFromArgv(int argc, char* argv[], char const* progname_env) | ||
| 504 | QPDFArgParser::bindBare(&QPDFJob::checkConfiguration, this)); | 500 | QPDFArgParser::bindBare(&QPDFJob::checkConfiguration, this)); |
| 505 | ap.parseOptions(); | 501 | ap.parseOptions(); |
| 506 | } | 502 | } |
| 507 | - | ||
| 508 | -void | ||
| 509 | -QPDFJob::initializeFromJson(std::string const& json) | ||
| 510 | -{ | ||
| 511 | - std::list<std::string> errors; | ||
| 512 | - JSON j = JSON::parse(json); | ||
| 513 | - if (! j.checkSchema(JOB_SCHEMA, JSON::f_optional, errors)) | ||
| 514 | - { | ||
| 515 | - std::ostringstream msg; | ||
| 516 | - msg << this->m->message_prefix | ||
| 517 | - << ": job json has errors:"; | ||
| 518 | - for (auto const& error: errors) | ||
| 519 | - { | ||
| 520 | - msg << std::endl << " " << error; | ||
| 521 | - } | ||
| 522 | - throw std::runtime_error(msg.str()); | ||
| 523 | - } | ||
| 524 | - | ||
| 525 | - JSONHandler jh; | ||
| 526 | - { | ||
| 527 | - jh.addDictHandlers( | ||
| 528 | - [](std::string const&){}, | ||
| 529 | - [](std::string const&){}); | ||
| 530 | - | ||
| 531 | - auto input = std::make_shared<JSONHandler>(); | ||
| 532 | - auto input_file = std::make_shared<JSONHandler>(); | ||
| 533 | - auto input_file_name = std::make_shared<JSONHandler>(); | ||
| 534 | - auto output = std::make_shared<JSONHandler>(); | ||
| 535 | - auto output_file = std::make_shared<JSONHandler>(); | ||
| 536 | - auto output_file_name = std::make_shared<JSONHandler>(); | ||
| 537 | - auto output_options = std::make_shared<JSONHandler>(); | ||
| 538 | - auto output_options_qdf = std::make_shared<JSONHandler>(); | ||
| 539 | - | ||
| 540 | - input->addDictHandlers( | ||
| 541 | - [](std::string const&){}, | ||
| 542 | - [](std::string const&){}); | ||
| 543 | - input_file->addDictHandlers( | ||
| 544 | - [](std::string const&){}, | ||
| 545 | - [](std::string const&){}); | ||
| 546 | - output->addDictHandlers( | ||
| 547 | - [](std::string const&){}, | ||
| 548 | - [](std::string const&){}); | ||
| 549 | - output_file->addDictHandlers( | ||
| 550 | - [](std::string const&){}, | ||
| 551 | - [](std::string const&){}); | ||
| 552 | - output_options->addDictHandlers( | ||
| 553 | - [](std::string const&){}, | ||
| 554 | - [](std::string const&){}); | ||
| 555 | - | ||
| 556 | - jh.addDictKeyHandler("input", input); | ||
| 557 | - input->addDictKeyHandler("file", input_file); | ||
| 558 | - input_file->addDictKeyHandler("name", input_file_name); | ||
| 559 | - jh.addDictKeyHandler("output", output); | ||
| 560 | - output->addDictKeyHandler("file", output_file); | ||
| 561 | - output_file->addDictKeyHandler("name", output_file_name); | ||
| 562 | - output->addDictKeyHandler("options", output_options); | ||
| 563 | - output_options->addDictKeyHandler("qdf", output_options_qdf); | ||
| 564 | - | ||
| 565 | - input_file_name->addStringHandler( | ||
| 566 | - [this](std::string const&, std::string const& v) { | ||
| 567 | - config()->inputFile(v.c_str()); | ||
| 568 | - }); | ||
| 569 | - output_file_name->addStringHandler( | ||
| 570 | - [this](std::string const&, std::string const& v) { | ||
| 571 | - config()->outputFile(v.c_str()); | ||
| 572 | - }); | ||
| 573 | - output_options_qdf->addBoolHandler( | ||
| 574 | - [this](std::string const&, bool v) { | ||
| 575 | - // QXXXQ require v to be true | ||
| 576 | - config()->qdf(); | ||
| 577 | - }); | ||
| 578 | - } | ||
| 579 | - | ||
| 580 | - // { | ||
| 581 | - // "input": { | ||
| 582 | - // "file": { | ||
| 583 | - // "name": "/home/ejb/source/examples/pdf/minimal.pdf" | ||
| 584 | - // } | ||
| 585 | - // }, | ||
| 586 | - // "output": { | ||
| 587 | - // "file": { | ||
| 588 | - // "name": "/tmp/a.pdf" | ||
| 589 | - // }, | ||
| 590 | - // "options": { | ||
| 591 | - // "qdf": true | ||
| 592 | - // } | ||
| 593 | - // } | ||
| 594 | - // } | ||
| 595 | - | ||
| 596 | - jh.handle(".", j); | ||
| 597 | -} |
libqpdf/QPDFJob_json.cc
0 โ 100644
| 1 | +#include <qpdf/QPDFJob.hh> | ||
| 2 | +#include <qpdf/JSONHandler.hh> | ||
| 3 | + | ||
| 4 | +#include <memory> | ||
| 5 | +#include <stdexcept> | ||
| 6 | +#include <sstream> | ||
| 7 | + | ||
| 8 | +static JSON JOB_SCHEMA = JSON::parse(QPDFJob::json_job_schema_v1().c_str()); | ||
| 9 | + | ||
| 10 | +void | ||
| 11 | +QPDFJob::initializeFromJson(std::string const& json) | ||
| 12 | +{ | ||
| 13 | + std::list<std::string> errors; | ||
| 14 | + JSON j = JSON::parse(json); | ||
| 15 | + if (! j.checkSchema(JOB_SCHEMA, JSON::f_optional, errors)) | ||
| 16 | + { | ||
| 17 | + std::ostringstream msg; | ||
| 18 | + msg << this->m->message_prefix | ||
| 19 | + << ": job json has errors:"; | ||
| 20 | + for (auto const& error: errors) | ||
| 21 | + { | ||
| 22 | + msg << std::endl << " " << error; | ||
| 23 | + } | ||
| 24 | + throw std::runtime_error(msg.str()); | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + JSONHandler jh; | ||
| 28 | + { | ||
| 29 | + jh.addDictHandlers( | ||
| 30 | + [](std::string const&){}, | ||
| 31 | + [](std::string const&){}); | ||
| 32 | + | ||
| 33 | + auto input = std::make_shared<JSONHandler>(); | ||
| 34 | + auto input_file = std::make_shared<JSONHandler>(); | ||
| 35 | + auto input_file_name = std::make_shared<JSONHandler>(); | ||
| 36 | + auto output = std::make_shared<JSONHandler>(); | ||
| 37 | + auto output_file = std::make_shared<JSONHandler>(); | ||
| 38 | + auto output_file_name = std::make_shared<JSONHandler>(); | ||
| 39 | + auto output_options = std::make_shared<JSONHandler>(); | ||
| 40 | + auto output_options_qdf = std::make_shared<JSONHandler>(); | ||
| 41 | + | ||
| 42 | + input->addDictHandlers( | ||
| 43 | + [](std::string const&){}, | ||
| 44 | + [](std::string const&){}); | ||
| 45 | + input_file->addDictHandlers( | ||
| 46 | + [](std::string const&){}, | ||
| 47 | + [](std::string const&){}); | ||
| 48 | + output->addDictHandlers( | ||
| 49 | + [](std::string const&){}, | ||
| 50 | + [](std::string const&){}); | ||
| 51 | + output_file->addDictHandlers( | ||
| 52 | + [](std::string const&){}, | ||
| 53 | + [](std::string const&){}); | ||
| 54 | + output_options->addDictHandlers( | ||
| 55 | + [](std::string const&){}, | ||
| 56 | + [](std::string const&){}); | ||
| 57 | + | ||
| 58 | + jh.addDictKeyHandler("input", input); | ||
| 59 | + input->addDictKeyHandler("file", input_file); | ||
| 60 | + input_file->addDictKeyHandler("name", input_file_name); | ||
| 61 | + jh.addDictKeyHandler("output", output); | ||
| 62 | + output->addDictKeyHandler("file", output_file); | ||
| 63 | + output_file->addDictKeyHandler("name", output_file_name); | ||
| 64 | + output->addDictKeyHandler("options", output_options); | ||
| 65 | + output_options->addDictKeyHandler("qdf", output_options_qdf); | ||
| 66 | + | ||
| 67 | + input_file_name->addStringHandler( | ||
| 68 | + [this](std::string const&, std::string const& v) { | ||
| 69 | + config()->inputFile(v.c_str()); | ||
| 70 | + }); | ||
| 71 | + output_file_name->addStringHandler( | ||
| 72 | + [this](std::string const&, std::string const& v) { | ||
| 73 | + config()->outputFile(v.c_str()); | ||
| 74 | + }); | ||
| 75 | + output_options_qdf->addBoolHandler( | ||
| 76 | + [this](std::string const&, bool v) { | ||
| 77 | + // QXXXQ require v to be true | ||
| 78 | + config()->qdf(); | ||
| 79 | + }); | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + // { | ||
| 83 | + // "input": { | ||
| 84 | + // "file": { | ||
| 85 | + // "name": "/home/ejb/source/examples/pdf/minimal.pdf" | ||
| 86 | + // } | ||
| 87 | + // }, | ||
| 88 | + // "output": { | ||
| 89 | + // "file": { | ||
| 90 | + // "name": "/tmp/a.pdf" | ||
| 91 | + // }, | ||
| 92 | + // "options": { | ||
| 93 | + // "qdf": true | ||
| 94 | + // } | ||
| 95 | + // } | ||
| 96 | + // } | ||
| 97 | + | ||
| 98 | + jh.handle(".", j); | ||
| 99 | +} |
libqpdf/build.mk
| @@ -74,6 +74,7 @@ SRCS_libqpdf = \ | @@ -74,6 +74,7 @@ SRCS_libqpdf = \ | ||
| 74 | libqpdf/QPDFJob.cc \ | 74 | libqpdf/QPDFJob.cc \ |
| 75 | libqpdf/QPDFJob_argv.cc \ | 75 | libqpdf/QPDFJob_argv.cc \ |
| 76 | libqpdf/QPDFJob_config.cc \ | 76 | libqpdf/QPDFJob_config.cc \ |
| 77 | + libqpdf/QPDFJob_json.cc \ | ||
| 77 | libqpdf/QPDFMatrix.cc \ | 78 | libqpdf/QPDFMatrix.cc \ |
| 78 | libqpdf/QPDFNameTreeObjectHelper.cc \ | 79 | libqpdf/QPDFNameTreeObjectHelper.cc \ |
| 79 | libqpdf/QPDFNumberTreeObjectHelper.cc \ | 80 | libqpdf/QPDFNumberTreeObjectHelper.cc \ |