Subversion-Projekte lars-tiefland.prado

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/**
3
 * TLiteral class file
4
 *
5
 * @author Qiang Xue <qiang.xue@gmail.com>
6
 * @link http://www.pradosoft.com/
7
 * @copyright Copyright &copy; 2005-2008 PradoSoft
8
 * @license http://www.pradosoft.com/license/
9
 * @version $Id: TLiteral.php 2541 2008-10-21 15:05:13Z qiang.xue $
10
 * @package System.Web.UI.WebControls
11
 */
12
 
13
/**
14
 * TLiteral class
15
 *
16
 * TLiteral displays a static text on the Web page.
17
 * TLiteral is similar to the TLabel control, except that the TLiteral
18
 * control does not have style properties (e.g. BackColor, Font, etc.)
19
 * You can programmatically control the text displayed in the control by setting
20
 * the {@link setText Text} property. The text displayed may be HTML-encoded
21
 * if the {@link setEncode Encode} property is set true (defaults to false).
22
 *
23
 * TLiteral will render the contents enclosed within its component tag
24
 * if {@link setText Text} is empty.
25
 *
26
 * Note, if {@link setEncode Encode} is false, make sure {@link setText Text}
27
 * does not contain unwanted characters that may bring security vulnerabilities.
28
 *
29
 * @author Qiang Xue <qiang.xue@gmail.com>
30
 * @version $Id: TLiteral.php 2541 2008-10-21 15:05:13Z qiang.xue $
31
 * @package System.Web.UI.WebControls
32
 * @since 3.0
33
 */
34
class TLiteral extends TControl implements IDataRenderer
35
{
36
	/**
37
	 * @return string the static text of the TLiteral
38
	 */
39
	public function getText()
40
	{
41
		return $this->getViewState('Text','');
42
	}
43
 
44
	/**
45
	 * Sets the static text of the TLiteral
46
	 * @param string the text to be set
47
	 */
48
	public function setText($value)
49
	{
50
		$this->setViewState('Text',$value,'');
51
	}
52
 
53
	/**
54
	 * Returns the static text of the TLiteral.
55
	 * This method is required by {@link IDataRenderer}.
56
	 * It is the same as {@link getText()}.
57
	 * @return string the static text of the TLiteral
58
	 * @see getText
59
	 * @since 3.1.0
60
	 */
61
	public function getData()
62
	{
63
		return $this->getText();
64
	}
65
 
66
	/**
67
	 * Sets the static text of the TLiteral.
68
	 * This method is required by {@link IDataRenderer}.
69
	 * It is the same as {@link setText()}.
70
	 * @param string the static text of the TLiteral
71
	 * @see setText
72
	 * @since 3.1.0
73
	 */
74
	public function setData($value)
75
	{
76
		$this->setText($value);
77
	}
78
 
79
	/**
80
	 * @return boolean whether the rendered text should be HTML-encoded. Defaults to false.
81
	 */
82
	public function getEncode()
83
	{
84
		return $this->getViewState('Encode',false);
85
	}
86
 
87
	/**
88
	 * @param boolean  whether the rendered text should be HTML-encoded.
89
	 */
90
	public function setEncode($value)
91
	{
92
		$this->setViewState('Encode',TPropertyValue::ensureBoolean($value),false);
93
	}
94
 
95
	/**
96
	 * Renders the literal control.
97
	 * @param THtmlWriter the writer used for the rendering purpose
98
	 */
99
	public function render($writer)
100
	{
101
		if(($text=$this->getText())!=='')
102
		{
103
			if($this->getEncode())
104
				$writer->write(THttpUtility::htmlEncode($text));
105
			else
106
				$writer->write($text);
107
		}
108
		else
109
			parent::render($writer);
110
	}
111
}
112