Project

General

Profile

« Previous | Next » 

Revision 9654

merge from 2.6 branch: add support for EML 2.1.1 in OAI-PMH provider. https://projects.ecoinformatics.org/ecoinfo/issues/7009

View differences:

lib/metacat.properties
485 485
Crosswalks.eml-2.0.0=edu.ucsb.nceas.metacat.oaipmh.provider.server.crosswalk.Eml200
486 486
Crosswalks.eml-2.0.1=edu.ucsb.nceas.metacat.oaipmh.provider.server.crosswalk.Eml201
487 487
Crosswalks.eml-2.1.0=edu.ucsb.nceas.metacat.oaipmh.provider.server.crosswalk.Eml210
488
Crosswalks.eml-2.1.1=edu.ucsb.nceas.metacat.oaipmh.provider.server.crosswalk.Eml211
488 489

  
489 490
######## Spatial section              #########################################
490 491

  
src/edu/ucsb/nceas/metacat/oaipmh/provider/server/crosswalk/Eml211.java
1
/**
2
 * Copyright 2006 OCLC Online Computer Library Center Licensed under the Apache
3
 * License, Version 2.0 (the "License"); you may not use this file except in
4
 * compliance with the License. You may obtain a copy of the License at
5
 * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or
6
 * agreed to in writing, software distributed under the License is distributed on
7
 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
8
 * or implied. See the License for the specific language governing permissions and
9
 * limitations under the License.
10
 */
11
package edu.ucsb.nceas.metacat.oaipmh.provider.server.crosswalk;
12

  
13
import java.util.HashMap;
14
import java.util.Properties;
15

  
16
import org.apache.log4j.Logger;
17

  
18
import ORG.oclc.oai.server.crosswalk.Crosswalk;
19
import ORG.oclc.oai.server.verb.CannotDisseminateFormatException;
20
import ORG.oclc.oai.server.verb.OAIInternalServerError;
21

  
22

  
23
/**
24
 * Provides eml-2.1.1 documents. We simply return the metadata that was read 
25
 * from Metacat.
26
 */
27
public class Eml211 extends Crosswalk {
28
  
29
  /* Class fields */
30

  
31
  private static final Logger logger = Logger.getLogger(Eml211.class);
32
  
33
  private static final String SCHEMA_LOCATION =
34
    "eml://ecoinformatics.org/eml-2.1.1 " +
35
    "http://knb.ecoinformatics.org/knb/schema/eml-2.1.1/eml.xsd";
36

  
37

  
38
  /* Constructors */
39

  
40
  /**
41
   * The constructor assigns the schemaLocation associated with this crosswalk.
42
   * Since the crosswalk is trivial in this case, no properties are utilized.
43
   * 
44
   * @param properties
45
   *          properties that are needed to configure the crosswalk.
46
   */
47
  public Eml211(Properties properties) throws OAIInternalServerError {
48
    super(SCHEMA_LOCATION);
49
  }
50
  
51
  
52
  /* Class methods */
53
  
54
  
55
  /* Instance methods */
56

  
57

  
58
  /**
59
   * Perform the actual crosswalk.
60
   * 
61
   * @param nativeItem  A HashMap object that contains the EML string that was
62
   *                    retrieved from Metacat and stored as the value of the
63
   *                    "recordBytes" key
64
   *                    
65
   * @return emlDoc  a String containing the metadata to be stored within 
66
   *                    the <metadata> element
67
   *                    
68
   * @exception CannotDisseminateFormatException
69
   *                    nativeItem doesn't support this format.
70
   */
71
  public String createMetadata(Object nativeItem)
72
      throws CannotDisseminateFormatException {
73
    HashMap recordMap = (HashMap) nativeItem;
74
    String xmlRec = (String) recordMap.get("recordBytes");    
75
    String emlDoc = xmlRec.trim();
76
    
77
    /*
78
     * Remove leading XML processing instructions because the document is going
79
     * to be placed inside an OAI <metadata> element.
80
     */
81
    while (emlDoc.startsWith("<?")) {
82
      int offset = emlDoc.indexOf("?>");
83
      emlDoc = emlDoc.substring(offset + 2).trim();
84
    }
85
      
86
    return emlDoc;
87
  }
88
  
89
  
90
  /**
91
   * Can this nativeItem be represented in 'eml-2.1.1' format?
92
   * 
93
   * @param nativeItem              a record in native format
94
   * @return true if 'eml-2.1.1' format is possible, false otherwise.
95
   */
96
  public boolean isAvailableFor(Object nativeItem) {
97
    boolean isAvailable = false;
98
    HashMap recordMap = (HashMap) nativeItem;
99
    String doctype = (String) recordMap.get("doctype");
100
    
101
    if (doctype.equals("eml://ecoinformatics.org/eml-2.1.1")) {
102
      isAvailable = true;
103
    }
104
    
105
    return isAvailable;
106
  }
107
  
108
}
0 109

  

Also available in: Unified diff