Changeset 1623

Show
Ignore:
Timestamp:
06/13/08 12:01:33 (3 months ago)
Author:
mikey
Message:

implement enhancement #143: enable common xsl directory for several projects in one installation

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/php/net/stubbles/websites/xml/skin/stubDefaultSkinGenerator.php

    r1607 r1623  
    130130        $xslProcessor->setParameter('', 'lang_base', substr($lang, 0, strpos($lang, '_')) . '_*'); 
    131131        stubXMLXIncludeStreamWrapper::register(); 
    132         stubXMLXIncludeStreamWrapper::setIncludePath(stubConfig::getPagePath() . '/txt'); 
     132        stubXMLXIncludeStreamWrapper::addIncludePath('default', stubConfig::getPagePath() . '/txt'); 
     133        if (stubRegistry::hasConfig('net.stubbles.websites.xml.skin.common') === true) { 
     134            stubXMLXIncludeStreamWrapper::addIncludePath('common', stubRegistry::getConfig('net.stubbles.websites.xml.skin.common')); 
     135        } 
     136         
    133137        stubXMLXIncludeStreamWrapper::setCachePath(stubConfig::getCachePath()); 
    134138        stubXMLXIncludeStreamWrapper::setXSLProcessor($xslProcessor); 
  • trunk/src/main/php/net/stubbles/xml/stubXMLXIncludeStreamWrapper.php

    r1534 r1623  
    88 */ 
    99stubClassLoader::load('net::stubbles::lang::stubRegistry', 
     10                      'net::stubbles::lang::exceptions::stubFileNotFoundException', 
    1011                      'net::stubbles::lang::exceptions::stubIOException', 
    1112                      'net::stubbles::xml::stubXMLException', 
     
    2526     * @var  bool 
    2627     */ 
    27     private static $registered     = false; 
     28    private static $registered      = false; 
    2829    /** 
    2930     * the xsl processor to use for the transformation 
     
    3940    protected static $cachePath; 
    4041    /** 
    41      * include path to use if file not found in current path 
    42      * 
    43      * @var  string 
    44      */ 
    45     protected static $includePath
     42     * list of include pathes where files may reside 
     43     * 
     44     * @var  array<string> 
     45     */ 
     46    protected static $includePathes = array()
    4647    /** 
    4748     * current xml file 
     
    114115 
    115116    /** 
    116      * sets the include path to use 
    117      * 
     117     * adds an include path 
     118     * 
     119     * @param  string  $key 
    118120     * @param  string  $includePath 
    119121     */ 
    120     public static function setIncludePath($includePath) 
    121     { 
    122         self::$includePath = $includePath; 
     122    public static function addIncludePath($key, $includePath) 
     123    { 
     124        self::$includePathes[$key] = $includePath; 
    123125    } 
    124126 
     
    131133     * @param   string  $opened_path  full path that was actually opened 
    132134     * @return  bool 
    133      * @throws  stubXMLException 
    134135     */ 
    135136    public function stream_open($path, $mode, $options, $opened_path) 
    136137    { 
    137138        $this->parsePath($path); 
    138         if (file_exists($this->fileName) == false) { 
    139             if (file_exists(self::$includePath . '/' . $this->fileName) == false) { 
    140                 return false; 
    141             } 
    142  
    143             $this->fileName = self::$includePath . '/' . $this->fileName; 
    144         } 
    145  
    146139        if (file_exists($this->cachedFileName) == false || $this->needsRefresh() == true) { 
    147140            $this->processFile(); 
     
    200193 
    201194        libxml_use_internal_errors($previousErrorHandling); 
    202         if (!is_writeable($this->cachedFileName)) { 
    203             throw new stubIOException("Can not write cache file to {$this->cachedFileName}."); 
    204         } 
    205          
    206195        $resultDoc->save($this->cachedFileName); 
    207196    } 
     
    329318     * parses the path into class members 
    330319     * 
    331      * @param  string  $path 
     320     * @param   string  $path 
     321     * @throws  stubFileNotFoundException 
    332322     */ 
    333323    protected function parsePath($path) 
    334324    { 
    335         list($fileName, $part) = sscanf($path, 'xinc://%[^?]?part=%[^$]'); 
    336         $this->fileName        = $fileName; 
    337         $this->part            = $part; 
    338         $language              = ''; 
    339         if (self::$xslProcessor->hasParameter('', 'lang') == true) { 
     325        list($key, $fileName, $part) = sscanf($path, 'xinc://%[^/?#]/%[^?]?part=%[^$]'); 
     326        if (null !== $fileName) { 
     327            if (isset(self::$includePathes[$key]) === false || file_exists(self::$includePathes[$key] . DIRECTORY_SEPARATOR . $fileName) === false) { 
     328                throw new stubFileNotFoundException(self::$includePathes[$key] . DIRECTORY_SEPARATOR . $fileName); 
     329            } 
     330             
     331            $this->fileName = self::$includePathes[$key] . DIRECTORY_SEPARATOR . $fileName; 
     332            $cacheKey       = $key . DIRECTORY_SEPARATOR; 
     333        } elseif (file_exists($key) === true) { 
     334            $this->fileName = $key; 
     335            $cacheKey       = ''; 
     336        } else { 
     337            throw new stubFileNotFoundException($fileName); 
     338        } 
     339         
     340        $this->part = $part; 
     341        $language   = ''; 
     342        if (self::$xslProcessor->hasParameter('', 'lang') === true) { 
    340343            $language = self::$xslProcessor->getParameter('', 'lang'); 
    341344        } 
    342345         
    343         $this->cachedFileName = self::$cachePath . '/' . $language  . '/' . $fileName; 
     346        $this->cachedFileName = self::$cachePath . DIRECTORY_SEPARATOR . $cacheKey . $language  . DIRECTORY_SEPARATOR . $fileName; 
    344347        if (file_exists(dirname($this->cachedFileName)) === false) { 
    345348            mkdir(dirname($this->cachedFileName), stubRegistry::getConfig('net.stubbles.filemode', 0700), true); 
  • trunk/src/main/resources/xsl/stub.xsl

    r1620 r1623  
    154154 
    155155  <xsl:template match="stub:include" name="stub:include"> 
     156    <xsl:param name="project" select="@project"/> 
    156157    <xsl:param name="href" select="@href"/> 
    157158    <xsl:param name="part" select="@part"/> 
     
    160161        <xsl:when test="$href"> 
    161162          <xsl:text>xinc://</xsl:text> 
     163          <xsl:choose> 
     164            <xsl:when test="$project"> 
     165              <xsl:value-of select="$project"/> 
     166            </xsl:when> 
     167            <xsl:otherwise> 
     168              <xsl:text>default</xsl:text> 
     169            </xsl:otherwise> 
     170          </xsl:choose> 
     171          <xsl:text>/</xsl:text> 
    162172          <xsl:value-of select="$href"/> 
    163173          <xsl:text>?part=</xsl:text> 
     
    176186    <xi:include href="{$xihref}"> 
    177187      <xi:fallback> 
    178         ERROR: Could not include part <xsl:value-of select="$part"/> in file <xsl:value-of select="$href"/> 
     188        ERROR: Could not include part <xsl:value-of select="$part"/> in file <xsl:value-of select="$href"/> from project <xsl:value-of select="$project"/> 
    179189      </xi:fallback> 
    180190    </xi:include>