1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #include <precomp.h> 29 #include "hd_docu.hxx" 30 31 32 // NOT FULLY DEFINED SERVICES 33 #include <ary/cpp/c_gate.hxx> 34 #include <ary/cpp/c_namesp.hxx> 35 #include <ary/cpp/c_class.hxx> 36 #include <ary/cpp/c_enum.hxx> 37 #include <ary/cpp/c_tydef.hxx> 38 #include <ary/cpp/c_funct.hxx> 39 #include <ary/cpp/c_vari.hxx> 40 #include <ary/cpp/c_enuval.hxx> 41 #include <ary/doc/d_oldcppdocu.hxx> 42 #include <ary/info/all_tags.hxx> 43 #include <ary/info/all_dts.hxx> 44 #include <adc_cl.hxx> 45 #include "html_kit.hxx" 46 #include "opageenv.hxx" 47 48 49 50 using namespace ary::info; 51 using namespace csi; 52 53 using html::DefList; 54 using html::DefListTerm; 55 using html::DefListDefinition; 56 using html::Headline; 57 using html::Link; 58 59 60 const char * 61 C_sTagHeadlines[ ary::info::C_eAtTag_NrOfClasses ] = 62 { 63 "ATTENTION!", "Author", "Changes", "Collaborators", 64 "Contact", // Contact may be unused 65 "Copyright", "Deprecated", "Description", "Date of Documentation", 66 "How to Derive from this Class", 67 "Heap object - owner is responsible for deletion.", 68 "Important Instances", 69 "Interface Only", 70 "Invariant", "Lifecycle", 71 "Multiplicity", "On Error", "Persistency", "Postcondition", 72 "Precondition", 73 "Responsibilities", 74 "Return", "Summary", "Todos", "Version", 75 "Base Classes", "Exceptions", "Implements", "Keywords", "Parameters", 76 "See Also", "Template Parameters", 77 "", "Since " 78 }; 79 80 81 82 Docu_Display::Docu_Display( OuputPage_Environment & io_rEnv ) 83 : HtmlDisplay_Impl(io_rEnv), 84 bUseHtmlInDocuTokens(false), 85 pCurClassOverwrite(0) 86 { 87 } 88 89 Docu_Display::~Docu_Display() 90 { 91 } 92 93 void 94 Docu_Display::Assign_Out( csi::xml::Element & o_rOut ) 95 { 96 Easy().Enter(o_rOut); 97 } 98 99 void 100 Docu_Display::Unassign_Out() 101 { 102 Easy().Leave(); 103 } 104 105 void 106 Docu_Display::do_Process( const ary::cpp::Namespace & i_rData ) 107 { 108 Process(i_rData.Docu()); 109 } 110 111 void 112 Docu_Display::do_Process( const ary::cpp::Class & i_rData ) 113 { 114 pCurClassOverwrite = &i_rData; 115 Process(i_rData.Docu()); 116 pCurClassOverwrite = 0; 117 } 118 119 void 120 Docu_Display::do_Process( const ary::cpp::Enum & i_rData ) 121 { 122 Process(i_rData.Docu()); 123 } 124 125 void 126 Docu_Display::do_Process( const ary::cpp::Typedef & i_rData ) 127 { 128 Process(i_rData.Docu()); 129 } 130 131 void 132 Docu_Display::do_Process( const ary::cpp::Function & i_rData ) 133 { 134 Process(i_rData.Docu()); 135 } 136 137 void 138 Docu_Display::do_Process( const ary::cpp::Variable & i_rData ) 139 { 140 Process(i_rData.Docu()); 141 } 142 143 144 145 // -------------- Interface ary::info::DocuDisplay ------------------ // 146 147 148 void 149 Docu_Display::do_Process(const ary::doc::Documentation & i_rData) 150 { 151 if (i_rData.Data() == 0) 152 return; 153 154 const ary::doc::OldCppDocu * 155 docdata = dynamic_cast< const ary::doc::OldCppDocu* >(i_rData.Data()); 156 csv_assert(docdata != 0); 157 158 Start_DocuBlock(); 159 160 if ( docdata->IsObsolete() ) 161 { 162 CurOut() 163 >> *new html::DefListTerm 164 >> *new html::Strong 165 << "D E P R E C A T E D"; 166 167 } 168 169 ary::doc::OldCppDocu::TagList::const_iterator 170 itEnd = docdata->Tags().end(); 171 for ( ary::doc::OldCppDocu::TagList::const_iterator it = docdata->Tags().begin(); 172 it != itEnd; 173 ++it ) 174 { 175 (*it)->StoreAt( *this ); 176 } 177 178 Finish_DocuBlock(); 179 } 180 181 void 182 Docu_Display::Display_StdTag( const StdTag & i_rData ) 183 { 184 csv_assert( uintt(i_rData.Std_Id()) < uintt(ary::info::C_eAtTag_NrOfClasses) ); 185 186 const ary::info::DocuText::TokenList & 187 rText = i_rData.CText().Tokens(); 188 typedef ary::info::DocuText::TokenList::const_iterator TokenIterator; 189 190 if ( rText.empty() ) 191 return; 192 else if ( rText.size() < 3 ) 193 { 194 bool bIsWhite = true; 195 for ( TokenIterator it = rText.begin(); 196 it != rText.end(); 197 ++it ) 198 { 199 if (bIsWhite) 200 bIsWhite = (*it)->IsWhite(); 201 } 202 if (bIsWhite) 203 return; 204 } 205 206 Write_TagTitle( C_sTagHeadlines[i_rData.Std_Id()] ); 207 Write_TagContents( i_rData.CText() ); 208 } 209 210 void 211 Docu_Display::Display_BaseTag( const BaseTag & ) 212 { 213 } 214 215 void 216 Docu_Display::Display_ExceptionTag( const ExceptionTag & ) 217 { 218 } 219 220 void 221 Docu_Display::Display_ImplementsTag( const ImplementsTag & ) 222 { 223 } 224 225 void 226 Docu_Display::Display_KeywordTag( const KeywordTag & ) 227 { 228 } 229 230 void 231 Docu_Display::Display_ParameterTag( const ParameterTag & i_rData ) 232 { 233 Write_TagTitle( "Parameters" ); 234 235 adcdisp::ExplanationTable 236 aParams( CurOut() >> *new DefListDefinition ); 237 238 for ( const ParameterTag * pParam = &i_rData; 239 pParam != 0; 240 pParam = pParam->GetNext() ) // KORR_FUTURE 241 { 242 aParams.AddEntry( pParam->ParamName().c_str() ); 243 244 Easy().Enter( aParams.Def() ); 245 Write_Text( pParam->CText() ); 246 Easy().Leave(); 247 } // end for 248 } 249 250 void 251 Docu_Display::Display_SeeTag( const SeeTag & i_rData ) 252 { 253 Write_TagTitle( "See Also" ); 254 255 DefListDefinition * dpDef = new DefListDefinition; 256 CurOut() << dpDef; 257 Easy().Enter(*dpDef); 258 259 for ( std::vector< ary::QualifiedName >::const_iterator 260 it = i_rData.References().begin(); 261 it != i_rData.References().end(); 262 ++it ) 263 { 264 Write_LinkableText( (*it) ); 265 CurOut() << new html::LineBreak; 266 } 267 268 Easy().Leave(); 269 } 270 271 void 272 Docu_Display::Display_TemplateTag( const TemplateTag & i_rData ) 273 { 274 Write_TagTitle( "Template Parameters" ); 275 276 adcdisp::ExplanationTable 277 aTplParams( CurOut() >> *new DefListDefinition ); 278 279 for ( const TemplateTag * pTplParam = &i_rData; 280 pTplParam != 0; 281 pTplParam = pTplParam->GetNext() ) 282 { 283 aTplParams.AddEntry( pTplParam->TplParamName().c_str() ); 284 285 Easy().Enter( aTplParams.Def() ); 286 Write_Text( pTplParam->CText() ); 287 Easy().Leave(); 288 } // end for 289 } 290 291 void 292 Docu_Display::Display_LabelTag( const LabelTag & ) 293 { 294 } 295 296 void 297 Docu_Display::Display_SinceTag( const ary::info::SinceTag & i_rData ) 298 { 299 if ( i_rData.Version().empty() ) 300 { 301 return; 302 } 303 304 // Transform the value of the @since tag into the text to be displayed. 305 String sDisplay; 306 if ( autodoc::CommandLine::Get_().DoesTransform_SinceTag() ) 307 { 308 sDisplay = autodoc::CommandLine::Get_() 309 .DisplayOf_SinceTagValue( i_rData.Version() ); 310 } 311 else 312 { 313 sDisplay = i_rData.Version(); 314 } 315 316 if (sDisplay.empty()) 317 return; 318 319 Write_TagTitle( "Since " ); 320 321 DefListDefinition * dpDef = new DefListDefinition; 322 CurOut() << dpDef; 323 324 Easy().Enter(*dpDef); 325 CurOut() << sDisplay; 326 Easy().Leave(); 327 } 328 329 void 330 Docu_Display::Display_DT_Text( const DT_Text & i_rData ) 331 { 332 Write_TextToken( i_rData.Text() ); 333 } 334 335 void 336 Docu_Display::Display_DT_MaybeLink( const DT_MaybeLink & i_rData ) 337 { 338 // KORR_FUTURE 339 Write_TextToken( i_rData.Text() ); 340 } 341 342 void 343 Docu_Display::Display_DT_Whitespace( const DT_Whitespace & i_rData ) 344 { 345 static char sSpace[300] = 346 " " 347 " " 348 " " 349 " " 350 " " 351 " "; 352 UINT8 nLength = i_rData.Length(); 353 sSpace[nLength] = NULCH; 354 CurOut() << sSpace; 355 sSpace[nLength] = ' '; 356 } 357 358 void 359 Docu_Display::Display_DT_Eol( const DT_Eol & ) 360 { 361 CurOut() << new html::Sbr; 362 } 363 364 void 365 Docu_Display::Display_DT_Xml( const ary::info::DT_Xml & i_rData ) 366 { 367 CurOut() << new xml::XmlCode( i_rData.Text() ); 368 } 369 370 const ary::cpp::Gate * 371 Docu_Display::inq_Get_ReFinder() const 372 { 373 return &Env().Gate(); 374 } 375 376 void 377 Docu_Display::Start_DocuBlock() 378 { 379 DYN DefList * dpDefList = new DefList; 380 CurOut() << dpDefList; 381 Easy().Enter( *dpDefList ); 382 } 383 384 void 385 Docu_Display::Finish_DocuBlock() 386 { 387 Easy().Leave(); 388 } 389 390 void 391 Docu_Display::Write_TagTitle( const char * i_sText, 392 const char * ) 393 { 394 if ( strcmp(i_sText,"ATTENTION!") == 0 ) 395 { 396 CurOut() 397 >> *new html::DefListTerm 398 << new html::ClassAttr("attention") 399 << i_sText; 400 } 401 else 402 { 403 CurOut() 404 >> *new html::DefListTerm 405 << i_sText; 406 } 407 } 408 409 void 410 Docu_Display::Write_TagContents( const DocuText & i_rDocuText ) 411 { 412 DefListDefinition * dpDef = new DefListDefinition; 413 CurOut() << dpDef; 414 415 Easy().Enter(*dpDef); 416 Write_Text(i_rDocuText); 417 Easy().Leave(); 418 } 419 420 void 421 Docu_Display::Write_Text( const ary::info::DocuText & i_rDocuText ) 422 { 423 if ( i_rDocuText.IsNoHtml() ) 424 { 425 CurOut() 426 << new xml::XmlCode("<pre>"); 427 bUseHtmlInDocuTokens = false; 428 } 429 else 430 { 431 bUseHtmlInDocuTokens = true; 432 } 433 i_rDocuText.StoreAt( *this ); 434 if ( i_rDocuText.IsNoHtml() ) 435 { 436 CurOut() 437 << new xml::XmlCode("</pre>"); 438 } 439 } 440 441 void 442 Docu_Display::Write_TextToken( const String & i_sText ) 443 { 444 if ( bUseHtmlInDocuTokens ) 445 CurOut() << new xml::XmlCode(i_sText); 446 else 447 CurOut() << i_sText; 448 } 449 450 void 451 Docu_Display::Write_LinkableText( const ary::QualifiedName & i_sQuName ) 452 { 453 const ary::cpp::CodeEntity * 454 pCe = FindUnambiguousCe( Env(), i_sQuName, pCurClassOverwrite ); 455 if ( pCe != 0 ) 456 { 457 csi::xml::Element * 458 pLink = new csi::html::Link( Link2Ce(Env(), *pCe) ); 459 CurOut() << pLink; 460 Easy().Enter(*pLink); 461 Write_QualifiedName(i_sQuName); 462 Easy().Leave(); 463 } 464 else 465 { 466 Write_QualifiedName(i_sQuName); 467 } 468 CurOut() << " "; 469 } 470 471 void 472 Docu_Display::Write_QualifiedName( const ary::QualifiedName & i_sQuName ) 473 { 474 if ( i_sQuName.IsAbsolute() ) 475 CurOut() << "::"; 476 for ( ary::QualifiedName::namespace_iterator it = i_sQuName.first_namespace(); 477 it != i_sQuName.end_namespace(); 478 ++it ) 479 { 480 CurOut() << (*it) << "::"; 481 } 482 CurOut() << i_sQuName.LocalName(); 483 if ( i_sQuName.IsFunction() ) 484 CurOut() << "()"; 485 } 486 487