1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: opageenv.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 #include "opageenv.hxx"
35 // NOT FULLY DEFINED SERVICES
36 #include <cosv/ploc_dir.hxx>
37 #include <ary/cpp/c_ce.hxx>
38 #include <ary/cpp/c_class.hxx>
39 #include <ary/cpp/c_enum.hxx>
40 #include <ary/cpp/c_gate.hxx>
41 #include <ary/cpp/c_namesp.hxx>
42 #include <ary/cpp/c_tydef.hxx>
43 #include <ary/cpp/cp_ce.hxx>
44 #include <ary/loc/loc_file.hxx>
45 #include <udm/html/htmlitem.hxx>
48 #include "strconst.hxx"
51 const String
C_sCppDir( "names" );
52 const String
C_sIndexDir( "ix" );
55 //************************ Implementation ********************//
60 void CreateDirectory( const csv::ploc::Path
& i_rPath
);
63 CreateDirectory( const csv::ploc::Path
& i_rPath
)
65 csv::ploc::Directory
aDirectory(i_rPath
);
66 if (NOT aDirectory
.Exists())
67 aDirectory
.PhysicalCreate();
70 //************************ CheshireCat ********************//
72 struct InNamespaceTree
83 EStack
< const ary::cpp::Namespace
* >
84 aNamespaces
; /// never empty.
85 EStack
< const ary::cpp::Class
* >
86 aClasses
; /// maybe empty.
87 const ary::cpp::CodeEntity
*
88 pCe
; /// CurFileCe, maybe 0
92 const ary::cpp::Namespace
&
96 const ary::cpp::Namespace
&
99 const ary::cpp::Class
&
104 InNamespaceTree::InNamespaceTree( const ary::cpp::Namespace
& i_rNsp
)
110 aNamespaces
.push( &i_rNsp
);
113 InNamespaceTree::~InNamespaceTree()
118 InNamespaceTree::GoDown( const ary::cpp::Namespace
& i_rNsp
)
120 aNamespaces
.push(&i_rNsp
);
121 aClasses
.erase_all();
127 InNamespaceTree::GoDown( const ary::cpp::Class
& i_rClass
)
129 aClasses
.push(&i_rClass
);
135 InNamespaceTree::GoUp()
137 if ( NOT aClasses
.empty() )
149 InIndex() : cLetter('A') {}
153 } // anonymous namespace
159 struct OuputPage_Environment::CheshireCat
161 csv::ploc::Path aOutputRoot
;
162 csv::ploc::Path aMyPath
;
163 csv::StreamStr aFileName
;
165 const ary::cpp::Gate
*
167 const display::CorporateFrame
*
173 Dyn
<InIndex
> pInIndex
;
176 const csv::ploc::Path
&
178 const ary::cpp::Gate
&
180 const display::CorporateFrame
&
183 void AddQualifiedName2Path(
184 const ary::cpp::CodeEntity
&
186 bool i_bIncludeLocalName
);
188 const Dyn
<InNamespaceTree
> &
189 NspEnv() const { return pInNamespace
; }
190 Dyn
<InNamespaceTree
> &
191 NspEnv() { return pInNamespace
; }
192 const ary::cpp::Namespace
*
193 Namespace() const { return pInNamespace
? pInNamespace
->aNamespaces
.top() : 0; }
194 const ary::cpp::Class
*
195 Class() const { return pInNamespace
? (pInNamespace
->aClasses
.empty() ? 0 : pInNamespace
->aClasses
.top()) : 0; }
198 OuputPage_Environment::
199 CheshireCat::CheshireCat( const csv::ploc::Path
& io_rOutputDir
,
200 const ary::cpp::Gate
& i_rGate
,
201 const display::CorporateFrame
& i_rLayout
)
202 : aOutputRoot(io_rOutputDir
),
203 aMyPath(io_rOutputDir
),
213 OuputPage_Environment::
214 CheshireCat::~CheshireCat()
219 OuputPage_Environment::
220 CheshireCat::AddQualifiedName2Path( const ary::cpp::CodeEntity
& i_rCe
,
221 bool i_bIncludeLocalName
)
223 if (NOT i_rCe
.Owner().IsValid())
225 aMyPath
.DirChain().PushBack( C_sCppDir
);
229 const ary::cpp::CodeEntity
&
230 rParent
= pGate
->Ces().Find_Ce( i_rCe
.Owner() );
231 AddQualifiedName2Path( rParent
, true );
233 if ( i_bIncludeLocalName
)
234 aMyPath
.DirChain().PushBack( i_rCe
.LocalName() );
239 //************************ OuputPage_Environment ********************//
241 OuputPage_Environment::OuputPage_Environment( const csv::ploc::Path
& io_rOutputDir
,
242 const ary::cpp::Gate
& i_rGate
,
243 const display::CorporateFrame
& i_rLayout
)
244 : pi( new CheshireCat(io_rOutputDir
, i_rGate
, i_rLayout
) )
248 OuputPage_Environment::~OuputPage_Environment()
253 OuputPage_Environment::MoveDir_2Root()
258 while ( pi
->aMyPath
.DirChain().Size() > pi
->aOutputRoot
.DirChain().Size() )
259 pi
->aMyPath
.DirChain().PopBack();
260 pi
->aMyPath
.SetFile(String ::Null_());
264 OuputPage_Environment::MoveDir_2Names()
266 pi
->NspEnv() = new InNamespaceTree( Gate().Ces().GlobalNamespace() );
267 pi
->aMyPath
.DirChain().PushBack( C_sCppDir
);
268 pi
->aMyPath
.SetFile(String ::Null_());
271 CreateDirectory( pi
->aMyPath
);
275 OuputPage_Environment::MoveDir_Down2( const ary::cpp::Namespace
& i_rNsp
)
277 csv_assert(i_rNsp
.Depth() > 0);
278 csv_assert( pi
->NspEnv() );
279 csv_assert( pi
->Namespace()->CeId() == i_rNsp
.Owner() );
281 pi
->NspEnv()->GoDown( i_rNsp
);
282 pi
->aMyPath
.DirChain().PushBack(i_rNsp
.LocalName());
284 pi
->aMyPath
.SetFile(String ::Null_());
286 CreateDirectory( pi
->aMyPath
);
290 OuputPage_Environment::MoveDir_Down2( const ary::cpp::Class
& i_rClass
)
292 csv_assert( pi
->NspEnv() );
293 if ( i_rClass
.Protection() == ary::cpp::PROTECT_global
)
295 csv_assert( pi
->Namespace()->CeId() == i_rClass
.Owner() );
299 csv_assert( pi
->Class() != 0 );
300 csv_assert( pi
->Class()->CeId() == i_rClass
.Owner() );
303 pi
->NspEnv()->GoDown(i_rClass
);
304 pi
->aMyPath
.DirChain().PushBack(i_rClass
.LocalName());
305 pi
->aMyPath
.SetFile(String ::Null_());
308 CreateDirectory( pi
->aMyPath
);
312 OuputPage_Environment::MoveDir_2Index()
315 pi
->pInIndex
= new InIndex
;
316 pi
->aMyPath
.DirChain().PushBack( String (C_sDIR_Index
) );
317 pi
->aMyPath
.SetFile(String ::Null_());
320 CreateDirectory( pi
->aMyPath
);
324 OuputPage_Environment::MoveDir_Up()
326 if ( pi
->nDepth
== 1 )
331 else if ( pi
->NspEnv() )
333 pi
->NspEnv()->GoUp();
334 pi
->aMyPath
.DirChain().PopBack();
335 pi
->aMyPath
.SetFile(String ::Null_());
341 OuputPage_Environment::SetFile_Css()
343 pi
->aMyPath
.SetFile( C_sHFN_Css
);
347 OuputPage_Environment::SetFile_Overview()
349 pi
->aMyPath
.SetFile( C_sHFN_Overview
);
353 OuputPage_Environment::SetFile_AllDefs()
356 pi
->aMyPath
.SetFile("def-all.html");
360 OuputPage_Environment::SetFile_Index( char i_cLetter
)
362 csv_assert( 'A' <= i_cLetter AND i_cLetter
<= 'Z' OR i_cLetter
== '_' );
364 static StreamStr
sIndexFileName(40);
365 sIndexFileName
.seekp(0);
366 sIndexFileName
<< "index-";
367 if ( i_cLetter
== '_' )
369 sIndexFileName
<< "27";
373 sIndexFileName
<< int(i_cLetter
-'A' + 1);
375 sIndexFileName
<< ".html";
377 pi
->aMyPath
.SetFile( sIndexFileName
.c_str() );
381 OuputPage_Environment::SetFile_Help()
383 pi
->aMyPath
.SetFile( C_sHFN_Help
);
387 OuputPage_Environment::SetFile_CurNamespace()
389 csv_assert( pi
->NspEnv() );
390 pi
->aMyPath
.SetFile("index.html");
391 pi
->NspEnv()->pCe
= pi
->Namespace();
392 pi
->NspEnv()->eType
= InNamespaceTree::t_namespace
;
396 OuputPage_Environment::SetFile_Class( const ary::cpp::Class
& i_rClass
)
398 csv_assert( pi
->NspEnv() );
399 pi
->aMyPath
.SetFile( ClassFileName(i_rClass
.LocalName()) );
400 pi
->NspEnv()->pCe
= &i_rClass
;
401 pi
->NspEnv()->eType
= InNamespaceTree::t_type
;
405 OuputPage_Environment::SetFile_Enum( const ary::cpp::Enum
& i_rEnum
)
407 csv_assert( pi
->NspEnv() );
408 pi
->aMyPath
.SetFile( EnumFileName(i_rEnum
.LocalName()) );
409 pi
->NspEnv()->pCe
= &i_rEnum
;
410 pi
->NspEnv()->eType
= InNamespaceTree::t_type
;
414 OuputPage_Environment::SetFile_Typedef( const ary::cpp::Typedef
& i_rTypedef
)
416 csv_assert( pi
->NspEnv() );
417 pi
->aMyPath
.SetFile( TypedefFileName(i_rTypedef
.LocalName()) );
418 pi
->NspEnv()->pCe
= &i_rTypedef
;
419 pi
->NspEnv()->eType
= InNamespaceTree::t_type
;
423 OuputPage_Environment::SetFile_Operations( const ary::loc::File
* i_pFile
)
425 csv_assert( pi
->NspEnv() );
426 if ( CurClass() != 0 )
427 pi
->aMyPath
.SetFile( "o.html" );
430 csv_assert( i_pFile
!= 0 );
431 pi
->aMyPath
.SetFile( HtmlFileName("o-", i_pFile
->LocalName()) );
433 pi
->NspEnv()->pCe
= 0;
434 pi
->NspEnv()->eType
= InNamespaceTree::t_operations
;
438 OuputPage_Environment::SetFile_Data( const ary::loc::File
* i_pFile
)
440 csv_assert( pi
->NspEnv() );
441 if ( CurClass() != 0 )
442 pi
->aMyPath
.SetFile( "d.html" );
445 csv_assert( i_pFile
!= 0 );
446 pi
->aMyPath
.SetFile( HtmlFileName("d-", i_pFile
->LocalName()) );
448 pi
->NspEnv()->pCe
= 0;
449 pi
->NspEnv()->eType
= InNamespaceTree::t_data
;
452 const ary::cpp::Namespace
*
453 OuputPage_Environment::CurNamespace() const
455 return pi
->Namespace();
458 const ary::cpp::Class
*
459 OuputPage_Environment::CurClass() const
464 const csv::ploc::Path
&
465 OuputPage_Environment::CurPath() const
470 const ary::cpp::Gate
&
471 OuputPage_Environment::Gate() const
476 const display::CorporateFrame
&
477 OuputPage_Environment::Layout() const
483 OuputPage_Environment::Depth() const
485 return static_cast<uintt
>(pi
->nDepth
);
489 OuputPage_Environment::RepositoryTitle() const
491 return Gate().RepositoryTitle();