00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 #include <algorithm>
00027 #include <mpcl/text/html/layout_table.hh>
00028 #include <mpcl/text/html/table_cell.hh>
00029 #include <mpcl/text/html/table_row.hh>
00030 
00031 
00032 
00033 
00034 
00035 
00036 mpcl::text::html::QTTag mpcl::text::html::TLayoutTable::
00037 findTag (const TString& rkyIDENTIFIER) const
00038 {
00039 
00040   TStringToTagMap::const_iterator   I;
00041   TStringToTagMap::const_iterator   J;
00042   TStringToTagMap::const_iterator   K;
00043   bool                                  gHasMoreIdentifiers;
00044 
00045 
00046 
00047 
00048 
00049   const TTableCell*                 pktCell;
00050   const TContainer*                 pktContainer;
00051   const TTableRow*                  pktRow;
00052   QTTag                             qtTag;
00053   TString                               yFirstIdentifierPart;
00054   TString                               yLastIdentifierPart;
00055   std::size_t                           zOffset;
00056 
00057   zOffset             = rkyIDENTIFIER.find (kcIdentifierSeparator);
00058   gHasMoreIdentifiers = ( TString::npos != zOffset );
00059   if ( !gHasMoreIdentifiers )
00060   {
00061     yFirstIdentifierPart = rkyIDENTIFIER;
00062   }
00063   else
00064   {
00065     yFirstIdentifierPart = rkyIDENTIFIER.substr (0, zOffset);
00066     yLastIdentifierPart  = rkyIDENTIFIER.substr (zOffset + 1);
00067   }
00068 
00069   
00070   
00071   
00072   I = tStringToTagMap.begin();
00073   for (; ( I != tStringToTagMap.end() && !qtTag ) ;++I)
00074   {
00075     
00076     
00077     
00078 
00079 
00080 
00081 
00082 
00083     pktRow = I->second.dynamicCast<const TTableRow*>();
00084     J      = pktRow->tStringToTagMap.begin();
00085     for (; ( ( J != pktRow->tStringToTagMap.end() ) && !qtTag ) ;++J)
00086     {
00087       
00088       
00089       
00090 
00091 
00092 
00093 
00094 
00095       pktCell = J->second.dynamicCast<const TTableCell*>();
00096       K       = pktCell->tStringToTagMap.find (yFirstIdentifierPart);
00097       if ( K != pktCell->tStringToTagMap.end() )
00098       {
00099         if ( !gHasMoreIdentifiers )
00100         {
00101           qtTag = K->second;
00102         }
00103         else
00104         {
00105 
00106 
00107 
00108 
00109           pktContainer = K->second.dynamicCast<const TContainer*>();
00110           qtTag        = pktContainer->findTag (yLastIdentifierPart);
00111         }
00112         break;
00113       }
00114     }
00115   }
00116   return qtTag;
00117 
00118 }  
00119 
00120 
00121 mpcl::text::html::QTTag mpcl::text::html::TLayoutTable::
00122 findOrInsertTag (const TString& rkyIDENTIFIER)
00123 {
00124 
00125   TStringToTagMap::iterator   I;
00126   TStringToTagMap::iterator   J;
00127   TStringToTagMap::iterator   K;
00128   bool                            gHasMoreIdentifiers;
00129 
00130 
00131 
00132 
00133 
00134   TTableCell*                 ptCell;
00135   TContainer*                 ptContainer;
00136   TTableRow*                  ptRow;
00137   QTTag                       qtTag;
00138   TString                         yFirstIdentifierPart;
00139   TString                         yLastIdentifierPart;
00140   std::size_t                     zOffset;
00141 
00142   zOffset             = rkyIDENTIFIER.find (kcIdentifierSeparator);
00143   gHasMoreIdentifiers = ( TString::npos != zOffset );
00144   if ( !gHasMoreIdentifiers )
00145   {
00146     yFirstIdentifierPart = rkyIDENTIFIER;
00147   }
00148   else
00149   {
00150     yFirstIdentifierPart = rkyIDENTIFIER.substr (0, zOffset);
00151     yLastIdentifierPart  = rkyIDENTIFIER.substr (zOffset + 1);
00152   }
00153 
00154   
00155   
00156   
00157   I = tStringToTagMap.begin();
00158   for (; ( I != tStringToTagMap.end() && !qtTag ) ;++I)
00159   {
00160     
00161     
00162     
00163 
00164 
00165 
00166 
00167 
00168     ptRow = I->second.dynamicCast<TTableRow*>();
00169     J     = ptRow->tStringToTagMap.begin();
00170     for (; ( ( J != ptRow->tStringToTagMap.end() ) && !qtTag ) ;++J)
00171     {
00172       
00173       
00174       
00175 
00176 
00177 
00178 
00179 
00180       ptCell = J->second.dynamicCast<TTableCell*>();
00181       K      = ptCell->tStringToTagMap.find (yFirstIdentifierPart);
00182       if ( K != ptCell->tStringToTagMap.end() )
00183       {
00184         if ( !gHasMoreIdentifiers )
00185         {
00186           qtTag = K->second;
00187         }
00188         else
00189         {
00190 
00191 
00192 
00193 
00194           ptContainer = K->second.dynamicCast<TContainer*>();
00195           qtTag       = ptContainer->findOrInsertTag (yLastIdentifierPart);
00196         }
00197         break;
00198       }
00199     }
00200   }
00201   if ( !qtTag && isDynamiclyLoadable() && !gHasMoreIdentifiers )
00202   {
00203     qtTag = new TTag (rkyIDENTIFIER.c_str(), true);
00204 
00205 
00206 
00207 
00208 
00209     ptRow = new TTableRow();
00210     ptRow->insert (QTTag (new TTableCell (qtTag)));
00211     insert (QTTag (ptRow));
00212   }
00213   if ( !qtTag )
00214   {
00215     const char*   pkcFormat  = "in '%s' there is no tag called '%s'";
00216     TString       yMessage (Format (pkcFormat, identifier().c_str(), rkyIDENTIFIER.c_str()));
00217 
00218     throw TConstraintException (yMessage, __FILE__, __LINE__);
00219   }
00220   return qtTag;
00221 
00222 }