KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > update > internal > core > Digest


1 /*******************************************************************************
2  * Copyright (c) 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.update.internal.core;
12
13 import java.io.File JavaDoc;
14 import java.io.IOException JavaDoc;
15 import java.io.InputStream JavaDoc;
16 import java.net.URL JavaDoc;
17 import java.util.jar.JarFile JavaDoc;
18 import java.util.zip.ZipEntry JavaDoc;
19
20 import org.eclipse.core.runtime.CoreException;
21 import org.eclipse.update.core.JarContentReference;
22 import org.eclipse.update.core.model.FeatureModel;
23 import org.xml.sax.SAXException JavaDoc;
24
25 public class Digest {
26     
27     private URL JavaDoc source;
28     private File JavaDoc localSource;
29     private JarFile JavaDoc digestJar;
30     private InputStream JavaDoc inputStream;
31     
32
33     public Digest(URL JavaDoc source){
34         this.source = source;
35     }
36     
37     public FeatureModel[] parseDigest() throws IOException JavaDoc, CoreException, SAXException JavaDoc {
38         DigestContentProvider digestContentProvider = new DigestContentProvider(source);
39         localSource = digestContentProvider.asLocalReference(new JarContentReference( null, source), null).asFile();
40         digestJar = new JarFile JavaDoc(localSource);
41         
42         ZipEntry JavaDoc digestEntry = digestJar.getEntry("digest.xml"); //$NON-NLS-1$
43

44         if (digestEntry != null) {
45             inputStream = digestJar.getInputStream(digestEntry);
46             DigestParser digest = new DigestParser();
47             digest.init(new LiteFeatureFactory());
48             return digest.parse(inputStream);
49         } else {
50             throw new CoreException(null);
51         }
52     }
53
54 }
55
Popular Tags