Changeset 878
- Timestamp:
- 08/22/07 17:57:00 (1 year ago)
- Files:
-
- trunk/build/stubbles/build.xml (modified) (1 diff)
- trunk/config/xsl-callbacks.ini (added)
- trunk/examples/config/xsl-callbacks.ini (added)
- trunk/src/main/php/net/stubbles/websites/xml/stubXMLPostInterceptor.php (modified) (5 diffs)
- trunk/src/test/php/net/stubbles/websites/xml/stubXMLPostInterceptorTestCase.php (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/build/stubbles/build.xml
r859 r878 39 39 <mkdir dir="${build.src.dir}/cache/xml/elements" /> 40 40 41 <mkdir dir="${build.src.dir}/config" /> 42 <copy file="${project.basedir}/../../config/xsl-callbacks.ini" tofile="${build.src.dir}/config/xsl-callbacks-dist.ini" /> 43 41 44 <mkdir dir="${build.src.dir}/config/errors" /> 42 45 <copy file="${project.basedir}/../../config/errors/500.html" tofile="${build.src.dir}/config/errors/500-dist.html" /> trunk/src/main/php/net/stubbles/websites/xml/stubXMLPostInterceptor.php
r842 r878 13 13 'net.stubbles.util.stubRegistry', 14 14 'net.stubbles.xml.xsl.stubXSLProcessor', 15 'net.stubbles.xml.xsl.util.stubXSLImageDimensions',16 15 'net.stubbles.xml.stubXMLXIncludeStreamWrapper', 17 16 'net.stubbles.xml.stubXMLStreamWriterFactory' … … 19 18 /** 20 19 * Post interceptor that transforms the xml result document into html. 20 * 21 * When using this post interceptor please make sure that within the registry 22 * a value accessible with key 'net.stubbles.ioc.stubBinder' is configured and 23 * an instance of net.stubbles.ioc.stubBinder. If the pre interceptor 24 * net.stubbles.ioc.stubIOCPreInterceptor is configured as pre interceptor this 25 * one will put a stubBinder instance into the registry. 26 * Please make sure as well that a file named xsl-callbacks.ini resides in the 27 * base config directory configured in stubConfig::getConfigPath(). 21 28 * 22 29 * @package stubbles … … 39 46 * does the postprocessing stuff 40 47 * 41 * @param stubRequest $request access to request data 42 * @param stubSession $session access to session data 43 * @param stubResponse $response access to response data 48 * @param stubRequest $request access to request data 49 * @param stubSession $session access to session data 50 * @param stubResponse $response access to response data 51 * @throws stubException 44 52 */ 45 53 public function postProcess(stubRequest $request, stubSession $session, stubResponse $response) 46 54 { 47 55 // does not work with another response type 48 if (($response instanceof stubXMLResponse) == false) {56 if (($response instanceof stubXMLResponse) === false) { 49 57 return false; 50 58 } 51 59 52 // first we create the xsl with the master.xsl 60 $binder = stubRegistry::get('net.stubbles.ioc.stubBinder'); 61 if (($binder instanceof stubBinder) === false) { 62 throw new stubException('No instance of net.stubbles.ioc.stubBinder in registry.'); 63 } 64 65 $binder->bind('stubXMLStreamWriter')->to(stubXMLStreamWriterFactory::getFqClassNameAsAvailable()); 66 $binder->bindConstant()->named('imagePath')->to(getcwd()); 53 67 $xslProcessor = $this->createXSLProcessor(); 54 $xslProcessor->registerCallback('image', $this->createImageCallback()); 68 $injector = $binder->getInjector(); 69 foreach ($this->getCallbackList() as $callbackName => $callbackClass) { 70 $xslProcessor->registerCallback($callbackName, $injector->getInstance($callbackClass)); 71 } 72 55 73 $xslProcessor->importXSLStylesheet($this->createXSLStylesheet()); 56 74 $page = $response->getPage(); … … 65 83 $language = 'en_EN'; 66 84 } 85 67 86 $xslProcessor->setParameter('', 'lang', $language); 68 // use same xsl processor for thexincludes87 // use same xsl processor for xincludes 69 88 $this->setXIncludeProcessor($xslProcessor); 70 89 90 // first we create the xsl with applying the master.xsl on the skin and the page 71 91 $skin = (($page->hasProperty('skin') === true) ? ($page->getProperty('skin')) : ('default')); 72 92 $xslProcessor->setXMLDocument($this->createXMLSkinDocument($skin)); 73 93 $resultXSL = $xslProcessor->transformToDoc(); 74 94 @$resultXSL->xinclude(); 75 95 76 96 // now we use the created xsl to transform the xml document created by the application 77 97 $xslProcessor = $this->createXSLProcessor(); … … 106 126 * creates a stubXSLImageDimensions 107 127 * 108 * @return stubXSLImageDimensions 128 * @return array 129 * @throws stubException 109 130 */ 110 protected function createImageCallback()131 protected function getCallbackList() 111 132 { 112 $image = new stubXSLImageDimensions(stubXMLStreamWriterFactory::createAsAvailable()); 113 $image->setPath(getcwd()); 114 return $image; 133 $iniFile = stubConfig::getConfigPath() . '/xsl-callbacks.ini'; 134 if (file_exists($iniFile) === false) { 135 throw new stubException('Configuration file ' . $iniFile . ' for XSL callback configuration is missing.'); 136 } 137 138 return parse_ini_file($iniFile); 115 139 } 116 140 trunk/src/test/php/net/stubbles/websites/xml/stubXMLPostInterceptorTestCase.php
r840 r878 12 12 Mock::generate('stubSession'); 13 13 Mock::generate('stubXSLProcessor'); 14 Mock::generate('stubObject'); 15 Mock::generatePartial('stubXMLPostInterceptor', 'stubTestXMLPostInterceptor', array('setXIncludeProcessor', 'createXSLProcessor', 'createImageCallback', 'createXSLStylesheet', 'createXMLSkinDocument')); 14 Mock::generatePartial('stubXMLPostInterceptor', 'stubTestXMLPostInterceptor', array('setXIncludeProcessor', 'createXSLProcessor', 'getCallbackList', 'createXSLStylesheet', 'createXMLSkinDocument')); 16 15 class TestDOMDocument extends DOMDocument 17 16 { … … 74 73 */ 75 74 protected $mockImageCallback; 76 75 77 76 /** 78 77 * set up test environment … … 94 93 $this->mockXSLProcessor->setReturnValue('transformToXML', '<html><head><title>Test</title></head><body><p>Hello world.</p></body></html>'); 95 94 $this->xmlPostInterceptor->setReturnValue('createXSLProcessor', $this->mockXSLProcessor); 96 $this->mockImageCallback = new MockstubObject(); 97 $this->xmlPostInterceptor->setReturnValue('createImageCallback', $this->mockImageCallback); 95 $this->xmlPostInterceptor->setReturnValue('getCallbackList', array()); 98 96 if (stubRegistry::hasConfig('net.stubbles.language') == true) { 99 97 stubRegistry::setConfig('net.stubbles.language', null); 100 98 } 99 100 stubRegistry::set('net.stubbles.ioc.stubBinder', new stubBinder()); 101 101 } 102 102 103 /** 104 * clear test environment 105 */ 106 public function tearDown() 107 { 108 stubRegistry::remove('net.stubbles.ioc.stubBinder'); 109 } 110 103 111 /** 104 112 * assure that a wrong response does not trigger any action … … 108 116 $this->assertFalse($this->xmlPostInterceptor->postProcess($this->mockRequest, $this->mockSession, $this->mockResponse)); 109 117 } 110 118 111 119 /** 112 120 * assure that a correct response works as expected … … 121 129 $this->assertTrue($this->xmlPostInterceptor->postProcess($this->mockRequest, $this->mockSession, $this->xmlResponse)); 122 130 } 123 131 124 132 /** 125 133 * assure that another skin will be used … … 131 139 $this->assertTrue($this->xmlPostInterceptor->postProcess($this->mockRequest, $this->mockSession, $this->xmlResponse)); 132 140 } 133 141 134 142 /** 135 143 * assure that the language value from the registry is taken … … 141 149 $this->assertTrue($this->xmlPostInterceptor->postProcess($this->mockRequest, $this->mockSession, $this->xmlResponse)); 142 150 } 143 151 144 152 /** 145 153 * assure that the language value from the page is taken … … 152 160 $this->assertTrue($this->xmlPostInterceptor->postProcess($this->mockRequest, $this->mockSession, $this->xmlResponse)); 153 161 } 154 162 155 163 /** 156 164 * assure that the language value from the session is taken … … 165 173 $this->assertTrue($this->xmlPostInterceptor->postProcess($this->mockRequest, $this->mockSession, $this->xmlResponse)); 166 174 } 175 176 /** 177 * assure that missing binder triggers an exception 178 */ 179 public function testWithoutBinderInRegistry() 180 { 181 stubRegistry::remove('net.stubbles.ioc.stubBinder'); 182 $this->expectException('stubException'); 183 $this->xmlPostInterceptor->postProcess($this->mockRequest, $this->mockSession, $this->xmlResponse); 184 } 167 185 } 168 186 ?>
