import {Attributes} from '../lang/Attributes';
import {BooleanUtil} from '../lang/BooleanUtil';
import {ObjectBase} from '../lang/ObjectBase';
import {ObjectUtil} from '../lang/ObjectUtil';
import {StringBuffer} from '../lang/StringBuffer';
import {StringUtil} from '../lang/StringUtil';
//==========================================================
// 标签环境类。
//
// @class
// @author maocy
// @version 150114
//==========================================================
export class TagContext extends ObjectBase {
public code: string;
public trimLeft: boolean;
public trimRight: boolean;
public _attributes: Attributes;
public _source: StringBuffer;
//==========================================================
// 构造处理。
//
// @method
//==========================================================
public constructor() {
super();
this.trimLeft = false;
this.trimRight = false;
this._attributes = new Attributes();
this._source = new StringBuffer();
}
//==========================================================
// 收集处理。
//
// @method
//==========================================================
public instanceAlloc() {
this._attributes.clear();
}
//==========================================================
// 取得属性值。
//
// @method
// @param name:String 名称
// @param value:String 默认值
// @return String 内容
//==========================================================
public get(name: string, defaultValue: any = null) {
return this._attributes.get(name, defaultValue);
}
//==========================================================
// 设置属性值。
//
// @method
// @param name:String 名称
// @param value:String 内容
//==========================================================
public set(name: string, value: any) {
this._attributes.set(name, value);
}
//==========================================================
// 设置布尔属性值。
//
// @method
// @param name:String 名称
// @param value:String 内容
//==========================================================
public setBoolean(name: string, value: boolean) {
this._attributes.set(name, BooleanUtil.toString(value));
}
//==========================================================
// 获得代码。
//
// @method
// @return TString 代码
//==========================================================
public source() {
return this._source.toString();
}
//==========================================================
// 输出文本。
//
// @method
// @param String 文本
//==========================================================
public write(source) {
if (!StringUtil.isEmpty(source)) {
this._source.append(source);
}
}
//==========================================================
// 重置代码内容。
//
// @method
//==========================================================
public resetSource(p) {
this._source.clear();
}
//==========================================================
// 释放处理。
//
// @method
//==========================================================
public dispose() {
this._attributes = ObjectUtil.dispose(this._attributes);
this._source = ObjectUtil.dispose(this._source);
super.dispose();
}
}