xref: /trunk/main/xml2cmp/source/xcd/cr_index.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 
29 #include "cr_index.hxx"
30 
31 #include <string.h>
32 #include <fstream>
33 #include "../support/syshelp.hxx"
34 #include "xmltree.hxx"
35 #include "parse.hxx"
36 #include "cr_html.hxx"
37 
38 
39 extern unsigned C_nSupportedServicesIndex;
40 
41 char C_sLineEnd[] = "\n";
42 
43 char C_sFileBegin[]     = "<HTML><HEAD></HEAD><BODY bgcolor=\"#ffffff\">\n";
44 char C_sFileEnd[]       = "</BODY></HTML>\n";
45 char C_sTableBegin[]    = "<TABLE WIDTH=100% BORDER=1 CELLPADDING=4 CELLSPACING=0><TBODY>\n";
46 char C_sTableEnd[]      = "</TBODY></TABLE>\n";
47 char C_sService[]       = "SupportedService";
48 char C_sModule[]        = "ModuleName";
49 char C_sComponentname[] = "ComponentName";
50 
51 
52 
53 Simstr sIdlRootPath;
54 
55 
56 Index::Index( const char *          i_sOutputDirectory,
57               const char *          i_sIdlRootPath,
58               const List<Simstr> &   )
59     :   aService2Module(20),
60         aModule2Service(20),
61         sOutputDirectory(i_sOutputDirectory),
62         sIdlRootPath(i_sIdlRootPath)
63         // sCurModule
64 {
65     ::sIdlRootPath = i_sIdlRootPath;
66 }
67 
68 Index::~Index()
69 {
70 }
71 
72 void
73 Index::GatherData(  const List<Simstr> & i_rInputFileList )
74 {
75     for ( unsigned i = 0; i < i_rInputFileList.size(); ++i )
76     {
77         ReadFile( i_rInputFileList[i].str() );
78     }
79 }
80 
81 void
82 Index::WriteOutput( const char * i_sOuputFile )
83 {
84     std::ofstream aOut( i_sOuputFile, std::ios::out );
85     if (! aOut)
86     {
87         std::cerr << "Error: Indexfile \""
88              << i_sOuputFile
89              << "\" could not be created."
90              << std::endl;
91         return;
92     }
93 
94     WriteStr(aOut, C_sFileBegin);
95 
96     WriteStr(aOut, "<H2>Module Descriptions Index</H2>");
97     WriteStr(aOut, C_sLineEnd );
98 
99 
100     WriteTableFromHeap( aOut, aService2Module, C_sService, C_sModule, lt_html );
101     WriteTableFromHeap( aOut, aModule2Service, C_sModule, C_sService, lt_idl );
102 
103     WriteStr( aOut, C_sFileEnd );
104     aOut.close();
105 }
106 
107 void
108 Index::InsertSupportedService( const Simstr &       i_sService )
109 {
110     aService2Module.InsertValue( i_sService, sCurModule );
111     aModule2Service.InsertValue( sCurModule, i_sService );
112 }
113 
114 void
115 Index::ReadFile(  const char * i_sFilename )
116 {
117     static char             sOutputHtml[1020];
118 
119     ModuleDescription   aModule;
120     X2CParser           aParser(aModule);
121 
122     // Parse
123     bool bResult = aParser.Parse(i_sFilename);
124     if (! bResult)
125     {
126         std::cerr << "Error: File \""
127              << i_sFilename
128              << "\" could not be parsed."
129              << std::endl;
130         return;
131     }
132 
133     // Create Html:
134     CreateHtmlFileName( sOutputHtml, aModule );
135     HtmlCreator     aHtmlCreator( sOutputHtml, aModule, sIdlRootPath );
136     aHtmlCreator.Run();
137 
138     // GetResults:
139     sCurModule = aModule.ModuleName();
140 
141     List< const MultipleTextElement* > aSupportedServices;
142     aModule.Get_SupportedServices(aSupportedServices);
143 
144     for ( unsigned s = 0; s < aSupportedServices.size(); ++s )
145     {
146         aSupportedServices[s]->Insert2Index(*this);
147     }
148 }
149 
150 void
151 Index::CreateHtmlFileName(  char *                      o_sOutputHtml,
152                             const ModuleDescription &   i_rModule )
153 {
154     if ( strlen(sOutputDirectory.str()) + strlen(i_rModule.ModuleName()) > 1000 )
155     {
156         strcpy( o_sOutputHtml, "too-long-filename.html");   // STRCPY SAFE HERE
157         return;
158     }
159 
160     strcpy( o_sOutputHtml, sOutputDirectory.str() );        // STRCPY SAFE HERE
161 #if defined(WNT) || defined(OS2)
162     strcat(o_sOutputHtml, "\\");                            // STRCAT SAFE HERE
163 #elif defined(UNX)
164     strcat(o_sOutputHtml, "/");                             // STRCAT SAFE HERE
165 #else
166 #error  WNT or UNX have to be defined.
167 #endif
168     strcat( o_sOutputHtml, i_rModule.ModuleName() );        // STRCAT SAFE HERE
169     strcat( o_sOutputHtml, ".html" );                       // STRCAT SAFE HERE
170 }
171 
172 
173 void
174 Index::WriteTableFromHeap( std::ostream &   o_rOut,
175                            Heap &       i_rHeap,
176                            const char * i_sIndexValue,
177                            const char * i_sIndexReference,
178                            E_LinkType       i_eLinkType )
179 {
180     WriteStr(o_rOut, "<H3><BR>");
181     WriteStr(o_rOut, i_sIndexValue );
182     WriteStr(o_rOut, " -> ");
183     WriteStr(o_rOut, i_sIndexReference );
184     WriteStr(o_rOut, "</H3>\n");
185 
186     WriteStr(o_rOut, C_sTableBegin);
187     WriteHeap( o_rOut, i_rHeap, i_eLinkType );
188     WriteStr(o_rOut, C_sTableEnd);
189 }
190 
191 
192 void
193 Index::WriteHeap( std::ostream &    o_rOut,
194                   Heap &        i_rHeap,
195                   E_LinkType    i_eLinkType )
196 {
197     static Simstr S_sKey;
198     static char C_sSpaceInName[] = "&nbsp;&nbsp;&nbsp;";
199     S_sKey = "";
200 
201 
202     WriteStr( o_rOut, "<TR><TD width=33% valign=\"top\">" );
203 
204     for ( HeapItem * pHeapTop = i_rHeap.ReleaseTop();
205           pHeapTop != 0;
206           pHeapTop = i_rHeap.ReleaseTop() )
207     {
208         if ( S_sKey != pHeapTop->Key() )
209         {
210             const char * pStart = pHeapTop->Key().str();
211             const char * pBreak = strstr( pStart, " in ");
212 
213             if (S_sKey.l()>0)
214             {
215                 WriteStr( o_rOut, "</TD></TR>\n" );
216                 WriteStr( o_rOut, "<TR><TD width=33% valign=\"top\">" );
217             }
218 
219             if ( pBreak == 0 )
220                 WriteStr( o_rOut, pStart );
221             else
222             {
223                 o_rOut.write( pStart, pBreak - pStart );
224                 WriteStr( o_rOut, C_sSpaceInName );
225                 WriteStr( o_rOut, pBreak );
226             }
227             WriteStr( o_rOut, "</TD><TD width=66%>" );
228             S_sKey = pHeapTop->Key();
229         }
230         else
231         {
232             WriteStr( o_rOut, "<BR>" );
233         }
234         WriteName( o_rOut, sIdlRootPath, pHeapTop->Value(), i_eLinkType );
235         delete pHeapTop;
236     }
237 
238     WriteStr( o_rOut, "</TD></TR>\n" );
239 }
240 
241 
242 
243 /** �bersicht der Struktur
244 
245 MODULEDESCRIPTION
246 {
247     ModuleName,
248     COMPONENTDESCRIPTION
249     {
250         Author,
251         Name,
252         Description,
253         LoaderName,
254         Language,
255         Status,
256         SupportedService+,
257         ReferenceDocu*
258         ServiceDependency*
259         Type*
260     }
261     ProjectBuildDependency*
262     RuntimeModuleDependency*
263     ReferenceDocu*
264     ServiceDependency*
265     Type*
266 }
267 
268 
269 */
270 
271 
272 
273 
274 
275 
276