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
23
24 #include <fstream>
25 #include "cr_html.hxx"
26 #include "xmltree.hxx"
27 #include "../support/syshelp.hxx"
28
29
30
31
32 char C_sHtmlFileHeader1[] =
33 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">\n"
34 "<HTML>\n"
35 "<HEAD>\n"
36 " <TITLE>";
37
38 char C_sHtmlFileHeader2[] =
39 "</TITLE>\n"
40 " <META NAME=\"GENERATOR\" CONTENT=\"xml2cmp\">\n"
41 "</HEAD>\n"
42 "<BODY BGCOLOR=\"#ffffff\">\n<P><BR></P>";
43
44
45 char C_sHtmlFileFoot[] = "</BODY>\n</HTML>\n";
46
47
HtmlCreator(const char * i_pOutputFileName,const XmlElement & i_rDocument,const Simstr & i_sIDL_BaseDirectory)48 HtmlCreator::HtmlCreator( const char * i_pOutputFileName,
49 const XmlElement & i_rDocument,
50 const Simstr & i_sIDL_BaseDirectory )
51 : aFile(i_pOutputFileName, std::ios::out
52 #if defined(WNT) || defined(OS2)
53 | std::ios::binary
54 #endif
55 ),
56 rDocument(i_rDocument),
57 sIdl_BaseDirectory(i_sIDL_BaseDirectory)
58 {
59 if ( !aFile )
60 {
61 std::cerr << "Error: " << i_pOutputFileName << " could not be created." << std::endl;
62 exit(0);
63 }
64 }
65
~HtmlCreator()66 HtmlCreator::~HtmlCreator()
67 {
68 aFile.close();
69 }
70
71 void
Run()72 HtmlCreator::Run()
73 {
74 WriteStr( C_sHtmlFileHeader1 );
75 WriteStr( "ModuleDescription" );
76 WriteStr( C_sHtmlFileHeader2 );
77
78 rDocument.Write2Html(*this);
79
80 WriteStr( "<P><BR><BR></P>\n" );
81 WriteStr( C_sHtmlFileFoot );
82 }
83
84 void
StartTable()85 HtmlCreator::StartTable()
86 {
87 WriteStr( "<P><BR></P>\n" );
88 WriteStr(
89 "<TABLE WIDTH=95% BORDER=1 CELLSPACING=0 CELLPADDING=4>\n"
90 " <TBODY>\n" );
91 }
92
93 void
FinishTable()94 HtmlCreator::FinishTable()
95 {
96 WriteStr( " </TBODY>\n"
97 "</TABLE>\n\n" );
98 }
99
100 void
StartBigCell(const char * i_sTitle)101 HtmlCreator::StartBigCell( const char * i_sTitle )
102 {
103 WriteStr( "<TR><TD COLSPAN=2>\n"
104 "<H4><BR>" );
105 WriteStr( i_sTitle );
106 WriteStr( "</H4>\n" );
107
108 }
109
110 void
FinishBigCell()111 HtmlCreator::FinishBigCell()
112 {
113 WriteStr( "</TD><TR>\n" );
114 }
115
116 void
Write_SglTextElement(const SglTextElement & i_rElement,bool i_bStrong)117 HtmlCreator::Write_SglTextElement( const SglTextElement & i_rElement,
118 bool i_bStrong )
119 {
120 StartRow();
121
122 WriteElementName( i_rElement.Name(), i_bStrong );
123
124 StartCell( "77%");
125 if (i_bStrong)
126 {
127 WriteStr( "<H4><A NAME=\"" );
128 unsigned nLen = strlen(i_rElement.Data());
129 if ( i_rElement.IsReversedName())
130 {
131 const char * pEnd = strchr(i_rElement.Data(), ' ');
132 nLen = (unsigned)( pEnd - i_rElement.Data() );
133 }
134 aFile.write( i_rElement.Data(), (int) nLen );
135 WriteStr( "\">" );
136 }
137
138 WriteName( aFile, sIdl_BaseDirectory, i_rElement.Data(),
139 i_bStrong ? lt_nolink : i_rElement.LinkType() );
140
141 if (i_bStrong)
142 WriteStr( "</A></H4>" );
143 FinishCell();
144
145 FinishRow();
146 }
147
148 void
Write_MultiTextElement(const MultipleTextElement & i_rElement)149 HtmlCreator::Write_MultiTextElement( const MultipleTextElement & i_rElement )
150 {
151 StartRow();
152
153 WriteElementName( i_rElement.Name(), false );
154
155 StartCell( "77%");
156 unsigned i_max = i_rElement.Size();
157 for ( unsigned i = 0; i < i_max; ++i )
158 {
159 if (i > 0)
160 WriteStr( "<BR>\n" );
161 WriteName( aFile, sIdl_BaseDirectory, i_rElement.Data(i), i_rElement.LinkType() );
162 } // end for
163 FinishCell();
164
165 FinishRow();
166 }
167
168 void
Write_SglText(const Simstr & i_sName,const Simstr & i_sValue)169 HtmlCreator::Write_SglText( const Simstr & i_sName,
170 const Simstr & i_sValue )
171 {
172 StartRow();
173
174 WriteElementName( i_sName, false );
175
176 StartCell( "77%");
177 WriteStr( i_sValue );
178 FinishCell();
179
180 FinishRow();
181 }
182
183 void
Write_ReferenceDocu(const Simstr & i_sName,const Simstr & i_sRef,const Simstr & i_sRole,const Simstr & i_sTitle)184 HtmlCreator::Write_ReferenceDocu( const Simstr & i_sName,
185 const Simstr & i_sRef,
186 const Simstr & i_sRole,
187 const Simstr & i_sTitle )
188 {
189 StartRow();
190
191 StartCell( "23%" );
192 WriteStr(i_sName);
193 FinishCell();
194
195 StartCell( "77%" );
196 if ( !i_sRef.is_empty() )
197 {
198 WriteStr("<A href=\"");
199 WriteStr(i_sRef);
200 WriteStr("\">");
201 if ( !i_sTitle.is_empty() )
202 WriteStr( i_sTitle );
203 else
204 WriteStr(i_sRef);
205 WriteStr("</A><BR>\n");
206 }
207 else if ( !i_sTitle.is_empty() )
208 {
209 WriteStr("Title: ");
210 WriteStr( i_sTitle );
211 WriteStr("<BR>\n");
212 }
213 if ( !i_sRole.is_empty() )
214 {
215 WriteStr("Role: ");
216 WriteStr( i_sRole );
217 }
218 FinishCell();
219
220 FinishRow();
221 }
222
223
224 void
StartRow()225 HtmlCreator::StartRow()
226 {
227 WriteStr( " <TR VALIGN=TOP>\n" );
228 }
229
230 void
FinishRow()231 HtmlCreator::FinishRow()
232 {
233 WriteStr( " </TR>\n" );
234 }
235
236 void
StartCell(const char * i_pWidth)237 HtmlCreator::StartCell( const char * i_pWidth)
238 {
239 WriteStr( " <TD WIDTH=" );
240 WriteStr( i_pWidth );
241 WriteStr( ">\n <P>" );
242 }
243
244 void
FinishCell()245 HtmlCreator::FinishCell()
246 {
247 WriteStr( "</P>\n </TD>\n" );
248 }
249
250 void
WriteElementName(const Simstr & i_sName,bool i_bStrong)251 HtmlCreator::WriteElementName( const Simstr & i_sName,
252 bool i_bStrong )
253 {
254 StartCell( "23%" );
255 if (i_bStrong)
256 WriteStr( "<H4>" );
257 WriteStr(i_sName);
258 if (i_bStrong)
259 WriteStr( "</H4>" );
260 FinishCell();
261 }
262
263
264
265