CardDavXmlUtilsTest.ktCardDavXmlUtils: root element extraction, contact ID parsing from multiget requests, XML element name/value extraction with namespace support, and XML entity escaping. These utilities form the XML parsing backbone of the CardDAV protocol handler.CardDavXmlUtils provides lightweight XML parsing without a full DOM/SAX parser — using regex-based extraction for CardDAV-specific XML payloads. This approach is chosen because CardDAV XML payloads are structurally predictable (defined by RFCs 4918, 6352) and performance-critical.
Extracts the XML root element name from a string, handling optional XML declaration (<?xml ... ?>) and namespace-prefixed elements (d:multistatus). Tests cover:
<d:multistatus xmlns:d="DAV:"> → multistatus<?xml version="1.0"?>, returns multistatusThis is critical for the PROPFIND/REPORT response handler to dispatch to the correct response builder based on the root element type.
Parses a CardDAV addressbook-multiget REPORT request body to extract ProjectForge contact IDs from <d:href> elements. Tests parse a realistic XML payload with three <d:href>{path}/ProjectForge-{id}.vcf</d:href> entries and verify correct extraction of IDs 7833476, 7858940, 7859171.
The method uses regex matching on the ProjectForge-{id}.vcf filename pattern within href elements. The result is a Sequence<Int> (lazy evaluation via .toList()).
Finds a named element in XML and returns its qualified name including namespace prefix:
propd:propExtracts the text content of a named element from XML, handling:
<etag> </etag> → " " (preserves whitespace)<etag /> → null (no text content)<d:etag /> → null<d:sync-token>123456</d:sync-token> → 123456Escapes five XML special characters per the XML 1.0 spec:
< → <> → > (handled; test input contains >)" → "& → &' → '<hurzel test="dkfsld"> & ' is escaped to <hurzel test="dkfsld"> & '.
All tests use Kotlin's let scope function with raw string literals ("""...""") for XML test data. trimIndent() and trimMargin() are used to clean up multiline test fixtures while preserving XML structure.
868d6abb7 2025 -> 2026 63081666f Source file headers: 2024-> 2025. 5167dab99 WIP: Carddav 6c1daac93 WIP: Carddav 0d7a81f91 WIP: Carddav dc3936193 WIP: Carddav (Thunderbird works, readonly, including images etc.) caee35750 WIP: Carddav 2ad0cfe66 WIP: Carddav