Example usage for org.apache.commons.digester3 NodeCreateRule NodeCreateRule

List of usage examples for org.apache.commons.digester3 NodeCreateRule NodeCreateRule

Introduction

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

Prototype

public NodeCreateRule(int nodeType) throws ParserConfigurationException 

Source Link

Document

Constructor.

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 w  w w. ja  va  2  s . c  o m
 *
 * @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;
}