Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members  

pattern_page.cc

00001 /*
00002 *  Name:      pattern_page.cc
00003 *  Author:    Rafael Jesus Alcantara Perez
00004 *  Summary:   HTML pattern page
00005 *  Date:      $Date: 2003/04/14 00:18:35 $
00006 *  Revision:  $Revision: 1.1 $
00007 *
00008 *  Copyright (C) 1994-2002  Rafael Jesus Alcantara Perez <rafa@dedalo-ing.com>
00009 *
00010 *  This program is free software; you can redistribute it and/or modify
00011 *  it under the terms of the GNU General Public License as published by
00012 *  the Free Software Foundation; either version 2 of the License, or
00013 *  (at your option) any later version.
00014 *
00015 *  This program is distributed in the hope that it will be useful,
00016 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 *  GNU General Public License for more details.
00019 *
00020 *  You should have received a copy of the GNU General Public License
00021 *  along with this program; if not, write to the Free Software
00022 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00023 *  MA 02111-1307, USA.
00024 */
00025 
00026 #include <fstream>
00027 #include <mpcl/system/defs.hh>
00028 #include <mpcl/text/html/pattern_page.hh>
00029 
00030 
00031 //
00032 //  C O N S T R U C T O R S
00033 //
00034 
00035 void mpcl::text::html::TPatternPage::
00036 read (std::basic_istream<char>& rtSOURCE_ISTREAM)
00037 {
00038 
00039   using std::getline;
00040   using system::GetErrorMessage;
00041 
00042   TString   yText;
00043 
00044   yPattern = "";
00045   while ( getline (rtSOURCE_ISTREAM, yText).good() )
00046   {
00047     yPattern.append (yText);
00048     yPattern.append (1, '\n');
00049   }
00050   if ( !rtSOURCE_ISTREAM.eof() )
00051   {
00052     TString   yMessage;
00053 
00054     yMessage = Format ( "error while reading pattern page file '%s'; %s" ,
00055                         yFileName.c_str()                                ,
00056                         GetErrorMessage()                                );
00057 
00058     //
00059     //  It could not read til the end of source pattern page file.
00060     //
00061     throw TConstraintException (yMessage, __FILE__, __LINE__);
00062   }
00063 
00064 }  // read()
00065 
00066 
00067 void mpcl::text::html::TPatternPage::
00068 readFromFile (const TString& rkyFILE_NAME)
00069 {
00070 
00071   std::ifstream   tIfstream;
00072 
00073   yFileName = rkyFILE_NAME;
00074   if ( !tIfstream )
00075   {
00076     throw TConstraintException ("could not find pattern page file", __FILE__, __LINE__);
00077   }
00078   else
00079   {
00080     tIfstream.open (yFileName.c_str());
00081     read (tIfstream);
00082   }
00083 
00084 }  // readFromFile()
00085 
00086 
00087 //
00088 //  S E L E C T O R S
00089 //
00090 
00091 void mpcl::text::html::TPatternPage::
00092 writeUsing ( std::basic_ostream<char>& rtTARGET_OSTREAM               ,
00093              const TString&            rkySOURCE_QUALIFIED_IDENTIFIER ) const
00094 {
00095 
00096   if ( isVisible() )
00097   {
00098     TStringToStringMap   tTargetVariableMap;
00099     TString              yNewPathIdentifier;
00100     TString              yPathIdentifier        = rkySOURCE_QUALIFIED_IDENTIFIER;
00101     TString              yGroupAlignInstruction = "group.";
00102 
00103     //
00104     //  Sets the proper instruction.
00105     //
00106     yGroupAlignInstruction += tAttributeMap ["group-align"];
00107     expand (tTargetVariableMap);
00108     if ( gIsQualified && !qualifiedIdentifier().empty() )
00109     {
00110       if ( !yPathIdentifier.empty() )
00111       {
00112         yPathIdentifier += kcIdentifierSeparator;
00113       }
00114       yPathIdentifier += qualifiedIdentifier();
00115     }
00116     tTargetVariableMap ["qualified-identifier"] = yPathIdentifier;
00117     if ( gIsRootNode )
00118     {
00119       if ( gIsQualified && gForwardIdentifier )
00120       {
00121         yNewPathIdentifier += qualifiedIdentifier();
00122       }
00123     }
00124     else
00125     {
00126       yNewPathIdentifier = rkySOURCE_QUALIFIED_IDENTIFIER;
00127       if ( gIsQualified && gForwardIdentifier && !qualifiedIdentifier().empty() )
00128       {
00129         if ( !yNewPathIdentifier.empty() )
00130         {
00131           yNewPathIdentifier += kcIdentifierSeparator;
00132         }
00133         yNewPathIdentifier += qualifiedIdentifier();
00134       }
00135     }
00136 
00137     //
00138     //  Outputs container.
00139     //
00140     TString              yTagIdentifier;
00141     TString::size_type   zDifference;
00142     TString::size_type   zFirstPercentOffset;
00143     TString              yPatternInstance (yPattern);
00144     TString::size_type   zLastPercentOffset = 0;
00145 
00146     while ( true )
00147     {
00148       zFirstPercentOffset = yPatternInstance.find ('%', zLastPercentOffset);
00149       if ( TString::npos == zFirstPercentOffset )
00150       {
00151         rtTARGET_OSTREAM << yPatternInstance.c_str() + zLastPercentOffset;
00152         break;
00153       }
00154       else
00155       {
00156         yPatternInstance [zFirstPercentOffset] = '\0';
00157         rtTARGET_OSTREAM << yPatternInstance.c_str() + zLastPercentOffset;
00158         ++zFirstPercentOffset;
00159         zLastPercentOffset = yPatternInstance.find ('%', zFirstPercentOffset);
00160         if ( TString::npos == zLastPercentOffset )
00161         {
00162           throw TConstraintException ("bad syntax in tag", __FILE__, __LINE__);
00163         }
00164         else
00165         {
00166           zDifference = zLastPercentOffset - zFirstPercentOffset;
00167           if ( !zDifference )
00168           {
00169             //
00170             //  This is the  escape  sequence for the  symbol '%': '%%',  so it
00171             //  writes a percentage symbol.
00172             //
00173             rtTARGET_OSTREAM << '%';
00174           }
00175           else
00176           {
00177             yTagIdentifier.assign (yPatternInstance, zFirstPercentOffset, zDifference);
00178             yPatternInstance [zLastPercentOffset] = '\0';
00179             tStringToTagMap [yTagIdentifier]->writeUsing ( rtTARGET_OSTREAM   ,
00180                                                            yNewPathIdentifier );
00181           }
00182           ++zLastPercentOffset;
00183         }
00184       }
00185     }
00186   }
00187 
00188 }  // writeUsing()

Generated on Mon Oct 13 02:35:23 2003 for MPCL by doxygen1.2.18