Changeset 31965 for main


Ignore:
Timestamp:
09/14/17 14:26:55 (3 years ago)
Author:
kjdon
Message:

new implementation of getMetadataPrefixElement. Pass in hte metadataFormat definition, so can get namespace and schema. Previously was hardcoded for dc, no allowance for new metadata formats

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/OAIXML.java

    r31915 r31965  
    306306  }
    307307
     308
    308309  public static long getTokenExpiration() {
    309310    return token_expiration*1000; // in milliseconds
     
    526527  }
    527528
    528   public static Element getMetadataPrefixElement(Document doc, String prefix, String version) {
    529     if (prefix.equals(META_FORMAT_DC)) {
    530       //examples of tag_name: dc, oai_dc:dc, etc.
    531       String tag_name = getMetadataTagName(prefix, version);
    532       Element oai = doc.createElement(tag_name);
    533       if (version.equals(OAI_VERSION2)) {
    534     oai.setAttribute("xmlns:oai_dc", "http://www.openarchives.org/OAI/2.0/oai_dc/");
     529  public static Element getMetadataPrefixElement(Document doc, String prefix, Element meta_format) {
     530
     531    Element ns_elem = (Element)GSXML.getChildByTagName(meta_format, METADATA_NAMESPACE);
     532    String namespace = null;
     533    if (ns_elem != null) {
     534      namespace = GSXML.getNodeText(ns_elem);
     535    }
     536    if (namespace == null || namespace.equals("")) {
     537      logger.error("No namespace URI found in metadataFormat elemnt for "+prefix);
     538      logger.error(XMLConverter.getPrettyString(meta_format));
     539      return null;
     540    }
     541
     542    Element sc_elem = (Element)GSXML.getChildByTagName(meta_format, SCHEMA);
     543    String schema = null;
     544    if (sc_elem != null) {
     545      schema = GSXML.getNodeText(sc_elem);
     546    }
     547    if (schema == null || schema.equals("")) {
     548      logger.error("No schema found in metadataFormat element for "+prefix);
     549      logger.error(XMLConverter.getPrettyString(meta_format));
     550      return null;
     551    }
     552     
     553    String tag_name = getMetadataTagName(prefix, oai_version);
     554    Element oai = doc.createElement(tag_name);
     555    oai.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
     556   
     557    if (oai_version.equals(OAI_VERSION2)) {
     558      oai.setAttribute("xmlns:"+prefix, namespace);
     559      if (prefix.equals(META_FORMAT_DC)) {
     560    // there seems to be an extra one for dc
    535561    oai.setAttribute("xmlns:dc", "http://purl.org/dc/elements/1.1/");
    536     oai.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
    537     oai.setAttribute("xsi:schemaLocation", "http://www.openarchives.org/OAI/2.0/oai_dc/ \n http://www.openarchives.org/OAI/2.0/oai_dc.xsd");
     562      }
     563      oai.setAttribute("xsi:schemaLocation", namespace+" \n "+schema);
     564    } else {
     565      oai.setAttribute("xmlns", "http://www.openarchives.com/OAI/1.1/");
     566      if (prefix.equals(META_FORMAT_DC)) {
     567    oai.setAttribute("xsi:schemaLocation", "http://www.openarchives.org/OAI/1.1/" + tag_name + ".xsd");
    538568      } else {
    539     oai.setAttribute("xmlns", "http://www.openarchives.com/OAI/1.1/");
    540     oai.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
    541     oai.setAttribute("xsi:schemaLocation", "http://www.openarchives.org/OAI/1.1/" + tag_name + ".xsd");       
    542       }
    543       return oai;
    544     }
    545     return null;
    546    
    547   }
    548 
     569    oai.setAttribute("xsi:schemaLocation", schema);
     570      }
     571    }
     572
     573    return oai;
     574   
     575  }
     576 
    549577  public static String getMetadataTagName(String prefix, String oai_version) {
    550578    if (prefix.equals(META_FORMAT_DC)) {
Note: See TracChangeset for help on using the changeset viewer.