#-- QAR_LOAD_TEMPLATE_XML_FILE.pm -----------------------------------------
#
# (c) Copyright Programming Research 2009
#
# Written: C. Waddingham, 30-October-2009
#
# Purpose: .template.xml file loader
#
#---------------------------------------------------------------------------

#-- package QAR_LOAD_TEMPLATE_XML_FILE: ------------------------------------

package QAR_LOAD_TEMPLATE_XML_FILE;

BEGIN
{
   use strict;
   use integer;

   require QAR_UTIL;
   require QAR_PATH;
   require QAR_XML_IO;
}

#---------------------------------------------------------------------------

sub LOAD_REPORT_TEMPLATE_XML_FILE
{
   # Usage: $hr_sections = LOAD_REPORT_TEMPLATE_XML_FILE();
   #
   # Loads a <option details>.xml file into memory.
   # Removes the XML DTD part from the memory image.
   # Lexically parses the memory image for XML markup and data tokens.
   # Parses the token set for all components of the definition
   # - assumes that $xml_file_path is well-formed.
   #
   # Loads:
   # <?xml version='1.0' encoding='UTF-8'?>
   #
   #<prdf:report xmlns:prdf='http://www.programmingresearch.com/todo'
   # xmlns:svg='http://www.w3.org/2000/svg' >
   #  <prdf:title>Code Review Document</prdf:title>
   #  <prdf:project_name>XML Project_Name</prdf:project_name>
   #  <prdf:date>6 August 2009</prdf:date>
   #  <prdf:front_page>
   #  </prdf:front_page>
   #  <prdf:main>
   #	<prdf:component filename='code_review_files.prdf.xml'/>
   #	<prdf:component filename='code_review_classes.prdf.xml'/>
   #	<prdf:component filename='code_review_functions.prdf.xml'/>
   #  </prdf:main>
   #  <prdf:appendices>
   #	<prdf:component filename='list_of_analysed_files.prdf.xml'/>
   #	<prdf:component filename='code_review_personality_options.prdf.xml'/>
   #	<prdf:component filename='code_review_report_settings.prdf.xml'/>
   #  </prdf:appendices>
   #</prdf:report> 
   #

   my $xml_file_name = QAR_PATH::REPORT_TEMPLATE_XML_FILEPATH();

   QAR_XML_IO::OPEN_XML_BUFFER( $xml_file_name );

   my $hr_sections = {};

   SECTION:
   foreach my $section ( "prdf:front_page", "prdf:main", "prdf:appendices", "prdf:version" )
   {
      while ( QAR_XML_IO::GET_CURRENT_TOKEN() ne "<$section>" )
      {
   	 QAR_XML_IO::ADVANCE_CURSOR();

         last SECTION if ( QAR_XML_IO::BEYOND_LAST_TOKEN() );
      }

      QAR_XML_IO::ADVANCE_CURSOR();
   
      my $ar_sections = [];
      while ( QAR_XML_IO::GET_CURRENT_TOKEN() ne "</$section>" )
      {
   	 push @$ar_sections, QAR_XML_IO::DECODE( QAR_XML_IO::PARSE_XML_ITEM( "prdf:component" ) );
      }

      $$hr_sections{ $section } = $ar_sections;

      QAR_XML_IO::ADVANCE_CURSOR();
   }

   QAR_XML_IO::CLOSE_XML_BUFFER();

   return $hr_sections;
}

#-- QAR_LOAD_TEMPLATE_XML_FILE ----------------------------------------

1
