xref: /AOO41X/main/autodoc/source/display/html/opageenv.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
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 "opageenv.hxx"
30 
31 
32 // NOT FULLY DEFINED SERVICES
33 #include <cosv/ploc_dir.hxx>
34 #include <ary/cpp/c_ce.hxx>
35 #include <ary/cpp/c_class.hxx>
36 #include <ary/cpp/c_enum.hxx>
37 #include <ary/cpp/c_gate.hxx>
38 #include <ary/cpp/c_namesp.hxx>
39 #include <ary/cpp/c_tydef.hxx>
40 #include <ary/cpp/cp_ce.hxx>
41 #include <ary/loc/loc_file.hxx>
42 #include <udm/html/htmlitem.hxx>
43 #include <estack.hxx>
44 #include "hdimpl.hxx"
45 #include "strconst.hxx"
46 
47 
48 const String  C_sCppDir( "names" );
49 const String  C_sIndexDir( "ix" );
50 
51 
52 //************************         Implementation          ********************//
53 
54 namespace
55 {
56 
57 void    CreateDirectory( const csv::ploc::Path &    i_rPath );
58 
59 void
60 CreateDirectory( const csv::ploc::Path & i_rPath )
61 {
62     csv::ploc::Directory aDirectory(i_rPath);
63 	if (NOT aDirectory.Exists())
64         aDirectory.PhysicalCreate();
65 }
66 
67 //************************         CheshireCat          ********************//
68 
69 struct InNamespaceTree
70 {
71     enum E_Type
72     {
73         t_unknown,
74         t_namespace,
75         t_type,
76         t_operations,
77         t_data
78     };
79 
80     EStack< const ary::cpp::Namespace * >
81                         aNamespaces; /// never empty.
82     EStack< const ary::cpp::Class * >
83                         aClasses;      /// maybe empty.
84     const ary::cpp::CodeEntity *
85                         pCe;        /// CurFileCe, maybe 0
86     E_Type              eType;
87 
88                         InNamespaceTree(
89                             const ary::cpp::Namespace &
90                                                 i_rNsp );
91                         ~InNamespaceTree();
92     void                GoDown(
93                             const ary::cpp::Namespace &
94                                                 i_rNsp );
95     void                GoDown(
96                             const ary::cpp::Class &
97                                                 i_rClass );
98     void                GoUp();
99 };
100 
101 InNamespaceTree::InNamespaceTree( const ary::cpp::Namespace & i_rNsp )
102     :   // aNamespaces,
103         // aClasses,
104         pCe(0),
105         eType(t_unknown)
106 {
107     aNamespaces.push( &i_rNsp );
108 }
109 
110 InNamespaceTree::~InNamespaceTree()
111 {
112 }
113 
114 void
115 InNamespaceTree::GoDown( const ary::cpp::Namespace & i_rNsp )
116 {
117     aNamespaces.push(&i_rNsp);
118     aClasses.erase_all();
119     pCe = 0;
120     eType = t_unknown;
121 }
122 
123 void
124 InNamespaceTree::GoDown( const ary::cpp::Class & i_rClass )
125 {
126     aClasses.push(&i_rClass);
127     pCe = 0;
128     eType = t_unknown;
129 }
130 
131 void
132 InNamespaceTree::GoUp()
133 {
134     if ( NOT aClasses.empty() )
135         aClasses.pop();
136     else
137         aNamespaces.pop();
138     pCe = 0;
139     eType = t_unknown;
140 }
141 
142 struct InIndex
143 {
144     char                cLetter;
145 
146                         InIndex() : cLetter('A') {}
147 };
148 
149 
150 }   // anonymous namespace
151 
152 
153 
154 
155 
156 struct OuputPage_Environment::CheshireCat
157 {
158     csv::ploc::Path     aOutputRoot;
159     csv::ploc::Path     aMyPath;
160     csv::StreamStr      aFileName;
161 
162     const ary::cpp::Gate *
163                         pGate;
164     const display::CorporateFrame *
165                         pLayout;
166     intt                nDepth;
167 
168     Dyn<InNamespaceTree>
169                         pInNamespace;
170     Dyn<InIndex>        pInIndex;
171 
172                         CheshireCat(
173                             const csv::ploc::Path &
174                                                 io_rOutputDir,
175                             const ary::cpp::Gate &
176                                                 i_rGate,
177                             const display::CorporateFrame &
178                                                 i_rLayout );
179                         ~CheshireCat();
180     void                AddQualifiedName2Path(
181                             const ary::cpp::CodeEntity &
182                                                 i_rCe,
183                             bool                i_bIncludeLocalName );
184 
185     const Dyn<InNamespaceTree> &
186                         NspEnv() const          { return pInNamespace; }
187     Dyn<InNamespaceTree> &
188                         NspEnv()                { return pInNamespace; }
189     const ary::cpp::Namespace *
190                         Namespace() const       { return pInNamespace ? pInNamespace->aNamespaces.top() : 0; }
191     const ary::cpp::Class *
192                         Class() const           { return pInNamespace ? (pInNamespace->aClasses.empty() ? 0 : pInNamespace->aClasses.top()) : 0; }
193 };
194 
195 OuputPage_Environment::
196 CheshireCat::CheshireCat( const csv::ploc::Path &         io_rOutputDir,
197                           const ary::cpp::Gate &   i_rGate,
198                           const display::CorporateFrame & i_rLayout )
199     :   aOutputRoot(io_rOutputDir),
200         aMyPath(io_rOutputDir),
201         aFileName(500),
202         pGate(&i_rGate),
203         pLayout(&i_rLayout),
204         nDepth(0),
205         pInNamespace(),
206         pInIndex()
207 {
208 }
209 
210 OuputPage_Environment::
211 CheshireCat::~CheshireCat()
212 {
213 }
214 
215 void
216 OuputPage_Environment::
217 CheshireCat::AddQualifiedName2Path( const ary::cpp::CodeEntity & i_rCe,
218                                     bool                    i_bIncludeLocalName )
219 {
220     if (NOT i_rCe.Owner().IsValid())
221     {
222         aMyPath.DirChain().PushBack( C_sCppDir );
223         return;
224     }
225 
226     const ary::cpp::CodeEntity &
227         rParent = pGate->Ces().Find_Ce( i_rCe.Owner() );
228     AddQualifiedName2Path( rParent, true );
229 
230     if ( i_bIncludeLocalName )
231         aMyPath.DirChain().PushBack( i_rCe.LocalName() );
232 }
233 
234 
235 
236 //************************         OuputPage_Environment          ********************//
237 
238 OuputPage_Environment::OuputPage_Environment( const csv::ploc::Path &           io_rOutputDir,
239                                               const ary::cpp::Gate &            i_rGate,
240                                               const display::CorporateFrame &   i_rLayout )
241     :   pi( new CheshireCat(io_rOutputDir, i_rGate, i_rLayout) )
242 {
243 }
244 
245 OuputPage_Environment::~OuputPage_Environment()
246 {
247 }
248 
249 void
250 OuputPage_Environment::MoveDir_2Root()
251 {
252     pi->NspEnv() = 0;
253     pi->pInIndex = 0;
254     pi->nDepth = 0;
255     while ( pi->aMyPath.DirChain().Size() > pi->aOutputRoot.DirChain().Size() )
256         pi->aMyPath.DirChain().PopBack();
257     pi->aMyPath.SetFile(String ::Null_());
258 }
259 
260 void
261 OuputPage_Environment::MoveDir_2Names()
262 {
263     pi->NspEnv() = new InNamespaceTree( Gate().Ces().GlobalNamespace() );
264     pi->aMyPath.DirChain().PushBack( C_sCppDir );
265     pi->aMyPath.SetFile(String ::Null_());
266     ++pi->nDepth;
267 
268    	CreateDirectory( pi->aMyPath );
269 }
270 
271 void
272 OuputPage_Environment::MoveDir_Down2( const ary::cpp::Namespace & i_rNsp )
273 {
274     csv_assert(i_rNsp.Depth() > 0);
275     csv_assert( pi->NspEnv() );
276     csv_assert( pi->Namespace()->CeId() == i_rNsp.Owner() );
277 
278     pi->NspEnv()->GoDown( i_rNsp );
279     pi->aMyPath.DirChain().PushBack(i_rNsp.LocalName());
280     ++pi->nDepth;
281     pi->aMyPath.SetFile(String ::Null_());
282 
283    	CreateDirectory( pi->aMyPath );
284 }
285 
286 void
287 OuputPage_Environment::MoveDir_Down2( const ary::cpp::Class & i_rClass )
288 {
289     csv_assert( pi->NspEnv() );
290     if ( i_rClass.Protection() == ary::cpp::PROTECT_global )
291     {
292         csv_assert( pi->Namespace()->CeId() == i_rClass.Owner() );
293     }
294     else
295     {
296         csv_assert( pi->Class() != 0 );
297         csv_assert( pi->Class()->CeId() == i_rClass.Owner() );
298     }
299 
300     pi->NspEnv()->GoDown(i_rClass);
301     pi->aMyPath.DirChain().PushBack(i_rClass.LocalName());
302     pi->aMyPath.SetFile(String ::Null_());
303     ++pi->nDepth;
304 
305    	CreateDirectory( pi->aMyPath );
306 }
307 
308 void
309 OuputPage_Environment::MoveDir_2Index()
310 {
311     MoveDir_2Root();
312     pi->pInIndex = new InIndex;
313     pi->aMyPath.DirChain().PushBack( String (C_sDIR_Index) );
314     pi->aMyPath.SetFile(String ::Null_());
315     pi->nDepth = 1;
316 
317    	CreateDirectory( pi->aMyPath );
318 }
319 
320 void
321 OuputPage_Environment::MoveDir_Up()
322 {
323  	if ( pi->nDepth == 1 )
324     {
325      	MoveDir_2Root();
326         return;
327     }
328     else if ( pi->NspEnv() )
329     {
330         pi->NspEnv()->GoUp();
331         pi->aMyPath.DirChain().PopBack();
332         pi->aMyPath.SetFile(String ::Null_());
333         --pi->nDepth;
334     }
335 }
336 
337 void
338 OuputPage_Environment::SetFile_Css()
339 {
340     pi->aMyPath.SetFile( C_sHFN_Css );
341 }
342 
343 void
344 OuputPage_Environment::SetFile_Overview()
345 {
346     pi->aMyPath.SetFile( C_sHFN_Overview );
347 }
348 
349 void
350 OuputPage_Environment::SetFile_AllDefs()
351 {
352     // Provisorium
353     pi->aMyPath.SetFile("def-all.html");
354 }
355 
356 void
357 OuputPage_Environment::SetFile_Index( char i_cLetter )
358 {
359     csv_assert( 'A' <= i_cLetter AND i_cLetter <= 'Z' OR i_cLetter == '_' );
360 
361     static StreamStr sIndexFileName(40);
362     sIndexFileName.seekp(0);
363     sIndexFileName << "index-";
364     if ( i_cLetter == '_' )
365     {
366         sIndexFileName << "27";
367     }
368     else
369     {
370         sIndexFileName << int(i_cLetter -'A' + 1);
371     }
372     sIndexFileName << ".html";
373 
374     pi->aMyPath.SetFile( sIndexFileName.c_str() );
375 }
376 
377 void
378 OuputPage_Environment::SetFile_Help()
379 {
380     pi->aMyPath.SetFile( C_sHFN_Help );
381 }
382 
383 void
384 OuputPage_Environment::SetFile_CurNamespace()
385 {
386     csv_assert( pi->NspEnv() );
387     pi->aMyPath.SetFile("index.html");
388     pi->NspEnv()->pCe = pi->Namespace();
389     pi->NspEnv()->eType = InNamespaceTree::t_namespace;
390 }
391 
392 void
393 OuputPage_Environment::SetFile_Class( const ary::cpp::Class & i_rClass )
394 {
395     csv_assert( pi->NspEnv() );
396     pi->aMyPath.SetFile( ClassFileName(i_rClass.LocalName()) );
397     pi->NspEnv()->pCe = &i_rClass;
398     pi->NspEnv()->eType = InNamespaceTree::t_type;
399 }
400 
401 void
402 OuputPage_Environment::SetFile_Enum( const ary::cpp::Enum & i_rEnum )
403 {
404     csv_assert( pi->NspEnv() );
405     pi->aMyPath.SetFile( EnumFileName(i_rEnum.LocalName()) );
406     pi->NspEnv()->pCe = &i_rEnum;
407     pi->NspEnv()->eType = InNamespaceTree::t_type;
408 }
409 
410 void
411 OuputPage_Environment::SetFile_Typedef( const ary::cpp::Typedef & i_rTypedef )
412 {
413     csv_assert( pi->NspEnv() );
414     pi->aMyPath.SetFile( TypedefFileName(i_rTypedef.LocalName()) );
415     pi->NspEnv()->pCe = &i_rTypedef;
416     pi->NspEnv()->eType = InNamespaceTree::t_type;
417 }
418 
419 void
420 OuputPage_Environment::SetFile_Operations( const ary::loc::File * i_pFile )
421 {
422     csv_assert( pi->NspEnv() );
423     if ( CurClass() != 0 )
424         pi->aMyPath.SetFile( "o.html" );
425 	else
426     {
427         csv_assert( i_pFile != 0 );
428         pi->aMyPath.SetFile( HtmlFileName("o-", i_pFile->LocalName()) );
429     }
430     pi->NspEnv()->pCe = 0;
431     pi->NspEnv()->eType = InNamespaceTree::t_operations;
432 }
433 
434 void
435 OuputPage_Environment::SetFile_Data( const ary::loc::File * i_pFile )
436 {
437     csv_assert( pi->NspEnv() );
438     if ( CurClass() != 0 )
439         pi->aMyPath.SetFile( "d.html" );
440     else
441     {
442         csv_assert( i_pFile != 0 );
443         pi->aMyPath.SetFile( HtmlFileName("d-", i_pFile->LocalName()) );
444     }
445     pi->NspEnv()->pCe = 0;
446     pi->NspEnv()->eType = InNamespaceTree::t_data;
447 }
448 
449 const ary::cpp::Namespace *
450 OuputPage_Environment::CurNamespace() const
451 {
452     return pi->Namespace();
453 }
454 
455 const ary::cpp::Class *
456 OuputPage_Environment::CurClass() const
457 {
458     return pi->Class();
459 }
460 
461 const csv::ploc::Path &
462 OuputPage_Environment::CurPath() const
463 {
464     return pi->aMyPath;
465 }
466 
467 const ary::cpp::Gate &
468 OuputPage_Environment::Gate() const
469 {
470     return *pi->pGate;
471 }
472 
473 const display::CorporateFrame &
474 OuputPage_Environment::Layout() const
475 {
476     return *pi->pLayout;
477 }
478 
479 uintt
480 OuputPage_Environment::Depth() const
481 {
482     return static_cast<uintt>(pi->nDepth);
483 }
484 
485 const String &
486 OuputPage_Environment::RepositoryTitle() const
487 {
488     return Gate().RepositoryTitle();
489 }
490