Changeset 1429
- Timestamp:
- 03/17/08 15:46:51 (2 months ago)
- Files:
-
- trunk/src/main/php/net/stubbles/websites/xml/skin/stubDefaultSkinGenerator.php (added)
- trunk/src/main/php/net/stubbles/websites/xml/skin/stubSkinGenerator.php (modified) (3 diffs)
- trunk/src/main/php/net/stubbles/websites/xml/stubXMLProcessor.php (modified) (2 diffs)
- trunk/src/test/php/net/stubbles/websites/WebsitesTestSuite.php (modified) (1 diff)
- trunk/src/test/php/net/stubbles/websites/xml/skin/stubDefaultSkinGeneratorTestCase.php (moved) (moved from trunk/src/test/php/net/stubbles/websites/xml/skin/stubSkinGeneratorTestCase.php) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/websites/xml/skin/stubSkinGenerator.php
r1425 r1429 1 1 <?php 2 2 /** 3 * Classto generate the skin to be applied onto the XML result document.3 * Interface to generate the skin to be applied onto the XML result document. 4 4 * 5 5 * @author Frank Kleine <mikey@stubbles.net> … … 7 7 * @subpackage websites_xml_skin 8 8 */ 9 stubClassLoader::load('net::stubbles::ioc::stubBinder', 10 'net::stubbles::ipo::session::stubSession', 11 'net::stubbles::lang::exceptions::stubRuntimeException', 12 'net::stubbles::util::stubFactory', 13 'net::stubbles::util::stubRegistry', 14 'net::stubbles::websites::stubPage', 15 'net::stubbles::xml::stubXMLXIncludeStreamWrapper', 16 'net::stubbles::xml::stubXMLStreamWriterFactory', 17 'net::stubbles::xml::xsl::stubXSLProcessor' 9 stubClassLoader::load('net::stubbles::ipo::session::stubSession', 10 'net::stubbles::websites::stubPage' 18 11 ); 19 12 /** 20 * Class to generate the skin to be applied onto the XML result document. 21 * 22 * Please make sure as well that a file named xsl-callbacks.ini resides in the 23 * base config directory configured in stubConfig::getConfigPath(). 13 * Interface to generate the skin to be applied onto the XML result document. 24 14 * 25 15 * @package stubbles 26 16 * @subpackage websites_xml_skin 27 17 */ 28 class stubSkinGenerator extends stubBaseObject18 interface stubSkinGenerator extends stubObject 29 19 { 30 20 /** 31 * callback config file name21 * returns the key for the skin to be generated 32 22 * 33 * @var string 23 * @param stubSession $session 24 * @param stubPage $page 25 * @return string 34 26 */ 35 protected $callbackConfigFile; 36 37 /** 38 * constructor 39 */ 40 public function __construct() 41 { 42 stubXMLXIncludeStreamWrapper::register(); 43 stubXMLXIncludeStreamWrapper::setIncludePath(stubConfig::getPagePath() . '/txt'); 44 stubXMLXIncludeStreamWrapper::setCachePath(stubConfig::getCachePath()); 45 $this->callbackConfigFile = stubConfig::getConfigPath() . '/xsl-callbacks.ini'; 46 } 47 48 /** 49 * sets the callback config file 50 * 51 * @param string $callbackConfigFile 52 */ 53 public function setCallbackConfigFile($callbackConfigFile) 54 { 55 $this->callbackConfigFile = $callbackConfigFile; 56 } 27 public function getSkinKey(stubSession $session, stubPage $page); 57 28 58 29 /** … … 62 33 * @param stubPage $page 63 34 * @return DOMDocument 64 * @throws stubRuntimeException65 35 */ 66 public function generate(stubSession $session, stubPage $page) 67 { 68 $binder = stubRegistry::get(stubBinder::REGISTRY_KEY); 69 if (($binder instanceof stubBinder) === false) { 70 throw new stubRuntimeException('No instance of net::stubbles::ioc::stubBinder in registry.'); 71 } 72 73 $binder->bind('stubXMLStreamWriter')->to(stubXMLStreamWriterFactory::getFqClassNameAsAvailable()); 74 $binder->bindConstant()->named('imagePath')->to(getcwd()); 75 $xslProcessor = $this->createXSLProcessor(); 76 $injector = $binder->getInjector(); 77 foreach ($this->getCallbackList() as $callbackName => $callbackClass) { 78 $xslProcessor->registerCallback($callbackName, $injector->getInstance($callbackClass)); 79 } 80 81 $xslProcessor->importXSLStylesheet($this->createXSLStylesheet()); 82 $xslProcessor->setParameter('', 'page', $page->getProperty('name')); 83 if ($session->hasValue('net.stubbles.language') == true) { 84 $language = $session->getValue('net.stubbles.language'); 85 } elseif ($page->hasProperty('language') == true) { 86 $language = $page->getProperty('language'); 87 } elseif (stubRegistry::hasConfig('net.stubbles.language') == true) { 88 $language = stubRegistry::getConfig('net.stubbles.language'); 89 } else { 90 $language = 'en_EN'; 91 } 92 93 $xslProcessor->setParameter('', 'lang', $language); 94 // use same xsl processor for xincludes 95 stubXMLXIncludeStreamWrapper::setXSLProcessor($xslProcessor); 96 97 // first we create the xsl with applying the master.xsl on the skin and the page 98 $skin = (($page->hasProperty('skin') === true) ? ($page->getProperty('skin')) : ('default')); 99 $xslProcessor->setXMLDocument($this->createXMLSkinDocument($skin)); 100 $resultXSL = $xslProcessor->transformToDoc(); 101 @$resultXSL->xinclude(); 102 return $resultXSL; 103 } 104 105 /** 106 * creates a stubXSLProcessor instance 107 * 108 * @return stubXSLProcessor 109 */ 110 // @codeCoverageIgnoreStart 111 protected function createXSLProcessor() 112 { 113 return new stubXSLProcessor(); 114 } 115 // @codeCoverageIgnoreEnd 116 117 /** 118 * creates the list of callbacks 119 * 120 * @return array 121 * @throws stubRuntimeException 122 */ 123 protected function getCallbackList() 124 { 125 if (file_exists($this->callbackConfigFile) === false) { 126 throw new stubRuntimeException('Configuration file ' . $this->callbackConfigFile . ' for XSL callback configuration is missing.'); 127 } 128 129 return parse_ini_file($this->callbackConfigFile); 130 } 131 132 /** 133 * creates the xsl stylesheet 134 * 135 * @return DOMDocument 136 * @todo fix selection of uri 137 */ 138 // @codeCoverageIgnoreStart 139 protected function createXSLStylesheet() 140 { 141 $uris = stubFactory::getResourceURIs('xsl/master.xsl'); 142 return DOMDocument::load($uris[0]); 143 } 144 // @codeCoverageIgnoreEnd 145 146 /** 147 * creates the skin document 148 * 149 * @param string $skin 150 * @return DOMDocument 151 */ 152 // @codeCoverageIgnoreStart 153 protected function createXMLSkinDocument($skin) 154 { 155 return DOMDocument::load(stubConfig::getPagePath() . '/skin/' . $skin . '.xml'); 156 } 157 // @codeCoverageIgnoreEnd 36 public function generate(stubSession $session, stubPage $page); 158 37 } 159 38 ?> trunk/src/main/php/net/stubbles/websites/xml/stubXMLProcessor.php
r1426 r1429 12 12 'net::stubbles::util::stubRegistry', 13 13 'net::stubbles::websites::processors::stubAbstractPageProcessor', 14 'net::stubbles::websites::xml::skin::stub SkinGenerator',14 'net::stubbles::websites::xml::skin::stubDefaultSkinGenerator', 15 15 'net::stubbles::xml::stubXMLStreamWriterFactory', 16 16 'net::stubbles::xml::serializer::stubXMLSerializer' … … 122 122 protected function createSkinGenerator() 123 123 { 124 return new stub SkinGenerator();124 return new stubDefaultSkinGenerator(); 125 125 } 126 126 // @codeCoverageIgnoreEnd trunk/src/test/php/net/stubbles/websites/WebsitesTestSuite.php
r1426 r1429 52 52 53 53 // xml skin 54 $suite->addTestFile($dir . '/xml/skin/stub SkinGeneratorTestCase.php');54 $suite->addTestFile($dir . '/xml/skin/stubDefaultSkinGeneratorTestCase.php'); 55 55 56 56 // xml generator trunk/src/test/php/net/stubbles/websites/xml/skin/stubDefaultSkinGeneratorTestCase.php
r1425 r1429 1 1 <?php 2 2 /** 3 * Tests for net::stubbles::websites::xml::skin::stub SkinGenerator.3 * Tests for net::stubbles::websites::xml::skin::stubDefaultSkinGenerator. 4 4 * 5 5 * @author Frank Kleine <mikey@stubbles.net> … … 7 7 * @subpackage websites_xml_skin_test 8 8 */ 9 stubClassLoader::load('net::stubbles::websites::xml::skin::stub SkinGenerator');9 stubClassLoader::load('net::stubbles::websites::xml::skin::stubDefaultSkinGenerator'); 10 10 /** 11 11 * Helper class to access a protected method. … … 14 14 * @subpackage websites_xml_skin_test 15 15 */ 16 class Teststub SkinGenerator extends stubSkinGenerator16 class TeststubDefaultSkinGenerator extends stubDefaultSkinGenerator 17 17 { 18 18 /** … … 27 27 } 28 28 /** 29 * Tests for net::stubbles::websites::xml::skin::stub SkinGenerator.29 * Tests for net::stubbles::websites::xml::skin::stubDefaultSkinGenerator. 30 30 * 31 31 * @package stubbles 32 32 * @subpackage websites_xml_skin_test 33 33 */ 34 class stub SkinGeneratorTestCase extends PHPUnit_Framework_TestCase34 class stubDefaultSkinGeneratorTestCase extends PHPUnit_Framework_TestCase 35 35 { 36 36 /** 37 37 * instance to test 38 38 * 39 * @var stub SkinGenerator39 * @var stubDefaultSkinGenerator 40 40 */ 41 41 protected $skinGenerator; … … 82 82 public function setUp() 83 83 { 84 $this->skinGenerator = $this->getMock('stub SkinGenerator',84 $this->skinGenerator = $this->getMock('stubDefaultSkinGenerator', 85 85 array('createXSLProcessor', 86 86 'getCallbackList', … … 141 141 { 142 142 $this->page->setProperty('skin', 'another'); 143 $this->page->setProperty('name', 'foo'); 143 144 $this->skinGenerator->expects($this->any())->method('getCallbackList')->will($this->returnValue(array())); 144 145 $this->skinGenerator->expects($this->once()) … … 147 148 ->will($this->returnValue($this->getMock('DOMDocument'))); 148 149 $this->assertSame($this->resultDomDocument, $this->skinGenerator->generate($this->mockSession, $this->page)); 150 $this->assertEquals(md5('anotherfooen_EN'), $this->skinGenerator->getSkinKey($this->mockSession, $this->page)); 149 151 } 150 152 … … 157 159 { 158 160 stubRegistry::setConfig('net.stubbles.language', 'foo'); 161 $this->page->setProperty('name', 'bar'); 159 162 $this->skinGenerator->expects($this->any())->method('getCallbackList')->will($this->returnValue(array())); 160 163 $this->skinGenerator->expects($this->any()) … … 163 166 $this->mockXSLProcessor->expects($this->at(2))->method('setParameter')->with($this->equalTo(''), $this->equalTo('lang'), $this->equalTo('foo')); 164 167 $this->assertSame($this->resultDomDocument, $this->skinGenerator->generate($this->mockSession, $this->page)); 168 $this->assertEquals(md5('defaultbarfoo'), $this->skinGenerator->getSkinKey($this->mockSession, $this->page)); 165 169 } 166 170 … … 173 177 { 174 178 $this->page->setProperty('language', 'bar'); 179 $this->page->setProperty('name', 'baz'); 175 180 stubRegistry::setConfig('net.stubbles.language', 'foo'); 176 181 $this->skinGenerator->expects($this->any())->method('getCallbackList')->will($this->returnValue(array())); … … 180 185 $this->mockXSLProcessor->expects($this->at(2))->method('setParameter')->with($this->equalTo(''), $this->equalTo('lang'), $this->equalTo('bar')); 181 186 $this->assertSame($this->resultDomDocument, $this->skinGenerator->generate($this->mockSession, $this->page)); 187 $this->assertEquals(md5('defaultbazbar'), $this->skinGenerator->getSkinKey($this->mockSession, $this->page)); 182 188 } 183 189 … … 193 199 ->method('createXMLSkinDocument') 194 200 ->will($this->returnValue($this->getMock('DOMDocument'))); 195 $this->mockSession->expects($this-> once())->method('hasValue')->will($this->returnValue(true));196 $this->mockSession->expects($this-> once())->method('getValue')->will($this->returnValue('baz'));201 $this->mockSession->expects($this->exactly(2))->method('hasValue')->will($this->returnValue(true)); 202 $this->mockSession->expects($this->exactly(2))->method('getValue')->will($this->returnValue('baz')); 197 203 $this->page->setProperty('language', 'bar'); 204 $this->page->setProperty('name', 'baz'); 198 205 stubRegistry::setConfig('net.stubbles.language', 'foo'); 199 206 $this->mockXSLProcessor->expects($this->at(2))->method('setParameter')->with($this->equalTo(''), $this->equalTo('lang'), $this->equalTo('baz')); 200 207 $this->assertSame($this->resultDomDocument, $this->skinGenerator->generate($this->mockSession, $this->page)); 208 $this->assertEquals(md5('defaultbazbaz'), $this->skinGenerator->getSkinKey($this->mockSession, $this->page)); 201 209 } 202 210 … … 220 228 public function callbacks() 221 229 { 222 $skinGenerator = new Teststub SkinGenerator();230 $skinGenerator = new TeststubDefaultSkinGenerator(); 223 231 $this->assertEquals(array('image' => 'net::stubbles::xml::xsl::util::stubXSLImageDimensions'), $skinGenerator->callGetCallbackList()); 224 232 } … … 232 240 public function callbacksConfigurationFileMissing() 233 241 { 234 $skinGenerator = new Teststub SkinGenerator();242 $skinGenerator = new TeststubDefaultSkinGenerator(); 235 243 $skinGenerator->setCallbackConfigFile(dirname(__FILE__) . '/doesNotExist.ini'); 236 244 $skinGenerator->callGetCallbackList();
