1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #include <fstream> 29*cdf0e10cSrcweir #include "cr_html.hxx" 30*cdf0e10cSrcweir #include "xmltree.hxx" 31*cdf0e10cSrcweir #include "../support/syshelp.hxx" 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir char C_sHtmlFileHeader1[] = 37*cdf0e10cSrcweir "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">\n" 38*cdf0e10cSrcweir "<HTML>\n" 39*cdf0e10cSrcweir "<HEAD>\n" 40*cdf0e10cSrcweir " <TITLE>"; 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir char C_sHtmlFileHeader2[] = 43*cdf0e10cSrcweir "</TITLE>\n" 44*cdf0e10cSrcweir " <META NAME=\"GENERATOR\" CONTENT=\"xml2cmp\">\n" 45*cdf0e10cSrcweir "</HEAD>\n" 46*cdf0e10cSrcweir "<BODY BGCOLOR=\"#ffffff\">\n<P><BR></P>"; 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir char C_sHtmlFileFoot[] = "</BODY>\n</HTML>\n"; 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir HtmlCreator::HtmlCreator( const char * i_pOutputFileName, 53*cdf0e10cSrcweir const XmlElement & i_rDocument, 54*cdf0e10cSrcweir const Simstr & i_sIDL_BaseDirectory ) 55*cdf0e10cSrcweir : aFile(i_pOutputFileName, std::ios::out 56*cdf0e10cSrcweir #if defined(WNT) || defined(OS2) 57*cdf0e10cSrcweir | std::ios::binary 58*cdf0e10cSrcweir #endif 59*cdf0e10cSrcweir ), 60*cdf0e10cSrcweir rDocument(i_rDocument), 61*cdf0e10cSrcweir sIdl_BaseDirectory(i_sIDL_BaseDirectory) 62*cdf0e10cSrcweir { 63*cdf0e10cSrcweir if ( !aFile ) 64*cdf0e10cSrcweir { 65*cdf0e10cSrcweir std::cerr << "Error: " << i_pOutputFileName << " could not be created." << std::endl; 66*cdf0e10cSrcweir exit(0); 67*cdf0e10cSrcweir } 68*cdf0e10cSrcweir } 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir HtmlCreator::~HtmlCreator() 71*cdf0e10cSrcweir { 72*cdf0e10cSrcweir aFile.close(); 73*cdf0e10cSrcweir } 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir void 76*cdf0e10cSrcweir HtmlCreator::Run() 77*cdf0e10cSrcweir { 78*cdf0e10cSrcweir WriteStr( C_sHtmlFileHeader1 ); 79*cdf0e10cSrcweir WriteStr( "ModuleDescription" ); 80*cdf0e10cSrcweir WriteStr( C_sHtmlFileHeader2 ); 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir rDocument.Write2Html(*this); 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir WriteStr( "<P><BR><BR></P>\n" ); 85*cdf0e10cSrcweir WriteStr( C_sHtmlFileFoot ); 86*cdf0e10cSrcweir } 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir void 89*cdf0e10cSrcweir HtmlCreator::StartTable() 90*cdf0e10cSrcweir { 91*cdf0e10cSrcweir WriteStr( "<P><BR></P>\n" ); 92*cdf0e10cSrcweir WriteStr( 93*cdf0e10cSrcweir "<TABLE WIDTH=95% BORDER=1 CELLSPACING=0 CELLPADDING=4>\n" 94*cdf0e10cSrcweir " <TBODY>\n" ); 95*cdf0e10cSrcweir } 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir void 98*cdf0e10cSrcweir HtmlCreator::FinishTable() 99*cdf0e10cSrcweir { 100*cdf0e10cSrcweir WriteStr( " </TBODY>\n" 101*cdf0e10cSrcweir "</TABLE>\n\n" ); 102*cdf0e10cSrcweir } 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir void 105*cdf0e10cSrcweir HtmlCreator::StartBigCell( const char * i_sTitle ) 106*cdf0e10cSrcweir { 107*cdf0e10cSrcweir WriteStr( "<TR><TD COLSPAN=2>\n" 108*cdf0e10cSrcweir "<H4><BR>" ); 109*cdf0e10cSrcweir WriteStr( i_sTitle ); 110*cdf0e10cSrcweir WriteStr( "</H4>\n" ); 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir } 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir void 115*cdf0e10cSrcweir HtmlCreator::FinishBigCell() 116*cdf0e10cSrcweir { 117*cdf0e10cSrcweir WriteStr( "</TD><TR>\n" ); 118*cdf0e10cSrcweir } 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir void 121*cdf0e10cSrcweir HtmlCreator::Write_SglTextElement( const SglTextElement & i_rElement, 122*cdf0e10cSrcweir bool i_bStrong ) 123*cdf0e10cSrcweir { 124*cdf0e10cSrcweir StartRow(); 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir WriteElementName( i_rElement.Name(), i_bStrong ); 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir StartCell( "77%"); 129*cdf0e10cSrcweir if (i_bStrong) 130*cdf0e10cSrcweir { 131*cdf0e10cSrcweir WriteStr( "<H4><A NAME=\"" ); 132*cdf0e10cSrcweir unsigned nLen = strlen(i_rElement.Data()); 133*cdf0e10cSrcweir if ( i_rElement.IsReversedName()) 134*cdf0e10cSrcweir { 135*cdf0e10cSrcweir const char * pEnd = strchr(i_rElement.Data(), ' '); 136*cdf0e10cSrcweir nLen = (unsigned)( pEnd - i_rElement.Data() ); 137*cdf0e10cSrcweir } 138*cdf0e10cSrcweir aFile.write( i_rElement.Data(), (int) nLen ); 139*cdf0e10cSrcweir WriteStr( "\">" ); 140*cdf0e10cSrcweir } 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir WriteName( aFile, sIdl_BaseDirectory, i_rElement.Data(), 143*cdf0e10cSrcweir i_bStrong ? lt_nolink : i_rElement.LinkType() ); 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir if (i_bStrong) 146*cdf0e10cSrcweir WriteStr( "</A></H4>" ); 147*cdf0e10cSrcweir FinishCell(); 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir FinishRow(); 150*cdf0e10cSrcweir } 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir void 153*cdf0e10cSrcweir HtmlCreator::Write_MultiTextElement( const MultipleTextElement & i_rElement ) 154*cdf0e10cSrcweir { 155*cdf0e10cSrcweir StartRow(); 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir WriteElementName( i_rElement.Name(), false ); 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir StartCell( "77%"); 160*cdf0e10cSrcweir unsigned i_max = i_rElement.Size(); 161*cdf0e10cSrcweir for ( unsigned i = 0; i < i_max; ++i ) 162*cdf0e10cSrcweir { 163*cdf0e10cSrcweir if (i > 0) 164*cdf0e10cSrcweir WriteStr( "<BR>\n" ); 165*cdf0e10cSrcweir WriteName( aFile, sIdl_BaseDirectory, i_rElement.Data(i), i_rElement.LinkType() ); 166*cdf0e10cSrcweir } // end for 167*cdf0e10cSrcweir FinishCell(); 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir FinishRow(); 170*cdf0e10cSrcweir } 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir void 173*cdf0e10cSrcweir HtmlCreator::Write_SglText( const Simstr & i_sName, 174*cdf0e10cSrcweir const Simstr & i_sValue ) 175*cdf0e10cSrcweir { 176*cdf0e10cSrcweir StartRow(); 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir WriteElementName( i_sName, false ); 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir StartCell( "77%"); 181*cdf0e10cSrcweir WriteStr( i_sValue ); 182*cdf0e10cSrcweir FinishCell(); 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir FinishRow(); 185*cdf0e10cSrcweir } 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir void 188*cdf0e10cSrcweir HtmlCreator::Write_ReferenceDocu( const Simstr & i_sName, 189*cdf0e10cSrcweir const Simstr & i_sRef, 190*cdf0e10cSrcweir const Simstr & i_sRole, 191*cdf0e10cSrcweir const Simstr & i_sTitle ) 192*cdf0e10cSrcweir { 193*cdf0e10cSrcweir StartRow(); 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir StartCell( "23%" ); 196*cdf0e10cSrcweir WriteStr(i_sName); 197*cdf0e10cSrcweir FinishCell(); 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir StartCell( "77%" ); 200*cdf0e10cSrcweir if ( !i_sRef.is_empty() ) 201*cdf0e10cSrcweir { 202*cdf0e10cSrcweir WriteStr("<A href=\""); 203*cdf0e10cSrcweir WriteStr(i_sRef); 204*cdf0e10cSrcweir WriteStr("\">"); 205*cdf0e10cSrcweir if ( !i_sTitle.is_empty() ) 206*cdf0e10cSrcweir WriteStr( i_sTitle ); 207*cdf0e10cSrcweir else 208*cdf0e10cSrcweir WriteStr(i_sRef); 209*cdf0e10cSrcweir WriteStr("</A><BR>\n"); 210*cdf0e10cSrcweir } 211*cdf0e10cSrcweir else if ( !i_sTitle.is_empty() ) 212*cdf0e10cSrcweir { 213*cdf0e10cSrcweir WriteStr("Title: "); 214*cdf0e10cSrcweir WriteStr( i_sTitle ); 215*cdf0e10cSrcweir WriteStr("<BR>\n"); 216*cdf0e10cSrcweir } 217*cdf0e10cSrcweir if ( !i_sRole.is_empty() ) 218*cdf0e10cSrcweir { 219*cdf0e10cSrcweir WriteStr("Role: "); 220*cdf0e10cSrcweir WriteStr( i_sRole ); 221*cdf0e10cSrcweir } 222*cdf0e10cSrcweir FinishCell(); 223*cdf0e10cSrcweir 224*cdf0e10cSrcweir FinishRow(); 225*cdf0e10cSrcweir } 226*cdf0e10cSrcweir 227*cdf0e10cSrcweir 228*cdf0e10cSrcweir void 229*cdf0e10cSrcweir HtmlCreator::StartRow() 230*cdf0e10cSrcweir { 231*cdf0e10cSrcweir WriteStr( " <TR VALIGN=TOP>\n" ); 232*cdf0e10cSrcweir } 233*cdf0e10cSrcweir 234*cdf0e10cSrcweir void 235*cdf0e10cSrcweir HtmlCreator::FinishRow() 236*cdf0e10cSrcweir { 237*cdf0e10cSrcweir WriteStr( " </TR>\n" ); 238*cdf0e10cSrcweir } 239*cdf0e10cSrcweir 240*cdf0e10cSrcweir void 241*cdf0e10cSrcweir HtmlCreator::StartCell( const char * i_pWidth) 242*cdf0e10cSrcweir { 243*cdf0e10cSrcweir WriteStr( " <TD WIDTH=" ); 244*cdf0e10cSrcweir WriteStr( i_pWidth ); 245*cdf0e10cSrcweir WriteStr( ">\n <P>" ); 246*cdf0e10cSrcweir } 247*cdf0e10cSrcweir 248*cdf0e10cSrcweir void 249*cdf0e10cSrcweir HtmlCreator::FinishCell() 250*cdf0e10cSrcweir { 251*cdf0e10cSrcweir WriteStr( "</P>\n </TD>\n" ); 252*cdf0e10cSrcweir } 253*cdf0e10cSrcweir 254*cdf0e10cSrcweir void 255*cdf0e10cSrcweir HtmlCreator::WriteElementName( const Simstr & i_sName, 256*cdf0e10cSrcweir bool i_bStrong ) 257*cdf0e10cSrcweir { 258*cdf0e10cSrcweir StartCell( "23%" ); 259*cdf0e10cSrcweir if (i_bStrong) 260*cdf0e10cSrcweir WriteStr( "<H4>" ); 261*cdf0e10cSrcweir WriteStr(i_sName); 262*cdf0e10cSrcweir if (i_bStrong) 263*cdf0e10cSrcweir WriteStr( "</H4>" ); 264*cdf0e10cSrcweir FinishCell(); 265*cdf0e10cSrcweir } 266*cdf0e10cSrcweir 267*cdf0e10cSrcweir 268*cdf0e10cSrcweir 269