Class JDomBuilder

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

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

    • JDomBuilder

      public JDomBuilder()
  • Method Details

    • resource

      public 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 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<Resource> collectResources(org.jdom2.Element element)
      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 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 ByOrganisation byOrganisation(org.jdom2.Element element, Organisation organisation)
      Builds a by-organisation model from xml.
      Parameters:
      element - not null
      organisation - 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 null
      organisationsById - 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 null
      map - not null
      Returns:
      unmodifiable set sort by natural order, not null
    • license

      public License license(org.jdom2.Element element)
      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 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 WithLicense withLicense(org.jdom2.Element element, Map<String,License> licenses, Map<String,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<WithLicense> withLicenses(Map<String,License> licenses, Map<String,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<ByOrganisation> publicDomain(Map<String,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 WithinDirectory withinDirectory(org.jdom2.Element element, Map<String,License> licenses, Map<String,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,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,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 License primaryLicense(org.jdom2.Document document, Map<String,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<WithinDirectory> collectContents(org.jdom2.Document document, Map<String,License> licenses, Map<String,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 Descriptor build(org.jdom2.Document document)
      Builds work from the given document.
      Parameters:
      document - not null
      Returns:
      not null
    • build

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