Changeset 1623
- Timestamp:
- 06/13/08 12:01:33 (3 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/websites/xml/skin/stubDefaultSkinGenerator.php
r1607 r1623 130 130 $xslProcessor->setParameter('', 'lang_base', substr($lang, 0, strpos($lang, '_')) . '_*'); 131 131 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 133 137 stubXMLXIncludeStreamWrapper::setCachePath(stubConfig::getCachePath()); 134 138 stubXMLXIncludeStreamWrapper::setXSLProcessor($xslProcessor); trunk/src/main/php/net/stubbles/xml/stubXMLXIncludeStreamWrapper.php
r1534 r1623 8 8 */ 9 9 stubClassLoader::load('net::stubbles::lang::stubRegistry', 10 'net::stubbles::lang::exceptions::stubFileNotFoundException', 10 11 'net::stubbles::lang::exceptions::stubIOException', 11 12 'net::stubbles::xml::stubXMLException', … … 25 26 * @var bool 26 27 */ 27 private static $registered = false;28 private static $registered = false; 28 29 /** 29 30 * the xsl processor to use for the transformation … … 39 40 protected static $cachePath; 40 41 /** 41 * include path to use if file not found in current path42 * 43 * @var string44 */ 45 protected static $includePath ;42 * list of include pathes where files may reside 43 * 44 * @var array<string> 45 */ 46 protected static $includePathes = array(); 46 47 /** 47 48 * current xml file … … 114 115 115 116 /** 116 * sets the include path to use 117 * 117 * adds an include path 118 * 119 * @param string $key 118 120 * @param string $includePath 119 121 */ 120 public static function setIncludePath($includePath)121 { 122 self::$includePath = $includePath;122 public static function addIncludePath($key, $includePath) 123 { 124 self::$includePathes[$key] = $includePath; 123 125 } 124 126 … … 131 133 * @param string $opened_path full path that was actually opened 132 134 * @return bool 133 * @throws stubXMLException134 135 */ 135 136 public function stream_open($path, $mode, $options, $opened_path) 136 137 { 137 138 $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 146 139 if (file_exists($this->cachedFileName) == false || $this->needsRefresh() == true) { 147 140 $this->processFile(); … … 200 193 201 194 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 206 195 $resultDoc->save($this->cachedFileName); 207 196 } … … 329 318 * parses the path into class members 330 319 * 331 * @param string $path 320 * @param string $path 321 * @throws stubFileNotFoundException 332 322 */ 333 323 protected function parsePath($path) 334 324 { 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) { 340 343 $language = self::$xslProcessor->getParameter('', 'lang'); 341 344 } 342 345 343 $this->cachedFileName = self::$cachePath . '/' . $language . '/'. $fileName;346 $this->cachedFileName = self::$cachePath . DIRECTORY_SEPARATOR . $cacheKey . $language . DIRECTORY_SEPARATOR . $fileName; 344 347 if (file_exists(dirname($this->cachedFileName)) === false) { 345 348 mkdir(dirname($this->cachedFileName), stubRegistry::getConfig('net.stubbles.filemode', 0700), true); trunk/src/main/resources/xsl/stub.xsl
r1620 r1623 154 154 155 155 <xsl:template match="stub:include" name="stub:include"> 156 <xsl:param name="project" select="@project"/> 156 157 <xsl:param name="href" select="@href"/> 157 158 <xsl:param name="part" select="@part"/> … … 160 161 <xsl:when test="$href"> 161 162 <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> 162 172 <xsl:value-of select="$href"/> 163 173 <xsl:text>?part=</xsl:text> … … 176 186 <xi:include href="{$xihref}"> 177 187 <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"/> 179 189 </xi:fallback> 180 190 </xi:include>
