]> source.dussan.org Git - archiva.git/blob
31ffc6b9d5201bae5c42e5faf576c545300472dc
[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.redback.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.getMergedIndexPath() != null && !value.getMergedIndexPath().equals(".indexer")
423             ) {
424                 String mergedIndexPath = "mergedIndexPath";
425                 registry.setString(prefix + mergedIndexPath, value.getMergedIndexPath());
426             }
427             if (value.getMergedIndexTtl() != 30
428             ) {
429                 String mergedIndexTtl = "mergedIndexTtl";
430                 registry.setInt(prefix + mergedIndexTtl, value.getMergedIndexTtl());
431             }
432             if (value.getCronExpression() != null && !value.getCronExpression().equals("")
433             ) {
434                 String cronExpression = "cronExpression";
435                 registry.setString(prefix + cronExpression, value.getCronExpression());
436             }
437             if (value.getRepositories() != null && value.getRepositories().size() > 0
438             ) {
439                 registry.removeSubset(prefix + "repositories");
440
441                 int count = 0;
442                 for (Iterator iter = value.getRepositories().iterator(); iter.hasNext(); count++) {
443                     String name = "repositories.repository(" + count + ")";
444                     String repository = (String) iter.next();
445                     registry.setString(prefix + name, repository);
446                 }
447             }
448         }
449     }
450
451     private void writeRepositoryCheckPath(String prefix, RepositoryCheckPath value, Registry registry) {
452         if (value != null) {
453             if (value.getUrl() != null
454             ) {
455                 String url = "url";
456                 registry.setString(prefix + url, value.getUrl());
457             }
458             if (value.getPath() != null
459             ) {
460                 String path = "path";
461                 registry.setString(prefix + path, value.getPath());
462             }
463         }
464     }
465
466     private void writeAbstractRepositoryConnectorConfiguration(String prefix, AbstractRepositoryConnectorConfiguration value, Registry registry) {
467         if (value != null) {
468             if (value.getSourceRepoId() != null
469             ) {
470                 String sourceRepoId = "sourceRepoId";
471                 registry.setString(prefix + sourceRepoId, value.getSourceRepoId());
472             }
473             if (value.getTargetRepoId() != null
474             ) {
475                 String targetRepoId = "targetRepoId";
476                 registry.setString(prefix + targetRepoId, value.getTargetRepoId());
477             }
478             if (value.getProxyId() != null
479             ) {
480                 String proxyId = "proxyId";
481                 registry.setString(prefix + proxyId, value.getProxyId());
482             }
483             if (value.getBlackListPatterns() != null && value.getBlackListPatterns().size() > 0
484             ) {
485                 registry.removeSubset(prefix + "blackListPatterns");
486
487                 int count = 0;
488                 for (Iterator iter = value.getBlackListPatterns().iterator(); iter.hasNext(); count++) {
489                     String name = "blackListPatterns.blackListPattern(" + count + ")";
490                     String blackListPattern = (String) iter.next();
491                     registry.setString(prefix + name, blackListPattern);
492                 }
493             }
494             if (value.getWhiteListPatterns() != null && value.getWhiteListPatterns().size() > 0
495             ) {
496                 registry.removeSubset(prefix + "whiteListPatterns");
497
498                 int count = 0;
499                 for (Iterator iter = value.getWhiteListPatterns().iterator(); iter.hasNext(); count++) {
500                     String name = "whiteListPatterns.whiteListPattern(" + count + ")";
501                     String whiteListPattern = (String) iter.next();
502                     registry.setString(prefix + name, whiteListPattern);
503                 }
504             }
505             if (value.getPolicies() != null && value.getPolicies().size() > 0
506             ) {
507                 registry.removeSubset(prefix + "policies");
508
509                 for (Iterator iter = value.getPolicies().keySet().iterator(); iter.hasNext(); ) {
510                     String key = (String) iter.next();
511                     String v = (String) value.getPolicies().get(key);
512
513                     registry.setString(prefix + "policies." + key, v);
514                 }
515             }
516             if (value.getProperties() != null && value.getProperties().size() > 0
517             ) {
518                 registry.removeSubset(prefix + "properties");
519
520                 for (Iterator iter = value.getProperties().keySet().iterator(); iter.hasNext(); ) {
521                     String key = (String) iter.next();
522                     String v = (String) value.getProperties().get(key);
523
524                     registry.setString(prefix + "properties." + key, v);
525                 }
526             }
527             String disabled = "disabled";
528             registry.setBoolean(prefix + disabled, value.isDisabled());
529         }
530     }
531
532     private void writeProxyConnectorRuleConfiguration(String prefix, ProxyConnectorRuleConfiguration value, Registry registry) {
533         if (value != null) {
534             if (value.getRuleType() != null
535             ) {
536                 String ruleType = "ruleType";
537                 registry.setString(prefix + ruleType, value.getRuleType());
538             }
539             if (value.getPattern() != null
540             ) {
541                 String pattern = "pattern";
542                 registry.setString(prefix + pattern, value.getPattern());
543             }
544             if (value.getProxyConnectors() != null && value.getProxyConnectors().size() > 0
545             ) {
546                 registry.removeSubset(prefix + "proxyConnectors");
547
548                 int count = 0;
549                 for (Iterator iter = value.getProxyConnectors().iterator(); iter.hasNext(); count++) {
550                     String name = "proxyConnectors.proxyConnector(" + count + ")";
551                     ProxyConnectorConfiguration o = (ProxyConnectorConfiguration) iter.next();
552                     writeProxyConnectorConfiguration(prefix + name + ".", o, registry);
553                 }
554             }
555         }
556     }
557
558     private void writeProxyConnectorConfiguration(String prefix, ProxyConnectorConfiguration value, Registry registry) {
559         if (value != null) {
560             if (value.getOrder() != 0
561             ) {
562                 String order = "order";
563                 registry.setInt(prefix + order, value.getOrder());
564             }
565             if (value.getSourceRepoId() != null
566             ) {
567                 String sourceRepoId = "sourceRepoId";
568                 registry.setString(prefix + sourceRepoId, value.getSourceRepoId());
569             }
570             if (value.getTargetRepoId() != null
571             ) {
572                 String targetRepoId = "targetRepoId";
573                 registry.setString(prefix + targetRepoId, value.getTargetRepoId());
574             }
575             if (value.getProxyId() != null
576             ) {
577                 String proxyId = "proxyId";
578                 registry.setString(prefix + proxyId, value.getProxyId());
579             }
580             if (value.getBlackListPatterns() != null && value.getBlackListPatterns().size() > 0
581             ) {
582                 registry.removeSubset(prefix + "blackListPatterns");
583
584                 int count = 0;
585                 for (Iterator iter = value.getBlackListPatterns().iterator(); iter.hasNext(); count++) {
586                     String name = "blackListPatterns.blackListPattern(" + count + ")";
587                     String blackListPattern = (String) iter.next();
588                     registry.setString(prefix + name, blackListPattern);
589                 }
590             }
591             if (value.getWhiteListPatterns() != null && value.getWhiteListPatterns().size() > 0
592             ) {
593                 registry.removeSubset(prefix + "whiteListPatterns");
594
595                 int count = 0;
596                 for (Iterator iter = value.getWhiteListPatterns().iterator(); iter.hasNext(); count++) {
597                     String name = "whiteListPatterns.whiteListPattern(" + count + ")";
598                     String whiteListPattern = (String) iter.next();
599                     registry.setString(prefix + name, whiteListPattern);
600                 }
601             }
602             if (value.getPolicies() != null && value.getPolicies().size() > 0
603             ) {
604                 registry.removeSubset(prefix + "policies");
605
606                 for (Iterator iter = value.getPolicies().keySet().iterator(); iter.hasNext(); ) {
607                     String key = (String) iter.next();
608                     String v = (String) value.getPolicies().get(key);
609
610                     registry.setString(prefix + "policies." + key, v);
611                 }
612             }
613             if (value.getProperties() != null && value.getProperties().size() > 0
614             ) {
615                 registry.removeSubset(prefix + "properties");
616
617                 for (Iterator iter = value.getProperties().keySet().iterator(); iter.hasNext(); ) {
618                     String key = (String) iter.next();
619                     String v = (String) value.getProperties().get(key);
620
621                     registry.setString(prefix + "properties." + key, v);
622                 }
623             }
624             String disabled = "disabled";
625             registry.setBoolean(prefix + disabled, value.isDisabled());
626         }
627     }
628
629     private void writeSyncConnectorConfiguration(String prefix, SyncConnectorConfiguration value, Registry registry) {
630         if (value != null) {
631             if (value.getCronExpression() != null && !value.getCronExpression().equals("0 0 * * * ?")
632             ) {
633                 String cronExpression = "cronExpression";
634                 registry.setString(prefix + cronExpression, value.getCronExpression());
635             }
636             if (value.getMethod() != null && !value.getMethod().equals("rsync")
637             ) {
638                 String method = "method";
639                 registry.setString(prefix + method, value.getMethod());
640             }
641             if (value.getSourceRepoId() != null
642             ) {
643                 String sourceRepoId = "sourceRepoId";
644                 registry.setString(prefix + sourceRepoId, value.getSourceRepoId());
645             }
646             if (value.getTargetRepoId() != null
647             ) {
648                 String targetRepoId = "targetRepoId";
649                 registry.setString(prefix + targetRepoId, value.getTargetRepoId());
650             }
651             if (value.getProxyId() != null
652             ) {
653                 String proxyId = "proxyId";
654                 registry.setString(prefix + proxyId, value.getProxyId());
655             }
656             if (value.getBlackListPatterns() != null && value.getBlackListPatterns().size() > 0
657             ) {
658                 registry.removeSubset(prefix + "blackListPatterns");
659
660                 int count = 0;
661                 for (Iterator iter = value.getBlackListPatterns().iterator(); iter.hasNext(); count++) {
662                     String name = "blackListPatterns.blackListPattern(" + count + ")";
663                     String blackListPattern = (String) iter.next();
664                     registry.setString(prefix + name, blackListPattern);
665                 }
666             }
667             if (value.getWhiteListPatterns() != null && value.getWhiteListPatterns().size() > 0
668             ) {
669                 registry.removeSubset(prefix + "whiteListPatterns");
670
671                 int count = 0;
672                 for (Iterator iter = value.getWhiteListPatterns().iterator(); iter.hasNext(); count++) {
673                     String name = "whiteListPatterns.whiteListPattern(" + count + ")";
674                     String whiteListPattern = (String) iter.next();
675                     registry.setString(prefix + name, whiteListPattern);
676                 }
677             }
678             if (value.getPolicies() != null && value.getPolicies().size() > 0
679             ) {
680                 registry.removeSubset(prefix + "policies");
681
682                 for (Iterator iter = value.getPolicies().keySet().iterator(); iter.hasNext(); ) {
683                     String key = (String) iter.next();
684                     String v = (String) value.getPolicies().get(key);
685
686                     registry.setString(prefix + "policies." + key, v);
687                 }
688             }
689             if (value.getProperties() != null && value.getProperties().size() > 0
690             ) {
691                 registry.removeSubset(prefix + "properties");
692
693                 for (Iterator iter = value.getProperties().keySet().iterator(); iter.hasNext(); ) {
694                     String key = (String) iter.next();
695                     String v = (String) value.getProperties().get(key);
696
697                     registry.setString(prefix + "properties." + key, v);
698                 }
699             }
700             String disabled = "disabled";
701             registry.setBoolean(prefix + disabled, value.isDisabled());
702         }
703     }
704
705     private void writeNetworkProxyConfiguration(String prefix, NetworkProxyConfiguration value, Registry registry) {
706         if (value != null) {
707             if (value.getId() != null
708             ) {
709                 String id = "id";
710                 registry.setString(prefix + id, value.getId());
711             }
712             if (value.getProtocol() != null && !value.getProtocol().equals("http")
713             ) {
714                 String protocol = "protocol";
715                 registry.setString(prefix + protocol, value.getProtocol());
716             }
717             if (value.getHost() != null
718             ) {
719                 String host = "host";
720                 registry.setString(prefix + host, value.getHost());
721             }
722             if (value.getPort() != 8080
723             ) {
724                 String port = "port";
725                 registry.setInt(prefix + port, value.getPort());
726             }
727             if (value.getUsername() != null
728             ) {
729                 String username = "username";
730                 registry.setString(prefix + username, value.getUsername());
731             }
732             if (value.getPassword() != null
733             ) {
734                 String password = "password";
735                 registry.setString(prefix + password, value.getPassword());
736             }
737             String useNtlm = "useNtlm";
738             registry.setBoolean(prefix + useNtlm, value.isUseNtlm());
739         }
740     }
741
742     private void writeRepositoryScanningConfiguration(String prefix, RepositoryScanningConfiguration value, Registry registry) {
743         if (value != null) {
744             if (value.getFileTypes() != null && value.getFileTypes().size() > 0
745             ) {
746                 registry.removeSubset(prefix + "fileTypes");
747
748                 int count = 0;
749                 for (Iterator iter = value.getFileTypes().iterator(); iter.hasNext(); count++) {
750                     String name = "fileTypes.fileType(" + count + ")";
751                     FileType o = (FileType) iter.next();
752                     writeFileType(prefix + name + ".", o, registry);
753                 }
754             }
755             if (value.getKnownContentConsumers() != null && value.getKnownContentConsumers().size() > 0
756             ) {
757                 registry.removeSubset(prefix + "knownContentConsumers");
758
759                 int count = 0;
760                 for (Iterator iter = value.getKnownContentConsumers().iterator(); iter.hasNext(); count++) {
761                     String name = "knownContentConsumers.knownContentConsumer(" + count + ")";
762                     String knownContentConsumer = (String) iter.next();
763                     registry.setString(prefix + name, knownContentConsumer);
764                 }
765             }
766             if (value.getInvalidContentConsumers() != null && value.getInvalidContentConsumers().size() > 0
767             ) {
768                 registry.removeSubset(prefix + "invalidContentConsumers");
769
770                 int count = 0;
771                 for (Iterator iter = value.getInvalidContentConsumers().iterator(); iter.hasNext(); count++) {
772                     String name = "invalidContentConsumers.invalidContentConsumer(" + count + ")";
773                     String invalidContentConsumer = (String) iter.next();
774                     registry.setString(prefix + name, invalidContentConsumer);
775                 }
776             }
777         }
778     }
779
780     private void writeFileType(String prefix, FileType value, Registry registry) {
781         if (value != null) {
782             if (value.getId() != null
783             ) {
784                 String id = "id";
785                 registry.setString(prefix + id, value.getId());
786             }
787             if (value.getPatterns() != null && value.getPatterns().size() > 0
788             ) {
789                 registry.removeSubset(prefix + "patterns");
790
791                 int count = 0;
792                 for (Iterator iter = value.getPatterns().iterator(); iter.hasNext(); count++) {
793                     String name = "patterns.pattern(" + count + ")";
794                     String pattern = (String) iter.next();
795                     registry.setString(prefix + name, pattern);
796                 }
797             }
798         }
799     }
800
801     private void writeOrganisationInformation(String prefix, OrganisationInformation value, Registry registry) {
802         if (value != null) {
803             if (value.getName() != null
804             ) {
805                 String name = "name";
806                 registry.setString(prefix + name, value.getName());
807             }
808             if (value.getUrl() != null
809             ) {
810                 String url = "url";
811                 registry.setString(prefix + url, value.getUrl());
812             }
813             if (value.getLogoLocation() != null
814             ) {
815                 String logoLocation = "logoLocation";
816                 registry.setString(prefix + logoLocation, value.getLogoLocation());
817             }
818         }
819     }
820
821     private void writeWebappConfiguration(String prefix, WebappConfiguration value, Registry registry) {
822         if (value != null) {
823             if (value.getUi() != null
824             ) {
825                 writeUserInterfaceOptions(prefix + "ui.", value.getUi(), registry);
826             }
827         }
828     }
829
830     private void writeUserInterfaceOptions(String prefix, UserInterfaceOptions value, Registry registry) {
831         if (value != null) {
832             String showFindArtifacts = "showFindArtifacts";
833             registry.setBoolean(prefix + showFindArtifacts, value.isShowFindArtifacts());
834             String appletFindEnabled = "appletFindEnabled";
835             registry.setBoolean(prefix + appletFindEnabled, value.isAppletFindEnabled());
836             String disableEasterEggs = "disableEasterEggs";
837             registry.setBoolean(prefix + disableEasterEggs, value.isDisableEasterEggs());
838             if (value.getApplicationUrl() != null
839             ) {
840                 String applicationUrl = "applicationUrl";
841                 registry.setString(prefix + applicationUrl, value.getApplicationUrl());
842             }
843             String disableRegistration = "disableRegistration";
844             registry.setBoolean(prefix + disableRegistration, value.isDisableRegistration());
845         }
846     }
847
848     private void writeNetworkConfiguration(String prefix, NetworkConfiguration value, Registry registry) {
849         if (value != null) {
850             if (value.getMaxTotal() != 30
851             ) {
852                 String maxTotal = "maxTotal";
853                 registry.setInt(prefix + maxTotal, value.getMaxTotal());
854             }
855             if (value.getMaxTotalPerHost() != 30
856             ) {
857                 String maxTotalPerHost = "maxTotalPerHost";
858                 registry.setInt(prefix + maxTotalPerHost, value.getMaxTotalPerHost());
859             }
860             String usePooling = "usePooling";
861             registry.setBoolean(prefix + usePooling, value.isUsePooling());
862         }
863     }
864
865     private void writeArchivaRuntimeConfiguration(String prefix, ArchivaRuntimeConfiguration value, Registry registry) {
866         if (value != null) {
867             if (value.getUrlFailureCacheConfiguration() != null
868             ) {
869                 writeCacheConfiguration(prefix + "urlFailureCacheConfiguration.", value.getUrlFailureCacheConfiguration(), registry);
870             }
871             if (value.getFileLockConfiguration() != null
872             ) {
873                 writeFileLockConfiguration(prefix + "fileLockConfiguration.", value.getFileLockConfiguration(), registry);
874             }
875             if (value.getDataDirectory() != null
876             ) {
877                 String dataDirectory = "dataDirectory";
878                 registry.setString(prefix + dataDirectory, value.getDataDirectory());
879             }
880             if (value.getRepositoryBaseDirectory() != null
881             ) {
882                 String repositoryBaseDirectory = "repositoryBaseDirectory";
883                 registry.setString(prefix + repositoryBaseDirectory, value.getRepositoryBaseDirectory());
884             }
885             if (value.getRemoteRepositoryBaseDirectory() != null
886             ) {
887                 String remoteRepositoryBaseDirectory = "remoteRepositoryBaseDirectory";
888                 registry.setString(prefix + remoteRepositoryBaseDirectory, value.getRemoteRepositoryBaseDirectory());
889             }
890             if (value.getDefaultLanguage() != null && !value.getDefaultLanguage().equals("en-US")
891             ) {
892                 String defaultLanguage = "defaultLanguage";
893                 registry.setString(prefix + defaultLanguage, value.getDefaultLanguage());
894             }
895             if (value.getLanguageRange() != null && !value.getLanguageRange().equals("en,fr,de")
896             ) {
897                 String languageRange = "languageRange";
898                 registry.setString(prefix + languageRange, value.getLanguageRange());
899             }
900             writeList(registry, value.getChecksumTypes(), prefix+"checksumTypes", "type");
901         }
902     }
903
904     private void writeRedbackRuntimeConfiguration(String prefix, RedbackRuntimeConfiguration value, Registry registry) {
905         if (value != null) {
906             String migratedFromRedbackConfiguration = "migratedFromRedbackConfiguration";
907             registry.setBoolean(prefix + migratedFromRedbackConfiguration, value.isMigratedFromRedbackConfiguration());
908             if (value.getUserManagerImpls() != null && value.getUserManagerImpls().size() > 0
909             ) {
910                 registry.removeSubset(prefix + "userManagerImpls");
911
912                 int count = 0;
913                 for (Iterator iter = value.getUserManagerImpls().iterator(); iter.hasNext(); count++) {
914                     String name = "userManagerImpls.userManagerImpl(" + count + ")";
915                     String userManagerImpl = (String) iter.next();
916                     registry.setString(prefix + name, userManagerImpl);
917                 }
918             }
919             if (value.getRbacManagerImpls() != null && value.getRbacManagerImpls().size() > 0
920             ) {
921                 registry.removeSubset(prefix + "rbacManagerImpls");
922
923                 int count = 0;
924                 for (Iterator iter = value.getRbacManagerImpls().iterator(); iter.hasNext(); count++) {
925                     String name = "rbacManagerImpls.rbacManagerImpl(" + count + ")";
926                     String rbacManagerImpl = (String) iter.next();
927                     registry.setString(prefix + name, rbacManagerImpl);
928                 }
929             }
930             if (value.getLdapConfiguration() != null
931             ) {
932                 writeLdapConfiguration(prefix + "ldapConfiguration.", value.getLdapConfiguration(), registry);
933             }
934             if (value.getLdapGroupMappings() != null && value.getLdapGroupMappings().size() > 0
935             ) {
936                 registry.removeSubset(prefix + "ldapGroupMappings");
937
938                 int count = 0;
939                 for (Iterator iter = value.getLdapGroupMappings().iterator(); iter.hasNext(); count++) {
940                     String name = "ldapGroupMappings.ldapGroupMapping(" + count + ")";
941                     LdapGroupMapping o = (LdapGroupMapping) iter.next();
942                     writeLdapGroupMapping(prefix + name + ".", o, registry);
943                 }
944             }
945             if (value.getConfigurationProperties() != null && value.getConfigurationProperties().size() > 0
946             ) {
947                 registry.removeSubset(prefix + "configurationProperties");
948
949                 for (Iterator iter = value.getConfigurationProperties().keySet().iterator(); iter.hasNext(); ) {
950                     String key = (String) iter.next();
951                     String v = (String) value.getConfigurationProperties().get(key);
952
953                     registry.setString(prefix + "configurationProperties." + key, v);
954                 }
955             }
956             String useUsersCache = "useUsersCache";
957             registry.setBoolean(prefix + useUsersCache, value.isUseUsersCache());
958             if (value.getUsersCacheConfiguration() != null
959             ) {
960                 writeCacheConfiguration(prefix + "usersCacheConfiguration.", value.getUsersCacheConfiguration(), registry);
961             }
962         }
963     }
964
965     private void writeArchivaDefaultConfiguration(String prefix, ArchivaDefaultConfiguration value, Registry registry) {
966         if (value != null) {
967             if (value.getDefaultCheckPaths() != null && value.getDefaultCheckPaths().size() > 0
968             ) {
969                 registry.removeSubset(prefix + "defaultCheckPaths");
970
971                 int count = 0;
972                 for (Iterator iter = value.getDefaultCheckPaths().iterator(); iter.hasNext(); count++) {
973                     String name = "defaultCheckPaths.defaultCheckPath(" + count + ")";
974                     RepositoryCheckPath o = (RepositoryCheckPath) iter.next();
975                     writeRepositoryCheckPath(prefix + name + ".", o, registry);
976                 }
977             }
978         }
979     }
980
981     private void writeLdapConfiguration(String prefix, LdapConfiguration value, Registry registry) {
982         if (value != null) {
983             if (value.getHostName() != null
984             ) {
985                 String hostName = "hostName";
986                 registry.setString(prefix + hostName, value.getHostName());
987             }
988             if (value.getPort() != 0
989             ) {
990                 String port = "port";
991                 registry.setInt(prefix + port, value.getPort());
992             }
993             String ssl = "ssl";
994             registry.setBoolean(prefix + ssl, value.isSsl());
995             if (value.getBaseDn() != null
996             ) {
997                 String baseDn = "baseDn";
998                 registry.setString(prefix + baseDn, value.getBaseDn());
999             }
1000             if (value.getBaseGroupsDn() != null
1001             ) {
1002                 String baseGroupsDn = "baseGroupsDn";
1003                 registry.setString(prefix + baseGroupsDn, value.getBaseGroupsDn());
1004             }
1005             if (value.getContextFactory() != null
1006             ) {
1007                 String contextFactory = "contextFactory";
1008                 registry.setString(prefix + contextFactory, value.getContextFactory());
1009             }
1010             if (value.getBindDn() != null
1011             ) {
1012                 String bindDn = "bindDn";
1013                 registry.setString(prefix + bindDn, value.getBindDn());
1014             }
1015             if (value.getPassword() != null
1016             ) {
1017                 String password = "password";
1018                 registry.setString(prefix + password, value.getPassword());
1019             }
1020             if (value.getAuthenticationMethod() != null
1021             ) {
1022                 String authenticationMethod = "authenticationMethod";
1023                 registry.setString(prefix + authenticationMethod, value.getAuthenticationMethod());
1024             }
1025             String bindAuthenticatorEnabled = "bindAuthenticatorEnabled";
1026             registry.setBoolean(prefix + bindAuthenticatorEnabled, value.isBindAuthenticatorEnabled());
1027             String writable = "writable";
1028             registry.setBoolean(prefix + writable, value.isWritable());
1029             String useRoleNameAsGroup = "useRoleNameAsGroup";
1030             registry.setBoolean(prefix + useRoleNameAsGroup, value.isUseRoleNameAsGroup());
1031             if (value.getExtraProperties() != null && value.getExtraProperties().size() > 0
1032             ) {
1033                 registry.removeSubset(prefix + "extraProperties");
1034
1035                 for (Iterator iter = value.getExtraProperties().keySet().iterator(); iter.hasNext(); ) {
1036                     String key = (String) iter.next();
1037                     String v = (String) value.getExtraProperties().get(key);
1038
1039                     registry.setString(prefix + "extraProperties." + key, v);
1040                 }
1041             }
1042         }
1043     }
1044
1045     private void writeFileLockConfiguration(String prefix, FileLockConfiguration value, Registry registry) {
1046         if (value != null) {
1047             String skipLocking = "skipLocking";
1048             registry.setBoolean(prefix + skipLocking, value.isSkipLocking());
1049             if (value.getLockingTimeout() != 0
1050             ) {
1051                 String lockingTimeout = "lockingTimeout";
1052                 registry.setInt(prefix + lockingTimeout, value.getLockingTimeout());
1053             }
1054         }
1055     }
1056
1057     private void writeCacheConfiguration(String prefix, CacheConfiguration value, Registry registry) {
1058         if (value != null) {
1059             if (value.getTimeToIdleSeconds() != -1
1060             ) {
1061                 String timeToIdleSeconds = "timeToIdleSeconds";
1062                 registry.setInt(prefix + timeToIdleSeconds, value.getTimeToIdleSeconds());
1063             }
1064             if (value.getTimeToLiveSeconds() != -1
1065             ) {
1066                 String timeToLiveSeconds = "timeToLiveSeconds";
1067                 registry.setInt(prefix + timeToLiveSeconds, value.getTimeToLiveSeconds());
1068             }
1069             if (value.getMaxElementsInMemory() != -1
1070             ) {
1071                 String maxElementsInMemory = "maxElementsInMemory";
1072                 registry.setInt(prefix + maxElementsInMemory, value.getMaxElementsInMemory());
1073             }
1074             if (value.getMaxElementsOnDisk() != -1
1075             ) {
1076                 String maxElementsOnDisk = "maxElementsOnDisk";
1077                 registry.setInt(prefix + maxElementsOnDisk, value.getMaxElementsOnDisk());
1078             }
1079         }
1080     }
1081
1082     private void writeLdapGroupMapping(String prefix, LdapGroupMapping value, Registry registry) {
1083         if (value != null) {
1084             if (value.getGroup() != null
1085             ) {
1086                 String group = "group";
1087                 registry.setString(prefix + group, value.getGroup());
1088             }
1089             if (value.getRoleNames() != null && value.getRoleNames().size() > 0
1090             ) {
1091                 registry.removeSubset(prefix + "roleNames");
1092
1093                 int count = 0;
1094                 for (Iterator iter = value.getRoleNames().iterator(); iter.hasNext(); count++) {
1095                     String name = "roleNames.roleName(" + count + ")";
1096                     String roleName = (String) iter.next();
1097                     registry.setString(prefix + name, roleName);
1098                 }
1099             }
1100         }
1101     }
1102
1103 }