Changeset 1426

Show
Ignore:
Timestamp:
03/14/08 17:53:51 (4 months ago)
Author:
mikey
Message:

get rid of stubXMLResponse

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/config/xml/interceptors.xml

    r1419 r1426  
    88  </preInterceptors> 
    99  <postInterceptors> 
    10     <postInterceptor type="net::stubbles::websites::xml::stubShowLastXMLInterceptor" /> 
    1110  </postInterceptors> 
    1211</xj:configuration> 
  • trunk/examples/config/xml/interceptors-xml.xml

    r1419 r1426  
    1010  </preInterceptors> 
    1111  <postInterceptors> 
    12     <postInterceptor type="net::stubbles::websites::xml::stubShowLastXMLInterceptor"/> 
    1312  </postInterceptors> 
    1413</xj:configuration> 
  • trunk/src/main/php/net/stubbles/websites/xml/stubShowLastXMLInterceptor.php

    r1360 r1426  
    11<?php 
    22/** 
    3  * Interceptor that stores the last XML tree in the session and 
    4  * is able to display it. 
    5  * 
    6  * This interceptor must be added as pre-interceptor AND 
    7  * post-interceptor. In the post-interceptor queue, it should 
    8  * be added prior to the XSL transformation processor. 
    9  * 
    10  * In the pre-interceptor queue, it cancels the request in case 
    11  * the request param showLastRequestXML is set and the session 
    12  * is not new. 
     3 * Preinterceptor that is able to display the last created XML result document. 
    134 * 
    145 * @author      Frank Kleine <mikey@stubbles.net> 
     
    178 * @subpackage  websites_xml 
    189 */ 
    19 stubClassLoader::load('net::stubbles::ipo::interceptors::stubPreInterceptor', 
    20                       'net::stubbles::websites::xml::stubXMLAbstractPostInterceptor' 
    21 ); 
     10stubClassLoader::load('net::stubbles::ipo::interceptors::stubPreInterceptor'); 
    2211/** 
    23  * Interceptor that stores the last XML tree in the session and 
    24  * is able to display it. 
     12 * Preinterceptor that is able to display the last created XML result document. 
    2513 * 
    26  * This interceptor must be added as pre-interceptor AND 
    27  * post-interceptor. In the post-interceptor queue, it should 
    28  * be added prior to the XSL transformation processor. 
    29  * 
    30  * In the pre-interceptor queue, it cancels the request in case 
    31  * the request param showLastRequestXML is set and the session 
    32  * is not new. 
     14 * This interceptor cancels the request in case the request param 
     15 * showLastRequestXML is set and the session is not new. 
    3316 * 
    3417 * @package     stubbles 
    3518 * @subpackage  websites_xml 
    3619 */ 
    37 class stubShowLastXMLInterceptor extends stubXMLAbstractPostInterceptor implements stubPreInterceptor 
     20class stubShowLastXMLInterceptor extends stubBaseObject implements stubPreInterceptor 
    3821{ 
    39     /** 
    40      * key with which last xml is stored in session 
    41      */ 
    42     const SESSION_KEY = 'net.stubbles.websites.lastRequestResponseData'; 
    43  
    4422    /** 
    4523     * does the preprocessing stuff 
     
    5331        if ($request->hasValue('showLastRequestXML') === true && $session->isNew() === false) { 
    5432            $response->addHeader('Content-type', 'text/xml'); 
    55             $response->write($session->getValue(self::SESSION_KEY)); 
     33            $response->write($session->getValue('net.stubbles.websites.lastRequestResponseData')); 
    5634            $request->cancel(); 
    5735        } 
    5836    } 
    59  
    60     /** 
    61      * does the postprocessing stuff 
    62      * 
    63      * @param  stubRequest      $request   access to request data 
    64      * @param  stubSession      $session   access to session data 
    65      * @param  stubXMLResponse  $response  access to response data 
    66      */ 
    67     protected function doPostProcess(stubRequest $request, stubSession $session, stubXMLResponse $response) 
    68     { 
    69         $xmlStreamWriter = $response->getXMLStreamWriter(); 
    70         if ($xmlStreamWriter->isFinished() === false) { 
    71             $xmlStreamWriter->writeEndElement(); 
    72         } 
    73          
    74         $session->putValue(self::SESSION_KEY, $xmlStreamWriter->asXML()); 
    75     } 
    7637} 
    7738?> 
  • trunk/src/main/php/net/stubbles/websites/xml/stubXMLProcessor.php

    r1425 r1426  
    1313                      'net::stubbles::websites::processors::stubAbstractPageProcessor', 
    1414                      'net::stubbles::websites::xml::skin::stubSkinGenerator', 
    15                       'net::stubbles::websites::xml::stubXMLResponse', 
    1615                      'net::stubbles::xml::stubXMLStreamWriterFactory', 
    1716                      'net::stubbles::xml::serializer::stubXMLSerializer' 
     
    4241    public function __construct(stubRequest $request, stubSession $session, stubResponse $response, stubPageFactory $pageFactory) 
    4342    { 
    44         $response = new stubXMLResponse($response); 
    4543        parent::__construct($request, $session, $response, $pageFactory); 
    4644        $this->pageDirPrefix = 'conf/'; 
     
    7674        $injector        = $binder->getInjector(); 
    7775        $xmlStreamWriter = $this->createXMLStreamWriter(); 
    78         $this->response->setPage($page); 
    7976        $xmlStreamWriter->writeStartElement('document'); 
    8077        $xmlStreamWriter->writeAttribute('page', $pageName); 
     
    8683 
    8784        $xmlStreamWriter->writeEndElement(); // end document 
    88         $this->response->setXMLStreamWriter($xmlStreamWriter); 
    8985        $xslProcessor = $this->createXSLProcessor(); 
    9086        $xslProcessor->importXSLStylesheet($this->createSkinGenerator()->generate($this->session, $page)); 
    9187        $xslProcessor->setXMLDocument($xmlStreamWriter->asDOM()); 
     88        $this->session->putValue('net.stubbles.websites.lastRequestResponseData', $xmlStreamWriter->asXML()); 
    9289        $this->response->replaceData(str_replace(' xmlns=""', '', preg_replace('/ xml:base="(.*)"/U', '', $xslProcessor->transformToXML()))); 
    9390    } 
  • trunk/src/test/php/net/stubbles/integration/InterceptorTestCase.php

    r1419 r1426  
    3939        $this->assertType('stubShowLastXMLInterceptor', $preInterceptors[0]); 
    4040        $postInterceptors = $interceptorXJConfInitializer->getPostInterceptors(); 
    41         $this->assertType('stubShowLastXMLInterceptor', $postInterceptors[0]); 
     41        $this->assertEquals(array(), $postInterceptors); 
    4242         
    4343        // cached 
     
    4646        $this->assertType('stubShowLastXMLInterceptor', $preInterceptors[0]); 
    4747        $postInterceptors = $interceptorXJConfInitializer->getPostInterceptors(); 
    48         $this->assertType('stubShowLastXMLInterceptor', $postInterceptors[0]); 
     48        $this->assertEquals(array(), $postInterceptors); 
    4949    } 
    5050} 
  • trunk/src/test/php/net/stubbles/websites/WebsitesTestSuite.php

    r1424 r1426  
    5050        $suite->addTestFile($dir . '/xml/stubShowLastXMLInterceptorTestCase.php'); 
    5151        $suite->addTestFile($dir . '/xml/stubXMLProcessorTestCase.php'); 
    52         $suite->addTestFile($dir . '/xml/stubXMLResponseTestCase.php'); 
    5352 
    5453        // xml skin 
  • trunk/src/test/php/net/stubbles/websites/xml/stubShowLastXMLInterceptorTestCase.php

    r1360 r1426  
    9494        $this->showLastXMLPreInterceptor->preProcess($this->mockRequest, $this->mockSession, $this->mockResponse); 
    9595    } 
    96  
    97     /** 
    98      * assure that postProcess() puts correct data into session 
    99      * 
    100      * @test 
    101      * @expectedException  stubRuntimeException 
    102      */ 
    103     public function postProcessNoXMLResponse() 
    104     { 
    105         $this->showLastXMLPreInterceptor->postProcess($this->mockRequest, $this->mockSession, $this->mockResponse); 
    106     } 
    107  
    108     /** 
    109      * assure that postProcess() puts correct data into session 
    110      * 
    111      * @test 
    112      */ 
    113     public function postProcessUnfinishedStreamWriter() 
    114     { 
    115         $mockXMLStreamWriter = $this->getMock('stubXMLStreamWriter'); 
    116         $mockXMLStreamWriter->expects($this->once()) 
    117                             ->method('isFinished') 
    118                             ->will($this->returnValue(false)); 
    119         $mockXMLStreamWriter->expects($this->once()) 
    120                             ->method('writeEndElement'); 
    121         $mockXMLStreamWriter->expects($this->once()) 
    122                             ->method('asXML') 
    123                             ->will($this->returnValue('foo')); 
    124         $xmlResponse = new stubXMLResponse($this->mockResponse); 
    125         $xmlResponse->setXMLStreamWriter($mockXMLStreamWriter); 
    126         $this->mockSession->expects($this->once())->method('putValue')->with($this->equalTo(stubShowLastXMLInterceptor::SESSION_KEY), $this->equalTo('foo')); 
    127         $this->showLastXMLPreInterceptor->postProcess($this->mockRequest, $this->mockSession, $xmlResponse); 
    128     } 
    129  
    130     /** 
    131      * assure that postProcess() puts correct data into session 
    132      * 
    133      * @test 
    134      */ 
    135     public function postProcessFinishedStreamWriter() 
    136     { 
    137         $mockXMLStreamWriter = $this->getMock('stubXMLStreamWriter'); 
    138         $mockXMLStreamWriter->expects($this->once()) 
    139                             ->method('isFinished') 
    140                             ->will($this->returnValue(true)); 
    141         $mockXMLStreamWriter->expects($this->never()) 
    142                             ->method('writeEndElement'); 
    143         $mockXMLStreamWriter->expects($this->once()) 
    144                             ->method('asXML') 
    145                             ->will($this->returnValue('foo')); 
    146         $xmlResponse = new stubXMLResponse($this->mockResponse); 
    147         $xmlResponse->setXMLStreamWriter($mockXMLStreamWriter); 
    148         $this->mockSession->expects($this->once())->method('putValue')->with($this->equalTo(stubShowLastXMLInterceptor::SESSION_KEY), $this->equalTo('foo')); 
    149         $this->showLastXMLPreInterceptor->postProcess($this->mockRequest, $this->mockSession, $xmlResponse); 
    150     } 
    15196} 
    15297?> 
  • trunk/src/test/php/net/stubbles/websites/xml/stubXMLProcessorTestCase.php

    r1423 r1426  
    157157        $domDocument0->createElement('bar', 'foo'); 
    158158        $this->mockXMLStreamWriter->expects($this->any())->method('asDOM')->will($this->returnValue($domDocument0)); 
     159        $this->mockXMLStreamWriter->expects($this->any())->method('asXML')->will($this->returnValue('<bar>foo</bar>')); 
     160        $this->mockSession->expects($this->at(1))->method('putValue')->with($this->equalTo('net.stubbles.websites.lastRequestResponseData'), $this->equalTo('<bar>foo</bar>')); 
    159161        $this->mockResponse->expects($this->once())->method('replaceData')->with($this->equalTo('<html><head><title>Test</title></head><body><p>Hello world.</p></body></html>')); 
    160162        $this->xmlProcessor->process(); 
     
    194196        $domDocument0->createElement('bar', 'foo'); 
    195197        $this->mockXMLStreamWriter->expects($this->any())->method('asDOM')->will($this->returnValue($domDocument0)); 
     198        $this->mockXMLStreamWriter->expects($this->any())->method('asXML')->will($this->returnValue('<bar>foo</bar>')); 
     199        $this->mockSession->expects($this->at(1))->method('putValue')->with($this->equalTo('net.stubbles.websites.lastRequestResponseData'), $this->equalTo('<bar>foo</bar>')); 
    196200        $this->mockResponse->expects($this->once())->method('replaceData')->with($this->equalTo('<html><head><title>Test</title></head><body><p>Hello world.</p></body></html>')); 
    197201        $this->xmlProcessor->process(); 
     
    232236        $domDocument0->createElement('bar', 'foo'); 
    233237        $this->mockXMLStreamWriter->expects($this->any())->method('asDOM')->will($this->returnValue($domDocument0)); 
     238        $this->mockXMLStreamWriter->expects($this->any())->method('asXML')->will($this->returnValue('<bar>foo</bar>')); 
     239        $this->mockSession->expects($this->at(1))->method('putValue')->with($this->equalTo('net.stubbles.websites.lastRequestResponseData'), $this->equalTo('<bar>foo</bar>')); 
    234240        $this->mockResponse->expects($this->once())->method('replaceData')->with($this->equalTo('<html><head><title>Test</title></head><body><p>Hello world.</p></body></html>')); 
    235241        $this->xmlProcessor->process();