From 81b7d150b1c815cdd032c2b5795b6c4244e56ace Mon Sep 17 00:00:00 2001 From: xue <> Date: Tue, 22 Nov 2005 22:23:25 +0000 Subject: --- .gitattributes | 2 +- framework/Web/Services/TPageService.php | 2 +- framework/Web/THttpResponse.php | 32 +++++ framework/Web/UI/THtmlTextWriter.php | 235 -------------------------------- framework/Web/UI/THtmlWriter.php | 235 ++++++++++++++++++++++++++++++++ framework/Web/UI/TPage.php | 1 - framework/core.php | 5 +- 7 files changed, 273 insertions(+), 239 deletions(-) delete mode 100644 framework/Web/UI/THtmlTextWriter.php create mode 100644 framework/Web/UI/THtmlWriter.php diff --git a/.gitattributes b/.gitattributes index 24b7d228..7f54e625 100644 --- a/.gitattributes +++ b/.gitattributes @@ -74,7 +74,7 @@ framework/Web/UI/TClientScriptManager.php -text framework/Web/UI/TControl.php -text framework/Web/UI/TForm.php -text framework/Web/UI/THiddenFieldPageStatePersister.php -text -framework/Web/UI/THtmlTextWriter.php -text +framework/Web/UI/THtmlWriter.php -text framework/Web/UI/TPage.php -text framework/Web/UI/TPageStatePersister.php -text framework/Web/UI/TPostBackOptions.php -text diff --git a/framework/Web/Services/TPageService.php b/framework/Web/Services/TPageService.php index 79f81bcd..3218138e 100644 --- a/framework/Web/Services/TPageService.php +++ b/framework/Web/Services/TPageService.php @@ -384,7 +384,7 @@ class TPageService extends TComponent implements IService $page=new $className($this->_properties); else throw new THttpException(404,'pageservice_page_unknown',$this->_pageType); - $writer=new THtmlTextWriter($this->_application->getResponse()); + $writer=$this->_application->getResponse()->createHtmlWriter(); $page->run($writer); $writer->flush(); } diff --git a/framework/Web/THttpResponse.php b/framework/Web/THttpResponse.php index 58bbfb99..dfa2d023 100644 --- a/framework/Web/THttpResponse.php +++ b/framework/Web/THttpResponse.php @@ -59,6 +59,10 @@ class THttpResponse extends TComponent implements IModule, ITextWriter * @var integer response status code */ private $_status=200; + /** + * @var string HTML writer type + */ + private $_htmlWriterType='System.Web.UI.THtmlWriter'; /** * Destructor. @@ -303,6 +307,34 @@ class THttpResponse extends TComponent implements IModule, ITextWriter { setcookie($cookie->getName(),null,0,$cookie->getPath(),$cookie->getDomain(),$cookie->getSecure()); } + + /** + * @return string the type of HTML writer to be used, defaults to THtmlWriter + */ + public function getHtmlWriterType() + { + return $this->_htmlWriterType; + } + + /** + * @param string the type of HTML writer to be used, may be the class name or the namespace + */ + public function setHtmlWriterType($value) + { + $this->_htmlWriterType=$value; + } + + /** + * Creates a new instance of HTML writer. + * If the type of the HTML writer is not supplied, {@link getHtmlWriterType HtmlWriterType} will be assumed. + * @param string type of the HTML writer to be created. If null, {@link getHtmlWriterType HtmlWriterType} will be assumed. + */ + public function createHtmlWriter($type=null) + { + if($type===null) + $type=$this->_htmlWriterType; + return Prado::createComponent($type,$this); + } } ?> \ No newline at end of file diff --git a/framework/Web/UI/THtmlTextWriter.php b/framework/Web/UI/THtmlTextWriter.php deleted file mode 100644 index 4ea78383..00000000 --- a/framework/Web/UI/THtmlTextWriter.php +++ /dev/null @@ -1,235 +0,0 @@ -2, - 'a'=>0, - 'acronym'=>0, - 'address'=>2, - 'area'=>1, - 'b'=>0, - 'base'=>1, - 'basefont'=>1, - 'bdo'=>0, - 'bgsound'=>1, - 'big'=>0, - 'blockquote'=>2, - 'body'=>2, - 'br'=>2, - 'button'=>0, - 'caption'=>2, - 'center'=>2, - 'cite'=>0, - 'code'=>0, - 'col'=>1, - 'colgroup'=>2, - 'del'=>0, - 'dd'=>0, - 'dfn'=>0, - 'dir'=>2, - 'div'=>2, - 'dl'=>2, - 'dt'=>0, - 'em'=>0, - 'embed'=>1, - 'fieldset'=>2, - 'font'=>0, - 'form'=>2, - 'frame'=>1, - 'frameset'=>2, - 'h1'=>2, - 'h2'=>2, - 'h3'=>2, - 'h4'=>2, - 'h5'=>2, - 'h6'=>2, - 'head'=>2, - 'hr'=>1, - 'html'=>2, - 'i'=>0, - 'iframe'=>2, - 'img'=>1, - 'input'=>1, - 'ins'=>0, - 'isindex'=>1, - 'kbd'=>0, - 'label'=>0, - 'legend'=>2, - 'li'=>0, - 'link'=>1, - 'map'=>2, - 'marquee'=>2, - 'menu'=>2, - 'meta'=>1, - 'nobr'=>0, - 'noframes'=>2, - 'noscript'=>2, - 'object'=>2, - 'ol'=>2, - 'option'=>2, - 'p'=>0, - 'param'=>2, - 'pre'=>2, - 'ruby'=>2, - 'rt'=>2, - 'q'=>0, - 's'=>0, - 'samp'=>0, - 'script'=>2, - 'select'=>2, - 'small'=>2, - 'span'=>0, - 'strike'=>0, - 'strong'=>0, - 'style'=>2, - 'sub'=>0, - 'sup'=>0, - 'table'=>2, - 'tbody'=>2, - 'td'=>0, - 'textarea'=>0, - 'tfoot'=>2, - 'th'=>0, - 'thead'=>2, - 'title'=>2, - 'tr'=>2, - 'tt'=>0, - 'u'=>0, - 'ul'=>2, - 'var'=>0, - 'wbr'=>1, - 'xml'=>2 - ); - private static $_attrEncode=array( - 'abbr'=>true, - 'accesskey'=>true, - 'align'=>false, - 'alt'=>true, - 'autocomplete'=>false, - 'axis'=>true, - 'background'=>true, - 'bgcolor'=>false, - 'border'=>false, - 'bordercolor'=>false, - 'cellpadding'=>false, - 'cellspacing'=>false, - 'checked'=>false, - 'class'=>true, - 'cols'=>false, - 'colspan'=>false, - 'content'=>true, - 'coords'=>false, - 'dir'=>false, - 'disabled'=>false, - 'for'=>false, - 'headers'=>true, - 'height'=>false, - 'href'=>true, - 'id'=>false, - 'longdesc'=>true, - 'maxlength'=>false, - 'multiple'=>false, - 'name'=>false, - 'nowrap'=>false, - 'onclick'=>true, - 'onchange'=>true, - 'readonly'=>false, - 'rel'=>false, - 'rows'=>false, - 'rowspan'=>false, - 'rules'=>false, - 'scope'=>false, - 'selected'=>false, - 'shape'=>false, - 'size'=>false, - 'src'=>true, - 'style'=>false, - 'tabindex'=>false, - 'target'=>false, - 'title'=>true, - 'type'=>false, - 'usemap'=>false, - 'valign'=>false, - 'value'=>true, - 'vcard_name'=>false, - 'width'=>false, - 'wrap'=>false - ); - - private $_attributes=array(); - private $_openTags=array(); - private $_writer=null; - - public function __construct($writer) - { - $this->_writer=$writer; - } - - public function isValidFormAttribute($name) - { - return true; - } - - public function addAttribute($name,$value) - { - $this->_attributes[$name]=isset(self::$_attrEncode[$name])?THttpUtility::htmlEncode($value):$value; - } - - public function flush() - { - $this->_writer->flush(); - } - - public function write($str) - { - $this->_writer->write($str); - } - - public function writeLine($str='') - { - $this->_writer->write($str.self::CHAR_NEWLINE); - } - - public function writeAttribute($name,$value,$encode=false) - { - $this->_writer->write(' '.$name.='"'.($encode?THttpUtility::htmlEncode($value):$value).'"'); - } - - public function renderBeginTag($tagName) - { - $tagType=isset(self::$_tagTypes[$tagName])?self::$_tagTypes[$tagName]:self::TAG_OTHER; - $str='<'.$tagName; - foreach($this->_attributes as $name=>$value) - $str.=' '.$name.'="'.$value.'"'; - if($tagType===self::TAG_NONCLOSING) - { - $str.=' />'; - array_push($this->_openTags,''); - } - else - { - $str.='>'; - array_push($this->_openTags,$tagName); - } - $this->_writer->write($str); - $this->_attributes=array(); - } - - public function renderEndTag() - { - if(!empty($this->_openTags) && ($tagName=array_pop($this->_openTags))!=='') - $this->_writer->write(''); - } -} - -?> \ No newline at end of file diff --git a/framework/Web/UI/THtmlWriter.php b/framework/Web/UI/THtmlWriter.php new file mode 100644 index 00000000..75926d55 --- /dev/null +++ b/framework/Web/UI/THtmlWriter.php @@ -0,0 +1,235 @@ +2, + 'a'=>0, + 'acronym'=>0, + 'address'=>2, + 'area'=>1, + 'b'=>0, + 'base'=>1, + 'basefont'=>1, + 'bdo'=>0, + 'bgsound'=>1, + 'big'=>0, + 'blockquote'=>2, + 'body'=>2, + 'br'=>2, + 'button'=>0, + 'caption'=>2, + 'center'=>2, + 'cite'=>0, + 'code'=>0, + 'col'=>1, + 'colgroup'=>2, + 'del'=>0, + 'dd'=>0, + 'dfn'=>0, + 'dir'=>2, + 'div'=>2, + 'dl'=>2, + 'dt'=>0, + 'em'=>0, + 'embed'=>1, + 'fieldset'=>2, + 'font'=>0, + 'form'=>2, + 'frame'=>1, + 'frameset'=>2, + 'h1'=>2, + 'h2'=>2, + 'h3'=>2, + 'h4'=>2, + 'h5'=>2, + 'h6'=>2, + 'head'=>2, + 'hr'=>1, + 'html'=>2, + 'i'=>0, + 'iframe'=>2, + 'img'=>1, + 'input'=>1, + 'ins'=>0, + 'isindex'=>1, + 'kbd'=>0, + 'label'=>0, + 'legend'=>2, + 'li'=>0, + 'link'=>1, + 'map'=>2, + 'marquee'=>2, + 'menu'=>2, + 'meta'=>1, + 'nobr'=>0, + 'noframes'=>2, + 'noscript'=>2, + 'object'=>2, + 'ol'=>2, + 'option'=>2, + 'p'=>0, + 'param'=>2, + 'pre'=>2, + 'ruby'=>2, + 'rt'=>2, + 'q'=>0, + 's'=>0, + 'samp'=>0, + 'script'=>2, + 'select'=>2, + 'small'=>2, + 'span'=>0, + 'strike'=>0, + 'strong'=>0, + 'style'=>2, + 'sub'=>0, + 'sup'=>0, + 'table'=>2, + 'tbody'=>2, + 'td'=>0, + 'textarea'=>0, + 'tfoot'=>2, + 'th'=>0, + 'thead'=>2, + 'title'=>2, + 'tr'=>2, + 'tt'=>0, + 'u'=>0, + 'ul'=>2, + 'var'=>0, + 'wbr'=>1, + 'xml'=>2 + ); + private static $_attrEncode=array( + 'abbr'=>true, + 'accesskey'=>true, + 'align'=>false, + 'alt'=>true, + 'autocomplete'=>false, + 'axis'=>true, + 'background'=>true, + 'bgcolor'=>false, + 'border'=>false, + 'bordercolor'=>false, + 'cellpadding'=>false, + 'cellspacing'=>false, + 'checked'=>false, + 'class'=>true, + 'cols'=>false, + 'colspan'=>false, + 'content'=>true, + 'coords'=>false, + 'dir'=>false, + 'disabled'=>false, + 'for'=>false, + 'headers'=>true, + 'height'=>false, + 'href'=>true, + 'id'=>false, + 'longdesc'=>true, + 'maxlength'=>false, + 'multiple'=>false, + 'name'=>false, + 'nowrap'=>false, + 'onclick'=>true, + 'onchange'=>true, + 'readonly'=>false, + 'rel'=>false, + 'rows'=>false, + 'rowspan'=>false, + 'rules'=>false, + 'scope'=>false, + 'selected'=>false, + 'shape'=>false, + 'size'=>false, + 'src'=>true, + 'style'=>false, + 'tabindex'=>false, + 'target'=>false, + 'title'=>true, + 'type'=>false, + 'usemap'=>false, + 'valign'=>false, + 'value'=>true, + 'vcard_name'=>false, + 'width'=>false, + 'wrap'=>false + ); + + private $_attributes=array(); + private $_openTags=array(); + private $_writer=null; + + public function __construct($writer) + { + $this->_writer=$writer; + } + + public function isValidFormAttribute($name) + { + return true; + } + + public function addAttribute($name,$value) + { + $this->_attributes[$name]=isset(self::$_attrEncode[$name])?THttpUtility::htmlEncode($value):$value; + } + + public function flush() + { + $this->_writer->flush(); + } + + public function write($str) + { + $this->_writer->write($str); + } + + public function writeLine($str='') + { + $this->_writer->write($str.self::CHAR_NEWLINE); + } + + public function writeAttribute($name,$value,$encode=false) + { + $this->_writer->write(' '.$name.='"'.($encode?THttpUtility::htmlEncode($value):$value).'"'); + } + + public function renderBeginTag($tagName) + { + $tagType=isset(self::$_tagTypes[$tagName])?self::$_tagTypes[$tagName]:self::TAG_OTHER; + $str='<'.$tagName; + foreach($this->_attributes as $name=>$value) + $str.=' '.$name.'="'.$value.'"'; + if($tagType===self::TAG_NONCLOSING) + { + $str.=' />'; + array_push($this->_openTags,''); + } + else + { + $str.='>'; + array_push($this->_openTags,$tagName); + } + $this->_writer->write($str); + $this->_attributes=array(); + } + + public function renderEndTag() + { + if(!empty($this->_openTags) && ($tagName=array_pop($this->_openTags))!=='') + $this->_writer->write(''); + } +} + +?> \ No newline at end of file diff --git a/framework/Web/UI/TPage.php b/framework/Web/UI/TPage.php index 232878da..50b29c35 100644 --- a/framework/Web/UI/TPage.php +++ b/framework/Web/UI/TPage.php @@ -1,6 +1,5 @@