From c7d531a10cf40d5f28f022f584c2d7396989e396 Mon Sep 17 00:00:00 2001 From: Legit Cheetah Date: Mon, 5 Feb 2024 14:32:51 +0100 Subject: [PATCH] added build method with working nesting --- src/main/Main.java | 11 ++++++++++- src/main/htmlTags/moduleBody.java | 7 +++++++ src/main/htmlTags/moduleDiv.java | 4 ++-- src/main/htmlTags/moduleGeneric.java | 21 ++++++++++++++++++++- 4 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 src/main/htmlTags/moduleBody.java diff --git a/src/main/Main.java b/src/main/Main.java index 60f7101..9022c4d 100644 --- a/src/main/Main.java +++ b/src/main/Main.java @@ -1,7 +1,16 @@ package main; +import main.htmlTags.*; + public class Main { public static void main(String[] args) { - + moduleBody body = new moduleBody(); + moduleDiv mainDiv = new moduleDiv(); + moduleDiv thirdDiv = new moduleDiv(); + moduleDiv secondDiv = new moduleDiv(); + body.addModule(mainDiv); + mainDiv.addModule(thirdDiv); + body.addModule(secondDiv); + System.out.println(body.build()); } } diff --git a/src/main/htmlTags/moduleBody.java b/src/main/htmlTags/moduleBody.java new file mode 100644 index 0000000..20a7ddc --- /dev/null +++ b/src/main/htmlTags/moduleBody.java @@ -0,0 +1,7 @@ +package main.htmlTags; + +public class moduleBody extends moduleGeneric{ + public moduleBody(){ + setTag("body"); + } +} diff --git a/src/main/htmlTags/moduleDiv.java b/src/main/htmlTags/moduleDiv.java index 421476f..9653611 100644 --- a/src/main/htmlTags/moduleDiv.java +++ b/src/main/htmlTags/moduleDiv.java @@ -2,7 +2,7 @@ package main.htmlTags; public class moduleDiv extends moduleGeneric { - public void tagDiv(){ - + public moduleDiv(){ + setTag("div"); } } diff --git a/src/main/htmlTags/moduleGeneric.java b/src/main/htmlTags/moduleGeneric.java index 2421010..32a023f 100644 --- a/src/main/htmlTags/moduleGeneric.java +++ b/src/main/htmlTags/moduleGeneric.java @@ -1,13 +1,16 @@ package main.htmlTags; +import java.util.ArrayList; + public class moduleGeneric { String tag = ""; int ID; + ArrayList content = new ArrayList<>(); public void addModule(moduleGeneric module){ - + content.add(module); } public void setID(int ID) { @@ -25,4 +28,20 @@ public class moduleGeneric { public String getTag() { return tag; } + + public StringBuilder build(){ + StringBuilder buildString = new StringBuilder(); + buildString + .append("\n<") + .append(tag) + .append(">"); + for (main.htmlTags.moduleGeneric moduleGeneric : content) { + buildString.append(moduleGeneric.build()); + } + buildString + .append("\n"); + return buildString; + } }