Modified:
/framework/trunk/piwi/index.php
/framework/trunk/piwi/lib/piwi/PiwiException.class.php
/framework/trunk/piwi/lib/piwi/inputprovider/xml/XMLPage.class.php
/framework/trunk/piwi/lib/piwi/page-processing/Pipeline.class.php
/framework/trunk/piwi/lib/piwi/page-processing/site/Site.class.php
=======================================
--- /framework/trunk/piwi/index.php Sat Oct 9 09:41:03 2010
+++ /framework/trunk/piwi/index.php Tue Oct 12 08:18:18 2010
@@ -136,17 +136,17 @@
$logger->debug('Pipeline initialized successfully');
try {
- $logger->debug('Site generating content');
- $pipeline->generateContent();
- $logger->debug("Beginning serialization");
- $pipeline->serialize();
+ $logger->debug('Generate full pipeline');
+ $pipeline->generate();
+ $logger->debug("Input -> Output succeded");
} catch (Exception $exception) {
// Show a page displaying the error
- Request :: setPageId('default');
- $exceptionPageGenerator = new ExceptionPageGenerator($exception);
- $xmlpage = BeanFactory :: getBeanById('xmlPage');
- $xmlpage->setContent($exceptionPageGenerator->generate());
- $pipeline->serialize($xmlpage);
+ $expage = new ExceptionPageGenerator($exception);
+ $pipeline->input('xml');
+ $pipeline->getPage()->setContent($expage->generate());
+ $pipeline->getPage()->generateContent(true);
+ $pipeline->output();
+
$logger->error('Site generation failed with exception: ' .
$exception->getMessage());
}
=======================================
--- /framework/trunk/piwi/lib/piwi/PiwiException.class.php Wed Nov 12
01:33:37 2008
+++ /framework/trunk/piwi/lib/piwi/PiwiException.class.php Tue Oct 12
08:18:18 2010
@@ -27,7 +27,10 @@
/** Errorcode PERMISSION_DENIED. */
const PERMISSION_DENIED = 1008;
-
+
+ /** Errorcode INVALID_XML_DEFINITION. */
+ const XML_ID_NOT_UNIQUE = 1009;
+
/**
* Constructor.
* @param string $message The error message.
=======================================
--- /framework/trunk/piwi/lib/piwi/inputprovider/xml/XMLPage.class.php Thu
Sep 30 07:07:45 2010
+++ /framework/trunk/piwi/lib/piwi/inputprovider/xml/XMLPage.class.php Tue
Oct 12 08:18:18 2010
@@ -17,26 +17,31 @@
* TODO refactor: some stuff should go to the parent generate content
method
* TODO refactor: this class must be easily able extend
*/
- public function generateContent() {
- $this->checkPermissions();
-
- $cache = $this->getCache();
- $content = $cache->getPage();
-
+ public function generateContent($manualContent = null) {
+ $content = null;
+ $cache = null;
+
+ if (!$manualContent) {
+ $this->checkPermissions();
+ $cache = $this->getCache();
+ $content = $cache->getPage();
+ }
if ($content != null) {
// Page has been found in cache
$this->content = $content;
} else {
// Page has not been found in cache, so load it and save it in the cache
- $filePath = $this->contentPath . '/' . $this->site->getFilePath();
-
- if (!file_exists($filePath)) {
- throw new PiwiException("Could not find the the requested page
(Path: '" . $filePath . "').",
- PiwiException :: ERR_404);
- }
-
- $this->content = new DOMDocument;
- $this->content->load($filePath);
+ if (!$manualContent) {
+ $filePath = $this->contentPath . '/' . $this->site->getFilePath();
+
+ if (!file_exists($filePath)) {
+ throw new PiwiException("Could not find the the requested page
(Path: '" . $filePath . "').",
+ PiwiException :: ERR_404);
+ }
+
+ $this->content = new DOMDocument;
+ $this->content->load($filePath);
+ }
// Configure the transformer
$processor = new XSLTProcessor;
@@ -48,7 +53,9 @@
$this->content = $processor->transformToDoc($this->content);
// Save page in cache
- $cache->cachePage($this->content);
+ if ($cache != null) {
+ $cache->cachePage($this->content);
+ }
}
return $this->content;
}
=======================================
--- /framework/trunk/piwi/lib/piwi/page-processing/Pipeline.class.php Sat
Oct 9 09:41:03 2010
+++ /framework/trunk/piwi/lib/piwi/page-processing/Pipeline.class.php Tue
Oct 12 08:18:18 2010
@@ -1,45 +1,60 @@
<?php
/**
- * The SiteSelector class selects a matching inputprovider implementation
based on the
+ * The Pipeline class selects a matching inputprovider implementation
based on the
* file ending of the requested content. The actual file which is to be
read is defined
* in the site.xml.
*
- * In other words, the SiteSelector connects the Site implementation to
the Page implementation.
+ * In other words, the pipeline:
*
- * New inputprovider implementations can be added in the context.xml with
adding the
- * extension and the preferred Page implementation for it.
+ * - chooses the input provider
+ * - takes care the input provider transforms the content to piwi xml
+ * - chooses the output provider
+ * - takes care the output provider transforms the content to the choosen
output format
+ *
+ * New inputprovider implementations can be added in the context.xml with
adding the
+ * extension and the preferred Page implementation for it.
*/
class Pipeline {
/** Reference to the processed page. */
private $page = null;
- private $errormode = false;
-
+ /** Map of extension / Page implementations */
private $pagemap = null;
+ /** Configuration */
private $configuration = null;
- /**
- * Constructor.
- */
+ /** Constructor */
public function __construct() {
}
/**
- * Processes the contents of the page.
+ * Standard generation of content.
+ * Choose input, generate content, choose output.
*/
- public function generateContent() {
- $this->_choosePipeline();
+ public function generate() {
+ $this->input();
$this->page->generateContent();
+ $this->output();
}
/**
* Selects a Page implementation based on the file extension.
+ *
+ * @param string $extension the extension to use for selecting the input
file, selected from the page map
+ * @param string $pageId the page id from the site
+ * @return void
*/
- private function _choosePipeline() {
- $path = $this->getSite()->getFilePath();
- $pos = strrpos($path, ".");
- $extension = substr($path, $pos + 1);
+ public function input($extension = null, $pageId = null) {
+ if ($pageId != null) {
+ Request::setPageId($pageId);
+ }
+
+ if ($extension == null) {
+ $path = $this->getSite()->getFilePath();
+ $pos = strrpos($path, ".");
+ $extension = substr($path, $pos + 1);
+ }
if (isset($this->pagemap[$extension])) {
if (is_object($this->pagemap[$extension])) {
@@ -57,28 +72,16 @@
}
/**
- * Sets the content of the page.
- * @param string $content The content as xml.
+ * Outputs the content, based on the serializer choosen by the url
extension
*/
- public function setContent($content) {
- $this->page->setContent($content);
- }
-
- /**
- * Executes the Serializer.
- */
- public function serialize($page = null) {
+ public function output() {
$extension = Request :: getExtension();
$serializer = $this->configuration->getSerializer($extension);
-
if ($serializer == null) {
$serializer = new HTMLSerializer();
}
- if ($page == null) {
- $page = $this->page;
- }
- $serializer->serialize($page->getContent());
+ $serializer->serialize($this->page->getContent());
}
/**
@@ -114,7 +117,8 @@
}
/**
- * Sets the Pagemap
+ * Sets the Pagemap as defined in the context.xml
+ *
* @param array $pagemap
* @return unknown_type
*/
=======================================
--- /framework/trunk/piwi/lib/piwi/page-processing/site/Site.class.php Sat
Oct 9 09:41:03 2010
+++ /framework/trunk/piwi/lib/piwi/page-processing/site/Site.class.php Tue
Oct 12 08:18:18 2010
@@ -15,10 +15,13 @@
/** Name of the folder where your templates are placed. */
protected $templatesPath = null;
+ private $log;
+
/**
* Constructor.
*/
public function __construct() {
+ $this->log = Logger :: getLogger('Site.class');
}
/**
@@ -29,11 +32,18 @@
if ($this->domXPath == null) {
$this->_loadSite();
}
-
- $template = $this->_getCurrentPageDOMNode()->getAttribute("template");
+ $template = null;
+ try {
+ $template = $this->_getCurrentPageDOMNode()->getAttribute("template");
+ } catch (PiwiException $e) {
+ if ($e->getCode() == PiwiException :: ERR_404) {
+ $this->log->warn('Could not fine template for: ' .
Request::getPageId() . " - returning default.php");
+ } else {
+ throw $e;
+ }
+ }
if ($template == null) {
-
$template = 'default.php';
}
return $this->templatesPath . '/' . $template;
@@ -249,7 +259,7 @@
} else if ($result->length > 1) {
throw new PiwiException("The id of the requested page is not
unique (Page: '" .
$pageId . "').",
- PiwiException :: ERR_404);
+ PiwiException :: XML_ID_NOT_UNIQUE);
} else {
throw new PiwiException("Could not find the requested page
(Page: '" .
$pageId . "').",