1 11 package org.eclipse.update.internal.model; 12 13 import java.io.IOException ; 14 import java.net.MalformedURLException ; 15 import java.net.URL ; 16 import java.net.URLClassLoader ; 17 import java.util.Locale ; 18 import java.util.MissingResourceException ; 19 import java.util.ResourceBundle ; 20 21 import org.eclipse.core.runtime.Assert; 22 import org.eclipse.core.runtime.CoreException; 23 import org.eclipse.update.configuration.ILocalSite; 24 import org.eclipse.update.configurator.IPlatformConfiguration; 25 import org.eclipse.update.internal.configurator.PlatformConfiguration; 26 import org.eclipse.update.internal.core.BaseSiteLocalFactory; 27 import org.eclipse.update.internal.core.InstallConfiguration; 28 import org.eclipse.update.internal.core.LocalSite; 29 import org.eclipse.update.internal.core.UpdateCore; 30 import org.eclipse.update.internal.core.UpdateManagerUtils; 31 32 35 36 public class SiteLocalParser { 37 38 private PlatformConfiguration platformConfig; 39 private SiteLocalModel site; 40 public static final String CONFIG = "config"; private ResourceBundle bundle; 42 private BaseSiteLocalFactory factory = new BaseSiteLocalFactory(); 43 44 47 private ResourceBundle getResourceBundle() throws CoreException { 48 ResourceBundle bundle = null; 49 URL url = null; 50 try { 51 url = UpdateManagerUtils.asDirectoryURL(site.getLocationURL()); 52 ClassLoader l = new URLClassLoader (new URL [] { url }, null); 53 bundle = ResourceBundle.getBundle("platform", Locale.getDefault(), l); } catch (MissingResourceException e) { 55 UpdateCore.warn(e.getLocalizedMessage() + ":" + url.toExternalForm()); } catch (MalformedURLException e) { 57 UpdateCore.warn(e.getLocalizedMessage()); 58 } 59 return bundle; 60 } 61 62 65 public SiteLocalParser(IPlatformConfiguration platformConfig, ILocalSite site) throws IOException , CoreException { 66 Assert.isTrue(platformConfig instanceof PlatformConfiguration); 67 this.platformConfig = (PlatformConfiguration)platformConfig; 68 69 Assert.isTrue(site instanceof SiteLocalModel); 70 this.site = (SiteLocalModel) site; 71 72 if (UpdateCore.DEBUG && UpdateCore.DEBUG_SHOW_PARSING) { 74 UpdateCore.debug("Start parsing localsite:" + ((SiteLocalModel) site).getLocationURLString()); } 76 77 bundle = getResourceBundle(); 78 79 processConfig(); 80 } 82 83 84 115 118 private void processConfig() throws MalformedURLException , CoreException { 119 120 String label = platformConfig.getConfiguration().getDate().toString(); 121 label = UpdateManagerUtils.getResourceString(label, bundle); 122 site.setLabel(label); 123 124 URL url = site.getLocationURL(); 125 InstallConfigurationModel config = factory.createInstallConfigurationModel(); 126 config.setLocationURLString(url.toExternalForm()); 127 config.setLabel(label); 128 config.resolve(url, site.getResourceBundleURL()); 129 130 ((LocalSite)site).addConfiguration((InstallConfiguration)config); 132 133 if (UpdateCore.DEBUG && UpdateCore.DEBUG_SHOW_PARSING) { 135 UpdateCore.debug("End Processing Config Tag: url:" + url.toExternalForm()); } 137 } 138 } 139 | Popular Tags |