View Javadoc
1   /*
2    * This file is part of ***  M y C o R e  ***
3    * See http://www.mycore.de/ for details.
4    *
5    * MyCoRe is free software: you can redistribute it and/or modify
6    * it under the terms of the GNU General Public License as published by
7    * the Free Software Foundation, either version 3 of the License, or
8    * (at your option) any later version.
9    *
10   * MyCoRe is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   *
15   * You should have received a copy of the GNU General Public License
16   * along with MyCoRe.  If not, see <http://www.gnu.org/licenses/>.
17   */
18  
19  package org.mycore.frontend.support;
20  
21  import java.util.ArrayList;
22  import java.util.List;
23  
24  import org.mycore.common.MCRSystemUserInformation;
25  import org.mycore.common.MCRUserInformation;
26  
27  import jakarta.xml.bind.JAXBContext;
28  import jakarta.xml.bind.JAXBException;
29  import jakarta.xml.bind.annotation.XmlAccessType;
30  import jakarta.xml.bind.annotation.XmlAccessorType;
31  import jakarta.xml.bind.annotation.XmlAttribute;
32  import jakarta.xml.bind.annotation.XmlElement;
33  import jakarta.xml.bind.annotation.XmlRootElement;
34  import jakarta.xml.bind.annotation.XmlType;
35  
36  @XmlRootElement(name = "login")
37  @XmlType(name = "base-login")
38  @XmlAccessorType(XmlAccessType.FIELD)
39  public class MCRLogin {
40  
41      @XmlAttribute(required = true)
42      protected String user;
43  
44      @XmlAttribute(required = true)
45      protected boolean guest;
46  
47      @XmlElement
48      protected Form form;
49  
50      public MCRLogin() {
51          super();
52      }
53  
54      public MCRLogin(MCRUserInformation userInformation, String formAction) {
55          this();
56          this.user = userInformation.getUserID();
57          this.guest = userInformation == MCRSystemUserInformation.getGuestInstance();
58          this.form = new Form(formAction);
59      }
60  
61      public static JAXBContext getContext() throws JAXBException {
62          return JAXBContext.newInstance(MCRLogin.class);
63      }
64  
65      public String getUser() {
66          return user;
67      }
68  
69      public void setUser(String user) {
70          this.user = user;
71      }
72  
73      public boolean isGuest() {
74          return guest;
75      }
76  
77      public void setGuest(boolean guest) {
78          this.guest = guest;
79      }
80  
81      public Form getForm() {
82          return form;
83      }
84  
85      public void setForm(Form form) {
86          this.form = form;
87      }
88  
89      @XmlType
90      @XmlAccessorType(XmlAccessType.FIELD)
91      public static class Form {
92          @XmlAttribute
93          String action;
94  
95          @XmlElement
96          List<InputField> input;
97  
98          public Form() {
99              input = new ArrayList<>();
100         }
101 
102         public Form(String formAction) {
103             this();
104             action = formAction;
105         }
106 
107         public String getAction() {
108             return action;
109         }
110 
111         public void setAction(String action) {
112             this.action = action;
113         }
114 
115         public List<InputField> getInput() {
116             return input;
117         }
118 
119         public void setInput(List<InputField> input) {
120             this.input = input;
121         }
122     }
123 
124     @XmlType
125     @XmlAccessorType(XmlAccessType.FIELD)
126     public static class InputField {
127         @XmlAttribute
128         String name;
129 
130         @XmlAttribute
131         String value;
132 
133         @XmlAttribute
134         String label;
135 
136         @XmlAttribute
137         String placeholder;
138 
139         @XmlAttribute
140         boolean isPassword;
141 
142         @XmlAttribute
143         boolean isHidden;
144 
145         public InputField() {
146         }
147 
148         public InputField(String name, String value, String label, String placeholder, boolean isPassword,
149             boolean isHidden) {
150             this();
151             this.name = name;
152             this.value = value;
153             this.label = label;
154             this.placeholder = placeholder;
155             this.isPassword = isPassword;
156             this.isHidden = isHidden;
157         }
158 
159         public String getName() {
160             return name;
161         }
162 
163         public void setName(String name) {
164             this.name = name;
165         }
166 
167         public String getValue() {
168             return value;
169         }
170 
171         public void setValue(String value) {
172             this.value = value;
173         }
174 
175         public String getLabel() {
176             return label;
177         }
178 
179         public void setLabel(String label) {
180             this.label = label;
181         }
182 
183         public String getPlaceholder() {
184             return placeholder;
185         }
186 
187         public void setPlaceholder(String placeholder) {
188             this.placeholder = placeholder;
189         }
190 
191         public boolean isHidden() {
192             return isHidden;
193         }
194 
195         public void setHidden(boolean isHidden) {
196             this.isHidden = isHidden;
197         }
198 
199         public boolean isPassword() {
200             return isPassword;
201         }
202 
203         public void setPassword(boolean isPassword) {
204             this.isPassword = isPassword;
205         }
206     }
207 
208 }