Home » geronimo-2.2-source-release » org.apache.geronimo.kernel.util » [javadoc | source]

    1   /**
    2    *  Licensed to the Apache Software Foundation (ASF) under one or more
    3    *  contributor license agreements.  See the NOTICE file distributed with
    4    *  this work for additional information regarding copyright ownership.
    5    *  The ASF licenses this file to You under the Apache License, Version 2.0
    6    *  (the "License"); you may not use this file except in compliance with
    7    *  the License.  You may obtain a copy of the License at
    8    *
    9    *     http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    *  Unless required by applicable law or agreed to in writing, software
   12    *  distributed under the License is distributed on an "AS IS" BASIS,
   13    *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    *  See the License for the specific language governing permissions and
   15    *  limitations under the License.
   16    */
   17   package org.apache.geronimo.kernel.util;
   18   
   19   // import java.io.IOException;
   20   import java.util.ArrayList;
   21   import java.util.List;
   22   import java.util.regex.Matcher;
   23   import java.util.regex.Pattern;
   24   
   25   import org.slf4j.Logger;
   26   import org.slf4j.LoggerFactory;
   27   
   28   /**
   29    * Utility functions related to Input validation.
   30    *
   31    * @version $Rev: 758297 $ $Date: 2009-03-25 08:11:16 -0700 (Wed, 25 Mar 2009) $
   32    */
   33   public class InputUtils {
   34       private static final Logger log = LoggerFactory.getLogger(InputUtils.class);
   35   
   36       private static final Pattern ILLEGAL_CHARS = Pattern.compile("[\\.]{2}|[<>:\\\\/\"\'\\|]");
   37   
   38       public final static void validateSafeInput(String input) {
   39           // look for illegal chars in input
   40           if (input != null) {
   41               Matcher inputMatcher = ILLEGAL_CHARS.matcher(input);
   42               if (inputMatcher.find()) 
   43               {
   44                   log.warn("Illegal characters detected in input" + input);
   45                   throw new IllegalArgumentException("input  "+input+" contains illegal characters: .. < > : / \\ \' \" | ");
   46               }
   47           }
   48       }
   49   
   50       public final static void validateSafeInput(ArrayList<String> inputs) {
   51           for (String input : inputs) {
   52               validateSafeInput(input);
   53           }
   54       }
   55   }

Home » geronimo-2.2-source-release » org.apache.geronimo.kernel.util » [javadoc | source]