A webpage-building library for Java applications.

Overview

Hypertext

Opus 14

A clean, simple and well-structured framework for writing HTML pages in Java.

API documentation is available here.

Goals:

  1. Use minimal resources when creating and writing pages.
  2. Involve minimal boilerplate and screen-wastage for the user.
  3. Be applicable both for static and procedurally-generated pages.

Dependency Details

Hypertext is available in Kenzie's repository.

<repository>
  <id>kenzie</id>
  <name>Kenzie's Repository</name>
  <url>https://repo.kenzie.mx/releases</url>
</repository>
<dependency>
  <groupId>mx.kenzie</groupId>
  <artifactId>hypertext</artifactId>
  <version>1.0.2</version>
</dependency>

Using Hypertext

Pages can be written through the PageWriter resource, which deals with exceptions, charsets and output automatically. Pages can also be written manually through the element write method, but this requires more effort on the part of the user.

try (final PageWriter writer = new PageWriter(file)) { // auto-handles streams
    writer.write(page);
}

To assemble a page, HTMElements (HyperText Markup Elements) must be assembled using a hybrid constructor/builder process. Each element references an individual HTML <tag></tag> pair (or single <tag />) and contains its metadata and children.

These can be assembled manually using new HTMElement("tagname") but, for simplicity, Hypertext contains an entire set of pre-defined HTML tag elements according to the HTML5 schema.

These can be used with a static import (for simplicity.)

import static mx.kenzie.hypertext.element.StandardElements.*;

With this import, the tags may then be used by name.

new Page(
    DOCTYPE_HTML,
    HTML.child(
        HEAD.child(
            TITLE.write("Page Title"),
            META.set("name", "description").set("content", "My description.")
        ),
        BODY.child(
            DIV.child(
                P.write("goodbye! :)")
            )
        )
    )
);

Tags can be modified using their builder methods. If the tag is finalised (as the standard set are) this will create a modifiable clone that can be altered. This is done to save memory where possible by reusing element objects unless they need to be different.

The .child(element, element, ...) method adds multiple elements as children.

BODY.child( // <body>
    DIV.child( // <div>
        P.write("goodbye! :)"), // <p></p>
        P.write("goodbye! :)")  // <p></p>
    ) // </div>
) // </body>

The .set(key, value) method sets a meta tag in the header to the given value.

META.set("name", "description").set("content", "My description.")
// <meta name="description" content="My description." />

The .classes(class, class, ...) method adds (multiple) classes to the element.

DIV.classes("col", "col-md-8", "col-lg-12")
// <div class="col col-md-8 col-lg-12"></div>

Some individual element types may have additional modifier methods.

Adding CSS Rules

Hypertext supports constructing basic CSS selectors and rules. These can either be written into a STYLE element in the head, or into a stylesheet using another PageWriter. Since Rules are writable elements, they can be written as well as normal HTML.

The simplest way to write CSS rules is using the constructor.

HEAD.child( // <head>
    STYLE.child( // <style>
        new Rule("p").rule("color", "red"),
        new Rule("div").rule("border-bottom", "2px solid black")
    ) // </style>
) // </head>
p {
  color: red;
}
div {
  border-bottom: 2px solid black;
}

This also supports using the HTMElements directly to select tags.

STYLE.child(
    new Rule(DIV).rule("background", "red")
)

However, more advanced selector-building methods are also available.

The multi-element selector:

STYLE.child(
    Rule.all(UL, P, DIV, BR)
)
ul, p, div, br {
}

Complex attribute selectors:

STYLE.child(
    Rule.of(DIV, ATTRIBUTE_EQUALS.of("name", "hello"))
)
div[name=hello] {
}

Many more types are available, with examples in the documentation.

Unwrapping Existing HTML

Existing HTML files can be unwrapped into HTMElements. This allows navigating, editing and reconstructing the page.

try(final Page page = SourceUnwrapper.forHTML(source)) {
    // page is available here
}
You might also like...

LightAdmin - [PoC] Pluggable CRUD UI library for Java web applications

 LightAdmin - [PoC] Pluggable CRUD UI library for Java web applications

LightAdmin - [PoC] Pluggable CRUD UI library for Java web applications The primary goal of this PoC project is to speed up application development by

Dec 16, 2022

🏗 Build container images for your Java applications.

🏗 Build container images for your Java applications.

Jib ☑️ Jib User Survey What do you like best about Jib? What needs to be improved? Please tell us by taking a one-minute survey. Your responses will h

Jan 9, 2023

Rivr is a lightweight open-source dialogue engine enabling Java developers to easily create enterprise-grade VoiceXML applications.

Overview Rivr is a lightweight open-source dialogue engine enabling Java developers to easily create enterprise-grade VoiceXML applications. Read our

Jun 27, 2022

Two Spring-boot applications registering themselves to an spring-boot-admin-server application as separate clients for the purpose of monitoring and managing the clients

Two Spring-boot applications registering themselves to an spring-boot-admin-server application as separate clients for the purpose of monitoring and managing the clients

Spring-boot-admin implementation with 1 Server and 2 clients Creating a Server application to monitor and manage Spring boot applications (clients) un

Dec 6, 2022

Generates and keeps up-to-date your Spring Boot applications' Let's Encrypt or other ACME compliant SSL certificates.

Generates and keeps up-to-date your Spring Boot applications' Let's Encrypt or other ACME compliant SSL certificates.

Generates and keeps up-to-date your Spring Boot applications' Let's Encrypt or other ACME compliant SSL certificates. Pure Java in a single file of library code. An automated embedded alternative to Certbot and docker-sidecars. No JVM restart is needed on certificate update.

Nov 18, 2022

Stetho is a debug bridge for Android applications, enabling the powerful Chrome Developer Tools and much more.

Stetho Stetho is a sophisticated debug bridge for Android applications. When enabled, developers have access to the Chrome Developer Tools feature nat

Jan 3, 2023

Sequence Alignment - Aligns two strings optimally as to minimize the cost of alignment. This algorithm has applications in aligning DNA, RNA, or protein.

Sequence_Alignment Aligns two strings optimally as to minimize the cost of alignment. This algorithm has applications in aligning DNA, RNA, or protein

Jan 8, 2022

Rails like error pages for Spring Boot applications that are only active in development.

Rails like error pages for Spring Boot applications that are only active in development.

Better Error Pages Table of Contents Introduction Demo Quick Start Configuration Limitations License Introduction This is a Spring Boot Starter projec

Jan 2, 2022

Cloud Native and Low Code Platform to create FullStack web Admin applications in minutes

Cloud Native and Low Code Platform to create FullStack web Admin applications in minutes

Cloud Native and Low Code Platform to create FullStack web Admin applications in minutes ✨ Features & Technologies REST API generator Low Code CRUD &

Dec 26, 2022
Releases(1.0.4)
  • 1.0.4(Jan 29, 2022)

    This release supports unwrapping CSS code to Rule elements via the SourceUnwrapper.

    It also supports unwrapping CSS directly from a <style>...</style> block. A minor bug with unwrapping singlet tags <br /> <meta ... /> was fixed in this release.

    Source code(tar.gz)
    Source code(zip)
  • 1.0.3(Jan 23, 2022)

    This release supports formatted pretty-printing of HTML and CSS.

    The page-writer can be switched to pretty-printing with writer.format(unit).

    Source code(tar.gz)
    Source code(zip)
  • 1.0.2(Jan 13, 2022)

    This release allows disseminating written HTML into a tree of HTMElements that can be manipulated in Java. Using the navigator and other tools, the element tree can be edited, sanitised or modified and then printed back as HTML.

    This allows editing existing HTML pages in Java via a program.

    Currently, this does not support cross-language tags like CSS <style> or JavaScript <script> elements in the HTML body.

    Source code(tar.gz)
    Source code(zip)
  • 1.0.1(Jan 13, 2022)

  • 1.0.0(Jan 12, 2022)

    This is the first draft of Hypertext.

    Basic elements and page-building is available, but there is very litttle support for building CSS rules.

    Future drafts will work on improving the build process, minimising the heap load (with procedural discarding of elements) and making the API easier to use.

    Source code(tar.gz)
    Source code(zip)
Owner
Kenzie
I make things.
Kenzie
Cross-platform framework for building truly native mobile apps with Java or Kotlin

Cross-platform framework for building truly native mobile apps with Java or Kotlin. Write Once Run Anywhere support for iOS, Android, Desktop & Web.

Codename One 1.4k Jan 5, 2023
Building your own Notepad Clone using Java Programming

Notepad Clone Using Java Getting Started Build your own Notepad using Java Programming Project Specifications A Notepad Clone in which the user inputs

Muhammad Asad 8 Nov 8, 2022
This is the java/Maven application we are building to solve one real world problem.

timly This is the java/Maven application we are building to solve one real world problem. As in MLH we are working with fellows across the globe and e

Osakpolor Obaseki 3 Feb 16, 2022
Kryptokrona Java SDK for building decentralized private communication and payment systems.

Kryptokrona Java SDK Kryptokrona is a decentralized blockchain from the Nordic based on CryptoNote, which forms the basis for Monero, among others. Cr

null 22 Oct 31, 2022
source code of the live coding demo for "Building resilient and scalable API backends with Apache Pulsar and Spring Reactive" talk held at ApacheCon@Home 2021

reactive-iot-backend The is the source code of the live coding demo for "Building resilient and scalable API backends with Apache Pulsar and Spring Re

Lari Hotari 4 Jan 13, 2022
A joint research effort for building highly optimized Reactive-Streams compliant operators.

reactive-streams-commons A joint research effort for building highly optimized Reactive-Streams compliant operators. Current implementors include RxJa

Reactor 350 Dec 23, 2022
Exploring Spring and Sprinboot by building projects

Explore-Spring-Springboot Exploring Spring and Sprinboot by building projects Requirements Java-JDK: 17 IDE supporting Maven Integration: Intellij IDE

Deepraj 4 Sep 19, 2022
Source code of course - Building Real-Time REST APIs with Spring Boot

springboot-blog-rest-api Learn how to build real-time REST APIs with Spring Boot by building a complete Blog App. Source code of Popular Building Real

Ramesh Fadatare 123 Jan 6, 2023
Building Open-Ended Embodied Agents with Internet-Scale Knowledge

Building Open-Ended Embodied Agents with Internet-Scale Knowledge [Website] [Arxiv Paper] [PDF] [Docs] [Open Database] [MineCLIP] [Team] is a new AI r

null 927 Jan 4, 2023
Nrich is a Java library developed at CROZ whose purpose is to make development of applications on JVM a little easier.

nrich Nrich is a Java library developed at CROZ whose purpose is to make development of applications on JVM a little easier. It contains modules that

CROZ 44 Nov 12, 2022