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
 
DcmJSONReaderoperator= (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< OFStringpermittedBulkdataDirs_
 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
dirpaththe 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
filepaththe 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 
)
privatevirtual

create DICOM element using the given tag and VR

Parameters
newElempointer to newly created DICOM element returned in this parameter
dcmTagattribute tag
vrthe 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 
)
privatevirtual

extract DICOM tag from the given string

Parameters
keyTokentoken containing the string representation of the tag in form of "ggggeeee"
tagkeystores 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
urithe file URI to convert
filepaththe file path is returned in this parameter
offsetthe byte offset within the file is returned in this parameter
lengththe 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
valuethe result string
ttoken pointer

◆ getTransferSyntax()

virtual E_TransferSyntax DcmJSONReader::getTransferSyntax ( ) const
inlinevirtual

set the transfer syntax for the dataset

Parameters
valuetransfer syntax

◆ isFileURI()

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

check if the given URI is a file URI

Parameters
uriURI 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
uriURI 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
elementelement into which the value will be inserted
filepathpath to the bulk data file
offsetoffset in bytes within the file from where to start reading
lengthnumber 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_inthe file path to be normalized
filepath_outthe 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 
)
privatevirtual

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

Parameters
datasetdataset stored in this parameter
metaheadermetaheader stored in this parameter
currentpointer to current JSMN Token
Returns
EC_Normal upon success, an error code otherwise

◆ parseElement()

virtual OFCondition DcmJSONReader::parseElement ( DcmItem dataset,
DcmItem metaheader,
OFJsmnTokenPtr current 
)
privatevirtual

parse a DICOM element that is not a sequence

Parameters
datasetdataset stored in this parameter
metaheadermetaheader stored in this parameter
currentpointer to current JSMN Token
Returns
EC_Normal upon success, an error code otherwise

◆ parseElementValueArray()

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

parse a value array from JSON to DICOM

Parameters
newElemPointer to element where the value should be stored
currentpointer to current token in the tokenArray
Returns
EC_Normal upon success, an error code otherwise

◆ parseJSON()

virtual OFCondition DcmJSONReader::parseJSON ( )
privatevirtual

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 
)
privatevirtual

parse a person name (PN value)

Parameters
valuestring containing the PN DICOM value
currentpointer to current token in the tokenArray
Returns
EC_Normal upon success, an error code otherwise

◆ parseSequence()

virtual OFCondition DcmJSONReader::parseSequence ( DcmSequenceOfItems sequence,
OFJsmnTokenPtr current 
)
privatevirtual

parse a DICOM sequence

Parameters
sequenceDICOM Sequence
currentpointer to current token in the tokenArray
Returns
EC_Normal upon success, an error code otherwise

◆ processJSONEscapeCharacters()

virtual OFCondition DcmJSONReader::processJSONEscapeCharacters ( OFString value)
privatevirtual

helper function processing escaped characters in JSON strings

Parameters
valuecontaining 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
fileformatDcmFileFormat instance to be populated with the parsed JSON content
ifnamename 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
ifnamename 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)
inlinevirtual

set the array handling policy

Parameters
valuenew 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)
inlinevirtual

set the "ignore bulk data URI" policy

Parameters
valuenew policy, true = ignore bulk data URIs

◆ setIgnoreMetaInfoPolicy()

virtual void DcmJSONReader::setIgnoreMetaInfoPolicy ( OFBool  value)
inlinevirtual

set the "ignore meta info" policy

Parameters
valuenew policy, true = ignore meta info elements in JSON dataset

◆ setStopOnErrorPolicy()

virtual void DcmJSONReader::setStopOnErrorPolicy ( OFBool  value)
inlinevirtual

set the "stop on error" policy

Parameters
valuenew policy, true = stop when encountering a parse error

◆ setTransferSyntax()

virtual void DcmJSONReader::setTransferSyntax ( E_TransferSyntax  value)
inlinevirtual

set the transfer syntax for the dataset

Parameters
valuetransfer syntax

◆ storeBulkValue()

virtual OFCondition DcmJSONReader::storeBulkValue ( DcmElement element,
Uint8 *  data,
size_t  length 
)
privatevirtual

store loaded bulk data value in a DICOM element

Parameters
elementelement into which the value will be inserted
databuffer containing the bulk data
lengthof the buffer
Returns
EC_Normal upon success, an error code otherwise

◆ storeInlineBinaryValue()

virtual OFCondition DcmJSONReader::storeInlineBinaryValue ( DcmElement element,
Uint8 *  data,
size_t  length 
)
privatevirtual

store decoded inline binary value in a DICOM element

Parameters
elementelement into which the value will be inserted
databuffer containing the inline binary data
lengthof 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
uriURI 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:


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