Skip to content

Commit

Permalink
Made URL prefix for hyperlinks configurable.
Browse files Browse the repository at this point in the history
Made URL prefix for hyperlinks to composite objects configurable. The
default behavior is to use the URL prefix http://localhost/dicom.cgi,
which is e.g. needed for DICOMscope.

Thanks to GitHub user "thewtex" (Matt McCormick) for the proposal and
the original patch. See GitHub pull request #108 for details.
  • Loading branch information
jriesmeier committed Sep 4, 2024
1 parent 1e1b3cb commit bd3dd3e
Show file tree
Hide file tree
Showing 38 changed files with 230 additions and 68 deletions.
15 changes: 11 additions & 4 deletions dcmsr/apps/dsr2html.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ static OFCondition checkCharacterSet(const char *ifname,
OFLOG_ERROR(dsr2htmlLogger, OFFIS_CONSOLE_APPLICATION << ": SpecificCharacterSet (0008,0005) "
<< "element absent (on the main data set level) but extended characters used in file: " << ifname);
OFLOG_DEBUG(dsr2htmlLogger, "use option --charset-assume to manually specify an appropriate character set");
result = makeOFCondition(OFM_dcmdata, EC_CODE_CannotSelectCharacterSet, OF_error, "Missing Specific Character Set");;
result = makeOFCondition(OFM_dcmdata, EC_CODE_CannotSelectCharacterSet, OF_error, "Missing Specific Character Set");
} else {
result = EC_Normal;
csetString = defaultCharset;
Expand Down Expand Up @@ -169,6 +169,7 @@ static OFCondition renderFile(STD_NAMESPACE ostream &out,
const char *ifname,
DcmFileFormat &dfile,
const char *cssName,
const char *urlPrefix,
const size_t readFlags,
const size_t renderFlags)
{
Expand All @@ -181,7 +182,7 @@ static OFCondition renderFile(STD_NAMESPACE ostream &out,
if (result.good())
{
/* render document in HTML format and write it to the output stream */
result = dsrdoc.renderHTML(out, renderFlags, cssName);
result = dsrdoc.renderHTML(out, renderFlags, cssName, urlPrefix);
} else {
OFLOG_FATAL(dsr2htmlLogger, OFFIS_CONSOLE_APPLICATION << ": error (" << result.text() << ") parsing file: " << ifname);
/* make sure that the caller does not report this error, too */
Expand All @@ -201,6 +202,7 @@ int main(int argc, char *argv[])
size_t opt_readFlags = 0;
size_t opt_renderFlags = DSRTypes::HF_renderDcmtkFootnote;
const char *opt_cssName = NULL;
const char *opt_urlPrefix = NULL;
const char *opt_defaultCharset = NULL;
E_FileReadMode opt_readMode = ERM_autoDetect;
E_TransferSyntax opt_ixfer = EXS_Unknown;
Expand Down Expand Up @@ -267,6 +269,8 @@ int main(int argc, char *argv[])
cmd.addOption("--always-expand-inline", "+Ra", "always expand content items inline");
cmd.addOption("--render-full-data", "+Rd", "render full data of content items");
cmd.addOption("--section-title-inline", "+Rt", "render section titles inline, not separately");
cmd.addOption("--hyperlink-url-prefix", "+Rh", 1, "[p]refix: string",
"use URL prefix p for hyperlinks to composite\nobjects (default: " DEFAULT_HTML_HYPERLINK_PREFIX_FOR_COMPOSITE_OBJECTS ")");
cmd.addSubGroup("document rendering:");
cmd.addOption("--document-type-title", "+Dt", "use document type as document title (default)");
cmd.addOption("--patient-info-title", "+Dp", "use patient information as document title");
Expand Down Expand Up @@ -423,6 +427,9 @@ int main(int argc, char *argv[])
if (cmd.findOption("--section-title-inline"))
opt_renderFlags |= DSRTypes::HF_renderSectionTitlesInline;

if (cmd.findOption("--hyperlink-url-prefix"))
app.checkValue(cmd.getValue(opt_urlPrefix));

/* document rendering */
cmd.beginOptionBlock();
if (cmd.findOption("--document-type-title"))
Expand Down Expand Up @@ -499,7 +506,7 @@ int main(int argc, char *argv[])
if (stream.good())
{
/* render to output file */
status = renderFile(stream, ifname, dfile, opt_cssName, opt_readFlags, opt_renderFlags);
status = renderFile(stream, ifname, dfile, opt_cssName, opt_urlPrefix, opt_readFlags, opt_renderFlags);
if (status.bad() && (status != EC_InternalError))
{
OFLOG_FATAL(dsr2htmlLogger, OFFIS_CONSOLE_APPLICATION << ": error (" << status.text() << ") writing file: "<< ofname);
Expand All @@ -509,7 +516,7 @@ int main(int argc, char *argv[])
result = 1;
} else {
/* use standard output */
status = renderFile(COUT, ifname, dfile, opt_cssName, opt_readFlags, opt_renderFlags);
status = renderFile(COUT, ifname, dfile, opt_cssName, opt_urlPrefix, opt_readFlags, opt_renderFlags);
if (status.bad() && (status != EC_InternalError))
{
OFLOG_FATAL(dsr2htmlLogger, OFFIS_CONSOLE_APPLICATION << ": error (" << status.text() << ") writing to standard output");
Expand Down
4 changes: 2 additions & 2 deletions dcmsr/apps/dsr2xml.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright (C) 2000-2022, OFFIS e.V.
* Copyright (C) 2000-2024, OFFIS e.V.
* All rights reserved. See COPYRIGHT file for details.
*
* This software and supporting documentation were developed by
Expand Down Expand Up @@ -86,7 +86,7 @@ static OFCondition checkCharacterSet(const char *ifname,
OFLOG_ERROR(dsr2xmlLogger, OFFIS_CONSOLE_APPLICATION << ": SpecificCharacterSet (0008,0005) "
<< "element absent (on the main data set level) but extended characters used in file: " << ifname);
OFLOG_DEBUG(dsr2xmlLogger, "use option --charset-assume to manually specify an appropriate character set");
result = makeOFCondition(OFM_dcmdata, EC_CODE_CannotSelectCharacterSet, OF_error, "Missing Specific Character Set");;
result = makeOFCondition(OFM_dcmdata, EC_CODE_CannotSelectCharacterSet, OF_error, "Missing Specific Character Set");
} else {
result = EC_Normal;
csetString = defaultCharset;
Expand Down
4 changes: 4 additions & 0 deletions dcmsr/docs/dsr2html.man
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ general rendering:
+Rt --section-title-inline
render section titles inline, not separately

+Rh --hyperlink-url-prefix [p]refix: string
use URL prefix p for hyperlinks to composite objects
(default: http://localhost/dicom.cgi)

document rendering:

+Dt --document-type-title
Expand Down
4 changes: 4 additions & 0 deletions dcmsr/include/dcmtk/dcmsr/dsrcodtn.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ class DCMTK_DCMSR_EXPORT DSRCodeTreeNode
size_t &annexNumber,
const size_t flags) const;

// --- reintroduce methods from base class

using DSRDocumentTreeNode::renderHTMLContentItem;


private:

Expand Down
8 changes: 7 additions & 1 deletion dcmsr/include/dcmtk/dcmsr/dsrcomtn.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,19 @@ class DCMTK_DCMSR_EXPORT DSRCompositeTreeNode
* @param annexNumber reference to the variable where the current annex number is stored.
* Value is increased automatically by 1 after a new entry has been added.
* @param flags flag used to customize the output (see DSRTypes::HF_xxx)
* @param urlPrefix URL prefix used for hyperlink to referenced composite object
** @return status, EC_Normal if successful, an error code otherwise
*/
virtual OFCondition renderHTMLContentItem(STD_NAMESPACE ostream &docStream,
STD_NAMESPACE ostream &annexStream,
const size_t nestingLevel,
size_t &annexNumber,
const size_t flags) const;
const size_t flags,
const char *urlPrefix) const;

// --- reintroduce methods from base class

using DSRDocumentTreeNode::renderHTMLContentItem;


private:
Expand Down
4 changes: 3 additions & 1 deletion dcmsr/include/dcmtk/dcmsr/dsrcomvl.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,14 @@ class DCMTK_DCMSR_EXPORT DSRCompositeReferenceValue
* @param annexNumber reference to the variable where the current annex number is stored.
* Value is increased automatically by 1 after a new entry has been added.
* @param flags flag used to customize the output (see DSRTypes::HF_xxx)
* @param urlPrefix optional URL prefix used for hyperlink to referenced composite object
** @return status, EC_Normal if successful, an error code otherwise
*/
virtual OFCondition renderHTML(STD_NAMESPACE ostream &docStream,
STD_NAMESPACE ostream &annexStream,
size_t &annexNumber,
const size_t flags) const;
const size_t flags,
const char *urlPrefix = NULL) const;

/** get SOP class UID
** @return current SOP class UID (might be invalid or an empty string)
Expand Down
12 changes: 11 additions & 1 deletion dcmsr/include/dcmtk/dcmsr/dsrcontn.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,15 @@ class DCMTK_DCMSR_EXPORT DSRContainerTreeNode
* @param annexNumber reference to the variable where the current annex number is stored.
* Value is increased automatically by 1 after a new entry has been added.
* @param flags flag used to customize the output (see DSRTypes::HF_xxx)
* @param urlPrefix URL prefix used for hyperlink to referenced composite object
** @return status, EC_Normal if successful, an error code otherwise
*/
virtual OFCondition renderHTML(STD_NAMESPACE ostream &docStream,
STD_NAMESPACE ostream &annexStream,
const size_t nestingLevel,
size_t &annexNumber,
const size_t flags) const;
const size_t flags,
const char *urlPrefix) const;

/** get continuity of content flag.
* This flag specifies whether or not its contained content items (child nodes) are
Expand All @@ -173,6 +175,10 @@ class DCMTK_DCMSR_EXPORT DSRContainerTreeNode
OFCondition setContinuityOfContent(const E_ContinuityOfContent continuityOfContent,
const OFBool check = OFTrue);

// --- reintroduce methods from base class

using DSRDocumentTreeNode::renderHTML;


protected:

Expand Down Expand Up @@ -215,6 +221,10 @@ class DCMTK_DCMSR_EXPORT DSRContainerTreeNode
size_t &annexNumber,
const size_t flags) const;

// --- reintroduce methods from base class

using DSRDocumentTreeNode::renderHTMLContentItem;


private:

Expand Down
4 changes: 4 additions & 0 deletions dcmsr/include/dcmtk/dcmsr/dsrdattn.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ class DCMTK_DCMSR_EXPORT DSRDateTreeNode
*/
virtual OFCondition checkValue(const OFString &dateValue) const;

// --- reintroduce methods from base class

using DSRDocumentTreeNode::renderHTMLContentItem;


private:

Expand Down
27 changes: 18 additions & 9 deletions dcmsr/include/dcmtk/dcmsr/dsrdoc.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,16 @@ class DCMTK_DCMSR_EXPORT DSRDocument
** @param stream output stream to which the HTML/XHTML document is written
* @param flags optional flag used to customize the output (see DSRTypes::HF_xxx)
* @param styleSheet optional filename/URL of a Cascading Style Sheet (CSS)
* @param urlPrefix optional URL prefix used for hyperlinks to referenced composite
* objects. If NULL, the default URL prefix is used, which is
* defined by DEFAULT_HTML_HYPERLINK_PREFIX_FOR_COMPOSITE_OBJECTS
* (http://localhost/dicom.cgi).
** @return status, EC_Normal if successful, an error code otherwise
*/
virtual OFCondition renderHTML(STD_NAMESPACE ostream &stream,
const size_t flags = 0,
const char *styleSheet = NULL);
const char *styleSheet = NULL,
const char *urlPrefix = NULL);


// --- get/set misc attributes ---
Expand Down Expand Up @@ -1278,22 +1283,26 @@ class DCMTK_DCMSR_EXPORT DSRDocument
const size_t flags);

/** render list of referenced SOP instances in HTML/XHTML format
** @param stream output stream to which the HTML/XHTML document is written
* @param refList list of referenced SOP instances to be rendered
* @param flags flag used to customize the output (see DSRTypes::HF_xxx)
** @param stream output stream to which the HTML/XHTML document is written
* @param refList list of referenced SOP instances to be rendered
* @param flags flag used to customize the output (see DSRTypes::HF_xxx)
* @param urlPrefix optional URL prefix used for hyperlinks to referenced composite objects
*/
void renderHTMLReferenceList(STD_NAMESPACE ostream &stream,
DSRSOPInstanceReferenceList &refList,
const size_t flags);
const size_t flags,
const char *urlPrefix = NULL);

/** render list of referenced SOP instances in HTML/XHTML format
** @param stream output stream to which the HTML/XHTML document is written
* @param refList list of referenced SOP instances to be rendered
* @param flags flag used to customize the output (see DSRTypes::HF_xxx)
** @param stream output stream to which the HTML/XHTML document is written
* @param refList list of referenced SOP instances to be rendered
* @param flags flag used to customize the output (see DSRTypes::HF_xxx)
* @param urlPrefix optional URL prefix used for hyperlinks to referenced composite objects
*/
void renderHTMLReferenceList(STD_NAMESPACE ostream &stream,
DSRReferencedInstanceList &refList,
const size_t flags);
const size_t flags,
const char *urlPrefix = NULL);

/** check the given dataset before reading.
* This methods checks whether the dataset contains at least the DICOM attributes SOP class UID
Expand Down
32 changes: 29 additions & 3 deletions dcmsr/include/dcmtk/dcmsr/dsrdoctn.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,15 +222,19 @@ class DCMTK_DCMSR_EXPORT DSRDocumentTreeNode
* @param annexStream output stream to which the HTML/XHTML document annex is written
* @param nestingLevel current nesting level. Used to render section headings.
* @param annexNumber reference to the variable where the current annex number is stored.
* Value is increased automatically by 1 after a new entry has been added.
* Value is increased automatically by 1 after a new entry has been
* added.
* @param flags flag used to customize the output (see DSRTypes::HF_xxx)
* @param urlPrefix optional URL prefix used for hyperlinks to referenced composite
* objects. If NULL, the default URL prefix is used.
** @return status, EC_Normal if successful, an error code otherwise
*/
virtual OFCondition renderHTML(STD_NAMESPACE ostream &docStream,
STD_NAMESPACE ostream &annexStream,
const size_t nestingLevel,
size_t &annexNumber,
const size_t flags) const;
const size_t flags,
const char *urlPrefix = NULL) const;

/** check whether content item is digitally signed.
* A content item is signed if the DigitalSignaturesSequence exists. This sequence is read
Expand Down Expand Up @@ -602,6 +606,26 @@ class DCMTK_DCMSR_EXPORT DSRDocumentTreeNode
size_t &annexNumber,
const size_t flags) const;

/** render content item (value) in HTML/XHTML format.
* This method calls the previous method (without 'urlPrefix'). Derived classes overwrite it
* to render the contents according to their value type.
** @param docStream output stream to which the main HTML/XHTML document is written
* @param annexStream output stream to which the HTML/XHTML document annex is written
* @param nestingLevel current nesting level. Used to render section headings.
* @param annexNumber reference to the variable where the current annex number is stored.
* Value is increased automatically by 1 after a new entry has been
* added.
* @param flags flag used to customize the output (see DSRTypes::HF_xxx)
* @param urlPrefix URL prefix used for hyperlink to referenced composite object
** @return status, EC_Normal if successful, an error code otherwise
*/
virtual OFCondition renderHTMLContentItem(STD_NAMESPACE ostream &docStream,
STD_NAMESPACE ostream &annexStream,
const size_t nestingLevel,
size_t &annexNumber,
const size_t flags,
const char *urlPrefix) const;

/** write common item start (XML tag)
** @param stream output stream to which the XML document is written
* @param flags flag used to customize the output (see DSRTypes::XF_xxx)
Expand Down Expand Up @@ -712,13 +736,15 @@ class DCMTK_DCMSR_EXPORT DSRDocumentTreeNode
* @param annexNumber reference to the variable where the current annex number is stored.
* Value is increased automatically by 1 after a new entry has been added.
* @param flags flag used to customize the output (see DSRTypes::HF_xxx)
* @param urlPrefix optional URL prefix used for hyperlink to referenced composite object
** @return status, EC_Normal if successful, an error code otherwise
*/
OFCondition renderHTMLChildNodes(STD_NAMESPACE ostream &docStream,
STD_NAMESPACE ostream &annexStream,
const size_t nestingLevel,
size_t &annexNumber,
const size_t flags) const;
const size_t flags,
const char *urlPrefix = NULL) const;

// --- static function ---

Expand Down
7 changes: 5 additions & 2 deletions dcmsr/include/dcmtk/dcmsr/dsrdoctr.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright (C) 2000-2018, OFFIS e.V.
* Copyright (C) 2000-2024, OFFIS e.V.
* All rights reserved. See COPYRIGHT file for details.
*
* This software and supporting documentation were developed by
Expand Down Expand Up @@ -137,11 +137,14 @@ class DCMTK_DCMSR_EXPORT DSRDocumentTree
** @param docStream output stream to which the main HTML/XHTML document is written
* @param annexStream output stream to which the HTML/XHTML document annex is written
* @param flags optional flag used to customize the output (see DSRTypes::HF_xxx)
* @param urlPrefix optional URL prefix used for hyperlinks to referenced composite
* objects. If NULL, the default URL prefix is used.
** @return status, EC_Normal if successful, an error code otherwise
*/
virtual OFCondition renderHTML(STD_NAMESPACE ostream &docStream,
STD_NAMESPACE ostream &annexStream,
const size_t flags = 0);
const size_t flags = 0,
const char *urlPrefix = NULL);

/** get document type
** @return current document type (might be DSRTypes::DT_invalid)
Expand Down
4 changes: 4 additions & 0 deletions dcmsr/include/dcmtk/dcmsr/dsrdtitn.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ class DCMTK_DCMSR_EXPORT DSRDateTimeTreeNode
*/
virtual OFCondition checkValue(const OFString &dateTimeValue) const;

// --- reintroduce methods from base class

using DSRDocumentTreeNode::renderHTMLContentItem;


private:

Expand Down
Loading

0 comments on commit bd3dd3e

Please sign in to comment.