View Javadoc
1   /*
2    * #%L
3    * wcm.io
4    * %%
5    * Copyright (C) 2014 wcm.io
6    * %%
7    * Licensed under the Apache License, Version 2.0 (the "License");
8    * you may not use this file except in compliance with the License.
9    * You may obtain a copy of the License at
10   *
11   *      http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   * #L%
19   */
20  package io.wcm.handler.commons.dom;
21  
22  import org.osgi.annotation.versioning.ProviderType;
23  
24  /**
25   * Html anchor (a) element.
26   */
27  @ProviderType
28  @SuppressWarnings("java:S110") // # parent inheritance
29  public final class Anchor extends AbstractNonSelfClosingHtmlElement {
30  
31    private static final long serialVersionUID = 1L;
32  
33    private static final String ELEMENT_NAME = "a";
34  
35    private static final String ATTRIBUTE_REL = "rel";
36    private static final String ATTRIBUTE_HREF = "href";
37    private static final String ATTRIBUTE_TARGET = "target";
38    private static final String ATTRIBUTE_TABINDEX = "tabindex";
39    private static final String ATTRIBUTE_ACCESSKEY = "accesskey";
40  
41    /**
42     * Initializes html element.
43     */
44    public Anchor() {
45      super(ELEMENT_NAME);
46    }
47  
48    /**
49     * Initializes html element.
50     * @param href Html "href" attribute.
51     */
52    public Anchor(String href) {
53      this();
54      setHRef(href);
55    }
56  
57    /**
58     * Initializes html element.
59     * @param href Html "href" attribute.
60     * @param target Html "target" attribute.
61     */
62    public Anchor(String href, String target) {
63      this();
64      setHRef(href);
65      setTarget(target);
66    }
67  
68    /**
69     * Html "rel" attribute.
70     * @return Value of attribute
71     */
72    public String getRel() {
73      return getAttributeValue(ATTRIBUTE_REL);
74    }
75  
76    /**
77     * Html "rel" attribute.
78     * @param value Value of attribute
79     * @return Self reference
80     */
81    public Anchor setRel(String value) {
82      setAttribute(ATTRIBUTE_REL, value);
83      return this;
84    }
85  
86    /**
87     * Html "href" attribute.
88     * @return Value of attribute
89     */
90    public String getHRef() {
91      return getAttributeValue(ATTRIBUTE_HREF);
92    }
93  
94    /**
95     * Html "href" attribute.
96     * @param value Value of attribute
97     * @return Self reference
98     */
99    public Anchor setHRef(String value) {
100     setAttribute(ATTRIBUTE_HREF, value);
101     return this;
102   }
103 
104   /**
105    * Html "target" attribute.
106    * @return Value of attribute
107    */
108   public String getTarget() {
109     return getAttributeValue(ATTRIBUTE_TARGET);
110   }
111 
112   /**
113    * Html "target" attribute.
114    * @param value Value of attribute
115    * @return Self reference
116    */
117   public Anchor setTarget(String value) {
118     setAttribute(ATTRIBUTE_TARGET, value);
119     return this;
120   }
121 
122   /**
123    * Html "tabindex" attribute.
124    * @return Value of attribute
125    */
126   public int getTabIndex() {
127     return getAttributeValueAsInteger(ATTRIBUTE_TABINDEX);
128   }
129 
130   /**
131    * Html "tabindex" attribute.
132    * @param value Value of attribute
133    * @return Self reference
134    */
135   public Anchor setTabIndex(int value) {
136     setAttributeValueAsInteger(ATTRIBUTE_TABINDEX, value);
137     return this;
138   }
139 
140   /**
141    * Html "accesskey" attribute.
142    * @return Value of attribute
143    */
144   public String getAccessKey() {
145     return getAttributeValue(ATTRIBUTE_ACCESSKEY);
146   }
147 
148   /**
149    * Html "accesskey" attribute.
150    * @param value Value of attribute
151    * @return Self reference
152    */
153   public Anchor setAccessKey(String value) {
154     setAttribute(ATTRIBUTE_ACCESSKEY, value);
155     return this;
156   }
157 
158   // -- overwrite methods for builder pattern with covariant return types --
159 
160   @Override
161   protected Anchor setEmptyAttributeValueAsBoolean(String attributeName, boolean value) {
162     return (Anchor)super.setEmptyAttributeValueAsBoolean(attributeName, value);
163   }
164 
165   @Override
166   public Anchor setId(String value) {
167     return (Anchor)super.setId(value);
168   }
169 
170   @Override
171   public Anchor setCssClass(String value) {
172     return (Anchor)super.setCssClass(value);
173   }
174 
175   @Override
176   public Anchor addCssClass(String value) {
177     return (Anchor)super.addCssClass(value);
178   }
179 
180   @Override
181   public Anchor setStyleString(String value) {
182     return (Anchor)super.setStyleString(value);
183   }
184 
185   @Override
186   public Anchor setStyle(String styleAttribute, String styleValue) {
187     return (Anchor)super.setStyle(styleAttribute, styleValue);
188   }
189 
190   @Override
191   public Anchor setTitle(String value) {
192     return (Anchor)super.setTitle(value);
193   }
194 
195   @Override
196   public Anchor setData(String attributeName, String value) {
197     return (Anchor)super.setData(attributeName, value);
198   }
199 
200   @Override
201   public Anchor setAttributeValueAsLong(String name, long value) {
202     return (Anchor)super.setAttributeValueAsLong(name, value);
203   }
204 
205   @Override
206   public Anchor setText(String text) {
207     return (Anchor)super.setText(text);
208   }
209 
210 }