Package org.apache.juneau.console
Class CardSource
java.lang.Object
org.apache.juneau.console.CardSource
One authored card handed to a
CardTypeHandler: its attributes, its raw body, and helpers to parse the
body as JSON5 or capture it as a <template data-card>. Built by <@card> and by C3's
PageSpec; tests build it directly.
Example:
CardSource
- Since:
- 10.0.0
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionbody()bodyMap()Registers the raw body as a<template data-card="{id}">via the builder'sCardSource.Builder.templateSinkand returns the card's own id as the template name.static CardSource.BuilderStarts building aCardSource.Builds anIllegalArgumentExceptionwhose message is prefixed with"<@card id='%s'> ".booleanid()json()Parses the body as JSON5 (cached after the first call).src()title()type()
-
Method Details
-
create
Starts building aCardSource.- Parameters:
type- The card type name. Must not benull or blank.id- The card id. Must not benull or blank.- Returns:
- A new
CardSource.Builder. - Throws:
IllegalArgumentException- Iftypeoridisnull or blank.
-
type
- Returns:
- The card type name.
-
id
- Returns:
- The card id.
-
title
- Returns:
- The card title, or
null .
-
src
- Returns:
- The card's data-source URL, or
null .
-
body
- Returns:
- The raw, trimmed body, or
null when absent.
-
hasJsonBody
- Returns:
true whenCardSource.Builder.bodyMap(Map)was used, or the raw body's first non-whitespace character is an opening curly brace.
-
json
Parses the body as JSON5 (cached after the first call).- Returns:
- The parsed body, or the
CardSource.Builder.bodyMap(Map)wrapped as aJsonMapwhen that was used. - Throws:
IllegalArgumentException- E-25 if the body is not JSON5 shaped; E-24 if it is but fails to parse.
-
bodyMap
- Returns:
- The pre-built map passed to
CardSource.Builder.bodyMap(Map)(the C3 path), ornull .
-
captureTemplate
Registers the raw body as a<template data-card="{id}">via the builder'sCardSource.Builder.templateSinkand returns the card's own id as the template name.- Returns:
id().- Throws:
IllegalArgumentException- If the body is absent/blank, or no template sink was registered.
-
error
Builds anIllegalArgumentExceptionwhose message is prefixed with"<@card id='%s'> ".- Parameters:
fmt- AString.format(String, Object...)pattern, using%splaceholders.args- The format arguments.- Returns:
- A new, unthrown exception (callers
throwit themselves).
-