KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > update > core > SiteContentProvider


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.core;
12  
13 import java.net.*;
14
15 import org.eclipse.core.runtime.*;
16 import org.eclipse.osgi.util.NLS;
17 import org.eclipse.update.internal.core.Messages;
18 import org.eclipse.update.internal.core.UpdateCore;
19
20 /**
21  * Base site content provider
22  * <p>
23  * <b>Note:</b> This class/interface is part of an interim API that is still under development and expected to
24  * change significantly before reaching stability. It is being made available at this early stage to solicit feedback
25  * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken
26  * (repeatedly) as the API evolves.
27  * </p>
28  */

29 public abstract class SiteContentProvider implements ISiteContentProvider {
30
31     private URL base;
32     private ISite site;
33
34     /**
35      * Constructor for SiteContentProvider
36      */

37     public SiteContentProvider(URL url) {
38         super();
39         this.base = url;
40     }
41
42     /**
43      * Returns the URL of this site
44      *
45      * @see ISiteContentProvider#getURL()
46      * @since 2.0
47      */

48     public URL getURL() {
49         return base;
50     }
51
52     /**
53      * Returns a URL for the identified archive
54      *
55      * @see ISiteContentProvider#getArchiveReference(String)
56      * @since 2.0
57      */

58     private URL getArchiveReference1(String JavaDoc archiveID) throws CoreException {
59         try {
60             return new URL(getURL(), archiveID);
61         } catch (MalformedURLException e) {
62             throw Utilities.newCoreException(
63                     NLS.bind(Messages.SiteContentProvider_ErrorCreatingURLForArchiveID, (new String JavaDoc[] { archiveID, getURL().toExternalForm() })),
64                     e);
65         }
66     }
67
68     /**
69      * Returns the site for this provider
70      *
71      * @see ISiteContentProvider#getSite()
72      * @since 2.0
73      */

74     public ISite getSite() {
75         return site;
76     }
77
78     /**
79      * Sets the site for this provider
80      *
81      * @param site site for this provider
82      * @since 2.0
83      */

84     public void setSite(ISite site) {
85         this.site = site;
86     }
87
88     public URL getArchiveReference(String JavaDoc archiveId) throws CoreException {
89         URL contentURL = null;
90         
91         contentURL = getArchiveURLfor(archiveId);
92         // if there is no mapping in the site.xml
93
// for this archiveId, use the default one
94
if (contentURL==null) {
95             return getArchiveReference1(archiveId);
96         }
97         
98         return contentURL;
99     }
100
101     /**
102      * return the URL associated with the id of teh archive for this site
103      * return null if the archiveId is null, empty or
104      * if teh list of archives on the site is null or empty
105      * of if there is no URL associated with the archiveID for this site
106      */

107     private URL getArchiveURLfor(String JavaDoc archiveId) {
108         URL result = null;
109         boolean found = false;
110     
111         IArchiveReference[] siteArchives = getSite().getArchives();
112         if (siteArchives.length > 0) {
113             for (int i = 0; i < siteArchives.length && !found; i++) {
114                 if (UpdateCore.DEBUG && UpdateCore.DEBUG_SHOW_INSTALL)
115                     UpdateCore.debug("GetArchiveURL for:"+archiveId+" compare to "+siteArchives[i].getPath()); //$NON-NLS-1$ //$NON-NLS-2$
116
if (archiveId.trim().equalsIgnoreCase(siteArchives[i].getPath())) {
117                     result = siteArchives[i].getURL();
118                     found = true;
119                     break;
120                 }
121             }
122         }
123         return result;
124     }
125 }
126
Popular Tags