import {JSONDigester} from "./JSONDigester"; /** * Concrete implementations of this class implement actions to be taken when * a corresponding nested pattern of XML elements has been matched. *

* Writing a custom Rule is considered perfectly normal when using Digester, * and is encouraged whenever the default set of Rule classes don't meet your * requirements; the digester framework can help process xml even when the * built-in rules aren't quite what is needed. *

* If a rule wishes to manipulate a digester stack (the default object stack, * a named stack, or the parameter stack) then it should only ever push * objects in the rule's begin method and always pop exactly the same * number of objects off the stack during the rule's end method. Of course * peeking at the objects on the stacks can be done from anywhere. *

* Rule objects should be stateless, ie they should not update any instance * member during the parsing process. A rule instance that changes state * will encounter problems if invoked in a "nested" manner; this can happen * if the same instance is added to digester multiple times or if a * wildcard pattern is used which can match both an element and a child of the * same element. The digester object stack and named stacks should be used to * store any state that a rule requires, making the rule class safe under all * possible uses. */ export abstract class Rule { private _digester:JSONDigester; get digester():JSONDigester { return this._digester; } set digester(value:JSONDigester) { this._digester = value; } /** * This method is called when the beginning of a matching XML element * is encountered. The default implementation delegates to the deprecated * method {@link #begin(Attributes) begin} without the * namespace and name parameters, to retain * backwards compatibility. * * @param namespace the namespace URI of the matching element, or an * empty string if the parser is not namespace aware or the element has * no namespace * @param name the local name if the parser is namespace aware, or just * the element name otherwise * @param attributes The attribute list of this element */ begin(name:string, attributes: {[key:string]: any}):void { } /** * This method is called when the body of a matching XML element is * encountered. If the element has no body, this method is * called with an empty string as the body text. *

* The default implementation delegates to the deprecated method * {@link #body(String) body} without the namespace and * name parameters, to retain backwards compatibility. * * @param namespace the namespace URI of the matching element, or an * empty string if the parser is not namespace aware or the element has * no namespace * @param name the local name if the parser is namespace aware, or just * the element name otherwise * @param text The text of the body of this element * @since Digester 1.4 */ body(name:string, text:string):void { } /** * This method is called when the end of a matching XML element * is encountered. The default implementation delegates to the deprecated * method {@link #end end} without the * namespace and name parameters, to retain * backwards compatibility. * * @param namespace the namespace URI of the matching element, or an * empty string if the parser is not namespace aware or the element has * no namespace * @param name the local name if the parser is namespace aware, or just * the element name otherwise * @since Digester 1.4 */ end(name:string):void { } /** * This method is called after all parsing methods have been * called, to allow Rules to remove temporary data. */ finish():void { } toString():string { return this.constructor.name; } }