// Path: inputvalidation/src/main/java/com/switchfly/inputvalidation/canonicalizer/HtmlAndQueryStringCanonicalizer.java
// public class HtmlAndQueryStringCanonicalizer extends StringCanonicalizer {
// 
//     @Override
//     public String execute(String content) {
//         if (StringUtils.isBlank(content)) {
//             return content;
//         }
//         String s = super.execute(content);
//         try {
//             s = StringEscapeUtils.unescapeHtml(s);
//         } catch (Exception e) {
//             throw new IllegalArgumentException("Canonicalization error", e);
//         }
//         try {
//             s = URLDecoder.decode(s, "UTF-8");
//         } catch (Exception e) {
//             // ignore and move on
//         }
//         return s;
//     }
// }
// 
// Path: inputvalidation/src/main/java/com/switchfly/inputvalidation/sanitizer/StripHtmlAndCleanPatternSanitizer.java
// public class StripHtmlAndCleanPatternSanitizer extends CleanPatternSanitizer {
// 
//     private final StripHtmlSanitizer _stripHtmlSanitizer = new StripHtmlSanitizer();
// 
//     public StripHtmlAndCleanPatternSanitizer(Pattern acceptedPattern) {
//         super(acceptedPattern);
//     }
// 
//     public StripHtmlAndCleanPatternSanitizer(String acceptedPattern) {
//         super(acceptedPattern);
//     }
// 
//     @Override
//     public String execute(String content) {
//         String htmlLess = _stripHtmlSanitizer.execute(content);
//         return super.execute(htmlLess);
//     }
// }
// 
// Path: inputvalidation/src/main/java/com/switchfly/inputvalidation/sanitizer/StripHtmlSanitizer.java
// public class StripHtmlSanitizer implements Sanitizer<String> {
// 
//     @Override
//     public String execute(String content) {
//         if (StringUtils.isBlank(content)) {
//             return content;
//         }
//         Document document = Jsoup.parse(content);
//         document.outputSettings().escapeMode(Entities.EscapeMode.xhtml);
//         for (Element element : document.select("script,link,iframe,style")) {
//             element.remove();
//         }
//         return document.text();
//     }
// }
// 
// Path: inputvalidation/src/main/java/com/switchfly/inputvalidation/validator/PatternValidator.java
// public class PatternValidator extends Validator<String> {
//     public static final int FLAGS = Pattern.DOTALL | Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE | Pattern.MULTILINE;
//     private final Pattern _pattern;
// 
//     public PatternValidator(String regex) {
//         _pattern = Pattern.compile(regex, FLAGS);
//     }
// 
//     public PatternValidator(Pattern pattern) {
//         _pattern = pattern;
//     }
// 
//     @Override
//     public boolean execute(String content) {
//         return StringUtils.isBlank(content) || _pattern.matcher(content).matches();
//     }
// }


import com.switchfly.inputvalidation.canonicalizer.HtmlAndQueryStringCanonicalizer;
import com.switchfly.inputvalidation.sanitizer.StripHtmlAndCleanPatternSanitizer;
import com.switchfly.inputvalidation.sanitizer.StripHtmlSanitizer;
import com.switchfly.inputvalidation.validator.PatternValidator;
/*
 * Copyright 2012 Switchfly
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.switchfly.inputvalidation;


public class PatternValidationStrategies implements ValidationStrategies {

    private final ValidationStrategy<String> _cleanStrategy;
    private final ValidationStrategy<String> _validateStrategy;

    public PatternValidationStrategies(String acceptedPattern) {
        _cleanStrategy =
// Path: inputvalidation/src/main/java/com/switchfly/inputvalidation/canonicalizer/HtmlAndQueryStringCanonicalizer.java
// public class HtmlAndQueryStringCanonicalizer extends StringCanonicalizer {
// 
//     @Override
//     public String execute(String content) {
//         if (StringUtils.isBlank(content)) {
//             return content;
//         }
//         String s = super.execute(content);
//         try {
//             s = StringEscapeUtils.unescapeHtml(s);
//         } catch (Exception e) {
//             throw new IllegalArgumentException("Canonicalization error", e);
//         }
//         try {
//             s = URLDecoder.decode(s, "UTF-8");
//         } catch (Exception e) {
//             // ignore and move on
//         }
//         return s;
//     }
// }
// 
// Path: inputvalidation/src/main/java/com/switchfly/inputvalidation/sanitizer/StripHtmlAndCleanPatternSanitizer.java
// public class StripHtmlAndCleanPatternSanitizer extends CleanPatternSanitizer {
// 
//     private final StripHtmlSanitizer _stripHtmlSanitizer = new StripHtmlSanitizer();
// 
//     public StripHtmlAndCleanPatternSanitizer(Pattern acceptedPattern) {
//         super(acceptedPattern);
//     }
// 
//     public StripHtmlAndCleanPatternSanitizer(String acceptedPattern) {
//         super(acceptedPattern);
//     }
// 
//     @Override
//     public String execute(String content) {
//         String htmlLess = _stripHtmlSanitizer.execute(content);
//         return super.execute(htmlLess);
//     }
// }
// 
// Path: inputvalidation/src/main/java/com/switchfly/inputvalidation/sanitizer/StripHtmlSanitizer.java
// public class StripHtmlSanitizer implements Sanitizer<String> {
// 
//     @Override
//     public String execute(String content) {
//         if (StringUtils.isBlank(content)) {
//             return content;
//         }
//         Document document = Jsoup.parse(content);
//         document.outputSettings().escapeMode(Entities.EscapeMode.xhtml);
//         for (Element element : document.select("script,link,iframe,style")) {
//             element.remove();
//         }
//         return document.text();
//     }
// }
// 
// Path: inputvalidation/src/main/java/com/switchfly/inputvalidation/validator/PatternValidator.java
// public class PatternValidator extends Validator<String> {
//     public static final int FLAGS = Pattern.DOTALL | Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE | Pattern.MULTILINE;
//     private final Pattern _pattern;
// 
//     public PatternValidator(String regex) {
//         _pattern = Pattern.compile(regex, FLAGS);
//     }
// 
//     public PatternValidator(Pattern pattern) {
//         _pattern = pattern;
//     }
// 
//     @Override
//     public boolean execute(String content) {
//         return StringUtils.isBlank(content) || _pattern.matcher(content).matches();
//     }
// }


// Path: inputvalidation/src/main/java/com/switchfly/inputvalidation/PatternValidationStrategies.java
import com.switchfly.inputvalidation.canonicalizer.HtmlAndQueryStringCanonicalizer;
import com.switchfly.inputvalidation.sanitizer.StripHtmlAndCleanPatternSanitizer;
import com.switchfly.inputvalidation.sanitizer.StripHtmlSanitizer;
import com.switchfly.inputvalidation.validator.PatternValidator;

/*
 * Copyright 2012 Switchfly
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.switchfly.inputvalidation;


public class PatternValidationStrategies implements ValidationStrategies {

    private final ValidationStrategy<String> _cleanStrategy;
    private final ValidationStrategy<String> _validateStrategy;

    public PatternValidationStrategies(String acceptedPattern) {
        _cleanStrategy =
            new ValidationStrategy<String>(new HtmlAndQueryStringCanonicalizer(), null, new StripHtmlAndCleanPatternSanitizer(acceptedPattern));