KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > about > AboutBundleGroupData


1 /*******************************************************************************
2  * Copyright (c) 2004, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal.about;
12
13 import java.io.IOException JavaDoc;
14 import java.io.InputStream JavaDoc;
15 import java.net.URL JavaDoc;
16 import java.util.zip.CRC32 JavaDoc;
17 import java.util.zip.CheckedInputStream JavaDoc;
18
19 import org.eclipse.core.runtime.IBundleGroup;
20 import org.eclipse.jface.resource.ImageDescriptor;
21 import org.eclipse.ui.branding.IBundleGroupConstants;
22
23 /**
24  * A small class to manage the information related to IBundleGroup's.
25  * @since 3.0
26  */

27 public class AboutBundleGroupData extends AboutData {
28     private IBundleGroup bundleGroup;
29
30     private URL JavaDoc licenseUrl;
31
32     private URL JavaDoc featureImageUrl;
33
34     private Long JavaDoc featureImageCrc;
35
36     private ImageDescriptor featureImage;
37
38     public AboutBundleGroupData(IBundleGroup bundleGroup) {
39         super(bundleGroup.getProviderName(), bundleGroup.getName(), bundleGroup
40                 .getVersion(), bundleGroup.getIdentifier());
41         this.bundleGroup = bundleGroup;
42     }
43
44     public IBundleGroup getBundleGroup() {
45         return bundleGroup;
46     }
47
48     public URL JavaDoc getLicenseUrl() {
49         if (licenseUrl == null) {
50             licenseUrl = getURL(bundleGroup
51                     .getProperty(IBundleGroupConstants.LICENSE_HREF));
52         }
53
54         return licenseUrl;
55     }
56
57     public URL JavaDoc getFeatureImageUrl() {
58         if (featureImageUrl == null) {
59             featureImageUrl = getURL(bundleGroup
60                     .getProperty(IBundleGroupConstants.FEATURE_IMAGE));
61         }
62         return featureImageUrl;
63     }
64
65     public ImageDescriptor getFeatureImage() {
66         if (featureImage == null) {
67             featureImage = getImage(getFeatureImageUrl());
68         }
69         return featureImage;
70     }
71
72     public Long JavaDoc getFeatureImageCrc() {
73         if (featureImageCrc != null) {
74             return featureImageCrc;
75         }
76
77         URL JavaDoc url = getFeatureImageUrl();
78         if (url == null) {
79             return null;
80         }
81
82         // Get the image bytes
83
InputStream JavaDoc in = null;
84         try {
85             CRC32 JavaDoc checksum = new CRC32 JavaDoc();
86             in = new CheckedInputStream JavaDoc(url.openStream(), checksum);
87
88             // the contents don't matter, the read just needs a place to go
89
byte[] sink = new byte[1024];
90             while (true) {
91                 if (in.read(sink) <= 0) {
92                     break;
93                 }
94             }
95
96             featureImageCrc = new Long JavaDoc(checksum.getValue());
97             return featureImageCrc;
98
99         } catch (IOException JavaDoc e) {
100             return null;
101         } finally {
102             if (in != null) {
103                 try {
104                     in.close();
105                 } catch (IOException JavaDoc e) {
106                     // do nothing
107
}
108             }
109         }
110     }
111
112     public String JavaDoc getAboutText() {
113         return bundleGroup.getProperty(IBundleGroupConstants.ABOUT_TEXT);
114     }
115 }
116
Popular Tags