0
|
1 |
/*
|
|
2 |
* Copyright (c) 2006 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.appdep.export;
|
|
19 |
|
|
20 |
import java.io.BufferedWriter;
|
|
21 |
import java.io.FileWriter;
|
|
22 |
import java.io.IOException;
|
|
23 |
import java.util.ArrayList;
|
|
24 |
import java.util.Iterator;
|
|
25 |
|
|
26 |
import com.nokia.s60tools.appdep.core.model.ComponentPropertiesData;
|
|
27 |
import com.nokia.s60tools.appdep.ui.views.data.PropertyData;
|
|
28 |
|
|
29 |
/**
|
|
30 |
* Represents the XML report data selected from "is used by" -view with "Export report..." functionality.
|
|
31 |
*/
|
|
32 |
public class IsUsedByXMLReport {
|
|
33 |
|
|
34 |
/**
|
|
35 |
* Data to be converted into XML.
|
|
36 |
*/
|
|
37 |
ArrayList<ComponentPropertiesData> isUsedByData;
|
|
38 |
/**
|
|
39 |
* SDK the data is got from.
|
|
40 |
*/
|
|
41 |
private String sdkName;
|
|
42 |
/**
|
|
43 |
* Targets the data is got from.
|
|
44 |
*/
|
|
45 |
private String targets;
|
|
46 |
/**
|
|
47 |
* Build type the data is got from.
|
|
48 |
*/
|
|
49 |
private String build;
|
|
50 |
/**
|
|
51 |
* Component or functions the 'is used by'-relation is asked for.
|
|
52 |
*/
|
|
53 |
private String usingComponentOrFunction;
|
|
54 |
/**
|
|
55 |
* Sort criteria used in the component list -view used to show
|
|
56 |
* 'is used by'-relation data, and from which query for XML representation
|
|
57 |
* is started from.
|
|
58 |
*/
|
|
59 |
private int sortCriteria;
|
|
60 |
|
|
61 |
/**
|
|
62 |
* Constructor.
|
|
63 |
* @param isUsedByData Data to be converted into XML
|
|
64 |
* @param sdkName SDK the data is got from
|
|
65 |
* @param targets Targets the data is got from.
|
|
66 |
* @param build Build type the data is got from.
|
|
67 |
* @param usingComponentOrFunction Component or functions the 'is used by'-relation is asked for.
|
|
68 |
* @param sortCriteria Sort criteria used in the component list -view used to show
|
|
69 |
* 'is used by'-relation data, and from which query for XML representation
|
|
70 |
* is started from.
|
|
71 |
*/
|
|
72 |
public IsUsedByXMLReport(ArrayList<ComponentPropertiesData> isUsedByData, String sdkName, String targets, String build, String usingComponentOrFunction, int sortCriteria) {
|
|
73 |
this.isUsedByData = isUsedByData;
|
|
74 |
this.sdkName = sdkName;
|
|
75 |
this.targets = targets;
|
|
76 |
this.build = build;
|
|
77 |
this.usingComponentOrFunction = usingComponentOrFunction;
|
|
78 |
this.sortCriteria = sortCriteria;
|
|
79 |
}
|
|
80 |
|
|
81 |
/**
|
|
82 |
* Gets component properties for the export report functionality.
|
|
83 |
* @return component properties for the export report functionality.
|
|
84 |
*/
|
|
85 |
private StringBuffer getExportProperties(){
|
|
86 |
|
|
87 |
StringBuffer b = new StringBuffer ();
|
|
88 |
|
|
89 |
ComponentPropertiesData data;
|
|
90 |
Iterator<ComponentPropertiesData> it = isUsedByData.iterator();
|
|
91 |
while(it.hasNext()){
|
|
92 |
data = it.next();
|
|
93 |
PropertyData [] props = data.toPropertyDataArray();
|
|
94 |
b.append("<isUsedBy>\n"); //$NON-NLS-1$
|
|
95 |
for(int i = 0; i<props.length; i++){
|
|
96 |
PropertyData prop = props[i];
|
|
97 |
b.append("<"); //$NON-NLS-1$
|
|
98 |
b.append(StringUtils.replace(prop.getPropertyDescription()," ", "_" )); //$NON-NLS-1$ //$NON-NLS-2$
|
|
99 |
b.append(">"); //$NON-NLS-1$
|
|
100 |
b.append(prop.getPropertyValue());
|
|
101 |
b.append("</"); //$NON-NLS-1$
|
|
102 |
b.append(StringUtils.replace(prop.getPropertyDescription()," ", "_" )); //$NON-NLS-1$ //$NON-NLS-2$
|
|
103 |
b.append(">\n"); //$NON-NLS-1$
|
|
104 |
|
|
105 |
}
|
|
106 |
b.append("</isUsedBy>\n"); //$NON-NLS-1$
|
|
107 |
}
|
|
108 |
|
|
109 |
return b;
|
|
110 |
}
|
|
111 |
|
|
112 |
/* (non-Javadoc)
|
|
113 |
* @see java.lang.Object#toString()
|
|
114 |
*/
|
|
115 |
public String toString(){
|
|
116 |
|
|
117 |
StringBuffer b = new StringBuffer();
|
|
118 |
|
|
119 |
//*********************************************************************
|
|
120 |
//Header
|
|
121 |
//*********************************************************************
|
|
122 |
|
|
123 |
// href=\"printReport.xsl\"
|
|
124 |
b.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><?xml-stylesheet type=\"text/xsl\" ?>"); //$NON-NLS-1$
|
|
125 |
b.append("\n<report>\n"); //$NON-NLS-1$
|
|
126 |
b.append("<info><sdk name=\""); //$NON-NLS-1$
|
|
127 |
b.append(this.sdkName);
|
|
128 |
b.append("\" target=\""); //$NON-NLS-1$
|
|
129 |
b.append(this.targets);
|
|
130 |
b.append("\" build=\""); //$NON-NLS-1$
|
|
131 |
b.append(this.build);
|
|
132 |
b.append("\"/></info>"); //$NON-NLS-1$
|
|
133 |
b.append("\n"); //$NON-NLS-1$
|
|
134 |
|
|
135 |
b.append("\n"); //$NON-NLS-1$
|
|
136 |
b.append("<isUsedByData>"); //$NON-NLS-1$
|
|
137 |
b.append("\n"); //$NON-NLS-1$
|
|
138 |
b.append("<component name=\""); //$NON-NLS-1$
|
|
139 |
b.append(usingComponentOrFunction);
|
|
140 |
b.append("\" sortCriteria= \""); //$NON-NLS-1$
|
|
141 |
b.append(sortCriteria);
|
|
142 |
b.append("\">\n"); //$NON-NLS-1$
|
|
143 |
|
|
144 |
b.append(getExportProperties());
|
|
145 |
|
|
146 |
b.append("\n"); //$NON-NLS-1$
|
|
147 |
b.append("</component>"); //$NON-NLS-1$
|
|
148 |
b.append("</isUsedByData>"); //$NON-NLS-1$
|
|
149 |
b.append("\n"); //$NON-NLS-1$
|
|
150 |
b.append("</report>"); //$NON-NLS-1$
|
|
151 |
b.append("\n"); //$NON-NLS-1$
|
|
152 |
return b.toString();
|
|
153 |
}
|
|
154 |
|
|
155 |
/**
|
|
156 |
* Write data as XML into given destination file.
|
|
157 |
* @param fileName Destination file.
|
|
158 |
*/
|
|
159 |
public void toFile( String fileName ) {
|
|
160 |
|
|
161 |
try {
|
|
162 |
BufferedWriter out = new BufferedWriter(new FileWriter(
|
|
163 |
fileName));
|
|
164 |
out.write(toString());
|
|
165 |
out.close();
|
|
166 |
} catch (IOException e) {
|
|
167 |
e.printStackTrace();
|
|
168 |
}
|
|
169 |
}
|
|
170 |
|
|
171 |
}
|