1010 *
1111 * Contributors:
1212 * IBM Corporation - initial API and implementation
13- * James D Miles (IBM Corp.) - bug 176250, Configurator needs to handle more platform urls
13+ * James D Miles (IBM Corp.) - bug 176250, Configurator needs to handle more platform urls
1414 *******************************************************************************/
1515package org .eclipse .update .internal .configurator ;
1616
2525import org .w3c .dom .*;
2626
2727public class Configuration implements IConfigurationConstants {
28-
28+
2929 private final HashMap <String , SiteEntry > sites = new HashMap <>();
3030 private final HashMap <String , URL > platformURLs = new HashMap <>();
3131 private Date date ;
@@ -35,7 +35,7 @@ public class Configuration implements IConfigurationConstants {
3535 private boolean isDirty ;
3636 private Configuration linkedConfig ; // shared configuration
3737 private URL associatedInstallURL = Utils .getInstallURL ();
38-
38+
3939 public Configuration () {
4040 this (new Date ());
4141 // the config is created now or out of a platform.xml without a date
@@ -44,37 +44,38 @@ public Configuration() {
4444 public Configuration (Date date ) {
4545 this .date = date ;
4646 }
47-
47+
4848 public void setURL (URL url ) {
4949 this .url = url ;
5050 }
51-
51+
5252 public URL getURL () {
5353 return url ;
5454 }
55-
55+
5656 public void setLinkedConfig (Configuration linkedConfig ) {
5757 this .linkedConfig = linkedConfig ;
5858 // make all the sites read-only
59- for (SiteEntry linkedSite : linkedConfig .getSites ())
59+ for (SiteEntry linkedSite : linkedConfig .getSites ()) {
6060 linkedSite .setUpdateable (false );
61+ }
6162 }
62-
63+
6364 public Configuration getLinkedConfig () {
6465 return linkedConfig ;
6566 }
66-
67+
6768 /**
6869 * @return true if the config needs to be saved
6970 */
7071 public boolean isDirty () {
7172 return isDirty ;
7273 }
73-
74+
7475 public void setDirty (boolean dirty ) {
7576 isDirty = dirty ;
7677 }
77-
78+
7879 public void addSiteEntry (String url , SiteEntry site ) {
7980 url = Utils .canonicalizeURL (url );
8081 // only add the same site once
@@ -92,7 +93,7 @@ public void addSiteEntry(String url, SiteEntry site) {
9293 }else {
9394 relSite = getInstallURL ();
9495 }
95-
96+
9697 pURL = new URL (url );
9798 URL rURL = PlatformConfiguration .resolvePlatformURL (pURL , relSite );
9899 String resolvedURL = rURL .toExternalForm ();
@@ -103,9 +104,9 @@ public void addSiteEntry(String url, SiteEntry site) {
103104 }
104105 }
105106 }
106-
107+
107108 public void removeSiteEntry (String url ) {
108- url =Utils .canonicalizeURL (url );
109+ url =Utils .canonicalizeURL (url );
109110 sites .remove (url );
110111 if (url .startsWith ("platform:" )){ //$NON-NLS-1$
111112 URL pURL ;
@@ -118,7 +119,7 @@ public void removeSiteEntry(String url) {
118119 }else {
119120 relSite = getInstallURL ();
120121 }
121-
122+
122123 pURL = new URL (url );
123124 URL rURL = PlatformConfiguration .resolvePlatformURL (pURL , relSite );
124125 String resolvedURL = rURL .toExternalForm ();
@@ -128,83 +129,88 @@ public void removeSiteEntry(String url) {
128129 }
129130 }
130131 }
131-
132+
132133 public SiteEntry getSiteEntry (String url ) {
133- url = Utils .canonicalizeURL (url );
134+ url = Utils .canonicalizeURL (url );
134135 SiteEntry site = sites .get (url );
135- if (site == null && linkedConfig != null )
136+ if (site == null && linkedConfig != null ) {
136137 site = linkedConfig .getSiteEntry (url );
138+ }
137139 return site ;
138140 }
139-
141+
140142 public SiteEntry [] getSites () {
141- if (linkedConfig == null )
143+ if (linkedConfig == null ) {
142144 return sites .values ().toArray (new SiteEntry [sites .size ()]);
145+ }
143146 ArrayList <SiteEntry > combinedSites = new ArrayList <>(sites .values ());
144147 combinedSites .addAll (linkedConfig .sites .values ());
145148 return combinedSites .toArray (new SiteEntry [combinedSites .size ()]);
146149 }
147-
148- public Element toXML (Document doc ) throws CoreException {
150+
151+ public Element toXML (Document doc ) throws CoreException {
149152 try {
150153 Element configElement = doc .createElement (CFG );
151154
152155 configElement .setAttribute (CFG_VERSION , VERSION );
153156 configElement .setAttribute (CFG_DATE , String .valueOf (date .getTime ()));
154157 String transitory = isTransient () ? "true" : "false" ; //$NON-NLS-1$ //$NON-NLS-2$
155158 configElement .setAttribute (CFG_TRANSIENT , transitory );
156-
159+
157160 if (linkedConfig != null ) {
158- // make externalized URL install relative
161+ // make externalized URL install relative
159162 configElement .setAttribute (CFG_SHARED_URL , Utils .makeRelative (getInstallURL (), linkedConfig .getURL ()).toExternalForm ());
160163 }
161164
162165 // collect site entries
163166 for (SiteEntry element : sites .values ()) {
164- if (linkedConfig != null && linkedConfig .getSiteEntry (element .getURL ().toExternalForm ()) != null )
167+ if (linkedConfig != null && linkedConfig .getSiteEntry (element .getURL ().toExternalForm ()) != null ) {
165168 continue ;
169+ }
166170 Element siteElement = element .toXML (doc );
167171 configElement .appendChild (siteElement );
168172 }
169-
173+
170174 return configElement ;
171-
175+
172176 } catch (Exception e ) {
173177 throw Utils .newCoreException ("" , e ); //$NON-NLS-1$
174- }
178+ }
175179 }
176-
180+
177181 public boolean isTransient () {
178182 return transientConfig ;
179183 }
180-
184+
181185 public void setTransient (boolean isTransient ) {
182186 this .transientConfig = isTransient ;
183187 }
184-
188+
185189 public Date getDate () {
186190 return date ;
187191 }
188-
192+
189193 public void setDate (Date date ) {
190194 this .date = date ;
191195 }
192-
196+
193197 public boolean unconfigureFeatureEntry (IPlatformConfiguration .IFeatureEntry feature ) {
194- for (SiteEntry site : getSites ())
195- if (site .unconfigureFeatureEntry (feature ))
198+ for (SiteEntry site : getSites ()) {
199+ if (site .unconfigureFeatureEntry (feature )) {
196200 return true ;
201+ }
202+ }
197203 return false ;
198204 }
199-
205+
200206 public void setLastModified (long lastModified ) {
201207 this .lastModified = lastModified ;
202208 }
203-
209+
204210 public long lastModified () {
205211 return (lastModified != 0 ) ? lastModified : date .getTime ();
206212 }
207-
213+
208214 /**
209215 * Returns the url as a platform:/ url, if possible, else leaves it unchanged
210216 */
@@ -213,20 +219,21 @@ public URL asPlatformURL(URL url) {
213219 if (url .getProtocol ().equals ("file" )) {//$NON-NLS-1$
214220 String rUrl = url .toExternalForm ();
215221 URL pUrl = platformURLs .get (rUrl );
216- if (pUrl == null )
222+ if (pUrl == null ) {
217223 return url ;
224+ }
218225 return pUrl ;
219226 }
220227 return url ;
221228 } catch (Exception e ) {
222229 return url ;
223230 }
224231 }
225-
232+
226233 public URL getInstallURL () {
227234 return associatedInstallURL ;
228235 }
229-
236+
230237 public void setInstallLocation (URL installURL ) {
231238 associatedInstallURL = installURL ;
232239 }
0 commit comments