Ignore:
Timestamp:
2012-07-19T15:07:02+12:00 (12 years ago)
Author:
kjdon
Message:

pass interface name to inlineImport... method, don't hard code default. Added new method, GSXLST.mergedXSLTDocumentCascade, which looks for a named stylesheet in collection/site/interface/base-interfaces, then merges them all together and returns the Document. Code copied from getXSLTDocument in TransformingReceptionist, which now calls this method

Location:
main/trunk/greenstone3/src/java/org/greenstone/gsdl3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/TransformingReceptionist.java

    r25912 r25987  
    739739        }
    740740
    741         GSXSLT.inlineImportAndIncludeFiles(skinAndLibraryDoc, null);
     741        GSXSLT.inlineImportAndIncludeFiles(skinAndLibraryDoc, null, (String) this.config_params.get(GSConstants.INTERFACE_NAME));
    742742        skinAndLibraryDoc = (Document) secondConfigFormatPass(collection, skinAndLibraryDoc, doc, new UserContext(request));
    743743
     
    864864            name = this.xslt_map.get(action);
    865865        }
    866         // now find the absolute path
    867         ArrayList<File> stylesheets = GSFile.getStylesheetFiles(GlobalProperties.getGSDL3Home(), (String) this.config_params.get(GSConstants.SITE_NAME), collection, (String) this.config_params.get(GSConstants.INTERFACE_NAME), base_interfaces, name);
    868         if (stylesheets.size() == 0)
    869         {
    870             logger.error(" Can't find stylesheet for " + name);
    871             return null;
    872         }
    873         logger.debug("Stylesheet: " + name);
    874 
    875         Document finalDoc = this.converter.getDOM(stylesheets.get(stylesheets.size() - 1), "UTF-8");
    876         if (finalDoc == null)
    877         {
    878             return null;
    879         }
    880 
    881         for (int i = stylesheets.size() - 2; i >= 0; i--)
    882         {
    883             Document currentDoc = this.converter.getDOM(stylesheets.get(i), "UTF-8");
    884             if (currentDoc == null)
    885             {
    886                 return null;
    887             }
    888 
    889             if (_debug)
    890             {
    891                 GSXSLT.mergeStylesheetsDebug(finalDoc, currentDoc.getDocumentElement(), true, true, stylesheets.get(stylesheets.size() - 1).getAbsolutePath(), stylesheets.get(i).getAbsolutePath());
    892             }
    893             else
    894             {
    895                 GSXSLT.mergeStylesheets(finalDoc, currentDoc.getDocumentElement(), true);
    896             }
    897         }
    898 
     866
     867        Document finalDoc = GSXSLT.mergedXSLTDocumentCascade(name, (String) this.config_params.get(GSConstants.SITE_NAME), collection, (String) this.config_params.get(GSConstants.INTERFACE_NAME), base_interfaces, _debug);
    899868        return finalDoc;
    900869    }
     870    //  // now find the absolute path
     871    //  ArrayList<File> stylesheets = GSFile.getStylesheetFiles(GlobalProperties.getGSDL3Home(), (String) this.config_params.get(GSConstants.SITE_NAME), collection, (String) this.config_params.get(GSConstants.INTERFACE_NAME), base_interfaces, name);
     872    //  if (stylesheets.size() == 0)
     873    //  {
     874    //      logger.error(" Can't find stylesheet for " + name);
     875    //      return null;
     876    //  }
     877    //  logger.debug("Stylesheet: " + name);
     878
     879    //  Document finalDoc = this.converter.getDOM(stylesheets.get(stylesheets.size() - 1), "UTF-8");
     880    //  if (finalDoc == null)
     881    //  {
     882    //      return null;
     883    //  }
     884
     885    //  for (int i = stylesheets.size() - 2; i >= 0; i--)
     886    //  {
     887    //      Document currentDoc = this.converter.getDOM(stylesheets.get(i), "UTF-8");
     888    //      if (currentDoc == null)
     889    //      {
     890    //          return null;
     891    //      }
     892
     893    //      if (_debug)
     894    //      {
     895    //          GSXSLT.mergeStylesheetsDebug(finalDoc, currentDoc.getDocumentElement(), true, true, stylesheets.get(stylesheets.size() - 1).getAbsolutePath(), stylesheets.get(i).getAbsolutePath());
     896    //      }
     897    //      else
     898    //      {
     899    //          GSXSLT.mergeStylesheets(finalDoc, currentDoc.getDocumentElement(), true);
     900    //      }
     901    //  }
     902
     903    //  return finalDoc;
     904    // }
    901905
    902906    // returns the path to the gslib.xsl file that is applicable for the current interface
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/GSXSLT.java

    r25982 r25987  
    2929import org.w3c.dom.NodeList;
    3030
     31import org.apache.log4j.*;
     32
    3133/** various functions for manipulating Greenstone xslt */
    3234public class GSXSLT
    3335{
     36
     37    static Logger logger = Logger.getLogger(org.greenstone.gsdl3.util.GSXSLT.class.getName());
     38
    3439    public static void mergeStylesheets(Document main_xsl, Element extra_xsl, boolean overwrite)
    3540    {
     
    215220    }
    216221
    217     public static void inlineImportAndIncludeFiles(Document doc, String pathExtra)
    218     {
    219         inlineImportAndIncludeFilesDebug(doc, pathExtra, false, null);
    220     }
    221 
    222     public static void inlineImportAndIncludeFilesDebug(Document doc, String pathExtra, boolean debug, String docFileName)
     222  public static void inlineImportAndIncludeFiles(Document doc, String pathExtra, String interface_name)
     223    {
     224      inlineImportAndIncludeFilesDebug(doc, pathExtra, false, null, interface_name);
     225    }
     226
     227  public static void inlineImportAndIncludeFilesDebug(Document doc, String pathExtra, boolean debug, String docFileName, String interface_name)
    223228    {
    224229        XMLConverter converter = new XMLConverter();
     
    233238            Element current = (Element) ((i < importList.getLength()) ? importList.item(i) : includeList.item(i - importList.getLength()));
    234239            String href = current.getAttribute("href");
    235             String filePath = GSFile.interfaceHome(GlobalProperties.getGSDL3Home(), "default") + File.separator + "transform" + File.separator + path.replace("/", File.separator) + href.replace("/", File.separator);
     240            String filePath = GSFile.interfaceHome(GlobalProperties.getGSDL3Home(), interface_name) + File.separator + "transform" + File.separator + path.replace("/", File.separator) + href.replace("/", File.separator);
     241            //String filePath = GSFile.stylesheetFile(GlobalProperties.getGSDL3Home(), site_name, collection, interface_name, base_interfaces,
    236242
    237243            try
     
    247253
    248254                //Do this recursively
    249                 inlineImportAndIncludeFilesDebug(inlineDoc, newPath, debug, filePath);
     255                inlineImportAndIncludeFilesDebug(inlineDoc, newPath, debug, filePath, interface_name);
    250256
    251257                GSXSLT.mergeStylesheetsDebug(doc, inlineDoc.getDocumentElement(), false, debug, docFileName, filePath);
     
    269275        }
    270276    }
     277
     278        public static Document mergedXSLTDocumentCascade(String xslt_filename, String site, String collection, String this_interface, ArrayList<String> base_interfaces, boolean debug) {
     279          XMLConverter converter = new XMLConverter();
     280          // find the list of stylesheets with this name
     281          ArrayList<File> stylesheets = GSFile.getStylesheetFiles(GlobalProperties.getGSDL3Home(), site, collection, this_interface, base_interfaces, xslt_filename);
     282        if (stylesheets.size() == 0)
     283        {
     284            logger.error(" Can't find stylesheet for " + xslt_filename);
     285            return null;
     286        }
     287        logger.debug("Stylesheet: " + xslt_filename);
     288
     289        Document finalDoc = converter.getDOM(stylesheets.get(stylesheets.size() - 1), "UTF-8");
     290        if (finalDoc == null)
     291        {
     292            return null;
     293        }
     294
     295        for (int i = stylesheets.size() - 2; i >= 0; i--)
     296        {
     297            Document currentDoc = converter.getDOM(stylesheets.get(i), "UTF-8");
     298            if (currentDoc == null)
     299            {
     300                return null;
     301            }
     302
     303            if (debug)
     304            {
     305                GSXSLT.mergeStylesheetsDebug(finalDoc, currentDoc.getDocumentElement(), true, true, stylesheets.get(stylesheets.size() - 1).getAbsolutePath(), stylesheets.get(i).getAbsolutePath());
     306            }
     307            else
     308            {
     309                GSXSLT.mergeStylesheets(finalDoc, currentDoc.getDocumentElement(), true);
     310            }
     311        }
     312
     313        return finalDoc;
     314    }
     315
     316
    271317
    272318    public static void modifyConfigFormatForDebug(Document doc, String fileName)
Note: See TracChangeset for help on using the changeset viewer.