Ignore:
Timestamp:
2011-05-09T14:37:04+12:00 (13 years ago)
Author:
sjm84
Message:

Updating this branch to match the latest Greenstone3 changes

Location:
main/branches/64_bit_Greenstone/greenstone3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/branches/64_bit_Greenstone/greenstone3

  • main/branches/64_bit_Greenstone/greenstone3/src/java/org/greenstone/gsdl3/collection/Collection.java

    r23606 r24007  
    4444import org.apache.log4j.*;
    4545
     46// Apache Commons
     47import org.apache.commons.lang3.*;
     48
    4649/**
    4750 * Represents a collection in Greenstone. A collection is an extension of
     
    6568    /** time when this collection was built */
    6669    protected long lastmodified = 0;
    67    
     70    /** earliestDatestamp of this collection. Necessary for OAI */
     71    protected long earliestDatestamp = 0;
     72
     73
    6874    /** An element containing the serviceRackList element of buildConfig.xml, used to determine whether it contains
    6975     *  the OAIPMH serviceRack
     
    130136    return is_public;
    131137    }
    132     //used by the OAIReceptionist to find out the earliest datestamp amongst all oai collections in the repository
     138    // Not used anymore by the OAIReceptionist to find out the earliest datestamp
     139    // amongst all oai collections in the repository. May be useful generally.
    133140    public long getLastmodified() {
    134141      return lastmodified;
    135142    }
     143    //used by the OAIReceptionist to find out the earliest datestamp amongst all oai collections in the repository
     144    public long getEarliestDatestamp() {
     145    return earliestDatestamp;
     146    }
     147
    136148    /** whether the service_map in ServiceCluster.java contains the service 'OAIPMH'
    137149     *  11/06/2007 xiao
     
    176188        build_config_elem = build_config_doc.getDocumentElement();
    177189    }
    178  
     190
    179191    lastmodified = build_config_file.lastModified();
    180192 
     
    211223        addPlugins(plugin_list);
    212224        if (plugin_list != null){
    213           Element plugin_elem = (Element)GSXML.getNamedElement(plugin_list, GSXML.PLUGIN_ELEM, GSXML.NAME_ATT, "HTMLPlug");
     225          Element plugin_elem = (Element)GSXML.getNamedElement(plugin_list, GSXML.PLUGIN_ELEM, GSXML.NAME_ATT, "HTMLPlugin");
    214226          if (plugin_elem != null) {
    215227            //get the option
    216             Element option_elem = (Element)GSXML.getNamedElement(plugin_elem, GSXML.PARAM_OPTION_ELEM, GSXML.NAME_ATT, "-tidy_html");
     228            Element option_elem = (Element)GSXML.getNamedElement(plugin_elem, GSXML.PARAM_OPTION_ELEM, GSXML.NAME_ATT, "-use_realistic_book");
    217229            if (option_elem != null) {
    218230              useBook = true;
     
    261273      } else {
    262274    has_oai = true;
     275   
     276    // extract earliestDatestamp from the buildconfig.xml for OAI
     277    Element metadata_list = (Element)GSXML.getChildByTagName(build_config_xml, GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
     278
     279    if(metadata_list != null) {
     280        NodeList children = metadata_list.getElementsByTagName(GSXML.METADATA_ELEM);
     281               // can't do getChildNodes(), because whitespace, such as newlines, creates Text nodes
     282        for (int i = 0; i < children.getLength(); i++) {
     283        Element metadata = (Element)children.item(i);
     284        if(metadata.getAttribute(GSXML.NAME_ATT).equals(OAIXML.EARLIEST_DATESTAMP)) {
     285            String earliestDatestampStr = GSXML.getValue(metadata);
     286            if(!earliestDatestampStr.equals("")) {
     287            earliestDatestamp = Long.parseLong(earliestDatestampStr);
     288            }
     289            break; // found a metadata element with name=earliestDatestamp in buildconfig
     290        }
     291        }
     292    }
     293   
     294    // If at the end of this, there is no value for earliestDatestamp, print out a warning
     295    logger.warn("No earliestDatestamp in buildConfig.xml for collection: " + this.cluster_name + ". Defaulting to 0.");
     296
    263297      }
     298    } else { // no list of services (no ServiceRackList), so no oai_service_rack either
     299    // explicitly set has_oai to false here, since it's initialised to true by default
     300    has_oai = false;
    264301    }
    265302    return true;
     
    275312        Element d = (Element) displaynodes.item(k);
    276313        String text = GSXML.getNodeText(d);
    277         text = text.replaceAll("_httpsite_", http_site);
    278         text = text.replaceAll("_httpcollection_", http_collection);
     314        text = StringUtils.replace(text, "_httpsite_", http_site);
     315        text = StringUtils.replace(text, "_httpcollection_", http_collection);
    279316        GSXML.setNodeText(d, text);
    280317        }
     
    338375
    339376        Element format_element = (Element) GSXML.getChildByTagName(request, GSXML.FORMAT_STRING_ELEM);
    340         String format_string = GSXML.getNodeText(format_element);
    341         //Element format_statement = (Element) format_element.getFirstChild();
     377        //String format_string = GSXML.getNodeText(format_element);
     378        Element format_statement = (Element) format_element.getFirstChild();
    342379
    343380        //logger.error("Format string: " + format_string);
     
    394431
    395432                // Write format statement
    396                 //String format_string = GSXML.xmlNodeToString(format_statement);
     433                String format_string = this.converter.getString(format_statement); //GSXML.xmlNodeToString(format_statement);
    397434                writer = new BufferedWriter(new FileWriter(format_statement_filename));
    398435                writer.write(format_string);
     
    416453
    417454                // Convert format string to a document
    418                 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    419                 DocumentBuilder builder = factory.newDocumentBuilder();
     455                //DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
     456                //DocumentBuilder builder = factory.newDocumentBuilder();
    420457                //String input = "<html><head><title></title></head><body>" + format_string + "</body></html>";
    421                 String input = format_string.substring(0,format_string.length()-1)+"</xml>";
    422                 logger.error(input);
    423                 InputSource is = new InputSource( new StringReader( input ) );
    424                 logger.error("About to parse format string");
    425                 Document format_statement = (Document) builder.parse( is );
    426                 logger.error("Done parsing format string");
     458                //String input = format_string.substring(0,format_string.length()-1)+"</xml>";
     459                //logger.error(input);
     460                //InputSource is = new InputSource( new StringReader( input ) );
     461                //logger.error("About to parse format string");
     462                //Document format_statement = (Document) builder.parse( is );
     463                //logger.error("Done parsing format string");
    427464
    428465                // open collectionConfig.xml and read in to w3 Document
     
    488525
    489526                // append new but we have a string!
    490                 GSXML.setNodeText(elem, format_string);
    491 
    492                 //current_node_list = format_statement.getChildNodes();
    493                 //for(k=0; k<current_node_list.getLength(); k++)
    494                 //{
    495                 //    current_node = elem.appendChild(current_node_list.item(k));
    496                 //}
     527                //GSXML.setNodeText(elem, "THIS IS A TEST");
     528                //GSXML.setNodeText(elem, format_string);
     529
     530                current_node_list = format_statement.getChildNodes();
     531                for(k=0; k<current_node_list.getLength(); k++)
     532                {
     533                    //if(transformed.getNodeType() == Node.DOCUMENT_NODE)
     534                //transformed = ((Document)transformed).getDocumentElement();
     535                    logger.error("Node type: "+current_node_list.item(k).getNodeType());
     536                    if(current_node_list.item(k).getNodeType() != Node.PROCESSING_INSTRUCTION_NODE)
     537                        current_node = elem.appendChild(this.doc.importNode(current_node_list.item(k),true));
     538                }
    497539
    498540                //String text = GSXML.getNodeText(elem);
     
    503545
    504546                // Now convert config document to string for writing to file
    505                 String new_config = GSXML.xmlNodeToString(config);
     547                String new_config = this.converter.getString(config);
    506548   
    507549                // Write to file (not original! for now)
Note: See TracChangeset for help on using the changeset viewer.