1*ab595ff6SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*ab595ff6SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*ab595ff6SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*ab595ff6SAndrew Rist * distributed with this work for additional information 6*ab595ff6SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*ab595ff6SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*ab595ff6SAndrew Rist * "License"); you may not use this file except in compliance 9*ab595ff6SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*ab595ff6SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*ab595ff6SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*ab595ff6SAndrew Rist * software distributed under the License is distributed on an 15*ab595ff6SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*ab595ff6SAndrew Rist * KIND, either express or implied. See the License for the 17*ab595ff6SAndrew Rist * specific language governing permissions and limitations 18*ab595ff6SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*ab595ff6SAndrew Rist *************************************************************/ 21*ab595ff6SAndrew Rist 22*ab595ff6SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #include <fstream> 25cdf0e10cSrcweir #include "cr_html.hxx" 26cdf0e10cSrcweir #include "xmltree.hxx" 27cdf0e10cSrcweir #include "../support/syshelp.hxx" 28cdf0e10cSrcweir 29cdf0e10cSrcweir 30cdf0e10cSrcweir 31cdf0e10cSrcweir 32cdf0e10cSrcweir char C_sHtmlFileHeader1[] = 33cdf0e10cSrcweir "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">\n" 34cdf0e10cSrcweir "<HTML>\n" 35cdf0e10cSrcweir "<HEAD>\n" 36cdf0e10cSrcweir " <TITLE>"; 37cdf0e10cSrcweir 38cdf0e10cSrcweir char C_sHtmlFileHeader2[] = 39cdf0e10cSrcweir "</TITLE>\n" 40cdf0e10cSrcweir " <META NAME=\"GENERATOR\" CONTENT=\"xml2cmp\">\n" 41cdf0e10cSrcweir "</HEAD>\n" 42cdf0e10cSrcweir "<BODY BGCOLOR=\"#ffffff\">\n<P><BR></P>"; 43cdf0e10cSrcweir 44cdf0e10cSrcweir 45cdf0e10cSrcweir char C_sHtmlFileFoot[] = "</BODY>\n</HTML>\n"; 46cdf0e10cSrcweir 47cdf0e10cSrcweir 48cdf0e10cSrcweir HtmlCreator::HtmlCreator( const char * i_pOutputFileName, 49cdf0e10cSrcweir const XmlElement & i_rDocument, 50cdf0e10cSrcweir const Simstr & i_sIDL_BaseDirectory ) 51cdf0e10cSrcweir : aFile(i_pOutputFileName, std::ios::out 52cdf0e10cSrcweir #if defined(WNT) || defined(OS2) 53cdf0e10cSrcweir | std::ios::binary 54cdf0e10cSrcweir #endif 55cdf0e10cSrcweir ), 56cdf0e10cSrcweir rDocument(i_rDocument), 57cdf0e10cSrcweir sIdl_BaseDirectory(i_sIDL_BaseDirectory) 58cdf0e10cSrcweir { 59cdf0e10cSrcweir if ( !aFile ) 60cdf0e10cSrcweir { 61cdf0e10cSrcweir std::cerr << "Error: " << i_pOutputFileName << " could not be created." << std::endl; 62cdf0e10cSrcweir exit(0); 63cdf0e10cSrcweir } 64cdf0e10cSrcweir } 65cdf0e10cSrcweir 66cdf0e10cSrcweir HtmlCreator::~HtmlCreator() 67cdf0e10cSrcweir { 68cdf0e10cSrcweir aFile.close(); 69cdf0e10cSrcweir } 70cdf0e10cSrcweir 71cdf0e10cSrcweir void 72cdf0e10cSrcweir HtmlCreator::Run() 73cdf0e10cSrcweir { 74cdf0e10cSrcweir WriteStr( C_sHtmlFileHeader1 ); 75cdf0e10cSrcweir WriteStr( "ModuleDescription" ); 76cdf0e10cSrcweir WriteStr( C_sHtmlFileHeader2 ); 77cdf0e10cSrcweir 78cdf0e10cSrcweir rDocument.Write2Html(*this); 79cdf0e10cSrcweir 80cdf0e10cSrcweir WriteStr( "<P><BR><BR></P>\n" ); 81cdf0e10cSrcweir WriteStr( C_sHtmlFileFoot ); 82cdf0e10cSrcweir } 83cdf0e10cSrcweir 84cdf0e10cSrcweir void 85cdf0e10cSrcweir HtmlCreator::StartTable() 86cdf0e10cSrcweir { 87cdf0e10cSrcweir WriteStr( "<P><BR></P>\n" ); 88cdf0e10cSrcweir WriteStr( 89cdf0e10cSrcweir "<TABLE WIDTH=95% BORDER=1 CELLSPACING=0 CELLPADDING=4>\n" 90cdf0e10cSrcweir " <TBODY>\n" ); 91cdf0e10cSrcweir } 92cdf0e10cSrcweir 93cdf0e10cSrcweir void 94cdf0e10cSrcweir HtmlCreator::FinishTable() 95cdf0e10cSrcweir { 96cdf0e10cSrcweir WriteStr( " </TBODY>\n" 97cdf0e10cSrcweir "</TABLE>\n\n" ); 98cdf0e10cSrcweir } 99cdf0e10cSrcweir 100cdf0e10cSrcweir void 101cdf0e10cSrcweir HtmlCreator::StartBigCell( const char * i_sTitle ) 102cdf0e10cSrcweir { 103cdf0e10cSrcweir WriteStr( "<TR><TD COLSPAN=2>\n" 104cdf0e10cSrcweir "<H4><BR>" ); 105cdf0e10cSrcweir WriteStr( i_sTitle ); 106cdf0e10cSrcweir WriteStr( "</H4>\n" ); 107cdf0e10cSrcweir 108cdf0e10cSrcweir } 109cdf0e10cSrcweir 110cdf0e10cSrcweir void 111cdf0e10cSrcweir HtmlCreator::FinishBigCell() 112cdf0e10cSrcweir { 113cdf0e10cSrcweir WriteStr( "</TD><TR>\n" ); 114cdf0e10cSrcweir } 115cdf0e10cSrcweir 116cdf0e10cSrcweir void 117cdf0e10cSrcweir HtmlCreator::Write_SglTextElement( const SglTextElement & i_rElement, 118cdf0e10cSrcweir bool i_bStrong ) 119cdf0e10cSrcweir { 120cdf0e10cSrcweir StartRow(); 121cdf0e10cSrcweir 122cdf0e10cSrcweir WriteElementName( i_rElement.Name(), i_bStrong ); 123cdf0e10cSrcweir 124cdf0e10cSrcweir StartCell( "77%"); 125cdf0e10cSrcweir if (i_bStrong) 126cdf0e10cSrcweir { 127cdf0e10cSrcweir WriteStr( "<H4><A NAME=\"" ); 128cdf0e10cSrcweir unsigned nLen = strlen(i_rElement.Data()); 129cdf0e10cSrcweir if ( i_rElement.IsReversedName()) 130cdf0e10cSrcweir { 131cdf0e10cSrcweir const char * pEnd = strchr(i_rElement.Data(), ' '); 132cdf0e10cSrcweir nLen = (unsigned)( pEnd - i_rElement.Data() ); 133cdf0e10cSrcweir } 134cdf0e10cSrcweir aFile.write( i_rElement.Data(), (int) nLen ); 135cdf0e10cSrcweir WriteStr( "\">" ); 136cdf0e10cSrcweir } 137cdf0e10cSrcweir 138cdf0e10cSrcweir WriteName( aFile, sIdl_BaseDirectory, i_rElement.Data(), 139cdf0e10cSrcweir i_bStrong ? lt_nolink : i_rElement.LinkType() ); 140cdf0e10cSrcweir 141cdf0e10cSrcweir if (i_bStrong) 142cdf0e10cSrcweir WriteStr( "</A></H4>" ); 143cdf0e10cSrcweir FinishCell(); 144cdf0e10cSrcweir 145cdf0e10cSrcweir FinishRow(); 146cdf0e10cSrcweir } 147cdf0e10cSrcweir 148cdf0e10cSrcweir void 149cdf0e10cSrcweir HtmlCreator::Write_MultiTextElement( const MultipleTextElement & i_rElement ) 150cdf0e10cSrcweir { 151cdf0e10cSrcweir StartRow(); 152cdf0e10cSrcweir 153cdf0e10cSrcweir WriteElementName( i_rElement.Name(), false ); 154cdf0e10cSrcweir 155cdf0e10cSrcweir StartCell( "77%"); 156cdf0e10cSrcweir unsigned i_max = i_rElement.Size(); 157cdf0e10cSrcweir for ( unsigned i = 0; i < i_max; ++i ) 158cdf0e10cSrcweir { 159cdf0e10cSrcweir if (i > 0) 160cdf0e10cSrcweir WriteStr( "<BR>\n" ); 161cdf0e10cSrcweir WriteName( aFile, sIdl_BaseDirectory, i_rElement.Data(i), i_rElement.LinkType() ); 162cdf0e10cSrcweir } // end for 163cdf0e10cSrcweir FinishCell(); 164cdf0e10cSrcweir 165cdf0e10cSrcweir FinishRow(); 166cdf0e10cSrcweir } 167cdf0e10cSrcweir 168cdf0e10cSrcweir void 169cdf0e10cSrcweir HtmlCreator::Write_SglText( const Simstr & i_sName, 170cdf0e10cSrcweir const Simstr & i_sValue ) 171cdf0e10cSrcweir { 172cdf0e10cSrcweir StartRow(); 173cdf0e10cSrcweir 174cdf0e10cSrcweir WriteElementName( i_sName, false ); 175cdf0e10cSrcweir 176cdf0e10cSrcweir StartCell( "77%"); 177cdf0e10cSrcweir WriteStr( i_sValue ); 178cdf0e10cSrcweir FinishCell(); 179cdf0e10cSrcweir 180cdf0e10cSrcweir FinishRow(); 181cdf0e10cSrcweir } 182cdf0e10cSrcweir 183cdf0e10cSrcweir void 184cdf0e10cSrcweir HtmlCreator::Write_ReferenceDocu( const Simstr & i_sName, 185cdf0e10cSrcweir const Simstr & i_sRef, 186cdf0e10cSrcweir const Simstr & i_sRole, 187cdf0e10cSrcweir const Simstr & i_sTitle ) 188cdf0e10cSrcweir { 189cdf0e10cSrcweir StartRow(); 190cdf0e10cSrcweir 191cdf0e10cSrcweir StartCell( "23%" ); 192cdf0e10cSrcweir WriteStr(i_sName); 193cdf0e10cSrcweir FinishCell(); 194cdf0e10cSrcweir 195cdf0e10cSrcweir StartCell( "77%" ); 196cdf0e10cSrcweir if ( !i_sRef.is_empty() ) 197cdf0e10cSrcweir { 198cdf0e10cSrcweir WriteStr("<A href=\""); 199cdf0e10cSrcweir WriteStr(i_sRef); 200cdf0e10cSrcweir WriteStr("\">"); 201cdf0e10cSrcweir if ( !i_sTitle.is_empty() ) 202cdf0e10cSrcweir WriteStr( i_sTitle ); 203cdf0e10cSrcweir else 204cdf0e10cSrcweir WriteStr(i_sRef); 205cdf0e10cSrcweir WriteStr("</A><BR>\n"); 206cdf0e10cSrcweir } 207cdf0e10cSrcweir else if ( !i_sTitle.is_empty() ) 208cdf0e10cSrcweir { 209cdf0e10cSrcweir WriteStr("Title: "); 210cdf0e10cSrcweir WriteStr( i_sTitle ); 211cdf0e10cSrcweir WriteStr("<BR>\n"); 212cdf0e10cSrcweir } 213cdf0e10cSrcweir if ( !i_sRole.is_empty() ) 214cdf0e10cSrcweir { 215cdf0e10cSrcweir WriteStr("Role: "); 216cdf0e10cSrcweir WriteStr( i_sRole ); 217cdf0e10cSrcweir } 218cdf0e10cSrcweir FinishCell(); 219cdf0e10cSrcweir 220cdf0e10cSrcweir FinishRow(); 221cdf0e10cSrcweir } 222cdf0e10cSrcweir 223cdf0e10cSrcweir 224cdf0e10cSrcweir void 225cdf0e10cSrcweir HtmlCreator::StartRow() 226cdf0e10cSrcweir { 227cdf0e10cSrcweir WriteStr( " <TR VALIGN=TOP>\n" ); 228cdf0e10cSrcweir } 229cdf0e10cSrcweir 230cdf0e10cSrcweir void 231cdf0e10cSrcweir HtmlCreator::FinishRow() 232cdf0e10cSrcweir { 233cdf0e10cSrcweir WriteStr( " </TR>\n" ); 234cdf0e10cSrcweir } 235cdf0e10cSrcweir 236cdf0e10cSrcweir void 237cdf0e10cSrcweir HtmlCreator::StartCell( const char * i_pWidth) 238cdf0e10cSrcweir { 239cdf0e10cSrcweir WriteStr( " <TD WIDTH=" ); 240cdf0e10cSrcweir WriteStr( i_pWidth ); 241cdf0e10cSrcweir WriteStr( ">\n <P>" ); 242cdf0e10cSrcweir } 243cdf0e10cSrcweir 244cdf0e10cSrcweir void 245cdf0e10cSrcweir HtmlCreator::FinishCell() 246cdf0e10cSrcweir { 247cdf0e10cSrcweir WriteStr( "</P>\n </TD>\n" ); 248cdf0e10cSrcweir } 249cdf0e10cSrcweir 250cdf0e10cSrcweir void 251cdf0e10cSrcweir HtmlCreator::WriteElementName( const Simstr & i_sName, 252cdf0e10cSrcweir bool i_bStrong ) 253cdf0e10cSrcweir { 254cdf0e10cSrcweir StartCell( "23%" ); 255cdf0e10cSrcweir if (i_bStrong) 256cdf0e10cSrcweir WriteStr( "<H4>" ); 257cdf0e10cSrcweir WriteStr(i_sName); 258cdf0e10cSrcweir if (i_bStrong) 259cdf0e10cSrcweir WriteStr( "</H4>" ); 260cdf0e10cSrcweir FinishCell(); 261cdf0e10cSrcweir } 262cdf0e10cSrcweir 263cdf0e10cSrcweir 264cdf0e10cSrcweir 265