001    // Copyright 2004, 2005 The Apache Software Foundation
002    //
003    // Licensed under the Apache License, Version 2.0 (the "License");
004    // you may not use this file except in compliance with the License.
005    // You may obtain a copy of the License at
006    //
007    //     http://www.apache.org/licenses/LICENSE-2.0
008    //
009    // Unless required by applicable law or agreed to in writing, software
010    // distributed under the License is distributed on an "AS IS" BASIS,
011    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012    // See the License for the specific language governing permissions and
013    // limitations under the License.
014    package org.apache.tapestry.asset;
015    
016    import java.util.List;
017    
018    import org.apache.tapestry.event.ResetEventListener;
019    import org.apache.tapestry.util.RegexpMatcher;
020    
021    
022    /**
023     * Implementation of {@link ResourceMatcher}.
024     * 
025     */
026    public class ResourceMatcherImpl implements ResetEventListener, ResourceMatcher {
027        
028        /** regexp matcher engine. */
029        protected RegexpMatcher _matcher;
030        /** Resource match configuration regexp strings. */
031        protected List _contributions;
032        
033        /** no args constructor. */
034        public ResourceMatcherImpl() { }
035        
036        /**
037         * Invoked by hivemind by default to initialize
038         * service.
039         */
040        public void initializeService() 
041        {
042            _matcher = new RegexpMatcher();
043        }
044        
045        /**
046         * {@inheritDoc}
047         */
048        public synchronized void resetEventDidOccur()
049        {
050            _matcher.clear();
051        }
052        
053        /**
054         * {@inheritDoc}
055         */
056        public boolean containsResource(String path)
057        {
058            if (_contributions == null || _contributions.size() < 1 || path == null)
059                return false;
060            
061            for (int i = 0; i < _contributions.size(); i++) {
062                String pattern = (String)_contributions.get(i);
063                
064                if (_matcher.contains(pattern, path))
065                    return true;
066            }
067            
068            return false;
069        }
070        
071        /**
072         * The set of contributed regexp strings that will positively
073         * match incoming path strings for this matcher.
074         * @param contributions
075         */
076        public void setContributions(List contributions)
077        {
078            this._contributions = contributions;
079        }
080    }