Changeset 32842 for gs3-extensions

Show
Ignore:
Timestamp:
03.03.2019 22:50:56 (8 months ago)
Author:
davidb
Message:

Shift from OAI as a template, to separate IIIF based classes

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

Legend:

Unmodified
Added
Removed
  • gs3-extensions/iiif-servlet/trunk/src/PREPARE.sh

    r32707 r32842  
    2626/bin/cp ../../web/WEB-INF/classes/OAIConfig.xml packages/cantaloupe-4.0.2/src/main/resources/. 
    2727 
     28echo "Copying Greenstone's IIIFConfig.xml into Cantaloupe's resources folder" 
     29/bin/cp ../../web/WEB-INF/classes/IIIFConfig.xml packages/cantaloupe-4.0.2/src/main/resources/. 
     30 
    2831 
    2932echo 
  • gs3-extensions/iiif-servlet/trunk/src/gsdl-src/java/org/greenstone/gsdl3/IIIFServerBridge.java

    r32720 r32842  
    3939import org.greenstone.gsdl3.util.GSParams; 
    4040import org.greenstone.gsdl3.util.GSXML; 
    41 import org.greenstone.gsdl3.util.OAIXML; 
     41import org.greenstone.gsdl3.util.IIIFXML; 
    4242import org.greenstone.gsdl3.util.XMLConverter; 
    4343import org.w3c.dom.Document; 
     
    5353 */ 
    5454/** 
    55  * OAI server configuration instructions * 
     55 * IIIF server configuration instructions * 
    5656 *  
    5757 */ 
     
    7171        private void configure() throws UnavailableException 
    7272        {        
    73         // Read in OAIConfig.xml (residing web/WEB-INF/classes/) and  
     73        // Read in IIIFConfig.xml (residing web/WEB-INF/classes/) and  
    7474        //use it to configure the receptionist.  
    75         Element oai_config = OAIXML.getOAIConfigXML(); 
    76         if (oai_config == null) 
    77         { 
    78             logger.error("Fail to parse oai config file OAIConfig.xml."); 
    79             throw new UnavailableException("IIIFServerBridge: Couldn't parse OAIConfig.xml"); 
     75        Element iiif_config = IIIFXML.getIIIFConfigXML(); 
     76        if (iiif_config == null) 
     77        { 
     78            logger.error("Fail to parse IIIF config file IIIFConfig.xml."); 
     79            throw new UnavailableException("IIIFServerBridge: Couldn't parse IIIFConfig.xml"); 
    8080        } 
    8181        // pass it to the receptionist 
    82         if (!this.recept.configure(oai_config)) { 
    83         logger.error("Couldn't configure receptionist"); 
     82        if (!this.recept.configure(iiif_config)) { 
     83        logger.error("Couldn't configure IIIF receptionist"); 
    8484        throw new UnavailableException("IIIFServerBridge: Couldn't configure receptionist");  
    8585        }        
     
    147147        { 
    148148            logger.error("IIIFServerBridge.init Error: invalid Communicator type: " + remote_site_type); 
    149             throw new UnavailableException("OAIServer: invalid communicator type"); 
     149            throw new UnavailableException("IIIFServerBridge: invalid communicator type"); 
    150150        } 
    151151         
     
    153153        { 
    154154            logger.error("IIIFServerBridge.init Error: Couldn't configure communicator"); 
    155             throw new UnavailableException("OAIServer: Couldn't configure communicator"); 
     155            throw new UnavailableException("IIIFServerBridge: Couldn't configure communicator"); 
    156156        } 
    157157        this.recept.setSiteName(remote_site_name); 
     
    175175        String verb = "GetRecord"; 
    176176        Document response_doc = XMLConverter.newDOM(); 
    177         Element xml_response = OAIXML.createBasicResponse(response_doc, verb, pairs); 
     177        Element xml_response = IIIFXML.createBasicResponse(response_doc, verb, pairs); 
    178178        Element verb_elem = null; 
    179179         
     
    195195        { 
    196196            logger.info("xml_result is null"); 
    197             verb_elem = OAIXML.createErrorElement(response_doc, "Internal error", ""); 
     197            verb_elem = IIIFXML.createErrorElement(response_doc, "Internal error", ""); 
    198198            xml_response.appendChild(verb_elem); 
    199199        } 
     
    210210            { 
    211211                logger.info("response element in xml_result is null"); 
    212                 verb_elem = OAIXML.createErrorElement(response_doc, "Internal error", ""); 
     212                verb_elem = IIIFXML.createErrorElement(response_doc, "Internal error", ""); 
    213213            } 
    214214            else 
     
    217217            } 
    218218 
    219             if ( verb_elem.getTagName().equals(OAIXML.ERROR)) 
     219            // ****** 
     220            xml_response.appendChild(response_doc.importNode(verb_elem, true)); 
     221            /* 
     222            if ( verb_elem.getTagName().equals(IIIFXML.ERROR)) 
    220223            { 
    221224              xml_response.appendChild(response_doc.importNode(verb_elem, true)); 
    222225            } 
    223             else if (OAIXML.oai_version.equals(OAIXML.OAI_VERSION2)) { 
     226            else if (IIIFXML.iiif_version.equals(IIIFXML.IIIF_VERSION2)) { 
    224227              xml_response.appendChild(response_doc.importNode(verb_elem, true)); 
    225228            } 
     
    227230            { 
    228231                GSXML.copyAllChildren(xml_response, verb_elem); 
    229             } 
     232                }*/ 
    230233        } 
    231234        /* 
     
    259262            if (index != -1) 
    260263            { //just a double check 
    261               Element param = GSXML.createParameter(doc, pairs[i].substring(0, index), OAIXML.oaiDecode(pairs[i].substring(index + 1))); 
     264              Element param = GSXML.createParameter(doc, pairs[i].substring(0, index), IIIFXML.oaiDecode(pairs[i].substring(index + 1))); 
    262265              request.appendChild(param); 
    263266            } 
  • gs3-extensions/iiif-servlet/trunk/src/gsdl-src/java/org/greenstone/gsdl3/core/IIIFMessageRouter.java

    r32707 r32842  
    2828import org.apache.commons.lang3.StringUtils; 
    2929import org.apache.log4j.Logger; 
    30 import org.greenstone.gsdl3.collection.OAICollection; 
     30import org.greenstone.gsdl3.collection.IIIFCollection; 
    3131import org.greenstone.gsdl3.collection.ServiceCluster; 
    3232import org.greenstone.gsdl3.comms.Communicator; 
     
    3636import org.greenstone.gsdl3.util.GSPath; 
    3737import org.greenstone.gsdl3.util.GSXML; 
    38 import org.greenstone.gsdl3.util.OAIXML; 
     38import org.greenstone.gsdl3.util.IIIFXML; 
    3939import org.greenstone.gsdl3.util.UserContext; 
    4040import org.greenstone.gsdl3.util.XMLConverter; 
     
    4848 * The hub of a Greenstone IIIF image server/bridge. 
    4949 *  
    50  * A simplified version of MessageRouter for OAIServer. Only loads up collections that have OAI services. 
     50 * A simplified version of MessageRouter for IIIFServerBridge. Only loads up collections that have IIIF services. 
    5151 */ 
    5252public class IIIFMessageRouter extends MessageRouter 
     
    5555  static Logger logger = Logger.getLogger(org.greenstone.gsdl3.core.IIIFMessageRouter.class.getName()); 
    5656 
    57   public Element oai_config = null; 
     57  public Element iiif_config = null; 
    5858    //*************************************************************** 
    5959    // public methods 
     
    7474        cleanUpModuleMapEntire(); 
    7575 
    76         // for oai, we don't do anything with the site config file. But we'll read it in and keep it in case need it later, eg for replace elements when retrieving metadata - which I don't think has been implemented 
     76        // **** 
     77        // for oai, we don't do anything with the site config 
     78        // file. But we'll read it in and keep it in case need 
     79        // it later, e.g. for replace elements when retrieving 
     80        // metadata - which I don't think has been implemented 
    7781        File configFile = new File(GSFile.siteConfigFile(this.site_home)); 
    7882 
     
    9296        this.config_info = config_doc.getDocumentElement(); 
    9397 
    94         // this is the receptionists OAIConfig.xml. Need to rethink how the MR gets this this if we ever talk to remote site, and whether it should be using it anyway 
    95         this.oai_config = OAIXML.getOAIConfigXML(); 
    96         if (this.oai_config == null) 
     98        // this is the receptionist's IFFFConfig.xml. 
     99        // Need to rethink how the MR gets this this if we 
     100        // ever talk to remote site, and whether it should be 
     101        // using it anyway 
     102        this.iiif_config = IIIFXML.getIIIFConfigXML(); 
     103        if (this.iiif_config == null) 
    97104        { 
    98           logger.error("Couldn't load in OAIConfig.xml"); 
     105          logger.error("Couldn't load in IIIFConfig.xml"); 
    99106          return false; 
    100107        } 
     
    122129        logger.info("Activating collection: " + col_name + "."); 
    123130        Document doc = this.collection_list.getOwnerDocument(); 
    124         // use our special OAICollection - this will only load in oai services 
    125         OAICollection c = new OAICollection(); 
     131        // use our special IIIFCollection - this will only load in IIIF services 
     132        IIIFCollection c = new IIIFCollection(); 
    126133 
    127134        c.setCollectionName(col_name); 
     
    135142 
    136143        logger.info("have just configured collection " + col_name); 
    137         if (!c.hasOAI()) { 
    138           logger.info ("collection "+col_name+" has no OAI services. Not keeping it loaded"); 
     144        if (!c.hasIIIF()) { 
     145          logger.info ("collection "+col_name+" has no IIIF services. Not keeping it loaded"); 
    139146          return false; 
    140147        } 
    141         if (!c.configureOAI(this.oai_config)) { 
    142           logger.info("couldn't configure the collection : "+col_name +" with the oai config info"); 
     148        if (!c.configureIIIF(this.iiif_config)) { 
     149          logger.info("couldn't configure the collection : "+col_name +" with the iiif config info"); 
    143150          return false; 
    144151        } 
     
    147154        Element e = doc.createElement(GSXML.COLLECTION_ELEM); 
    148155        e.setAttribute(GSXML.NAME_ATT, col_name); 
     156        /* 
    149157        e.setAttribute(OAIXML.LASTMODIFIED, "" + c.getLastmodified()); 
    150158        e.setAttribute(OAIXML.EARLIEST_DATESTAMP, "" + c.getEarliestDatestamp()); 
    151159        e.setAttribute(OAIXML.EARLIEST_OAI_DATESTAMP, "" + c.getEarliestOAIDatestamp()); 
     160        */ 
    152161        this.collection_list.appendChild(e); 
    153162        return true; 
     
    168177     * @return the result Element - should be <response> 
    169178     */ 
     179    /* 
    170180  protected Element processMessage(Element req) { 
    171181    Document doc = XMLConverter.newDOM(); 
     
    185195  } 
    186196 
    187  
     197    */ 
    188198} 
  • gs3-extensions/iiif-servlet/trunk/src/gsdl-src/java/org/greenstone/gsdl3/core/IIIFReceptionist.java

    r32707 r32842  
    4646  protected String site_name = null; 
    4747  /** The unique  repository identifier */ 
     48    /* 
    4849  protected String repository_id = null; 
    49        
     50    */ 
     51     
    5052  /** the configure file of this receptionist passed from the iiif restlet. */ 
    51   protected Element oai_config = null; 
     53  protected Element iiif_config = null; 
    5254 
    5355  /** the message router that the Receptionist and Actions will talk to */ 
     
    9698  } 
    9799  /** sets the message router  - it should already be created and 
    98    * configured in the init() of a servlet/restlet (OAIServer, for example) before being passed to the receptionist*/ 
     100   * configured in the init() of a servlet/restlet (IIIFServerBridge, for example) before being passed to the receptionist*/ 
    99101  public void setMessageRouter(ModuleInterface mr) { 
    100102    this.mr = mr; 
     
    112114      return false; 
    113115    } 
    114     oai_config = config; 
    115      
     116    iiif_config = config; 
     117 
     118    /* 
    116119    repository_id = getRepositoryIdentifier();  
    117  
     120    */ 
     121     
     122    /* 
    118123    if (!configureSetInfo()) { 
    119124      // there are no sets 
     
    121126      return false; 
    122127    } 
    123  
     128    */ 
     129     
    124130    return true; 
    125131  } 
    126132 
     133    /* 
    127134  private boolean configureSetInfo() { 
    128135    this.set_set = new HashSet<String>(); 
     
    235242    return true; 
    236243  } 
    237  
     244    */ 
     245     
    238246  protected void resetMessageRouter() { 
    239247    // we just need to send a configure request to MR 
     
    259267  } 
    260268 
    261   //Compose a message/response element used to send back to the OAIServer servlet.  
    262   //This method is only used within OAIReceptionist 
     269  //Compose a message/response element used to send back to the IIIFServerBridge servlet.  
     270  //This method is only used within IIIFReceptionist 
    263271  private Element getMessage(Document doc, Element e) { 
    264272    Element msg = doc.createElement(GSXML.MESSAGE_ELEM); 
     
    281289    if (!message.getTagName().equals(GSXML.MESSAGE_ELEM)) { 
    282290      logger.error(" Invalid message. GSDL message should start with <"+GSXML.MESSAGE_ELEM+">, instead it starts with:"+message.getTagName()+"."); 
    283       return OAIXML.createErrorMessage(OAIXML.BAD_ARGUMENT, "Internal messaging error"); 
     291      return IIIFXML.createErrorMessage(OAIXML.BAD_ARGUMENT, "Internal messaging error"); 
    284292    } 
    285293    
     
    288296    if (request == null) { 
    289297      logger.error(" message had no request!"); 
    290       return OAIXML.createErrorMessage(OAIXML.BAD_ARGUMENT, "Internal messaging error"); 
     298      return IIIFXML.createErrorMessage(OAIXML.BAD_ARGUMENT, "Internal messaging error"); 
    291299    } 
    292300 
     
    295303    if (!reset.equals("")) { 
    296304      resetMessageRouter(); 
    297       configureSetInfo(); 
    298       return OAIXML.createResetResponse(true); 
     305      // configureSetInfo(); // **** 
     306      return IIIFXML.createResetResponse(true); 
    299307    } 
    300308 
     
    303311    //The only thing that the oai receptionist can be sure is that these verbs are valid, nothing else. 
    304312    String verb = request.getAttribute(GSXML.TO_ATT); 
     313    /* 
    305314    if (verb.equals(OAIXML.IDENTIFY)) { 
    306315      return doIdentify(); 
    307     } 
     316      }*/ 
     317     
    308318    if (verb.equals(OAIXML.GET_RECORD)) { 
    309319      return doGetRecord(request); 
    310320    } 
    311321 
    312     // should never get here as verbs were checked in OAIServer 
    313     return OAIXML.createErrorMessage(OAIXML.BAD_VERB, "Unexpected things happened"); 
    314      
    315   } 
    316  
     322    // should never get here as verbs were checked in IIIFServerBridge 
     323    return IIIFXML.createErrorMessage(OAIXML.BAD_VERB, "Unexpected things happened"); 
     324     
     325  } 
     326 
     327    /* 
    317328  private String getRepositoryIdentifier() { 
    318     Element ri = (Element)GSXML.getChildByTagName(oai_config, OAIXML.REPOSITORY_IDENTIFIER); 
     329    Element ri = (Element)GSXML.getChildByTagName(iiif_config, OAIXML.REPOSITORY_IDENTIFIER); 
    319330    if (ri != null) {  
    320331      return GSXML.getNodeText(ri); 
     
    322333    return ""; 
    323334  } 
    324  
     335    */ 
    325336 
    326337  private void copyNamedElementfromConfig(Element to_elem, String element_name) { 
    327     Element original_element = (Element)GSXML.getChildByTagName(oai_config, element_name); 
     338    Element original_element = (Element)GSXML.getChildByTagName(iiif_config, element_name); 
    328339    if(original_element != null) { 
    329340      GSXML.copyNode(to_elem, original_element); 
     
    331342  } 
    332343 
     344    /* 
    333345  private Element doIdentify() { 
    334346    //The validation for this verb has been done in OAIServer.validate(). So no bother here. 
     
    348360         
    349361    //There can be more than one admin email according to the OAI specification 
    350     NodeList admin_emails = GSXML.getChildrenByTagName(oai_config, OAIXML.ADMIN_EMAIL); 
     362    NodeList admin_emails = GSXML.getChildrenByTagName(iiif_config, OAIXML.ADMIN_EMAIL); 
    351363    int num_admin = 0; 
    352364    Element from_admin_email = null;   
     
    358370    } 
    359371 
    360     /* IIIF does not have the equivalent of oai earliestDatestamp */ 
     372    // IIIF does not have the equivalent of oai earliestDatestamp  
    361373      
    362374    // output the oai identifier 
     
    368380 
    369381    // if there are any oaiInfo metadata, add them in too. 
    370     Element info = (Element)GSXML.getChildByTagName(oai_config, OAIXML.OAI_INFO); 
     382    Element info = (Element)GSXML.getChildByTagName(iiif_config, OAIXML.OAI_INFO); 
    371383    if (info != null) { 
    372384      NodeList meta = GSXML.getChildrenByTagName(info, OAIXML.METADATA); 
     
    383395    return getMessage(doc, identify); 
    384396  } 
    385  
     397    */ 
     398     
    386399  private Element doGetRecord(Element req){ 
    387400    logger.info(""); 
     
    392405    */  
    393406    Document doc = XMLConverter.newDOM(); 
    394     Element get_record = doc.createElement(OAIXML.GET_RECORD); 
     407    Element get_record = doc.createElement(IIIFXML.GET_RECORD); 
    395408 
    396409    HashSet<String> valid_strs = new HashSet<String>();