001/* 002 * Copyright 2017 Anyware Services 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.ametys.cms.remote; 017 018import java.util.HashSet; 019import java.util.Set; 020import java.util.regex.Pattern; 021 022import org.apache.avalon.framework.configuration.Configurable; 023import org.apache.avalon.framework.configuration.Configuration; 024import org.apache.avalon.framework.configuration.ConfigurationException; 025 026/** 027 * Static implementation of a {@link RemoteUrl} 028 * 029 */ 030public class StaticRemoteUrl implements RemoteUrl, Configurable 031{ 032 Set<Pattern> _patterns; 033 034 @Override 035 public void configure(Configuration configuration) throws ConfigurationException 036 { 037 _patterns = new HashSet<>(); 038 039 Configuration patternsConfig = configuration.getChild("patterns"); 040 041 for (Configuration patternConfig : patternsConfig.getChildren("pattern")) 042 { 043 _patterns.add(Pattern.compile(patternConfig.getValue())); 044 } 045 } 046 047 @Override 048 public Set<Pattern> getAllowedUrls() 049 { 050 return _patterns; 051 } 052 053}