001: /*******************************************************************************
002: * Copyright (c) 2004, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.internal.about;
011:
012: import java.io.IOException;
013: import java.io.InputStream;
014: import java.net.URL;
015: import java.util.zip.CRC32;
016: import java.util.zip.CheckedInputStream;
017:
018: import org.eclipse.core.runtime.IBundleGroup;
019: import org.eclipse.jface.resource.ImageDescriptor;
020: import org.eclipse.ui.branding.IBundleGroupConstants;
021:
022: /**
023: * A small class to manage the information related to IBundleGroup's.
024: * @since 3.0
025: */
026: public class AboutBundleGroupData extends AboutData {
027: private IBundleGroup bundleGroup;
028:
029: private URL licenseUrl;
030:
031: private URL featureImageUrl;
032:
033: private Long featureImageCrc;
034:
035: private ImageDescriptor featureImage;
036:
037: public AboutBundleGroupData(IBundleGroup bundleGroup) {
038: super (bundleGroup.getProviderName(), bundleGroup.getName(),
039: bundleGroup.getVersion(), bundleGroup.getIdentifier());
040: this .bundleGroup = bundleGroup;
041: }
042:
043: public IBundleGroup getBundleGroup() {
044: return bundleGroup;
045: }
046:
047: public URL getLicenseUrl() {
048: if (licenseUrl == null) {
049: licenseUrl = getURL(bundleGroup
050: .getProperty(IBundleGroupConstants.LICENSE_HREF));
051: }
052:
053: return licenseUrl;
054: }
055:
056: public URL getFeatureImageUrl() {
057: if (featureImageUrl == null) {
058: featureImageUrl = getURL(bundleGroup
059: .getProperty(IBundleGroupConstants.FEATURE_IMAGE));
060: }
061: return featureImageUrl;
062: }
063:
064: public ImageDescriptor getFeatureImage() {
065: if (featureImage == null) {
066: featureImage = getImage(getFeatureImageUrl());
067: }
068: return featureImage;
069: }
070:
071: public Long getFeatureImageCrc() {
072: if (featureImageCrc != null) {
073: return featureImageCrc;
074: }
075:
076: URL url = getFeatureImageUrl();
077: if (url == null) {
078: return null;
079: }
080:
081: // Get the image bytes
082: InputStream in = null;
083: try {
084: CRC32 checksum = new CRC32();
085: in = new CheckedInputStream(url.openStream(), checksum);
086:
087: // the contents don't matter, the read just needs a place to go
088: byte[] sink = new byte[1024];
089: while (true) {
090: if (in.read(sink) <= 0) {
091: break;
092: }
093: }
094:
095: featureImageCrc = new Long(checksum.getValue());
096: return featureImageCrc;
097:
098: } catch (IOException e) {
099: return null;
100: } finally {
101: if (in != null) {
102: try {
103: in.close();
104: } catch (IOException e) {
105: // do nothing
106: }
107: }
108: }
109: }
110:
111: public String getAboutText() {
112: return bundleGroup
113: .getProperty(IBundleGroupConstants.ABOUT_TEXT);
114: }
115: }
|