Retarget java 8

This commit is contained in:
zontreck 2023-12-05 02:05:38 -07:00
parent db0a0eef97
commit daf65a6059
8 changed files with 687 additions and 749 deletions

View file

@ -1,3 +1,3 @@
apiVer=1.4 apiVer=1.4
Bus_API=1.0 Bus_API=1.0
Bus_Patch=29 Bus_Patch=30

View file

@ -2,11 +2,10 @@ package dev.zontreck.ariaslib.file;
import java.io.*; import java.io.*;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths;
public class AriaIO public class AriaIO {
{ public static void write(Path fileName, Entry folder) {
public static void write(Path fileName, Entry folder)
{
try { try {
DataOutputStream dos = new DataOutputStream(new FileOutputStream(fileName.toFile())); DataOutputStream dos = new DataOutputStream(new FileOutputStream(fileName.toFile()));
folder.write(dos); folder.write(dos);
@ -18,8 +17,7 @@ public class AriaIO
} }
} }
public static Entry read(Path fileName) public static Entry read(Path fileName) {
{
try { try {
DataInputStream dis = new DataInputStream(new FileInputStream(fileName.toFile())); DataInputStream dis = new DataInputStream(new FileInputStream(fileName.toFile()));
return Entry.read(dis); return Entry.read(dis);
@ -31,6 +29,6 @@ public class AriaIO
} }
public static Path resolveDataFile(String main) { public static Path resolveDataFile(String main) {
return Path.of(main+".aria"); return Paths.get(main + ".aria");
} }
} }

View file

@ -1,19 +1,15 @@
package dev.zontreck.ariaslib.file; package dev.zontreck.ariaslib.file;
import dev.zontreck.ariaslib.terminal.Terminal;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Array;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
* An entry in the serialized file * An entry in the serialized file
*/ */
public class Entry<K> public class Entry<K> {
{
public static final byte YES = 1; public static final byte YES = 1;
public static final byte NO = 0; public static final byte NO = 0;
@ -21,297 +17,156 @@ public class Entry<K>
public String name; public String name;
public K value; public K value;
public Entry(K v, String name) public Entry(K v, String name) {
{ value = v;
value=v; this.name = name;
this.name=name; if (v instanceof String) {
if(v instanceof String) {
type = EntryType.STRING; type = EntryType.STRING;
}else if(v instanceof Integer) } else if (v instanceof Integer) {
{ type = EntryType.INT;
type=EntryType.INT; } else if (v instanceof List<?>) {
} else if(v instanceof List<?>)
{
type = EntryType.FOLDER; type = EntryType.FOLDER;
} else if(v instanceof Boolean) } else if (v instanceof Boolean) {
{
type = EntryType.BOOL; type = EntryType.BOOL;
} else if(v instanceof Long) } else if (v instanceof Long) {
{
type = EntryType.LONG; type = EntryType.LONG;
}else if(v instanceof Short) } else if (v instanceof Short) {
{
type = EntryType.SHORT; type = EntryType.SHORT;
}else if(v instanceof Byte) } else if (v instanceof Byte) {
{
type = EntryType.BYTE; type = EntryType.BYTE;
}else if(v instanceof Double) } else if (v instanceof Double) {
{
type = EntryType.DOUBLE; type = EntryType.DOUBLE;
}else if(v instanceof Float) } else if (v instanceof Float) {
{
type = EntryType.FLOAT; type = EntryType.FLOAT;
}else if(v instanceof int[]){ } else if (v instanceof int[]) {
type = EntryType.INT_ARRAY; type = EntryType.INT_ARRAY;
}else if(v instanceof String[]) } else if (v instanceof String[]) {
{
type = EntryType.STRING_ARRAY; type = EntryType.STRING_ARRAY;
}else if(v instanceof byte[]) } else if (v instanceof byte[]) {
{
type = EntryType.BYTE_ARRAY; type = EntryType.BYTE_ARRAY;
}else if(v instanceof long[]) } else if (v instanceof long[]) {
{
type = EntryType.LONG_ARRAY; type = EntryType.LONG_ARRAY;
} } else {
else{
type = EntryType.INVALID; type = EntryType.INVALID;
} }
} }
private Entry(){} private Entry() {
public void write(DataOutputStream dos) throws IOException {
dos.writeByte((int)type.value);
byte[] nameBytes = name.getBytes();
dos.writeInt(nameBytes.length);
dos.write(nameBytes);
switch(type)
{
case FOLDER:
{
List<Entry<?>> entries = (List<Entry<?>>) value;
dos.writeInt(entries.size());
for (Entry<?> x:
entries) {
x.write(dos);
}
break;
}
case STRING:
{
String s = (String)value;
byte[] bS = s.getBytes();
dos.writeInt(bS.length);
dos.write(bS);
break;
}
case INT:
{
dos.writeInt((int)value);
break;
}
case BOOL:
{
boolean X = (boolean)value;
if(X) dos.writeByte(YES);
else dos.writeByte(NO);
break;
}
case LONG:
{
long lng = (long)value;
dos.writeLong(lng);
break;
}
case SHORT:
{
short s = (short)value;
dos.writeShort(s);
break;
}
case BYTE:
{
dos.write((byte)value);
break;
}
case DOUBLE:
{
dos.writeDouble((double)value);
break;
}
case FLOAT:
{
dos.writeFloat((float)value);
break;
}
case INT_ARRAY:
{
int[] arr = (int[])value;
dos.writeInt(arr.length);
for (int x: arr
) {
dos.writeInt(x);
}
break;
}
case STRING_ARRAY:
{
String[] arr = (String[]) value;
dos.writeInt(arr.length);
for(String s : arr)
{
byte[] bArr = s.getBytes();
dos.writeInt(bArr.length);
dos.write(bArr);
}
break;
}
case BYTE_ARRAY:
{
byte[] arr = (byte[])value;
dos.writeInt(arr.length);
for(byte b : arr)
{
dos.write(b);
}
break;
}
case LONG_ARRAY:
{
long[] arr = (long[]) value;
dos.writeInt(arr.length);
for(long L : arr)
{
dos.writeLong(L);
}
break;
}
}
} }
public static Entry read(DataInputStream dis) throws IOException { public static Entry read(DataInputStream dis) throws IOException {
EntryType et = EntryType.of(dis.readByte()); EntryType et = EntryType.of(dis.readByte());
int nameLen = dis.readInt(); int nameLen = dis.readInt();
byte[] nm = dis.readNBytes(nameLen); byte[] nm = new byte[nameLen];
for (int i = 0; i < nameLen; i++) {
nm[i] = dis.readByte();
}
Entry work = new Entry<>(); Entry work = new Entry<>();
work.type = et; work.type = et;
work.name = new String(nm); work.name = new String(nm);
//System.out.println("Read start: " + work.name + " [ " + work.type.toString() + " ]"); //System.out.println("Read start: " + work.name + " [ " + work.type.toString() + " ]");
switch(et) switch (et) {
{ case FOLDER: {
case FOLDER:
{
Entry<List<Entry>> entries = (Entry<List<Entry>>) work; Entry<List<Entry>> entries = (Entry<List<Entry>>) work;
entries.value = new ArrayList<>(); entries.value = new ArrayList<>();
int numEntries = dis.readInt(); int numEntries = dis.readInt();
for(int i = 0; i<numEntries; i++) for (int i = 0; i < numEntries; i++) {
{
entries.value.add(Entry.read(dis)); entries.value.add(Entry.read(dis));
} }
break; break;
} }
case STRING: case STRING: {
{
Entry<String> w = (Entry<String>) work; Entry<String> w = (Entry<String>) work;
int vLen = dis.readInt(); int vLen = dis.readInt();
w.value = new String(dis.readNBytes(vLen)); byte[] x = new byte[vLen];
for (int i = 0; i < vLen; i++) {
x[i] = dis.readByte();
}
w.value = new String(x);
break; break;
} }
case INT: case INT: {
{
Entry<Integer> w = (Entry<Integer>) work; Entry<Integer> w = (Entry<Integer>) work;
w.value = dis.readInt(); w.value = dis.readInt();
break; break;
} }
case BOOL: case BOOL: {
{
Entry<Boolean> w = (Entry<Boolean>) work; Entry<Boolean> w = (Entry<Boolean>) work;
byte b = dis.readByte(); byte b = dis.readByte();
if(b == YES)w.value = true; if (b == YES) w.value = true;
else w.value=false; else w.value = false;
break; break;
} }
case LONG: case LONG: {
{
Entry<Long> w = (Entry<Long>) work; Entry<Long> w = (Entry<Long>) work;
w.value = dis.readLong(); w.value = dis.readLong();
break; break;
} }
case SHORT: case SHORT: {
{
Entry<Short> w = (Entry<Short>) work; Entry<Short> w = (Entry<Short>) work;
w.value = dis.readShort(); w.value = dis.readShort();
break; break;
} }
case BYTE: case BYTE: {
{
Entry<Byte> w = (Entry<Byte>) work; Entry<Byte> w = (Entry<Byte>) work;
w.value = dis.readByte(); w.value = dis.readByte();
break; break;
} }
case DOUBLE: case DOUBLE: {
{
Entry<Double> w = (Entry<Double>) work; Entry<Double> w = (Entry<Double>) work;
w.value = dis.readDouble(); w.value = dis.readDouble();
break; break;
} }
case FLOAT: case FLOAT: {
{
Entry<Float> w = (Entry<Float>) work; Entry<Float> w = (Entry<Float>) work;
w.value = dis.readFloat(); w.value = dis.readFloat();
break; break;
} }
case INT_ARRAY: case INT_ARRAY: {
{
Entry<int[]> w = (Entry<int[]>) work; Entry<int[]> w = (Entry<int[]>) work;
int num = dis.readInt(); int num = dis.readInt();
w.value = new int[num]; w.value = new int[num];
for(int i=0;i<num;i++) for (int i = 0; i < num; i++) {
{
w.value[i] = dis.readInt(); w.value[i] = dis.readInt();
} }
break; break;
} }
case STRING_ARRAY: case STRING_ARRAY: {
{
Entry<String[]> w = (Entry<String[]>) work; Entry<String[]> w = (Entry<String[]>) work;
int num = dis.readInt(); int num = dis.readInt();
w.value = new String[num]; w.value = new String[num];
for(int i=0;i<num;i++) for (int i = 0; i < num; i++) {
{
int len = dis.readInt(); int len = dis.readInt();
byte[] bStr = dis.readNBytes(len); byte[] bStr = new byte[len];
for (int j = 0; j < len; j++) {
bStr[j] = dis.readByte();
}
w.value[i] = new String(bStr); w.value[i] = new String(bStr);
} }
break; break;
} }
case BYTE_ARRAY: case BYTE_ARRAY: {
{
Entry<byte[]> w = (Entry<byte[]>) work; Entry<byte[]> w = (Entry<byte[]>) work;
int num = dis.readInt(); int num = dis.readInt();
w.value = new byte[num]; w.value = new byte[num];
for(int i=0;i<num;i++) for (int i = 0; i < num; i++) {
{
w.value[i] = dis.readByte(); w.value[i] = dis.readByte();
} }
break; break;
} }
case LONG_ARRAY: case LONG_ARRAY: {
{
Entry<long[]> w = (Entry<long[]>) work; Entry<long[]> w = (Entry<long[]>) work;
int num = dis.readInt(); int num = dis.readInt();
w.value = new long[num]; w.value = new long[num];
for(int i=0;i<num;i++) for (int i = 0; i < num; i++) {
{
w.value[i] = dis.readLong(); w.value[i] = dis.readLong();
} }
break; break;
@ -323,4 +178,104 @@ public class Entry<K>
return work; return work;
} }
public void write(DataOutputStream dos) throws IOException {
dos.writeByte((int) type.value);
byte[] nameBytes = name.getBytes();
dos.writeInt(nameBytes.length);
dos.write(nameBytes);
switch (type) {
case FOLDER: {
List<Entry<?>> entries = (List<Entry<?>>) value;
dos.writeInt(entries.size());
for (Entry<?> x :
entries) {
x.write(dos);
}
break;
}
case STRING: {
String s = (String) value;
byte[] bS = s.getBytes();
dos.writeInt(bS.length);
dos.write(bS);
break;
}
case INT: {
dos.writeInt((Integer) value);
break;
}
case BOOL: {
boolean x = (Boolean) value;
if (x) dos.writeByte(YES);
else dos.writeByte(NO);
break;
}
case LONG: {
dos.writeLong((Long) value);
break;
}
case SHORT: {
dos.writeShort((Short) value);
break;
}
case BYTE: {
dos.write((Byte) value);
break;
}
case DOUBLE: {
dos.writeDouble((Double) value);
break;
}
case FLOAT: {
dos.writeFloat((Float) value);
break;
}
case INT_ARRAY: {
int[] arr = (int[]) value;
dos.writeInt(arr.length);
for (int x : arr
) {
dos.writeInt(x);
}
break;
}
case STRING_ARRAY: {
String[] arr = (String[]) value;
dos.writeInt(arr.length);
for (String s : arr) {
byte[] bArr = s.getBytes();
dos.writeInt(bArr.length);
dos.write(bArr);
}
break;
}
case BYTE_ARRAY: {
byte[] arr = (byte[]) value;
dos.writeInt(arr.length);
for (byte b : arr) {
dos.write(b);
}
break;
}
case LONG_ARRAY: {
long[] arr = (long[]) value;
dos.writeInt(arr.length);
for (long L : arr) {
dos.writeLong(L);
}
break;
}
}
}
} }

View file

@ -6,285 +6,278 @@ import dev.zontreck.ariaslib.html.bootstrap.Size;
import dev.zontreck.ariaslib.util.Percent; import dev.zontreck.ariaslib.util.Percent;
public class Bootstrap { public class Bootstrap {
public static class Border { public static class Border {
public static Border make ( ) { public Side side;
return new Border ( ); public int width = 1;
} public boolean usesSides = false;
public Colors colors;
public boolean invert;
public enum Side { public static Border make() {
Start, return new Border();
End, }
Top,
Bottom
}
public Side side; public Border withColor(Colors color) {
public int width = 1; this.colors = color.withPrefix("border");
public boolean usesSides = false; return this;
public Colors colors; }
public Border withColor ( Colors color ) { public Border widthSide(Side side) {
this.colors = color.withPrefix ( "border" ); this.side = side;
return this; usesSides = true;
} return this;
}
public Border widthSide ( Side side ) { public Border withWidth(int width) {
this.side = side; this.width = width;
usesSides = true; return this;
return this; }
}
public Border withWidth ( int width ) { /**
this.width = width; * Removes borders instead of adding
return this; */
} public Border setInverted() {
invert = true;
return this;
}
public boolean invert; public void apply(HTMLElementBuilder elem) {
elem.addClass("border");
/** colors.apply(elem);
* Removes borders instead of adding
*/ if (usesSides) {
public Border setInverted ( ) { elem.addClass("border-" + side.name().toLowerCase() + (invert ? "-0" : ""));
invert = true; } else {
return this; if (invert) elem.addClass("border-0");
} }
}
public void apply ( HTMLElementBuilder elem ) { public enum Side {
elem.addClass ( "border" ); Start,
End,
Top,
Bottom
}
}
colors.apply ( elem ); public static class Opacity {
public Percent value;
public String prefix;
if ( usesSides ) { public static Opacity make() {
elem.addClass ( "border-" + side.name ( ).toLowerCase ( ) + ( invert ? "-0" : "" ) ); return new Opacity();
} }
else {
if ( invert ) elem.addClass ( "border-0" );
}
}
}
public static class Opacity { public Opacity withPercent(Percent val) {
public Percent value; value = val;
public String prefix; return this;
}
public static Opacity make ( ) { public Opacity withPrefix(String pref) {
return new Opacity ( ); this.prefix = pref;
} return this;
}
public Opacity withPercent ( Percent val ) { public void apply(HTMLElementBuilder builder) {
value = val; builder.addClass((prefix != "" ? prefix + "-" : "") + "opacity-" + value.get());
return this; }
} }
public Opacity withPrefix ( String pref ) { public static class Colors {
this.prefix = pref; public Color color;
return this; public boolean emphasis;
} public boolean subtle;
public String prefix;
public void apply ( HTMLElementBuilder builder ) { public static Colors make() {
builder.addClass ( ( prefix != "" ? prefix + "-" : "" ) + "opacity-" + value.get ( ) ); return new Colors();
} }
}
public static class Colors { public Colors withColor(Color color) {
public static Colors make ( ) { this.color = color;
return new Colors ( ); return this;
} }
public Color color; public Colors setEmphasis() {
public boolean emphasis; emphasis = true;
public boolean subtle; return this;
public String prefix; }
public Colors setSubtle() {
subtle = true;
return this;
}
public Colors withPrefix(String prefix) {
this.prefix = prefix;
return this;
}
public void apply(HTMLElementBuilder builder) {
builder.addClass(((prefix != "") ? prefix + "-" : "") + color.name().toLowerCase() + (emphasis ? "-emphasis" : "") + (subtle ? "-subtle" : ""));
}
}
public static class Background {
public Colors color;
public Opacity opacity;
public boolean gradient;
public static Background make() {
return new Background();
}
public Background withColor(Colors color) {
this.color = color.withPrefix("bg");
return this;
}
public Background withOpacity(Opacity op) {
this.opacity = op.withPrefix("bg");
return this;
}
public Background setGradient() {
gradient = true;
return this;
}
public Colors withColor ( Color color ) { public void apply(HTMLElementBuilder builder) {
this.color = color; color.apply(builder);
return this; opacity.apply(builder);
} if (gradient)
builder.addClass(".bg-gradient");
}
}
public Colors setEmphasis ( ) { public static class Shadow {
emphasis = true; public Size size;
return this;
}
public Colors setSubtle ( ) { public static Shadow make() {
subtle = true; return new Shadow();
return this; }
}
public Colors withPrefix ( String prefix ) { public Shadow withSize(Size size) {
this.prefix = prefix; this.size = size;
return this; return this;
} }
public void apply ( HTMLElementBuilder builder ) { public void apply(HTMLElementBuilder builder) {
builder.addClass ( ( ( prefix != "" ) ? prefix + "-" : "" ) + color.name ( ).toLowerCase ( ) + ( emphasis ? "-emphasis" : "" ) + ( subtle ? "-subtle" : "" ) ); builder.addClass("shadow" + size.sizeText());
} }
} }
public static class Background { public static class FocusRing {
public static Background make ( ) { public Colors color;
return new Background ( );
}
public Colors color; public static FocusRing make() {
public Opacity opacity; return new FocusRing();
public boolean gradient; }
public Background withColor ( Colors color ) { public FocusRing withColor(Colors color) {
this.color = color.withPrefix ( "bg" ); this.color = color.withPrefix("focus-ring");
return this; return this;
} }
public Background withOpacity ( Opacity op ) { public void apply(HTMLElementBuilder builder) {
this.opacity = op.withPrefix ( "bg" ); builder.addClass("focus-ring");
return this; color.apply(builder);
} }
}
public Background setGradient ( ) { public static class Link {
gradient = true; public Colors color;
return this;
} public static Link make() {
return new Link();
}
public Link withColor(Colors color) {
this.color = color.withPrefix("link");
return this;
}
public void apply(HTMLElementBuilder builder) {
color.apply(builder);
}
}
public static class Toast {
public Icons icon;
public HTMLElementBuilder toastHeader;
public HTMLElementBuilder toastBody;
public Toast() {
toastHeader = new HTMLElementBuilder("div").addClass("toast-header");
toastHeader.addChild("svg").addClass("bi").addClass(icon.getClassName()).addClass("rounded");
toastHeader.addChild("strong").addClass("me-auto");
toastHeader.addChild("small").withText("Text?");
toastHeader.addChild("button").withAttribute("type", "button").addClass("btn-close").withAttribute("data-bs-dismiss", "toast").withAttribute("aria-label", "Close");
toastBody = new HTMLElementBuilder("div").addClass("toast-body");
}
public static Toast make() {
return new Toast();
}
public Toast withIcon(Icons icon) {
this.icon = icon;
return this;
}
public void apply(HTMLElementBuilder builder) {
HTMLElementBuilder toast = builder.addChild("div").addClass("toast").withAttribute("role", "alert").withAttribute("aria-live", "assertive").withAttribute("aria-atomic", "true");
toast.addChild(toastHeader);
toast.addChild(toastBody);
}
}
public static class Button {
public Colors color;
public boolean outline;
public Size size;
public static Button make() {
return new Button();
}
public Button withColor(Colors color) {
this.color = color;
return this;
}
public Button setOutline() {
outline = true;
return this;
}
public Button withSize(Size size) {
this.size = size;
return this;
}
public void apply ( HTMLElementBuilder builder ) { public void apply(HTMLElementBuilder builder) {
color.apply ( builder ); builder.addClass("btn");
opacity.apply ( builder );
if ( gradient )
builder.addClass ( ".bg-gradient" );
}
}
public static class Shadow { if (outline) {
public static Shadow make ( ) { color.withPrefix("btn-outline");
return new Shadow ( ); } else color.withPrefix("btn");
}
public Size size; color.apply(builder);
if (size != Size.Regular)
builder.addClass("btn" + size.sizeText());
}
public Shadow withSize ( Size size ) { }
this.size = size;
return this;
}
public void apply ( HTMLElementBuilder builder ) { public static class Disabled {
builder.addClass ( "shadow" + size.sizeText ( ) ); public static void setDisabled(HTMLElementBuilder builder) {
} builder.withAttribute("disabled");
} }
}
public static class FocusRing {
public static FocusRing make ( ) {
return new FocusRing ( );
}
public Colors color;
public FocusRing withColor ( Colors color ) {
this.color = color.withPrefix ( "focus-ring" );
return this;
}
public void apply ( HTMLElementBuilder builder ) {
builder.addClass ( "focus-ring" );
color.apply ( builder );
}
}
public static class Link {
public static Link make ( ) {
return new Link ( );
}
public Colors color;
public Link withColor ( Colors color ) {
this.color = color.withPrefix ( "link" );
return this;
}
public void apply ( HTMLElementBuilder builder ) {
color.apply ( builder );
}
}
public static class Toast {
public static Toast make ( ) {
return new Toast ( );
}
public Icons icon;
public Toast withIcon ( Icons icon ) {
this.icon = icon;
return this;
}
public Toast ( ) {
toastHeader = new HTMLElementBuilder ( "div" ).addClass ( "toast-header" );
toastHeader.addChild ( "svg" ).addClass ( "bi" ).addClass ( icon.getClassName ( ) ).addClass ( "rounded" );
toastHeader.addChild ( "strong" ).addClass ( "me-auto" );
toastHeader.addChild ( "small" ).withText ( "Text?" );
toastHeader.addChild ( "button" ).withAttribute ( "type" , "button" ).addClass ( "btn-close" ).withAttribute ( "data-bs-dismiss" , "toast" ).withAttribute ( "aria-label" , "Close" );
toastBody = new HTMLElementBuilder ( "div" ).addClass ( "toast-body" );
}
public HTMLElementBuilder toastHeader;
public HTMLElementBuilder toastBody;
public void apply ( HTMLElementBuilder builder ) {
var toast = builder.addChild ( "div" ).addClass ( "toast" ).withAttribute ( "role" , "alert" ).withAttribute ( "aria-live" , "assertive" ).withAttribute ( "aria-atomic" , "true" );
toast.addChild ( toastHeader );
toast.addChild ( toastBody );
}
}
public static class Button {
public static Button make ( ) {
return new Button ( );
}
public Colors color;
public boolean outline;
public Button withColor ( Colors color ) {
this.color = color;
return this;
}
public Button setOutline ( ) {
outline = true;
return this;
}
public Size size;
public Button withSize ( Size size ) {
this.size = size;
return this;
}
public void apply ( HTMLElementBuilder builder ) {
builder.addClass ( "btn" );
if ( outline ) {
color.withPrefix ( "btn-outline" );
}
else color.withPrefix ( "btn" );
color.apply ( builder );
if ( size != Size.Regular )
builder.addClass ( "btn" + size.sizeText ( ) );
}
}
public static class Disabled {
public static void setDisabled ( HTMLElementBuilder builder ) {
builder.withAttribute ( "disabled" );
}
}
} }

View file

@ -3,53 +3,53 @@ package dev.zontreck.ariaslib.html;
public class DOM { public class DOM {
public static HTMLElementBuilder beginBootstrapDOM ( String pageTitle ) { public static HTMLElementBuilder beginBootstrapDOM(String pageTitle) {
var builder = new HTMLElementBuilder ( "!doctype" ).withText ( "html" ); HTMLElementBuilder builder = new HTMLElementBuilder("!doctype").withText("html");
var html = builder.getOrCreate ( "html" ); HTMLElementBuilder html = builder.getOrCreate("html");
var head = html.getOrCreate ( "head" ); HTMLElementBuilder head = html.getOrCreate("head");
head.addChild ( "meta" ).withAttribute ( "charset" , "utf-8" ); head.addChild("meta").withAttribute("charset", "utf-8");
head.addChild ( "meta" ).withAttribute ( "name" , "viewport" ).withAttribute ( "content" , "width=device-width, initial-scale=1" ); head.addChild("meta").withAttribute("name", "viewport").withAttribute("content", "width=device-width, initial-scale=1");
head.getOrCreate ( "link" ).withAttribute ( "href" , "https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" ).withAttribute ( "integrity" , "sha384-9ndCyUaIbzAi2FUVXJi0CjmCapSmO7SnpJef0486qhLnuZ2cdeRhO02iuK6FUUVM" ).withAttribute ( "crossorigin" , "anonymous" ).withAttribute ( "rel" , "stylesheet" ); head.getOrCreate("link").withAttribute("href", "https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css").withAttribute("integrity", "sha384-9ndCyUaIbzAi2FUVXJi0CjmCapSmO7SnpJef0486qhLnuZ2cdeRhO02iuK6FUUVM").withAttribute("crossorigin", "anonymous").withAttribute("rel", "stylesheet");
head.addClass ( "link" ).withAttribute ( "rel" , "stylesheet" ).withAttribute ( "href" , "https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css" ); head.addClass("link").withAttribute("rel", "stylesheet").withAttribute("href", "https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css");
head.getOrCreate ( "title" ).withText ( pageTitle ); head.getOrCreate("title").withText(pageTitle);
var body = html.getOrCreate ( "body" ); HTMLElementBuilder body = html.getOrCreate("body");
body.addChild ( "script" ).withAttribute ( "src" , "https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js" ).withAttribute ( "integrity" , "sha384-geWF76RCwLtnZ8qwWowPQNguL3RmwHVBC9FhGdlKrxdiJJigb/j/68SIy3Te4Bkz" ).withAttribute ( "crossorigin" , "anonymous" ).withText ( " " ); body.addChild("script").withAttribute("src", "https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js").withAttribute("integrity", "sha384-geWF76RCwLtnZ8qwWowPQNguL3RmwHVBC9FhGdlKrxdiJJigb/j/68SIy3Te4Bkz").withAttribute("crossorigin", "anonymous").withText(" ");
body.addChild ( "script" ).withAttribute ( "src" , "https://code.jquery.com/jquery-3.7.0.min.js" ).withAttribute ( "crossorigin" , "anonymous" ).withText ( " " ); body.addChild("script").withAttribute("src", "https://code.jquery.com/jquery-3.7.0.min.js").withAttribute("crossorigin", "anonymous").withText(" ");
body.addChild ( "style" ).withText ( "\n" + body.addChild("style").withText("\n" +
" .command-popover{\n" + " .command-popover{\n" +
" --bs-popover-header-bg: var(--bs-info);\n" + " --bs-popover-header-bg: var(--bs-info);\n" +
" --bs-popover-header-color: var(--bs-dark);\n" + " --bs-popover-header-color: var(--bs-dark);\n" +
" --bs-popover-bg: var(--bs-dark);\n" + " --bs-popover-bg: var(--bs-dark);\n" +
" --bs-popover-body-color: var(--bs-light);\n" + " --bs-popover-body-color: var(--bs-light);\n" +
" }\n" ); " }\n");
return builder; return builder;
} }
public static void addPopOverScan ( HTMLElementBuilder builder ) { public static void addPopOverScan(HTMLElementBuilder builder) {
builder.getChildByTagName ( "html" ).getChildByTagName ( "body" ).addChild ( "script" ).withText ( "" + builder.getChildByTagName("html").getChildByTagName("body").addChild("script").withText("" +
"function scanPopOver()" + "function scanPopOver()" +
"{" + "{" +
"var popoverTriggerList = document.querySelectorAll('[data-bs-toggle=\"popover\"]');\n" + "var popoverTriggerList = document.querySelectorAll('[data-bs-toggle=\"popover\"]');\n" +
"var popoverList = [...popoverTriggerList].map(popoverTriggerEl => new bootstrap.Popover(popoverTriggerEl));" + "var popoverList = [...popoverTriggerList].map(popoverTriggerEl => new bootstrap.Popover(popoverTriggerEl));" +
"" + "" +
"}" ); "}");
} }
public static String closeHTML ( ) { public static String closeHTML() {
return "</body></html>"; return "</body></html>";
} }
} }

View file

@ -1,28 +1,25 @@
package dev.zontreck.ariaslib.html.bootstrap; package dev.zontreck.ariaslib.html.bootstrap;
public enum Size public enum Size {
{ Small,
Small, Regular,
Regular, Large,
Large, None;
None;
public String sizeText() public String sizeText() {
{ switch (this) {
switch(this) case Small:
{ return "-sm";
case Small -> {
return "-sm"; case None:
} return "-none";
case None -> {
return "-none"; case Large:
} return "-lg";
case Large -> {
return "-lg"; default:
} return "";
default -> {
return ""; }
} }
}
}
} }

View file

@ -9,108 +9,107 @@ import java.util.List;
import java.util.Map; import java.util.Map;
public class DynamicSerializer { public class DynamicSerializer {
/** /**
* Serializes the object instance * Serializes the object instance
* *
* @param inst The class object to serialize * @param inst The class object to serialize
* @return A byte array of serialized data * @return A byte array of serialized data
*/ */
public static byte[] doSerialize ( Object inst ) throws InvocationTargetException, IllegalAccessException { public static byte[] doSerialize(Object inst) throws InvocationTargetException, IllegalAccessException {
Map<String, Object> ret = serialize ( inst ); Map<String, Object> ret = serialize(inst);
JsonObject js = new JsonObject ( ret ); JsonObject js = new JsonObject(ret);
return js.toJSONString ( ).getBytes ( ); return js.toJSONString().getBytes();
} }
private static Map<String, Object> serialize ( Object inst ) throws InvocationTargetException, IllegalAccessException { private static Map<String, Object> serialize(Object inst) throws InvocationTargetException, IllegalAccessException {
Class<?> clazz = inst.getClass ( ); Class<?> clazz = inst.getClass();
if ( ! clazz.isAnnotationPresent ( DynSerial.class ) ) if (!clazz.isAnnotationPresent(DynSerial.class))
return null; return null;
Method[] mth = clazz.getDeclaredMethods ( ); Method[] mth = clazz.getDeclaredMethods();
Method onComplete = null; Method onComplete = null;
for ( for (
Method mt : Method mt :
mth mth
) { ) {
if ( mt.isAnnotationPresent ( PreSerialize.class ) ) { if (mt.isAnnotationPresent(PreSerialize.class)) {
mt.invoke ( inst ); mt.invoke(inst);
} }
if ( mt.isAnnotationPresent ( Completed.class ) ) if (mt.isAnnotationPresent(Completed.class))
onComplete = mt; onComplete = mt;
} }
Field[] fields = clazz.getDeclaredFields ( ); Field[] fields = clazz.getDeclaredFields();
Map<String, Object> ret = new HashMap<> ( ); Map<String, Object> ret = new HashMap<>();
for ( for (
Field field : Field field :
fields fields
) { ) {
field.setAccessible ( true ); field.setAccessible(true);
if ( field.isAnnotationPresent ( IgnoreSerialization.class ) ) if (field.isAnnotationPresent(IgnoreSerialization.class))
continue; continue;
Object fieldVal = field.get ( inst ); Object fieldVal = field.get(inst);
if ( fieldVal == null ) continue; if (fieldVal == null) continue;
String fieldName = field.getName ( ); String fieldName = field.getName();
if (field.isAnnotationPresent ( ListOrMap.class )) { if (field.isAnnotationPresent(ListOrMap.class)) {
// Special handling for List and Map types // Special handling for List and Map types
ret.put(fieldName, serializeCollectionOrMap(fieldVal)); ret.put(fieldName, serializeCollectionOrMap(fieldVal));
continue; continue;
} }
if ( ! ( fieldVal.getClass ( ).isAnnotationPresent ( DynSerial.class ) ) ) { if (!(fieldVal.getClass().isAnnotationPresent(DynSerial.class))) {
// Special handler for List and Map is needed right here. // Special handler for List and Map is needed right here.
if(fieldVal instanceof List || fieldVal instanceof Map) continue; if (fieldVal instanceof List || fieldVal instanceof Map) continue;
ret.put ( fieldName , fieldVal ); ret.put(fieldName, fieldVal);
} } else {
else { Map<String, Object> TMP = serialize(fieldVal);
Map<String, Object> TMP = serialize ( fieldVal ); ret.put(fieldName, TMP);
ret.put ( fieldName , TMP ); }
} }
}
if ( onComplete != null ) if (onComplete != null)
onComplete.invoke ( inst , false ); onComplete.invoke(inst, false);
return ret; return ret;
} }
@SuppressWarnings ("unchecked") @SuppressWarnings("unchecked")
private static Object serializeCollectionOrMap ( Object collectionOrMap ) throws InvocationTargetException, IllegalAccessException { private static Object serializeCollectionOrMap(Object collectionOrMap) throws InvocationTargetException, IllegalAccessException {
if ( collectionOrMap instanceof List<?> list ) { if (collectionOrMap instanceof List<?>) {
List<Object> serializedList = new ArrayList<> ( ); List<?> list = (List<?>) collectionOrMap;
for ( Object item : list ) { List<Object> serializedList = new ArrayList<>();
if ( item.getClass ( ).isAnnotationPresent ( DynSerial.class ) ) { for (Object item : list) {
serializedList.add ( serialize ( item ) ); if (item.getClass().isAnnotationPresent(DynSerial.class)) {
} serializedList.add(serialize(item));
else { } else {
serializedList.add ( item ); serializedList.add(item);
} }
} }
return serializedList; return serializedList;
} } else if (collectionOrMap instanceof Map<?, ?>) {
else if ( collectionOrMap instanceof Map<?,?> mp ) { Map<?, ?> mp = (Map<?, ?>) collectionOrMap;
Map<String,Object> map = (Map<String, Object> ) mp; Map<String, Object> map = (Map<String, Object>) mp;
Map<String, Object> serializedMap = new HashMap<> ( ); Map<String, Object> serializedMap = new HashMap<>();
for ( Map.Entry<String, Object> entry : map.entrySet ( ) ) { for (Map.Entry<String, Object> entry : map.entrySet()) {
String key = entry.getKey ( ); String key = entry.getKey();
Object value = entry.getValue ( ); Object value = entry.getValue();
if ( value.getClass ( ).isAnnotationPresent ( DynSerial.class ) ) { if (value.getClass().isAnnotationPresent(DynSerial.class)) {
value = serialize ( value ); value = serialize(value);
} }
serializedMap.put ( key , value ); serializedMap.put(key, value);
} }
return serializedMap; return serializedMap;
} }
return collectionOrMap; return collectionOrMap;
} }
} }

View file

@ -10,178 +10,174 @@ import java.util.List;
import java.util.Map; import java.util.Map;
public class JsonObject { public class JsonObject {
private Map<String, Object> data; private Map<String, Object> data;
public JsonObject() { public JsonObject() {
data = new HashMap<>(); data = new HashMap<>();
} }
public JsonObject(Map<String, Object> dat) public JsonObject(Map<String, Object> dat) {
{ data = new HashMap<>(dat);
data = new HashMap<> ( dat ); }
}
public void put(String key, Object value) { public static JsonObject parseJSON(InputStream inputStream) throws IOException {
data.put(key, value); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
} StringBuilder jsonString = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
jsonString.append(line);
}
return parseJsonObject(jsonString.toString());
}
public Object get(String key) { private static JsonObject parseJsonObject(String jsonString) {
return data.get(key); JsonObject jsonObject = new JsonObject();
} jsonString = jsonString.trim();
if (jsonString.startsWith("{") && jsonString.endsWith("}")) {
jsonString = jsonString.substring(1, jsonString.length() - 1);
String[] keyValuePairs = jsonString.split(",");
for (String pair : keyValuePairs) {
String[] keyValue = pair.split(":");
if (keyValue.length == 2) {
String key = keyValue[0].trim().replace("\"", "");
String value = keyValue[1].trim();
jsonObject.put(key, parseValue(value));
}
}
}
return jsonObject;
}
public void merge(Map<String,Object> ret) private static Object parseValue(String value) {
{ if (value.startsWith("{") && value.endsWith("}")) {
data.putAll ( ret ); return parseJsonObject(value);
} } else if (value.startsWith("[") && value.endsWith("]")) {
return parseJSONArray(value);
} else if (value.startsWith("\"") && value.endsWith("\"")) {
return value.substring(1, value.length() - 1);
} else if (value.equalsIgnoreCase("true")) {
return true;
} else if (value.equalsIgnoreCase("false")) {
return false;
} else if (value.equalsIgnoreCase("null")) {
return null;
} else {
try {
return Integer.parseInt(value);
} catch (NumberFormatException e) {
try {
return Double.parseDouble(value);
} catch (NumberFormatException ex) {
return value;
}
}
}
}
public Map<String, Object> getMap() private static List<Object> parseJSONArray(String jsonArray) {
{ List<Object> list = new ArrayList<>();
return new HashMap<> ( data ); jsonArray = jsonArray.trim();
} if (jsonArray.startsWith("[") && jsonArray.endsWith("]")) {
jsonArray = jsonArray.substring(1, jsonArray.length() - 1);
String[] elements = jsonArray.split(",");
for (String element : elements) {
list.add(parseValue(element.trim()));
}
}
return list;
}
public void add(String key, Object value) { public void put(String key, Object value) {
if (data.containsKey(key)) { data.put(key, value);
Object existingValue = data.get(key); }
if (existingValue instanceof List) {
((List<Object>) existingValue).add(value);
} else {
List<Object> list = new ArrayList<>();
list.add(existingValue);
list.add(value);
data.put(key, list);
}
} else {
data.put(key, value);
}
}
public String toJSONString() { public Object get(String key) {
StringBuilder sb = new StringBuilder(); return data.get(key);
sb.append("{"); }
boolean first = true; public void merge(Map<String, Object> ret) {
for (Map.Entry<String, Object> entry : data.entrySet()) { data.putAll(ret);
if (!first) { }
sb.append(",");
}
first = false;
sb.append("\""); public Map<String, Object> getMap() {
sb.append(escape(entry.getKey())); return new HashMap<>(data);
sb.append("\":"); }
sb.append(toJSONValue(entry.getValue()));
}
sb.append("}"); public void add(String key, Object value) {
return sb.toString(); if (data.containsKey(key)) {
} Object existingValue = data.get(key);
if (existingValue instanceof List) {
((List<Object>) existingValue).add(value);
} else {
List<Object> list = new ArrayList<>();
list.add(existingValue);
list.add(value);
data.put(key, list);
}
} else {
data.put(key, value);
}
}
private String escape(String str) { public String toJSONString() {
if(str == null)return ""; StringBuilder sb = new StringBuilder();
// Add necessary escape characters (e.g., double quotes, backslashes) sb.append("{");
// You can implement this method based on your specific requirements.
// This is a simplified version for demonstration purposes.
return str.replace("\"", "\\\"");
}
private String toJSONValue(Object value) { boolean first = true;
if (value instanceof String) { for (Map.Entry<String, Object> entry : data.entrySet()) {
return "\"" + escape(value.toString()) + "\""; if (!first) {
} else if (value instanceof JsonObject js) { sb.append(",");
return js.toJSONString(); }
} else if (value instanceof List) { first = false;
return toJSONList ( ( List<Object> ) value );
} else if(value instanceof Map<?,?> mp )
{
return new JsonObject ( (Map<String, Object> ) mp ).toJSONString ();
} else {
return value.toString();
}
}
private String toJSONList(List<Object> list) { sb.append("\"");
StringBuilder sb = new StringBuilder(); sb.append(escape(entry.getKey()));
sb.append("["); sb.append("\":");
sb.append(toJSONValue(entry.getValue()));
}
boolean first = true; sb.append("}");
for (Object item : list) { return sb.toString();
if (!first) { }
sb.append(",");
}
first = false;
sb.append(toJSONValue(item)); private String escape(String str) {
} if (str == null) return "";
// Add necessary escape characters (e.g., double quotes, backslashes)
// You can implement this method based on your specific requirements.
// This is a simplified version for demonstration purposes.
return str.replace("\"", "\\\"");
}
sb.append("]"); private String toJSONValue(Object value) {
return sb.toString(); if (value instanceof String) {
} return "\"" + escape(value.toString()) + "\"";
} else if (value instanceof JsonObject) {
return ((JsonObject) value).toJSONString();
} else if (value instanceof List) {
return toJSONList((List<Object>) value);
} else if (value instanceof Map<?, ?>) {
return new JsonObject((Map<String, Object>) ((Map<?, ?>) value)).toJSONString();
} else {
return value.toString();
}
}
public static JsonObject parseJSON( InputStream inputStream) throws IOException { private String toJSONList(List<Object> list) {
BufferedReader reader = new BufferedReader(new InputStreamReader (inputStream)); StringBuilder sb = new StringBuilder();
StringBuilder jsonString = new StringBuilder(); sb.append("[");
String line;
while ((line = reader.readLine()) != null) {
jsonString.append(line);
}
return parseJsonObject(jsonString.toString());
}
private static JsonObject parseJsonObject(String jsonString) { boolean first = true;
JsonObject jsonObject = new JsonObject(); for (Object item : list) {
jsonString = jsonString.trim(); if (!first) {
if (jsonString.startsWith("{") && jsonString.endsWith("}")) { sb.append(",");
jsonString = jsonString.substring(1, jsonString.length() - 1); }
String[] keyValuePairs = jsonString.split(","); first = false;
for (String pair : keyValuePairs) {
String[] keyValue = pair.split(":");
if (keyValue.length == 2) {
String key = keyValue[0].trim().replace("\"", "");
String value = keyValue[1].trim();
jsonObject.put(key, parseValue(value));
}
}
}
return jsonObject;
}
private static Object parseValue(String value) { sb.append(toJSONValue(item));
if (value.startsWith("{") && value.endsWith("}")) { }
return parseJsonObject(value);
} else if (value.startsWith("[") && value.endsWith("]")) {
return parseJSONArray(value);
} else if (value.startsWith("\"") && value.endsWith("\"")) {
return value.substring(1, value.length() - 1);
} else if (value.equalsIgnoreCase("true")) {
return true;
} else if (value.equalsIgnoreCase("false")) {
return false;
} else if (value.equalsIgnoreCase("null")) {
return null;
} else {
try {
return Integer.parseInt(value);
} catch (NumberFormatException e) {
try {
return Double.parseDouble(value);
} catch (NumberFormatException ex) {
return value;
}
}
}
}
private static List<Object> parseJSONArray(String jsonArray) { sb.append("]");
List<Object> list = new ArrayList<>(); return sb.toString();
jsonArray = jsonArray.trim(); }
if (jsonArray.startsWith("[") && jsonArray.endsWith("]")) {
jsonArray = jsonArray.substring(1, jsonArray.length() - 1);
String[] elements = jsonArray.split(",");
for (String element : elements) {
list.add(parseValue(element.trim()));
}
}
return list;
}
} }