Update ooo320-m1
[ooovba.git] / xml2cmp / source / xcd / cr_index.cxx
blob3414640f496fea2731f1c1e14eff43535065e897
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_index.cxx,v $
10 * $Revision: 1.12 $
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 ************************************************************************/
32 #include "cr_index.hxx"
34 #include <string.h>
35 #include <fstream>
36 #include "../support/syshelp.hxx"
37 #include "xmltree.hxx"
38 #include "parse.hxx"
39 #include "cr_html.hxx"
42 extern unsigned C_nSupportedServicesIndex;
44 char C_sLineEnd[] = "\n";
46 char C_sFileBegin[] = "<HTML><HEAD></HEAD><BODY bgcolor=\"#ffffff\">\n";
47 char C_sFileEnd[] = "</BODY></HTML>\n";
48 char C_sTableBegin[] = "<TABLE WIDTH=100% BORDER=1 CELLPADDING=4 CELLSPACING=0><TBODY>\n";
49 char C_sTableEnd[] = "</TBODY></TABLE>\n";
50 char C_sService[] = "SupportedService";
51 char C_sModule[] = "ModuleName";
52 char C_sComponentname[] = "ComponentName";
56 Simstr sIdlRootPath;
59 Index::Index( const char * i_sOutputDirectory,
60 const char * i_sIdlRootPath,
61 const List<Simstr> & )
62 : aService2Module(20),
63 aModule2Service(20),
64 sOutputDirectory(i_sOutputDirectory),
65 sIdlRootPath(i_sIdlRootPath)
66 // sCurModule
68 ::sIdlRootPath = i_sIdlRootPath;
71 Index::~Index()
75 void
76 Index::GatherData( const List<Simstr> & i_rInputFileList )
78 for ( unsigned i = 0; i < i_rInputFileList.size(); ++i )
80 ReadFile( i_rInputFileList[i].str() );
84 void
85 Index::WriteOutput( const char * i_sOuputFile )
87 std::ofstream aOut( i_sOuputFile, std::ios::out );
88 if (! aOut)
90 std::cerr << "Error: Indexfile \""
91 << i_sOuputFile
92 << "\" could not be created."
93 << std::endl;
94 return;
97 WriteStr(aOut, C_sFileBegin);
99 WriteStr(aOut, "<H2>Module Descriptions Index</H2>");
100 WriteStr(aOut, C_sLineEnd );
103 WriteTableFromHeap( aOut, aService2Module, C_sService, C_sModule, lt_html );
104 WriteTableFromHeap( aOut, aModule2Service, C_sModule, C_sService, lt_idl );
106 WriteStr( aOut, C_sFileEnd );
107 aOut.close();
110 void
111 Index::InsertSupportedService( const Simstr & i_sService )
113 aService2Module.InsertValue( i_sService, sCurModule );
114 aModule2Service.InsertValue( sCurModule, i_sService );
117 void
118 Index::ReadFile( const char * i_sFilename )
120 static char sOutputHtml[1020];
122 ModuleDescription aModule;
123 X2CParser aParser(aModule);
125 // Parse
126 bool bResult = aParser.Parse(i_sFilename);
127 if (! bResult)
129 std::cerr << "Error: File \""
130 << i_sFilename
131 << "\" could not be parsed."
132 << std::endl;
133 return;
136 // Create Html:
137 CreateHtmlFileName( sOutputHtml, aModule );
138 HtmlCreator aHtmlCreator( sOutputHtml, aModule, sIdlRootPath );
139 aHtmlCreator.Run();
141 // GetResults:
142 sCurModule = aModule.ModuleName();
144 List< const MultipleTextElement* > aSupportedServices;
145 aModule.Get_SupportedServices(aSupportedServices);
147 for ( unsigned s = 0; s < aSupportedServices.size(); ++s )
149 aSupportedServices[s]->Insert2Index(*this);
153 void
154 Index::CreateHtmlFileName( char * o_sOutputHtml,
155 const ModuleDescription & i_rModule )
157 if ( strlen(sOutputDirectory.str()) + strlen(i_rModule.ModuleName()) > 1000 )
159 strcpy( o_sOutputHtml, "too-long-filename.html"); // STRCPY SAFE HERE
160 return;
163 strcpy( o_sOutputHtml, sOutputDirectory.str() ); // STRCPY SAFE HERE
164 #if defined(WNT) || defined(OS2)
165 strcat(o_sOutputHtml, "\\"); // STRCAT SAFE HERE
166 #elif defined(UNX)
167 strcat(o_sOutputHtml, "/"); // STRCAT SAFE HERE
168 #else
169 #error WNT or UNX have to be defined.
170 #endif
171 strcat( o_sOutputHtml, i_rModule.ModuleName() ); // STRCAT SAFE HERE
172 strcat( o_sOutputHtml, ".html" ); // STRCAT SAFE HERE
176 void
177 Index::WriteTableFromHeap( std::ostream & o_rOut,
178 Heap & i_rHeap,
179 const char * i_sIndexValue,
180 const char * i_sIndexReference,
181 E_LinkType i_eLinkType )
183 WriteStr(o_rOut, "<H3><BR>");
184 WriteStr(o_rOut, i_sIndexValue );
185 WriteStr(o_rOut, " -> ");
186 WriteStr(o_rOut, i_sIndexReference );
187 WriteStr(o_rOut, "</H3>\n");
189 WriteStr(o_rOut, C_sTableBegin);
190 WriteHeap( o_rOut, i_rHeap, i_eLinkType );
191 WriteStr(o_rOut, C_sTableEnd);
195 void
196 Index::WriteHeap( std::ostream & o_rOut,
197 Heap & i_rHeap,
198 E_LinkType i_eLinkType )
200 static Simstr S_sKey;
201 static char C_sSpaceInName[] = "&nbsp;&nbsp;&nbsp;";
202 S_sKey = "";
205 WriteStr( o_rOut, "<TR><TD width=33% valign=\"top\">" );
207 for ( HeapItem * pHeapTop = i_rHeap.ReleaseTop();
208 pHeapTop != 0;
209 pHeapTop = i_rHeap.ReleaseTop() )
211 if ( S_sKey != pHeapTop->Key() )
213 const char * pStart = pHeapTop->Key().str();
214 const char * pBreak = strstr( pStart, " in ");
216 if (S_sKey.l()>0)
218 WriteStr( o_rOut, "</TD></TR>\n" );
219 WriteStr( o_rOut, "<TR><TD width=33% valign=\"top\">" );
222 if ( pBreak == 0 )
223 WriteStr( o_rOut, pStart );
224 else
226 o_rOut.write( pStart, pBreak - pStart );
227 WriteStr( o_rOut, C_sSpaceInName );
228 WriteStr( o_rOut, pBreak );
230 WriteStr( o_rOut, "</TD><TD width=66%>" );
231 S_sKey = pHeapTop->Key();
233 else
235 WriteStr( o_rOut, "<BR>" );
237 WriteName( o_rOut, sIdlRootPath, pHeapTop->Value(), i_eLinkType );
238 delete pHeapTop;
241 WriteStr( o_rOut, "</TD></TR>\n" );
246 /** Übersicht der Struktur
248 MODULEDESCRIPTION
250 ModuleName,
251 COMPONENTDESCRIPTION
253 Author,
254 Name,
255 Description,
256 LoaderName,
257 Language,
258 Status,
259 SupportedService+,
260 ReferenceDocu*
261 ServiceDependency*
262 Type*
264 ProjectBuildDependency*
265 RuntimeModuleDependency*
266 ReferenceDocu*
267 ServiceDependency*
268 Type*