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