DCMTK Version 3.7.0 OFFIS DICOM Toolkit

Public Member Functions | Private Member Functions | Private Attributes | List of all members
DcmJSONReader Class Reference

input stream that reads from standard input More...

## Public Member Functions
| DcmJSONReader ()
| constructor
virtual | ~DcmJSONReader ()
| destructor
virtual void | clear ()
| delete all internal buffers, but keep policy settings
virtual OFCondition | readJSONFile (const char *ifname)
| read a JSON file and store the content in this object More...
virtual OFCondition | readJSONFromStdin ()
| read a JSON dataset from stdin and store the content in this object More...
virtual void | setIgnoreBulkdataURIPolicy (OFBool value)
| set the "ignore bulk data URI" policy More...
virtual void | setStopOnErrorPolicy (OFBool value)
| set the "stop on error" policy More...
virtual void | setIgnoreMetaInfoPolicy (OFBool value)
| set the "ignore meta info" policy More...
virtual void | setArrayHandlingPolicy (signed long value)
| set the array handling policy More...
virtual void | setTransferSyntax (E_TransferSyntax value)
| set the transfer syntax for the dataset More...
virtual E_TransferSyntax | getTransferSyntax () const
| set the transfer syntax for the dataset More...
virtual OFCondition | readAndConvertJSONFile (DcmFileFormat &fileformat, const char *ifname)
| parse the JSON file with the given filename More...
virtual OFCondition | dumpJSONTokenArray ()
| dump the token array produced by the JSMN parser to stderr
virtual OFBool | isFileURI (const OFString &uri) const
| check if the given URI is a file URI More...
virtual OFBool | isHttpURI (const OFString &uri) const
| check if the given URI is a http: or https: URI More...
virtual OFCondition | urlDecode (OFString &uri) const
| URL decode the given URI, i.e. More...
virtual OFCondition | fileURItoPath (const OFString &uri, OFString &filepath, size_t &offset, size_t &length) const
| convert a file URI to a file path in the local filesystem More...
virtual OFCondition | normalizePath (const OFString &filepath_in, OFString &filepath_out) const
| normalize a file path into an absolute path without symbolic links. More...
virtual OFCondition | addPermittedBulkdataPath (const OFString &dirpath)
| add a path from which bulk data files may be read if referenced by a file BulkdataURI. More...
virtual OFBool | bulkdataPathPermitted (const OFString &filepath) const
| check if the given normalized path (which may include a filename) is in the list of permitted bulk data paths as defined by calls to addPermittedBulkdataPath(). More...
virtual OFCondition | loadBulkdataFile (DcmElement &element, const OFString &filepath, size_t offset, size_t length)
| load bulk data from file and insert it into the given element More...

## Private Member Functions
OFCondition | reserveTokens ()
| calculate the required number of tokens for the JSON dataset and allocate the token array accordingly
virtual OFCondition | parseJSON ()
| parse the JSON dataset that has be read into the buffer More...
| DcmJSONReader (const DcmJSONReader &)
| private unimplemented copy constructor
DcmJSONReader & | operator= (const DcmJSONReader &)
| private unimplemented copy assignment operator
void | getTokenContent (OFString &value, OFJsmnTokenPtr t)
| helper function to retrieve the content of the token. More...
virtual OFCondition | createElement (DcmElement *&newElem, DcmTag &dcmTag, const OFString &vr)
| create DICOM element using the given tag and VR More...
virtual OFCondition | extractTag (OFJsmnTokenPtr keyToken, DcmTagKey &tagkey)
| extract DICOM tag from the given string More...
virtual OFCondition | processJSONEscapeCharacters (OFString &value)
| helper function processing escaped characters in JSON strings More...
virtual OFCondition | parseDataSet (DcmItem *dataset, DcmItem *metaheader, OFJsmnTokenPtr &current)
| parse the dataset part of an XML file containing a DICOM file or a DICOM dataset. More...
virtual OFCondition | parseSequence (DcmSequenceOfItems &sequence, OFJsmnTokenPtr &current)
| parse a DICOM sequence More...
virtual OFCondition | parseElement (DcmItem *dataset, DcmItem *metaheader, OFJsmnTokenPtr &current)
| parse a DICOM element that is not a sequence More...
virtual OFCondition | parseElementValueArray (DcmElement *&newElem, OFJsmnTokenPtr &current)
| parse a value array from JSON to DICOM More...
virtual OFCondition | parsePersonName (OFString &value, OFJsmnTokenPtr &current)
| parse a person name (PN value) More...
virtual OFCondition | storeInlineBinaryValue (DcmElement &element, Uint8 *data, size_t length)
| store decoded inline binary value in a DICOM element More...
virtual OFCondition | storeBulkValue (DcmElement &element, Uint8 *data, size_t length)
| store loaded bulk data value in a DICOM element More...

## Private Attributes
char * | jsonDataset_
| null terminated character string containing the entire JSON dataset
size_t | jsonDatasetLen_
| size of jsonDataset_ in bytes, not including the terminating null byte
OFJsmnTokenPtr | tokenArray_
| array of parsed JSON tokens
int | tokenNumber_
| number of tokens in tokenArray_
OFBool | ignoreBulkdataURIPolicy_
| policy for handling bulk data URIs (true = ignore)
OFBool | stopOnErrorPolicy_
| policy for error handling (false = ignore)
OFBool | ignoreMetaInfoPolicy_
| policy for handling meta info elements in the JSON dataset (true = ignore)
signed long | arrayHandlingPolicy_
| policy for handling arrays of multiple datasets. More...
E_TransferSyntax | xferSyntax_
| transfer syntax of the dataset, default: LittleEndianExplicit
OFList< OFString > | permittedBulkdataDirs_
| list of directories to which file URIs may point

## Detailed Description

input stream that reads from standard input

## Member Function Documentation

## ◆ addPermittedBulkdataPath()

virtual OFCondition DcmJSONReader::addPermittedBulkdataPath | ( | const OFString & | dirpath | ) |
| virtual

add a path from which bulk data files may be read if referenced by a file BulkdataURI.

The path will be normalized before being stored. All subdirectories of the given directory will also be accepted a valid paths.

Parameters

  dirpath | the directory path that is acceptable for bulk data

Returns
  EC_Normal upon success, an error code otherwise

## ◆ bulkdataPathPermitted()

virtual OFBool DcmJSONReader::bulkdataPathPermitted | ( | const OFString & | filepath | ) | const
| virtual

check if the given normalized path (which may include a filename) is in the list of permitted bulk data paths as defined by calls to addPermittedBulkdataPath().

Parameters

  filepath | the file path to be checked

Returns
  OFTrue if path is permitted, OFFalse otherwise

## ◆ createElement()

virtual OFCondition DcmJSONReader::createElement | ( | DcmElement *& | newElem,
|  | DcmTag & | dcmTag,
|  | const OFString & | vr
| ) |  |
| private virtual

create DICOM element using the given tag and VR

Parameters

  newElem | pointer to newly created DICOM element returned in this parameter
  dcmTag | attribute tag
  vr | the string representation of the VR (if present)

Returns
  EC_Normal upon success, an error code otherwise

## ◆ extractTag()

virtual OFCondition DcmJSONReader::extractTag | ( | OFJsmnTokenPtr | keyToken,
|  | DcmTagKey & | tagkey
| ) |  |
| private virtual

extract DICOM tag from the given string

Parameters

  keyToken | token containing the string representation of the tag in form of "ggggeeee"
  tagkey | stores the extracted DICOM tag

Returns
  EC_Normal upon success, an error code otherwise

## ◆ fileURItoPath()

virtual OFCondition DcmJSONReader::fileURItoPath | ( | const OFString & | uri,
|  | OFString & | filepath,
|  | size_t & | offset,
|  | size_t & | length
| ) |  | const
| virtual

convert a file URI to a file path in the local filesystem

Parameters

  uri | the file URI to convert
  filepath | the file path is returned in this parameter
  offset | the byte offset within the file is returned in this parameter
  length | the number of bytes to read from the file is returned in this parameter, 0 means 'unlimited'

Returns
  EC_Normal upon success, an error code otherwise

## ◆ getTokenContent()

void DcmJSONReader::getTokenContent | ( | OFString & | value,
|  | OFJsmnTokenPtr | t
| ) |  |
| private

helper function to retrieve the content of the token.

There is no check on boundaries!

Parameters

  value | the result string
  t | token pointer

## ◆ getTransferSyntax()

virtual E_TransferSyntax DcmJSONReader::getTransferSyntax | ( |  | ) | const
| inline virtual

set the transfer syntax for the dataset

Parameters

  value | transfer syntax

## ◆ isFileURI()

virtual OFBool DcmJSONReader::isFileURI | ( | const OFString & | uri | ) | const
| virtual

check if the given URI is a file URI

Parameters

  uri | URI to check

Returns
  true if the URI is a file URI

## ◆ isHttpURI()

virtual OFBool DcmJSONReader::isHttpURI | ( | const OFString & | uri | ) | const
| virtual

check if the given URI is a http: or https: URI

Parameters

  uri | URI to check

Returns
  true if the URI is a http: or https: URI

## ◆ loadBulkdataFile()

virtual OFCondition DcmJSONReader::loadBulkdataFile | ( | DcmElement & | element,
|  | const OFString & | filepath,
|  | size_t | offset,
|  | size_t | length
| ) |  |
| virtual

load bulk data from file and insert it into the given element

Parameters

  element | element into which the value will be inserted
  filepath | path to the bulk data file
  offset | offset in bytes within the file from where to start reading
  length | number of bytes to read from file, 0 for the entire file from the given offset

Returns
  EC_Normal upon success, an error code otherwise

## ◆ normalizePath()

virtual OFCondition DcmJSONReader::normalizePath | ( | const OFString & | filepath_in,
|  | OFString & | filepath_out
| ) |  | const
| virtual

normalize a file path into an absolute path without symbolic links.

On Windows, the long version of directory and file names will be generated and converted to uppercase, since the Win32 file API uses case insensitive filenames

Parameters

  filepath_in | the file path to be normalized
  filepath_out | the normalized file path is returned in this parameter. This parameter must not reference the same string as filepath_in.

Returns
  EC_Normal upon success, an error code otherwise

## ◆ parseDataSet()

virtual OFCondition DcmJSONReader::parseDataSet | ( | DcmItem * | dataset,
|  | DcmItem * | metaheader,
|  | OFJsmnTokenPtr & | current
| ) |  |
| private virtual

parse the dataset part of an XML file containing a DICOM file or a DICOM dataset.

Parameters

  dataset | dataset stored in this parameter
  metaheader | metaheader stored in this parameter
  current | pointer to current JSMN Token

Returns
  EC_Normal upon success, an error code otherwise

## ◆ parseElement()

virtual OFCondition DcmJSONReader::parseElement | ( | DcmItem * | dataset,
|  | DcmItem * | metaheader,
|  | OFJsmnTokenPtr & | current
| ) |  |
| private virtual

parse a DICOM element that is not a sequence

Parameters

  dataset | dataset stored in this parameter
  metaheader | metaheader stored in this parameter
  current | pointer to current JSMN Token

Returns
  EC_Normal upon success, an error code otherwise

## ◆ parseElementValueArray()

virtual OFCondition DcmJSONReader::parseElementValueArray | ( | DcmElement *& | newElem,
|  | OFJsmnTokenPtr & | current
| ) |  |
| private virtual

parse a value array from JSON to DICOM

Parameters

  newElem | Pointer to element where the value should be stored
  current | pointer to current token in the tokenArray

Returns
  EC_Normal upon success, an error code otherwise

## ◆ parseJSON()

virtual OFCondition DcmJSONReader::parseJSON | ( |  | ) |
| private virtual

parse the JSON dataset that has be read into the buffer

Returns
  EC_Normal upon success, an error code otherwise

## ◆ parsePersonName()

virtual OFCondition DcmJSONReader::parsePersonName | ( | OFString & | value,
|  | OFJsmnTokenPtr & | current
| ) |  |
| private virtual

parse a person name (PN value)

Parameters

  value | string containing the PN DICOM value
  current | pointer to current token in the tokenArray

Returns
  EC_Normal upon success, an error code otherwise

## ◆ parseSequence()

virtual OFCondition DcmJSONReader::parseSequence | ( | DcmSequenceOfItems & | sequence,
|  | OFJsmnTokenPtr & | current
| ) |  |
| private virtual

parse a DICOM sequence

Parameters

  sequence | DICOM Sequence
  current | pointer to current token in the tokenArray

Returns
  EC_Normal upon success, an error code otherwise

## ◆ processJSONEscapeCharacters()

virtual OFCondition DcmJSONReader::processJSONEscapeCharacters | ( | OFString & | value | ) |
| private virtual

helper function processing escaped characters in JSON strings

Parameters

  value | containing the string. The string will be changed

Returns
  EC_Normal upon success, an error code otherwise

## ◆ readAndConvertJSONFile()

virtual OFCondition DcmJSONReader::readAndConvertJSONFile | ( | DcmFileFormat & | fileformat,
|  | const char * | ifname
| ) |  |
| virtual

parse the JSON file with the given filename

Parameters

  fileformat | DcmFileFormat instance to be populated with the parsed JSON content
  ifname | name of the JSON file to be read

Returns
  EC_Normal upon success, an error code otherwise

## ◆ readJSONFile()

virtual OFCondition DcmJSONReader::readJSONFile | ( | const char * | ifname | ) |
| virtual

read a JSON file and store the content in this object

Parameters

  ifname | name of the JSON file to be read

Returns
  EC_Normal upon success, an error code otherwise

## ◆ readJSONFromStdin()

virtual OFCondition DcmJSONReader::readJSONFromStdin | ( |  | ) |
| virtual

read a JSON dataset from stdin and store the content in this object

Returns
  EC_Normal upon success, an error code otherwise

## ◆ setArrayHandlingPolicy()

virtual void DcmJSONReader::setArrayHandlingPolicy | ( | signed long | value | ) |
| inline virtual

set the array handling policy

Parameters

  value | new policy -1: reject arrays with more than one dataset 0: store arrays with multiple datasets as a private sequence n > 0: select dataset n from the array, ignore all others

## ◆ setIgnoreBulkdataURIPolicy()

virtual void DcmJSONReader::setIgnoreBulkdataURIPolicy | ( | OFBool | value | ) |
| inline virtual

set the "ignore bulk data URI" policy

Parameters

  value | new policy, true = ignore bulk data URIs

## ◆ setIgnoreMetaInfoPolicy()

virtual void DcmJSONReader::setIgnoreMetaInfoPolicy | ( | OFBool | value | ) |
| inline virtual

set the "ignore meta info" policy

Parameters

  value | new policy, true = ignore meta info elements in JSON dataset

## ◆ setStopOnErrorPolicy()

virtual void DcmJSONReader::setStopOnErrorPolicy | ( | OFBool | value | ) |
| inline virtual

set the "stop on error" policy

Parameters

  value | new policy, true = stop when encountering a parse error

## ◆ setTransferSyntax()

virtual void DcmJSONReader::setTransferSyntax | ( | E_TransferSyntax | value | ) |
| inline virtual

set the transfer syntax for the dataset

Parameters

  value | transfer syntax

## ◆ storeBulkValue()

virtual OFCondition DcmJSONReader::storeBulkValue | ( | DcmElement & | element,
|  | Uint8 * | data,
|  | size_t | length
| ) |  |
| private virtual

store loaded bulk data value in a DICOM element

Parameters

  element | element into which the value will be inserted
  data | buffer containing the bulk data
  length | of the buffer

Returns
  EC_Normal upon success, an error code otherwise

## ◆ storeInlineBinaryValue()

virtual OFCondition DcmJSONReader::storeInlineBinaryValue | ( | DcmElement & | element,
|  | Uint8 * | data,
|  | size_t | length
| ) |  |
| private virtual

store decoded inline binary value in a DICOM element

Parameters

  element | element into which the value will be inserted
  data | buffer containing the inline binary data
  length | of the buffer

Returns
  EC_Normal upon success, an error code otherwise

## ◆ urlDecode()

virtual OFCondition DcmJSONReader::urlDecode | ( | OFString & | uri | ) | const
| virtual

URL decode the given URI, i.e.

replace all instances of 'xx' with the hex number xx by the corresponding byte.

Parameters

  uri | URI string, will be modified by this method.

Returns
  EC_Normal upon success, an error code otherwise

## Member Data Documentation

## ◆ arrayHandlingPolicy_

signed long DcmJSONReader::arrayHandlingPolicy_
| private

policy for handling arrays of multiple datasets.

- -1: reject arrays with more than one dataset
- 0: store arrays with multiple datasets as a private sequence
- n > 0: select dataset n from the array, ignore all others

The documentation for this class was generated from the following file:

- dcmdata/include/dcmtk/dcmdata/dcjsonrd.h

Generated on Mon Dec 15 2025 for DCMTK Version 3.7.0 by Doxygen 1.9.1