Class: ViewServiceDoc

ViewServiceDoc()

new ViewServiceDoc()

The ViewServiceDoc handles HTML returned from the MetacatUI view service. It handles parsing, normalizing, and annotating the HTML, including rewriting legacy ecogrid links, marking taxonomic coverage sections, and marking the first row of attribute tables as active. It also collects entity summaries from the HTML, including PIDs, file names, and object URLs.
Since:
  • 2.39.0
Source:

Methods

annotateEntitySection(section, pidopt) → {string|null}

Add entity details class and useful data attributes to one section.
Parameters:
Name Type Attributes Default Description
section Element Entity section element
pid string <optional>
null PID to set. Falls back to identifiers already present in the section.
Source:
Returns:
A selector for the annotated section
Type
string | null

annotateEntitySections(root) → {number}

Normalize and annotate entity sections using identifiers already present in the rendered HTML.
Parameters:
Name Type Description
root DocumentFragment Detached parse root
Source:
Returns:
Number of sections annotated
Type
number

collectEntities(root) → {Array.<object>}

Collect entity summaries from annotated sections.
Parameters:
Name Type Description
root DocumentFragment Detached parse root
Source:
Returns:
Plain entity summaries
Type
Array.<object>

createTemplate() → {HTMLTemplateElement|null}

Create a detached template for temporary HTML parsing.
Source:
Returns:
Parsed template, or null when the current runtime does not provide DOM APIs.
Type
HTMLTemplateElement | null

findAndAnnotateEntitySection(params) → {Element|null}

Find and annotate the section that describes one data entity.
Parameters:
Name Type Description
params object Lookup params
Source:
Returns:
Matching annotated entity section
Type
Element | null

findEntitySection(params) → {Element|null}

Find the section that describes one data entity.
Parameters:
Name Type Description
params object Lookup params
Properties
Name Type Attributes Description
pid string Entity PID
fileName string <optional>
Entity file name
metadataPid string <optional>
Current metadata PID
root DocumentFragment Detached parse root
Source:
Returns:
Matching entity section
Type
Element | null

findEntitySectionByAnchor(root, pid) → {Element|null}

Find an entity section by anchor ID.
Parameters:
Name Type Description
root DocumentFragment Detached parse root
pid string Normalized PID
Source:
Returns:
Matching section
Type
Element | null
Find an entity section by a legacy Online Distribution Info link.
Parameters:
Name Type Description
root DocumentFragment Detached parse root
pid string Normalized PID
Source:
Returns:
Matching section
Type
Element | null

findEntitySectionByFileName(root, fileName) → {Element|null}

Find an entity section by object or entity file name.
Parameters:
Name Type Description
root DocumentFragment Detached parse root
fileName string File name
Source:
Returns:
Matching section
Type
Element | null

getCandidateEntitySections(root) → {Array.<Element>}

Find possible entity sections in rendered metadata
Parameters:
Name Type Description
root DocumentFragment Detached parse root
Source:
Returns:
Candidate entity section elements
Type
Array.<Element>

getEntityName(section) → {string|null}

Get the entity display name from a section.
Parameters:
Name Type Description
section Element Entity section
Source:
Returns:
Entity name
Type
string | null

getObjectName(section) → {string|null}

Get the object/file name from a section.
Parameters:
Name Type Description
section Element Entity section
Source:
Returns:
Object name
Type
string | null

hasTransformError() → {boolean}

Check whether the view service returned a transform error response.
Source:
Returns:
True when parsing detected a transform error
Type
boolean

inferEntityPidFromSection(section) → {string|null}

Infer an entity PID from markup inside an entity section.
Parameters:
Name Type Description
section Element Candidate entity section
Source:
Returns:
Normalized PID, or null when not found
Type
string | null

isEmpty() → {boolean}

Check whether the rendered document has no content.
Source:
Returns:
True when the document is empty
Type
boolean

isUnstyled() → {boolean}

Check whether the rendered HTML is missing the expected metadata root.
Source:
Returns:
True when the document is rendered but unstyled
Type
boolean

markAttributeTableDefaults(root) → {number}

Mark the first row in each attribute list table active.
Parameters:
Name Type Description
root DocumentFragment Detached parse root
Source:
Returns:
Number of rows marked
Type
number

markLegacyTaxonomicCoverage(root) → {number}

Mark legacy taxonomic coverage sections for styling.
Parameters:
Name Type Description
root DocumentFragment Detached parse root
Source:
Returns:
Number of sections marked
Type
number

parse(rawHtmlopt, optionsopt) → {ViewServiceDoc}

Parse and normalize the rendered HTML.
Parameters:
Name Type Attributes Description
rawHtml string <optional>
Raw HTML. Defaults to the current `rawHtml`
options object <optional>
Parse options
Properties
Name Type Attributes Description
resolveBaseUrl string <optional>
Resolve URL for ecogrid links
Source:
Returns:
This instance
Type
ViewServiceDoc

recordMutation(type, detailsopt)

Record a deterministic markup mutation.
Parameters:
Name Type Attributes Description
type string Mutation type
details object <optional>
Mutation details
Source:

recordWarning(type, detailsopt)

Record a parse warning.
Parameters:
Name Type Attributes Description
type string Warning type
details object <optional>
Warning details
Source:
Rewrite legacy ecogrid links to resolve service links when configured.
Parameters:
Name Type Description
root DocumentFragment Detached parse root
Source:
Returns:
Number of links rewritten
Type
number

summarizeEntitySection(section, index) → {object}

Build a plain summary from one entity section.
Parameters:
Name Type Default Description
section Element Entity section
index number 0 Entity index
Source:
Returns:
Entity summary
Type
object

toJSON() → {object}

Return a JSON-safe snapshot.
Source:
Returns:
Plain document state
Type
object

dataIdMatchesPid(value, pid, xmlSafePid) → {boolean}

Compare a data-id value to a PID or its legacy XML-safe form.
Parameters:
Name Type Description
value string Candidate data-id
pid string Normalized PID
xmlSafePid string XML-safe PID
Source:
Returns:
True when the values match
Type
boolean

escapeAttributeValue(value) → {string}

Escape a value for use inside a quoted CSS attribute selector.
Parameters:
Name Type Description
value * Attribute value
Source:
Returns:
Escaped attribute value
Type
string

extractEcoGridPid(text) → {string|null}

Extract a PID from a legacy ecogrid link label.
Parameters:
Name Type Description
text string Link text
Source:
Returns:
PID, or null when not an ecogrid label
Type
string | null

extractPidFromHref(href) → {string|null}

Extract a likely DataONE PID from an object or resolve href.
Parameters:
Name Type Description
href string Candidate href
Source:
Returns:
Normalized PID, or null when not found
Type
string | null

findEntitySectionByDataId(root, pid) → {Element|null}

Find an entity section by existing data-id.
Parameters:
Name Type Description
root DocumentFragment Detached parse root
pid string Normalized PID
Source:
Returns:
Matching section
Type
Element | null
Find an entity section containing a link with data-pid.
Parameters:
Name Type Description
root DocumentFragment Detached parse root
pid string Normalized PID
Source:
Returns:
Matching section
Type
Element | null

findEntitySectionBySelector(root, criteria) → {Element|null}

Find an entity section by standardized data attributes.
Parameters:
Name Type Description
root DocumentFragment | Element Search root
criteria object Selector criteria
Source:
Returns:
Matching section
Type
Element | null

fromHtml(rawHtml, optionsopt) → {ViewServiceDoc}

Create and parse a rendered metadata document from raw HTML.
Parameters:
Name Type Attributes Description
rawHtml string Raw service response
options object <optional>
Constructor and parse options
Source:
Returns:
Parsed document
Type
ViewServiceDoc

getControlValue(section, labelText) → {string|null}

Get a value from a legacy label/control-well pair.
Parameters:
Name Type Description
section Element Entity section
labelText string Label text to match
Source:
Returns:
Control value
Type
string | null
Return the nearest entity container for a link, promoting a form section when needed to match legacy view-service markup.
Parameters:
Name Type Description
link Element Link element
Source:
Returns:
Entity container
Type
Element | null

getEntityObjectUrl(section, pid) → {string|null}

Get the object URL for an entity section.
Parameters:
Name Type Description
section Element Entity section
pid string Entity PID
Source:
Returns:
Object URL
Type
string | null

getSelector(criteriaopt) → {string}

Build a standardized selector for annotated entity sections.
Parameters:
Name Type Attributes Description
criteria object <optional>
Selector criteria
Properties
Name Type Attributes Description
pid string <optional>
Entity PID
fileName string <optional>
Entity file name
objectName string <optional>
Object name alias
entityName string <optional>
Entity name
Source:
Returns:
CSS selector, or an empty string when no criteria exist.
Type
string

hrefMatchesPid(href, pid) → {boolean}

Check whether an href contains a PID in one common encoded form.
Parameters:
Name Type Description
href string Candidate href
pid string Normalized PID
Source:
Returns:
True when href appears to reference the PID
Type
boolean
Infer a PID from online distribution links inside a section.
Parameters:
Name Type Description
section Element Candidate entity section
Source:
Returns:
Normalized PID, or null when not found
Type
string | null

isTransformError(html) → {boolean}

Determine whether a response is a view-service transform error message.
Parameters:
Name Type Description
html string Trimmed response text
Source:
Returns:
True when the text matches the known transform error
Type
boolean

normalizeHtml(value) → {string}

Normalize raw HTML input while preserving whitespace.
Parameters:
Name Type Description
value * Candidate HTML
Source:
Returns:
String HTML
Type
string

normalizeIdentifier(value) → {string|null}

Normalize view-service entity identifiers.
Parameters:
Name Type Description
value * Candidate identifier
Source:
Returns:
Normalized identifier, or null for empty input
Type
string | null
Rewrite one legacy ecogrid label to a resolve service URL.
Parameters:
Name Type Description
link string Link text that may contain an ecogrid PID
baseUrl string Resolve service base URL
Source:
Returns:
Rewrite data, or false when the link cannot be rewritten.
Type
Object | false

textIncludes(element, phrase) → {boolean}

Test whether element text includes a phrase.
Parameters:
Name Type Description
element Element Element to inspect
phrase string Phrase to find
Source:
Returns:
True when phrase is present
Type
boolean

ViewServiceDoc(optionsopt)

new ViewServiceDoc(optionsopt)

Parameters:
Name Type Attributes Description
options object <optional>
Constructor options
Properties
Name Type Attributes Description
pid string <optional>
PID or SID rendered by the view service
rawHtml string <optional>
Raw HTML returned by the service
url string <optional>
Final response URL
contentType string <optional>
Response content type
resolveBaseUrl string <optional>
Resolve URL used for legacy ecogrid link rewrites.
Source:

Methods

annotateEntitySection(section, pidopt) → {string|null}

Add entity details class and useful data attributes to one section.
Parameters:
Name Type Attributes Default Description
section Element Entity section element
pid string <optional>
null PID to set. Falls back to identifiers already present in the section.
Source:
Returns:
A selector for the annotated section
Type
string | null

annotateEntitySections(root) → {number}

Normalize and annotate entity sections using identifiers already present in the rendered HTML.
Parameters:
Name Type Description
root DocumentFragment Detached parse root
Source:
Returns:
Number of sections annotated
Type
number

collectEntities(root) → {Array.<object>}

Collect entity summaries from annotated sections.
Parameters:
Name Type Description
root DocumentFragment Detached parse root
Source:
Returns:
Plain entity summaries
Type
Array.<object>

createTemplate() → {HTMLTemplateElement|null}

Create a detached template for temporary HTML parsing.
Source:
Returns:
Parsed template, or null when the current runtime does not provide DOM APIs.
Type
HTMLTemplateElement | null

findAndAnnotateEntitySection(params) → {Element|null}

Find and annotate the section that describes one data entity.
Parameters:
Name Type Description
params object Lookup params
Source:
Returns:
Matching annotated entity section
Type
Element | null

findEntitySection(params) → {Element|null}

Find the section that describes one data entity.
Parameters:
Name Type Description
params object Lookup params
Properties
Name Type Attributes Description
pid string Entity PID
fileName string <optional>
Entity file name
metadataPid string <optional>
Current metadata PID
root DocumentFragment Detached parse root
Source:
Returns:
Matching entity section
Type
Element | null

findEntitySectionByAnchor(root, pid) → {Element|null}

Find an entity section by anchor ID.
Parameters:
Name Type Description
root DocumentFragment Detached parse root
pid string Normalized PID
Source:
Returns:
Matching section
Type
Element | null
Find an entity section by a legacy Online Distribution Info link.
Parameters:
Name Type Description
root DocumentFragment Detached parse root
pid string Normalized PID
Source:
Returns:
Matching section
Type
Element | null

findEntitySectionByFileName(root, fileName) → {Element|null}

Find an entity section by object or entity file name.
Parameters:
Name Type Description
root DocumentFragment Detached parse root
fileName string File name
Source:
Returns:
Matching section
Type
Element | null

getCandidateEntitySections(root) → {Array.<Element>}

Find possible entity sections in rendered metadata
Parameters:
Name Type Description
root DocumentFragment Detached parse root
Source:
Returns:
Candidate entity section elements
Type
Array.<Element>

getEntityName(section) → {string|null}

Get the entity display name from a section.
Parameters:
Name Type Description
section Element Entity section
Source:
Returns:
Entity name
Type
string | null

getObjectName(section) → {string|null}

Get the object/file name from a section.
Parameters:
Name Type Description
section Element Entity section
Source:
Returns:
Object name
Type
string | null

hasTransformError() → {boolean}

Check whether the view service returned a transform error response.
Source:
Returns:
True when parsing detected a transform error
Type
boolean

inferEntityPidFromSection(section) → {string|null}

Infer an entity PID from markup inside an entity section.
Parameters:
Name Type Description
section Element Candidate entity section
Source:
Returns:
Normalized PID, or null when not found
Type
string | null

isEmpty() → {boolean}

Check whether the rendered document has no content.
Source:
Returns:
True when the document is empty
Type
boolean

isUnstyled() → {boolean}

Check whether the rendered HTML is missing the expected metadata root.
Source:
Returns:
True when the document is rendered but unstyled
Type
boolean

markAttributeTableDefaults(root) → {number}

Mark the first row in each attribute list table active.
Parameters:
Name Type Description
root DocumentFragment Detached parse root
Source:
Returns:
Number of rows marked
Type
number

markLegacyTaxonomicCoverage(root) → {number}

Mark legacy taxonomic coverage sections for styling.
Parameters:
Name Type Description
root DocumentFragment Detached parse root
Source:
Returns:
Number of sections marked
Type
number

parse(rawHtmlopt, optionsopt) → {ViewServiceDoc}

Parse and normalize the rendered HTML.
Parameters:
Name Type Attributes Description
rawHtml string <optional>
Raw HTML. Defaults to the current `rawHtml`
options object <optional>
Parse options
Properties
Name Type Attributes Description
resolveBaseUrl string <optional>
Resolve URL for ecogrid links
Source:
Returns:
This instance
Type
ViewServiceDoc

recordMutation(type, detailsopt)

Record a deterministic markup mutation.
Parameters:
Name Type Attributes Description
type string Mutation type
details object <optional>
Mutation details
Source:

recordWarning(type, detailsopt)

Record a parse warning.
Parameters:
Name Type Attributes Description
type string Warning type
details object <optional>
Warning details
Source:
Rewrite legacy ecogrid links to resolve service links when configured.
Parameters:
Name Type Description
root DocumentFragment Detached parse root
Source:
Returns:
Number of links rewritten
Type
number

summarizeEntitySection(section, index) → {object}

Build a plain summary from one entity section.
Parameters:
Name Type Default Description
section Element Entity section
index number 0 Entity index
Source:
Returns:
Entity summary
Type
object

toJSON() → {object}

Return a JSON-safe snapshot.
Source:
Returns:
Plain document state
Type
object

dataIdMatchesPid(value, pid, xmlSafePid) → {boolean}

Compare a data-id value to a PID or its legacy XML-safe form.
Parameters:
Name Type Description
value string Candidate data-id
pid string Normalized PID
xmlSafePid string XML-safe PID
Source:
Returns:
True when the values match
Type
boolean

escapeAttributeValue(value) → {string}

Escape a value for use inside a quoted CSS attribute selector.
Parameters:
Name Type Description
value * Attribute value
Source:
Returns:
Escaped attribute value
Type
string

extractEcoGridPid(text) → {string|null}

Extract a PID from a legacy ecogrid link label.
Parameters:
Name Type Description
text string Link text
Source:
Returns:
PID, or null when not an ecogrid label
Type
string | null

extractPidFromHref(href) → {string|null}

Extract a likely DataONE PID from an object or resolve href.
Parameters:
Name Type Description
href string Candidate href
Source:
Returns:
Normalized PID, or null when not found
Type
string | null

findEntitySectionByDataId(root, pid) → {Element|null}

Find an entity section by existing data-id.
Parameters:
Name Type Description
root DocumentFragment Detached parse root
pid string Normalized PID
Source:
Returns:
Matching section
Type
Element | null
Find an entity section containing a link with data-pid.
Parameters:
Name Type Description
root DocumentFragment Detached parse root
pid string Normalized PID
Source:
Returns:
Matching section
Type
Element | null

findEntitySectionBySelector(root, criteria) → {Element|null}

Find an entity section by standardized data attributes.
Parameters:
Name Type Description
root DocumentFragment | Element Search root
criteria object Selector criteria
Source:
Returns:
Matching section
Type
Element | null

fromHtml(rawHtml, optionsopt) → {ViewServiceDoc}

Create and parse a rendered metadata document from raw HTML.
Parameters:
Name Type Attributes Description
rawHtml string Raw service response
options object <optional>
Constructor and parse options
Source:
Returns:
Parsed document
Type
ViewServiceDoc

getControlValue(section, labelText) → {string|null}

Get a value from a legacy label/control-well pair.
Parameters:
Name Type Description
section Element Entity section
labelText string Label text to match
Source:
Returns:
Control value
Type
string | null
Return the nearest entity container for a link, promoting a form section when needed to match legacy view-service markup.
Parameters:
Name Type Description
link Element Link element
Source:
Returns:
Entity container
Type
Element | null

getEntityObjectUrl(section, pid) → {string|null}

Get the object URL for an entity section.
Parameters:
Name Type Description
section Element Entity section
pid string Entity PID
Source:
Returns:
Object URL
Type
string | null

getSelector(criteriaopt) → {string}

Build a standardized selector for annotated entity sections.
Parameters:
Name Type Attributes Description
criteria object <optional>
Selector criteria
Properties
Name Type Attributes Description
pid string <optional>
Entity PID
fileName string <optional>
Entity file name
objectName string <optional>
Object name alias
entityName string <optional>
Entity name
Source:
Returns:
CSS selector, or an empty string when no criteria exist.
Type
string

hrefMatchesPid(href, pid) → {boolean}

Check whether an href contains a PID in one common encoded form.
Parameters:
Name Type Description
href string Candidate href
pid string Normalized PID
Source:
Returns:
True when href appears to reference the PID
Type
boolean
Infer a PID from online distribution links inside a section.
Parameters:
Name Type Description
section Element Candidate entity section
Source:
Returns:
Normalized PID, or null when not found
Type
string | null

isTransformError(html) → {boolean}

Determine whether a response is a view-service transform error message.
Parameters:
Name Type Description
html string Trimmed response text
Source:
Returns:
True when the text matches the known transform error
Type
boolean

normalizeHtml(value) → {string}

Normalize raw HTML input while preserving whitespace.
Parameters:
Name Type Description
value * Candidate HTML
Source:
Returns:
String HTML
Type
string

normalizeIdentifier(value) → {string|null}

Normalize view-service entity identifiers.
Parameters:
Name Type Description
value * Candidate identifier
Source:
Returns:
Normalized identifier, or null for empty input
Type
string | null
Rewrite one legacy ecogrid label to a resolve service URL.
Parameters:
Name Type Description
link string Link text that may contain an ecogrid PID
baseUrl string Resolve service base URL
Source:
Returns:
Rewrite data, or false when the link cannot be rewritten.
Type
Object | false

textIncludes(element, phrase) → {boolean}

Test whether element text includes a phrase.
Parameters:
Name Type Description
element Element Element to inspect
phrase string Phrase to find
Source:
Returns:
True when phrase is present
Type
boolean