0
|
1 |
/*
|
|
2 |
* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
package com.nokia.s60tools.apiquery.popup.actions;
|
|
19 |
|
|
20 |
import java.io.BufferedWriter;
|
|
21 |
import java.io.File;
|
|
22 |
import java.io.FileWriter;
|
|
23 |
import java.io.IOException;
|
|
24 |
import java.util.Hashtable;
|
|
25 |
import java.util.Set;
|
|
26 |
import java.util.SortedMap;
|
|
27 |
import java.util.Vector;
|
|
28 |
|
|
29 |
import org.eclipse.core.resources.IFile;
|
|
30 |
import org.eclipse.core.resources.IProject;
|
|
31 |
|
|
32 |
import com.nokia.s60tools.apiquery.servlets.APIQueryWebServerConfigurator;
|
|
33 |
import com.nokia.s60tools.apiquery.servlets.ReportActionConstants;
|
|
34 |
import com.nokia.s60tools.apiquery.settings.UserSettings;
|
|
35 |
import com.nokia.s60tools.apiquery.shared.common.ProductInfoRegistry;
|
|
36 |
import com.nokia.s60tools.apiquery.shared.datatypes.APIDetailField;
|
|
37 |
import com.nokia.s60tools.apiquery.shared.datatypes.APIDetails;
|
|
38 |
import com.nokia.s60tools.apiquery.shared.datatypes.APIQueryParameters;
|
|
39 |
import com.nokia.s60tools.apiquery.shared.plugin.APIQueryPlugin;
|
|
40 |
import com.nokia.s60tools.apiquery.shared.resources.Messages;
|
|
41 |
import com.nokia.s60tools.apiquery.shared.util.console.APIQueryConsole;
|
|
42 |
import com.nokia.s60tools.util.resource.FileUtils;
|
|
43 |
|
|
44 |
/**
|
|
45 |
* Class representing Actice Project API Query report.
|
|
46 |
* Initialize by constructor and ask for HTML or CSV -report.
|
|
47 |
*
|
|
48 |
*/
|
|
49 |
public class CheckProjectReport {
|
|
50 |
|
|
51 |
/**
|
|
52 |
*
|
|
53 |
*/
|
|
54 |
private static final String HTML_WHITE_SPACE = " "; //$NON-NLS-1$
|
|
55 |
|
|
56 |
/**
|
|
57 |
* _
|
|
58 |
*/
|
|
59 |
public static final String UNKNOWN_API_NAME_SEPARATOR = "_"; //$NON-NLS-1$
|
|
60 |
|
|
61 |
/**
|
|
62 |
* Unknown
|
|
63 |
*/
|
|
64 |
public static final String UNKNOWN_API_NAME = Messages.getString("CheckProjectReport.Unknown_MSg"); //$NON-NLS-1$
|
|
65 |
|
|
66 |
/**
|
|
67 |
* API name, Headers which is used from that API
|
|
68 |
*/
|
|
69 |
private final SortedMap<String, Vector<String>> usedHeaders;
|
|
70 |
|
|
71 |
/**
|
|
72 |
* API name, Files which is using that API
|
|
73 |
*/
|
|
74 |
private final Hashtable<String, Vector<IFile>> usingFiles;
|
|
75 |
|
|
76 |
/**
|
|
77 |
* <API Name, API Details> APIs which project is using
|
|
78 |
*/
|
|
79 |
private final Hashtable<String, APIDetails> projectUsingAPIDetails;
|
|
80 |
|
|
81 |
/**
|
|
82 |
* Fields to be added to report from APIDetails besides API Name, Used Headers and Using Files
|
|
83 |
*/
|
|
84 |
String [] apiDetailsToReport = null;
|
|
85 |
|
|
86 |
private final IProject selectedProject;
|
|
87 |
|
|
88 |
|
|
89 |
|
|
90 |
/**
|
|
91 |
*
|
|
92 |
* @param usedHeaders <API name, Headers which is used from that API>
|
|
93 |
* @param usingFiles <API name, Files which is using that API>
|
|
94 |
* @param projectUsingAPIDetails <API Name, API Details> APIs which project is using
|
|
95 |
* @throws IllegalArgumentException if usedHeaders and usingFiles is not same sized or argument is null.
|
|
96 |
*/
|
|
97 |
public CheckProjectReport(SortedMap<String, Vector<String>> usedHeaders,
|
|
98 |
Hashtable<String, Vector<IFile>> usingFiles,
|
|
99 |
Hashtable<String, APIDetails> projectUsingAPIDetails, String [] apiDetailsToReport,
|
|
100 |
IProject selectedProject)
|
|
101 |
throws IllegalArgumentException
|
|
102 |
{
|
|
103 |
if(usedHeaders == null || usingFiles == null || usedHeaders.size() != usingFiles.size()){
|
|
104 |
throw new IllegalArgumentException(
|
|
105 |
Messages.getString("CheckProjectReport.UsedHeader_ErrMsg")); //$NON-NLS-1$
|
|
106 |
}
|
|
107 |
this.usedHeaders = usedHeaders;
|
|
108 |
this.usingFiles = usingFiles;
|
|
109 |
this.projectUsingAPIDetails = projectUsingAPIDetails;
|
|
110 |
this.apiDetailsToReport = apiDetailsToReport;
|
|
111 |
this.selectedProject = selectedProject;
|
|
112 |
|
|
113 |
}
|
|
114 |
|
|
115 |
|
|
116 |
/**
|
|
117 |
* Generating report as HTML format
|
|
118 |
* @param title
|
|
119 |
* @return a report
|
|
120 |
*/
|
|
121 |
public String toHTML(String title) {
|
|
122 |
StringBuffer html = new StringBuffer();
|
|
123 |
//Get API Names from used Headers keys
|
|
124 |
Set <String> apis = usedHeaders.keySet();
|
|
125 |
Vector<String> tmpVect;
|
|
126 |
|
|
127 |
//Add HTML header to report
|
|
128 |
html.append(getHTMLHeader(title));
|
|
129 |
String note = Messages.getString("CheckProjectReport.NoteForReportLinks_Msg"); //$NON-NLS-1$
|
|
130 |
html.append("<p>" + note //$NON-NLS-1$
|
|
131 |
+ "</p>"); //$NON-NLS-1$
|
|
132 |
|
|
133 |
html.append("<table border=\"1\" cellspacing=\"0\" cellpadding=\"1\">"); //$NON-NLS-1$
|
|
134 |
html.append("<tr><th>"); //$NON-NLS-1$
|
|
135 |
html.append(Messages.getString("CheckProjectReport.APIName_Msg")); //$NON-NLS-1$
|
|
136 |
html.append("</th>" ); //$NON-NLS-1$
|
|
137 |
//Adding titles to API Details information
|
|
138 |
for (int i = 0; i < apiDetailsToReport.length; i++) {
|
|
139 |
html.append("<th>"); //$NON-NLS-1$
|
|
140 |
html.append(apiDetailsToReport[i]);
|
|
141 |
html.append("</th>"); //$NON-NLS-1$
|
|
142 |
}
|
|
143 |
|
|
144 |
html.append("<th>");//$NON-NLS-1$
|
|
145 |
html.append(Messages.getString("CheckProjectReport.UsedHeader_Msg")); //$NON-NLS-1$
|
|
146 |
html.append("</th><th>");//$NON-NLS-1$
|
|
147 |
html.append(Messages.getString("CheckProjectReport.UsingFile_Msg")); //$NON-NLS-1$
|
|
148 |
html.append("</th></tr>"); //$NON-NLS-1$
|
|
149 |
html.append("\n"); //$NON-NLS-1$
|
|
150 |
|
|
151 |
String [] detailsToReport ;//For API Details
|
|
152 |
//Add all APIs used in project to report
|
|
153 |
for (String api : apis) {
|
|
154 |
html.append("<tr>"); //$NON-NLS-1$
|
|
155 |
|
|
156 |
tmpVect = usedHeaders.get(api);
|
|
157 |
html.append("<td>"); //$NON-NLS-1$
|
|
158 |
//Adding API Name to html. If details for API could not be found, adding name this.UNKNOWN_API_NAME
|
|
159 |
if(!api.startsWith(UNKNOWN_API_NAME + UNKNOWN_API_NAME_SEPARATOR)){
|
|
160 |
|
|
161 |
//Creating link for launching action to run API Query by API Name
|
|
162 |
html.append("<a href=\"" +getServletURL() +"?" +ReportActionConstants.PARAM_QUERY_FOR //$NON-NLS-1$ //$NON-NLS-2$
|
|
163 |
+"=" +api //$NON-NLS-1$
|
|
164 |
+"&" +ReportActionConstants.ACTION_QUERY_TYPE //$NON-NLS-1$
|
|
165 |
+"=" +APIQueryParameters.QUERY_BY_API_NAME +"\">" +api +"</a>"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
166 |
}
|
|
167 |
//API Is unknown
|
|
168 |
else{
|
|
169 |
html.append("<i>"); //$NON-NLS-1$
|
|
170 |
html.append(UNKNOWN_API_NAME);
|
|
171 |
html.append("</i>"); //$NON-NLS-1$
|
|
172 |
}
|
|
173 |
//Adding API Details to html
|
|
174 |
detailsToReport = getApiDetails(api);
|
|
175 |
for (int i = 0; i < detailsToReport.length; i++) {
|
|
176 |
html.append("<td>"); //$NON-NLS-1$
|
|
177 |
int searchMethodId = UserSettings.getInstance().getCurrentlySelectedSearchMethod().
|
|
178 |
getQueryTypeByAPIDetailNameInDetails(apiDetailsToReport[i]);
|
|
179 |
//If search method is supported
|
|
180 |
if(searchMethodId != -1
|
|
181 |
&& UserSettings.getInstance().getCurrentlySelectedSearchMethod().isSupportedQueryType(searchMethodId)
|
|
182 |
&& !detailsToReport[i].equals(HTML_WHITE_SPACE)){
|
|
183 |
|
|
184 |
String comma = ","; //$NON-NLS-1$
|
|
185 |
String [] items = detailsToReport[i].split(comma);
|
|
186 |
for (int j = 0; j < items.length; j++) {
|
|
187 |
|
|
188 |
//Creating link for launching action to run API Query by a type
|
|
189 |
html.append("<a href=\"" +getServletURL() //$NON-NLS-1$
|
|
190 |
+"?" +ReportActionConstants.PARAM_QUERY_FOR //$NON-NLS-1$
|
|
191 |
+"=" +items[j] //$NON-NLS-1$
|
|
192 |
+"&" +ReportActionConstants.ACTION_QUERY_TYPE //$NON-NLS-1$
|
|
193 |
+"=" +searchMethodId +"\">" +items[j] +"</a>"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
194 |
if(j < (items.length-1)){
|
|
195 |
html.append(comma);
|
|
196 |
}
|
|
197 |
}
|
|
198 |
|
|
199 |
}
|
|
200 |
//If current topic is not supported for API Query
|
|
201 |
else{
|
|
202 |
html.append(detailsToReport[i]);
|
|
203 |
}
|
|
204 |
html.append("</td>\n"); //$NON-NLS-1$
|
|
205 |
}
|
|
206 |
|
|
207 |
html.append("</td>\n<td>"); //$NON-NLS-1$
|
|
208 |
//Adding "used headers" to html
|
|
209 |
for (String header : tmpVect) {
|
|
210 |
//Creating link for launching action to open file
|
|
211 |
html.append("<a href=\"" +getServletURL() //$NON-NLS-1$
|
|
212 |
+"?" +ReportActionConstants.ACTION_OPEN_USED_HEADER //$NON-NLS-1$
|
|
213 |
+"=" +header +getProjectNameParam() +"\">"); //$NON-NLS-1$ //$NON-NLS-2$
|
|
214 |
html.append(header);
|
|
215 |
html.append("</a>"); //$NON-NLS-1$
|
|
216 |
html.append(" "); //$NON-NLS-1$
|
|
217 |
}
|
|
218 |
html.append("</td>\n<td>"); //$NON-NLS-1$
|
|
219 |
Vector<IFile> usingFileTmpVect = usingFiles.get(api);
|
|
220 |
|
|
221 |
Vector<IFile> allreadyAdded = new Vector<IFile>();
|
|
222 |
//Adding "using files" to html
|
|
223 |
for (IFile file : usingFileTmpVect) {
|
|
224 |
//To prevent adding duplicates of same file
|
|
225 |
if(!allreadyAdded.contains(file)){
|
|
226 |
//Creating link for launching action to open file
|
|
227 |
html.append("<a href=\"" +getServletURL() //$NON-NLS-1$
|
|
228 |
+"?" +ReportActionConstants.ACTION_OPEN_USING_FILE //$NON-NLS-1$
|
|
229 |
+"=" +file.getProjectRelativePath().toOSString() +getProjectNameParam() +"\">"); //$NON-NLS-1$ //$NON-NLS-2$
|
|
230 |
html.append(file.getName());
|
|
231 |
html.append("</a>"); //$NON-NLS-1$
|
|
232 |
html.append(" "); //$NON-NLS-1$
|
|
233 |
allreadyAdded.add(file);
|
|
234 |
}
|
|
235 |
|
|
236 |
}
|
|
237 |
html.append("</td>\n</tr>\n"); //$NON-NLS-1$
|
|
238 |
}
|
|
239 |
|
|
240 |
html.append("</table>"); //$NON-NLS-1$
|
|
241 |
html.append("\n"); //$NON-NLS-1$
|
|
242 |
|
|
243 |
|
|
244 |
//Add HTML end tags to report
|
|
245 |
html.append(getHTMLEndTags());
|
|
246 |
return html.toString();
|
|
247 |
}
|
|
248 |
|
|
249 |
private String getProjectNameParam(){
|
|
250 |
return "&" +ReportActionConstants.PARAM_PROJECT_NAME +"=" +selectedProject.getName(); //$NON-NLS-1$ //$NON-NLS-2$
|
|
251 |
}
|
|
252 |
|
|
253 |
/**
|
|
254 |
* Get URL for actio Servlet
|
|
255 |
* @return http://[server]:[port]/[servlet]
|
|
256 |
*/
|
|
257 |
private String getServletURL(){
|
|
258 |
return "http://" +APIQueryWebServerConfigurator.WEB_SERVER_HOST //$NON-NLS-1$
|
|
259 |
+":" +APIQueryWebServerConfigurator.WEB_SERVER_HTTP_PORT //$NON-NLS-1$
|
|
260 |
+"/" +ReportActionConstants.SERVLET_NAME; //$NON-NLS-1$
|
|
261 |
}
|
|
262 |
|
|
263 |
/**
|
|
264 |
* get API Details to report. Founding API_DETAILS_TO_REPORT keys from
|
|
265 |
* projectUsingAPIDetails by api.
|
|
266 |
* @param api
|
|
267 |
* @return
|
|
268 |
*/
|
|
269 |
private String[] getApiDetails(String api){
|
|
270 |
String[] detailsToReport = new String [apiDetailsToReport.length];
|
|
271 |
APIDetails details = projectUsingAPIDetails.get(api);
|
|
272 |
if(details != null){
|
|
273 |
APIDetailField field;
|
|
274 |
for (int i = 0; i < apiDetailsToReport.length; i++) {
|
|
275 |
field = details.getDetail(apiDetailsToReport[i]);
|
|
276 |
//To fill up empty HTML table columns, adding an white space ( )
|
|
277 |
//to detail where is no real data. This looks bettre in UI (HTML report)
|
|
278 |
if(field.getValue() != null && !field.getValue().trim().equals("")){ //$NON-NLS-1$
|
|
279 |
detailsToReport[i] = field.getValue();
|
|
280 |
}
|
|
281 |
//To avoid HTML table different behavior with empty slots, putting a white space to emtpy slots
|
|
282 |
else{
|
|
283 |
detailsToReport[i] = HTML_WHITE_SPACE;
|
|
284 |
}
|
|
285 |
}
|
|
286 |
}
|
|
287 |
else {
|
|
288 |
//To avoid HTML table different behavior with empty slots, putting a white space to emtpy slots
|
|
289 |
for (int i = 0; i < apiDetailsToReport.length; i++) {
|
|
290 |
detailsToReport[i] = HTML_WHITE_SPACE;
|
|
291 |
}
|
|
292 |
}
|
|
293 |
return detailsToReport;
|
|
294 |
}
|
|
295 |
|
|
296 |
/**
|
|
297 |
*
|
|
298 |
* Not implemented.
|
|
299 |
*
|
|
300 |
* Generate report in CSV format.
|
|
301 |
* @return <code>null</code>
|
|
302 |
*/
|
|
303 |
public String toCSV() {
|
|
304 |
//Not implemented
|
|
305 |
return null;
|
|
306 |
}
|
|
307 |
|
|
308 |
/**
|
|
309 |
* Writes this.toHTML() to file
|
|
310 |
* @param title
|
|
311 |
* @param fileName
|
|
312 |
*/
|
|
313 |
public void toHTMLFile(String title, String fileName ) {
|
|
314 |
|
|
315 |
try {
|
|
316 |
BufferedWriter out = new BufferedWriter(new FileWriter(
|
|
317 |
fileName));
|
|
318 |
out.write(toHTML(title));
|
|
319 |
out.close();
|
|
320 |
} catch (IOException e) {
|
|
321 |
e.printStackTrace();
|
|
322 |
}
|
|
323 |
}
|
|
324 |
/**
|
|
325 |
*
|
|
326 |
* Not implemented until {@link #toCSV()} is implemented.
|
|
327 |
*
|
|
328 |
* Writes this.toCSV() to file
|
|
329 |
* @param title
|
|
330 |
* @param fileName
|
|
331 |
*/
|
|
332 |
public void toCSVFile(String title, String fileName ) {
|
|
333 |
|
|
334 |
try {
|
|
335 |
BufferedWriter out = new BufferedWriter(new FileWriter(
|
|
336 |
fileName));
|
|
337 |
out.write(toCSV());
|
|
338 |
out.close();
|
|
339 |
} catch (IOException e) {
|
|
340 |
e.printStackTrace();
|
|
341 |
}
|
|
342 |
}
|
|
343 |
|
|
344 |
/**
|
|
345 |
* generating html header and opening body and adding title to it
|
|
346 |
* @param title
|
|
347 |
* @return
|
|
348 |
*/
|
|
349 |
private StringBuffer getHTMLHeader(String title){
|
|
350 |
StringBuffer b = new StringBuffer();
|
|
351 |
b.append("<html><head><title>"); //$NON-NLS-1$
|
|
352 |
b.append(title);
|
|
353 |
b.append("</title>\n"); //$NON-NLS-1$
|
|
354 |
b.append(getHTMLStyles());
|
|
355 |
|
|
356 |
b.append("\n</head><body>\n"); //$NON-NLS-1$
|
|
357 |
b.append("<h1>"); //$NON-NLS-1$
|
|
358 |
b.append(title);
|
|
359 |
b.append("</h1>\n"); //$NON-NLS-1$
|
|
360 |
return b;
|
|
361 |
}
|
|
362 |
/**
|
|
363 |
* get body and html end tags
|
|
364 |
* @return
|
|
365 |
*/
|
|
366 |
private StringBuffer getHTMLEndTags(){
|
|
367 |
StringBuffer b = new StringBuffer();
|
|
368 |
b.append("</body></html>"); //$NON-NLS-1$
|
|
369 |
return b;
|
|
370 |
}
|
|
371 |
/**
|
|
372 |
* get HTML style sheet
|
|
373 |
* @return styles
|
|
374 |
*/
|
|
375 |
private StringBuffer getHTMLStyles(){
|
|
376 |
|
|
377 |
String cssPath = null;
|
|
378 |
|
|
379 |
try {
|
|
380 |
//Get location for stylesheet file
|
|
381 |
cssPath = APIQueryPlugin.getDefault().getPluginInstallPath() +
|
|
382 |
File.separatorChar + ProductInfoRegistry.getResourcesRelativePath()
|
|
383 |
+File.separatorChar + ProductInfoRegistry.getReportCSSFileName();
|
|
384 |
//return contents of the stylesheet file
|
|
385 |
return FileUtils.loadDataFromFile(cssPath);
|
|
386 |
} catch (Exception e) {
|
|
387 |
//FileNotFoundException or IOException may occur
|
|
388 |
e.printStackTrace();
|
|
389 |
APIQueryConsole.getInstance().println(
|
|
390 |
Messages.getString("CheckProjectReport.UnableToLoadCSS_Part1_ErrMsg") +cssPath +Messages.getString("CheckProjectReport.UnableToLoadCSS_Part2_ErrMsg") +e, //$NON-NLS-1$ //$NON-NLS-2$
|
|
391 |
APIQueryConsole.MSG_ERROR);
|
|
392 |
//If there was an error, returning dummy (hard coded) styles
|
|
393 |
return getDummyCSS();
|
|
394 |
}
|
|
395 |
|
|
396 |
}
|
|
397 |
|
|
398 |
/**
|
|
399 |
* If there is something wrong, hard coded styles can be used
|
|
400 |
* @return dummy styles
|
|
401 |
*/
|
|
402 |
private StringBuffer getDummyCSS() {
|
|
403 |
StringBuffer b = new StringBuffer();
|
|
404 |
b.append("<style type=\"text/css\">"); //$NON-NLS-1$
|
|
405 |
b.append("body {background-color: white; font-family: Verdana; font-size: 10px; }"); //$NON-NLS-1$
|
|
406 |
b.append("p { font-family=\"Verdana\"; font-size: 10px; }"); //$NON-NLS-1$
|
|
407 |
b.append("td { font-family=\"Verdana\"; font-size: 10px; text-align: left; }"); //$NON-NLS-1$
|
|
408 |
b.append("th { font-family=\"Verdana\"; font-size: 10px; font-weight: bold; text-align: left; }"); //$NON-NLS-1$
|
|
409 |
b.append("dt { font-family=\"Verdana\"; font-size: 10px; font-weight: normal text-align: left; }"); //$NON-NLS-1$
|
|
410 |
b.append("h1 { font-family=\"Verdana\"; font-size: 18px; }"); //$NON-NLS-1$
|
|
411 |
b.append("</style>"); //$NON-NLS-1$
|
|
412 |
return b;
|
|
413 |
}
|
|
414 |
|
|
415 |
}
|