Class JDomBuilder
java.lang.Object
org.apache.creadur.whisker.fromxml.JDomBuilder
Builds a model from xml using JDOM.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild(InputStream xmlStream) build(org.jdom2.Document document) Builds work from the given document.byOrganisation(org.jdom2.Element byOrganisation, Map<String, Organisation> organisationsById) Builds a by-organisation model from xml.byOrganisation(org.jdom2.Element element, Organisation organisation) Builds a by-organisation model from xml.collectByOrganisations(org.jdom2.Element parent, Map<String, Organisation> map) Collects by-organisation children.collectContents(org.jdom2.Document document, Map<String, License> licenses, Map<String, Organisation> organisations) Collects contents of the document.collectResources(org.jdom2.Element element) license(org.jdom2.Element element) Builds a license model from xml.Finds the license with an id matching that referenced by the element.mapLicenses(org.jdom2.Document document) Collects license definitions within document.mapNotices(org.jdom2.Document document) Collects notices in the given documents.mapOrganisations(org.jdom2.Document document) Collects organisation definitions within document.organisation(org.jdom2.Element element) Builds an organisation model from xml.organisation(org.jdom2.Element element, Map<String, Organisation> organisationsById) parameters(org.jdom2.Element element) Builds a list of parameter values by name.primaryCopyrightNotice(org.jdom2.Document document) Gets the additional primary copyright notice from the document.primaryLicense(org.jdom2.Document document, Map<String, License> licenses) Finds the primary license for the given document from the given licenses.primaryNotice(org.jdom2.Document document) Retrieves the text of the primary notice.primaryOrganisationId(org.jdom2.Document document) Retrieves the ID of the primary organisation.publicDomain(Map<String, Organisation> organisations, org.jdom2.Element parent) Collects child organisations of public domain.resource(org.jdom2.Element element) Builds a resource.withinDirectory(org.jdom2.Element element, Map<String, License> licenses, Map<String, Organisation> organisations) Builds a within directory model from XML.withLicense(org.jdom2.Element element, Map<String, License> licenses, Map<String, Organisation> organisations) withLicenses(Map<String, License> licenses, Map<String, Organisation> organisations, org.jdom2.Element parent) Collects child with-licenses.
-
Constructor Details
-
JDomBuilder
public JDomBuilder()
-
-
Method Details
-
resource
Builds a resource.- Parameters:
element- not null- Returns:
- built resource, not null
- Throws:
UnexpectedElementException- when element is not named 'resource'
-
organisation
Builds an organisation model from xml.- Parameters:
element- , not null- Returns:
Organisationnot null- Throws:
UnexpectedElementException- when element is not named 'organisation'
-
collectResources
- Parameters:
element- JDOM element to collect.- Returns:
- collected resources.
-
organisation
public Organisation organisation(org.jdom2.Element element, Map<String, Organisation> organisationsById) throws MissingIDException - Parameters:
element- modelled ByOrganisation, not nullorganisationsById- organisations identified, not null- Returns:
- Finds the organisation linked by ID from the given element.
- Throws:
MissingIDException- when the linked organisation is not found in the given map
-
byOrganisation
Builds a by-organisation model from xml.- Parameters:
element- not nullorganisation- not null- Returns:
- not null
-
byOrganisation
public ByOrganisation byOrganisation(org.jdom2.Element byOrganisation, Map<String, Organisation> organisationsById) throws MissingIDException Builds a by-organisation model from xml.- Parameters:
byOrganisation- not nullorganisationsById- not null- Returns:
- not null
- Throws:
MissingIDException- when the linked organisation is not found in the given map
-
collectByOrganisations
public SortedSet<ByOrganisation> collectByOrganisations(org.jdom2.Element parent, Map<String, Organisation> map) Collects by-organisation children.- Parameters:
parent- not nullmap- not null- Returns:
- unmodifiable set sort by natural order, not null
-
license
Builds a license model from xml.- Parameters:
element- not null- Returns:
- not null
-
license
public License license(org.jdom2.Element element, Map<String, License> licenses) throws MissingIDExceptionFinds the license with an id matching that referenced by the element.- Parameters:
element- not nulllicenses- not null- Returns:
- not null
- Throws:
MissingIDException- when referenced license isn't found in the collection
-
withLicense
public WithLicense withLicense(org.jdom2.Element element, Map<String, License> licenses, Map<String, Organisation> organisations) throws MissingIDException- Parameters:
element- not nulllicenses- not nullorganisations- not null- Returns:
- Builds a with-license model from xml.
- Throws:
MissingIDException- when referenced license isn't found in the collection
-
parameters
Builds a list of parameter values by name.- Parameters:
element- not null- Returns:
- parameter values indexed by value, not null
- Throws:
DuplicateElementException- when two parameters shared the same name
-
withLicenses
public Collection<WithLicense> withLicenses(Map<String, License> licenses, Map<String, Organisation> organisations, org.jdom2.Element parent) Collects child with-licenses.- Parameters:
licenses- not nullorganisations- not nullparent- not null- Returns:
- not null, possibly empty
-
publicDomain
public Collection<ByOrganisation> publicDomain(Map<String, Organisation> organisations, org.jdom2.Element parent) Collects child organisations of public domain.- Parameters:
organisations- not nullparent- not null- Returns:
- not null, possibly null
-
withinDirectory
public WithinDirectory withinDirectory(org.jdom2.Element element, Map<String, License> licenses, Map<String, Organisation> organisations) Builds a within directory model from XML.- Parameters:
element- not nulllicenses- not nullorganisations- not null- Returns:
- not null
-
mapOrganisations
Collects organisation definitions within document.- Parameters:
document- , not null- Returns:
- organisations indexed by id, not null possibly empty
-
mapLicenses
-
-
primaryCopyrightNotice
Gets the additional primary copyright notice from the document.- Parameters:
document- not null- Returns:
- optional primary copyright notice, possibly null
-
mapNotices
-
primaryNotice
Retrieves the text of the primary notice.- Parameters:
document- , not null- Returns:
- the text of the primary notice, or null when there is no primary notice
-
primaryOrganisationId
Retrieves the ID of the primary organisation.- Parameters:
document- , not null- Returns:
- the id of the primary organisation when set, otherwise null
-
collectContents
public Collection<WithinDirectory> collectContents(org.jdom2.Document document, Map<String, License> licenses, Map<String, Organisation> organisations) throws DuplicateElementExceptionCollects contents of the document.- Parameters:
document- not nulllicenses- not nullorganisations- not null- Returns:
- not null, possibly empty
- Throws:
DuplicateElementException- when directory names are not unique
-
build
Builds work from the given document.- Parameters:
document- not null- Returns:
- not null
-
build
- Throws:
org.jdom2.JDOMExceptionIOException
-