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.ConsumerType;
23
24
25 /**
26 * Contains factory methods for creating and adding Html elements and specialized types.
27 * This class cannot be instanciated directly, but provides factory methods for HtmlElement-based classes.
28 */
29 @ConsumerType
30 public abstract class AbstractHtmlElementFactory extends AbstractElement {
31
32 private static final long serialVersionUID = 1L;
33
34 /**
35 * Initializes html element factory.
36 * @param name Element name
37 */
38 protected AbstractHtmlElementFactory(String name) {
39 super(name);
40 }
41
42 /**
43 * Creates and adds html element.
44 * @param elementName Element name
45 * @return Html element.
46 */
47 public final HtmlElement create(String elementName) {
48 return this.add(new HtmlElement(elementName));
49 }
50
51 /**
52 * Creates and adds html comment.
53 * @param text Comment
54 * @return Html comment.
55 */
56 public final HtmlComment createComment(String text) {
57 HtmlComment comment = new HtmlComment(text);
58 this.addContent(comment);
59 return comment;
60 }
61
62 /**
63 * Creates and adds div element.
64 * @return Html element.
65 */
66 public final Div createDiv() {
67 return this.add(new Div());
68 }
69
70 /**
71 * Creates and adds span element.
72 * @return Html element.
73 */
74 public final Span createSpan() {
75 return this.add(new Span());
76 }
77
78 /**
79 * Creates and adds span element.
80 * @param text Text
81 * @return Html element.
82 */
83 public final Span createSpan(String text) {
84 return this.add(new Span(text));
85 }
86
87 /**
88 * Creates and adds anchor (a) element.
89 * @return Html element.
90 */
91 public final Anchor createAnchor() {
92 return this.add(new Anchor());
93 }
94
95 /**
96 * Creates and adds anchor (a) element.
97 * @param href Html "href" attribute.
98 * @return Html element.
99 */
100 public final Anchor createAnchor(String href) {
101 return this.add(new Anchor(href));
102 }
103
104 /**
105 * Creates and adds anchor (a) element.
106 * @param href Html "href" attribute.
107 * @param target Html "target" attribute.
108 * @return Html element.
109 */
110 public final Anchor createAnchor(String href, String target) {
111 return this.add(new Anchor(href, target));
112 }
113
114 /**
115 * Creates and adds imgage (img) element.
116 * @return Html element.
117 */
118 public final Image createImage() {
119 return this.add(new Image());
120 }
121
122 /**
123 * Creates and adds imgage (img) element.
124 * @param src Html "src" attribute.
125 * @return Html element.
126 */
127 public final Image createImage(String src) {
128 return this.add(new Image(src));
129 }
130
131 /**
132 * Creates and adds imgage (img) element.
133 * @param src Html "src" attribute.
134 * @param alt Html "alt" attribute.
135 * @return Html element.
136 */
137 public final Image createImage(String src, String alt) {
138 return this.add(new Image(src, alt));
139 }
140
141 /**
142 * Creates and adds imgage (img) element.
143 * @param src Html "src" attribute.
144 * @param width Html "width" attribute.
145 * @param height Html "height" attribute.
146 * @return Html element.
147 */
148 public final Image createImage(String src, int width, int height) {
149 return this.add(new Image(src, width, height));
150 }
151
152 /**
153 * Creates and adds imgage (img) element.
154 * @param src Html "src" attribute.
155 * @param alt Html "alt" attribute.
156 * @param width Html "width" attribute.
157 * @param height Html "height" attribute.
158 * @return Html element.
159 */
160 public final Image createImage(String src, String alt, int width, int height) {
161 return this.add(new Image(src, alt, width, height));
162 }
163
164 /**
165 * Creates and adds script element.
166 * @return Html element.
167 */
168 public final Script createScript() {
169 return this.add(new Script());
170 }
171
172 /**
173 * Creates and adds script element.
174 * @param script Script block
175 * @return Html element.
176 */
177 public final Script createScript(String script) {
178 return this.add(new Script(script));
179 }
180
181 /**
182 * Creates and adds noscript element.
183 * @return Html element.
184 */
185 public final NoScript createNoScript() {
186 return this.add(new NoScript());
187 }
188
189 /**
190 * Creates and adds figure element.
191 * @return Html element.
192 */
193 public final Figure createFigure() {
194 return this.add(new Figure());
195 }
196
197 /**
198 * Creates and adds figure caption element.
199 * @return Html element.
200 */
201 public final FigCaption createFigCaption() {
202 return this.add(new FigCaption());
203 }
204
205 /**
206 * Creates and adds video element.
207 * @return Html element.
208 */
209 public final Video createVideo() {
210 return this.add(new Video());
211 }
212
213 /**
214 * Creates and adds audio element.
215 * @return Html element.
216 */
217 public final Audio createAudio() {
218 return this.add(new Audio());
219 }
220
221 /**
222 * Creates and adds source element.
223 * @return Html element.
224 */
225 public final Source createSource() {
226 return this.add(new Source());
227 }
228
229 }