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 29*cdf0e10cSrcweir #include "cr_index.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <string.h> 32*cdf0e10cSrcweir #include <fstream> 33*cdf0e10cSrcweir #include "../support/syshelp.hxx" 34*cdf0e10cSrcweir #include "xmltree.hxx" 35*cdf0e10cSrcweir #include "parse.hxx" 36*cdf0e10cSrcweir #include "cr_html.hxx" 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir extern unsigned C_nSupportedServicesIndex; 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir char C_sLineEnd[] = "\n"; 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir char C_sFileBegin[] = "<HTML><HEAD></HEAD><BODY bgcolor=\"#ffffff\">\n"; 44*cdf0e10cSrcweir char C_sFileEnd[] = "</BODY></HTML>\n"; 45*cdf0e10cSrcweir char C_sTableBegin[] = "<TABLE WIDTH=100% BORDER=1 CELLPADDING=4 CELLSPACING=0><TBODY>\n"; 46*cdf0e10cSrcweir char C_sTableEnd[] = "</TBODY></TABLE>\n"; 47*cdf0e10cSrcweir char C_sService[] = "SupportedService"; 48*cdf0e10cSrcweir char C_sModule[] = "ModuleName"; 49*cdf0e10cSrcweir char C_sComponentname[] = "ComponentName"; 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir Simstr sIdlRootPath; 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir Index::Index( const char * i_sOutputDirectory, 57*cdf0e10cSrcweir const char * i_sIdlRootPath, 58*cdf0e10cSrcweir const List<Simstr> & ) 59*cdf0e10cSrcweir : aService2Module(20), 60*cdf0e10cSrcweir aModule2Service(20), 61*cdf0e10cSrcweir sOutputDirectory(i_sOutputDirectory), 62*cdf0e10cSrcweir sIdlRootPath(i_sIdlRootPath) 63*cdf0e10cSrcweir // sCurModule 64*cdf0e10cSrcweir { 65*cdf0e10cSrcweir ::sIdlRootPath = i_sIdlRootPath; 66*cdf0e10cSrcweir } 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir Index::~Index() 69*cdf0e10cSrcweir { 70*cdf0e10cSrcweir } 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir void 73*cdf0e10cSrcweir Index::GatherData( const List<Simstr> & i_rInputFileList ) 74*cdf0e10cSrcweir { 75*cdf0e10cSrcweir for ( unsigned i = 0; i < i_rInputFileList.size(); ++i ) 76*cdf0e10cSrcweir { 77*cdf0e10cSrcweir ReadFile( i_rInputFileList[i].str() ); 78*cdf0e10cSrcweir } 79*cdf0e10cSrcweir } 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir void 82*cdf0e10cSrcweir Index::WriteOutput( const char * i_sOuputFile ) 83*cdf0e10cSrcweir { 84*cdf0e10cSrcweir std::ofstream aOut( i_sOuputFile, std::ios::out ); 85*cdf0e10cSrcweir if (! aOut) 86*cdf0e10cSrcweir { 87*cdf0e10cSrcweir std::cerr << "Error: Indexfile \"" 88*cdf0e10cSrcweir << i_sOuputFile 89*cdf0e10cSrcweir << "\" could not be created." 90*cdf0e10cSrcweir << std::endl; 91*cdf0e10cSrcweir return; 92*cdf0e10cSrcweir } 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir WriteStr(aOut, C_sFileBegin); 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir WriteStr(aOut, "<H2>Module Descriptions Index</H2>"); 97*cdf0e10cSrcweir WriteStr(aOut, C_sLineEnd ); 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir WriteTableFromHeap( aOut, aService2Module, C_sService, C_sModule, lt_html ); 101*cdf0e10cSrcweir WriteTableFromHeap( aOut, aModule2Service, C_sModule, C_sService, lt_idl ); 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir WriteStr( aOut, C_sFileEnd ); 104*cdf0e10cSrcweir aOut.close(); 105*cdf0e10cSrcweir } 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir void 108*cdf0e10cSrcweir Index::InsertSupportedService( const Simstr & i_sService ) 109*cdf0e10cSrcweir { 110*cdf0e10cSrcweir aService2Module.InsertValue( i_sService, sCurModule ); 111*cdf0e10cSrcweir aModule2Service.InsertValue( sCurModule, i_sService ); 112*cdf0e10cSrcweir } 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir void 115*cdf0e10cSrcweir Index::ReadFile( const char * i_sFilename ) 116*cdf0e10cSrcweir { 117*cdf0e10cSrcweir static char sOutputHtml[1020]; 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir ModuleDescription aModule; 120*cdf0e10cSrcweir X2CParser aParser(aModule); 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir // Parse 123*cdf0e10cSrcweir bool bResult = aParser.Parse(i_sFilename); 124*cdf0e10cSrcweir if (! bResult) 125*cdf0e10cSrcweir { 126*cdf0e10cSrcweir std::cerr << "Error: File \"" 127*cdf0e10cSrcweir << i_sFilename 128*cdf0e10cSrcweir << "\" could not be parsed." 129*cdf0e10cSrcweir << std::endl; 130*cdf0e10cSrcweir return; 131*cdf0e10cSrcweir } 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir // Create Html: 134*cdf0e10cSrcweir CreateHtmlFileName( sOutputHtml, aModule ); 135*cdf0e10cSrcweir HtmlCreator aHtmlCreator( sOutputHtml, aModule, sIdlRootPath ); 136*cdf0e10cSrcweir aHtmlCreator.Run(); 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir // GetResults: 139*cdf0e10cSrcweir sCurModule = aModule.ModuleName(); 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir List< const MultipleTextElement* > aSupportedServices; 142*cdf0e10cSrcweir aModule.Get_SupportedServices(aSupportedServices); 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir for ( unsigned s = 0; s < aSupportedServices.size(); ++s ) 145*cdf0e10cSrcweir { 146*cdf0e10cSrcweir aSupportedServices[s]->Insert2Index(*this); 147*cdf0e10cSrcweir } 148*cdf0e10cSrcweir } 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir void 151*cdf0e10cSrcweir Index::CreateHtmlFileName( char * o_sOutputHtml, 152*cdf0e10cSrcweir const ModuleDescription & i_rModule ) 153*cdf0e10cSrcweir { 154*cdf0e10cSrcweir if ( strlen(sOutputDirectory.str()) + strlen(i_rModule.ModuleName()) > 1000 ) 155*cdf0e10cSrcweir { 156*cdf0e10cSrcweir strcpy( o_sOutputHtml, "too-long-filename.html"); // STRCPY SAFE HERE 157*cdf0e10cSrcweir return; 158*cdf0e10cSrcweir } 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir strcpy( o_sOutputHtml, sOutputDirectory.str() ); // STRCPY SAFE HERE 161*cdf0e10cSrcweir #if defined(WNT) || defined(OS2) 162*cdf0e10cSrcweir strcat(o_sOutputHtml, "\\"); // STRCAT SAFE HERE 163*cdf0e10cSrcweir #elif defined(UNX) 164*cdf0e10cSrcweir strcat(o_sOutputHtml, "/"); // STRCAT SAFE HERE 165*cdf0e10cSrcweir #else 166*cdf0e10cSrcweir #error WNT or UNX have to be defined. 167*cdf0e10cSrcweir #endif 168*cdf0e10cSrcweir strcat( o_sOutputHtml, i_rModule.ModuleName() ); // STRCAT SAFE HERE 169*cdf0e10cSrcweir strcat( o_sOutputHtml, ".html" ); // STRCAT SAFE HERE 170*cdf0e10cSrcweir } 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir void 174*cdf0e10cSrcweir Index::WriteTableFromHeap( std::ostream & o_rOut, 175*cdf0e10cSrcweir Heap & i_rHeap, 176*cdf0e10cSrcweir const char * i_sIndexValue, 177*cdf0e10cSrcweir const char * i_sIndexReference, 178*cdf0e10cSrcweir E_LinkType i_eLinkType ) 179*cdf0e10cSrcweir { 180*cdf0e10cSrcweir WriteStr(o_rOut, "<H3><BR>"); 181*cdf0e10cSrcweir WriteStr(o_rOut, i_sIndexValue ); 182*cdf0e10cSrcweir WriteStr(o_rOut, " -> "); 183*cdf0e10cSrcweir WriteStr(o_rOut, i_sIndexReference ); 184*cdf0e10cSrcweir WriteStr(o_rOut, "</H3>\n"); 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir WriteStr(o_rOut, C_sTableBegin); 187*cdf0e10cSrcweir WriteHeap( o_rOut, i_rHeap, i_eLinkType ); 188*cdf0e10cSrcweir WriteStr(o_rOut, C_sTableEnd); 189*cdf0e10cSrcweir } 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir void 193*cdf0e10cSrcweir Index::WriteHeap( std::ostream & o_rOut, 194*cdf0e10cSrcweir Heap & i_rHeap, 195*cdf0e10cSrcweir E_LinkType i_eLinkType ) 196*cdf0e10cSrcweir { 197*cdf0e10cSrcweir static Simstr S_sKey; 198*cdf0e10cSrcweir static char C_sSpaceInName[] = " "; 199*cdf0e10cSrcweir S_sKey = ""; 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir 202*cdf0e10cSrcweir WriteStr( o_rOut, "<TR><TD width=33% valign=\"top\">" ); 203*cdf0e10cSrcweir 204*cdf0e10cSrcweir for ( HeapItem * pHeapTop = i_rHeap.ReleaseTop(); 205*cdf0e10cSrcweir pHeapTop != 0; 206*cdf0e10cSrcweir pHeapTop = i_rHeap.ReleaseTop() ) 207*cdf0e10cSrcweir { 208*cdf0e10cSrcweir if ( S_sKey != pHeapTop->Key() ) 209*cdf0e10cSrcweir { 210*cdf0e10cSrcweir const char * pStart = pHeapTop->Key().str(); 211*cdf0e10cSrcweir const char * pBreak = strstr( pStart, " in "); 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir if (S_sKey.l()>0) 214*cdf0e10cSrcweir { 215*cdf0e10cSrcweir WriteStr( o_rOut, "</TD></TR>\n" ); 216*cdf0e10cSrcweir WriteStr( o_rOut, "<TR><TD width=33% valign=\"top\">" ); 217*cdf0e10cSrcweir } 218*cdf0e10cSrcweir 219*cdf0e10cSrcweir if ( pBreak == 0 ) 220*cdf0e10cSrcweir WriteStr( o_rOut, pStart ); 221*cdf0e10cSrcweir else 222*cdf0e10cSrcweir { 223*cdf0e10cSrcweir o_rOut.write( pStart, pBreak - pStart ); 224*cdf0e10cSrcweir WriteStr( o_rOut, C_sSpaceInName ); 225*cdf0e10cSrcweir WriteStr( o_rOut, pBreak ); 226*cdf0e10cSrcweir } 227*cdf0e10cSrcweir WriteStr( o_rOut, "</TD><TD width=66%>" ); 228*cdf0e10cSrcweir S_sKey = pHeapTop->Key(); 229*cdf0e10cSrcweir } 230*cdf0e10cSrcweir else 231*cdf0e10cSrcweir { 232*cdf0e10cSrcweir WriteStr( o_rOut, "<BR>" ); 233*cdf0e10cSrcweir } 234*cdf0e10cSrcweir WriteName( o_rOut, sIdlRootPath, pHeapTop->Value(), i_eLinkType ); 235*cdf0e10cSrcweir delete pHeapTop; 236*cdf0e10cSrcweir } 237*cdf0e10cSrcweir 238*cdf0e10cSrcweir WriteStr( o_rOut, "</TD></TR>\n" ); 239*cdf0e10cSrcweir } 240*cdf0e10cSrcweir 241*cdf0e10cSrcweir 242*cdf0e10cSrcweir 243*cdf0e10cSrcweir /** �bersicht der Struktur 244*cdf0e10cSrcweir 245*cdf0e10cSrcweir MODULEDESCRIPTION 246*cdf0e10cSrcweir { 247*cdf0e10cSrcweir ModuleName, 248*cdf0e10cSrcweir COMPONENTDESCRIPTION 249*cdf0e10cSrcweir { 250*cdf0e10cSrcweir Author, 251*cdf0e10cSrcweir Name, 252*cdf0e10cSrcweir Description, 253*cdf0e10cSrcweir LoaderName, 254*cdf0e10cSrcweir Language, 255*cdf0e10cSrcweir Status, 256*cdf0e10cSrcweir SupportedService+, 257*cdf0e10cSrcweir ReferenceDocu* 258*cdf0e10cSrcweir ServiceDependency* 259*cdf0e10cSrcweir Type* 260*cdf0e10cSrcweir } 261*cdf0e10cSrcweir ProjectBuildDependency* 262*cdf0e10cSrcweir RuntimeModuleDependency* 263*cdf0e10cSrcweir ReferenceDocu* 264*cdf0e10cSrcweir ServiceDependency* 265*cdf0e10cSrcweir Type* 266*cdf0e10cSrcweir } 267*cdf0e10cSrcweir 268*cdf0e10cSrcweir 269*cdf0e10cSrcweir */ 270*cdf0e10cSrcweir 271*cdf0e10cSrcweir 272*cdf0e10cSrcweir 273*cdf0e10cSrcweir 274*cdf0e10cSrcweir 275*cdf0e10cSrcweir 276