Changeset 8562


Ignore:
Timestamp:
2004-11-16T12:22:43+13:00 (19 years ago)
Author:
kjdon
Message:

interfaces are now based on another, rather than all using the default as a base. So the chain of looking for xslt is now collection, site, current interface, base interfaces (maybe more than one or none)

Location:
trunk/gsdl3/src/java/org/greenstone/gsdl3
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/core/Receptionist.java

    r5402 r8562  
    1313import java.util.HashMap;
    1414import java.util.Enumeration;
     15import java.util.ArrayList;
    1516
    1617/** the most basic Receptionist, used for interface generation.
     
    4041    protected Element language_list = null;
    4142
     43    /** the list of interfaces this is based on */
     44    protected ArrayList base_interfaces = null;
     45   
    4246    public Receptionist() {
    4347    this.converter = new XMLConverter();
     
    7882   
    7983    Element config_doc = this.converter.getDOM(interface_config_file).getDocumentElement();
     84    String base_interface = config_doc.getAttribute("baseInterface");
     85    setUpBaseInterface(base_interface);
    8086    Element action_list = (Element)GSXML.getChildByTagName(config_doc, GSXML.ACTION_ELEM+GSXML.LIST_MODIFIER);
    8187    NodeList actions = action_list.getElementsByTagName(GSXML.ACTION_ELEM);
     
    193199    page.appendChild(page_response);
    194200
    195     ///ystem.out.println("REceptionist: raw page="+this.converter.getString(page));
     201    ///ystem.out.println("Receptionist: raw page="+this.converter.getString(page));
    196202    // transform the result in some way
    197203    Element resulting_page = postProcessPage(page);
     
    200206    }
    201207
     208    protected boolean setUpBaseInterface(String base_interface) {
     209    if (base_interface== null || base_interface.equals("")) {
     210        // there was no base interface, the list remains null
     211        return true;
     212    }
     213    // foreach base interface
     214    while (!base_interface.equals("")) {
     215        // find the base interface config file
     216        File base_interface_config_file = new File(GSFile.interfaceConfigFile(GSFile.interfaceHome((String)this.config_params.get(GSConstants.GSDL3_HOME), base_interface)));
     217        if (!base_interface_config_file.exists()) {
     218        System.err.println("Receptionist: base interface config file: "+base_interface_config_file.getPath()+" not found!");
     219        return false;
     220        }
     221        // the interface name is valid, add it to the list
     222        if (base_interfaces == null) {
     223        base_interfaces = new ArrayList();
     224        }
     225        base_interfaces.add(base_interface);
     226        // now see if this has a base interface
     227        Element config_doc = this.converter.getDOM(base_interface_config_file).getDocumentElement();
     228        base_interface = config_doc.getAttribute("baseInterface");
     229    }
     230    return true;
     231    }
    202232    protected void preProcessRequest(Element request) {
    203233    return;
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/core/TransformingReceptionist.java

    r5693 r8562  
    5454   
    5555    Element config_doc = this.converter.getDOM(interface_config_file, "utf-8").getDocumentElement();
     56    String base_interface = config_doc.getAttribute("baseInterface");
     57    setUpBaseInterface(base_interface);
    5658    Element action_list = (Element)GSXML.getChildByTagName(config_doc, GSXML.ACTION_ELEM+GSXML.LIST_MODIFIER);
    5759    NodeList actions = action_list.getElementsByTagName(GSXML.ACTION_ELEM);
     
    122124    protected Element transformPage(Element page) {
    123125
     126    //ystem.out.println("page before transfomring:");
     127    //ystem.out.println(this.converter.getPrettyString(page));
     128
    124129    Element request = (Element)GSXML.getChildByTagName(page, GSXML.PAGE_REQUEST_ELEM);
    125130    String action = request.getAttribute("action");
     
    147152    if (format_elem != null) {
    148153        //page_response.removeChild(format_elem);
    149        
     154        ///ystem.err.println("format elem="+this.converter.getPrettyString(format_elem));
    150155        // need to transform the format info
    151         String stylesheet_file = GSFile.stylesheetFile((String)this.config_params.get(GSConstants.GSDL3_HOME), (String)this.config_params.get(GSConstants.SITE_NAME), (String)this.config_params.get(GSConstants.INTERFACE_NAME), "",   "config_format.xsl");
     156        String stylesheet_file = GSFile.stylesheetFile((String)this.config_params.get(GSConstants.GSDL3_HOME), (String)this.config_params.get(GSConstants.SITE_NAME), collection, (String)this.config_params.get(GSConstants.INTERFACE_NAME), base_interfaces,   "config_format.xsl");
    152157        Document stylesheet = this.converter.getDOM(new File(stylesheet_file));
    153158        Document format_doc = this.converter.newDOM();
    154159        format_doc.appendChild(format_doc.importNode(format_elem, true));
    155160        Element new_format = (Element)this.transformer.transform(stylesheet, format_doc);
     161        ///ystem.err.println("new format elem="+this.converter.getPrettyString(new_format));
     162       
    156163        // add it in to the main stylesheet
    157164        GSXSLT.mergeStylesheets(style_doc, new_format);
     
    161168   
    162169    // there is a thing called a URIResolver which you can set for a transformer or transformer factory. may be able to use this instead of this absoluteIncludepaths hack
    163     GSXSLT.absoluteIncludePaths(style_doc, (String)this.config_params.get(GSConstants.GSDL3_HOME), (String)this.config_params.get(GSConstants.SITE_NAME), (String)this.config_params.get(GSConstants.INTERFACE_NAME), collection);
     170    GSXSLT.absoluteIncludePaths(style_doc, (String)this.config_params.get(GSConstants.GSDL3_HOME), (String)this.config_params.get(GSConstants.SITE_NAME), collection, (String)this.config_params.get(GSConstants.INTERFACE_NAME), base_interfaces);
    164171    // put the page into a document - this is necessary for xslt to get the paths right if you have paths relative to the document root eg /page.
    165172    Document doc = this.converter.newDOM();
     
    181188    }
    182189    // now find the absolute path
    183     String stylesheet = GSFile.stylesheetFile((String)this.config_params.get(GSConstants.GSDL3_HOME), (String)this.config_params.get(GSConstants.SITE_NAME), (String)this.config_params.get(GSConstants.INTERFACE_NAME), collection, name);
     190    String stylesheet = GSFile.stylesheetFile((String)this.config_params.get(GSConstants.GSDL3_HOME), (String)this.config_params.get(GSConstants.SITE_NAME), collection, (String)this.config_params.get(GSConstants.INTERFACE_NAME), base_interfaces, name);
    184191    if (stylesheet==null) {
    185192        System.out.println("TransformingReceptionist: cant find stylesheet for "+name);
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/util/GSFile.java

    r6893 r8562  
    2929import java.lang.ClassLoader; // to find files on the class path
    3030import java.net.URL;
     31import java.util.ArrayList;
    3132
    3233/**
     
    210211   
    211212    /** returns the absolute path to a stylesheet
    212      * stylesheets are looked for in the following order
    213      * collect-specific,
    214      * site-specific, interface-specific, default
     213     * stylesheets are looked for in the following places, in the
     214     * following order:
     215     * current collection, current site, current interface, base interfaces
    215216     * returns null  if the file cannot be found
    216217     *
     
    218219    static public String stylesheetFile(String gsdl3_home,
    219220                    String site_name,
     221                    String collection,
    220222                    String interface_name,
    221                     String collection,
     223                    ArrayList base_interfaces,
    222224                    String filename) {
    223225
     
    234236        }
    235237    }
    236     // try site one next
    237238   
     239    // try site one next   
    238240    stylesheet = new File(site_home +File.separatorChar+
    239                    "transform"+File.separatorChar+filename);
     241                  "transform"+File.separatorChar+filename);
    240242    if (stylesheet.exists()) {
    241243        return stylesheet.getPath();
    242244    }
     245   
    243246    // try current interface
    244247    String interface_home = interfaceHome(gsdl3_home,
     
    249252        return stylesheet.getPath();
    250253    }
    251     // try default interface
    252     interface_home = interfaceHome(gsdl3_home, "default");
    253     stylesheet = new File(interface_home+File.separatorChar+
    254                   "transform"+File.separatorChar+filename);
    255     if (stylesheet.exists()) {
    256         return stylesheet.getPath();
     254    // try base interface
     255    if (base_interfaces==null || base_interfaces.size()==0) {
     256        return null; // no base interfaces to look for
     257    }
     258    for (int i=0; i<base_interfaces.size(); i++) {
     259        interface_home = interfaceHome(gsdl3_home, (String)base_interfaces.get(i));
     260        stylesheet = new File(interface_home+File.separatorChar+
     261                  "transform"+File.separatorChar+filename);
     262        if (stylesheet.exists()) {
     263        return stylesheet.getPath();
     264        }
    257265    }
    258266       
    259     // cant find it
     267    // still can't find it and we have looked everywhere
    260268    return null;
    261269    }
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/util/GSXSLT.java

    r4860 r8562  
    99import java.util.HashMap;
    1010import java.util.Vector;
     11import java.util.ArrayList;
    1112
    1213/** various functions for manipulating Greenstone xslt  */
     
    4243                        String gsdl3_home,
    4344                        String site_name,
     45                        String collection,
    4446                        String interface_name,
    45                         String collection) {
     47                        ArrayList base_interfaces) {
    4648   
    4749   
     
    5153        String name = child.getNodeName();
    5254        if (name.equals("xsl:import") || name.equals("xsl:include")) {
    53         ((Element)child).setAttribute("href", GSFile.stylesheetFile(gsdl3_home, site_name, interface_name, collection, ((Element)child).getAttribute("href")));
     55        ((Element)child).setAttribute("href", GSFile.stylesheetFile(gsdl3_home, site_name, collection, interface_name, base_interfaces, ((Element)child).getAttribute("href")));
    5456        }
    5557        child = child.getNextSibling();
Note: See TracChangeset for help on using the changeset viewer.