This project has retired. For details please refer to its Attic page.
Source code
001
002package org.apache.archiva.configuration.io.registry;
003
004/*
005 * Licensed to the Apache Software Foundation (ASF) under one
006 * or more contributor license agreements.  See the NOTICE file
007 * distributed with this work for additional information
008 * regarding copyright ownership.  The ASF licenses this file
009 * to you under the Apache License, Version 2.0 (the
010 * "License"); you may not use this file except in compliance
011 * with the License.  You may obtain a copy of the License at
012 *
013 *   http://www.apache.org/licenses/LICENSE-2.0
014 *
015 * Unless required by applicable law or agreed to in writing,
016 * software distributed under the License is distributed on an
017 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
018 * KIND, either express or implied.  See the License for the
019 * specific language governing permissions and limitations
020 * under the License.
021 */
022
023import org.apache.archiva.configuration.*;
024import org.apache.archiva.components.registry.Registry;
025
026import java.util.Iterator;
027import java.util.List;
028
029// Util imports
030// Model class imports
031
032
033/**
034 * Generate Plexus Registry output mechanism for model 'Configuration'.
035 */
036public class ConfigurationRegistryWriter {
037    public void write(Configuration model, Registry registry) {
038        writeConfiguration("", model, registry);
039    }
040
041    private void writeList(Registry registry, List<String> subList, String subsetPath, String elementName) {
042        if (subList != null && subList.size() > 0
043        ) {
044            registry.removeSubset(subsetPath);
045
046            int count = 0;
047            for (Iterator<String> iter = subList.iterator(); iter.hasNext(); count++) {
048                String name = subsetPath + "." + elementName + "(" + count + ")";
049                String value = iter.next();
050                registry.setString(name, value);
051            }
052        }
053    }
054
055    private void writeConfiguration(String prefix, Configuration value, Registry registry) {
056        if (value != null) {
057            if (value.getVersion() != null
058            ) {
059                String version = "version";
060                registry.setString(prefix + version, value.getVersion());
061            }
062            if (value.getMetadataStore() != null && !value.getMetadataStore().equals("jcr")
063            ) {
064                String metadataStore = "metadataStore";
065                registry.setString(prefix + metadataStore, value.getMetadataStore());
066            }
067            if (value.getRepositoryGroups() != null && value.getRepositoryGroups().size() > 0
068            ) {
069                registry.removeSubset(prefix + "repositoryGroups");
070
071                int count = 0;
072                for (Iterator iter = value.getRepositoryGroups().iterator(); iter.hasNext(); count++) {
073                    String name = "repositoryGroups.repositoryGroup(" + count + ")";
074                    RepositoryGroupConfiguration o = (RepositoryGroupConfiguration) iter.next();
075                    writeRepositoryGroupConfiguration(prefix + name + ".", o, registry);
076                }
077            }
078            if (value.getManagedRepositories() != null && value.getManagedRepositories().size() > 0
079            ) {
080                registry.removeSubset(prefix + "managedRepositories");
081
082                int count = 0;
083                for (Iterator iter = value.getManagedRepositories().iterator(); iter.hasNext(); count++) {
084                    String name = "managedRepositories.managedRepository(" + count + ")";
085                    ManagedRepositoryConfiguration o = (ManagedRepositoryConfiguration) iter.next();
086                    writeManagedRepositoryConfiguration(prefix + name + ".", o, registry);
087                }
088            }
089            if (value.getRemoteRepositories() != null && value.getRemoteRepositories().size() > 0
090            ) {
091                registry.removeSubset(prefix + "remoteRepositories");
092
093                int count = 0;
094                for (Iterator iter = value.getRemoteRepositories().iterator(); iter.hasNext(); count++) {
095                    String name = "remoteRepositories.remoteRepository(" + count + ")";
096                    RemoteRepositoryConfiguration o = (RemoteRepositoryConfiguration) iter.next();
097                    writeRemoteRepositoryConfiguration(prefix + name + ".", o, registry);
098                }
099            }
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.getMergedIndexPath() != null && !value.getMergedIndexPath().equals(".indexer")
429            ) {
430                String mergedIndexPath = "mergedIndexPath";
431                registry.setString(prefix + mergedIndexPath, value.getMergedIndexPath());
432            }
433            if (value.getMergedIndexTtl() != 30
434            ) {
435                String mergedIndexTtl = "mergedIndexTtl";
436                registry.setInt(prefix + mergedIndexTtl, value.getMergedIndexTtl());
437            }
438            if (value.getCronExpression() != null && !value.getCronExpression().equals("")
439            ) {
440                String cronExpression = "cronExpression";
441                registry.setString(prefix + cronExpression, value.getCronExpression());
442            }
443            if (value.getRepositories() != null && value.getRepositories().size() > 0
444            ) {
445                registry.removeSubset(prefix + "repositories");
446
447                int count = 0;
448                for (Iterator iter = value.getRepositories().iterator(); iter.hasNext(); count++) {
449                    String name = "repositories.repository(" + count + ")";
450                    String repository = (String) iter.next();
451                    registry.setString(prefix + name, repository);
452                }
453            }
454        }
455    }
456
457    private void writeRepositoryCheckPath(String prefix, RepositoryCheckPath value, Registry registry) {
458        if (value != null) {
459            if (value.getUrl() != null
460            ) {
461                String url = "url";
462                registry.setString(prefix + url, value.getUrl());
463            }
464            if (value.getPath() != null
465            ) {
466                String path = "path";
467                registry.setString(prefix + path, value.getPath());
468            }
469        }
470    }
471
472    private void writeAbstractRepositoryConnectorConfiguration(String prefix, AbstractRepositoryConnectorConfiguration value, Registry registry) {
473        if (value != null) {
474            if (value.getSourceRepoId() != null
475            ) {
476                String sourceRepoId = "sourceRepoId";
477                registry.setString(prefix + sourceRepoId, value.getSourceRepoId());
478            }
479            if (value.getTargetRepoId() != null
480            ) {
481                String targetRepoId = "targetRepoId";
482                registry.setString(prefix + targetRepoId, value.getTargetRepoId());
483            }
484            if (value.getProxyId() != null
485            ) {
486                String proxyId = "proxyId";
487                registry.setString(prefix + proxyId, value.getProxyId());
488            }
489            if (value.getBlackListPatterns() != null && value.getBlackListPatterns().size() > 0
490            ) {
491                registry.removeSubset(prefix + "blackListPatterns");
492
493                int count = 0;
494                for (Iterator iter = value.getBlackListPatterns().iterator(); iter.hasNext(); count++) {
495                    String name = "blackListPatterns.blackListPattern(" + count + ")";
496                    String blackListPattern = (String) iter.next();
497                    registry.setString(prefix + name, blackListPattern);
498                }
499            }
500            if (value.getWhiteListPatterns() != null && value.getWhiteListPatterns().size() > 0
501            ) {
502                registry.removeSubset(prefix + "whiteListPatterns");
503
504                int count = 0;
505                for (Iterator iter = value.getWhiteListPatterns().iterator(); iter.hasNext(); count++) {
506                    String name = "whiteListPatterns.whiteListPattern(" + count + ")";
507                    String whiteListPattern = (String) iter.next();
508                    registry.setString(prefix + name, whiteListPattern);
509                }
510            }
511            if (value.getPolicies() != null && value.getPolicies().size() > 0
512            ) {
513                registry.removeSubset(prefix + "policies");
514
515                for (Iterator iter = value.getPolicies().keySet().iterator(); iter.hasNext(); ) {
516                    String key = (String) iter.next();
517                    String v = (String) value.getPolicies().get(key);
518
519                    registry.setString(prefix + "policies." + key, v);
520                }
521            }
522            if (value.getProperties() != null && value.getProperties().size() > 0
523            ) {
524                registry.removeSubset(prefix + "properties");
525
526                for (Iterator iter = value.getProperties().keySet().iterator(); iter.hasNext(); ) {
527                    String key = (String) iter.next();
528                    String v = (String) value.getProperties().get(key);
529
530                    registry.setString(prefix + "properties." + key, v);
531                }
532            }
533            String disabled = "disabled";
534            registry.setBoolean(prefix + disabled, value.isDisabled());
535        }
536    }
537
538    private void writeProxyConnectorRuleConfiguration(String prefix, ProxyConnectorRuleConfiguration value, Registry registry) {
539        if (value != null) {
540            if (value.getRuleType() != null
541            ) {
542                String ruleType = "ruleType";
543                registry.setString(prefix + ruleType, value.getRuleType());
544            }
545            if (value.getPattern() != null
546            ) {
547                String pattern = "pattern";
548                registry.setString(prefix + pattern, value.getPattern());
549            }
550            if (value.getProxyConnectors() != null && value.getProxyConnectors().size() > 0
551            ) {
552                registry.removeSubset(prefix + "proxyConnectors");
553
554                int count = 0;
555                for (Iterator iter = value.getProxyConnectors().iterator(); iter.hasNext(); count++) {
556                    String name = "proxyConnectors.proxyConnector(" + count + ")";
557                    ProxyConnectorConfiguration o = (ProxyConnectorConfiguration) iter.next();
558                    writeProxyConnectorConfiguration(prefix + name + ".", o, registry);
559                }
560            }
561        }
562    }
563
564    private void writeProxyConnectorConfiguration(String prefix, ProxyConnectorConfiguration value, Registry registry) {
565        if (value != null) {
566            if (value.getOrder() != 0
567            ) {
568                String order = "order";
569                registry.setInt(prefix + order, value.getOrder());
570            }
571            if (value.getSourceRepoId() != null
572            ) {
573                String sourceRepoId = "sourceRepoId";
574                registry.setString(prefix + sourceRepoId, value.getSourceRepoId());
575            }
576            if (value.getTargetRepoId() != null
577            ) {
578                String targetRepoId = "targetRepoId";
579                registry.setString(prefix + targetRepoId, value.getTargetRepoId());
580            }
581            if (value.getProxyId() != null
582            ) {
583                String proxyId = "proxyId";
584                registry.setString(prefix + proxyId, value.getProxyId());
585            }
586            if (value.getBlackListPatterns() != null && value.getBlackListPatterns().size() > 0
587            ) {
588                registry.removeSubset(prefix + "blackListPatterns");
589
590                int count = 0;
591                for (Iterator iter = value.getBlackListPatterns().iterator(); iter.hasNext(); count++) {
592                    String name = "blackListPatterns.blackListPattern(" + count + ")";
593                    String blackListPattern = (String) iter.next();
594                    registry.setString(prefix + name, blackListPattern);
595                }
596            }
597            if (value.getWhiteListPatterns() != null && value.getWhiteListPatterns().size() > 0
598            ) {
599                registry.removeSubset(prefix + "whiteListPatterns");
600
601                int count = 0;
602                for (Iterator iter = value.getWhiteListPatterns().iterator(); iter.hasNext(); count++) {
603                    String name = "whiteListPatterns.whiteListPattern(" + count + ")";
604                    String whiteListPattern = (String) iter.next();
605                    registry.setString(prefix + name, whiteListPattern);
606                }
607            }
608            if (value.getPolicies() != null && value.getPolicies().size() > 0
609            ) {
610                registry.removeSubset(prefix + "policies");
611
612                for (Iterator iter = value.getPolicies().keySet().iterator(); iter.hasNext(); ) {
613                    String key = (String) iter.next();
614                    String v = (String) value.getPolicies().get(key);
615
616                    registry.setString(prefix + "policies." + key, v);
617                }
618            }
619            if (value.getProperties() != null && value.getProperties().size() > 0
620            ) {
621                registry.removeSubset(prefix + "properties");
622
623                for (Iterator iter = value.getProperties().keySet().iterator(); iter.hasNext(); ) {
624                    String key = (String) iter.next();
625                    String v = (String) value.getProperties().get(key);
626
627                    registry.setString(prefix + "properties." + key, v);
628                }
629            }
630            String disabled = "disabled";
631            registry.setBoolean(prefix + disabled, value.isDisabled());
632        }
633    }
634
635    private void writeSyncConnectorConfiguration(String prefix, SyncConnectorConfiguration value, Registry registry) {
636        if (value != null) {
637            if (value.getCronExpression() != null && !value.getCronExpression().equals("0 0 * * * ?")
638            ) {
639                String cronExpression = "cronExpression";
640                registry.setString(prefix + cronExpression, value.getCronExpression());
641            }
642            if (value.getMethod() != null && !value.getMethod().equals("rsync")
643            ) {
644                String method = "method";
645                registry.setString(prefix + method, value.getMethod());
646            }
647            if (value.getSourceRepoId() != null
648            ) {
649                String sourceRepoId = "sourceRepoId";
650                registry.setString(prefix + sourceRepoId, value.getSourceRepoId());
651            }
652            if (value.getTargetRepoId() != null
653            ) {
654                String targetRepoId = "targetRepoId";
655                registry.setString(prefix + targetRepoId, value.getTargetRepoId());
656            }
657            if (value.getProxyId() != null
658            ) {
659                String proxyId = "proxyId";
660                registry.setString(prefix + proxyId, value.getProxyId());
661            }
662            if (value.getBlackListPatterns() != null && value.getBlackListPatterns().size() > 0
663            ) {
664                registry.removeSubset(prefix + "blackListPatterns");
665
666                int count = 0;
667                for (Iterator iter = value.getBlackListPatterns().iterator(); iter.hasNext(); count++) {
668                    String name = "blackListPatterns.blackListPattern(" + count + ")";
669                    String blackListPattern = (String) iter.next();
670                    registry.setString(prefix + name, blackListPattern);
671                }
672            }
673            if (value.getWhiteListPatterns() != null && value.getWhiteListPatterns().size() > 0
674            ) {
675                registry.removeSubset(prefix + "whiteListPatterns");
676
677                int count = 0;
678                for (Iterator iter = value.getWhiteListPatterns().iterator(); iter.hasNext(); count++) {
679                    String name = "whiteListPatterns.whiteListPattern(" + count + ")";
680                    String whiteListPattern = (String) iter.next();
681                    registry.setString(prefix + name, whiteListPattern);
682                }
683            }
684            if (value.getPolicies() != null && value.getPolicies().size() > 0
685            ) {
686                registry.removeSubset(prefix + "policies");
687
688                for (Iterator iter = value.getPolicies().keySet().iterator(); iter.hasNext(); ) {
689                    String key = (String) iter.next();
690                    String v = (String) value.getPolicies().get(key);
691
692                    registry.setString(prefix + "policies." + key, v);
693                }
694            }
695            if (value.getProperties() != null && value.getProperties().size() > 0
696            ) {
697                registry.removeSubset(prefix + "properties");
698
699                for (Iterator iter = value.getProperties().keySet().iterator(); iter.hasNext(); ) {
700                    String key = (String) iter.next();
701                    String v = (String) value.getProperties().get(key);
702
703                    registry.setString(prefix + "properties." + key, v);
704                }
705            }
706            String disabled = "disabled";
707            registry.setBoolean(prefix + disabled, value.isDisabled());
708        }
709    }
710
711    private void writeNetworkProxyConfiguration(String prefix, NetworkProxyConfiguration value, Registry registry) {
712        if (value != null) {
713            if (value.getId() != null
714            ) {
715                String id = "id";
716                registry.setString(prefix + id, value.getId());
717            }
718            if (value.getProtocol() != null && !value.getProtocol().equals("http")
719            ) {
720                String protocol = "protocol";
721                registry.setString(prefix + protocol, value.getProtocol());
722            }
723            if (value.getHost() != null
724            ) {
725                String host = "host";
726                registry.setString(prefix + host, value.getHost());
727            }
728            if (value.getPort() != 8080
729            ) {
730                String port = "port";
731                registry.setInt(prefix + port, value.getPort());
732            }
733            if (value.getUsername() != null
734            ) {
735                String username = "username";
736                registry.setString(prefix + username, value.getUsername());
737            }
738            if (value.getPassword() != null
739            ) {
740                String password = "password";
741                registry.setString(prefix + password, value.getPassword());
742            }
743            String useNtlm = "useNtlm";
744            registry.setBoolean(prefix + useNtlm, value.isUseNtlm());
745        }
746    }
747
748    private void writeRepositoryScanningConfiguration(String prefix, RepositoryScanningConfiguration value, Registry registry) {
749        if (value != null) {
750            if (value.getFileTypes() != null && value.getFileTypes().size() > 0
751            ) {
752                registry.removeSubset(prefix + "fileTypes");
753
754                int count = 0;
755                for (Iterator iter = value.getFileTypes().iterator(); iter.hasNext(); count++) {
756                    String name = "fileTypes.fileType(" + count + ")";
757                    FileType o = (FileType) iter.next();
758                    writeFileType(prefix + name + ".", o, registry);
759                }
760            }
761            if (value.getKnownContentConsumers() != null && value.getKnownContentConsumers().size() > 0
762            ) {
763                registry.removeSubset(prefix + "knownContentConsumers");
764
765                int count = 0;
766                for (Iterator iter = value.getKnownContentConsumers().iterator(); iter.hasNext(); count++) {
767                    String name = "knownContentConsumers.knownContentConsumer(" + count + ")";
768                    String knownContentConsumer = (String) iter.next();
769                    registry.setString(prefix + name, knownContentConsumer);
770                }
771            }
772            if (value.getInvalidContentConsumers() != null && value.getInvalidContentConsumers().size() > 0
773            ) {
774                registry.removeSubset(prefix + "invalidContentConsumers");
775
776                int count = 0;
777                for (Iterator iter = value.getInvalidContentConsumers().iterator(); iter.hasNext(); count++) {
778                    String name = "invalidContentConsumers.invalidContentConsumer(" + count + ")";
779                    String invalidContentConsumer = (String) iter.next();
780                    registry.setString(prefix + name, invalidContentConsumer);
781                }
782            }
783        }
784    }
785
786    private void writeFileType(String prefix, FileType value, Registry registry) {
787        if (value != null) {
788            if (value.getId() != null
789            ) {
790                String id = "id";
791                registry.setString(prefix + id, value.getId());
792            }
793            if (value.getPatterns() != null && value.getPatterns().size() > 0
794            ) {
795                registry.removeSubset(prefix + "patterns");
796
797                int count = 0;
798                for (Iterator iter = value.getPatterns().iterator(); iter.hasNext(); count++) {
799                    String name = "patterns.pattern(" + count + ")";
800                    String pattern = (String) iter.next();
801                    registry.setString(prefix + name, pattern);
802                }
803            }
804        }
805    }
806
807    private void writeOrganisationInformation(String prefix, OrganisationInformation value, Registry registry) {
808        if (value != null) {
809            if (value.getName() != null
810            ) {
811                String name = "name";
812                registry.setString(prefix + name, value.getName());
813            }
814            if (value.getUrl() != null
815            ) {
816                String url = "url";
817                registry.setString(prefix + url, value.getUrl());
818            }
819            if (value.getLogoLocation() != null
820            ) {
821                String logoLocation = "logoLocation";
822                registry.setString(prefix + logoLocation, value.getLogoLocation());
823            }
824        }
825    }
826
827    private void writeWebappConfiguration(String prefix, WebappConfiguration value, Registry registry) {
828        if (value != null) {
829            if (value.getUi() != null
830            ) {
831                writeUserInterfaceOptions(prefix + "ui.", value.getUi(), registry);
832            }
833        }
834    }
835
836    private void writeUserInterfaceOptions(String prefix, UserInterfaceOptions value, Registry registry) {
837        if (value != null) {
838            String showFindArtifacts = "showFindArtifacts";
839            registry.setBoolean(prefix + showFindArtifacts, value.isShowFindArtifacts());
840            String appletFindEnabled = "appletFindEnabled";
841            registry.setBoolean(prefix + appletFindEnabled, value.isAppletFindEnabled());
842            String disableEasterEggs = "disableEasterEggs";
843            registry.setBoolean(prefix + disableEasterEggs, value.isDisableEasterEggs());
844            if (value.getApplicationUrl() != null
845            ) {
846                String applicationUrl = "applicationUrl";
847                registry.setString(prefix + applicationUrl, value.getApplicationUrl());
848            }
849            String disableRegistration = "disableRegistration";
850            registry.setBoolean(prefix + disableRegistration, value.isDisableRegistration());
851        }
852    }
853
854    private void writeNetworkConfiguration(String prefix, NetworkConfiguration value, Registry registry) {
855        if (value != null) {
856            if (value.getMaxTotal() != 30
857            ) {
858                String maxTotal = "maxTotal";
859                registry.setInt(prefix + maxTotal, value.getMaxTotal());
860            }
861            if (value.getMaxTotalPerHost() != 30
862            ) {
863                String maxTotalPerHost = "maxTotalPerHost";
864                registry.setInt(prefix + maxTotalPerHost, value.getMaxTotalPerHost());
865            }
866            String usePooling = "usePooling";
867            registry.setBoolean(prefix + usePooling, value.isUsePooling());
868        }
869    }
870
871    private void writeArchivaRuntimeConfiguration(String prefix, ArchivaRuntimeConfiguration value, Registry registry) {
872        if (value != null) {
873            if (value.getUrlFailureCacheConfiguration() != null
874            ) {
875                writeCacheConfiguration(prefix + "urlFailureCacheConfiguration.", value.getUrlFailureCacheConfiguration(), registry);
876            }
877            if (value.getFileLockConfiguration() != null
878            ) {
879                writeFileLockConfiguration(prefix + "fileLockConfiguration.", value.getFileLockConfiguration(), registry);
880            }
881            if (value.getDataDirectory() != null
882            ) {
883                String dataDirectory = "dataDirectory";
884                registry.setString(prefix + dataDirectory, value.getDataDirectory());
885            }
886            if (value.getRepositoryBaseDirectory() != null
887            ) {
888                String repositoryBaseDirectory = "repositoryBaseDirectory";
889                registry.setString(prefix + repositoryBaseDirectory, value.getRepositoryBaseDirectory());
890            }
891            if (value.getRemoteRepositoryBaseDirectory() != null
892            ) {
893                String remoteRepositoryBaseDirectory = "remoteRepositoryBaseDirectory";
894                registry.setString(prefix + remoteRepositoryBaseDirectory, value.getRemoteRepositoryBaseDirectory());
895            }
896            if (value.getRepositoryGroupBaseDirectory() != null
897            ) {
898                String repositoryGroupBaseDirectory = "repositoryGroupBaseDirectory";
899                registry.setString(prefix + repositoryGroupBaseDirectory, value.getRepositoryGroupBaseDirectory());
900            }
901
902            if (value.getDefaultLanguage() != null && !value.getDefaultLanguage().equals("en-US")
903            ) {
904                String defaultLanguage = "defaultLanguage";
905                registry.setString(prefix + defaultLanguage, value.getDefaultLanguage());
906            }
907            if (value.getLanguageRange() != null && !value.getLanguageRange().equals("en,fr,de")
908            ) {
909                String languageRange = "languageRange";
910                registry.setString(prefix + languageRange, value.getLanguageRange());
911            }
912            writeList(registry, value.getChecksumTypes(), prefix+"checksumTypes", "type");
913        }
914    }
915
916    private void writeRedbackRuntimeConfiguration(String prefix, RedbackRuntimeConfiguration value, Registry registry) {
917        if (value != null) {
918            String migratedFromRedbackConfiguration = "migratedFromRedbackConfiguration";
919            registry.setBoolean(prefix + migratedFromRedbackConfiguration, value.isMigratedFromRedbackConfiguration());
920            if (value.getUserManagerImpls() != null && value.getUserManagerImpls().size() > 0
921            ) {
922                registry.removeSubset(prefix + "userManagerImpls");
923
924                int count = 0;
925                for (Iterator iter = value.getUserManagerImpls().iterator(); iter.hasNext(); count++) {
926                    String name = "userManagerImpls.userManagerImpl(" + count + ")";
927                    String userManagerImpl = (String) iter.next();
928                    registry.setString(prefix + name, userManagerImpl);
929                }
930            }
931            if (value.getRbacManagerImpls() != null && value.getRbacManagerImpls().size() > 0
932            ) {
933                registry.removeSubset(prefix + "rbacManagerImpls");
934
935                int count = 0;
936                for (Iterator iter = value.getRbacManagerImpls().iterator(); iter.hasNext(); count++) {
937                    String name = "rbacManagerImpls.rbacManagerImpl(" + count + ")";
938                    String rbacManagerImpl = (String) iter.next();
939                    registry.setString(prefix + name, rbacManagerImpl);
940                }
941            }
942            if (value.getLdapConfiguration() != null
943            ) {
944                writeLdapConfiguration(prefix + "ldapConfiguration.", value.getLdapConfiguration(), registry);
945            }
946            if (value.getLdapGroupMappings() != null && value.getLdapGroupMappings().size() > 0
947            ) {
948                registry.removeSubset(prefix + "ldapGroupMappings");
949
950                int count = 0;
951                for (Iterator iter = value.getLdapGroupMappings().iterator(); iter.hasNext(); count++) {
952                    String name = "ldapGroupMappings.ldapGroupMapping(" + count + ")";
953                    LdapGroupMapping o = (LdapGroupMapping) iter.next();
954                    writeLdapGroupMapping(prefix + name + ".", o, registry);
955                }
956            }
957            if (value.getConfigurationProperties() != null && value.getConfigurationProperties().size() > 0
958            ) {
959                registry.removeSubset(prefix + "configurationProperties");
960
961                for (Iterator iter = value.getConfigurationProperties().keySet().iterator(); iter.hasNext(); ) {
962                    String key = (String) iter.next();
963                    String v = (String) value.getConfigurationProperties().get(key);
964
965                    registry.setString(prefix + "configurationProperties." + key, v);
966                }
967            }
968            String useUsersCache = "useUsersCache";
969            registry.setBoolean(prefix + useUsersCache, value.isUseUsersCache());
970            if (value.getUsersCacheConfiguration() != null
971            ) {
972                writeCacheConfiguration(prefix + "usersCacheConfiguration.", value.getUsersCacheConfiguration(), registry);
973            }
974        }
975    }
976
977    private void writeArchivaDefaultConfiguration(String prefix, ArchivaDefaultConfiguration value, Registry registry) {
978        if (value != null) {
979            if (value.getDefaultCheckPaths() != null && value.getDefaultCheckPaths().size() > 0
980            ) {
981                registry.removeSubset(prefix + "defaultCheckPaths");
982
983                int count = 0;
984                for (Iterator iter = value.getDefaultCheckPaths().iterator(); iter.hasNext(); count++) {
985                    String name = "defaultCheckPaths.defaultCheckPath(" + count + ")";
986                    RepositoryCheckPath o = (RepositoryCheckPath) iter.next();
987                    writeRepositoryCheckPath(prefix + name + ".", o, registry);
988                }
989            }
990        }
991    }
992
993    private void writeLdapConfiguration(String prefix, LdapConfiguration value, Registry registry) {
994        if (value != null) {
995            if (value.getHostName() != null
996            ) {
997                String hostName = "hostName";
998                registry.setString(prefix + hostName, value.getHostName());
999            }
1000            if (value.getPort() != 0
1001            ) {
1002                String port = "port";
1003                registry.setInt(prefix + port, value.getPort());
1004            }
1005            String ssl = "ssl";
1006            registry.setBoolean(prefix + ssl, value.isSsl());
1007            if (value.getBaseDn() != null
1008            ) {
1009                String baseDn = "baseDn";
1010                registry.setString(prefix + baseDn, value.getBaseDn());
1011            }
1012            if (value.getBaseGroupsDn() != null
1013            ) {
1014                String baseGroupsDn = "baseGroupsDn";
1015                registry.setString(prefix + baseGroupsDn, value.getBaseGroupsDn());
1016            }
1017            if (value.getContextFactory() != null
1018            ) {
1019                String contextFactory = "contextFactory";
1020                registry.setString(prefix + contextFactory, value.getContextFactory());
1021            }
1022            if (value.getBindDn() != null
1023            ) {
1024                String bindDn = "bindDn";
1025                registry.setString(prefix + bindDn, value.getBindDn());
1026            }
1027            if (value.getPassword() != null
1028            ) {
1029                String password = "password";
1030                registry.setString(prefix + password, value.getPassword());
1031            }
1032            if (value.getAuthenticationMethod() != null
1033            ) {
1034                String authenticationMethod = "authenticationMethod";
1035                registry.setString(prefix + authenticationMethod, value.getAuthenticationMethod());
1036            }
1037            String bindAuthenticatorEnabled = "bindAuthenticatorEnabled";
1038            registry.setBoolean(prefix + bindAuthenticatorEnabled, value.isBindAuthenticatorEnabled());
1039            String writable = "writable";
1040            registry.setBoolean(prefix + writable, value.isWritable());
1041            String useRoleNameAsGroup = "useRoleNameAsGroup";
1042            registry.setBoolean(prefix + useRoleNameAsGroup, value.isUseRoleNameAsGroup());
1043            if (value.getExtraProperties() != null && value.getExtraProperties().size() > 0
1044            ) {
1045                registry.removeSubset(prefix + "extraProperties");
1046
1047                for (Iterator iter = value.getExtraProperties().keySet().iterator(); iter.hasNext(); ) {
1048                    String key = (String) iter.next();
1049                    String v = (String) value.getExtraProperties().get(key);
1050
1051                    registry.setString(prefix + "extraProperties." + key, v);
1052                }
1053            }
1054        }
1055    }
1056
1057    private void writeFileLockConfiguration(String prefix, FileLockConfiguration value, Registry registry) {
1058        if (value != null) {
1059            String skipLocking = "skipLocking";
1060            registry.setBoolean(prefix + skipLocking, value.isSkipLocking());
1061            if (value.getLockingTimeout() != 0
1062            ) {
1063                String lockingTimeout = "lockingTimeout";
1064                registry.setInt(prefix + lockingTimeout, value.getLockingTimeout());
1065            }
1066        }
1067    }
1068
1069    private void writeCacheConfiguration(String prefix, CacheConfiguration value, Registry registry) {
1070        if (value != null) {
1071            if (value.getTimeToIdleSeconds() != -1
1072            ) {
1073                String timeToIdleSeconds = "timeToIdleSeconds";
1074                registry.setInt(prefix + timeToIdleSeconds, value.getTimeToIdleSeconds());
1075            }
1076            if (value.getTimeToLiveSeconds() != -1
1077            ) {
1078                String timeToLiveSeconds = "timeToLiveSeconds";
1079                registry.setInt(prefix + timeToLiveSeconds, value.getTimeToLiveSeconds());
1080            }
1081            if (value.getMaxElementsInMemory() != -1
1082            ) {
1083                String maxElementsInMemory = "maxElementsInMemory";
1084                registry.setInt(prefix + maxElementsInMemory, value.getMaxElementsInMemory());
1085            }
1086            if (value.getMaxElementsOnDisk() != -1
1087            ) {
1088                String maxElementsOnDisk = "maxElementsOnDisk";
1089                registry.setInt(prefix + maxElementsOnDisk, value.getMaxElementsOnDisk());
1090            }
1091        }
1092    }
1093
1094    private void writeLdapGroupMapping(String prefix, LdapGroupMapping value, Registry registry) {
1095        if (value != null) {
1096            if (value.getGroup() != null
1097            ) {
1098                String group = "group";
1099                registry.setString(prefix + group, value.getGroup());
1100            }
1101            if (value.getRoleNames() != null && value.getRoleNames().size() > 0
1102            ) {
1103                registry.removeSubset(prefix + "roleNames");
1104
1105                int count = 0;
1106                for (Iterator iter = value.getRoleNames().iterator(); iter.hasNext(); count++) {
1107                    String name = "roleNames.roleName(" + count + ")";
1108                    String roleName = (String) iter.next();
1109                    registry.setString(prefix + name, roleName);
1110                }
1111            }
1112        }
1113    }
1114
1115}