1 /**
  2  * Copyright (C) 2013 KO GmbH <aditya.bhatt@kogmbh.com>
  3  *
  4  * @licstart
  5  * This file is part of WebODF.
  6  *
  7  * WebODF is free software: you can redistribute it and/or modify it
  8  * under the terms of the GNU Affero General Public License (GNU AGPL)
  9  * as published by the Free Software Foundation, either version 3 of
 10  * the License, or (at your option) any later version.
 11  *
 12  * WebODF is distributed in the hope that it will be useful, but
 13  * WITHOUT ANY WARRANTY; without even the implied warranty of
 14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 15  * GNU Affero General Public License for more details.
 16  *
 17  * You should have received a copy of the GNU Affero General Public License
 18  * along with WebODF.  If not, see <http://www.gnu.org/licenses/>.
 19  * @licend
 20  *
 21  * @source: http://www.webodf.org/
 22  * @source: https://github.com/kogmbh/WebODF/
 23  */
 24 
 25 /*global runtime, core*/
 26 /*jslint emptyblock: true, unparam: true*/
 27 
 28 /**
 29  * A structure that acts like a filter for all purposes,
 30  * and also can be combined with other instances of it's own kind or other filters.
 31  * @constructor
 32  * @implements {core.PositionFilter}
 33  */
 34 core.PositionFilterChain = function PositionFilterChain() {
 35     "use strict";
 36 
 37     var /**@type{!Array.<!core.PositionFilter|!core.PositionFilterChain>}*/
 38         filterChain = [],
 39         /**@const*/
 40         FILTER_ACCEPT = core.PositionFilter.FilterResult.FILTER_ACCEPT,
 41         /**@const*/
 42         FILTER_REJECT  = core.PositionFilter.FilterResult.FILTER_REJECT;
 43 
 44     /**
 45      * Returns accept if all filters in the chain accept the position, else reject.
 46      * @param {!core.PositionIterator} iterator
 47      * @return {!core.PositionFilter.FilterResult}
 48      */
 49     this.acceptPosition = function (iterator) {
 50         var i;
 51         for (i = 0; i < filterChain.length; i += 1) {
 52             if (filterChain[i].acceptPosition(iterator) === FILTER_REJECT) {
 53                 return FILTER_REJECT;
 54             }
 55         }
 56         return FILTER_ACCEPT;
 57     };
 58 
 59     /**
 60      * Adds a filter to the filter chain.
 61      * @param {!core.PositionFilter|!core.PositionFilterChain} filterInstance
 62      * @return {undefined}
 63      */
 64     this.addFilter = function (filterInstance) {
 65         filterChain.push(filterInstance);
 66     };
 67 
 68 };
 69