Changeset 279
- Timestamp:
- 02/19/07 18:17:29 (2 years ago)
- Files:
-
- trunk/config/xml/processors.xml (modified) (1 diff)
- trunk/docroot/index.php (modified) (2 diffs)
- trunk/docroot/xml.php (modified) (2 diffs)
- trunk/src/main/php/net/stubbles/websites/memphis/stubMemphisPageProcessor.php (modified) (3 diffs)
- trunk/src/main/php/net/stubbles/websites/processors/stubDefaultProcessorResolver.php (modified) (3 diffs)
- trunk/src/main/php/net/stubbles/websites/processors/stubProcessor.php (modified) (2 diffs)
- trunk/src/main/php/net/stubbles/websites/processors/stubProcessorResolver.php (modified) (2 diffs)
- trunk/src/main/php/net/stubbles/websites/processors/stubSimpleProcessorResolver.php (modified) (3 diffs)
- trunk/src/main/php/net/stubbles/websites/stubPageFactory.php (modified) (2 diffs)
- trunk/src/main/php/net/stubbles/websites/stubXJConfPageFactory.php (added)
- trunk/src/main/php/net/stubbles/websites/xml/stubXMLProcessor.php (modified) (6 diffs)
- trunk/src/main/resources/xjconf/processors.xml (modified) (1 diff)
- trunk/src/test/php/net/stubbles/websites/WebsitesTestSuite.php (modified) (1 diff)
- trunk/src/test/php/net/stubbles/websites/xml (added)
- trunk/src/test/php/net/stubbles/websites/xml/stubXMLProcessorTestCase.php (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/config/xml/processors.xml
r241 r279 3 3 xmlns:xj="http://xjconf.net/XJConf" 4 4 xmlns="http://stubbles.net/websites"> 5 <defaultResolver default="page"> 6 <processor name="page" type="net.stubbles.websites.processors.stubPageProcessor" /> 5 <defaultResolver default="xml"> 6 <pageFactory type="net.stubbles.websites.stubXJConfPageFactory" /> 7 <processor name="xml" type="net.stubbles.websites.xml.stubXMLPageProcessor" /> 8 <processor name="page" type="net.stubbles.websites.memphis.stubMemphisPageProcessor" /> 7 9 </defaultResolver> 8 10 </xj:configuration> trunk/docroot/index.php
r274 r279 3 3 require '../lib/stubbles.php'; 4 4 stubClassLoader::load('net.stubbles.websites.memphis.stubMemphisPageProcessor', 5 'net.stubbles.websites.stubXJConfPageFactory', 5 6 'net.stubbles.ipo.request.stubWebRequest', 6 7 'net.stubbles.ipo.session.stubPHPSession' … … 10 11 public static function main() 11 12 { 12 $request = new stubWebRequest(); 13 $session = new stubPHPSession('stubSID'); 14 $processor = new stubMemphisPageProcessor($request, $session); 13 $request = new stubWebRequest(); 14 $session = new stubPHPSession('stubSID'); 15 $pageFactory = new stubXJConfPageFactory(stubXJConfLoader::getInstance()); 16 $processor = new stubMemphisPageProcessor($request, $session, $pageFactory); 15 17 $processor->process()->getResponse()->send(); 16 18 } trunk/docroot/xml.php
r274 r279 4 4 stubClassLoader::load('net.stubbles.websites.xml.stubXMLProcessor', 5 5 'net.stubbles.websites.xml.stubXMLPagePostInterceptor', 6 'net.stubbles.websites.stubXJConfPageFactory', 6 7 'net.stubbles.ipo.request.stubWebRequest', 7 8 'net.stubbles.ipo.session.stubPHPSession' … … 19 20 unlink($file->getPathname()); 20 21 } 21 $request = new stubWebRequest(); 22 $session = new stubPHPSession('stubSID'); 23 $processor = new stubXMLProcessor($request, $session); 22 $request = new stubWebRequest(); 23 $session = new stubPHPSession('stubSID'); 24 $pageFactory = new stubXJConfPageFactory(stubXJConfLoader::getInstance()); 25 $processor = new stubXMLProcessor($request, $session, $pageFactory); 24 26 $postInterceptor = new stubXMLPagePostInterceptor(); 25 27 $postInterceptor->setRequest($request); trunk/src/main/php/net/stubbles/websites/memphis/stubMemphisPageProcessor.php
r267 r279 8 8 */ 9 9 stubClassLoader::load('net.stubbles.websites.processors.stubProcessor', 10 'net.stubbles.ipo.request.stubRequest', 11 'net.stubbles.ipo.session.stubSession', 12 'net.stubbles.ipo.response.stubBaseResponse', 13 'net.stubbles.websites.stubPageFactory' 10 'net.stubbles.ipo.response.stubBaseResponse' 14 11 ); 15 12 /** … … 49 46 * constructor 50 47 * 51 * @param stubRequest $request the current request 52 * @param stubSession $session the current session 48 * @param stubRequest $request the current request 49 * @param stubSession $session the current session 50 * @param stubPageFactory $pageFactory page factory to use to read the page configuration 53 51 */ 54 public function __construct(stubRequest $request, stubSession $session )52 public function __construct(stubRequest $request, stubSession $session, stubPageFactory $pageFactory) 55 53 { 56 54 $this->request = $request; 57 55 $this->session = $session; 56 $this->pageFactory = $pageFactory; 58 57 $this->response = new stubBaseResponse(); 59 $this->pageFactory = new stubPageFactory(stubXJConfLoader::getInstance());60 58 } 61 59 … … 77 75 78 76 try { 79 $page = $this->pageFactory->getPage( stubConfig::getConfigPath() . '/xml/pages/memphis/' . $pageName . '.xml');77 $page = $this->pageFactory->getPage('memphis/' . $pageName); 80 78 } catch (stubPageConfigurationException $pce) { 81 79 $this->response->replaceData((string) $pce); trunk/src/main/php/net/stubbles/websites/processors/stubDefaultProcessorResolver.php
r241 r279 25 25 * list of processors 26 26 * 27 * @var array 27 * @var array<string,string> 28 28 */ 29 29 protected $processors = array(); 30 /** 31 * the page factory to use to read the page configuration 32 * 33 * @var stubPageFactory 34 */ 35 protected $pageFactory = null; 30 36 31 37 /** … … 51 57 52 58 /** 59 * sets the page factory to use to read the page configuration 60 * 61 * @param stubPageFactory $pageFactory 62 */ 63 public function setPageFactory(stubPageFactory $pageFactory) 64 { 65 $this->pageFactory = $pageFactory; 66 } 67 68 /** 53 69 * resolves the request and creates the appropriate processor 54 70 * … … 71 87 stubClassLoader::load($this->processors[$paramValue]); 72 88 $className = stubClassLoader::getNonQualifiedClassName($this->processors[$paramValue]); 73 $processor = new $className($request, $session );89 $processor = new $className($request, $session, $this->pageFactory); 74 90 if (($processor instanceof stubProcessor) == false) { 75 91 throw new stubProcessorException($this->processors[$paramValue] . ' is not an instance of ' . stubClassLoader::getFullQualifiedClassName('stubProcessor')); trunk/src/main/php/net/stubbles/websites/processors/stubProcessor.php
r240 r279 9 9 stubClassLoader::load('net.stubbles.ipo.request.stubRequest', 10 10 'net.stubbles.ipo.response.stubResponse', 11 'net.stubbles.ipo.session.stubSession' 11 'net.stubbles.ipo.session.stubSession', 12 'net.stubbles.websites.stubPageFactory' 12 13 ); 13 14 /** … … 22 23 * constructor 23 24 * 24 * @param stubRequest $request the current request 25 * @param stubSession $session the current session 25 * @param stubRequest $request the current request 26 * @param stubSession $session the current session 27 * @param stubPageFactory $pageFactory page factory to use to read the page configuration 26 28 */ 27 #public function __construct(stubRequest $request, stubSession $session );28 29 #public function __construct(stubRequest $request, stubSession $session, stubPageFactory $pageFactory); 30 29 31 /** 30 32 * processes the request trunk/src/main/php/net/stubbles/websites/processors/stubProcessorResolver.php
r241 r279 10 10 'net.stubbles.ipo.session.stubSession', 11 11 'net.stubbles.websites.processors.stubProcessor', 12 'net.stubbles.websites.processors.stubProcessorException' 12 'net.stubbles.websites.processors.stubProcessorException', 13 'net.stubbles.websites.stubPageFactory' 13 14 ); 14 15 /** … … 22 23 { 23 24 /** 25 * sets the page factory to use to read the page configuration 26 * 27 * @param stubPageFactory $pageFactory 28 */ 29 public function setPageFactory(stubPageFactory $pageFactory); 30 31 /** 24 32 * resolves the request and creates the appropriate processor 25 33 * trunk/src/main/php/net/stubbles/websites/processors/stubSimpleProcessorResolver.php
r241 r279 21 21 * @var string 22 22 */ 23 protected $processor = null; 23 protected $processor = null; 24 /** 25 * the page factory to use to read the page configuration 26 * 27 * @var stubPageFactory 28 */ 29 protected $pageFactory = null; 24 30 25 31 /** … … 31 37 { 32 38 $this->processor = $fqClassName; 39 } 40 41 /** 42 * sets the page factory to use to read the page configuration 43 * 44 * @param stubPageFactory $pageFactory 45 */ 46 public function setPageFactory(stubPageFactory $pageFactory) 47 { 48 $this->pageFactory = $pageFactory; 33 49 } 34 50 … … 45 61 stubClassLoader::load($this->processor); 46 62 $className = stubClassLoader::getNonQualifiedClassName($this->processor); 47 $processor = new $className($request, $session );63 $processor = new $className($request, $session, $this->pageFactory); 48 64 if (($processor instanceof stubProcessor) == false) { 49 65 throw new stubProcessorException($this->processor . ' is not an instance of ' . stubClassLoader::getFullQualifiedClassName('stubProcessor')); trunk/src/main/php/net/stubbles/websites/stubPageFactory.php
r267 r279 1 1 <?php 2 2 /** 3 * Class to read the page configuration and to create the page.3 * Interface for a page factory: returns a configured stubPage instance. 4 4 * 5 5 * @author Frank Kleine <mikey@stubbles.net> … … 11 11 'net.stubbles.websites.stubPageConfigurationException' 12 12 ); 13 XJConfLoader::load('DefinitionParser',14 'XmlParser',15 'XJConfClassLoader'16 );17 13 /** 18 * Class to read the page configuration and to create the page.14 * Interface for a page factory: returns a configured stubPage instance. 19 15 * 20 16 * @package stubbles 21 17 * @subpackage websites 22 18 */ 23 class stubPageFactory extends stubBaseObject 19 interface stubPageFactory 24 20 { 25 21 /** 26 * the xml parser22 * checks whether the page factory knows the page or not 27 23 * 28 * @var XmlParser 24 * @param string $configSource source of the page configuration to use 25 * @return bool 29 26 */ 30 p rivate static $xmlParser;31 27 public function hasPage($configSource); 28 32 29 /** 33 * constructor30 * returns the configured stubPage instance 34 31 * 35 * @param stubXJConfLoader $classLoader class loader to use for loading unloaded classes 36 */ 37 public function __construct(stubXJConfLoader $classLoader) 38 { 39 if (null == self::$xmlParser) { 40 $tagParser = new DefinitionParser(array('http://stubbles.net/websites' => $classLoader)); 41 $defs = $tagParser->parse(stubFactory::getResourceURI('xjconf/websites.xml')); 42 43 self::$xmlParser = new XmlParser(); 44 self::$xmlParser->setTagDefinitions($defs); 45 } 46 } 47 48 /** 49 * Return the loaded page. 50 * 51 * @param string $configfile name of configuration file where page is configured 52 * @return stubMemphisPage 32 * @param string $configSource source of the page configuration to use 33 * @return stubPage 53 34 * @throws stubPageConfigurationException 54 35 */ 55 public function getPage($configFile) 56 { 57 try { 58 self::$xmlParser->parse($configFile); 59 } catch (XJConfException $xjce) { 60 throw new stubPageConfigurationException('Can not read page configuration from ' . $configFile, $xjce); 61 } 62 63 return self::$xmlParser->getConfigValue('page'); 64 } 36 public function getPage($configSource); 65 37 } 66 38 ?> trunk/src/main/php/net/stubbles/websites/xml/stubXMLProcessor.php
r276 r279 8 8 */ 9 9 stubClassLoader::load('net.stubbles.websites.processors.stubProcessor', 10 'net.stubbles.ipo.request.stubRequest',11 'net.stubbles.ipo.session.stubSession',12 10 'net.stubbles.ipo.response.stubBaseResponse', 13 'net.stubbles.websites.stubPageFactory',14 11 'net.stubbles.util.validators.stubRegexValidator', 15 12 'net.stubbles.xml.stubDomXMLStreamWriter', … … 21 18 * @package stubbles 22 19 * @subpackage websites_xml 23 * @todo use a stubXMLStreamWriterFactory to create a stubXMLStreamWriter24 20 * @todo think about how to get the skin information from 25 * stub XMLPageDocumentinto the stubXMLPagePostInterceptor21 * stubPage into the stubXMLPagePostInterceptor 26 22 */ 27 23 class stubXMLProcessor extends stubBaseObject implements stubProcessor … … 45 41 */ 46 42 protected $response; 43 /** 44 * the page factory to use to read the page configuration 45 * 46 * @var stubPageFactory 47 */ 48 protected $pageFactory; 47 49 48 50 /** 49 51 * constructor 50 52 * 51 * @param stubRequest $request the current request 52 * @param stubSession $session the current session 53 * @param stubRequest $request the current request 54 * @param stubSession $session the current session 55 * @param stubPageFactory $pageFactory page factory to use to read the page configuration 53 56 */ 54 public function __construct(stubRequest $request, stubSession $session )57 public function __construct(stubRequest $request, stubSession $session, stubPageFactory $pageFactory) 55 58 { 56 59 $this->request = $request; 57 60 $this->session = $session; 61 $this->pageFactory = $pageFactory; 58 62 $this->response = new stubBaseResponse(); 59 63 } … … 68 72 { 69 73 if ($this->request->hasValue('page') == true) { 70 $pageName = $this->request->getValidatedValue(new stubRegexValidator('([a-zA-Z0-9_]) *'), 'page');71 if (null == $pageName || file_exists(stubConfig::getConfigPath() . '/xml/pages/conf/' . $pageName . '.xml') == false) {74 $pageName = $this->request->getValidatedValue(new stubRegexValidator('([a-zA-Z0-9_])'), 'page'); 75 if (null == $pageName || $this->pageFactory->hasPage('conf/' . $pageName) == false) { 72 76 $pageName = 'index'; 73 77 } … … 76 80 } 77 81 78 $xmlStreamWriter = new stubDomXMLStreamWriter(); 82 $xmlSerializer = $this->createXMLSerializer(); 83 $xmlStreamWriter = $this->createXMLStreamWriter(); 84 $page = $this->pageFactory->getPage('conf/' . $pageName); 85 $elements = $page->getElements(); 79 86 $xmlStreamWriter->writeStartElement('document'); 80 $xmlSerializer = new stubXMLSerializer();81 82 $pageFactory = new stubPageFactory(stubXJConfLoader::getInstance());83 $page = $pageFactory->getPage(stubConfig::getConfigPath() . '/xml/pages/conf/' . $pageName . '.xml');84 $elements = $page->getElements();85 87 foreach ($elements as $name => $element) { 86 88 $data = $element->process($this->request, $this->session, $this->response); 87 89 $xmlSerializer->serialize($data, $xmlStreamWriter, array(stubXMLSerializer::OPT_ROOT_TAG => $name)); 88 90 } 89 90 91 91 92 $xmlStreamWriter->writeEndElement(); // end document … … 104 105 return $this->response; 105 106 } 107 108 /** 109 * returns a xml stream writer 110 * 111 * @return stubXMLStreamWriter 112 * @todo use a stubXMLStreamWriterFactory to create the stubXMLStreamWriter 113 */ 114 protected function createXMLStreamWriter() 115 { 116 $xmlStreamWriter = new stubDomXMLStreamWriter(); 117 return $xmlStreamWriter; 118 } 119 120 /** 121 * returns the xml serializer 122 * 123 * @return stubXMLSerializer 124 */ 125 protected function createXMLSerializer() 126 { 127 $xmlSerializer = new stubXMLSerializer(); 128 return $xmlSerializer; 129 } 106 130 } 107 131 ?> trunk/src/main/resources/xjconf/processors.xml
r241 r279 14 14 <attribute name="processor" type="string" /> 15 15 </tag> 16 <abstractTag name="pageFactory" abstractType="net.stubbles.websites.stubPageFactory" concreteTypeAttribute="type" /> 16 17 </namespace> 17 18 </defines> trunk/src/test/php/net/stubbles/websites/WebsitesTestSuite.php
r277 r279 23 23 $this->TestSuite('All websites classes tests'); 24 24 $this->addTestFile($dir . '/stubPageTestCase.php'); 25 26 // xml tests 27 $this->addTestFile($dir . '/xml/stubXMLProcessorTestCase.php'); 25 28 } 26 29 }
