merge the formfield patch from ooo-build
[ooovba.git] / xml2cmp / source / xcd / cr_html.cxx
blobbe276daa10cafe56c6af5e68ac194ccfb7314621
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cr_html.cxx,v $
10 * $Revision: 1.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include <fstream>
32 #include "cr_html.hxx"
33 #include "xmltree.hxx"
34 #include "../support/syshelp.hxx"
39 char C_sHtmlFileHeader1[] =
40 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">\n"
41 "<HTML>\n"
42 "<HEAD>\n"
43 " <TITLE>";
45 char C_sHtmlFileHeader2[] =
46 "</TITLE>\n"
47 " <META NAME=\"GENERATOR\" CONTENT=\"xml2cmp\">\n"
48 "</HEAD>\n"
49 "<BODY BGCOLOR=\"#ffffff\">\n<P><BR></P>";
52 char C_sHtmlFileFoot[] = "</BODY>\n</HTML>\n";
55 HtmlCreator::HtmlCreator( const char * i_pOutputFileName,
56 const XmlElement & i_rDocument,
57 const Simstr & i_sIDL_BaseDirectory )
58 : aFile(i_pOutputFileName, std::ios::out
59 #if defined(WNT) || defined(OS2)
60 | std::ios::binary
61 #endif
63 rDocument(i_rDocument),
64 sIdl_BaseDirectory(i_sIDL_BaseDirectory)
66 if ( !aFile )
68 std::cerr << "Error: " << i_pOutputFileName << " could not be created." << std::endl;
69 exit(0);
73 HtmlCreator::~HtmlCreator()
75 aFile.close();
78 void
79 HtmlCreator::Run()
81 WriteStr( C_sHtmlFileHeader1 );
82 WriteStr( "ModuleDescription" );
83 WriteStr( C_sHtmlFileHeader2 );
85 rDocument.Write2Html(*this);
87 WriteStr( "<P><BR><BR></P>\n" );
88 WriteStr( C_sHtmlFileFoot );
91 void
92 HtmlCreator::StartTable()
94 WriteStr( "<P><BR></P>\n" );
95 WriteStr(
96 "<TABLE WIDTH=95% BORDER=1 CELLSPACING=0 CELLPADDING=4>\n"
97 " <TBODY>\n" );
100 void
101 HtmlCreator::FinishTable()
103 WriteStr( " </TBODY>\n"
104 "</TABLE>\n\n" );
107 void
108 HtmlCreator::StartBigCell( const char * i_sTitle )
110 WriteStr( "<TR><TD COLSPAN=2>\n"
111 "<H4><BR>" );
112 WriteStr( i_sTitle );
113 WriteStr( "</H4>\n" );
117 void
118 HtmlCreator::FinishBigCell()
120 WriteStr( "</TD><TR>\n" );
123 void
124 HtmlCreator::Write_SglTextElement( const SglTextElement & i_rElement,
125 bool i_bStrong )
127 StartRow();
129 WriteElementName( i_rElement.Name(), i_bStrong );
131 StartCell( "77%");
132 if (i_bStrong)
134 WriteStr( "<H4><A NAME=\"" );
135 unsigned nLen = strlen(i_rElement.Data());
136 if ( i_rElement.IsReversedName())
138 const char * pEnd = strchr(i_rElement.Data(), ' ');
139 nLen = (unsigned)( pEnd - i_rElement.Data() );
141 aFile.write( i_rElement.Data(), (int) nLen );
142 WriteStr( "\">" );
145 WriteName( aFile, sIdl_BaseDirectory, i_rElement.Data(),
146 i_bStrong ? lt_nolink : i_rElement.LinkType() );
148 if (i_bStrong)
149 WriteStr( "</A></H4>" );
150 FinishCell();
152 FinishRow();
155 void
156 HtmlCreator::Write_MultiTextElement( const MultipleTextElement & i_rElement )
158 StartRow();
160 WriteElementName( i_rElement.Name(), false );
162 StartCell( "77%");
163 unsigned i_max = i_rElement.Size();
164 for ( unsigned i = 0; i < i_max; ++i )
166 if (i > 0)
167 WriteStr( "<BR>\n" );
168 WriteName( aFile, sIdl_BaseDirectory, i_rElement.Data(i), i_rElement.LinkType() );
169 } // end for
170 FinishCell();
172 FinishRow();
175 void
176 HtmlCreator::Write_SglText( const Simstr & i_sName,
177 const Simstr & i_sValue )
179 StartRow();
181 WriteElementName( i_sName, false );
183 StartCell( "77%");
184 WriteStr( i_sValue );
185 FinishCell();
187 FinishRow();
190 void
191 HtmlCreator::Write_ReferenceDocu( const Simstr & i_sName,
192 const Simstr & i_sRef,
193 const Simstr & i_sRole,
194 const Simstr & i_sTitle )
196 StartRow();
198 StartCell( "23%" );
199 WriteStr(i_sName);
200 FinishCell();
202 StartCell( "77%" );
203 if ( !i_sRef.is_empty() )
205 WriteStr("<A href=\"");
206 WriteStr(i_sRef);
207 WriteStr("\">");
208 if ( !i_sTitle.is_empty() )
209 WriteStr( i_sTitle );
210 else
211 WriteStr(i_sRef);
212 WriteStr("</A><BR>\n");
214 else if ( !i_sTitle.is_empty() )
216 WriteStr("Title: ");
217 WriteStr( i_sTitle );
218 WriteStr("<BR>\n");
220 if ( !i_sRole.is_empty() )
222 WriteStr("Role: ");
223 WriteStr( i_sRole );
225 FinishCell();
227 FinishRow();
231 void
232 HtmlCreator::StartRow()
234 WriteStr( " <TR VALIGN=TOP>\n" );
237 void
238 HtmlCreator::FinishRow()
240 WriteStr( " </TR>\n" );
243 void
244 HtmlCreator::StartCell( const char * i_pWidth)
246 WriteStr( " <TD WIDTH=" );
247 WriteStr( i_pWidth );
248 WriteStr( ">\n <P>" );
251 void
252 HtmlCreator::FinishCell()
254 WriteStr( "</P>\n </TD>\n" );
257 void
258 HtmlCreator::WriteElementName( const Simstr & i_sName,
259 bool i_bStrong )
261 StartCell( "23%" );
262 if (i_bStrong)
263 WriteStr( "<H4>" );
264 WriteStr(i_sName);
265 if (i_bStrong)
266 WriteStr( "</H4>" );
267 FinishCell();