View Javadoc
1   /*
2    * The contents of this file are subject to the terms of the Common Development and
3    * Distribution License (the License). You may not use this file except in compliance with the
4    * License.
5    *
6    * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
7    * specific language governing permission and limitations under the License.
8    *
9    * When distributing Covered Software, include this CDDL Header Notice in each file and include
10   * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
11   * Header, with the fields enclosed by brackets [] replaced by your own identifying
12   * information: "Portions copyright [year] [name of copyright owner]".
13   *
14   * Copyright 2016 ForgeRock AS.
15   */
16  
17  package org.forgerock.api.transform;
18  
19  import org.forgerock.util.i18n.LocalizableString;
20  
21  import io.swagger.models.Info;
22  
23  /**
24   * A localizable {@code Info}.
25   */
26  class LocalizableInfo extends Info implements LocalizableTitleAndDescription<Info> {
27  
28      private LocalizableString title;
29      private LocalizableString description;
30  
31      @Override
32      public LocalizableInfo title(LocalizableString title) {
33          this.title = title;
34          return this;
35      }
36  
37      @Override
38      public LocalizableInfo description(LocalizableString description) {
39          this.description = description;
40          return this;
41      }
42  
43      @Override
44      public LocalizableInfo title(String title) {
45          setTitle(title);
46          return this;
47      }
48  
49      @Override
50      public void setTitle(String title) {
51          super.setTitle(title);
52          this.title = new LocalizableString(title);
53      }
54  
55      @Override
56      public LocalizableInfo description(String description) {
57          setDescription(description);
58          return this;
59      }
60  
61      @Override
62      public void setDescription(String description) {
63          super.setDescription(description);
64          this.description = new LocalizableString(description);
65      }
66  
67      @Override
68      public LocalizableString getLocalizableTitle() {
69          return title;
70      }
71  
72      @Override
73      public LocalizableString getLocalizableDescription() {
74          return description;
75      }
76  
77      @Override
78      public LocalizableInfo mergeWith(Info info) {
79          super.mergeWith(info);
80          if (info instanceof LocalizableInfo) {
81              LocalizableInfo localizableInfo = (LocalizableInfo) info;
82              if (localizableInfo.description != null) {
83                  this.description = localizableInfo.description;
84              }
85              if (localizableInfo.title != null) {
86                  this.title = localizableInfo.title;
87              }
88          } else {
89              if (info.getDescription() != null) {
90                  description(info.getDescription());
91              }
92              if (info.getTitle() != null) {
93                  title(info.getTitle());
94              }
95          }
96          return this;
97      }
98  }