Changeset 342
- Timestamp:
- 03/07/07 11:13:52 (1 year ago)
- Files:
-
- trunk/docroot/xml.php (modified) (2 diffs)
- trunk/src/main/php/net/stubbles/websites/xml/stubXMLPostInterceptor.php (moved) (moved from trunk/src/main/php/net/stubbles/websites/xml/stubXMLPagePostInterceptor.php) (3 diffs)
- trunk/src/test/php/net/stubbles/websites/WebsitesTestSuite.php (modified) (1 diff)
- trunk/src/test/php/net/stubbles/websites/xml/stubXMLPostInterceptorTestCase.php (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/docroot/xml.php
r340 r342 3 3 require '../lib/stubbles.php'; 4 4 stubClassLoader::load('net.stubbles.websites.xml.stubXMLProcessor', 5 'net.stubbles.websites.xml.stubXMLP agePostInterceptor',5 'net.stubbles.websites.xml.stubXMLPostInterceptor', 6 6 'net.stubbles.websites.xml.stubXMLPreInterceptor', 7 7 'net.stubbles.websites.stubXJConfPageFactory', … … 48 48 $pageFactory = new stubXJConfPageFactory(stubXJConfLoader::getInstance()); 49 49 $processor = new stubXMLProcessor($request, $session, $response, $pageFactory); 50 $postInterceptor = new stubXMLP agePostInterceptor();50 $postInterceptor = new stubXMLPostInterceptor(); 51 51 $response = $processor->process()->getResponse(); 52 52 $postInterceptor->setSession($session); trunk/src/main/php/net/stubbles/websites/xml/stubXMLPostInterceptor.php
r340 r342 22 22 * @package stubbles 23 23 * @subpackage websites_xml 24 * @Inject(stub Response)24 * @Inject(stubSession:stubResponse) 25 25 * @todo make <xsl:import href="copy.xsl"/> work if loaded from a star file 26 26 * in master.xsl and masterXInclude.xsl 27 27 * @todo clean the transformation result: xml:base, xml declaration, whitespace 28 28 */ 29 class stubXMLP agePostInterceptor extends stubBaseObject implements stubPostInterceptor29 class stubXMLPostInterceptor extends stubBaseObject implements stubPostInterceptor 30 30 { 31 31 /** … … 77 77 public function postProcess() 78 78 { 79 // does not work with another response type 80 if (($this->response instanceof stubXMLResponse) == false) { 81 return false; 82 } 83 79 84 // 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()); 85 88 $page = $this->response->getPage(); 86 89 $xslProcessor->setParameter('', 'page', $page->getProperty('name')); … … 96 99 $xslProcessor->setParameter('', 'lang', $language); 97 100 // use same xsl processor for the xincludes 98 stubXMLXIncludeStreamWrapper::setXSLProcessor($xslProcessor);101 $this->setXIncludeProcessor($xslProcessor); 99 102 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)); 106 105 $resultXSL = $xslProcessor->transformToDoc(); 107 106 $resultXSL->xinclude(); 108 107 109 108 // now we use the created xsl to transform the xml document created by the application 110 $xslProcessor = new stubXSLProcessor();109 $xslProcessor = $this->createXSLProcessor(); 111 110 $xslProcessor->importXSLStylesheet($resultXSL); 112 111 $xslProcessor->setXMLDocument(DOMDocument::loadXML($this->response->getData())); 113 112 $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'); 114 167 } 115 168 } trunk/src/test/php/net/stubbles/websites/WebsitesTestSuite.php
r292 r342 33 33 34 34 // xml tests 35 $this->addTestFile($dir . '/xml/stubXMLPostInterceptorTestCase.php'); 35 36 $this->addTestFile($dir . '/xml/stubXMLProcessorTestCase.php'); 36 37 $this->addTestFile($dir . '/xml/stubXMLResponseTestCase.php');
