Home | History | Annotate | Download | only in exceptions
      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 
     17 package com.google.clearsilver.jsilver.exceptions;
     18 
     19 /**
     20  * Thrown when there is a problem applying auto escaping.
     21  */
     22 public class JSilverAutoEscapingException extends JSilverException {
     23 
     24   public static final int UNKNOWN_POSITION = -1;
     25 
     26   public JSilverAutoEscapingException(String message, String templateName, int line, int column) {
     27     super(createMessage(message, templateName, line, column));
     28   }
     29 
     30   public JSilverAutoEscapingException(String message, String templateName) {
     31     this(message, templateName, UNKNOWN_POSITION, UNKNOWN_POSITION);
     32   }
     33 
     34   /**
     35    * Keeping the same format as JSilverBadSyntaxException.
     36    */
     37   private static String createMessage(String message, String resourceName, int line, int column) {
     38     StringBuilder result = new StringBuilder(message);
     39     if (resourceName != null) {
     40       result.append(" resource=").append(resourceName);
     41     }
     42     if (line != UNKNOWN_POSITION) {
     43       result.append(" line=").append(line);
     44     }
     45     if (column != UNKNOWN_POSITION) {
     46       result.append(" column=").append(column);
     47     }
     48     return result.toString();
     49   }
     50 
     51   public JSilverAutoEscapingException(String message) {
     52     super(message);
     53   }
     54 
     55   public JSilverAutoEscapingException(String message, Throwable cause) {
     56     super(message, cause);
     57   }
     58 }
     59