Class JDomBuilder

java.lang.Object
org.apache.creadur.whisker.fromxml.JDomBuilder

public class JDomBuilder extends Object
Builds a model from xml using JDOM.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    org.apache.creadur.whisker.model.Descriptor
    build(InputStream xmlStream)
     
    org.apache.creadur.whisker.model.Descriptor
    build(org.jdom2.Document document)
    Builds work from the given document.
    org.apache.creadur.whisker.model.ByOrganisation
    byOrganisation(org.jdom2.Element byOrganisation, Map<String,org.apache.creadur.whisker.model.Organisation> organisationsById)
    Builds a by-organisation model from xml.
    org.apache.creadur.whisker.model.ByOrganisation
    byOrganisation(org.jdom2.Element element, org.apache.creadur.whisker.model.Organisation organisation)
    Builds a by-organisation model from xml.
    SortedSet<org.apache.creadur.whisker.model.ByOrganisation>
    collectByOrganisations(org.jdom2.Element parent, Map<String,org.apache.creadur.whisker.model.Organisation> map)
    Collects by-organisation children.
    Collection<org.apache.creadur.whisker.model.WithinDirectory>
    collectContents(org.jdom2.Document document, Map<String,org.apache.creadur.whisker.model.License> licenses, Map<String,org.apache.creadur.whisker.model.Organisation> organisations)
    Collects contents of the document.
    Collection<org.apache.creadur.whisker.model.Resource>
    collectResources(org.jdom2.Element element)
     
    org.apache.creadur.whisker.model.License
    license(org.jdom2.Element element)
    Builds a license model from xml.
    org.apache.creadur.whisker.model.License
    license(org.jdom2.Element element, Map<String,org.apache.creadur.whisker.model.License> licenses)
    Finds the license with an id matching that referenced by the element.
    Map<String,org.apache.creadur.whisker.model.License>
    mapLicenses(org.jdom2.Document document)
    Collects license definitions within document.
    mapNotices(org.jdom2.Document document)
    Collects notices in the given documents.
    Map<String,org.apache.creadur.whisker.model.Organisation>
    mapOrganisations(org.jdom2.Document document)
    Collects organisation definitions within document.
    org.apache.creadur.whisker.model.Organisation
    organisation(org.jdom2.Element element)
    Builds an organisation model from xml.
    org.apache.creadur.whisker.model.Organisation
    organisation(org.jdom2.Element element, Map<String,org.apache.creadur.whisker.model.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.
    org.apache.creadur.whisker.model.License
    primaryLicense(org.jdom2.Document document, Map<String,org.apache.creadur.whisker.model.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.
    Collection<org.apache.creadur.whisker.model.ByOrganisation>
    publicDomain(Map<String,org.apache.creadur.whisker.model.Organisation> organisations, org.jdom2.Element parent)
    Collects child organisations of public domain.
    org.apache.creadur.whisker.model.Resource
    resource(org.jdom2.Element element)
    Builds a resource.
    org.apache.creadur.whisker.model.WithinDirectory
    withinDirectory(org.jdom2.Element element, Map<String,org.apache.creadur.whisker.model.License> licenses, Map<String,org.apache.creadur.whisker.model.Organisation> organisations)
    Builds a within directory model from XML.
    org.apache.creadur.whisker.model.WithLicense
    withLicense(org.jdom2.Element element, Map<String,org.apache.creadur.whisker.model.License> licenses, Map<String,org.apache.creadur.whisker.model.Organisation> organisations)
     
    Collection<org.apache.creadur.whisker.model.WithLicense>
    withLicenses(Map<String,org.apache.creadur.whisker.model.License> licenses, Map<String,org.apache.creadur.whisker.model.Organisation> organisations, org.jdom2.Element parent)
    Collects child with-licenses.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • JDomBuilder

      public JDomBuilder()
  • Method Details

    • resource

      public org.apache.creadur.whisker.model.Resource resource(org.jdom2.Element element) throws UnexpectedElementException
      Builds a resource.
      Parameters:
      element - not null
      Returns:
      built resource, not null
      Throws:
      UnexpectedElementException - when element is not named 'resource'
    • organisation

      public org.apache.creadur.whisker.model.Organisation organisation(org.jdom2.Element element) throws UnexpectedElementException
      Builds an organisation model from xml.
      Parameters:
      element - , not null
      Returns:
      Organisation not null
      Throws:
      UnexpectedElementException - when element is not named 'organisation'
    • collectResources

      public Collection<org.apache.creadur.whisker.model.Resource> collectResources(org.jdom2.Element element)
      Parameters:
      element - JDOM element to collect.
      Returns:
      collected resources.
    • organisation

      public org.apache.creadur.whisker.model.Organisation organisation(org.jdom2.Element element, Map<String,org.apache.creadur.whisker.model.Organisation> organisationsById) throws MissingIDException
      Parameters:
      element - modelled ByOrganisation, not null
      organisationsById - 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

      public org.apache.creadur.whisker.model.ByOrganisation byOrganisation(org.jdom2.Element element, org.apache.creadur.whisker.model.Organisation organisation)
      Builds a by-organisation model from xml.
      Parameters:
      element - not null
      organisation - not null
      Returns:
      not null
    • byOrganisation

      public org.apache.creadur.whisker.model.ByOrganisation byOrganisation(org.jdom2.Element byOrganisation, Map<String,org.apache.creadur.whisker.model.Organisation> organisationsById) throws MissingIDException
      Builds a by-organisation model from xml.
      Parameters:
      byOrganisation - not null
      organisationsById - not null
      Returns:
      not null
      Throws:
      MissingIDException - when the linked organisation is not found in the given map
    • collectByOrganisations

      public SortedSet<org.apache.creadur.whisker.model.ByOrganisation> collectByOrganisations(org.jdom2.Element parent, Map<String,org.apache.creadur.whisker.model.Organisation> map)
      Collects by-organisation children.
      Parameters:
      parent - not null
      map - not null
      Returns:
      unmodifiable set sort by natural order, not null
    • license

      public org.apache.creadur.whisker.model.License license(org.jdom2.Element element)
      Builds a license model from xml.
      Parameters:
      element - not null
      Returns:
      not null
    • license

      public org.apache.creadur.whisker.model.License license(org.jdom2.Element element, Map<String,org.apache.creadur.whisker.model.License> licenses) throws MissingIDException
      Finds the license with an id matching that referenced by the element.
      Parameters:
      element - not null
      licenses - not null
      Returns:
      not null
      Throws:
      MissingIDException - when referenced license isn't found in the collection
    • withLicense

      public org.apache.creadur.whisker.model.WithLicense withLicense(org.jdom2.Element element, Map<String,org.apache.creadur.whisker.model.License> licenses, Map<String,org.apache.creadur.whisker.model.Organisation> organisations) throws MissingIDException
      Parameters:
      element - not null
      licenses - not null
      organisations - not null
      Returns:
      Builds a with-license model from xml.
      Throws:
      MissingIDException - when referenced license isn't found in the collection
    • parameters

      public Map<String,String> parameters(org.jdom2.Element element) throws DuplicateElementException
      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<org.apache.creadur.whisker.model.WithLicense> withLicenses(Map<String,org.apache.creadur.whisker.model.License> licenses, Map<String,org.apache.creadur.whisker.model.Organisation> organisations, org.jdom2.Element parent)
      Collects child with-licenses.
      Parameters:
      licenses - not null
      organisations - not null
      parent - not null
      Returns:
      not null, possibly empty
    • publicDomain

      public Collection<org.apache.creadur.whisker.model.ByOrganisation> publicDomain(Map<String,org.apache.creadur.whisker.model.Organisation> organisations, org.jdom2.Element parent)
      Collects child organisations of public domain.
      Parameters:
      organisations - not null
      parent - not null
      Returns:
      not null, possibly null
    • withinDirectory

      public org.apache.creadur.whisker.model.WithinDirectory withinDirectory(org.jdom2.Element element, Map<String,org.apache.creadur.whisker.model.License> licenses, Map<String,org.apache.creadur.whisker.model.Organisation> organisations)
      Builds a within directory model from XML.
      Parameters:
      element - not null
      licenses - not null
      organisations - not null
      Returns:
      not null
    • mapOrganisations

      public Map<String,org.apache.creadur.whisker.model.Organisation> mapOrganisations(org.jdom2.Document document)
      Collects organisation definitions within document.
      Parameters:
      document - , not null
      Returns:
      organisations indexed by id, not null possibly empty
    • mapLicenses

      public Map<String,org.apache.creadur.whisker.model.License> mapLicenses(org.jdom2.Document document)
      Collects license definitions within document.
      Parameters:
      document - , not null
      Returns:
      licenses, indexed by id, not null, possibly empty
    • primaryLicense

      public org.apache.creadur.whisker.model.License primaryLicense(org.jdom2.Document document, Map<String,org.apache.creadur.whisker.model.License> licenses)
      Finds the primary license for the given document from the given licenses.
      Parameters:
      document - not null
      licenses - not null
      Returns:
      not null
    • primaryCopyrightNotice

      public String primaryCopyrightNotice(org.jdom2.Document document)
      Gets the additional primary copyright notice from the document.
      Parameters:
      document - not null
      Returns:
      optional primary copyright notice, possibly null
    • mapNotices

      public Map<String,String> mapNotices(org.jdom2.Document document)
      Collects notices in the given documents.
      Parameters:
      document - , not null
      Returns:
      notices indexed by id, immutable, not null, possibly empty
    • primaryNotice

      public String primaryNotice(org.jdom2.Document document)
      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

      public String primaryOrganisationId(org.jdom2.Document document)
      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<org.apache.creadur.whisker.model.WithinDirectory> collectContents(org.jdom2.Document document, Map<String,org.apache.creadur.whisker.model.License> licenses, Map<String,org.apache.creadur.whisker.model.Organisation> organisations) throws DuplicateElementException
      Collects contents of the document.
      Parameters:
      document - not null
      licenses - not null
      organisations - not null
      Returns:
      not null, possibly empty
      Throws:
      DuplicateElementException - when directory names are not unique
    • build

      public org.apache.creadur.whisker.model.Descriptor build(org.jdom2.Document document)
      Builds work from the given document.
      Parameters:
      document - not null
      Returns:
      not null
    • build

      public org.apache.creadur.whisker.model.Descriptor build(InputStream xmlStream) throws org.jdom2.JDOMException, IOException
      Throws:
      org.jdom2.JDOMException
      IOException