1 11 package org.eclipse.update.core; 12 13 import java.io.IOException ; 14 import java.io.InputStream ; 15 import java.net.MalformedURLException ; 16 import java.net.URL ; 17 import java.net.URLClassLoader ; 18 import java.util.Locale ; 19 import java.util.MissingResourceException ; 20 import java.util.ResourceBundle ; 21 22 import org.eclipse.core.runtime.CoreException; 23 import org.eclipse.osgi.util.NLS; 24 import org.eclipse.update.core.model.ArchiveReferenceModel; 25 import org.eclipse.update.core.model.CategoryModel; 26 import org.eclipse.update.core.model.InvalidSiteTypeException; 27 import org.eclipse.update.core.model.SiteModel; 28 import org.eclipse.update.core.model.SiteModelFactory; 29 import org.eclipse.update.core.model.URLEntryModel; 30 import org.eclipse.update.internal.core.Messages; 31 import org.eclipse.update.internal.core.UpdateCore; 32 import org.eclipse.update.internal.core.UpdateManagerUtils; 33 import org.eclipse.update.internal.core.connection.ConnectionFactory; 34 import org.eclipse.update.internal.core.connection.IResponse; 35 36 56 public abstract class BaseSiteFactory extends SiteModelFactory implements ISiteFactory { 57 58 59 66 public abstract ISite createSite(URL url) throws CoreException, InvalidSiteTypeException; 67 68 77 protected ResourceBundle getResourceBundle(URL url) { 78 ResourceBundle bundle = null; 79 80 try { 81 url = UpdateManagerUtils.asDirectoryURL(url); 82 ClassLoader l = new URLClassLoader (new URL [] { url }, null); 83 bundle = ResourceBundle.getBundle(Site.SITE_FILE, Locale.getDefault(), l); 84 } catch (MissingResourceException e) { 85 UpdateCore.warn(e.getLocalizedMessage() + ":" + url.toExternalForm()); } catch (MalformedURLException e) { 87 UpdateCore.warn(NLS.bind(Messages.BaseSiteFactory_CannotRetriveParentDirectory, (new String [] { url.toExternalForm() }))); 88 } 89 90 return bundle; 91 } 92 93 100 public SiteModel createSiteMapModel() { 101 return new Site(); 102 } 103 104 105 112 public SiteFeatureReferenceModel createFeatureReferenceModel() { 113 return new SiteFeatureReference(); 114 } 115 116 123 public ArchiveReferenceModel createArchiveReferenceModel() { 124 return new ArchiveReference(); 125 } 126 127 128 135 public URLEntryModel createURLEntryModel() { 136 return new URLEntry(); 137 } 138 139 140 147 public CategoryModel createSiteCategoryModel() { 148 return new Category(); 149 } 150 151 158 protected InputStream openStream(URL resolvedURL) throws IOException { 159 IResponse response = ConnectionFactory.get(resolvedURL); 160 return response.getInputStream(); 161 } 162 163 } 164 | Popular Tags |