001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU General
007: * Public License Version 2 only ("GPL") or the Common Development and Distribution
008: * License("CDDL") (collectively, the "License"). You may not use this file except in
009: * compliance with the License. You can obtain a copy of the License at
010: * http://www.netbeans.org/cddl-gplv2.html or nbbuild/licenses/CDDL-GPL-2-CP. See the
011: * License for the specific language governing permissions and limitations under the
012: * License. When distributing the software, include this License Header Notice in
013: * each file and include the License file at nbbuild/licenses/CDDL-GPL-2-CP. Sun
014: * designates this particular file as subject to the "Classpath" exception as
015: * provided by Sun in the GPL Version 2 section of the License file that
016: * accompanied this code. If applicable, add the following below the License Header,
017: * with the fields enclosed by brackets [] replaced by your own identifying
018: * information: "Portions Copyrighted [year] [name of copyright owner]"
019: *
020: * Contributor(s):
021: *
022: * The Original Software is NetBeans. The Initial Developer of the Original Software
023: * is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun Microsystems, Inc. All
024: * Rights Reserved.
025: *
026: * If you wish your version of this file to be governed by only the CDDL or only the
027: * GPL Version 2, indicate your decision by adding "[Contributor] elects to include
028: * this software in this distribution under the [CDDL or GPL Version 2] license." If
029: * you do not indicate a single choice of license, a recipient has the option to
030: * distribute your version of this file under either the CDDL, the GPL Version 2 or
031: * to extend the choice of license to its licensees as provided above. However, if
032: * you add GPL Version 2 code and therefore, elected the GPL Version 2 license, then
033: * the option applies only if the new code is made subject to such option by the
034: * copyright holder.
035: */
036:
037: package org.netbeans.installer.infra.server.client.servlets;
038:
039: import java.io.IOException;
040: import java.io.PrintWriter;
041: import java.util.Arrays;
042: import java.util.HashMap;
043: import java.util.LinkedList;
044: import java.util.List;
045: import java.util.Map;
046: import javax.ejb.EJB;
047: import javax.servlet.ServletException;
048: import javax.servlet.http.HttpServlet;
049: import javax.servlet.http.HttpServletRequest;
050: import javax.servlet.http.HttpServletResponse;
051: import org.netbeans.installer.infra.server.ejb.Manager;
052: import org.netbeans.installer.infra.server.ejb.ManagerException;
053: import org.netbeans.installer.product.Registry;
054: import org.netbeans.installer.product.RegistryNode;
055: import org.netbeans.installer.product.components.Group;
056: import org.netbeans.installer.product.components.Product;
057: import org.netbeans.installer.utils.helper.Platform;
058:
059: public class Components2 extends HttpServlet {
060: @EJB
061: private Manager manager;
062:
063: protected void doGet(HttpServletRequest request,
064: HttpServletResponse response) throws ServletException,
065: IOException {
066: final List<String> java = Arrays.asList("nb-platform",
067: "nb-base", "nb-javase");
068: final List<String> javaee = Arrays.asList("nb-platform",
069: "nb-base", "nb-javase", "nb-javaee", "glassfish",
070: "tomcat", "sjsas");
071: final List<String> javame = Arrays.asList("nb-platform",
072: "nb-base", "nb-javase", "nb-javame");
073: final List<String> ruby = Arrays.asList("nb-platform",
074: "nb-base", "nb-ruby");
075: final List<String> cnd = Arrays.asList("nb-platform",
076: "nb-base", "nb-cnd");
077:
078: final List<String> full = Arrays.asList("nb-platform",
079: "nb-base", "nb-javase", "nb-javaee", "nb-javame",
080: "nb-cnd", "nb-soa", "nb-uml", "nb-ruby", "nb-php",
081: "glassfish", "openesb", "sjsam", "tomcat", "sjsas");
082: final List<String> hidden = Arrays.asList("nb-platform",
083: //"nb-base",
084: "openesb", "sjsam");
085: final Map<String, String> notes = new HashMap<String, String>();
086: //notes.put("nb-javase", "for Java SE, includes GUI Builder, Profiler");
087:
088: try {
089: response.setContentType("text/javascript; charset=UTF-8");
090: final PrintWriter out = response.getWriter();
091:
092: final Registry registry = manager.loadRegistry("NetBeans");
093:
094: final List<Product> products = getProducts(registry
095: .getRegistryRoot());
096: final List<Group> groups = getGroups(registry
097: .getRegistryRoot());
098:
099: final Map<Integer, Integer> productMapping = new HashMap<Integer, Integer>();
100:
101: final List<String> productUids = new LinkedList<String>();
102: final List<String> productVersions = new LinkedList<String>();
103: final List<String> productDisplayNames = new LinkedList<String>();
104: final List<String> productNotes = new LinkedList<String>();
105: final List<String> productDescriptions = new LinkedList<String>();
106: final List<String> productDownloadSizes = new LinkedList<String>();
107: final List<List<Platform>> productPlatforms = new LinkedList<List<Platform>>();
108: final List<String> productProperties = new LinkedList<String>();
109:
110: final List<Integer> defaultGroupProducts = new LinkedList<Integer>();
111: final List<List<Integer>> groupProducts = new LinkedList<List<Integer>>();
112: final List<String> groupDisplayNames = new LinkedList<String>();
113: final List<String> groupDescriptions = new LinkedList<String>();
114:
115: for (int i = 0; i < products.size(); i++) {
116: final Product product = products.get(i);
117:
118: boolean existingFound = false;
119: for (int j = 0; j < productUids.size(); j++) {
120: if (productUids.get(j).equals(product.getUid())
121: && productVersions.get(j).equals(
122: product.getVersion().toString())) {
123: productPlatforms.get(j).addAll(
124: product.getPlatforms());
125: productMapping.put(i, j);
126: existingFound = true;
127: break;
128: }
129: }
130:
131: if (existingFound) {
132: continue;
133: }
134:
135: long size = (long) Math.ceil(((double) product
136: .getDownloadSize()) / 1024.);
137: productUids.add(product.getUid());
138: productVersions.add(product.getVersion().toString());
139: productDisplayNames.add(product.getDisplayName()
140: .replace("\"", "\\\"").replaceAll("\r\n|\r|\n",
141: "\\\n"));
142: productDescriptions.add(product.getDescription()
143: .replace("\"", "\\\"").replaceAll("\r\n|\r|\n",
144: "\\\n"));
145: productDownloadSizes.add(Long.toString(size));
146: productPlatforms.add(product.getPlatforms());
147:
148: if (notes.get(product.getUid()) != null) {
149: productNotes.add(notes.get(product.getUid())
150: .replace("\"", "\\\"").replaceAll(
151: "\r\n|\r|\n", "\\\n"));
152: } else {
153: productNotes.add("");
154: }
155:
156: String properties = "PROPERTY_NONE";
157: if (java.contains(product.getUid())) {
158: properties += " | PROPERTY_JAVA";
159: }
160: if (javaee.contains(product.getUid())) {
161: properties += " | PROPERTY_JAVAEE";
162: }
163: if (javame.contains(product.getUid())) {
164: properties += " | PROPERTY_JAVAME";
165: }
166: if (ruby.contains(product.getUid())) {
167: properties += " | PROPERTY_RUBY";
168: }
169: if (cnd.contains(product.getUid())) {
170: properties += " | PROPERTY_CND";
171: }
172: if (full.contains(product.getUid())) {
173: properties += " | PROPERTY_FULL";
174: }
175: if (hidden.contains(product.getUid())) {
176: properties += " | PROPERTY_HIDDEN";
177: }
178: productProperties.add(properties);
179:
180: productMapping.put(i, productUids.size() - 1);
181: }
182:
183: out.println("product_uids = new Array();");
184: for (int i = 0; i < productUids.size(); i++) {
185: out.println(" product_uids[" + i + "] = \""
186: + productUids.get(i) + "\";");
187: }
188: out.println();
189:
190: out.println("product_versions = new Array();");
191: for (int i = 0; i < productVersions.size(); i++) {
192: out.println(" product_versions[" + i + "] = \""
193: + productVersions.get(i) + "\";");
194: }
195: out.println();
196:
197: out.println("product_display_names = new Array();");
198: for (int i = 0; i < productDisplayNames.size(); i++) {
199: out.println(" product_display_names[" + i + "] = \""
200: + productDisplayNames.get(i) + "\";");
201: }
202: out.println();
203:
204: out.println("product_notes = new Array();");
205: for (int i = 0; i < productNotes.size(); i++) {
206: out.println(" product_notes[" + i + "] = \""
207: + productNotes.get(i) + "\";");
208: }
209: out.println();
210:
211: out.println("product_descriptions = new Array();");
212: for (int i = 0; i < productDescriptions.size(); i++) {
213: out.println(" product_descriptions[" + i + "] = \""
214: + productDescriptions.get(i) + "\";");
215: }
216: out.println();
217:
218: out.println("product_download_sizes = new Array();");
219: for (int i = 0; i < productDownloadSizes.size(); i++) {
220: out.println(" product_download_sizes[" + i + "] = "
221: + productDownloadSizes.get(i) + ";");
222: }
223: out.println();
224:
225: out.println("product_platforms = new Array();");
226: for (int i = 0; i < productPlatforms.size(); i++) {
227: out.println(" product_platforms[" + i
228: + "] = new Array();");
229: for (int j = 0; j < productPlatforms.get(i).size(); j++) {
230: out.println(" product_platforms[" + i + "]["
231: + j + "] = \""
232: + productPlatforms.get(i).get(j) + "\";");
233: }
234: }
235: out.println();
236:
237: out.println("product_properties = new Array();");
238: for (int i = 0; i < productProperties.size(); i++) {
239: out.println(" product_properties[" + i + "] = "
240: + productProperties.get(i) + ";");
241: }
242: out.println();
243:
244: for (int i = 0; i < productUids.size(); i++) {
245: defaultGroupProducts.add(Integer.valueOf(i));
246: }
247:
248: for (Group group : groups) {
249: List<Integer> components = new LinkedList<Integer>();
250: for (int i = 0; i < products.size(); i++) {
251: if (products.get(i).getParent().equals(group)) {
252: Integer index = Integer.valueOf(productMapping
253: .get(i));
254: if (!components.contains(index)) {
255: components.add(index);
256: defaultGroupProducts.remove(index);
257: }
258: }
259: }
260:
261: groupProducts.add(components);
262: groupDisplayNames.add(group.getDisplayName().replace(
263: "\"", "\\\"").replaceAll("\r\n|\r|\n", "\\\n"));
264: groupDescriptions.add(group.getDescription().replace(
265: "\"", "\\\"").replaceAll("\r\n|\r|\n", "\\\n"));
266: }
267:
268: if (defaultGroupProducts.size() > 0) {
269: groupProducts.add(0, defaultGroupProducts);
270: groupDisplayNames.add(0, "");
271: groupDescriptions.add(0, "");
272: }
273:
274: out.println("group_products = new Array();");
275: for (int i = 0; i < groupProducts.size(); i++) {
276: out.println(" group_products[" + i
277: + "] = new Array();");
278: for (int j = 0; j < groupProducts.get(i).size(); j++) {
279: out.println(" group_products[" + i + "]["
280: + j + "] = " + groupProducts.get(i).get(j)
281: + ";");
282: }
283: }
284: out.println();
285:
286: out.println("group_display_names = new Array();");
287: for (int i = 0; i < groupDisplayNames.size(); i++) {
288: out.println(" group_display_names[" + i + "] = \""
289: + groupDisplayNames.get(i) + "\";");
290: }
291: out.println();
292:
293: out.println("group_descriptions = new Array();");
294: for (int i = 0; i < groupDescriptions.size(); i++) {
295: out.println(" group_descriptions[" + i + "] = \""
296: + groupDescriptions.get(i) + "\";");
297: }
298: out.println();
299:
300: out.close();
301: } catch (ManagerException e) {
302: e.printStackTrace();
303: } catch (IOException e) {
304: e.printStackTrace();
305: }
306: }
307:
308: private List<Product> getProducts(RegistryNode root) {
309: final List<Product> list = new LinkedList<Product>();
310:
311: for (RegistryNode node : root.getChildren()) {
312: if (node instanceof Product) {
313: list.add((Product) node);
314: }
315:
316: list.addAll(getProducts(node));
317: }
318:
319: return list;
320: }
321:
322: private List<Group> getGroups(RegistryNode root) {
323: final List<Group> list = new LinkedList<Group>();
324:
325: for (RegistryNode node : root.getChildren()) {
326: if (node instanceof Group) {
327: list.add((Group) node);
328: }
329:
330: list.addAll(getGroups(node));
331: }
332:
333: return list;
334: }
335: }
|