Changeset 32883


Ignore:
Timestamp:
2019-03-08T11:40:31+13:00 (2 years ago)
Author:
davidb
Message:

Code tidy up

Location:
gs3-extensions/iiif-servlet/trunk/src/gsdl-src/java/org/greenstone/gsdl3
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • gs3-extensions/iiif-servlet/trunk/src/gsdl-src/java/org/greenstone/gsdl3/IIIFServerBridge.java

    r32875 r32883  
    8686    }
    8787
    88     /**
    89     * initialise the class
    90     */
     88    /**
     89    * initialise the class
     90    */
    9191    public void init(String site_name) throws UnavailableException, Exception
    9292    {
    93         ////GlobalProperties.loadGlobalProperties(config.getServletContext().getRealPath(""));
    94            
    9593        org.greenstone.util.GlobalProperties.loadGlobalProperties("");
    96         //org.greenstone.util.GlobalProperties.loadGlobalProperties(config.getServletContext().getRealPath(""));
    97         //org.greenstone.util.GlobalProperties.loadGlobalProperties("/home/osboxes/research/code/greenstone3-svn/web");
    9894        java.io.InputStream in = Class.forName("org.greenstone.util.GlobalProperties").getClassLoader().getResourceAsStream("global.properties");
    9995
    100         //String gsdl3_writablehome = System.getProperty("gsdl3.writablehome");
    10196        String tomcat_context = System.getProperty("tomcat.context");
    102         System.err.println("*** in = " + in);
    103         //System.err.println("*** gsdl3.writablehome = " + gsdl3_writablehome);
    104         System.err.println("*** tomcat.context = " + tomcat_context);
    10597       
    10698        // the receptionist -the servlet will talk to this
     
    121113    } // end of init()
    122114
     115    /*
     116      Written but never used/tested
     117    */
     118   
    123119        public void remote_init(String remote_site_name, String remote_site_type, String remote_site_address) throws UnavailableException
    124120        {
     
    166162        public String doGetDocumentMessage(String identifier)
    167163    {
    168         // oai always requires the content type be text/xml
    169         //request.setCharacterEncoding("UTF-8");
    170             //response.setContentType("text/xml;charset=UTF-8");
    171         //PrintWriter out = response.getWriter();
    172164        String result = "";
    173165       
     
    178170        String verb = "GetRecord";
    179171        Document response_doc = XMLConverter.newDOM();
    180         Element xml_response = IIIFXML.createBasicResponse(response_doc, verb, pairs);
     172        //Element xml_response = IIIFXML.createBasicResponse(response_doc, verb, pairs);
    181173        Element verb_elem = null;
    182174       
     
    185177        Element xml_message = request_doc.createElement(GSXML.MESSAGE_ELEM);
    186178        Element xml_request = request_doc.createElement(GSXML.REQUEST_ELEM);
    187         // The type attribute is set to be 'oaiService' from OAIServer to OAIReceptionist.
    188         ////xml_request.setAttribute(GSXML.TYPE_ATT, OAIXML.OAI_SERVICE); // ****
    189         //xml_request.setAttribute(GSXML.LANG_ATT, lang);
    190179        xml_request.setAttribute(GSXML.TO_ATT, verb);
    191180        addParams(xml_request, pairs);
    192181
    193         //xml_request.setAttribute(GSXML.OUTPUT_ATT, output);????
    194182        xml_message.appendChild(xml_request);
    195183
     
    199187            logger.info("xml_result is null");
    200188            verb_elem = IIIFXML.createErrorElement(response_doc, "Internal error", "");
    201             xml_response.appendChild(verb_elem);
     189            //xml_response.appendChild(verb_elem);
    202190        }
    203191        else
     
    206194            //
    207195            // All response elements are in the form (with a corresponding verb
    208             // name): <message> <response> <verb> ... <resumptionToken> .. this
    209             // is optional! </resumptionToken> </verb> </response> </message>
     196            // name): <message> <response> <verb> ... </verb> </response> </message>
    210197            //
    211198            Node res = GSXML.getChildByTagName(xml_result, GSXML.RESPONSE_ELEM);
     
    216203            }
    217204            else {
    218                 System.err.println("*** res (verb_elem) = " + XMLConverter.getPrettyString(res));
    219                
    220205                verb_elem = GSXML.getFirstElementChild(res); // GetRecord
    221206                Node record_node = GSXML.getFirstElementChild(verb_elem); // record
    222207                Element metadata_list_elem = (Element)GSXML.getChildByTagName(record_node,"metadata"); // metadata
    223208
    224                 System.err.println("*** metadata_list_elem = " + XMLConverter.getPrettyString(metadata_list_elem));
    225 
    226209                Element assocfilepath_metadata_elem = (Element)GSXML.getChildByTagName(metadata_list_elem,"assocfilepath");
    227210                String assocfilepath_metadata_val = GSXML.getNodeText(assocfilepath_metadata_elem);
     
    233216            }
    234217
    235             // ******
    236             xml_response.appendChild(response_doc.importNode(verb_elem, true));
    237             /*
    238             if ( verb_elem.getTagName().equals(IIIFXML.ERROR))
    239             {
    240               xml_response.appendChild(response_doc.importNode(verb_elem, true));
    241             }
    242             else if (IIIFXML.iiif_version.equals(IIIFXML.IIIF_VERSION2)) {
    243               xml_response.appendChild(response_doc.importNode(verb_elem, true));
    244             }
    245             else
    246             {
    247                 GSXML.copyAllChildren(xml_response, verb_elem);
    248                 }*/
    249         }
    250         /*
    251         out.println("<?xml version='1.0' encoding='UTF-8' ?>");
    252         if (this.use_oai_stylesheet)
    253         {
    254             out.println("<?xml-stylesheet type='text/xsl' href='" + this.oai_stylesheet + "' ?>\n");
    255         }
    256         out.println(XMLConverter.getPrettyString(xml_response));
    257         */
    258        
    259         //return XMLConverter.getPrettyString(xml_response);
     218            //xml_response.appendChild(response_doc.importNode(verb_elem, true));
     219        }
    260220        return result;
    261         //return xml_response;
    262221    }
    263222
  • gs3-extensions/iiif-servlet/trunk/src/gsdl-src/java/org/greenstone/gsdl3/collection/IIIFCollection.java

    r32860 r32883  
    128128    protected boolean configureServiceRackList(Element service_rack_list, Element extra_info)
    129129    {
    130         //logger.info("*** Away to call getNamedElement() for service_rack_list = " + XMLConverter.getPrettyString(service_rack_list));
    131        
    132130      // find the IIIFPMH service
    133131      Element iiif_service_xml = GSXML.getNamedElement(service_rack_list, GSXML.SERVICE_CLASS_ELEM, GSXML.NAME_ATT, "IIIFPMH");
     
    143141
    144142      if(this.iiif_service_rack == null) {
    145           logger.info("*** away to call constructor to IIIFPMH");
    146143        this.iiif_service_rack = new IIIFPMH();
    147144      }
     
    153150
    154151      // pass the xml node to the service for configuration
    155       logger.info("*** away to configure service rack IIIFPMH");
    156      
    157152      if (this.iiif_service_rack.configure(iiif_service_xml, extra_info)) {
    158153   
  • gs3-extensions/iiif-servlet/trunk/src/gsdl-src/java/org/greenstone/gsdl3/core/IIIFMessageRouter.java

    r32860 r32883  
    7575
    7676        // ****
    77         // for oai, we don't do anything with the site config
     77        // for iiif, we don't do anything with the site config
    7878        // 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
     79        // it later
    8180        File configFile = new File(GSFile.siteConfigFile(this.site_home));
    8281
  • gs3-extensions/iiif-servlet/trunk/src/gsdl-src/java/org/greenstone/gsdl3/core/IIIFReceptionist.java

    r32860 r32883  
    136136    if (!message.getTagName().equals(GSXML.MESSAGE_ELEM)) {
    137137      logger.error(" Invalid message. GSDL message should start with <"+GSXML.MESSAGE_ELEM+">, instead it starts with:"+message.getTagName()+".");
    138       return IIIFXML.createErrorMessage(OAIXML.BAD_ARGUMENT, "Internal messaging error");
     138      return IIIFXML.createErrorMessage(IIIFXML.BAD_ARGUMENT, "Internal messaging error");
    139139    }
    140140   
     
    143143    if (request == null) {
    144144      logger.error(" message had no request!");
    145       return IIIFXML.createErrorMessage(OAIXML.BAD_ARGUMENT, "Internal messaging error");
     145      return IIIFXML.createErrorMessage(IIIFXML.BAD_ARGUMENT, "Internal messaging error");
    146146    }
    147147
     
    150150    if (!reset.equals("")) {
    151151      resetMessageRouter();
    152       // configureSetInfo(); // ****
    153152      return IIIFXML.createResetResponse(true);
    154153    }
     
    156155   
    157156    //At this stage, the value of 'to' attribute of the request must be the 'verb'
    158     //The only thing that the oai receptionist can be sure is that these verbs are valid, nothing else.
     157    //The only thing that the iiif receptionist can be sure is that these verbs are valid, nothing else.
    159158    String verb = request.getAttribute(GSXML.TO_ATT);
    160159   
    161     if (verb.equals(OAIXML.GET_RECORD)) {
     160    if (verb.equals(IIIFXML.GET_RECORD)) {
    162161      return doGetRecord(request);
    163162    }
    164163
    165164    // should never get here as verbs were checked in IIIFServerBridge
    166     return IIIFXML.createErrorMessage(OAIXML.BAD_VERB, "Unexpected things happened");
     165    return IIIFXML.createErrorMessage(IIIFXML.BAD_VERB, "Unexpected things happened");
    167166   
    168167  }
     
    174173    Element get_record = doc.createElement(IIIFXML.GET_RECORD);
    175174
    176     HashSet<String> valid_strs = new HashSet<String>();
    177     valid_strs.add(OAIXML.IDENTIFIER);
    178     valid_strs.add(OAIXML.METADATA_PREFIX);
     175    //HashSet<String> valid_strs = new HashSet<String>(); // ****
     176    //valid_strs.add(IIIFXML.IDENTIFIER);
     177    //valid_strs.add(IIIFXML.METADATA_PREFIX);
    179178
    180179    NodeList params = GSXML.getChildrenByTagName(req, GSXML.PARAM_ELEM);
    181180    HashMap<String, String> param_map = GSXML.getParamMap(params);   
    182181
    183     // Any need to check all params are valid, like OAI??
    184    
    185     String identifier = param_map.get(OAIXML.IDENTIFIER);
     182    // Any need to check all params are valid, like OAI?? // ****
     183   
     184    String identifier = param_map.get(IIIFXML.IDENTIFIER);
    186185   
    187186    // get the names
     
    189188    if(strs == null || strs.length < 2) {
    190189      logger.error("identifier is not in the form coll:id" + identifier);
    191       return OAIXML.createErrorMessage(OAIXML.ID_DOES_NOT_EXIST, "");
     190      return IIIFXML.createErrorMessage(IIIFXML.ID_DOES_NOT_EXIST, "");
    192191    }   
    193192    String coll_name = strs[0];
     
    199198    req.setAttribute(GSXML.TO_ATT, coll_name + "/" + verb);
    200199    // reset the identifier element
    201     Element param = GSXML.getNamedElement(req, GSXML.PARAM_ELEM, GSXML.NAME_ATT, OAIXML.IDENTIFIER);
     200    Element param = GSXML.getNamedElement(req, GSXML.PARAM_ELEM, GSXML.NAME_ATT, IIIFXML.IDENTIFIER);
    202201    if (param != null) {
    203       param.setAttribute(GSXML.NAME_ATT, OAIXML.OID);
     202      param.setAttribute(GSXML.NAME_ATT, IIIFXML.OID);
    204203      param.setAttribute(GSXML.VALUE_ATT, oid);
    205204    }   
  • gs3-extensions/iiif-servlet/trunk/src/gsdl-src/java/org/greenstone/gsdl3/service/IIIFPMH.java

    r32874 r32883  
    2323import org.greenstone.gsdl3.util.GSXML;
    2424import org.greenstone.gsdl3.util.IIIFXML;
    25 //import org.greenstone.gsdl3.util.OAIXML; // ****
    2625import org.greenstone.gsdl3.util.OID;
    2726import org.greenstone.gsdl3.util.GSFile;
     
    6766  // set this up during configure
    6867  protected Element list_sets_response = null;
    69  
    70   protected Element meta_formats_definition = null;
    71   protected HashMap<String, HashSet<String>> format_elements_map = null;
    72   protected HashMap<String, Element> format_meta_elem_map = null;
    73  
    74   protected String index_stem = "";
     68     
     69  protected String index_stem = ""; // ****
    7570  protected String infodb_type = "";
    7671 
     
    214209    Element metadata_message = doc.createElement(IIIFXML.METADATA);
    215210
    216     // the <oai:dc namespace...> 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);
    222     // for each element in the definition
    223 
    224211    addFirstMetadata(metadata_message, "assocfilepath", info);
    225212    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     /*
    237     for (int i=0; i<elements.getLength(); i++) {
    238       Element e = (Element)elements.item(i);
    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    
    246     // output any metadata that is not just a simple mapping
    247     //addCustomMetadata(prfx_str_elem, prefix, info); // ****
     213   
    248214    return metadata_message;
    249215  }
    250216
    251217  /** a simple addMetadata where we look for meta_name metadata, and add as that name*/
    252 
    253218   
    254219  protected void addFirstMetadata(Element meta_list_elem, String meta_name, DBInfo info) {
     
    261226   
    262227   
    263   /** more complicated addMetadata - can add multiple items. */
    264     /*
    265   protected void addMetadata(Element meta_list_elem, String new_meta_name, String select_type, String name_list, DBInfo info) {
    266     String[] names = name_list.split(",");
    267     for (int i=0; i<names.length; i++) {
    268       Vector<String> values;
    269       // some special words
    270       if (names[i].startsWith(OAIXML.GSF_LINK_PREFIX)) {
    271     values = new Vector<String>();
    272     String base_url = OAIXML.getBaseURL(); // e.g. e.g. http://host:port/greenstone3/oaiserver
    273     String link_url = null;
    274     if (names[i].equals(OAIXML.GSF_LINK_PREFIX+OAIXML.LINK_TYPE_DOCUMENT)) {
    275       link_url =  base_url.replace("oaiserver", "library") + "/collection/" + this.coll_name + "/document/" + info.getInfo("Identifier");
    276     } else if (names[i].equals(OAIXML.GSF_LINK_PREFIX+OAIXML.LINK_TYPE_SOURCE)) {
    277       String srcfile = info.getInfo("srclinkFile");
    278       if (!srcfile.equals("")) {
    279         link_url = base_url.replace("oaiserver", "") + "sites/"
    280              + this.site_name
    281              + "/collect/" + this.coll_name + "/index/assoc/"
    282              + info.getInfo("assocfilepath") + "/" + srcfile;
    283       }
    284     }
    285     if (link_url !=null) {
    286       values.add(link_url);
    287     }
    288       } else {
    289     values = info.getMultiInfo(names[i]);
    290       }
    291       if (values == null || values.size()==0) {
    292     continue;
    293       }
    294       for (int j=0; j<values.size(); j++) {
    295     addMetadataElement(meta_list_elem, new_meta_name, values.get(j));
    296     if (select_type.equals(OAIXML.SELECT_SINGLE_VALUE)) {
    297       return; // only want to add one value
    298     }
    299       }
    300       if (select_type.equals(OAIXML.SELECT_FIRST_VALID_META)) {
    301     return; // we have added all values of this meta elem
    302       }
    303       // otherwise, we will keep going through the list and add them all.
    304     }
    305   }
    306     */
    307    
    308   // specific metadata formats might need to do some custom metadata that is not
    309   //just a standard mapping.
    310     /*
    311   protected void addCustomMetadata(Element meta_list_elem, String prefix, DBInfo info) {
    312    
    313 
    314   }
    315     */
    316    
    317228  /** create the actual metadata element for the list */
    318229
     
    331242   
    332243        Element identifier = doc.createElement(IIIFXML.IDENTIFIER);
    333     GSXML.setNodeText(identifier, coll_name + ":" + oid);
     244    GSXML.setNodeText(identifier, coll_name + ":" + oid); // **** OID
    334245        header.appendChild(identifier);
    335246
  • gs3-extensions/iiif-servlet/trunk/src/gsdl-src/java/org/greenstone/gsdl3/util/IIIFXML.java

    r32874 r32883  
    5656  // IIIF error codes
    5757  public static final String ID_DOES_NOT_EXIST = "idDoesNotExist";
    58 
     58  public static final String BAD_ARGUMENT      = "badArgument";
     59  public static final String BAD_VERB          = "badVerb";
     60   
    5961  // General
    6062  public static final String IIIF_PMH = "IIIF-PMH"; // ****
    61     public static final String RESPONSE_DATE = "responseDate"; // ****
     63    //public static final String RESPONSE_DATE = "responseDate"; // ****
    6264  public static final String REQUEST = "request";
    6365   
     
    7173  public static final String METADATA = "metadata";
    7274
    73     //public static final String OAIPMH = "OAIPMH"; // ****
    74    
    75     //public static final String OAI_SET_LIST = "oaiSetList"; // ****
    76     //public static final String OAI_SERVICE_UNAVAILABLE = "OAI service unavailable";
    77     public static final String OID = "OID"; // ****
     75  public static final String OID = "OID"; // ****
    7876   
    7977  public static final String IIIF_SERVICE_RACK = "IIIFPMH";
    80   //system-dependent file separator, maybe '/' or '\'
    81   //public static final String FILE_SEPARATOR = File.separator;
    82     //public static final String OAI_VERSION1 = "1.0";
    83     //public static final String IIIF_VERSION2 = "2.1"; // ****
     78
    8479  /*************************above are final values****************************/
    85    
    86    
    87   //initialized in getIIIFConfigXML()
     80
    8881  public static Element iiif_config_elem = null;
    8982   
    90     public static final String iiif_version = "2.1"; // ****
     83  public static final String iiif_version = "2.1"; // ****
    9184  public static String baseURL = "";
    9285   
     
    169162    GSXML.setNodeText(request_elem, baseURL);
    170163     
    171     //Node resp_date = GSXML.getChildByTagName(response, RESPONSE_DATE); // ****
    172    
    173164    return response;
    174165  }
     
    211202  }
    212203
    213   // This is the response message sent when there's a request to activate/deactivate a non-OAI collection
    214   // A request to activate a non-existent/non-OAI collection is not invalid, it's just that we won't process it.
     204  // This is the response message sent when there's a request to activate/deactivate a non-IIIF collection
     205  // A request to activate a non-existent/non-IIIF collection is not invalid, it's just that we won't process it.
    215206  // So we still return status code OK (OK status code is needed for servercontrol.pm of activate.pl to recognise
    216207  // that the command had been "successful" when it runs de/activate).
     
    278269   *  escaped sequences (eg, '%3A').
    279270   */
     271    /*
    280272    public static String iiifEncode(String original_str) { // ****
    281273    logger.info("iiifEncode() " + original_str);     
     
    287279    return original_str; 
    288280  }
    289 
     281    */
     282   
    290283  public static Element createResponseHeader(Document response_doc, String verb) {
    291       //String tag_name = (iiif_version.equals(IIIF_VERSION2))? IIIF_PMH : verb; // ****
    292       String tag_name = IIIF_PMH;
     284    String tag_name = IIIF_PMH;
    293285    Element iiif = response_doc.createElement(tag_name);
    294     //Element resp_date = response_doc.createElement(RESPONSE_DATE); // ****
    295286    Element req = response_doc.createElement(REQUEST);
    296     //oai.appendChild(resp_date);
    297287    iiif.appendChild(req);
    298288
    299289    return iiif;
    300   }
    301 
    302     /*
    303   public static Element createOAIIdentifierXML(Document doc, String repository_id, String sample_collection, String sample_doc_id) {
    304     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>";
    305 
    306     Document xml_doc = converter.getDOM(xml);
    307     return (Element)doc.importNode(xml_doc.getDocumentElement(), true);
    308    
    309 
    310   }
    311     */
    312 
    313     /*
    314   public static Element createGSDLElement(Document doc) {
    315     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>";
    316     Document xml_doc = converter.getDOM(xml);
    317     return (Element)doc.importNode(xml_doc.getDocumentElement(), true);   
    318   }
    319     */
    320    
     290  }   
    321291}
    322292
Note: See TracChangeset for help on using the changeset viewer.