Commit 8d42eb2632ca5c2ae1200160e78116505b57f6b0

Authored by Jay Berkenbilt
1 parent 4fe2e06b

Add scaffolding for QPDF JSON reactor

include/qpdf/QPDF.hh
... ... @@ -115,22 +115,18 @@ class QPDF
115 115 // complete representation of a PDF. See "QPDF JSON Format" in the
116 116 // manual for details.
117 117 QPDF_DLL
118   - void
119   - createFromJSON(std::string const& json_file);
  118 + void createFromJSON(std::string const& json_file);
120 119 QPDF_DLL
121   - void
122   - createFromJSON(std::shared_ptr<InputSource>);
  120 + void createFromJSON(std::shared_ptr<InputSource>);
123 121  
124 122 // Update a PDF from an input source that contains JSON in the
125 123 // same format as is written by qpdf --json (version 2 or higher).
126 124 // Objects in the PDF and not in the JSON are not modified. See
127 125 // "QPDF JSON Format" in the manual for details.
128 126 QPDF_DLL
129   - void
130   - updateFromJSON(std::string const& json_file);
  127 + void updateFromJSON(std::string const& json_file);
131 128 QPDF_DLL
132   - void
133   - updateFromJSON(std::shared_ptr<InputSource>);
  129 + void updateFromJSON(std::shared_ptr<InputSource>);
134 130  
135 131 // Close or otherwise release the input source. Once this has been
136 132 // called, no other methods of qpdf can be called safely except
... ... @@ -999,6 +995,20 @@ class QPDF
999 995 };
1000 996 friend class ResolveRecorder;
1001 997  
  998 + class JSONReactor: public JSON::Reactor
  999 + {
  1000 + public:
  1001 + virtual ~JSONReactor() = default;
  1002 + virtual void dictionaryStart() override;
  1003 + virtual void arrayStart() override;
  1004 + virtual void containerEnd(JSON const& value) override;
  1005 + virtual void topLevelScalar() override;
  1006 + virtual bool
  1007 + dictionaryItem(std::string const& key, JSON const& value) override;
  1008 + virtual bool arrayItem(JSON const& value) override;
  1009 + };
  1010 + friend class JSONReactor;
  1011 +
1002 1012 void parse(char const* password);
1003 1013 void inParse(bool);
1004 1014 void setTrailer(QPDFObjectHandle obj);
... ... @@ -1508,6 +1518,9 @@ class QPDF
1508 1518 int depth);
1509 1519 void filterCompressedObjects(std::map<int, int> const& object_stream_data);
1510 1520  
  1521 + // JSON import
  1522 + void importJSON(std::shared_ptr<InputSource>, bool must_be_complete);
  1523 +
1511 1524 // Type conversion helper methods
1512 1525 template <typename T>
1513 1526 static qpdf_offset_t
... ...
libqpdf/QPDF_json.cc
... ... @@ -3,15 +3,53 @@
3 3 #include <qpdf/FileInputSource.hh>
4 4  
5 5 void
  6 +QPDF::JSONReactor::dictionaryStart()
  7 +{
  8 + // QXXXXQ
  9 +}
  10 +
  11 +void
  12 +QPDF::JSONReactor::arrayStart()
  13 +{
  14 + // QXXXXQ
  15 +}
  16 +
  17 +void
  18 +QPDF::JSONReactor::containerEnd(JSON const& value)
  19 +{
  20 + // QXXXXQ
  21 +}
  22 +
  23 +void
  24 +QPDF::JSONReactor::topLevelScalar()
  25 +{
  26 + // QXXXXQ
  27 +}
  28 +
  29 +bool
  30 +QPDF::JSONReactor::dictionaryItem(std::string const& key, JSON const& value)
  31 +{
  32 + // QXXXXQ
  33 + return true;
  34 +}
  35 +
  36 +bool
  37 +QPDF::JSONReactor::arrayItem(JSON const& value)
  38 +{
  39 + // QXXXXQ
  40 + return true;
  41 +}
  42 +
  43 +void
6 44 QPDF::createFromJSON(std::string const& json_file)
7 45 {
8 46 createFromJSON(std::make_shared<FileInputSource>(json_file.c_str()));
9 47 }
10 48  
11 49 void
12   -QPDF::createFromJSON(std::shared_ptr<InputSource>)
  50 +QPDF::createFromJSON(std::shared_ptr<InputSource> is)
13 51 {
14   - // QXXXQ
  52 + importJSON(is, true);
15 53 }
16 54  
17 55 void
... ... @@ -21,7 +59,13 @@ QPDF::updateFromJSON(std::string const&amp; json_file)
21 59 }
22 60  
23 61 void
24   -QPDF::updateFromJSON(std::shared_ptr<InputSource>)
  62 +QPDF::updateFromJSON(std::shared_ptr<InputSource> is)
  63 +{
  64 + importJSON(is, false);
  65 +}
  66 +
  67 +void
  68 +QPDF::importJSON(std::shared_ptr<InputSource>, bool must_be_complete)
25 69 {
26 70 // QXXXQ
27 71 }
... ...