Example usage for org.apache.commons.digester3 Digester addSetNext

List of usage examples for org.apache.commons.digester3 Digester addSetNext

Introduction

In this page you can find the example usage for org.apache.commons.digester3 Digester addSetNext.

Prototype

public void addSetNext(String pattern, String methodName) 

Source Link

Document

Add a "set next" rule for the specified parameters.

Usage

From source file:org.gbif.metadata.eml.EmlFactory.java

/**
 * Uses rule based parsing to read the EML XML and build the EML model.
 * Note the following: - Metadata provider rules are omitted on the assumption that the provider is the same as the
 * creator - Contact rules are omitted on the assumption that contacts are covered by the creator and associated
 * parties - Publisher rules are omitted on the assumption the publisher is covered by the creator and associated
 * parties//from   ww  w.jav  a 2  s  .c  om
 *
 * @param xml To read. Note this will be closed before returning
 *
 * @return The EML populated
 *
 * @throws IOException  If the Stream cannot be read from
 * @throws SAXException If the XML is not well formed
 */
public static Eml build(InputStream xml) throws IOException, SAXException, ParserConfigurationException {
    Digester digester = new Digester();
    digester.setNamespaceAware(true);

    // push the EML object onto the stack
    Eml eml = new Eml();
    digester.push(eml);

    // add the rules

    // language as xml:lang attribute
    digester.addCallMethod("eml", "setMetadataLanguage", 1);
    digester.addCallParam("eml", 0, "xml:lang");
    // guid as packageId attribute
    digester.addCallMethod("eml", "setPackageId", 1);
    digester.addCallParam("eml", 0, "packageId");

    // alternative ids
    digester.addCallMethod("eml/dataset/alternateIdentifier", "addAlternateIdentifier", 1);
    digester.addCallParam("eml/dataset/alternateIdentifier", 0);

    // title together with language
    digester.addCallMethod("eml/dataset/title", "setTitle", 2);
    digester.addCallParam("eml/dataset/title", 0);
    digester.addCallParam("eml/dataset/title", 1, "xml:lang");

    digester.addBeanPropertySetter("eml/dataset/language", "language");

    // descriptions, broken into multiple paragraphs
    digester.addCallMethod("eml/dataset/abstract/para", "addDescriptionPara", 1);
    digester.addCallParam("eml/dataset/abstract/para", 0);

    digester.addBeanPropertySetter("eml/dataset/additionalInfo/para", "additionalInfo");
    digester.addRule("eml/dataset/intellectualRights/para", new NodeCreateRule(Node.ELEMENT_NODE));
    digester.addSetNext("eml/dataset/intellectualRights/para", "parseIntellectualRights");
    digester.addCallMethod("eml/dataset/methods/methodStep/description/para", "addMethodStep", 1);
    digester.addCallParam("eml/dataset/methods/methodStep/description/para", 0);
    digester.addBeanPropertySetter("eml/dataset/methods/sampling/studyExtent/description/para", "studyExtent");
    digester.addBeanPropertySetter("eml/dataset/methods/sampling/samplingDescription/para",
            "sampleDescription");
    digester.addBeanPropertySetter("eml/dataset/methods/qualityControl/description/para", "qualityControl");
    digester.addBeanPropertySetter("eml/dataset/distribution/online/url", "distributionUrl");
    digester.addBeanPropertySetter("eml/dataset/purpose/para", "purpose");
    digester.addBeanPropertySetter("eml/dataset/maintenance/description/para", "updateFrequencyDescription");
    digester.addCallMethod("eml/dataset/maintenance/maintenanceUpdateFrequency", "setUpdateFrequency", 1);
    digester.addCallParam("eml/dataset/maintenance/maintenanceUpdateFrequency", 0);
    digester.addCallMethod("eml/additionalMetadata/metadata/gbif/citation", "setCitation", 2);
    digester.addCallParam("eml/additionalMetadata/metadata/gbif/citation", 0);
    digester.addCallParam("eml/additionalMetadata/metadata/gbif/citation", 1, "identifier");
    digester.addCallMethod("eml/additionalMetadata/metadata/gbif/specimenPreservationMethod",
            "addSpecimenPreservationMethod", 1);
    digester.addCallParam("eml/additionalMetadata/metadata/gbif/specimenPreservationMethod", 0);
    digester.addBeanPropertySetter("eml/additionalMetadata/metadata/gbif/resourceLogoUrl", "logoUrl");
    digester.addBeanPropertySetter("eml/additionalMetadata/metadata/gbif/hierarchyLevel", "hierarchyLevel");
    digester.addCallMethod("eml/dataset/pubDate", "setPubDateAsString", 1);
    digester.addCallParam("eml/dataset/pubDate", 0);

    digester.addCallMethod("eml/additionalMetadata/metadata/gbif/dateStamp", "setDateStamp", 1);
    digester.addCallParam("eml/additionalMetadata/metadata/gbif/dateStamp", 0);

    addAgentRules(digester, "eml/dataset/creator", "addCreator");
    addAgentRules(digester, "eml/dataset/metadataProvider", "addMetadataProvider");
    addAgentRules(digester, "eml/dataset/contact", "addContact");
    addAgentRules(digester, "eml/dataset/associatedParty", "addAssociatedParty");
    addKeywordRules(digester);
    addBibliographicCitations(digester);
    addGeographicCoverageRules(digester);
    addTemporalCoverageRules(digester);
    addLivingTimePeriodRules(digester);
    addFormationPeriodRules(digester);
    addTaxonomicCoverageRules(digester);
    addProjectRules(digester);
    addCollectionRules(digester);
    addPhysicalDataRules(digester);
    addJGTICuratorialIUnit(digester);

    // now parse and return the EML
    try {
        digester.parse(xml);
    } finally {
        xml.close();
    }

    return eml;
}

From source file:org.gbif.metadata.eml.EmlFactory.java

/**
 * This is a reusable set of rules to build Agents and their Addresses, and add the Agent to the predecessor object
 * on the Stack Note that we are ignoring the userId as there have been no requests for the IPT to support this.
 *
 * @param digester     to add the rules to
 * @param prefix       The XPath prefix to prepend for extracting the Agent information
 * @param parentMethod Of the previous stack object to call and add the Agent to
 *///from   w ww .  ja  va 2s  . c  o  m
private static void addAgentRules(Digester digester, String prefix, String parentMethod) {
    digester.addObjectCreate(prefix, Agent.class);
    digester.addBeanPropertySetter(prefix + "/individualName/givenName", "firstName");
    digester.addBeanPropertySetter(prefix + "/individualName/surName", "lastName");
    digester.addBeanPropertySetter(prefix + "/organizationName", "organisation");
    digester.addBeanPropertySetter(prefix + "/positionName", "position");
    digester.addBeanPropertySetter(prefix + "/phone", "phone");
    digester.addBeanPropertySetter(prefix + "/electronicMailAddress", "email");
    digester.addBeanPropertySetter(prefix + "/onlineUrl", "homepage");

    digester.addBeanPropertySetter(prefix + "/role", "role");

    digester.addObjectCreate(prefix + "/address", Address.class);
    digester.addBeanPropertySetter(prefix + "/address/city", "city");
    digester.addBeanPropertySetter(prefix + "/address/administrativeArea", "province");
    digester.addBeanPropertySetter(prefix + "/address/postalCode", "postalCode");
    digester.addBeanPropertySetter(prefix + "/address/country", "country");
    digester.addBeanPropertySetter(prefix + "/address/deliveryPoint", "address");
    digester.addSetNext(prefix + "/address", "setAddress"); // called on </address> to set on parent Agent

    digester.addObjectCreate(prefix + "/userId", UserId.class);
    digester.addCallMethod(prefix + "/userId", "setDirectory", 1);
    digester.addCallParam(prefix + "/userId", 0, "directory");
    digester.addBeanPropertySetter(prefix + "/userId", "identifier");
    digester.addSetNext(prefix + "/userId", "addUserId"); // called on </userId> to set on parent Agent

    digester.addSetNext(prefix, parentMethod); // method called on parent object which is the previous stack object
}

From source file:org.gbif.metadata.eml.EmlFactory.java

/**
 * Add rules to extract the keywords.//from w  w  w  .j a v  a2 s . c  om
 *
 * @param digester to add the rules to
 */
private static void addKeywordRules(Digester digester) {
    digester.addObjectCreate("eml/dataset/keywordSet", KeywordSet.class);
    digester.addCallMethod("eml/dataset/keywordSet/keyword", "add", 1);
    digester.addCallParam("eml/dataset/keywordSet/keyword", 0);
    digester.addBeanPropertySetter("eml/dataset/keywordSet/keywordThesaurus", "keywordThesaurus");
    digester.addSetNext("eml/dataset/keywordSet", "addKeywordSet"); // add the
    // KeywordSet
    // to the
    // list in
    // EML
}

From source file:org.gbif.metadata.eml.EmlFactory.java

/**
 * Add rules to extract the bibliographic citations.
 *
 * @param digester to add the rules to//from w  w  w  .jav  a2  s .com
 */
private static void addBibliographicCitations(Digester digester) {
    digester.addObjectCreate("eml/additionalMetadata/metadata/gbif/bibliography",
            BibliographicCitationSet.class);
    digester.addCallMethod("eml/additionalMetadata/metadata/gbif/bibliography/citation", "add", 2);
    digester.addCallParam("eml/additionalMetadata/metadata/gbif/bibliography/citation", 0);
    digester.addCallParam("eml/additionalMetadata/metadata/gbif/bibliography/citation", 1, "identifier");
    // add the BibliographicCitations to the list in EML
    digester.addSetNext("eml/additionalMetadata/metadata/gbif/bibliography", "setBibliographicCitationSet");
}

From source file:org.gbif.metadata.eml.EmlFactory.java

/**
 * Adds rules to get the geographic coverage.
 *
 * @param digester to add the rules to/*from w w w .  jav  a2  s. co m*/
 */
private static void addGeographicCoverageRules(Digester digester) {
    digester.addObjectCreate("eml/dataset/coverage/geographicCoverage", GeospatialCoverage.class);
    digester.addBeanPropertySetter("eml/dataset/coverage/geographicCoverage/geographicDescription",
            "description");
    digester.addObjectCreate("eml/dataset/coverage/geographicCoverage/boundingCoordinates", BBox.class);
    digester.addBeanPropertySetter(
            "eml/dataset/coverage/geographicCoverage/boundingCoordinates/westBoundingCoordinate", "minX");
    digester.addBeanPropertySetter(
            "eml/dataset/coverage/geographicCoverage/boundingCoordinates/eastBoundingCoordinate", "maxX");
    digester.addBeanPropertySetter(
            "eml/dataset/coverage/geographicCoverage/boundingCoordinates/northBoundingCoordinate", "maxY");
    digester.addBeanPropertySetter(
            "eml/dataset/coverage/geographicCoverage/boundingCoordinates/southBoundingCoordinate", "minY");
    digester.addSetNext("eml/dataset/coverage/geographicCoverage/boundingCoordinates",
            "setBoundingCoordinates"); // add
    // the BBox to the GeospatialCoverage
    digester.addSetNext("eml/dataset/coverage/geographicCoverage", "addGeospatialCoverage"); // add the
    // GeospatialCoverage to the list in
    // EML
}

From source file:org.gbif.metadata.eml.EmlFactory.java

/**
 * Adds rules to extract the temporal coverage.
 *
 * @param digester to add the rules to//from  w ww . j  a v a 2 s . c  o m
 */
private static void addTemporalCoverageRules(Digester digester) {
    digester.addObjectCreate("eml/dataset/coverage/temporalCoverage", TemporalCoverage.class);
    digester.addCallMethod("eml/dataset/coverage/temporalCoverage/singleDateTime/calendarDate", "setStart", 1);
    digester.addCallParam("eml/dataset/coverage/temporalCoverage/singleDateTime/calendarDate", 0);
    digester.addCallMethod("eml/dataset/coverage/temporalCoverage/singleDateTime/calendarDate", "setEnd", 1);
    digester.addCallParam("eml/dataset/coverage/temporalCoverage/singleDateTime/calendarDate", 0);
    digester.addCallMethod("eml/dataset/coverage/temporalCoverage/rangeOfDates/beginDate/calendarDate",
            "setStart", 1);
    digester.addCallParam("eml/dataset/coverage/temporalCoverage/rangeOfDates/beginDate/calendarDate", 0);
    digester.addCallMethod("eml/dataset/coverage/temporalCoverage/rangeOfDates/endDate/calendarDate", "setEnd",
            1);
    digester.addCallParam("eml/dataset/coverage/temporalCoverage/rangeOfDates/endDate/calendarDate", 0);
    // add the TemporalCoverage to the list in EML
    digester.addSetNext("eml/dataset/coverage/temporalCoverage", "addTemporalCoverage");
}

From source file:org.gbif.metadata.eml.EmlFactory.java

/**
 * Adds rules to extract the livingTimePeriod temporal coverage.
 *
 * @param digester to add the rules to//  w  ww  .jav a2s.  co m
 */
private static void addLivingTimePeriodRules(Digester digester) {
    digester.addObjectCreate("eml/additionalMetadata/metadata/gbif/livingTimePeriod", TemporalCoverage.class);
    digester.addCallMethod("eml/additionalMetadata/metadata/gbif/livingTimePeriod", "setLivingTimePeriod", 1);
    digester.addCallParam("eml/additionalMetadata/metadata/gbif/livingTimePeriod", 0);
    digester.addSetNext("eml/additionalMetadata/metadata/gbif/livingTimePeriod", "addTemporalCoverage"); // add the
    // TemporalCoverage to the list in EML
}

From source file:org.gbif.metadata.eml.EmlFactory.java

/**
 * Adds rules to extract the formationPeriod temporal coverage.
 *
 * @param digester to add the rules to/*from  w ww.ja v a2  s.  c  o  m*/
 */
private static void addFormationPeriodRules(Digester digester) {
    digester.addObjectCreate("eml/additionalMetadata/metadata/gbif/formationPeriod", TemporalCoverage.class);
    digester.addCallMethod("eml/additionalMetadata/metadata/gbif/formationPeriod", "setFormationPeriod", 1);
    digester.addCallParam("eml/additionalMetadata/metadata/gbif/formationPeriod", 0);
    digester.addSetNext("eml/additionalMetadata/metadata/gbif/formationPeriod", "addTemporalCoverage"); // add the
    // TemporalCoverage to the list in EML
}

From source file:org.gbif.metadata.eml.EmlFactory.java

/**
 * Adds rules to extract the taxonomic coverage.
 *
 * @param digester to add the rules to/*  www  . j a  va  2s  . co m*/
 */
private static void addTaxonomicCoverageRules(Digester digester) {
    digester.addObjectCreate("eml/dataset/coverage/taxonomicCoverage", TaxonomicCoverage.class);
    digester.addBeanPropertySetter("eml/dataset/coverage/taxonomicCoverage/generalTaxonomicCoverage",
            "description");
    digester.addObjectCreate("eml/dataset/coverage/taxonomicCoverage/taxonomicClassification",
            TaxonKeyword.class);
    digester.addBeanPropertySetter(
            "eml/dataset/coverage/taxonomicCoverage/taxonomicClassification/taxonRankName", "rank");
    digester.addBeanPropertySetter(
            "eml/dataset/coverage/taxonomicCoverage/taxonomicClassification/taxonRankValue", "scientificName");
    digester.addBeanPropertySetter("eml/dataset/coverage/taxonomicCoverage/taxonomicClassification/commonName",
            "commonName");
    digester.addSetNext("eml/dataset/coverage/taxonomicCoverage/taxonomicClassification", "addTaxonKeyword"); // adds the TaxonKeyword part of the
    // TaxonomicCoverage
    digester.addSetNext("eml/dataset/coverage/taxonomicCoverage", "addTaxonomicCoverage"); // add the TaxonomicCoverage to the list in EML
}

From source file:org.gbif.metadata.eml.EmlFactory.java

/**
 * Add rules for parsing the project details.
 *
 * @param digester to add the rules to//from ww w .  j  ava2  s.  com
 */
private static void addProjectRules(Digester digester) {
    digester.addObjectCreate("eml/dataset/project", Project.class);
    digester.addCallMethod("eml/dataset/project", "setIdentifier", 1);
    digester.addCallParam("eml/dataset/project", 0, "id");
    digester.addBeanPropertySetter("eml/dataset/project/title", "title");
    addAgentRules(digester, "eml/dataset/project/personnel", "addProjectPersonnel");
    digester.addBeanPropertySetter("eml/dataset/project/abstract/para", "description");
    digester.addBeanPropertySetter("eml/dataset/project/funding/para", "funding");
    addStudyAreaDescriptionRules(digester);
    digester.addBeanPropertySetter("eml/dataset/project/designDescription/description/para",
            "designDescription");
    digester.addSetNext("eml/dataset/project", "setProject");
}