001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.juneau.bean.html5;
018
019import org.apache.juneau.marshall.*;
020
021/**
022 * DTO for an HTML <a class="doclink" href="https://www.w3.org/TR/html5/forms.html#the-keygen-element">&lt;keygen&gt;</a>
023 * element.
024 *
025 * <p>
026 * The keygen element represents a key-pair generator control for forms. It generates a public/private
027 * key pair and submits the public key to the server. This element is deprecated in HTML5 and should
028 * not be used in new projects. Modern web applications should use Web Crypto API instead.
029 *
030 * <h2 class='section'>Examples:</h2>
031 * <p class='bcode w800'>
032 *    <jk>import static</jk> org.apache.juneau.bean.html5.HtmlBuilder.*;
033 *
034 *    <jc>// Basic keygen with RSA key type</jc>
035 *    Keygen <jv>keygen1</jv> = <jsm>keygen</jsm>()
036 *       .name(<js>"userkey"</js>)
037 *       .keytype(<js>"RSA"</js>);
038 *
039 *    <jc>// Keygen with challenge string</jc>
040 *    Keygen <jv>keygen2</jv> = <jsm>keygen</jsm>()
041 *       .name(<js>"certkey"</js>)
042 *       .keytype(<js>"RSA"</js>)
043 *       .challenge(<js>"server-challenge-string"</js>);
044 *
045 *    <jc>// Keygen with form association</jc>
046 *    Keygen <jv>keygen3</jv> = <jsm>keygen</jsm>()
047 *       .name(<js>"formkey"</js>)
048 *       .keytype(<js>"DSA"</js>)
049 *       .form(<js>"myform"</js>);
050 *
051 *    <jc>// Keygen with disabled state</jc>
052 *    Keygen <jv>keygen4</jv> = <jsm>keygen</jsm>()
053 *       .name(<js>"disabledkey"</js>)
054 *       .keytype(<js>"RSA"</js>)
055 *       .disabled(<jk>true</jk>);
056 * </p>
057 *
058 * <p>
059 * The following convenience methods are provided for constructing instances of this bean:
060 * <ul class='javatree'>
061 *    <li class='jc'>{@link HtmlBuilder}
062 *    <ul class='javatree'>
063 *       <li class='jm'>{@link HtmlBuilder#keygen() keygen()}
064 *    </ul>
065 * </ul>
066 *
067 * <h2 class='section'>See Also:</h2><ul>
068 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauBeanHtml5">juneau-bean-html5</a>
069 * </ul>
070 */
071@Marshalled(typeName = "keygen")
072public class Keygen extends HtmlElementVoid<Keygen> {
073
074   /**
075    * Creates an empty {@link Keygen} element.
076    */
077   public Keygen() { /* Empty constructor. */ }
078
079   /**
080    * <a class="doclink" href="https://www.w3.org/TR/html5/forms.html#attr-fe-autofocus">autofocus</a> attribute.
081    *
082    * <p>
083    * Automatically focus the form control when the page is loaded.
084    *
085    * @param value
086    *    The new value for this attribute.
087    *    Typically a {@link Boolean} or {@link String}.
088    *    Can be <jk>null</jk> to unset the attribute.
089    * @return This object.
090    */
091   public Keygen autofocus(Object value) {
092      attr("autofocus", value);
093      return this;
094   }
095
096   /**
097    * <a class="doclink" href="https://www.w3.org/TR/html5/forms.html#attr-keygen-challenge">challenge</a> attribute.
098    *
099    * <p>
100    * Specifies a challenge string that will be packaged with the generated and signed public key.
101    * This is used for additional security in key generation processes.
102    *
103    * <p>
104    * The challenge string is typically provided by the server and used to verify the key generation.
105    *
106    * @param value The challenge string to package with the generated key. Can be <jk>null</jk> to unset the attribute.
107    * @return This object.
108    */
109   public Keygen challenge(String value) {
110      attr("challenge", value);
111      return this;
112   }
113
114   /**
115    * <a class="doclink" href="https://www.w3.org/TR/html5/forms.html#attr-fe-disabled">disabled</a> attribute.
116    *
117    * <p>
118    * Whether the form control is disabled.
119    *
120    * <p>
121    * This attribute uses deminimized values:
122    * <ul>
123    *    <li><jk>false</jk> - Attribute is not added</li>
124    *    <li><jk>true</jk> - Attribute is added as <js>"disabled"</js></li>
125    *    <li>Other values - Passed through as-is</li>
126    * </ul>
127    *
128    * @param value
129    *    The new value for this attribute.
130    *    Typically a {@link Boolean} or {@link String}.
131    *    Can be <jk>null</jk> to unset the attribute.
132    * @return This object.
133    */
134   public Keygen disabled(Object value) {
135      attr("disabled", deminimize(value, "disabled"));
136      return this;
137   }
138
139   /**
140    * <a class="doclink" href="https://www.w3.org/TR/html5/forms.html#attr-fae-form">form</a> attribute.
141    *
142    * <p>
143    * Associates the keygen element with a form element by specifying the form's ID. This allows the keygen
144    * to be placed outside the form element while still being part of the form.
145    *
146    * <p>
147    * The value should match the ID of a form element in the same document.
148    *
149    * @param value The ID of the form element to associate with this keygen. Can be <jk>null</jk> to unset the attribute.
150    * @return This object.
151    */
152   public Keygen form(String value) {
153      attr("form", value);
154      return this;
155   }
156
157   /**
158    * <a class="doclink" href="https://www.w3.org/TR/html5/forms.html#attr-keygen-keytype">keytype</a> attribute.
159    *
160    * <p>
161    * Specifies the type of cryptographic key to generate.
162    *
163    * <p>
164    * Common values:
165    * <ul>
166    *    <li><js>"RSA"</js> - RSA key pair (default)</li>
167    *    <li><js>"DSA"</js> - DSA key pair</li>
168    *    <li><js>"EC"</js> - Elliptic curve key pair</li>
169    * </ul>
170    *
171    * @param value The type of cryptographic key to generate. Can be <jk>null</jk> to unset the attribute.
172    * @return This object.
173    */
174   public Keygen keytype(String value) {
175      attr("keytype", value);
176      return this;
177   }
178
179   /**
180    * <a class="doclink" href="https://www.w3.org/TR/html5/forms.html#attr-fe-name">name</a> attribute.
181    *
182    * <p>
183    * Specifies the name of the keygen element. This name is used when the form is submitted and
184    * can be used to access the element via the form.elements API.
185    *
186    * <p>
187    * The name should be unique within the form and should not contain spaces or special characters.
188    *
189    * @param value The name of the keygen element for submission and API access. Can be <jk>null</jk> to unset the attribute.
190    * @return This object.
191    */
192   public Keygen name(String value) {
193      attr("name", value);
194      return this;
195   }
196
197}