1/* 2 * Copyright (C) 2010 Google Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.google.clearsilver.jsilver.functions.html; 18 19import com.google.clearsilver.jsilver.functions.escape.HtmlEscapeFunction; 20 21import java.io.IOException; 22 23/** 24 * Validates that a given string is a valid URI and return the HTML escaped string if it is. 25 * Otherwise the string {@code #} is returned. 26 * 27 * @see BaseUrlValidateFunction 28 */ 29public class HtmlUrlValidateFunction extends BaseUrlValidateFunction { 30 31 private final HtmlEscapeFunction htmlEscape; 32 33 /** 34 * isUnquoted should be true if the URL appears in an unquoted attribute. like: <a href=<?cs 35 * var: uri ?>> 36 */ 37 public HtmlUrlValidateFunction(boolean isUnquoted) { 38 htmlEscape = new HtmlEscapeFunction(isUnquoted); 39 } 40 41 protected void applyEscaping(String in, Appendable out) throws IOException { 42 htmlEscape.filter(in, out); 43 } 44} 45