]> source.dussan.org Git - archiva.git/blob
83202f531dc52a8b15746430fb7c0c883b8c52bf
[archiva.git] /
1
2 package org.apache.archiva.configuration.io.registry;
3
4 /*
5  * Licensed to the Apache Software Foundation (ASF) under one
6  * or more contributor license agreements.  See the NOTICE file
7  * distributed with this work for additional information
8  * regarding copyright ownership.  The ASF licenses this file
9  * to you under the Apache License, Version 2.0 (the
10  * "License"); you may not use this file except in compliance
11  * with the License.  You may obtain a copy of the License at
12  *
13  *   http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing,
16  * software distributed under the License is distributed on an
17  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18  * KIND, either express or implied.  See the License for the
19  * specific language governing permissions and limitations
20  * under the License.
21  */
22
23 import org.apache.archiva.configuration.*;
24 import org.apache.archiva.components.registry.Registry;
25
26 import java.util.Iterator;
27 import java.util.List;
28
29 // Util imports
30 // Model class imports
31
32
33 /**
34  * Generate Plexus Registry output mechanism for model 'Configuration'.
35  */
36 public class ConfigurationRegistryWriter {
37     public void write(Configuration model, Registry registry) {
38         writeConfiguration("", model, registry);
39     }
40
41     private void writeList(Registry registry, List<String> subList, String subsetPath, String elementName) {
42         if (subList != null && subList.size() > 0
43         ) {
44             registry.removeSubset(subsetPath);
45
46             int count = 0;
47             for (Iterator<String> iter = subList.iterator(); iter.hasNext(); count++) {
48                 String name = subsetPath + "." + elementName + "(" + count + ")";
49                 String value = iter.next();
50                 registry.setString(name, value);
51             }
52         }
53     }
54
55     private void writeConfiguration(String prefix, Configuration value, Registry registry) {
56         if (value != null) {
57             if (value.getVersion() != null
58             ) {
59                 String version = "version";
60                 registry.setString(prefix + version, value.getVersion());
61             }
62             if (value.getMetadataStore() != null && !value.getMetadataStore().equals("jcr")
63             ) {
64                 String metadataStore = "metadataStore";
65                 registry.setString(prefix + metadataStore, value.getMetadataStore());
66             }
67             if (value.getRepositoryGroups() != null && value.getRepositoryGroups().size() > 0
68             ) {
69                 registry.removeSubset(prefix + "repositoryGroups");
70
71                 int count = 0;
72                 for (Iterator iter = value.getRepositoryGroups().iterator(); iter.hasNext(); count++) {
73                     String name = "repositoryGroups.repositoryGroup(" + count + ")";
74                     RepositoryGroupConfiguration o = (RepositoryGroupConfiguration) iter.next();
75                     writeRepositoryGroupConfiguration(prefix + name + ".", o, registry);
76                 }
77             }
78             if (value.getManagedRepositories() != null && value.getManagedRepositories().size() > 0
79             ) {
80                 registry.removeSubset(prefix + "managedRepositories");
81
82                 int count = 0;
83                 for (Iterator iter = value.getManagedRepositories().iterator(); iter.hasNext(); count++) {
84                     String name = "managedRepositories.managedRepository(" + count + ")";
85                     ManagedRepositoryConfiguration o = (ManagedRepositoryConfiguration) iter.next();
86                     writeManagedRepositoryConfiguration(prefix + name + ".", o, registry);
87                 }
88             }
89             if (value.getRemoteRepositories() != null && value.getRemoteRepositories().size() > 0
90             ) {
91                 registry.removeSubset(prefix + "remoteRepositories");
92
93                 int count = 0;
94                 for (Iterator iter = value.getRemoteRepositories().iterator(); iter.hasNext(); count++) {
95                     String name = "remoteRepositories.remoteRepository(" + count + ")";
96                     RemoteRepositoryConfiguration o = (RemoteRepositoryConfiguration) iter.next();
97                     writeRemoteRepositoryConfiguration(prefix + name + ".", o, registry);
98                 }
99             }
100             if (value.getProxyConnectors() != null && value.getProxyConnectors().size() > 0
101             ) {
102                 registry.removeSubset(prefix + "proxyConnectors");
103
104                 int count = 0;
105                 for (Iterator iter = value.getProxyConnectors().iterator(); iter.hasNext(); count++) {
106                     String name = "proxyConnectors.proxyConnector(" + count + ")";
107                     ProxyConnectorConfiguration o = (ProxyConnectorConfiguration) iter.next();
108                     writeProxyConnectorConfiguration(prefix + name + ".", o, registry);
109                 }
110             }
111             if (value.getNetworkProxies() != null && value.getNetworkProxies().size() > 0
112             ) {
113                 registry.removeSubset(prefix + "networkProxies");
114
115                 int count = 0;
116                 for (Iterator iter = value.getNetworkProxies().iterator(); iter.hasNext(); count++) {
117                     String name = "networkProxies.networkProxy(" + count + ")";
118                     NetworkProxyConfiguration o = (NetworkProxyConfiguration) iter.next();
119                     writeNetworkProxyConfiguration(prefix + name + ".", o, registry);
120                 }
121             }
122             if (value.getLegacyArtifactPaths() != null && value.getLegacyArtifactPaths().size() > 0
123             ) {
124                 registry.removeSubset(prefix + "legacyArtifactPaths");
125
126                 int count = 0;
127                 for (Iterator iter = value.getLegacyArtifactPaths().iterator(); iter.hasNext(); count++) {
128                     String name = "legacyArtifactPaths.legacyArtifactPath(" + count + ")";
129                     LegacyArtifactPath o = (LegacyArtifactPath) iter.next();
130                     writeLegacyArtifactPath(prefix + name + ".", o, registry);
131                 }
132             }
133             if (value.getRepositoryScanning() != null
134             ) {
135                 writeRepositoryScanningConfiguration(prefix + "repositoryScanning.", value.getRepositoryScanning(), registry);
136             }
137             if (value.getWebapp() != null
138             ) {
139                 writeWebappConfiguration(prefix + "webapp.", value.getWebapp(), registry);
140             }
141             if (value.getOrganisationInfo() != null
142             ) {
143                 writeOrganisationInformation(prefix + "organisationInfo.", value.getOrganisationInfo(), registry);
144             }
145             if (value.getNetworkConfiguration() != null
146             ) {
147                 writeNetworkConfiguration(prefix + "networkConfiguration.", value.getNetworkConfiguration(), registry);
148             }
149             if (value.getRedbackRuntimeConfiguration() != null
150             ) {
151                 writeRedbackRuntimeConfiguration(prefix + "redbackRuntimeConfiguration.", value.getRedbackRuntimeConfiguration(), registry);
152             }
153             if (value.getArchivaRuntimeConfiguration() != null
154             ) {
155                 writeArchivaRuntimeConfiguration(prefix + "archivaRuntimeConfiguration.", value.getArchivaRuntimeConfiguration(), registry);
156             }
157             if (value.getProxyConnectorRuleConfigurations() != null && value.getProxyConnectorRuleConfigurations().size() > 0
158             ) {
159                 registry.removeSubset(prefix + "proxyConnectorRuleConfigurations");
160
161                 int count = 0;
162                 for (Iterator iter = value.getProxyConnectorRuleConfigurations().iterator(); iter.hasNext(); count++) {
163                     String name = "proxyConnectorRuleConfigurations.proxyConnectorRuleConfiguration(" + count + ")";
164                     ProxyConnectorRuleConfiguration o = (ProxyConnectorRuleConfiguration) iter.next();
165                     writeProxyConnectorRuleConfiguration(prefix + name + ".", o, registry);
166                 }
167             }
168             if (value.getArchivaDefaultConfiguration() != null
169             ) {
170                 writeArchivaDefaultConfiguration(prefix + "archivaDefaultConfiguration.", value.getArchivaDefaultConfiguration(), registry);
171             }
172         }
173     }
174
175     private void writeAbstractRepositoryConfiguration(String prefix, AbstractRepositoryConfiguration value, Registry registry) {
176         if (value != null) {
177             if (value.getId() != null
178             ) {
179                 String id = "id";
180                 registry.setString(prefix + id, value.getId());
181             }
182             if (value.getType() != null && !value.getType().equals("MAVEN")
183             ) {
184                 String type = "type";
185                 registry.setString(prefix + type, value.getType());
186             }
187             if (value.getName() != null
188             ) {
189                 String name = "name";
190                 registry.setString(prefix + name, value.getName());
191             }
192             if (value.getLayout() != null && !value.getLayout().equals("default")
193             ) {
194                 String layout = "layout";
195                 registry.setString(prefix + layout, value.getLayout());
196             }
197             if (value.getIndexDir() != null && !value.getIndexDir().equals("")
198             ) {
199                 String indexDir = "indexDir";
200                 registry.setString(prefix + indexDir, value.getIndexDir());
201             }
202             if (value.getPackedIndexDir() != null && !value.getPackedIndexDir().equals("")
203             ) {
204                 String packedIndexDir = "packedIndexDir";
205                 registry.setString(prefix + packedIndexDir, value.getPackedIndexDir());
206             }
207             if (value.getDescription() != null && !value.getDescription().equals("")
208             ) {
209                 String description = "description";
210                 registry.setString(prefix + description, value.getDescription());
211             }
212         }
213     }
214
215     private void writeRemoteRepositoryConfiguration(String prefix, RemoteRepositoryConfiguration value, Registry registry) {
216         if (value != null) {
217             if (value.getUrl() != null
218             ) {
219                 String url = "url";
220                 registry.setString(prefix + url, value.getUrl());
221             }
222             if (value.getUsername() != null
223             ) {
224                 String username = "username";
225                 registry.setString(prefix + username, value.getUsername());
226             }
227             if (value.getPassword() != null
228             ) {
229                 String password = "password";
230                 registry.setString(prefix + password, value.getPassword());
231             }
232             if (value.getTimeout() != 60
233             ) {
234                 String timeout = "timeout";
235                 registry.setInt(prefix + timeout, value.getTimeout());
236             }
237             if (value.getRefreshCronExpression() != null && !value.getRefreshCronExpression().equals("0 0 08 ? * SUN")
238             ) {
239                 String refreshCronExpression = "refreshCronExpression";
240                 registry.setString(prefix + refreshCronExpression, value.getRefreshCronExpression());
241             }
242             String downloadRemoteIndex = "downloadRemoteIndex";
243             registry.setBoolean(prefix + downloadRemoteIndex, value.isDownloadRemoteIndex());
244             if (value.getRemoteIndexUrl() != null
245             ) {
246                 String remoteIndexUrl = "remoteIndexUrl";
247                 registry.setString(prefix + remoteIndexUrl, value.getRemoteIndexUrl());
248             }
249             if (value.getRemoteDownloadNetworkProxyId() != null
250             ) {
251                 String remoteDownloadNetworkProxyId = "remoteDownloadNetworkProxyId";
252                 registry.setString(prefix + remoteDownloadNetworkProxyId, value.getRemoteDownloadNetworkProxyId());
253             }
254             if (value.getRemoteDownloadTimeout() != 300
255             ) {
256                 String remoteDownloadTimeout = "remoteDownloadTimeout";
257                 registry.setInt(prefix + remoteDownloadTimeout, value.getRemoteDownloadTimeout());
258             }
259             String downloadRemoteIndexOnStartup = "downloadRemoteIndexOnStartup";
260             registry.setBoolean(prefix + downloadRemoteIndexOnStartup, value.isDownloadRemoteIndexOnStartup());
261             if (value.getExtraParameters() != null && value.getExtraParameters().size() > 0
262             ) {
263                 registry.removeSubset(prefix + "extraParameters");
264
265                 for (Iterator iter = value.getExtraParameters().keySet().iterator(); iter.hasNext(); ) {
266                     String key = (String) iter.next();
267                     String v = (String) value.getExtraParameters().get(key);
268
269                     registry.setString(prefix + "extraParameters." + key, v);
270                 }
271             }
272             if (value.getExtraHeaders() != null && value.getExtraHeaders().size() > 0
273             ) {
274                 registry.removeSubset(prefix + "extraHeaders");
275
276                 for (Iterator iter = value.getExtraHeaders().keySet().iterator(); iter.hasNext(); ) {
277                     String key = (String) iter.next();
278                     String v = (String) value.getExtraHeaders().get(key);
279
280                     registry.setString(prefix + "extraHeaders." + key, v);
281                 }
282             }
283             if (value.getCheckPath() != null
284             ) {
285                 String checkPath = "checkPath";
286                 registry.setString(prefix + checkPath, value.getCheckPath());
287             }
288             if (value.getId() != null
289             ) {
290                 String id = "id";
291                 registry.setString(prefix + id, value.getId());
292             }
293             if (value.getType() != null && !value.getType().equals("MAVEN")
294             ) {
295                 String type = "type";
296                 registry.setString(prefix + type, value.getType());
297             }
298             if (value.getName() != null
299             ) {
300                 String name = "name";
301                 registry.setString(prefix + name, value.getName());
302             }
303             if (value.getLayout() != null && !value.getLayout().equals("default")
304             ) {
305                 String layout = "layout";
306                 registry.setString(prefix + layout, value.getLayout());
307             }
308             if (value.getIndexDir() != null && !value.getIndexDir().equals("")
309             ) {
310                 String indexDir = "indexDir";
311                 registry.setString(prefix + indexDir, value.getIndexDir());
312             }
313             if (value.getPackedIndexDir() != null && !value.getPackedIndexDir().equals("")
314             ) {
315                 String packedIndexDir = "packedIndexDir";
316                 registry.setString(prefix + packedIndexDir, value.getPackedIndexDir());
317             }
318             if (value.getDescription() != null && !value.getDescription().equals("")
319             ) {
320                 String description = "description";
321                 registry.setString(prefix + description, value.getDescription());
322             }
323         }
324     }
325
326     private void writeManagedRepositoryConfiguration(String prefix, ManagedRepositoryConfiguration value, Registry registry) {
327         if (value != null) {
328             if (value.getLocation() != null
329             ) {
330                 String location = "location";
331                 registry.setString(prefix + location, value.getLocation());
332             }
333             String releases = "releases";
334             registry.setBoolean(prefix + releases, value.isReleases());
335             String blockRedeployments = "blockRedeployments";
336             registry.setBoolean(prefix + blockRedeployments, value.isBlockRedeployments());
337             String snapshots = "snapshots";
338             registry.setBoolean(prefix + snapshots, value.isSnapshots());
339             String scanned = "scanned";
340             registry.setBoolean(prefix + scanned, value.isScanned());
341             if (value.getRefreshCronExpression() != null && !value.getRefreshCronExpression().equals("0 0 * * * ?")
342             ) {
343                 String refreshCronExpression = "refreshCronExpression";
344                 registry.setString(prefix + refreshCronExpression, value.getRefreshCronExpression());
345             }
346             if (value.getRetentionCount() != 2
347             ) {
348                 String retentionCount = "retentionCount";
349                 registry.setInt(prefix + retentionCount, value.getRetentionCount());
350             }
351             if (value.getRetentionPeriod() != 100
352             ) {
353                 String retentionPeriod = "retentionPeriod";
354                 registry.setInt(prefix + retentionPeriod, value.getRetentionPeriod());
355             }
356             String deleteReleasedSnapshots = "deleteReleasedSnapshots";
357             registry.setBoolean(prefix + deleteReleasedSnapshots, value.isDeleteReleasedSnapshots());
358             String skipPackedIndexCreation = "skipPackedIndexCreation";
359             registry.setBoolean(prefix + skipPackedIndexCreation, value.isSkipPackedIndexCreation());
360             String stageRepoNeeded = "stageRepoNeeded";
361             registry.setBoolean(prefix + stageRepoNeeded, value.isStageRepoNeeded());
362             if (value.getId() != null
363             ) {
364                 String id = "id";
365                 registry.setString(prefix + id, value.getId());
366             }
367             if (value.getType() != null && !value.getType().equals("MAVEN")
368             ) {
369                 String type = "type";
370                 registry.setString(prefix + type, value.getType());
371             }
372             if (value.getName() != null
373             ) {
374                 String name = "name";
375                 registry.setString(prefix + name, value.getName());
376             }
377             if (value.getLayout() != null && !value.getLayout().equals("default")
378             ) {
379                 String layout = "layout";
380                 registry.setString(prefix + layout, value.getLayout());
381             }
382             if (value.getIndexDir() != null && !value.getIndexDir().equals("")
383             ) {
384                 String indexDir = "indexDir";
385                 registry.setString(prefix + indexDir, value.getIndexDir());
386             }
387             if (value.getPackedIndexDir() != null && !value.getPackedIndexDir().equals("")
388             ) {
389                 String packedIndexDir = "packedIndexDir";
390                 registry.setString(prefix + packedIndexDir, value.getPackedIndexDir());
391             }
392             if (value.getDescription() != null && !value.getDescription().equals("")
393             ) {
394                 String description = "description";
395                 registry.setString(prefix + description, value.getDescription());
396             }
397         }
398     }
399
400     private void writeLegacyArtifactPath(String prefix, LegacyArtifactPath value, Registry registry) {
401         if (value != null) {
402             if (value.getPath() != null
403             ) {
404                 String path = "path";
405                 registry.setString(prefix + path, value.getPath());
406             }
407             if (value.getArtifact() != null
408             ) {
409                 String artifact = "artifact";
410                 registry.setString(prefix + artifact, value.getArtifact());
411             }
412         }
413     }
414
415     private void writeRepositoryGroupConfiguration(String prefix, RepositoryGroupConfiguration value, Registry registry) {
416         if (value != null) {
417             if (value.getId() != null
418             ) {
419                 String id = "id";
420                 registry.setString(prefix + id, value.getId());
421             }
422             if (value.getName() != null) {
423                 registry.setString(prefix + "name", value.getName());
424             }
425             if (value.getType() != null) {
426                 registry.setString(prefix + "type", value.getType());
427             }
428             if (value.getLocation()!=null) {
429                 registry.setString( prefix+"location", value.getType( ) );
430             }
431             if (value.getMergedIndexPath() != null && !value.getMergedIndexPath().equals(".indexer")
432             ) {
433                 String mergedIndexPath = "mergedIndexPath";
434                 registry.setString(prefix + mergedIndexPath, value.getMergedIndexPath());
435             }
436             if (value.getMergedIndexTtl() != 30
437             ) {
438                 String mergedIndexTtl = "mergedIndexTtl";
439                 registry.setInt(prefix + mergedIndexTtl, value.getMergedIndexTtl());
440             }
441             if (value.getCronExpression() != null && !value.getCronExpression().equals("")
442             ) {
443                 String cronExpression = "cronExpression";
444                 registry.setString(prefix + cronExpression, value.getCronExpression());
445             }
446             if (value.getRepositories() != null && value.getRepositories().size() > 0
447             ) {
448                 registry.removeSubset(prefix + "repositories");
449
450                 int count = 0;
451                 for (Iterator iter = value.getRepositories().iterator(); iter.hasNext(); count++) {
452                     String name = "repositories.repository(" + count + ")";
453                     String repository = (String) iter.next();
454                     registry.setString(prefix + name, repository);
455                 }
456             }
457         }
458     }
459
460     private void writeRepositoryCheckPath(String prefix, RepositoryCheckPath value, Registry registry) {
461         if (value != null) {
462             if (value.getUrl() != null
463             ) {
464                 String url = "url";
465                 registry.setString(prefix + url, value.getUrl());
466             }
467             if (value.getPath() != null
468             ) {
469                 String path = "path";
470                 registry.setString(prefix + path, value.getPath());
471             }
472         }
473     }
474
475     private void writeAbstractRepositoryConnectorConfiguration(String prefix, AbstractRepositoryConnectorConfiguration value, Registry registry) {
476         if (value != null) {
477             if (value.getSourceRepoId() != null
478             ) {
479                 String sourceRepoId = "sourceRepoId";
480                 registry.setString(prefix + sourceRepoId, value.getSourceRepoId());
481             }
482             if (value.getTargetRepoId() != null
483             ) {
484                 String targetRepoId = "targetRepoId";
485                 registry.setString(prefix + targetRepoId, value.getTargetRepoId());
486             }
487             if (value.getProxyId() != null
488             ) {
489                 String proxyId = "proxyId";
490                 registry.setString(prefix + proxyId, value.getProxyId());
491             }
492             if (value.getBlackListPatterns() != null && value.getBlackListPatterns().size() > 0
493             ) {
494                 registry.removeSubset(prefix + "blackListPatterns");
495
496                 int count = 0;
497                 for (Iterator iter = value.getBlackListPatterns().iterator(); iter.hasNext(); count++) {
498                     String name = "blackListPatterns.blackListPattern(" + count + ")";
499                     String blackListPattern = (String) iter.next();
500                     registry.setString(prefix + name, blackListPattern);
501                 }
502             }
503             if (value.getWhiteListPatterns() != null && value.getWhiteListPatterns().size() > 0
504             ) {
505                 registry.removeSubset(prefix + "whiteListPatterns");
506
507                 int count = 0;
508                 for (Iterator iter = value.getWhiteListPatterns().iterator(); iter.hasNext(); count++) {
509                     String name = "whiteListPatterns.whiteListPattern(" + count + ")";
510                     String whiteListPattern = (String) iter.next();
511                     registry.setString(prefix + name, whiteListPattern);
512                 }
513             }
514             if (value.getPolicies() != null && value.getPolicies().size() > 0
515             ) {
516                 registry.removeSubset(prefix + "policies");
517
518                 for (Iterator iter = value.getPolicies().keySet().iterator(); iter.hasNext(); ) {
519                     String key = (String) iter.next();
520                     String v = (String) value.getPolicies().get(key);
521
522                     registry.setString(prefix + "policies." + key, v);
523                 }
524             }
525             if (value.getProperties() != null && value.getProperties().size() > 0
526             ) {
527                 registry.removeSubset(prefix + "properties");
528
529                 for (Iterator iter = value.getProperties().keySet().iterator(); iter.hasNext(); ) {
530                     String key = (String) iter.next();
531                     String v = (String) value.getProperties().get(key);
532
533                     registry.setString(prefix + "properties." + key, v);
534                 }
535             }
536             String disabled = "disabled";
537             registry.setBoolean(prefix + disabled, value.isDisabled());
538         }
539     }
540
541     private void writeProxyConnectorRuleConfiguration(String prefix, ProxyConnectorRuleConfiguration value, Registry registry) {
542         if (value != null) {
543             if (value.getRuleType() != null
544             ) {
545                 String ruleType = "ruleType";
546                 registry.setString(prefix + ruleType, value.getRuleType());
547             }
548             if (value.getPattern() != null
549             ) {
550                 String pattern = "pattern";
551                 registry.setString(prefix + pattern, value.getPattern());
552             }
553             if (value.getProxyConnectors() != null && value.getProxyConnectors().size() > 0
554             ) {
555                 registry.removeSubset(prefix + "proxyConnectors");
556
557                 int count = 0;
558                 for (Iterator iter = value.getProxyConnectors().iterator(); iter.hasNext(); count++) {
559                     String name = "proxyConnectors.proxyConnector(" + count + ")";
560                     ProxyConnectorConfiguration o = (ProxyConnectorConfiguration) iter.next();
561                     writeProxyConnectorConfiguration(prefix + name + ".", o, registry);
562                 }
563             }
564         }
565     }
566
567     private void writeProxyConnectorConfiguration(String prefix, ProxyConnectorConfiguration value, Registry registry) {
568         if (value != null) {
569             if (value.getOrder() != 0
570             ) {
571                 String order = "order";
572                 registry.setInt(prefix + order, value.getOrder());
573             }
574             if (value.getSourceRepoId() != null
575             ) {
576                 String sourceRepoId = "sourceRepoId";
577                 registry.setString(prefix + sourceRepoId, value.getSourceRepoId());
578             }
579             if (value.getTargetRepoId() != null
580             ) {
581                 String targetRepoId = "targetRepoId";
582                 registry.setString(prefix + targetRepoId, value.getTargetRepoId());
583             }
584             if (value.getProxyId() != null
585             ) {
586                 String proxyId = "proxyId";
587                 registry.setString(prefix + proxyId, value.getProxyId());
588             }
589             if (value.getBlackListPatterns() != null && value.getBlackListPatterns().size() > 0
590             ) {
591                 registry.removeSubset(prefix + "blackListPatterns");
592
593                 int count = 0;
594                 for (Iterator iter = value.getBlackListPatterns().iterator(); iter.hasNext(); count++) {
595                     String name = "blackListPatterns.blackListPattern(" + count + ")";
596                     String blackListPattern = (String) iter.next();
597                     registry.setString(prefix + name, blackListPattern);
598                 }
599             }
600             if (value.getWhiteListPatterns() != null && value.getWhiteListPatterns().size() > 0
601             ) {
602                 registry.removeSubset(prefix + "whiteListPatterns");
603
604                 int count = 0;
605                 for (Iterator iter = value.getWhiteListPatterns().iterator(); iter.hasNext(); count++) {
606                     String name = "whiteListPatterns.whiteListPattern(" + count + ")";
607                     String whiteListPattern = (String) iter.next();
608                     registry.setString(prefix + name, whiteListPattern);
609                 }
610             }
611             if (value.getPolicies() != null && value.getPolicies().size() > 0
612             ) {
613                 registry.removeSubset(prefix + "policies");
614
615                 for (Iterator iter = value.getPolicies().keySet().iterator(); iter.hasNext(); ) {
616                     String key = (String) iter.next();
617                     String v = (String) value.getPolicies().get(key);
618
619                     registry.setString(prefix + "policies." + key, v);
620                 }
621             }
622             if (value.getProperties() != null && value.getProperties().size() > 0
623             ) {
624                 registry.removeSubset(prefix + "properties");
625
626                 for (Iterator iter = value.getProperties().keySet().iterator(); iter.hasNext(); ) {
627                     String key = (String) iter.next();
628                     String v = (String) value.getProperties().get(key);
629
630                     registry.setString(prefix + "properties." + key, v);
631                 }
632             }
633             String disabled = "disabled";
634             registry.setBoolean(prefix + disabled, value.isDisabled());
635         }
636     }
637
638     private void writeSyncConnectorConfiguration(String prefix, SyncConnectorConfiguration value, Registry registry) {
639         if (value != null) {
640             if (value.getCronExpression() != null && !value.getCronExpression().equals("0 0 * * * ?")
641             ) {
642                 String cronExpression = "cronExpression";
643                 registry.setString(prefix + cronExpression, value.getCronExpression());
644             }
645             if (value.getMethod() != null && !value.getMethod().equals("rsync")
646             ) {
647                 String method = "method";
648                 registry.setString(prefix + method, value.getMethod());
649             }
650             if (value.getSourceRepoId() != null
651             ) {
652                 String sourceRepoId = "sourceRepoId";
653                 registry.setString(prefix + sourceRepoId, value.getSourceRepoId());
654             }
655             if (value.getTargetRepoId() != null
656             ) {
657                 String targetRepoId = "targetRepoId";
658                 registry.setString(prefix + targetRepoId, value.getTargetRepoId());
659             }
660             if (value.getProxyId() != null
661             ) {
662                 String proxyId = "proxyId";
663                 registry.setString(prefix + proxyId, value.getProxyId());
664             }
665             if (value.getBlackListPatterns() != null && value.getBlackListPatterns().size() > 0
666             ) {
667                 registry.removeSubset(prefix + "blackListPatterns");
668
669                 int count = 0;
670                 for (Iterator iter = value.getBlackListPatterns().iterator(); iter.hasNext(); count++) {
671                     String name = "blackListPatterns.blackListPattern(" + count + ")";
672                     String blackListPattern = (String) iter.next();
673                     registry.setString(prefix + name, blackListPattern);
674                 }
675             }
676             if (value.getWhiteListPatterns() != null && value.getWhiteListPatterns().size() > 0
677             ) {
678                 registry.removeSubset(prefix + "whiteListPatterns");
679
680                 int count = 0;
681                 for (Iterator iter = value.getWhiteListPatterns().iterator(); iter.hasNext(); count++) {
682                     String name = "whiteListPatterns.whiteListPattern(" + count + ")";
683                     String whiteListPattern = (String) iter.next();
684                     registry.setString(prefix + name, whiteListPattern);
685                 }
686             }
687             if (value.getPolicies() != null && value.getPolicies().size() > 0
688             ) {
689                 registry.removeSubset(prefix + "policies");
690
691                 for (Iterator iter = value.getPolicies().keySet().iterator(); iter.hasNext(); ) {
692                     String key = (String) iter.next();
693                     String v = (String) value.getPolicies().get(key);
694
695                     registry.setString(prefix + "policies." + key, v);
696                 }
697             }
698             if (value.getProperties() != null && value.getProperties().size() > 0
699             ) {
700                 registry.removeSubset(prefix + "properties");
701
702                 for (Iterator iter = value.getProperties().keySet().iterator(); iter.hasNext(); ) {
703                     String key = (String) iter.next();
704                     String v = (String) value.getProperties().get(key);
705
706                     registry.setString(prefix + "properties." + key, v);
707                 }
708             }
709             String disabled = "disabled";
710             registry.setBoolean(prefix + disabled, value.isDisabled());
711         }
712     }
713
714     private void writeNetworkProxyConfiguration(String prefix, NetworkProxyConfiguration value, Registry registry) {
715         if (value != null) {
716             if (value.getId() != null
717             ) {
718                 String id = "id";
719                 registry.setString(prefix + id, value.getId());
720             }
721             if (value.getProtocol() != null && !value.getProtocol().equals("http")
722             ) {
723                 String protocol = "protocol";
724                 registry.setString(prefix + protocol, value.getProtocol());
725             }
726             if (value.getHost() != null
727             ) {
728                 String host = "host";
729                 registry.setString(prefix + host, value.getHost());
730             }
731             if (value.getPort() != 8080
732             ) {
733                 String port = "port";
734                 registry.setInt(prefix + port, value.getPort());
735             }
736             if (value.getUsername() != null
737             ) {
738                 String username = "username";
739                 registry.setString(prefix + username, value.getUsername());
740             }
741             if (value.getPassword() != null
742             ) {
743                 String password = "password";
744                 registry.setString(prefix + password, value.getPassword());
745             }
746             String useNtlm = "useNtlm";
747             registry.setBoolean(prefix + useNtlm, value.isUseNtlm());
748         }
749     }
750
751     private void writeRepositoryScanningConfiguration(String prefix, RepositoryScanningConfiguration value, Registry registry) {
752         if (value != null) {
753             if (value.getFileTypes() != null && value.getFileTypes().size() > 0
754             ) {
755                 registry.removeSubset(prefix + "fileTypes");
756
757                 int count = 0;
758                 for (Iterator iter = value.getFileTypes().iterator(); iter.hasNext(); count++) {
759                     String name = "fileTypes.fileType(" + count + ")";
760                     FileType o = (FileType) iter.next();
761                     writeFileType(prefix + name + ".", o, registry);
762                 }
763             }
764             if (value.getKnownContentConsumers() != null && value.getKnownContentConsumers().size() > 0
765             ) {
766                 registry.removeSubset(prefix + "knownContentConsumers");
767
768                 int count = 0;
769                 for (Iterator iter = value.getKnownContentConsumers().iterator(); iter.hasNext(); count++) {
770                     String name = "knownContentConsumers.knownContentConsumer(" + count + ")";
771                     String knownContentConsumer = (String) iter.next();
772                     registry.setString(prefix + name, knownContentConsumer);
773                 }
774             }
775             if (value.getInvalidContentConsumers() != null && value.getInvalidContentConsumers().size() > 0
776             ) {
777                 registry.removeSubset(prefix + "invalidContentConsumers");
778
779                 int count = 0;
780                 for (Iterator iter = value.getInvalidContentConsumers().iterator(); iter.hasNext(); count++) {
781                     String name = "invalidContentConsumers.invalidContentConsumer(" + count + ")";
782                     String invalidContentConsumer = (String) iter.next();
783                     registry.setString(prefix + name, invalidContentConsumer);
784                 }
785             }
786         }
787     }
788
789     private void writeFileType(String prefix, FileType value, Registry registry) {
790         if (value != null) {
791             if (value.getId() != null
792             ) {
793                 String id = "id";
794                 registry.setString(prefix + id, value.getId());
795             }
796             if (value.getPatterns() != null && value.getPatterns().size() > 0
797             ) {
798                 registry.removeSubset(prefix + "patterns");
799
800                 int count = 0;
801                 for (Iterator iter = value.getPatterns().iterator(); iter.hasNext(); count++) {
802                     String name = "patterns.pattern(" + count + ")";
803                     String pattern = (String) iter.next();
804                     registry.setString(prefix + name, pattern);
805                 }
806             }
807         }
808     }
809
810     private void writeOrganisationInformation(String prefix, OrganisationInformation value, Registry registry) {
811         if (value != null) {
812             if (value.getName() != null
813             ) {
814                 String name = "name";
815                 registry.setString(prefix + name, value.getName());
816             }
817             if (value.getUrl() != null
818             ) {
819                 String url = "url";
820                 registry.setString(prefix + url, value.getUrl());
821             }
822             if (value.getLogoLocation() != null
823             ) {
824                 String logoLocation = "logoLocation";
825                 registry.setString(prefix + logoLocation, value.getLogoLocation());
826             }
827         }
828     }
829
830     private void writeWebappConfiguration(String prefix, WebappConfiguration value, Registry registry) {
831         if (value != null) {
832             if (value.getUi() != null
833             ) {
834                 writeUserInterfaceOptions(prefix + "ui.", value.getUi(), registry);
835             }
836         }
837     }
838
839     private void writeUserInterfaceOptions(String prefix, UserInterfaceOptions value, Registry registry) {
840         if (value != null) {
841             String showFindArtifacts = "showFindArtifacts";
842             registry.setBoolean(prefix + showFindArtifacts, value.isShowFindArtifacts());
843             String appletFindEnabled = "appletFindEnabled";
844             registry.setBoolean(prefix + appletFindEnabled, value.isAppletFindEnabled());
845             String disableEasterEggs = "disableEasterEggs";
846             registry.setBoolean(prefix + disableEasterEggs, value.isDisableEasterEggs());
847             if (value.getApplicationUrl() != null
848             ) {
849                 String applicationUrl = "applicationUrl";
850                 registry.setString(prefix + applicationUrl, value.getApplicationUrl());
851             }
852             String disableRegistration = "disableRegistration";
853             registry.setBoolean(prefix + disableRegistration, value.isDisableRegistration());
854         }
855     }
856
857     private void writeNetworkConfiguration(String prefix, NetworkConfiguration value, Registry registry) {
858         if (value != null) {
859             if (value.getMaxTotal() != 30
860             ) {
861                 String maxTotal = "maxTotal";
862                 registry.setInt(prefix + maxTotal, value.getMaxTotal());
863             }
864             if (value.getMaxTotalPerHost() != 30
865             ) {
866                 String maxTotalPerHost = "maxTotalPerHost";
867                 registry.setInt(prefix + maxTotalPerHost, value.getMaxTotalPerHost());
868             }
869             String usePooling = "usePooling";
870             registry.setBoolean(prefix + usePooling, value.isUsePooling());
871         }
872     }
873
874     private void writeArchivaRuntimeConfiguration(String prefix, ArchivaRuntimeConfiguration value, Registry registry) {
875         if (value != null) {
876             if (value.getUrlFailureCacheConfiguration() != null
877             ) {
878                 writeCacheConfiguration(prefix + "urlFailureCacheConfiguration.", value.getUrlFailureCacheConfiguration(), registry);
879             }
880             if (value.getFileLockConfiguration() != null
881             ) {
882                 writeFileLockConfiguration(prefix + "fileLockConfiguration.", value.getFileLockConfiguration(), registry);
883             }
884             if (value.getDataDirectory() != null
885             ) {
886                 String dataDirectory = "dataDirectory";
887                 registry.setString(prefix + dataDirectory, value.getDataDirectory());
888             }
889             if (value.getRepositoryBaseDirectory() != null
890             ) {
891                 String repositoryBaseDirectory = "repositoryBaseDirectory";
892                 registry.setString(prefix + repositoryBaseDirectory, value.getRepositoryBaseDirectory());
893             }
894             if (value.getRemoteRepositoryBaseDirectory() != null
895             ) {
896                 String remoteRepositoryBaseDirectory = "remoteRepositoryBaseDirectory";
897                 registry.setString(prefix + remoteRepositoryBaseDirectory, value.getRemoteRepositoryBaseDirectory());
898             }
899             if (value.getRepositoryGroupBaseDirectory() != null
900             ) {
901                 String repositoryGroupBaseDirectory = "repositoryGroupBaseDirectory";
902                 registry.setString(prefix + repositoryGroupBaseDirectory, value.getRepositoryGroupBaseDirectory());
903             }
904
905             if (value.getDefaultLanguage() != null && !value.getDefaultLanguage().equals("en-US")
906             ) {
907                 String defaultLanguage = "defaultLanguage";
908                 registry.setString(prefix + defaultLanguage, value.getDefaultLanguage());
909             }
910             if (value.getLanguageRange() != null && !value.getLanguageRange().equals("en,fr,de")
911             ) {
912                 String languageRange = "languageRange";
913                 registry.setString(prefix + languageRange, value.getLanguageRange());
914             }
915             writeList(registry, value.getChecksumTypes(), prefix+"checksumTypes", "type");
916         }
917     }
918
919     private void writeRedbackRuntimeConfiguration(String prefix, RedbackRuntimeConfiguration value, Registry registry) {
920         if (value != null) {
921             String migratedFromRedbackConfiguration = "migratedFromRedbackConfiguration";
922             registry.setBoolean(prefix + migratedFromRedbackConfiguration, value.isMigratedFromRedbackConfiguration());
923             if (value.getUserManagerImpls() != null && value.getUserManagerImpls().size() > 0
924             ) {
925                 registry.removeSubset(prefix + "userManagerImpls");
926
927                 int count = 0;
928                 for (Iterator iter = value.getUserManagerImpls().iterator(); iter.hasNext(); count++) {
929                     String name = "userManagerImpls.userManagerImpl(" + count + ")";
930                     String userManagerImpl = (String) iter.next();
931                     registry.setString(prefix + name, userManagerImpl);
932                 }
933             }
934             if (value.getRbacManagerImpls() != null && value.getRbacManagerImpls().size() > 0
935             ) {
936                 registry.removeSubset(prefix + "rbacManagerImpls");
937
938                 int count = 0;
939                 for (Iterator iter = value.getRbacManagerImpls().iterator(); iter.hasNext(); count++) {
940                     String name = "rbacManagerImpls.rbacManagerImpl(" + count + ")";
941                     String rbacManagerImpl = (String) iter.next();
942                     registry.setString(prefix + name, rbacManagerImpl);
943                 }
944             }
945             if (value.getLdapConfiguration() != null
946             ) {
947                 writeLdapConfiguration(prefix + "ldapConfiguration.", value.getLdapConfiguration(), registry);
948             }
949             if (value.getLdapGroupMappings() != null && value.getLdapGroupMappings().size() > 0
950             ) {
951                 registry.removeSubset(prefix + "ldapGroupMappings");
952
953                 int count = 0;
954                 for (Iterator iter = value.getLdapGroupMappings().iterator(); iter.hasNext(); count++) {
955                     String name = "ldapGroupMappings.ldapGroupMapping(" + count + ")";
956                     LdapGroupMapping o = (LdapGroupMapping) iter.next();
957                     writeLdapGroupMapping(prefix + name + ".", o, registry);
958                 }
959             }
960             if (value.getConfigurationProperties() != null && value.getConfigurationProperties().size() > 0
961             ) {
962                 registry.removeSubset(prefix + "configurationProperties");
963
964                 for (Iterator iter = value.getConfigurationProperties().keySet().iterator(); iter.hasNext(); ) {
965                     String key = (String) iter.next();
966                     String v = (String) value.getConfigurationProperties().get(key);
967
968                     registry.setString(prefix + "configurationProperties." + key, v);
969                 }
970             }
971             String useUsersCache = "useUsersCache";
972             registry.setBoolean(prefix + useUsersCache, value.isUseUsersCache());
973             if (value.getUsersCacheConfiguration() != null
974             ) {
975                 writeCacheConfiguration(prefix + "usersCacheConfiguration.", value.getUsersCacheConfiguration(), registry);
976             }
977         }
978     }
979
980     private void writeArchivaDefaultConfiguration(String prefix, ArchivaDefaultConfiguration value, Registry registry) {
981         if (value != null) {
982             if (value.getDefaultCheckPaths() != null && value.getDefaultCheckPaths().size() > 0
983             ) {
984                 registry.removeSubset(prefix + "defaultCheckPaths");
985
986                 int count = 0;
987                 for (Iterator iter = value.getDefaultCheckPaths().iterator(); iter.hasNext(); count++) {
988                     String name = "defaultCheckPaths.defaultCheckPath(" + count + ")";
989                     RepositoryCheckPath o = (RepositoryCheckPath) iter.next();
990                     writeRepositoryCheckPath(prefix + name + ".", o, registry);
991                 }
992             }
993         }
994     }
995
996     private void writeLdapConfiguration(String prefix, LdapConfiguration value, Registry registry) {
997         if (value != null) {
998             if (value.getHostName() != null
999             ) {
1000                 String hostName = "hostName";
1001                 registry.setString(prefix + hostName, value.getHostName());
1002             }
1003             if (value.getPort() != 0
1004             ) {
1005                 String port = "port";
1006                 registry.setInt(prefix + port, value.getPort());
1007             }
1008             String ssl = "ssl";
1009             registry.setBoolean(prefix + ssl, value.isSsl());
1010             if (value.getBaseDn() != null
1011             ) {
1012                 String baseDn = "baseDn";
1013                 registry.setString(prefix + baseDn, value.getBaseDn());
1014             }
1015             if (value.getBaseGroupsDn() != null
1016             ) {
1017                 String baseGroupsDn = "baseGroupsDn";
1018                 registry.setString(prefix + baseGroupsDn, value.getBaseGroupsDn());
1019             }
1020             if (value.getContextFactory() != null
1021             ) {
1022                 String contextFactory = "contextFactory";
1023                 registry.setString(prefix + contextFactory, value.getContextFactory());
1024             }
1025             if (value.getBindDn() != null
1026             ) {
1027                 String bindDn = "bindDn";
1028                 registry.setString(prefix + bindDn, value.getBindDn());
1029             }
1030             if (value.getPassword() != null
1031             ) {
1032                 String password = "password";
1033                 registry.setString(prefix + password, value.getPassword());
1034             }
1035             if (value.getAuthenticationMethod() != null
1036             ) {
1037                 String authenticationMethod = "authenticationMethod";
1038                 registry.setString(prefix + authenticationMethod, value.getAuthenticationMethod());
1039             }
1040             String bindAuthenticatorEnabled = "bindAuthenticatorEnabled";
1041             registry.setBoolean(prefix + bindAuthenticatorEnabled, value.isBindAuthenticatorEnabled());
1042             String writable = "writable";
1043             registry.setBoolean(prefix + writable, value.isWritable());
1044             String useRoleNameAsGroup = "useRoleNameAsGroup";
1045             registry.setBoolean(prefix + useRoleNameAsGroup, value.isUseRoleNameAsGroup());
1046             if (value.getExtraProperties() != null && value.getExtraProperties().size() > 0
1047             ) {
1048                 registry.removeSubset(prefix + "extraProperties");
1049
1050                 for (Iterator iter = value.getExtraProperties().keySet().iterator(); iter.hasNext(); ) {
1051                     String key = (String) iter.next();
1052                     String v = (String) value.getExtraProperties().get(key);
1053
1054                     registry.setString(prefix + "extraProperties." + key, v);
1055                 }
1056             }
1057         }
1058     }
1059
1060     private void writeFileLockConfiguration(String prefix, FileLockConfiguration value, Registry registry) {
1061         if (value != null) {
1062             String skipLocking = "skipLocking";
1063             registry.setBoolean(prefix + skipLocking, value.isSkipLocking());
1064             if (value.getLockingTimeout() != 0
1065             ) {
1066                 String lockingTimeout = "lockingTimeout";
1067                 registry.setInt(prefix + lockingTimeout, value.getLockingTimeout());
1068             }
1069         }
1070     }
1071
1072     private void writeCacheConfiguration(String prefix, CacheConfiguration value, Registry registry) {
1073         if (value != null) {
1074             if (value.getTimeToIdleSeconds() != -1
1075             ) {
1076                 String timeToIdleSeconds = "timeToIdleSeconds";
1077                 registry.setInt(prefix + timeToIdleSeconds, value.getTimeToIdleSeconds());
1078             }
1079             if (value.getTimeToLiveSeconds() != -1
1080             ) {
1081                 String timeToLiveSeconds = "timeToLiveSeconds";
1082                 registry.setInt(prefix + timeToLiveSeconds, value.getTimeToLiveSeconds());
1083             }
1084             if (value.getMaxElementsInMemory() != -1
1085             ) {
1086                 String maxElementsInMemory = "maxElementsInMemory";
1087                 registry.setInt(prefix + maxElementsInMemory, value.getMaxElementsInMemory());
1088             }
1089             if (value.getMaxElementsOnDisk() != -1
1090             ) {
1091                 String maxElementsOnDisk = "maxElementsOnDisk";
1092                 registry.setInt(prefix + maxElementsOnDisk, value.getMaxElementsOnDisk());
1093             }
1094         }
1095     }
1096
1097     private void writeLdapGroupMapping(String prefix, LdapGroupMapping value, Registry registry) {
1098         if (value != null) {
1099             if (value.getGroup() != null
1100             ) {
1101                 String group = "group";
1102                 registry.setString(prefix + group, value.getGroup());
1103             }
1104             if (value.getRoleNames() != null && value.getRoleNames().size() > 0
1105             ) {
1106                 registry.removeSubset(prefix + "roleNames");
1107
1108                 int count = 0;
1109                 for (Iterator iter = value.getRoleNames().iterator(); iter.hasNext(); count++) {
1110                     String name = "roleNames.roleName(" + count + ")";
1111                     String roleName = (String) iter.next();
1112                     registry.setString(prefix + name, roleName);
1113                 }
1114             }
1115         }
1116     }
1117
1118 }