1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22 #include <precomp.h>
23 #include <idl/hi_display.hxx>
24
25
26 // NOT FULLY DEFINED SERVICES
27 #include <cosv/file.hxx>
28 #include <ary/idl/i_ce.hxx>
29 #include <ary/idl/i_module.hxx>
30 #include <ary/getncast.hxx>
31 #include <toolkit/out_tree.hxx>
32 #include <cfrstd.hxx>
33 #include "hi_ary.hxx"
34 #include "hi_env.hxx"
35 #include "hi_main.hxx"
36
37
38 extern const String C_sCssFilename_Idl;
39
40
41 inline bool
IsModule(const ary::idl::CodeEntity & i_ce) const42 HtmlDisplay_Idl::IsModule( const ary::idl::CodeEntity & i_ce ) const
43 {
44 return ary::is_type<ary::idl::Module>(i_ce);
45 }
46
47 inline const ary::idl::Module &
Module_Cast(const ary::idl::CodeEntity & i_ce) const48 HtmlDisplay_Idl::Module_Cast( const ary::idl::CodeEntity & i_ce ) const
49 {
50 return ary::ary_cast<ary::idl::Module>(i_ce);
51 }
52
53
54
55
HtmlDisplay_Idl()56 HtmlDisplay_Idl::HtmlDisplay_Idl()
57 : pCurPageEnv(),
58 pMainDisplay()
59 {
60 }
61
~HtmlDisplay_Idl()62 HtmlDisplay_Idl::~HtmlDisplay_Idl()
63 {
64 }
65
66 void
do_Run(const char * i_sOutputDirectory,const ary::idl::Gate & i_rAryGate,const display::CorporateFrame & i_rLayout)67 HtmlDisplay_Idl::do_Run( const char * i_sOutputDirectory,
68 const ary::idl::Gate & i_rAryGate,
69 const display::CorporateFrame & i_rLayout )
70 {
71 SetRunData( i_sOutputDirectory, i_rAryGate, i_rLayout );
72
73 Create_StartFile();
74 Create_CssFile();
75 Create_FilesInNameTree();
76 Create_IndexFiles();
77 Create_FilesInProjectTree();
78 Create_PackageList();
79 Create_HelpFile();
80 }
81
82 void
SetRunData(const char * i_sOutputDirectory,const ary::idl::Gate & i_rAryGate,const display::CorporateFrame & i_rLayout)83 HtmlDisplay_Idl::SetRunData( const char * i_sOutputDirectory,
84 const ary::idl::Gate & i_rAryGate,
85 const display::CorporateFrame & i_rLayout )
86 {
87 csv::ploc::Path aOutputDir( i_sOutputDirectory, true );
88 pCurPageEnv = new HtmlEnvironment_Idl( aOutputDir, i_rAryGate, i_rLayout );
89 pMainDisplay = new MainDisplay_Idl(*pCurPageEnv);
90 }
91
92 void
Create_StartFile()93 HtmlDisplay_Idl::Create_StartFile()
94 {
95 }
96
97 void
Create_FilesInNameTree()98 HtmlDisplay_Idl::Create_FilesInNameTree()
99 {
100 Cout() << "\nCreate files in subtree namespaces ..." << Endl();
101
102 const ary::idl::Module &
103 rGlobalNamespace = pCurPageEnv->Data().GlobalNamespace();
104 pCurPageEnv->Goto_Directory( pCurPageEnv->OutputTree().NamesRoot(), true );
105
106 RecursiveDisplay_Module(rGlobalNamespace);
107
108 Cout() << "... done." << Endl();
109 }
110
111 void
Create_IndexFiles()112 HtmlDisplay_Idl::Create_IndexFiles()
113 {
114 Cout() << "\nCreate files in subtree index ..." << Endl();
115 pCurPageEnv->Goto_Directory( pCurPageEnv->OutputTree().IndexRoot(), true );
116 pMainDisplay->WriteGlobalIndices();
117 Cout() << "... done.\n" << Endl();
118 }
119
120 typedef ary::Dyn_StdConstIterator<ary::idl::Ce_id> Dyn_CeIterator;
121 typedef ary::StdConstIterator<ary::idl::Ce_id> CeIterator;
122
123 void
RecursiveDisplay_Module(const ary::idl::Module & i_module)124 HtmlDisplay_Idl::RecursiveDisplay_Module( const ary::idl::Module & i_module )
125 {
126 i_module.Accept(*pMainDisplay);
127
128 Dyn_CeIterator
129 aMembers;
130 i_module.Get_Names(aMembers);
131
132 for ( CeIterator & iter = *aMembers;
133 iter;
134 ++iter )
135 {
136 const ary::idl::CodeEntity &
137 rCe = pCurPageEnv->Data().Find_Ce(*iter);
138
139 if ( NOT IsModule(rCe) )
140 rCe.Accept(*pMainDisplay);
141 else
142 {
143 pCurPageEnv->Goto_DirectoryLevelDown( rCe.LocalName(), true );
144 RecursiveDisplay_Module( Module_Cast(rCe) );
145 pCurPageEnv->Goto_DirectoryLevelUp();
146 }
147 } // end for
148 }
149
150 void
Create_FilesInProjectTree()151 HtmlDisplay_Idl::Create_FilesInProjectTree()
152 {
153 }
154
155 void
Create_PackageList()156 HtmlDisplay_Idl::Create_PackageList()
157 {
158 #if 0
159 Cout() << "\nCreate package list ..." << std::flush;
160
161 pCurPageEnv->CurPosition() = pCurPageEnv->OutputTree().Root();
162
163 // KORR
164 // ...
165
166 Cout() << " done." << Endl();
167 #endif // 0
168 }
169
170 void
Create_HelpFile()171 HtmlDisplay_Idl::Create_HelpFile()
172 {
173 }
174
175 void
Create_CssFile()176 HtmlDisplay_Idl::Create_CssFile()
177 {
178 Cout() << "\nCreate css file ..." << Endl();
179
180 pCurPageEnv->Goto_Directory( pCurPageEnv->OutputTree().Root(), true );
181 pCurPageEnv->Set_CurFile( C_sCssFilename_Idl );
182
183 StreamLock
184 slCurFilePath(700);
185 pCurPageEnv->Get_CurFilePath(slCurFilePath());
186
187 csv::File
188 aCssFile(slCurFilePath().c_str(), csv::CFM_CREATE);
189 csv::OpenCloseGuard
190 aOpenGuard(aCssFile);
191 if (NOT aOpenGuard)
192 {
193 Cerr() << "Can't create file " << slCurFilePath().c_str() << "." << Endl();
194 return;
195 }
196
197 aCssFile.write("/* Autodoc css file for IDL documentation */\n\n\n");
198 aCssFile.write(pCurPageEnv->Layout().CssStyle());
199 aCssFile.write("\n\n\n");
200 aCssFile.write(pCurPageEnv->Layout().CssStylesExplanation());
201 }
202