KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 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 import java.io.*;
13
14 import org.eclipse.core.runtime.*;
15 import org.eclipse.osgi.util.NLS;
16 import org.eclipse.update.core.*;
17
18 /**
19  * Plugin Content Consumer on a Site
20  */

21 public class SiteFileNonPluginContentConsumer extends ContentConsumer {
22
23     private String JavaDoc path;
24     private boolean closed = false;
25
26     /*
27      * Constructor
28      */

29     public SiteFileNonPluginContentConsumer(String JavaDoc featurePath) {
30         this.path = featurePath;
31     }
32
33     /*
34      * @see ISiteContentConsumer#store(ContentReference, IProgressMonitor)
35      */

36     public void store(ContentReference contentReference, IProgressMonitor monitor) throws CoreException {
37
38         if (closed) {
39             UpdateCore.warn("Attempt to store in a closed SiteFileNonPluginContentConsumer", new Exception JavaDoc()); //$NON-NLS-1$
40
return;
41         }
42
43         InputStream inStream = null;
44         String JavaDoc featurePath = path;
45         String JavaDoc contentKey = contentReference.getIdentifier();
46         featurePath += contentKey;
47         try {
48             inStream = contentReference.getInputStream();
49             UpdateManagerUtils.copyToLocal(inStream, featurePath, null);
50             UpdateManagerUtils.checkPermissions(contentReference, featurePath); // 20305
51
} catch (IOException e) {
52             throw Utilities.newCoreException(NLS.bind(Messages.GlobalConsumer_ErrorCreatingFile, (new String JavaDoc[] { featurePath })), e);
53         } finally {
54             if (inStream != null) {
55                 try {
56                     // close stream
57
inStream.close();
58                 } catch (IOException e) {
59                 }
60             }
61         }
62
63     }
64
65     /*
66      * @see ISiteContentConsumer#close()
67      */

68     public void close() {
69         if (closed) {
70             UpdateCore.warn("Attempt to close a closed SiteFileNonPluginContentConsumer", new Exception JavaDoc()); //$NON-NLS-1$
71
return;
72         }
73         closed = true;
74     }
75
76 }
77
Popular Tags