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 <idl/hi_display.hxx>
30 
31 
32 // NOT FULLY DEFINED SERVICES
33 #include <cosv/file.hxx>
34 #include <ary/idl/i_ce.hxx>
35 #include <ary/idl/i_module.hxx>
36 #include <ary/getncast.hxx>
37 #include <toolkit/out_tree.hxx>
38 #include <cfrstd.hxx>
39 #include "hi_ary.hxx"
40 #include "hi_env.hxx"
41 #include "hi_main.hxx"
42 
43 
44 extern const String C_sCssFilename_Idl;
45 
46 
47 inline bool
48 HtmlDisplay_Idl::IsModule( const ary::idl::CodeEntity & i_ce ) const
49 {
50  	return ary::is_type<ary::idl::Module>(i_ce);
51 }
52 
53 inline const ary::idl::Module &
54 HtmlDisplay_Idl::Module_Cast( const ary::idl::CodeEntity & i_ce ) const
55 {
56  	return ary::ary_cast<ary::idl::Module>(i_ce);
57 }
58 
59 
60 
61 
62 HtmlDisplay_Idl::HtmlDisplay_Idl()
63     :   pCurPageEnv(),
64         pMainDisplay()
65 {
66 }
67 
68 HtmlDisplay_Idl::~HtmlDisplay_Idl()
69 {
70 }
71 
72 void
73 HtmlDisplay_Idl::do_Run( const char *                       i_sOutputDirectory,
74                          const ary::idl::Gate &             i_rAryGate,
75                          const display::CorporateFrame &    i_rLayout )
76 {
77     SetRunData( i_sOutputDirectory, i_rAryGate, i_rLayout );
78 
79     Create_StartFile();
80     Create_CssFile();
81     Create_FilesInNameTree();
82     Create_IndexFiles();
83     Create_FilesInProjectTree();
84     Create_PackageList();
85     Create_HelpFile();
86 }
87 
88 void
89 HtmlDisplay_Idl::SetRunData( const char *                       i_sOutputDirectory,
90                              const ary::idl::Gate &             i_rAryGate,
91                              const display::CorporateFrame &    i_rLayout  )
92 {
93     csv::ploc::Path aOutputDir( i_sOutputDirectory, true );
94     pCurPageEnv = new HtmlEnvironment_Idl( aOutputDir, i_rAryGate, i_rLayout );
95     pMainDisplay = new MainDisplay_Idl(*pCurPageEnv);
96 }
97 
98 void
99 HtmlDisplay_Idl::Create_StartFile()
100 {
101 }
102 
103 void
104 HtmlDisplay_Idl::Create_FilesInNameTree()
105 {
106     Cout() << "\nCreate files in subtree namespaces ..." << Endl();
107 
108     const ary::idl::Module &
109         rGlobalNamespace = pCurPageEnv->Data().GlobalNamespace();
110     pCurPageEnv->Goto_Directory( pCurPageEnv->OutputTree().NamesRoot(), true );
111 
112     RecursiveDisplay_Module(rGlobalNamespace);
113 
114     Cout() << "... done." << Endl();
115 }
116 
117 void
118 HtmlDisplay_Idl::Create_IndexFiles()
119 {
120     Cout() << "\nCreate files in subtree index ..." << Endl();
121     pCurPageEnv->Goto_Directory( pCurPageEnv->OutputTree().IndexRoot(), true );
122     pMainDisplay->WriteGlobalIndices();
123     Cout() << "... done.\n" << Endl();
124 }
125 
126 typedef ary::Dyn_StdConstIterator<ary::idl::Ce_id>  Dyn_CeIterator;
127 typedef ary::StdConstIterator<ary::idl::Ce_id>      CeIterator;
128 
129 void
130 HtmlDisplay_Idl::RecursiveDisplay_Module( const ary::idl::Module & i_module )
131 {
132     i_module.Accept(*pMainDisplay);
133 
134     Dyn_CeIterator
135         aMembers;
136     i_module.Get_Names(aMembers);
137 
138     for ( CeIterator & iter = *aMembers;
139           iter;
140           ++iter )
141     {
142         const ary::idl::CodeEntity &
143             rCe = pCurPageEnv->Data().Find_Ce(*iter);
144 
145         if ( NOT IsModule(rCe) )
146             rCe.Accept(*pMainDisplay);
147         else
148         {
149             pCurPageEnv->Goto_DirectoryLevelDown( rCe.LocalName(), true );
150             RecursiveDisplay_Module( Module_Cast(rCe) );
151             pCurPageEnv->Goto_DirectoryLevelUp();
152         }
153     }   // end for
154 }
155 
156 void
157 HtmlDisplay_Idl::Create_FilesInProjectTree()
158 {
159 }
160 
161 void
162 HtmlDisplay_Idl::Create_PackageList()
163 {
164 #if 0
165     Cout() << "\nCreate package list ..." << std::flush;
166 
167     pCurPageEnv->CurPosition() = pCurPageEnv->OutputTree().Root();
168 
169     // KORR
170     // ...
171 
172     Cout() << " done." << Endl();
173 #endif // 0
174 }
175 
176 void
177 HtmlDisplay_Idl::Create_HelpFile()
178 {
179 }
180 
181 void
182 HtmlDisplay_Idl::Create_CssFile()
183 {
184     Cout() << "\nCreate css file ..." << Endl();
185 
186     pCurPageEnv->Goto_Directory( pCurPageEnv->OutputTree().Root(), true );
187     pCurPageEnv->Set_CurFile( C_sCssFilename_Idl );
188 
189     StreamLock
190         slCurFilePath(700);
191     pCurPageEnv->Get_CurFilePath(slCurFilePath());
192 
193     csv::File
194         aCssFile(slCurFilePath().c_str(), csv::CFM_CREATE);
195     csv::OpenCloseGuard
196         aOpenGuard(aCssFile);
197     if (NOT aOpenGuard)
198     {
199         Cerr() << "Can't create file " << slCurFilePath().c_str() << "." << Endl();
200         return;
201     }
202 
203     aCssFile.write("/*      Autodoc css file for IDL documentation      */\n\n\n");
204     aCssFile.write(pCurPageEnv->Layout().CssStyle());
205     aCssFile.write("\n\n\n");
206     aCssFile.write(pCurPageEnv->Layout().CssStylesExplanation());
207 }
208