BrightSide Workbench Full Report + Source Code
WebElement.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2021 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero 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  * This program 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 Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.elephant.web.context;
20 
21 import java.util.Map;
22 import java.util.TreeMap;
23 import org.turro.string.Strings;
24 import org.turro.elephant.context.IElement;
25 import org.turro.elephant.impl.context.AttributeItem;
26 import org.turro.elephant.impl.context.AttributeSupport;
27 import org.turro.elephant.impl.context.DefaultElement;
28 import org.turro.elephant.layout.IManageable;
29 import org.turro.reflection.Reflections;
30 
35 public class WebElement {
36 
37  private String elementClass, role;
38  private Map<String, String> attributes = new TreeMap<>();
39 
40  public String getElementClass() {
41  return elementClass;
42  }
43 
44  public void setElementClass(String elementClass) {
45  this.elementClass = elementClass;
46  }
47 
48  public String getRole() {
49  return role;
50  }
51 
52  public void setRole(String role) {
53  this.role = role;
54  }
55 
56  public Map<String, String> getAttributes() {
57  return attributes;
58  }
59 
60  public void setAttributes(Map<String, String> attributes) {
61  this.attributes = attributes;
62  }
63 
64  /* Utils */
65 
66  public boolean isEmpty() {
67  return Strings.isBlank(elementClass);
68  }
69 
70  /* Factory */
71 
72  public IElement getInstance(WebContext context) {
73  IElement element = isEmpty() ? null : (IElement) Reflections.of(elementClass).instance();
74  if(element == null) element = new DefaultElement();
75  AttributeSupport attribs = ((IManageable) element).getAttributes();
76  attributes.forEach((k, v) -> {
77  attribs.addAttribute(new AttributeItem("attrib:" + k, v, AttributeItem.STRING_ATTR, null));
78  });
79  return element;
80  }
81 
82 }
Map< String, String > getAttributes()
Definition: WebElement.java:56
void setAttributes(Map< String, String > attributes)
Definition: WebElement.java:60
void setElementClass(String elementClass)
Definition: WebElement.java:44
IElement getInstance(WebContext context)
Definition: WebElement.java:72