refactored to class based system

This commit is contained in:
Legit Cheetah 2024-02-06 18:09:05 +01:00
parent 169c0a4c68
commit 36e2248ab3
19 changed files with 258 additions and 268 deletions

View File

@ -1,6 +1,6 @@
package main;
public enum htmlTagsEnum {
public enum HtmlTagsEnum {
//TestTag is only for testing, it is not a valid Html Tag!
TESTTAG("testtag"),
ABBREVIATION("abb"),
@ -69,7 +69,7 @@ public enum htmlTagsEnum {
return this.tag;
}
private htmlTagsEnum(String tag){
private HtmlTagsEnum(String tag){
this.tag = tag;
}
}

View File

@ -1,10 +1,11 @@
package main;
import main.htmlSites.siteGeneric;
import main.htmlSites.SiteGeneric;
public class Main {
public static void main(String[] args) {
siteGeneric site = new siteGeneric();
SiteGeneric site = new SiteGeneric();
site.setID("1");
System.out.println(site.build());
}
}

View File

@ -1,27 +0,0 @@
package main;
public class html {
public String htmlContentModule(htmlTagsEnum tag, String content){
return "<"+tag.getTag()+">\n"+content+"\n</"+tag.getTag()+">\n";
}
public String htmlInlineModule(htmlTagsEnum tag, String content){
return "<"+tag.getTag()+">"+content+"</"+tag.getTag()+">\n";
}
public String htmlSingleModule(htmlTagsEnum tag){
return "<"+tag.getTag()+">\n";
}
public String customContentModule(String tag, String content){
return "<"+tag+">\n"+content+"\n</"+tag+">\n";
}
public String customInlineModule(String tag, String content){
return "<"+tag+">"+content+"</"+tag+">\n";
}
public String customSingleModule(String tag){
return "<"+tag+">\n";
}
}

View File

@ -0,0 +1,17 @@
package main.htmlModules;
public class ModuleComment extends ModuleGeneric {
public ModuleComment(String comment){
this.comment = comment;
}
@Override
public StringBuilder build() {
StringBuilder output = new StringBuilder();
output
.append("<!--")
.append(comment)
.append("-->");
return output;
}
}

View File

@ -0,0 +1,62 @@
package main.htmlModules;
import main.HtmlTagsEnum;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class ModuleGeneric {
protected HtmlTagsEnum tag = null;
protected String comment;
protected List<ModuleGeneric> content = new ArrayList<>();
//Global Attributes
protected char accessKey;
protected String styleClass;
protected Boolean contentEditable;
protected String dataPrefix;
protected String dataValue;
protected String dir;
protected Enum draggable;
protected String enterKeyHint;
protected boolean hidden;
protected String id;
protected boolean inert;
protected Enum inputMethod;
protected Enum lang;
protected boolean popOver;
protected String popOverTaret;
protected Boolean spellcheck;
protected HashMap style;
protected int tabIndex;
protected String title;
protected Boolean translate;
//
public StringBuilder build(){
StringBuilder buildString = new StringBuilder();
buildString
.append("\n<")
.append(tag.getTag())
.append(id != null ? " id=\"" + id +"\"" : "")
.append(">");
for (ModuleGeneric moduleGeneric : content) {
if(moduleGeneric instanceof ModuleComment moduleComment){
buildString.append(moduleComment.build());
}else{
buildString.append(moduleGeneric.build());
}
}
buildString
.append("\n</")
.append(tag.getTag())
.append(">");
return buildString;
}
}

View File

@ -0,0 +1,35 @@
package main.htmlModules;
import main.HtmlTagsEnum;
public class ModuleTag extends ModuleGeneric {
public ModuleTag(){
}
public void addModule(ModuleGeneric module){
content.add(module);
}
public void addComment(String comment){
content.add(new ModuleComment(comment));
}
public void setID(String ID) {
this.id = ID;
}
public String getID() {
return id;
}
public void setTag(HtmlTagsEnum tag) {
this.tag = tag;
}
public HtmlTagsEnum getTag() {
return tag;
}
}

View File

@ -0,0 +1,10 @@
package main.htmlModules.tags;
import main.HtmlTagsEnum;
import main.htmlModules.ModuleTag;
public class ModuleBody extends ModuleTag {
public ModuleBody(){
setTag(HtmlTagsEnum.BODY);
}
}

View File

@ -0,0 +1,11 @@
package main.htmlModules.tags;
import main.HtmlTagsEnum;
import main.htmlModules.ModuleTag;
public class ModuleDiv extends ModuleTag {
public ModuleDiv(){
setTag(HtmlTagsEnum.DIV);
}
}

View File

@ -0,0 +1,10 @@
package main.htmlModules.tags;
import main.HtmlTagsEnum;
import main.htmlModules.ModuleTag;
public class ModuleHTML extends ModuleTag {
public ModuleHTML(){
setTag(HtmlTagsEnum.HTML);
}
}

View File

@ -0,0 +1,10 @@
package main.htmlModules.tags;
import main.HtmlTagsEnum;
import main.htmlModules.ModuleTag;
public class ModuleHead extends ModuleTag {
public ModuleHead(){
setTag(HtmlTagsEnum.HEAD);
}
}

View File

@ -0,0 +1,39 @@
package main.htmlSites;
import main.htmlModules.tags.ModuleBody;
import main.htmlModules.tags.ModuleHead;
import main.htmlModules.ModuleTag;
import main.HtmlTagsEnum;
public class SiteGeneric extends ModuleTag {
ModuleHead head;
ModuleBody body;
public SiteGeneric(){
this(new ModuleHead(),new ModuleBody());
}
public SiteGeneric(ModuleHead head){
this(head ,new ModuleBody());
}
public SiteGeneric(ModuleBody body){
this(new ModuleHead(),body);
}
SiteGeneric(ModuleHead head, ModuleBody body){
this.head = head;
this.body = body;
setTag(HtmlTagsEnum.HTML);
addModule(this.head);
addModule(this.body);
}
@Override
public StringBuilder build() {
StringBuilder buildString = new StringBuilder();
buildString
.append("<!DOCTYPE html>")
.append(super.build());
return buildString;
}
}

View File

@ -1,39 +0,0 @@
package main.htmlSites;
import main.htmlTagModules.moduleBody;
import main.htmlTagModules.moduleGeneric;
import main.htmlTagModules.moduleHead;
import main.htmlTagsEnum;
public class siteGeneric extends moduleGeneric {
moduleHead head;
moduleBody body;
public siteGeneric(){
this(new moduleHead(),new moduleBody());
}
public siteGeneric(moduleHead head){
this(head ,new moduleBody());
}
public siteGeneric(moduleBody body){
this(new moduleHead(),body);
}
siteGeneric(moduleHead head, moduleBody body){
this.head = head;
this.body = body;
setTag(htmlTagsEnum.HTML);
addModule(this.head);
addModule(this.body);
}
@Override
public StringBuilder build() {
StringBuilder buildString = new StringBuilder();
buildString
.append("<!DOCTYPE html>")
.append(super.build());
return buildString;
}
}

View File

@ -1,9 +0,0 @@
package main.htmlTagModules;
import main.htmlTagsEnum;
public class moduleBody extends moduleGeneric{
public moduleBody(){
setTag(htmlTagsEnum.BODY);
}
}

View File

@ -1,10 +0,0 @@
package main.htmlTagModules;
import main.htmlTagsEnum;
public class moduleDiv extends moduleGeneric {
public moduleDiv(){
setTag(htmlTagsEnum.DIV);
}
}

View File

@ -1,50 +0,0 @@
package main.htmlTagModules;
import main.htmlTagsEnum;
import java.util.ArrayList;
public class moduleGeneric {
htmlTagsEnum tag = null;
int ID;
ArrayList<moduleGeneric> content = new ArrayList<>();
public void addModule(moduleGeneric module){
content.add(module);
}
public void setID(int ID) {
this.ID = ID;
}
public int getID() {
return ID;
}
public void setTag(htmlTagsEnum tag) {
this.tag = tag;
}
public htmlTagsEnum getTag() {
return tag;
}
public StringBuilder build(){
StringBuilder buildString = new StringBuilder();
buildString
.append("\n<")
.append(tag.getTag())
.append(">");
for (main.htmlTagModules.moduleGeneric moduleGeneric : content) {
buildString.append(moduleGeneric.build());
}
buildString
.append("\n</")
.append(tag.getTag())
.append(">");
return buildString;
}
}

View File

@ -1,9 +0,0 @@
package main.htmlTagModules;
import main.htmlTagsEnum;
public class moduleHTML extends moduleGeneric{
public moduleHTML(){
setTag(htmlTagsEnum.HTML);
}
}

View File

@ -1,9 +0,0 @@
package main.htmlTagModules;
import main.htmlTagsEnum;
public class moduleHead extends moduleGeneric {
public moduleHead(){
setTag(htmlTagsEnum.HEAD);
}
}

View File

@ -1,6 +1,6 @@
package test;
import main.htmlTagsEnum;
import main.HtmlTagsEnum;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
@ -9,63 +9,63 @@ public class htmlTagsEnumTest {
@Test
void htmlTagsEnumTagsTest(){
assertEquals(htmlTagsEnum.ABBREVIATION.getTag(),"abb");
assertEquals(htmlTagsEnum.ADDRESS.getTag(),"address");
assertEquals(htmlTagsEnum.ARTICLE.getTag(),"article");
assertEquals(htmlTagsEnum.ASIDE.getTag(),"aside");
assertEquals(htmlTagsEnum.BLINK.getTag(),"blink");
assertEquals(htmlTagsEnum.BIDIRECTIONALTEXTOVERRIDE.getTag(),"bdo");
assertEquals(htmlTagsEnum.BODY.getTag(),"body");
assertEquals(htmlTagsEnum.BOLD.getTag(),"b");
assertEquals(htmlTagsEnum.BREAK.getTag(),"br");
assertEquals(htmlTagsEnum.CANVAS.getTag(),"canvas");
assertEquals(htmlTagsEnum.CODE.getTag(),"code");
assertEquals(htmlTagsEnum.DELETE.getTag(),"delete");
assertEquals(htmlTagsEnum.DIV.getTag(),"div");
assertEquals(htmlTagsEnum.FIGURE.getTag(),"figure");
assertEquals(htmlTagsEnum.FIGURECAPTION.getTag(),"figcaption");
assertEquals(htmlTagsEnum.FOOTER.getTag(),"footer");
assertEquals(htmlTagsEnum.FORM.getTag(),"form");
assertEquals(htmlTagsEnum.HEAD.getTag(),"head");
assertEquals(htmlTagsEnum.HEADER.getTag(),"header");
assertEquals(htmlTagsEnum.HEADLINE1.getTag(),"h1");
assertEquals(htmlTagsEnum.HEADLINE2.getTag(),"h2");
assertEquals(htmlTagsEnum.HEADLINE3.getTag(),"h3");
assertEquals(htmlTagsEnum.HEADLINE4.getTag(),"h4");
assertEquals(htmlTagsEnum.HEADLINE5.getTag(),"h5");
assertEquals(htmlTagsEnum.HEADLINE6.getTag(),"h6");
assertEquals(htmlTagsEnum.INPUT.getTag(),"input");
assertEquals(htmlTagsEnum.INSERT.getTag(),"insert");
assertEquals(htmlTagsEnum.INTERNETFRAME.getTag(),"iframe");
assertEquals(htmlTagsEnum.ITALICS.getTag(),"i");
assertEquals(htmlTagsEnum.KEYGEN.getTag(),"keygen");
assertEquals(htmlTagsEnum.LINK.getTag(),"a");
assertEquals(htmlTagsEnum.LISTITEM.getTag(),"li");
assertEquals(htmlTagsEnum.LISTORDERED.getTag(),"ol");
assertEquals(htmlTagsEnum.LISTUNORDERED.getTag(),"ul");
assertEquals(htmlTagsEnum.MAIN.getTag(),"main");
assertEquals(htmlTagsEnum.MARQUEE.getTag(),"marquee");
assertEquals(htmlTagsEnum.MENU.getTag(),"menu");
assertEquals(htmlTagsEnum.META.getTag(),"meta");
assertEquals(htmlTagsEnum.NAVIGATION.getTag(),"nav");
assertEquals(htmlTagsEnum.PARAGRAPH.getTag(),"p");
assertEquals(htmlTagsEnum.PRETAG.getTag(),"pretag");
assertEquals(htmlTagsEnum.RUBY.getTag(),"ruby");
assertEquals(htmlTagsEnum.RUBYPARENTHESIS.getTag(),"rp");
assertEquals(htmlTagsEnum.RUBYTEXT.getTag(),"rt");
assertEquals(htmlTagsEnum.SCRIPT.getTag(),"script");
assertEquals(htmlTagsEnum.SECTION.getTag(),"section");
assertEquals(htmlTagsEnum.SMALL.getTag(),"small");
assertEquals(htmlTagsEnum.SPAN.getTag(),"span");
assertEquals(htmlTagsEnum.STRIKE.getTag(),"s");
assertEquals(htmlTagsEnum.TABLE.getTag(),"table");
assertEquals(htmlTagsEnum.TABLECOLUM.getTag(),"td");
assertEquals(htmlTagsEnum.TABLECOLUMNTITLE.getTag(),"th");
assertEquals(htmlTagsEnum.TABLEROW.getTag(),"tr");
assertEquals(htmlTagsEnum.TEXTAREA.getTag(),"textarea");
assertEquals(htmlTagsEnum.TITLE.getTag(),"title");
assertEquals(htmlTagsEnum.UNDERLINE.getTag(),"u");
assertEquals(htmlTagsEnum.VARIABLE.getTag(),"var");
assertEquals(htmlTagsEnum.WANTEDBREAK.getTag(),"wbr");
assertEquals(HtmlTagsEnum.ABBREVIATION.getTag(),"abb");
assertEquals(HtmlTagsEnum.ADDRESS.getTag(),"address");
assertEquals(HtmlTagsEnum.ARTICLE.getTag(),"article");
assertEquals(HtmlTagsEnum.ASIDE.getTag(),"aside");
assertEquals(HtmlTagsEnum.BLINK.getTag(),"blink");
assertEquals(HtmlTagsEnum.BIDIRECTIONALTEXTOVERRIDE.getTag(),"bdo");
assertEquals(HtmlTagsEnum.BODY.getTag(),"body");
assertEquals(HtmlTagsEnum.BOLD.getTag(),"b");
assertEquals(HtmlTagsEnum.BREAK.getTag(),"br");
assertEquals(HtmlTagsEnum.CANVAS.getTag(),"canvas");
assertEquals(HtmlTagsEnum.CODE.getTag(),"code");
assertEquals(HtmlTagsEnum.DELETE.getTag(),"delete");
assertEquals(HtmlTagsEnum.DIV.getTag(),"div");
assertEquals(HtmlTagsEnum.FIGURE.getTag(),"figure");
assertEquals(HtmlTagsEnum.FIGURECAPTION.getTag(),"figcaption");
assertEquals(HtmlTagsEnum.FOOTER.getTag(),"footer");
assertEquals(HtmlTagsEnum.FORM.getTag(),"form");
assertEquals(HtmlTagsEnum.HEAD.getTag(),"head");
assertEquals(HtmlTagsEnum.HEADER.getTag(),"header");
assertEquals(HtmlTagsEnum.HEADLINE1.getTag(),"h1");
assertEquals(HtmlTagsEnum.HEADLINE2.getTag(),"h2");
assertEquals(HtmlTagsEnum.HEADLINE3.getTag(),"h3");
assertEquals(HtmlTagsEnum.HEADLINE4.getTag(),"h4");
assertEquals(HtmlTagsEnum.HEADLINE5.getTag(),"h5");
assertEquals(HtmlTagsEnum.HEADLINE6.getTag(),"h6");
assertEquals(HtmlTagsEnum.INPUT.getTag(),"input");
assertEquals(HtmlTagsEnum.INSERT.getTag(),"insert");
assertEquals(HtmlTagsEnum.INTERNETFRAME.getTag(),"iframe");
assertEquals(HtmlTagsEnum.ITALICS.getTag(),"i");
assertEquals(HtmlTagsEnum.KEYGEN.getTag(),"keygen");
assertEquals(HtmlTagsEnum.LINK.getTag(),"a");
assertEquals(HtmlTagsEnum.LISTITEM.getTag(),"li");
assertEquals(HtmlTagsEnum.LISTORDERED.getTag(),"ol");
assertEquals(HtmlTagsEnum.LISTUNORDERED.getTag(),"ul");
assertEquals(HtmlTagsEnum.MAIN.getTag(),"main");
assertEquals(HtmlTagsEnum.MARQUEE.getTag(),"marquee");
assertEquals(HtmlTagsEnum.MENU.getTag(),"menu");
assertEquals(HtmlTagsEnum.META.getTag(),"meta");
assertEquals(HtmlTagsEnum.NAVIGATION.getTag(),"nav");
assertEquals(HtmlTagsEnum.PARAGRAPH.getTag(),"p");
assertEquals(HtmlTagsEnum.PRETAG.getTag(),"pretag");
assertEquals(HtmlTagsEnum.RUBY.getTag(),"ruby");
assertEquals(HtmlTagsEnum.RUBYPARENTHESIS.getTag(),"rp");
assertEquals(HtmlTagsEnum.RUBYTEXT.getTag(),"rt");
assertEquals(HtmlTagsEnum.SCRIPT.getTag(),"script");
assertEquals(HtmlTagsEnum.SECTION.getTag(),"section");
assertEquals(HtmlTagsEnum.SMALL.getTag(),"small");
assertEquals(HtmlTagsEnum.SPAN.getTag(),"span");
assertEquals(HtmlTagsEnum.STRIKE.getTag(),"s");
assertEquals(HtmlTagsEnum.TABLE.getTag(),"table");
assertEquals(HtmlTagsEnum.TABLECOLUM.getTag(),"td");
assertEquals(HtmlTagsEnum.TABLECOLUMNTITLE.getTag(),"th");
assertEquals(HtmlTagsEnum.TABLEROW.getTag(),"tr");
assertEquals(HtmlTagsEnum.TEXTAREA.getTag(),"textarea");
assertEquals(HtmlTagsEnum.TITLE.getTag(),"title");
assertEquals(HtmlTagsEnum.UNDERLINE.getTag(),"u");
assertEquals(HtmlTagsEnum.VARIABLE.getTag(),"var");
assertEquals(HtmlTagsEnum.WANTEDBREAK.getTag(),"wbr");
}
}

View File

@ -1,52 +0,0 @@
package test;
import main.html;
import main.htmlTagsEnum;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
class htmlTest {
html html = new main.html();
@Test
void htmlContentModuleTest() {
assertEquals("<testtag>\ncontent\n</testtag>\n",html.htmlContentModule(htmlTagsEnum.TESTTAG,"content"));
assertNotEquals("<testtag>\ncontent\n</testtag>\n",html.htmlContentModule(htmlTagsEnum.TESTTAG,"fail"));
assertNotEquals("<testtag>\ncontent\n</testtag>",html.htmlContentModule(htmlTagsEnum.TESTTAG,"content"));
}
@Test
void htmlInlineModuleTest() {
assertEquals("<testtag>content</testtag>\n",html.htmlInlineModule(htmlTagsEnum.TESTTAG,"content"));
assertNotEquals("<testtag>content</testtag>\n",html.htmlInlineModule(htmlTagsEnum.TESTTAG,"fail"));
assertNotEquals("<testtag>content</testtag>",html.htmlInlineModule(htmlTagsEnum.TESTTAG,"content"));
}
@Test
void htmlSingleModuleTest(){
assertEquals("testtag>\n", html.htmlSingleModule(htmlTagsEnum.TESTTAG));
assertNotEquals("testtag", html.htmlSingleModule(htmlTagsEnum.TESTTAG));
}
@Test
void customContentModuleTest() {
assertEquals("<testtag>\ncontent\n</testtag>\n",html.customContentModule("testtag","content"));
assertNotEquals("<testtag>\ncontent\n</testtag>\n",html.customContentModule("testtag","fail"));
assertNotEquals("<testtag>\ncontent\n</testtag>",html.customContentModule("testtag","content"));
}
@Test
void customInlineModuleTest() {
assertEquals("<testtag>content</testtag>\n",html.customInlineModule("testtag","content"));
assertNotEquals("<testtag>content</testtag>\n",html.customInlineModule("testtag","fail"));
assertNotEquals("<testtag>content</testtag>",html.customInlineModule("testtag","content"));
}
@Test
void customSingleModuleTest(){
assertEquals("testtag>\n", html.customSingleModule("testtag"));
assertNotEquals("testtag", html.customSingleModule("testtag"));
}
}