Debian Codegraph @

bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteModel.java

raw
1 /*******************************************************************************
2 * Copyright (c) 2000, 2017 IBM Corporation and others.
3 *
4 * This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License 2.0
6 * which accompanies this distribution, and is available at
7 * https://www.eclipse.org/legal/epl-2.0/
8 *
9 * SPDX-License-Identifier: EPL-2.0
10 *
11 * Contributors:
12 * IBM Corporation - initial API and implementation
13 *******************************************************************************/
14 package org.eclipse.equinox.internal.p2.updatesite;
15
16 import java.net.URI;
17 import java.net.URISyntaxException;
18 import java.util.ArrayList;
19 import java.util.HashMap;
20 import java.util.List;
21 import java.util.Locale;
22 import java.util.Map;
23
24 import org.eclipse.equinox.p2.publisher.eclipse.URLEntry;
25 import org.eclipse.equinox.p2.repository.spi.RepositoryReference;
26
27 /**
28 * A model of an update site.
29 *
30 * Copied from org.eclipse.update.core.model.SiteModel.
31 */
32 public class SiteModel {
33
34 private List<URLEntry> archiveReferences;
35 /**
36 * Map of String (category id) -> SiteCategory
37 */
38 private Map<String, SiteCategory> categories;
39 private URLEntry description;
40 /**
41 * Map of String (feature id) -> SiteFeature
42 */
43 private List<SiteFeature> features;
44 private List<SiteBundle> bundles;
45 private List<SiteIU> ius;
46 private URI locationURI;
47 private String locationURIString;
48 private String mirrorsURIString;
49 private String statsURIString;
50 private String type;
51 private URLEntry[] associateSites;
52 private String digestURIString;
53 private List<String> messageKeys;
54 private Map<Locale, Map<String, String>> localizations;
55 private List<RepositoryReference> repositoryReferences;
56 private List<SiteFeature> statsFeatures;
57 private List<SiteBundle> statsBundles;
58
59 /**
60 * Creates an uninitialized site model object.
61 *
62 * @since 2.0
63 */
64 public SiteModel() {
65 super();
66 }
67
68 /**
69 * Adds an archive reference model to site. Throws a runtime exception if this
70 * object is marked read-only.
71 *
72 * @param archiveReference archive reference model
73 * @since 2.0
74 */
75 public void addArchive(URLEntry archiveReference) {
76 if (this.archiveReferences == null)
77 this.archiveReferences = new ArrayList<>();
78 if (!this.archiveReferences.contains(archiveReference))
79 this.archiveReferences.add(archiveReference);
80 }
81
82 /**
83 * Adds a category to the site.
84 *
85 * @param category category model
86 */
87 public void addCategory(SiteCategory category) {
88 if (categories == null)
89 categories = new HashMap<>();
90 if (!categories.containsKey(category.getName())) {
91 categories.put(category.getName(), category);
92 if (localizations != null && !localizations.isEmpty())
93 category.setLocalizations(localizations);
94 }
95 }
96
97 /**
98 * Adds a feature reference model to site.
99 *
100 * @param featureReference feature reference model
101 */
102 public void addFeature(SiteFeature featureReference) {
103 if (this.features == null)
104 this.features = new ArrayList<>();
105 this.features.add(featureReference);
106 }
107
108 /**
109 * Adds a bundle reference model to site.
110 *
111 * @param bundleReference bundle reference model
112 */
113 public void addBundle(SiteBundle bundleReference) {
114 if (this.bundles == null)
115 this.bundles = new ArrayList<>();
116 this.bundles.add(bundleReference);
117 }
118
119 /**
120 * Adds a feature reference model to site stats artifacts.
121 *
122 * @param featureReference feature reference model
123 */
124 public void addStatsFeature(SiteFeature featureReference) {
125 if (this.statsFeatures == null)
126 this.statsFeatures = new ArrayList<>();
127 this.statsFeatures.add(featureReference);
128 }
129
130 /**
131 * Adds a bundle reference model to site stats artifacts
132 *
133 * @param bundleReference bundle reference model
134 */
135 public void addStatsBundle(SiteBundle bundleReference) {
136 if (this.statsBundles == null)
137 this.statsBundles = new ArrayList<>();
138 this.statsBundles.add(bundleReference);
139 }
140
141 /**
142 * Adds a iu model to site.
143 *
144 * @param iu iu model
145 */
146 public void addIU(SiteIU iu) {
147 if (this.ius == null)
148 this.ius = new ArrayList<>();
149 this.ius.add(iu);
150 }
151
152 /**
153 * Adds a repository reference to the site
154 *
155 * @param ref repository reference
156 */
157 public void addRepositoryReference(RepositoryReference ref) {
158 if (this.repositoryReferences == null)
159 this.repositoryReferences = new ArrayList<>();
160 this.repositoryReferences.add(ref);
161 }
162
163 /**
164 * Returns an array of plug-in and non-plug-in archive reference models on this
165 * site
166 *
167 * @return an array of archive reference models, or an empty array if there are
168 * no archives known to this site.
169 * @since 2.0
170 */
171 public URLEntry[] getArchives() {
172 if (archiveReferences == null || archiveReferences.size() == 0)
173 return new URLEntry[0];
174
175 return archiveReferences.toArray(new URLEntry[0]);
176 }
177
178 public URLEntry[] getAssociatedSites() {
179 return associateSites;
180 }
181
182 /**
183 * Returns an array of category models for this site.
184 *
185 * @return array of site category models, or an empty array.
186 * @since 2.0
187 */
188 public SiteCategory[] getCategories() {
189 if (categories == null || categories.size() == 0)
190 return new SiteCategory[0];
191 return categories.values().toArray(new SiteCategory[0]);
192 }
193
194 /**
195 * Returns the category with the given name.
196 *
197 * @return the category with the given name, or <code>null</code>
198 */
199 public SiteCategory getCategory(String name) {
200 return (categories == null ? null : categories.get(name));
201 }
202
203 /**
204 * Returns the site description.
205 *
206 * @return site description, or <code>null</code>.
207 */
208 public URLEntry getDescription() {
209 return description;
210 }
211
212 /**
213 * Returns an array of feature reference models on this site.
214 *
215 * @return an array of feature reference models, or an empty array.
216 */
217 public SiteFeature[] getFeatures() {
218 if (features == null || features.size() == 0)
219 return new SiteFeature[0];
220 return features.toArray(new SiteFeature[0]);
221 }
222
223 /**
224 * Returns an array of bundle reference models on this site.
225 *
226 * @return an array of bundle reference models, or an empty array.
227 */
228 public SiteBundle[] getBundles() {
229 if (bundles == null || bundles.size() == 0)
230 return new SiteBundle[0];
231 return bundles.toArray(new SiteBundle[0]);
232 }
233
234 /**
235 * Returns an array of feature reference models for stats on this site.
236 *
237 * @return an array of feature reference models, or an empty array.
238 */
239 public SiteFeature[] getStatsFeatures() {
240 if (statsFeatures == null || statsFeatures.size() == 0)
241 return new SiteFeature[0];
242 return statsFeatures.toArray(new SiteFeature[0]);
243 }
244
245 /**
246 * Returns an array of bundle reference models for stats on this site.
247 *
248 * @return an array of bundle reference models, or an empty array.
249 */
250 public SiteBundle[] getStatsBundles() {
251 if (statsBundles == null || statsBundles.size() == 0)
252 return new SiteBundle[0];
253 return statsBundles.toArray(new SiteBundle[0]);
254 }
255
256 /**
257 * Returns an array of IU models on this site.
258 *
259 * @return an array of IU models, or an empty array.
260 */
261 public SiteIU[] getIUs() {
262 if (ius == null || ius.size() == 0)
263 return new SiteIU[0];
264 return ius.toArray(new SiteIU[0]);
265 }
266
267 /**
268 * Returns an array of repository references for this site.
269 *
270 * @return an array of repository references, or an empty array.
271 */
272 public RepositoryReference[] getRepositoryReferences() {
273 if (repositoryReferences == null || repositoryReferences.size() == 0)
274 return new RepositoryReference[0];
275 return repositoryReferences.toArray(new RepositoryReference[repositoryReferences.size()]);
276 }
277
278 /**
279 * Returns the URI of the stats repository that tracks downloads.
280 *
281 * @return a String representation of the stats URI.
282 */
283 public String getStatsURI() {
284 return statsURIString;
285 }
286
287 /**
288 * Gets the localizations for the site as a map from locale to the set of
289 * translated properties for that locale.
290 *
291 * @return a map from locale to property set
292 * @since 3.4
293 */
294 public Map<Locale, Map<String, String>> getLocalizations() {
295 return this.localizations;
296 }
297
298 /**
299 * Returns the resolved URI for the site.
300 *
301 * @return url, or <code>null</code>
302 */
303 public URI getLocationURI() {
304 if (locationURI == null && locationURIString != null) {
305 try {
306 locationURI = new URI(locationURIString);
307 } catch (URISyntaxException e) {
308 // ignore and return null
309 }
310 }
311 return locationURI;
312 }
313
314 /**
315 * Returns the unresolved URI string for the site.
316 *
317 * @return url string, or <code>null</code>
318 */
319 public String getLocationURIString() {
320 return locationURIString;
321 }
322
323 /**
324 * Return the keys for translatable strings
325 *
326 * @return the list of keys for translatable strings; may be null
327 * @since 3.4
328 */
329 public List<String> getMessageKeys() {
330 return messageKeys;
331 }
332
333 /**
334 * Returns the URI from which the list of mirrors of this site can be retrieved.
335 *
336 */
337 public String getMirrorsURI() {
338 return mirrorsURIString;
339 }
340
341 /**
342 * Returns the site type.
343 *
344 * @return site type, or <code>null</code>.
345 * @since 2.0
346 */
347 public String getType() {
348 return type;
349 }
350
351 /**
352 * Sets the site description.
353 *
354 * @param description site description
355 * @since 2.0
356 */
357 public void setDescription(URLEntry description) {
358 this.description = description;
359 }
360
361 /**
362 * Sets the localizations for the site as a map from locale to the set of
363 * translated properties for that locale.
364 *
365 * @param localizations as a map from locale to property set
366 * @since 3.4
367 */
368 public void setLocalizations(Map<Locale, Map<String, String>> localizations) {
369 this.localizations = localizations;
370 if (localizations != null && !localizations.isEmpty() && //
371 categories != null && !categories.isEmpty()) {
372 for (SiteCategory category : categories.values()) {
373 category.setLocalizations(localizations);
374 }
375 }
376 }
377
378 /**
379 * Sets the unresolved URI for the site.
380 *
381 * @param locationURIString url for the site (as a string)
382 * @since 2.0
383 */
384 public void setLocationURIString(String locationURIString) {
385 this.locationURIString = locationURIString;
386 }
387
388 /**
389 * Sets keys for translatable strings
390 *
391 * @param keys for translatable strings
392 * @since 3.4
393 */
394 public void setMessageKeys(List<String> keys) {
395 this.messageKeys = keys;
396 }
397
398 /**
399 * Sets the mirrors url. Mirror sites will then be obtained from this mirror url
400 * later. This method is complementary to setMirrorsiteEntryModels(), and only
401 * one of these methods should be called.
402 *
403 * @param mirrorsURI additional update site mirrors
404 * @since 3.1
405 */
406 public void setMirrorsURIString(String mirrorsURI) {
407 this.mirrorsURIString = mirrorsURI;
408 }
409
410 /**
411 * Sets the site type. Throws a runtime exception if this object is marked
412 * read-only.
413 *
414 * @param type site type
415 * @since 2.0
416 */
417 public void setType(String type) {
418 this.type = type;
419 }
420
421 /**
422 * Sets the associated sites for this update site.
423 *
424 * @param associateSites the associated sites
425 */
426 public void setAssociateSites(URLEntry[] associateSites) {
427 this.associateSites = associateSites;
428 }
429
430 public void setDigestURIString(String digestURIString) {
431 this.digestURIString = digestURIString;
432 }
433
434 public String getDigestURIString() {
435 return digestURIString;
436 }
437
438 /**
439 * Sets the URI of the stats repository used to track downloads.
440 *
441 * @param statsURI a String describing the stats URI
442 */
443 public void setStatsURIString(String statsURI) {
444 this.statsURIString = statsURI;
445 }
446
447 }