Changeset 32874

Show
Ignore:
Timestamp:
07.03.2019 22:47:07 (2 weeks ago)
Author:
davidb
Message:

Next round of changes, migrating from OAI imprint to what is needed for IIIF

Location:
gs3-extensions/iiif-servlet/trunk/src
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • gs3-extensions/iiif-servlet/trunk/src/README.txt

    r32867 r32874  
    1515e.g. jdbm.jar needs to be here to avoid Class Not Found 
    1616 
     17 
     18pushd $GSDL3SRCHOME 
     19cp -i ./packages/tomcat/webapps/gs-cantaloupe/WEB-INF/classes/lib/jdbm.jar ./packages/tomcat/webapps/gs-cantaloupe/WEB-INF/lib/. 
     20popd 
  • gs3-extensions/iiif-servlet/trunk/src/gsdl-src/java/org/greenstone/gsdl3/IIIFServerBridge.java

    r32860 r32874  
    170170            //response.setContentType("text/xml;charset=UTF-8"); 
    171171        //PrintWriter out = response.getWriter(); 
    172  
     172        String result = ""; 
     173         
    173174        String[] pairs = new String[2]; 
    174175        pairs[0] = "verb=GetRecord"; 
     
    185186        Element xml_request = request_doc.createElement(GSXML.REQUEST_ELEM); 
    186187        // The type attribute is set to be 'oaiService' from OAIServer to OAIReceptionist. 
    187         ////xml_request.setAttribute(GSXML.TYPE_ATT, OAIXML.OAI_SERVICE); 
     188        ////xml_request.setAttribute(GSXML.TYPE_ATT, OAIXML.OAI_SERVICE); // **** 
    188189        //xml_request.setAttribute(GSXML.LANG_ATT, lang); 
    189190        xml_request.setAttribute(GSXML.TO_ATT, verb); 
     
    211212            if (res == null) 
    212213            { 
    213                 logger.info("response element in xml_result is null"); 
    214                 verb_elem = IIIFXML.createErrorElement(response_doc, "Internal error", ""); 
    215             } 
    216             else 
    217             { 
    218                 verb_elem = GSXML.getFirstElementChild(res); 
     214                logger.info("response element in xml_result is null"); 
     215                verb_elem = IIIFXML.createErrorElement(response_doc, "Internal error", ""); 
     216            } 
     217            else { 
     218                System.err.println("*** res (verb_elem) = " + XMLConverter.getPrettyString(res)); 
     219                 
     220                verb_elem = GSXML.getFirstElementChild(res); // GetRecord 
     221                Node record_node = GSXML.getFirstElementChild(verb_elem); // record 
     222                Element metadata_list_elem = (Element)GSXML.getChildByTagName(record_node,"metadata"); // metadata 
     223 
     224                System.err.println("*** metadata_list_elem = " + XMLConverter.getPrettyString(metadata_list_elem)); 
     225                String assocfilepath_metadata = GSXML.getMetadataValue(metadata_list_elem,"assocfilepath"); 
     226                String image_metadata = GSXML.getMetadataValue(metadata_list_elem,"Image"); 
     227                //Node assocfilepath_metadata_node = GSXML.getChildByTagName("assocfilepath"); 
     228                //Node image_metadata_node = GSXML.getChildByTagName("Image"); 
     229 
     230                result = assocfilepath_metadata + "/" + image_metadata; 
    219231            } 
    220232 
     
    243255        */ 
    244256         
    245         return XMLConverter.getPrettyString(xml_response); 
     257        //return XMLConverter.getPrettyString(xml_response); 
     258        return result; 
     259        //return xml_response; 
    246260    } 
    247261 
     
    264278            if (index != -1) 
    265279            { //just a double check 
    266               Element param = GSXML.createParameter(doc, pairs[i].substring(0, index), IIIFXML.oaiDecode(pairs[i].substring(index + 1))); 
     280              Element param = GSXML.createParameter(doc, pairs[i].substring(0, index), IIIFXML.iiifDecode(pairs[i].substring(index + 1))); 
    267281              request.appendChild(param); 
    268282            } 
  • gs3-extensions/iiif-servlet/trunk/src/gsdl-src/java/org/greenstone/gsdl3/service/IIIFPMH.java

    r32860 r32874  
    2323import org.greenstone.gsdl3.util.GSXML; 
    2424import org.greenstone.gsdl3.util.IIIFXML; 
    25 import org.greenstone.gsdl3.util.OAIXML; // **** 
     25//import org.greenstone.gsdl3.util.OAIXML; // **** 
    2626import org.greenstone.gsdl3.util.OID; 
    2727import org.greenstone.gsdl3.util.GSFile; 
     
    7070  protected Element meta_formats_definition = null; 
    7171  protected HashMap<String, HashSet<String>> format_elements_map = null; 
    72   protected HashMap<String, Element> format_response_map = null; 
    7372  protected HashMap<String, Element> format_meta_elem_map = null; 
    7473   
     
    134133    Element get_record = this.desc_doc.createElement(GSXML.SERVICE_ELEM); 
    135134    get_record.setAttribute(GSXML.NAME_ATT, IIIFXML.GET_RECORD); 
    136     get_record.setAttribute(GSXML.TYPE_ATT, "oai"); 
     135    get_record.setAttribute(GSXML.TYPE_ATT, "iiif"); 
    137136    this.short_service_info.appendChild(get_record); 
    138137     
     
    165164      Element get_record = doc.createElement(GSXML.SERVICE_ELEM); 
    166165      get_record.setAttribute(GSXML.NAME_ATT, IIIFXML.GET_RECORD); 
    167       get_record.setAttribute(GSXML.TYPE_ATT, "oai"); 
     166      get_record.setAttribute(GSXML.TYPE_ATT, "iiif"); 
    168167      return get_record; 
    169168    } 
     
    172171  } 
    173172     
    174   /** returns the actual record element used in the OAI GetRecord response */ 
     173  /** returns the actual record element used in the IIIF GetRecord response */ 
    175174  protected Element processGetRecord(Element req) { 
    176175    /** arguments: 
    177176        identifier: required 
    178         metadataPrefix: required 
    179177     *  Exceptions: badArgument; cannotDisseminateFormat; idDoesNotExist 
    180178     */  
     
    182180    HashMap<String, String> param_map = GSXML.getParamMap(params);     
    183181     
    184     String prefix = param_map.get(OAIXML.METADATA_PREFIX); 
    185     if (prefix == null || prefix.equals("")) { 
    186       //Just a double-check 
    187       logger.error("the value of metadataPrefix att is not present in the request."); 
    188       return IIIFXML.createErrorResponse(OAIXML.CANNOT_DISSEMINATE_FORMAT, ""); 
    189     } 
    190      
    191     // check that we support this format 
    192     if (!format_response_map.containsKey(prefix)) { 
    193       logger.error("metadata prefix is not supported for collection "+this.coll_name); 
    194       return IIIFXML.createErrorResponse(OAIXML.CANNOT_DISSEMINATE_FORMAT, ""); 
    195     } 
    196  
    197182    Document doc = XMLConverter.newDOM(); 
    198183     
    199184    String oid = param_map.get(IIIFXML.OID); // TODO should this be identifier??? 
    200185     
    201     //get a DBInfo object of the identifier; if this identifier is not present in the database, 
     186    // Get a DBInfo object of the identifier; if this identifier is not present in the database, 
    202187    // null is returned. 
    203188    DBInfo info = this.coll_db.getInfo(oid); 
    204189    if (info == null) { 
    205     //if(!OID_is_deleted) { // we don't expect to find entries for deleted docs in index db. // **** 
    206         logger.error("OID: " + oid + " is not present in the collection index database."); 
    207         return IIIFXML.createErrorResponse(IIIFXML.ID_DOES_NOT_EXIST, ""); 
    208         //} // if doc deleted, id missing in indexdb is not an error: doc id would exist only in oai-inf db, marked as deleted 'D' // **** 
     190    logger.error("OID: " + oid + " is not present in the collection index database."); 
     191    return IIIFXML.createErrorResponse(IIIFXML.ID_DOES_NOT_EXIST, ""); 
    209192    } 
    210193 
     
    218201    record.appendChild(createHeaderElement(doc, oid));       
    219202    //compose the metadata element 
    220     record.appendChild(createMetadataElement(doc, prefix, info)); 
     203    record.appendChild(createMetadataElement(doc, info)); 
    221204    get_record.appendChild(record); 
    222205    return get_record_response; 
     
    224207 
    225208     
    226  /** create the metadata element used when processing ListRecords/GetRecord requests 
     209 /** create the metadata element used when processing GetRecord request 
    227210   */ 
    228211 
    229   protected Element createMetadataElement(Document doc, String prefix, DBInfo info) { 
     212  protected Element createMetadataElement(Document doc, DBInfo info) { 
    230213    // the <metadata> element 
    231     Element metadata = doc.createElement(OAIXML.METADATA); 
     214    Element metadata_message = doc.createElement(IIIFXML.METADATA); 
     215 
    232216    // the <oai:dc namespace...> element 
    233     Element prfx_str_elem = (Element)doc.importNode(this.format_meta_elem_map.get(prefix), true);  
    234     metadata.appendChild(prfx_str_elem); 
    235      
    236     Element meta_format_element = GSXML.getNamedElement(this.meta_formats_definition, OAIXML.METADATA_FORMAT, GSXML.NAME_ATT, prefix); 
    237     NodeList elements = meta_format_element.getElementsByTagName(OAIXML.ELEMENT); 
     217    //Element prfx_str_elem = (Element)doc.importNode(this.format_meta_elem_map.get(prefix), true);  
     218    //metadata.appendChild(prfx_str_elem); 
     219     
     220    //Element meta_format_element = GSXML.getNamedElement(this.meta_formats_definition, OAIXML.METADATA_FORMAT, GSXML.NAME_ATT, prefix); 
     221    //NodeList elements = meta_format_element.getElementsByTagName(OAIXML.ELEMENT); 
    238222    // for each element in the definition 
     223 
     224    addFirstMetadata(metadata_message, "assocfilepath", info); 
     225    addFirstMetadata(metadata_message, "Image", info); 
     226 
     227    /*       
     228    Set<String> keys = info.getKeys(); 
     229    if (keys != null && keys.size()!=0) { 
     230    for (String metaname: keys) { 
     231        addMetadata(metadata_message, metaname, info); 
     232    } 
     233    } 
     234    */ 
     235     
     236    /* 
    239237    for (int i=0; i<elements.getLength(); i++) { 
    240238      Element e = (Element)elements.item(i); 
    241       Element map = (Element)GSXML.getChildByTagName(e, OAIXML.MAPPING); 
    242       if (map == null) { 
    243     // look up the element name 
    244     addMetadata(prfx_str_elem, e.getAttribute(GSXML.NAME_ATT), info); 
    245       } else { 
    246     // we go though the list of names in the mapping 
    247     addMetadata(prfx_str_elem, e.getAttribute(GSXML.NAME_ATT), map.getAttribute(OAIXML.SELECT), map.getAttribute(OAIXML.ELEMENTS), info); 
    248       } 
    249     } 
     239 
     240      // look up the element name 
     241      //addMetadata(prfx_str_elem, e.getAttribute(GSXML.NAME_ATT), info); 
     242      addMetadata(metadata, e.getAttribute(GSXML.NAME_ATT), info); 
     243    } 
     244    */ 
     245     
    250246    // output any metadata that is not just a simple mapping 
    251     // addCustomMetadata(prfx_str_elem, prefix, info); // **** 
    252     return metadata; 
     247    //addCustomMetadata(prfx_str_elem, prefix, info); // **** 
     248    return metadata_message; 
    253249  } 
    254250 
    255251  /** a simple addMetadata where we look for meta_name metadata, and add as that name*/ 
    256252 
    257   protected void addMetadata(Element meta_list_elem, String meta_name, DBInfo info) { 
    258     Vector<String> values = info.getMultiInfo(meta_name); 
    259     if (values != null && values.size()!=0) { 
    260       for (int i=0; i<values.size(); i++) { 
    261     addMetadataElement(meta_list_elem, meta_name, values.get(i)); 
    262       } 
    263     } 
    264   } 
    265  
     253     
     254  protected void addFirstMetadata(Element meta_list_elem, String meta_name, DBInfo info) { 
     255      Vector<String> values = info.getMultiInfo(meta_name); 
     256      if (values != null && values.size()>0) { 
     257      addMetadataElement(meta_list_elem, meta_name, values.get(0)); 
     258       
     259      } 
     260  } 
     261     
     262     
    266263  /** more complicated addMetadata - can add multiple items. */ 
    267  
     264    /* 
    268265  protected void addMetadata(Element meta_list_elem, String new_meta_name, String select_type, String name_list, DBInfo info) { 
    269266    String[] names = name_list.split(","); 
     
    307304    } 
    308305  } 
    309    
     306    */ 
     307     
    310308  // specific metadata formats might need to do some custom metadata that is not 
    311309  //just a standard mapping. 
     310    /* 
    312311  protected void addCustomMetadata(Element meta_list_elem, String prefix, DBInfo info) { 
    313312     
    314313 
    315314  } 
    316  
     315    */ 
     316     
    317317  /** create the actual metadata element for the list */ 
    318318 
     
    328328  protected Element createHeaderElement(Document doc, String oid) { 
    329329 
    330         Element header = doc.createElement(OAIXML.HEADER); 
     330        Element header = doc.createElement(IIIFXML.HEADER); 
    331331     
    332332        Element identifier = doc.createElement(IIIFXML.IDENTIFIER); 
  • gs3-extensions/iiif-servlet/trunk/src/gsdl-src/java/org/greenstone/gsdl3/util/IIIFXML.java

    r32860 r32874  
    3737  static Logger logger = Logger.getLogger(org.greenstone.gsdl3.util.IIIFXML.class.getName()); 
    3838 
    39   // the leading keyword of oai protocol 
     39  // the leading keyword of IIIF protocol // **** 
    4040  public static final String VERB = "verb"; 
    4141 
     
    6767     
    6868  // record response data 
    69   // SET_SPEC 
    7069  public static final String RECORD = "record"; 
    71  
    72     public static final String OAIPMH = "OAIPMH"; // **** 
     70  public static final String HEADER = "header"; 
     71  public static final String METADATA = "metadata"; 
     72 
     73    //public static final String OAIPMH = "OAIPMH"; // **** 
    7374     
    7475    //public static final String OAI_SET_LIST = "oaiSetList"; // **** 
     
    8081  //public static final String FILE_SEPARATOR = File.separator; 
    8182    //public static final String OAI_VERSION1 = "1.0"; 
    82     public static final String IIIF_VERSION2 = "2.1"; // **** 
     83    //public static final String IIIF_VERSION2 = "2.1"; // **** 
    8384  /*************************above are final values****************************/ 
    8485     
     
    143144 
    144145     
    145   /** TODO: returns a basic response for appropriate oai version 
     146  /** TODO: returns a basic response (loosely based on OAI XML message) 
    146147   *   
    147148   */ 
     
    161162    String[] strs = pairs[i].split("="); 
    162163    if(strs != null && strs.length == 2) { 
    163       request_elem.setAttribute(strs[0], oaiDecode(strs[1])); 
     164      request_elem.setAttribute(strs[0], iiifDecode(strs[1])); 
    164165    } 
    165166      } 
     
    168169    GSXML.setNodeText(request_elem, baseURL); 
    169170       
    170     Node resp_date = GSXML.getChildByTagName(response, RESPONSE_DATE); // **** 
     171    //Node resp_date = GSXML.getChildByTagName(response, RESPONSE_DATE); // **** 
    171172     
    172173    return response; 
     
    265266   *  original form (eg, ':').  
    266267   */ 
    267   public static String oaiDecode(String escaped_str) { 
    268     logger.info("oaiDecode() " +escaped_str); 
     268  public static String iiifDecode(String escaped_str) { 
     269    logger.info("iiifDecode() " +escaped_str); 
    269270    for (int i=0; i<special_char.length; i++) { 
    270271      if (escaped_str.indexOf(escape_sequence[i]) != -1) { 
     
    277278   *  escaped sequences (eg, '%3A').  
    278279   */ 
    279     public static String oaiEncode(String original_str) { // **** 
    280     logger.info("oaiEncode() " + original_str);       
     280    public static String iiifEncode(String original_str) { // **** 
     281    logger.info("iiifEncode() " + original_str);       
    281282    for (int i=0; i<special_char.length; i++) { 
    282283      if (original_str.indexOf(special_char[i]) != -1) { 
     
    288289 
    289290  public static Element createResponseHeader(Document response_doc, String verb) { 
    290       String tag_name = (iiif_version.equals(IIIF_VERSION2))? IIIF_PMH : verb; // **** 
    291     Element oai = response_doc.createElement(tag_name); 
    292     Element resp_date = response_doc.createElement(RESPONSE_DATE); // **** 
     291      //String tag_name = (iiif_version.equals(IIIF_VERSION2))? IIIF_PMH : verb; // **** 
     292      String tag_name = IIIF_PMH; 
     293    Element iiif = response_doc.createElement(tag_name); 
     294    //Element resp_date = response_doc.createElement(RESPONSE_DATE); // **** 
    293295    Element req = response_doc.createElement(REQUEST); 
    294     oai.appendChild(resp_date); 
    295     oai.appendChild(req); 
    296  
    297     if(iiif_version.equals(IIIF_VERSION2)) { // **** 
    298       oai.setAttribute("xmlns", "http://www.openarchives.org/OAI/2.0/"); 
    299       oai.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); 
    300       oai.setAttribute("xsi:schemaLocation", "http://www.openarchives.org/OAI/2.0/ \n http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd"); 
    301     } else { 
    302       oai.setAttribute("xmlns", "http://www.openarchives.com/OAI/1.1/OAI_" + verb); 
    303       oai.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); 
    304       oai.setAttribute("xsi:schemaLocation", "http://www.openarchives.org/OAI/1.1/OAI_" + verb + "\n http://www.openarchives.org/OAI/1.1/OAI_" + verb + ".xsd"); 
    305     } 
    306     return oai; 
    307   } 
    308  
    309      
     296    //oai.appendChild(resp_date); 
     297    iiif.appendChild(req); 
     298 
     299    return iiif; 
     300  } 
     301 
     302    /* 
    310303  public static Element createOAIIdentifierXML(Document doc, String repository_id, String sample_collection, String sample_doc_id) { 
    311304    String xml = "<oai-identifier xmlns=\"http://www.openarchives.org/OAI/2.0/oai-identifier\"\n xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n xsi:schemaLocation=\"http://www.openarchives.org/OAI/2.0/oai-identifier\n http://www.openarchives.org/OAI/2.0/oai-identifier.xsd\">\n <scheme>oai</scheme>\n<repositoryIdentifier>" + repository_id + "</repositoryIdentifier>\n<delimiter>:</delimiter>\n<sampleIdentifier>oai:"+repository_id+":"+sample_collection+":"+sample_doc_id+"</sampleIdentifier>\n</oai-identifier>"; 
     
    316309 
    317310  } 
    318  
     311    */ 
     312 
     313    /* 
    319314  public static Element createGSDLElement(Document doc) { 
    320315    String xml = "<gsdl xmlns=\"http://www.greenstone.org/namespace/gsdl_oaiinfo/1.0/gsdl_oaiinfo\"\n xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n xsi:schemaLocation=\"http://www.greenstone.org/namespace/gsdl_oaiinfo/1.0/gsdl_oaiinfo\n   http://www.greenstone.org/namespace/gsdl_oaiinfo/1.0/gsdl_oaiinfo.xsd\"></gsdl>"; 
     
    322317    return (Element)doc.importNode(xml_doc.getDocumentElement(), true);     
    323318  } 
     319    */ 
     320     
    324321} 
    325322 
  • gs3-extensions/iiif-servlet/trunk/src/src/main/java/edu/illinois/library/cantaloupe/resource/iiif/v2/GSInformationResource.java

    r32859 r32874  
    102102    IIIFServerBridge gs_iiif_bridge = new IIIFServerBridge(); 
    103103    gs_iiif_bridge.init(site_name); 
    104     String gs_message = gs_iiif_bridge.doGetDocumentMessage(coll_name + ":" + doc_id); 
     104    String collect_image_filename = gs_iiif_bridge.doGetDocumentMessage(coll_name + ":" + doc_id); 
     105    String site_image_filename = site_name + "/collect/" + coll_name + "/index/assoc/" + collect_image_filename; 
     106     
     107    //System.err.println("**** gs_message = " + XMLConverter.getPrettyString(gs_message_elem)); 
     108    System.err.println("**** Greenstone site image filename = " + site_image_filename); 
    105109     
    106110        final Source source = new SourceFactory().newSource(