dsrxmld.h

00001 /*
00002  *
00003  *  Copyright (C) 2003-2005, OFFIS
00004  *
00005  *  This software and supporting documentation were developed by
00006  *
00007  *    Kuratorium OFFIS e.V.
00008  *    Healthcare Information and Communication Systems
00009  *    Escherweg 2
00010  *    D-26121 Oldenburg, Germany
00011  *
00012  *  THIS SOFTWARE IS MADE AVAILABLE,  AS IS,  AND OFFIS MAKES NO  WARRANTY
00013  *  REGARDING  THE  SOFTWARE,  ITS  PERFORMANCE,  ITS  MERCHANTABILITY  OR
00014  *  FITNESS FOR ANY PARTICULAR USE, FREEDOM FROM ANY COMPUTER DISEASES  OR
00015  *  ITS CONFORMITY TO ANY SPECIFICATION. THE ENTIRE RISK AS TO QUALITY AND
00016  *  PERFORMANCE OF THE SOFTWARE IS WITH THE USER.
00017  *
00018  *  Module: dcmsr
00019  *
00020  *  Author: Joerg Riesmeier
00021  *
00022  *  Purpose:
00023  *    classes: DSRXMLDocument
00024  *
00025  *  Last Update:      $Author: meichel $
00026  *  Update Date:      $Date: 2005/12/08 16:05:36 $
00027  *  CVS/RCS Revision: $Revision: 1.5 $
00028  *  Status:           $State: Exp $
00029  *
00030  *  CVS/RCS Log at end of file
00031  *
00032  */
00033 
00034 
00035 #ifndef DSRXMLD_H
00036 #define DSRXMLD_H
00037 
00038 #include "dcmtk/config/osconfig.h"   /* make sure OS specific configuration is included first */
00039 
00040 #include "dcmtk/ofstd/ofstream.h"
00041 #include "dcmtk/dcmsr/dsrtypes.h"
00042 #include "dcmtk/dcmsr/dsrxmlc.h"
00043 
00044 
00045 /*--------------------*
00046  *  type definitions  *
00047  *--------------------*/
00048 
00049 #ifndef WITH_LIBXML
00050 // define types if 'libxml' absent
00051 typedef void (*xmlDocPtr);
00052 typedef void (*xmlCharEncodingHandlerPtr);
00053 typedef char xmlChar;
00054 #endif
00055 
00056 
00057 /*---------------------*
00058  *  class declaration  *
00059  *---------------------*/
00060 
00067 class DSRXMLDocument
00068   : protected DSRTypes
00069 {
00070 
00071   public:
00072 
00073   // --- constructors and destructor ---
00074 
00077     DSRXMLDocument();
00078 
00081     virtual ~DSRXMLDocument();
00082 
00083 
00084   // --- misc routines ---
00085 
00088     void clear();
00089 
00093     OFBool valid() const;
00094 
00099     OFConsole *getLogStream() const;
00100 
00107     void setLogStream(OFConsole *stream);
00108 
00109 
00110   // --- input and output ---
00111 
00119     OFCondition read(const OFString &filename,
00120                      const size_t flags = 0);
00121 
00122 
00123   // --- character encoding ---
00124 
00129     OFBool encodingHandlerValid() const;
00130 
00136     OFCondition setEncodingHandler(const char *charset);
00137 
00138 
00139   // --- navigation and checking ---
00140 
00144     DSRXMLCursor getRootNode() const;
00145 
00156     DSRXMLCursor getNamedNode(const DSRXMLCursor &cursor,
00157                               const char *name,
00158                               const OFBool required = OFTrue) const;
00159 
00165     OFBool matchNode(const DSRXMLCursor &cursor,
00166                      const char *name) const;
00167 
00173     OFCondition checkNode(const DSRXMLCursor &cursor,
00174                           const char *name) const;
00175 
00176 
00177   // --- get attributes and node content ---
00178 
00184     OFBool hasAttribute(const DSRXMLCursor &cursor,
00185                         const char *name) const;
00186 
00198     OFString &getStringFromAttribute(const DSRXMLCursor &cursor,
00199                                      OFString &stringValue,
00200                                      const char *name,
00201                                      const OFBool encoding = OFFalse,
00202                                      const OFBool required = OFTrue) const;
00203 
00214     OFCondition getElementFromAttribute(const DSRXMLCursor &cursor,
00215                                         DcmElement &delem,
00216                                         const char *name,
00217                                         const OFBool encoding = OFFalse,
00218                                         const OFBool required = OFTrue) const;
00219 
00228     OFString &getStringFromNodeContent(const DSRXMLCursor &cursor,
00229                                        OFString &stringValue,
00230                                        const char *name = NULL,
00231                                        const OFBool encoding = OFFalse,
00232                                        const OFBool clearString = OFTrue) const;
00233 
00241     OFCondition getElementFromNodeContent(const DSRXMLCursor &cursor,
00242                                           DcmElement &delem,
00243                                           const char *name = NULL,
00244                                           const OFBool encoding = OFFalse) const;
00245 
00253     E_ValueType getValueTypeFromNode(const DSRXMLCursor &cursor) const;
00254 
00261     E_RelationshipType getRelationshipTypeFromNode(const DSRXMLCursor &cursor) const;
00262 
00263 
00264   // --- error/warning messages ---
00265 
00269     void printUnexpectedNodeWarning(const DSRXMLCursor &cursor) const;
00270 
00275     void printGeneralNodeError(const DSRXMLCursor &cursor,
00276                                const OFCondition &result) const;
00277 
00278   protected:
00279 
00285     OFBool convertUtf8ToCharset(const xmlChar *fromString,
00286                                 OFString &toString) const;
00287 
00292     void printMissingAttributeError(const DSRXMLCursor &cursor,
00293                                     const char *name) const;
00294 
00295   // --- static function ---
00296 
00303     static OFString &getFullNodePath(const DSRXMLCursor &cursor,
00304                                      OFString &stringValue,
00305                                      const OFBool omitCurrent = OFFalse);
00306 
00307 
00308   private:
00309 
00311     xmlDocPtr Document;
00313     xmlCharEncodingHandlerPtr EncodingHandler;
00314 
00316     OFConsole *LogStream;
00317 
00318 // --- declaration copy constructor and assignment operator
00319 
00320     DSRXMLDocument(const DSRXMLDocument &);
00321     DSRXMLDocument &operator=(const DSRXMLDocument &);
00322 };
00323 
00324 
00325 #endif
00326 
00327 
00328 /*
00329  *  CVS/RCS Log:
00330  *  $Log: dsrxmld.h,v $
00331  *  Revision 1.5  2005/12/08 16:05:36  meichel
00332  *  Changed include path schema for all DCMTK header files
00333  *
00334  *  Revision 1.4  2004/01/05 14:35:44  joergr
00335  *  Renamed XML attribute "ref_id" to "ref".
00336  *
00337  *  Revision 1.3  2003/12/01 15:46:18  joergr
00338  *  Changed XML encoding of by-reference relationships if flag
00339  *  XF_valueTypeAsAttribute is set.
00340  *
00341  *  Revision 1.2  2003/08/07 17:31:00  joergr
00342  *  Removed libxml dependency from header files. Simplifies linking (MSVC).
00343  *
00344  *  Revision 1.1  2003/08/07 12:16:37  joergr
00345  *  Added interface classes hiding the access to libxml (document and cursor
00346  *  class).
00347  *
00348  *
00349  */


Generated on 20 Dec 2005 for OFFIS DCMTK Version 3.5.4 by Doxygen 1.4.5