Coverage Report - org.seasar.teeda.core.el.impl.JspELParserUtil
 
Classes in this File Line Coverage Branch Coverage Complexity
JspELParserUtil
88%
23/26
72%
13/18
3.667
 
 1  
 /*
 2  
  * Copyright 2004-2011 the Seasar Foundation and the Others.
 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,
 13  
  * either express or implied. See the License for the specific language
 14  
  * governing permissions and limitations under the License.
 15  
  */
 16  
 package org.seasar.teeda.core.el.impl;
 17  
 
 18  
 import javax.faces.el.ReferenceSyntaxException;
 19  
 
 20  
 import org.seasar.framework.exception.EmptyRuntimeException;
 21  
 
 22  
 /**
 23  
  * @author shot
 24  
  */
 25  
 public class JspELParserUtil {
 26  
 
 27  
     private static final String JSP_OPEN_BRACE = "${";
 28  
 
 29  
     private static final String JSP_CLOSE_BRACE = "}";
 30  
 
 31  0
     private JspELParserUtil() {
 32  0
     }
 33  
 
 34  
     public static String convertToJspExpression(final String expression) {
 35  201
         return convertToJspExpression(expression, "#{", "}");
 36  
     }
 37  
 
 38  
     public static String convertToJspExpression(final String expression,
 39  
             final String openBrace, final String closeBrace) {
 40  201
         if (expression == null) {
 41  1
             throw new EmptyRuntimeException("expression");
 42  
         }
 43  200
         if (openBrace == null || closeBrace == null) {
 44  0
             throw new ReferenceSyntaxException();
 45  
         }
 46  200
         String str = expression;
 47  200
         if (str.startsWith(openBrace) && str.indexOf(closeBrace) > 0) {
 48  77
             int pos = str.indexOf(closeBrace);
 49  77
             String s = str.substring(JSP_OPEN_BRACE.length(), pos);
 50  77
             String postfix = str.substring(pos + 1);
 51  77
             str = JSP_OPEN_BRACE + s + JSP_CLOSE_BRACE
 52  
                     + convertToJspExpression(postfix);
 53  
         } else {
 54  123
             int pos1 = str.indexOf(openBrace);
 55  123
             int pos2 = str.indexOf(closeBrace);
 56  123
             if (pos1 > 0) {
 57  28
                 if (pos2 > pos1) {
 58  24
                     String prefix = str.substring(0, pos1);
 59  24
                     String s = str.substring(pos1 + openBrace.length(), pos2);
 60  24
                     String postfix = str.substring(pos2 + 1);
 61  24
                     str = prefix + JSP_OPEN_BRACE + s + JSP_CLOSE_BRACE
 62  
                             + convertToJspExpression(postfix);
 63  4
                 } else if (pos2 >= 0 && pos2 <= pos1) {
 64  4
                     String prefix = str.substring(0, pos2 + 1);
 65  4
                     String s = str.substring(pos2 + 1);
 66  4
                     str = prefix + convertToJspExpression(s);
 67  
                 }
 68  
             }
 69  
         }
 70  200
         return str;
 71  
     }
 72  
 
 73  
 }