Files
LuaScript/src/main/java/org/openautonomousconnection/luascript/hosts/DomHost.java

150 lines
3.7 KiB
Java
Raw Normal View History

2026-01-16 21:47:04 +01:00
package org.openautonomousconnection.luascript.hosts;
import java.util.List;
import java.util.Map;
/**
2026-02-10 19:24:38 +01:00
* Abstraction over DOM access for scripting.
2026-01-16 21:47:04 +01:00
*
2026-02-10 19:24:38 +01:00
* <p>All element references are by stable element {@code id}.</p>
2026-01-16 21:47:04 +01:00
*/
public interface DomHost {
/**
2026-02-10 19:24:38 +01:00
* Returns a list of all element ids in the document.
2026-01-16 21:47:04 +01:00
*
2026-02-10 19:24:38 +01:00
* @return list of ids (never null)
2026-01-16 21:47:04 +01:00
*/
List<String> getAllElementIds();
/**
2026-02-10 19:24:38 +01:00
* Returns all attributes of the element.
2026-01-16 21:47:04 +01:00
*
* @param elementId element id
2026-02-10 19:24:38 +01:00
* @return attributes map (never null)
2026-01-16 21:47:04 +01:00
*/
Map<String, String> getAttributes(String elementId);
/**
2026-02-10 19:24:38 +01:00
* Returns the element tag name, lowercase if possible.
2026-01-16 21:47:04 +01:00
*
* @param elementId element id
2026-02-10 19:24:38 +01:00
* @return tag name (never null)
2026-01-16 21:47:04 +01:00
*/
String getTagName(String elementId);
/**
2026-02-10 19:24:38 +01:00
* Returns the element text content.
2026-01-16 21:47:04 +01:00
*
* @param elementId element id
2026-02-10 19:24:38 +01:00
* @return text (never null)
2026-01-16 21:47:04 +01:00
*/
String getTextContent(String elementId);
/**
2026-02-10 19:24:38 +01:00
* Sets the element text content.
2026-01-16 21:47:04 +01:00
*
* @param elementId element id
2026-02-11 23:24:54 +01:00
* @param text new text
2026-01-16 21:47:04 +01:00
*/
void setTextContent(String elementId, String text);
/**
2026-02-10 19:24:38 +01:00
* Returns an attribute value or null if missing.
2026-01-16 21:47:04 +01:00
*
* @param elementId element id
2026-02-11 23:24:54 +01:00
* @param name attribute name
2026-02-10 19:24:38 +01:00
* @return value or null if missing
2026-01-16 21:47:04 +01:00
*/
String getAttribute(String elementId, String name);
/**
2026-02-10 19:24:38 +01:00
* Sets an attribute value (empty string allowed).
2026-01-16 21:47:04 +01:00
*
* @param elementId element id
2026-02-11 23:24:54 +01:00
* @param name attribute name
* @param value attribute value
2026-01-16 21:47:04 +01:00
*/
void setAttribute(String elementId, String name, String value);
/**
2026-02-10 19:24:38 +01:00
* Removes an attribute from the element.
2026-01-16 21:47:04 +01:00
*
* @param elementId element id
2026-02-11 23:24:54 +01:00
* @param name attribute name
2026-01-16 21:47:04 +01:00
*/
void removeAttribute(String elementId, String name);
/**
2026-02-10 19:24:38 +01:00
* Returns the parent element id or null if none.
2026-01-16 21:47:04 +01:00
*
* @param elementId element id
* @return parent id or null
*/
String getParentId(String elementId);
/**
2026-02-10 19:24:38 +01:00
* Returns children element ids.
2026-01-16 21:47:04 +01:00
*
* @param elementId element id
2026-02-10 19:24:38 +01:00
* @return list of children ids (never null)
2026-01-16 21:47:04 +01:00
*/
List<String> getChildrenIds(String elementId);
/**
2026-02-10 19:24:38 +01:00
* Creates an element and makes it addressable immediately.
2026-01-16 21:47:04 +01:00
*
2026-02-11 23:24:54 +01:00
* @param tagName tag name
2026-02-10 19:24:38 +01:00
* @param requestedId requested id or null
2026-01-16 21:47:04 +01:00
* @return created element id
*/
String createElement(String tagName, String requestedId);
/**
2026-02-10 19:24:38 +01:00
* Removes an element from the document.
2026-01-16 21:47:04 +01:00
*
* @param elementId element id
*/
void removeElement(String elementId);
/**
2026-02-10 19:24:38 +01:00
* Appends a child element to a parent.
2026-01-16 21:47:04 +01:00
*
* @param parentId parent id
2026-02-11 23:24:54 +01:00
* @param childId child id
2026-01-16 21:47:04 +01:00
*/
void appendChild(String parentId, String childId);
/**
2026-02-10 19:24:38 +01:00
* Inserts {@code childId} before {@code beforeChildId} within {@code parentId}.
2026-01-16 21:47:04 +01:00
*
2026-02-11 23:24:54 +01:00
* @param parentId parent id
* @param childId child id
2026-01-16 21:47:04 +01:00
* @param beforeChildId existing child id
*/
void insertBefore(String parentId, String childId, String beforeChildId);
/**
2026-02-10 19:24:38 +01:00
* Checks if an element with the given id exists.
2026-01-16 21:47:04 +01:00
*
* @param id element id
* @return true if exists
*/
boolean exists(String id);
/**
2026-02-10 19:24:38 +01:00
* Queries elements by tag name and returns their ids.
2026-01-16 21:47:04 +01:00
*
2026-02-10 19:24:38 +01:00
* @param tagName tag name
* @return list of ids (never null)
2026-01-16 21:47:04 +01:00
*/
List<String> queryByTag(String tagName);
/**
2026-02-10 19:24:38 +01:00
* Queries elements by class token and returns their ids.
2026-01-16 21:47:04 +01:00
*
2026-02-10 19:24:38 +01:00
* @param className class name token
* @return list of ids (never null)
2026-01-16 21:47:04 +01:00
*/
List<String> queryByClass(String className);
}