KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > update > internal > model > SiteLocalParser


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.model;
12
13 import java.io.IOException JavaDoc;
14 import java.net.MalformedURLException JavaDoc;
15 import java.net.URL JavaDoc;
16 import java.net.URLClassLoader JavaDoc;
17 import java.util.Locale JavaDoc;
18 import java.util.MissingResourceException JavaDoc;
19 import java.util.ResourceBundle JavaDoc;
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 /**
33  * parse the default site.xml
34  */

35
36 public class SiteLocalParser {
37
38     private PlatformConfiguration platformConfig;
39     private SiteLocalModel site;
40     public static final String JavaDoc CONFIG = "config"; //$NON-NLS-1$
41
private ResourceBundle JavaDoc bundle;
42     private BaseSiteLocalFactory factory = new BaseSiteLocalFactory();
43
44     /**
45      * return the appropriate resource bundle for this sitelocal
46      */

47     private ResourceBundle JavaDoc getResourceBundle() throws CoreException {
48         ResourceBundle JavaDoc bundle = null;
49         URL JavaDoc url = null;
50         try {
51             url = UpdateManagerUtils.asDirectoryURL(site.getLocationURL());
52             ClassLoader JavaDoc l = new URLClassLoader JavaDoc(new URL JavaDoc[] { url }, null);
53             bundle = ResourceBundle.getBundle("platform", Locale.getDefault(), l); //$NON-NLS-1$
54
} catch (MissingResourceException JavaDoc e) {
55             UpdateCore.warn(e.getLocalizedMessage() + ":" + url.toExternalForm()); //$NON-NLS-1$
56
} catch (MalformedURLException JavaDoc e) {
57             UpdateCore.warn(e.getLocalizedMessage());
58         }
59         return bundle;
60     }
61
62     /**
63      * Constructor for DefaultSiteParser
64      */

65     public SiteLocalParser(IPlatformConfiguration platformConfig, ILocalSite site) throws IOException JavaDoc, 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         // DEBUG:
73
if (UpdateCore.DEBUG && UpdateCore.DEBUG_SHOW_PARSING) {
74             UpdateCore.debug("Start parsing localsite:" + ((SiteLocalModel) site).getLocationURLString()); //$NON-NLS-1$
75
}
76         
77         bundle = getResourceBundle();
78         
79         processConfig();
80         //processHistory();
81
}
82
83     
84 // /**
85
// * process the Site info
86
// */
87
// private void processSite(Attributes attributes) throws MalformedURLException {
88
// //
89
// String info = attributes.getValue("label"); //$NON-NLS-1$
90
// info = UpdateManagerUtils.getResourceString(info, bundle);
91
// site.setLabel(info);
92
//
93
// // history
94
// String historyString = attributes.getValue("history"); //$NON-NLS-1$
95
// int history;
96
// if (historyString == null || historyString.equals("")) { //$NON-NLS-1$
97
// history = SiteLocalModel.DEFAULT_HISTORY;
98
// } else {
99
// history = Integer.parseInt(historyString);
100
// }
101
// site.setMaximumHistoryCount(history);
102
//
103
// //stamp
104
// String stampString = attributes.getValue("stamp"); //$NON-NLS-1$
105
// long stamp = Long.parseLong(stampString);
106
// site.setStamp(stamp);
107
//
108
// // DEBUG:
109
// if (UpdateCore.DEBUG && UpdateCore.DEBUG_SHOW_PARSING) {
110
// UpdateCore.debug("End process Site label:" + info); //$NON-NLS-1$
111
// }
112
//
113
// }
114

115     /**
116      * process the Config info
117      */

118     private void processConfig() throws MalformedURLException JavaDoc, CoreException {
119
120         String JavaDoc label = platformConfig.getConfiguration().getDate().toString();
121         label = UpdateManagerUtils.getResourceString(label, bundle);
122         site.setLabel(label);
123
124         URL JavaDoc 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         // add the config
131
((LocalSite)site).addConfiguration((InstallConfiguration)config);
132
133         // DEBUG:
134
if (UpdateCore.DEBUG && UpdateCore.DEBUG_SHOW_PARSING) {
135             UpdateCore.debug("End Processing Config Tag: url:" + url.toExternalForm()); //$NON-NLS-1$
136
}
137     }
138 }
139
Popular Tags