Changeset 342

Show
Ignore:
Timestamp:
03/07/07 11:13:52 (1 year ago)
Author:
mikey
Message:

renamed net.stubbles.websites.xml.stubXMLPagePostInterceptor to net.stubbles.websites.xml.stubXMLPostInterceptor
added test for net.stubbles.websites.xml.stubXMLPostInterceptor

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/docroot/xml.php

    r340 r342  
    33require '../lib/stubbles.php'; 
    44stubClassLoader::load('net.stubbles.websites.xml.stubXMLProcessor', 
    5                       'net.stubbles.websites.xml.stubXMLPagePostInterceptor', 
     5                      'net.stubbles.websites.xml.stubXMLPostInterceptor', 
    66                      'net.stubbles.websites.xml.stubXMLPreInterceptor', 
    77                      'net.stubbles.websites.stubXJConfPageFactory', 
     
    4848        $pageFactory = new stubXJConfPageFactory(stubXJConfLoader::getInstance()); 
    4949        $processor   = new stubXMLProcessor($request, $session, $response, $pageFactory); 
    50         $postInterceptor = new stubXMLPagePostInterceptor(); 
     50        $postInterceptor = new stubXMLPostInterceptor(); 
    5151        $response = $processor->process()->getResponse(); 
    5252        $postInterceptor->setSession($session); 
  • trunk/src/main/php/net/stubbles/websites/xml/stubXMLPostInterceptor.php

    r340 r342  
    2222 * @package     stubbles 
    2323 * @subpackage  websites_xml 
    24  * @Inject(stubResponse) 
     24 * @Inject(stubSession:stubResponse) 
    2525 * @todo        make <xsl:import href="copy.xsl"/> work if loaded from a star file 
    2626 *              in master.xsl and masterXInclude.xsl 
    2727 * @todo        clean the transformation result: xml:base, xml declaration, whitespace 
    2828 */ 
    29 class stubXMLPagePostInterceptor extends stubBaseObject implements stubPostInterceptor 
     29class stubXMLPostInterceptor extends stubBaseObject implements stubPostInterceptor 
    3030{ 
    3131    /** 
     
    7777    public function postProcess() 
    7878    { 
     79        // does not work with another response type 
     80        if (($this->response instanceof stubXMLResponse) == false) { 
     81            return false; 
     82        } 
     83         
    7984        // first we create the xsl with the master.xsl 
    80         $xslProcessor = new stubXSLProcessor(); 
    81         $image = new stubXSLImageDimensions(stubXMLStreamWriterFactory::createAsAvailable()); 
    82         $image->setPath(getcwd()); 
    83         $xslProcessor->registerCallback('image', $image); 
    84         $xslProcessor->importXSLStylesheet(DOMDocument::load(stubFactory::getResourceURI('xsl/master.xsl'))); 
     85        $xslProcessor = $this->createXSLProcessor(); 
     86        $xslProcessor->registerCallback('image', $this->createImageCallback()); 
     87        $xslProcessor->importXSLStylesheet($this->createXSLStylesheet()); 
    8588        $page = $this->response->getPage(); 
    8689        $xslProcessor->setParameter('', 'page', $page->getProperty('name')); 
     
    9699        $xslProcessor->setParameter('', 'lang', $language); 
    97100        // use same xsl processor for the xincludes 
    98         stubXMLXIncludeStreamWrapper::setXSLProcessor($xslProcessor); 
     101        $this->setXIncludeProcessor($xslProcessor); 
    99102         
    100         if ($page->hasProperty('skin') == true) { 
    101             $skin = $page->getProperty('skin'); 
    102         } else { 
    103             $skin = 'default'; 
    104         } 
    105         $xslProcessor->setXMLDocument(DOMDocument::load(stubConfig::getConfigPath() . '/xml/pages/skin/' . $skin . '.xml')); 
     103        $skin = (($page->hasProperty('skin') == true) ? ($page->getProperty('skin')) : ('default')); 
     104        $xslProcessor->setXMLDocument($this->createXMLSkinDocument($skin)); 
    106105        $resultXSL = $xslProcessor->transformToDoc(); 
    107106        $resultXSL->xinclude(); 
    108107         
    109108        // now we use the created xsl to transform the xml document created by the application 
    110         $xslProcessor = new stubXSLProcessor(); 
     109        $xslProcessor = $this->createXSLProcessor(); 
    111110        $xslProcessor->importXSLStylesheet($resultXSL); 
    112111        $xslProcessor->setXMLDocument(DOMDocument::loadXML($this->response->getData())); 
    113112        $this->response->replaceData($xslProcessor->transformToDoc()->saveXML()); 
     113        return true; 
     114    } 
     115     
     116    /** 
     117     * use same xsl processor for the xincludes 
     118     * 
     119     * @param  stubXSLProcessor  $xslProcessor 
     120     */ 
     121    protected function setXIncludeProcessor($xslProcessor) 
     122    { 
     123        stubXMLXIncludeStreamWrapper::setXSLProcessor($xslProcessor); 
     124    } 
     125     
     126    /** 
     127     * creates a stubXSLProcessor instance 
     128     * 
     129     * @return  stubXSLProcessor 
     130     */ 
     131    protected function createXSLProcessor() 
     132    { 
     133        $xslProcessor = new stubXSLProcessor(); 
     134        return $xslProcessor; 
     135    } 
     136     
     137    /** 
     138     * creates a stubXSLImageDimensions  
     139     * 
     140     * @return  stubXSLImageDimensions 
     141     */ 
     142    protected function createImageCallback() 
     143    { 
     144        $image = new stubXSLImageDimensions(stubXMLStreamWriterFactory::createAsAvailable()); 
     145        $image->setPath(getcwd()); 
     146        return $image; 
     147    } 
     148     
     149    /** 
     150     * creates the xsl stylesheet 
     151     * 
     152     * @return  DOMDocument 
     153     */ 
     154    protected function createXSLStylesheet() 
     155    { 
     156        return DOMDocument::load(stubFactory::getResourceURI('xsl/master.xsl')); 
     157    } 
     158     
     159    /** 
     160     * creates the skin document 
     161     * 
     162     * @return  DOMDocument 
     163     */ 
     164    protected function createXMLSkinDocument($skin) 
     165    { 
     166        return DOMDocument::load(stubConfig::getConfigPath() . '/xml/pages/skin/' . $skin . '.xml'); 
    114167    } 
    115168} 
  • trunk/src/test/php/net/stubbles/websites/WebsitesTestSuite.php

    r292 r342  
    3333         
    3434        // xml tests 
     35        $this->addTestFile($dir . '/xml/stubXMLPostInterceptorTestCase.php'); 
    3536        $this->addTestFile($dir . '/xml/stubXMLProcessorTestCase.php'); 
    3637        $this->addTestFile($dir . '/xml/stubXMLResponseTestCase.php');