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

tag.cc

00001 /*
00002 *  Name:      tag.cc
00003 *  Authors:   Angel Jimenez Jimenez
00004 *             Rafael Jesus Alcantara Perez
00005 *  Summary:   HTML base tag
00006 *  Date:      $Date: 2003/04/14 00:18:35 $
00007 *  Revision:  $Revision: 1.1 $
00008 *
00009 *  Copyright (C) 1994-2002  Rafael Jesus Alcantara Perez <rafa@dedalo-ing.com>
00010 *
00011 *  This program is free software; you can redistribute it and/or modify
00012 *  it under the terms of the GNU General Public License as published by
00013 *  the Free Software Foundation; either version 2 of the License, or
00014 *  (at your option) any later version.
00015 *
00016 *  This program is distributed in the hope that it will be useful,
00017 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 *  GNU General Public License for more details.
00020 *
00021 *  You should have received a copy of the GNU General Public License
00022 *  along with this program; if not, write to the Free Software
00023 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00024 *  MA 02111-1307, USA.
00025 */
00026 
00027 #include <cstdlib>
00028 #include <mpcl/text/codegen/clause_body_string.hh>
00029 #include <mpcl/text/html/tag.hh>
00030 
00031 
00032 //
00033 //  L O C A L   V A R I A B L E S
00034 //
00035 
00036 mpcl::text::codegen::TPatternBasedCodeGenerator*   mpcl::text::html::TTag::_ptCodeGenerator = NULL;
00037 
00038 
00039 //
00040 //  C O N S T R U C T O R S
00041 //
00042 
00043 void mpcl::text::html::TTag::
00044 _setCodeGenerator (const TPatternBasedCodeGenerator& rktCG)
00045 {
00046 
00047   _ptCodeGenerator = (TPatternBasedCodeGenerator*) &rktCG;
00048 
00049 }  // setCodeGenerator()
00050 
00051 
00052 mpcl::text::html::TTag::
00053 TTag (bool gDYNAMICALLY_CREATED)                  :
00054   IOutputStreamable<>      ()                     ,
00055   gForwardIdentifier       (true)                 ,
00056   gHasBeenDynamiclyCreated (gDYNAMICALLY_CREATED) ,
00057   gIsDynamiclyLoadable     (false)                ,
00058   gIsQualified             (false)                ,
00059   gIsRootNode              (false)                ,
00060   gIsVisible               (true)                 ,
00061   tAttributeMap            ()
00062 {
00063 
00064   tAttributeMap.bind ("class",                "");
00065   tAttributeMap.bind ("class-identifier",     "tag");
00066   tAttributeMap.bind ("id",                   "");
00067   tAttributeMap.bind ("identifier",           "");
00068   tAttributeMap.bind ("qualified-identifier", "");
00069   tAttributeMap.bind ("value",                "");
00070 
00071 }  // TTag()
00072 
00073 
00074 mpcl::text::html::TTag::
00075 TTag (const char* pkcIDENTIFIER, const char* pkcVALUE) :
00076   IOutputStreamable<>      ()                          ,
00077   gForwardIdentifier       (true)                      ,
00078   gHasBeenDynamiclyCreated (false)                     ,
00079   gIsDynamiclyLoadable     (false)                     ,
00080   gIsQualified             (false)                     ,
00081   gIsRootNode              (false)                     ,
00082   gIsVisible               (true)                      ,
00083   tAttributeMap            ()
00084 {
00085   
00086   tAttributeMap.bind ("class",                "");
00087   tAttributeMap.bind ("class-identifier",     "tag");
00088   tAttributeMap.bind ("id",                   pkcIDENTIFIER);
00089   tAttributeMap.bind ("identifier",           pkcIDENTIFIER);
00090   tAttributeMap.bind ("qualified-identifier", pkcIDENTIFIER);
00091   tAttributeMap.bind ("value",                pkcVALUE);
00092 
00093 }  // TTag()
00094 
00095 
00096 mpcl::text::html::TTag::
00097 TTag (const char* pkcIDENTIFIER, bool gDYNAMICALLY_CREATED) :
00098   IOutputStreamable<>      ()                               ,
00099   gForwardIdentifier       (true)                           ,
00100   gHasBeenDynamiclyCreated (gDYNAMICALLY_CREATED)           ,
00101   gIsDynamiclyLoadable     (false)                          ,
00102   gIsQualified             (false)                          ,
00103   gIsRootNode              (false)                          ,
00104   gIsVisible               (true)                           ,
00105   tAttributeMap            ()
00106 {
00107   
00108   tAttributeMap.bind ("class",                "");
00109   tAttributeMap.bind ("class-identifier",     "tag");
00110   tAttributeMap.bind ("id",                   pkcIDENTIFIER);
00111   tAttributeMap.bind ("identifier",           pkcIDENTIFIER);
00112   tAttributeMap.bind ("qualified-identifier", pkcIDENTIFIER);
00113   tAttributeMap.bind ("value",                "");
00114 
00115 }  // TTag()
00116 
00117 
00118 mpcl::text::html::TTag::
00119 ~TTag (void)
00120 {
00121 
00122   clear();
00123 
00124 }  // TTag()
00125 
00126 
00127 void mpcl::text::html::TTag::
00128 setClass (const TString& rkyCLASS, bool)
00129 {
00130 
00131   tAttributeMap ["class"] = rkyCLASS;
00132 
00133 }  // setClass()
00134 
00135 
00136 void mpcl::text::html::TTag::
00137 setClass (const char* pkcCLASS, bool)
00138 {
00139 
00140   tAttributeMap ["class"] = pkcCLASS;
00141 
00142 }  // setClass()
00143 
00144 
00145 //
00146 //  S E L E C T O R S
00147 //
00148 
00149 mpcl::text::html::TTag::iterator mpcl::text::html::TTag::
00150 begin (void)
00151 {
00152 
00153   const char*   pkcFormat = "this class ('%s') doesn't support this function";
00154   TString       yMessage (Format (pkcFormat, identifier().c_str()));
00155 
00156   throw TConstraintException (yMessage, __FILE__, __LINE__);
00157   return iterator();
00158 
00159 }  // begin()
00160       
00161 
00162 mpcl::text::html::TTag::const_iterator mpcl::text::html::TTag::
00163 begin (void) const
00164 {
00165 
00166   const char*   pkcFormat = "this class ('%s') doesn't support this function";
00167   TString       yMessage (Format (pkcFormat, identifier().c_str()));
00168 
00169   throw TConstraintException (yMessage, __FILE__, __LINE__);
00170   return const_iterator();
00171 
00172 }  // begin()
00173       
00174 
00175 mpcl::text::TString mpcl::text::html::TTag::
00176 code (const char* pkcINSTRUCTION, const char* pkcCLAUSE) const
00177 {
00178 
00179   TString   yCode;
00180 
00181   if ( !_ptCodeGenerator )
00182   {
00183     throw TNoCodeGeneratorException ("no code generator", __FILE__, __LINE__);
00184   }
00185   else
00186   {
00187     yCode = (*_ptCodeGenerator) [pkcINSTRUCTION][pkcCLAUSE].instantiate();
00188   }
00189   return yCode;
00190 
00191 }  // code()
00192 
00193 
00194 mpcl::text::TString mpcl::text::html::TTag::
00195 code ( const char*               pkcINSTRUCTION ,
00196        const char*               pkcCLAUSE      ,
00197        const TStringToStringMap& rktVALUE_MAP   ) const
00198 {
00199 
00200   using codegen::TClauseBodyString;
00201 
00202   TString   yCode;
00203 
00204   if ( !_ptCodeGenerator )
00205   {
00206     throw TNoCodeGeneratorException ("no code generator", __FILE__, __LINE__);
00207   }
00208   else
00209   {
00210     TClauseBodyString   yClauseBody ((*_ptCodeGenerator) [pkcINSTRUCTION][pkcCLAUSE]);
00211 
00212     yClauseBody.setParameterExistenceSensitiveness (false);
00213     yCode = yClauseBody.instantiate (rktVALUE_MAP);
00214   }
00215   return yCode;
00216 
00217 }  // code()
00218 
00219 
00220 mpcl::text::html::TTag::iterator mpcl::text::html::TTag::
00221 end (void)
00222 {
00223 
00224   const char*   pkcFormat = "this class ('%s') doesn't support this function";
00225   TString       yMessage (Format (pkcFormat, identifier().c_str()));
00226 
00227   throw TConstraintException (yMessage, __FILE__, __LINE__);
00228   return iterator();
00229 
00230 }  // end()
00231 
00232 
00233 mpcl::text::html::TTag::const_iterator mpcl::text::html::TTag::
00234 end (void) const
00235 {
00236 
00237   const char*   pkcFormat = "this class ('%s') doesn't support this function";
00238   TString       yMessage (Format (pkcFormat, identifier().c_str()));
00239 
00240   throw TConstraintException (yMessage, __FILE__, __LINE__);
00241   return const_iterator();
00242 
00243 }  // end()
00244 
00245 
00246 void mpcl::text::html::TTag::
00247 expand (TStringToStringMap& rtTARGET_VARIABLE_MAP) const
00248 {
00249 
00250   TStringToStringMap::const_iterator   ktIter = tAttributeMap.begin();
00251   TStringToStringMap::const_iterator   ktEnd  = tAttributeMap.end();
00252 
00253   for (; ( ktIter != ktEnd ) ;++ktIter)
00254   {
00255     if ( ktIter->first == "align" )
00256     {
00257       rtTARGET_VARIABLE_MAP.bind ("align", code ("attribute.align", ktIter->second.c_str()));
00258     }
00259     else if ( ktIter->first == "bgcolor" )
00260     {
00261       if ( ktIter->second.empty() )
00262       {
00263         rtTARGET_VARIABLE_MAP.bind ("bgcolor", "");
00264       }
00265       else
00266       {
00267         rtTARGET_VARIABLE_MAP.bind ("bgcolor", code ("attribute", "bgcolor", tAttributeMap));
00268       }
00269     }
00270     else if ( ktIter->first == "cgi-method" )
00271     {
00272       rtTARGET_VARIABLE_MAP.bind ("cgi-method", code ("attribute.cgi-method", ktIter->second.c_str()));
00273     }
00274     else if ( ktIter->first == "checked" )
00275     {
00276       rtTARGET_VARIABLE_MAP.bind ("checked", code ("attribute.checked", ktIter->second.c_str()));
00277     }
00278     else if ( ktIter->first == "class" )
00279     {
00280       if ( ktIter->second.empty() )
00281       {
00282         rtTARGET_VARIABLE_MAP.bind ("class", "");
00283       }
00284       else
00285       {
00286         rtTARGET_VARIABLE_MAP.bind ("class", code ("attribute", "class", tAttributeMap));
00287       }
00288     }
00289     else if ( ktIter->first == "colspan" )
00290     {
00291       if ( ktIter->second.empty() )
00292       {
00293         rtTARGET_VARIABLE_MAP.bind ("colspan", "");
00294       }
00295       else
00296       {
00297         rtTARGET_VARIABLE_MAP.bind ("colspan", code ("attribute", "colspan", tAttributeMap));
00298       }
00299     }
00300     else if ( ktIter->first == "halign" )
00301     {
00302       rtTARGET_VARIABLE_MAP.bind ("halign", code ("attribute.halign", ktIter->second.c_str()));
00303     }
00304     else if ( ktIter->first == "height" )
00305     {
00306       if ( ktIter->second.empty() )
00307       {
00308         rtTARGET_VARIABLE_MAP.bind ("height", "");
00309       }
00310       else
00311       {
00312         rtTARGET_VARIABLE_MAP.bind ("height", code ("attribute", "height", tAttributeMap));
00313       }
00314     }
00315     else if ( ktIter->first == "href" )
00316     {
00317       if ( ktIter->second.empty() )
00318       {
00319         rtTARGET_VARIABLE_MAP.bind ("href", "");
00320       }
00321       else
00322       {
00323         rtTARGET_VARIABLE_MAP.bind ("href", code ("attribute", "href", tAttributeMap));
00324       }
00325     }
00326     else if ( ktIter->first == "id" )
00327     {
00328       if ( ktIter->second.empty() )
00329       {
00330         rtTARGET_VARIABLE_MAP.bind ("id", "");
00331       }
00332       else
00333       {
00334         rtTARGET_VARIABLE_MAP.bind ("id", code ("attribute", "id", tAttributeMap));
00335       }
00336     }
00337     else if ( ktIter->first == "ismap" )
00338     {
00339       rtTARGET_VARIABLE_MAP.bind ("ismap", code ("attribute.ismap", ktIter->second.c_str()));
00340     }
00341     else if ( ktIter->first == "maxlength" )
00342     {
00343       if ( 0 < atoi (ktIter->second.c_str()) )
00344       {
00345         rtTARGET_VARIABLE_MAP.bind ("maxlength", code ("attribute", "maxlength", tAttributeMap));
00346       }
00347       else
00348       {
00349         rtTARGET_VARIABLE_MAP.bind ("maxlength", "");
00350       }
00351     }
00352     else if ( ktIter->first == "multiple" )
00353     {
00354       rtTARGET_VARIABLE_MAP.bind ("multiple", code ("attribute.multiple", ktIter->second.c_str()));
00355     }
00356     else if ( ktIter->first == "noresize" )
00357     {
00358       rtTARGET_VARIABLE_MAP.bind ("noresize", code ("attribute.noresize", ktIter->second.c_str()));
00359     }
00360     else if ( ktIter->first == "noshade" )
00361     {
00362       rtTARGET_VARIABLE_MAP.bind ("noshade", code ("attribute.noshade", ktIter->second.c_str()));
00363     }
00364     else if ( ktIter->first == "nowrap" )
00365     {
00366       rtTARGET_VARIABLE_MAP.bind ("nowrap", code ("attribute.nowrap", ktIter->second.c_str()));
00367     }
00368     else if ( ktIter->first == "rowspan" )
00369     {
00370       if ( ktIter->second.empty() )
00371       {
00372         rtTARGET_VARIABLE_MAP.bind ("rowspan", "");
00373       }
00374       else
00375       {
00376         rtTARGET_VARIABLE_MAP.bind ("rowspan", code ("attribute", "rowspan", tAttributeMap));
00377       }
00378     }
00379     else if ( ktIter->first == "selected" )
00380     {
00381       rtTARGET_VARIABLE_MAP.bind ("selected", code ("attribute.selected", ktIter->second.c_str()));
00382     }
00383     else if ( ktIter->first == "size" )
00384     {
00385       if ( 0 < atoi (ktIter->second.c_str()) )
00386       {
00387         rtTARGET_VARIABLE_MAP.bind ("size", code ("attribute", "size", tAttributeMap));
00388       }
00389       else
00390       {
00391         rtTARGET_VARIABLE_MAP.bind ("size", "");
00392       }
00393     }
00394     else if ( ktIter->first == "target-named-anchor" )
00395     {
00396       if ( ktIter->second.empty() )
00397       {
00398         rtTARGET_VARIABLE_MAP.bind ("target-named-anchor", "");
00399       }
00400       else
00401       {
00402         rtTARGET_VARIABLE_MAP.bind ("target-named-anchor", TString ("#") + ktIter->second);
00403       }
00404     }
00405     else if ( ktIter->first == "valign" )
00406     {
00407       rtTARGET_VARIABLE_MAP.bind ("valign", code ("attribute.valign", ktIter->second.c_str()));
00408     }
00409     else if ( ktIter->first == "width" )
00410     {
00411       if ( ktIter->second.empty() )
00412       {
00413         rtTARGET_VARIABLE_MAP.bind ("width", "");
00414       }
00415       else
00416       {
00417         rtTARGET_VARIABLE_MAP.bind ("width", code ("attribute", "width", tAttributeMap));
00418       }
00419     }
00420     else
00421     {
00422       rtTARGET_VARIABLE_MAP.bind (ktIter->first, ktIter->second);
00423     }
00424   }
00425 
00426 }  // expand()
00427 
00428 
00429 const mpcl::text::html::TTag& mpcl::text::html::TTag::
00430 operator [] (const char*) const
00431 {
00432   
00433   const char*   pkcFormat = "this class ('%s') doesn't support this operator";
00434   TString       yMessage (Format (pkcFormat, identifier().c_str()));
00435 
00436   throw TConstraintException (yMessage, __FILE__, __LINE__);
00437   return *this;
00438   
00439 }  // operator []()
00440 
00441 
00442 mpcl::text::html::TTag& mpcl::text::html::TTag::
00443 operator [] (const char*)
00444 {
00445   
00446   const char*   pkcFormat = "this class ('%s') doesn't support this operator";
00447   TString       yMessage (Format (pkcFormat, identifier().c_str()));
00448 
00449   throw TConstraintException (yMessage, __FILE__, __LINE__);
00450   return *this;
00451   
00452 }  // operator []()
00453 
00454 
00455 mpcl::text::html::TTag::size_type mpcl::text::html::TTag::
00456 size (void) const
00457 {
00458 
00459   const char*   pkcFormat = "this class ('%s') doesn't support this function";
00460   TString       yMessage (Format (pkcFormat, identifier().c_str()));
00461 
00462   throw TConstraintException (yMessage, __FILE__, __LINE__);
00463   return 0;
00464 
00465 }  // size()
00466 
00467 
00468 mpcl::text::html::QTTag mpcl::text::html::TTag::
00469 tag (const TString&) const
00470 {
00471 
00472   const char*   pkcFormat = "this class ('%s') doesn't support this operator";
00473   TString       yMessage (Format (pkcFormat, identifier().c_str()));
00474 
00475   throw TConstraintException (yMessage, __FILE__, __LINE__);
00476   return QTTag();
00477 
00478 }  // tag()
00479 
00480 
00481 void mpcl::text::html::TTag::
00482 writeUsing ( std::basic_ostream<char>&  rtTARGET_OSTREAM        ,
00483              const TString&             rkyQUALIFIED_IDENTIFIER ) const
00484 {
00485 
00486   if ( isVisible() )
00487   {
00488     TStringToStringMap   tTargetValueMap;
00489     TString              yPathIdentifier = rkyQUALIFIED_IDENTIFIER;
00490 
00491     expand (tTargetValueMap);
00492     if ( gIsQualified && !qualifiedIdentifier().empty() )
00493     {
00494       if ( !yPathIdentifier.empty() )
00495       {
00496         yPathIdentifier += kcIdentifierSeparator;
00497       }
00498       yPathIdentifier += qualifiedIdentifier();
00499     }
00500     tTargetValueMap ["qualified-identifier"] = yPathIdentifier;
00501     rtTARGET_OSTREAM << code (tTargetValueMap ["class-identifier"].c_str(), "body", tTargetValueMap);
00502   }
00503   
00504 }  // writeUsing()

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