Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed to the Apache Software Foundation (ASF) under one or more
   * contributor license agreements.  See the NOTICE file distributed with
   * this work for additional information regarding copyright ownership.
   * The ASF licenses this file to You 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 org.apache.jasper.tagplugins.jstl;
 
 import static org.jboss.web.JasperMessages.MESSAGES;
 
 
 
Util contains some often used consts, static methods and embedded class to support the JSTL tag plugin.
 
 
 public class Util {
     
     public static final String VALID_SCHEME_CHAR = 
         "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+.-";
     
     public static final String DEFAULT_ENCODING = 
         "ISO-8859-1";
     
     public static final int HIGHEST_SPECIAL = '>';
     
     public static char[][] specialCharactersRepresentation = new char[ + 1][];
     
     static {
         ['&'] = "&".toCharArray();
         ['<'] = "&lt;".toCharArray();
         ['>'] = "&gt;".toCharArray();
         ['"'] = "&#034;".toCharArray();
         ['\''] = "&#039;".toCharArray();
     }
    
    
Converts the given string description of a scope to the corresponding PageContext constant. The validity of the given scope has already been checked by the appropriate TLV.

Parameters:
scope String description of scope
Returns:
PageContext constant corresponding to given scope description taken from org.apache.taglibs.standard.tag.common.core.Util
 
     public static int getScope(String scope){
         int ret = .;
         
         if("request".equalsIgnoreCase(scope)){
             ret = .;
         }else if("session".equalsIgnoreCase(scope)){
             ret = .;
         }else if("application".equalsIgnoreCase(scope)){
             ret = .;
         }
         
         return ret;
     }
    
    
Returns true if our current URL is absolute, false otherwise. taken from org.apache.taglibs.standard.tag.common.core.ImportSupport
 
     public static boolean isAbsoluteUrl(String url){
         if(url == null){
             return false;
        }
        
        int colonPos = url.indexOf(":");
        if(colonPos == -1){
            return false;
        }
        
        for(int i=0;i<colonPos;i++){
            if(.indexOf(url.charAt(i)) == -1){
                return false;
            }
        }
        
        return true;
    }
    
    
Get the value associated with a content-type attribute. Syntax defined in RFC 2045, section 5.1. taken from org.apache.taglibs.standard.tag.common.core.Util
    public static String getContentTypeAttribute(String inputString name) {
        int begin;
        int end;
        int index = input.toUpperCase(.).indexOf(name.toUpperCase(.));
        if (index == -1) return null;
        index = index + name.length(); // positioned after the attribute name
        index = input.indexOf('='index); // positioned at the '='
        if (index == -1) return null;
        index += 1; // positioned after the '='
        input = input.substring(index).trim();
        
        if (input.charAt(0) == '"') {
            // attribute value is a quoted string
            begin = 1;
            end = input.indexOf('"'begin);
            if (end == -1) return null;
        } else {
            begin = 0;
            end = input.indexOf(';');
            if (end == -1) end = input.indexOf(' ');
            if (end == -1) end = input.length();
        }
        return input.substring(beginend).trim();
    }
    
    
Strips a servlet session ID from url. The session ID is encoded as a URL "path parameter" beginning with "jsessionid=". We thus remove anything we find between ";jsessionid=" (inclusive) and either EOS or a subsequent ';' (exclusive). taken from org.apache.taglibs.standard.tag.common.core.ImportSupport
    public static String stripSession(String url) {
        StringBuilder u = new StringBuilder(url);
        int sessionStart;
        while ((sessionStart = u.toString().indexOf(";" + . + "=")) != -1) {
            int sessionEnd = u.toString().indexOf(";"sessionStart + 1);
            if (sessionEnd == -1)
                sessionEnd = u.toString().indexOf("?"sessionStart + 1);
            if (sessionEnd == -1) 				// still
                sessionEnd = u.length();
            u.delete(sessionStartsessionEnd);
        }
        return u.toString();
    }
    
    
    
Performs the following substring replacements (to facilitate output to XML/HTML pages): & -> & < -> < > -> > " -> &#034; ' -> &#039; See also OutSupport.writeEscapedXml(). taken from org.apache.taglibs.standard.tag.common.core.Util
    public static String escapeXml(String buffer) {
        int start = 0;
        int length = buffer.length();
        char[] arrayBuffer = buffer.toCharArray();
        StringBuilder escapedBuffer = null;
        
        for (int i = 0; i < lengthi++) {
            char c = arrayBuffer[i];
            if (c <= ) {
                char[] escaped = [c];
                if (escaped != null) {
                    // create StringBuilder to hold escaped xml string
                    if (start == 0) {
                        escapedBuffer = new StringBuilder(length + 5);
                    }
                    // add unescaped portion
                    if (start < i) {
                        escapedBuffer.append(arrayBuffer,start,i-start);
                    }
                    start = i + 1;
                    // add escaped xml
                    escapedBuffer.append(escaped);
                }
            }
        }
        // no xml escaping was necessary
        if (start == 0) {
            return buffer;
        }
        // add rest of unescaped portion
        if (start < length) {
            escapedBuffer.append(arrayBuffer,start,length-start);
        }
        return escapedBuffer.toString();
    }
    
    
Utility methods taken from org.apache.taglibs.standard.tag.common.core.UrlSupport
    public static String resolveUrl(
            String urlString contextPageContext pageContext)
    throws JspException {
        // don't touch absolute URLs
        if (isAbsoluteUrl(url))
            return url;
        
        // normalize relative URLs against a context root
        HttpServletRequest request =
            (HttpServletRequestpageContext.getRequest();
        if (context == null) {
            if (url.startsWith("/"))
                return (request.getContextPath() + url);
            else
                return url;
        } else {
            if (!context.startsWith("/") || !url.startsWith("/")) {
                throw new JspTagException(.invalidContextAndUrlValues());
            }
            if (context.equals("/")) {
                // Don't produce string starting with '//', many
                // browsers interpret this as host name, not as
                // path on same host.
                return url;
            } else {
                return (context + url);
            }
        }
    }
    
    
Wraps responses to allow us to retrieve results as Strings. mainly taken from org.apache.taglibs.standard.tag.common.core.importSupport
    public static class ImportResponseWrapper extends HttpServletResponseWrapper{
        
        private StringWriter sw = new StringWriter();
        private ByteArrayOutputStream bos = new ByteArrayOutputStream();
        private ServletOutputStream sos = new ServletOutputStream() {
            public void write(int bthrows IOException {
                .write(b);
            }
        };
        private boolean isWriterUsed;
        private boolean isStreamUsed;
        private int status = 200;
        private String charEncoding;
        
        public ImportResponseWrapper(HttpServletResponse arg0) {
            super(arg0);
            // TODO Auto-generated constructor stub
        }
        
        public PrintWriter getWriter() {
            if ()
                throw .usedOutputStreamAfterWriter();
             = true;
            return new PrintWriter();
        }
        
        public ServletOutputStream getOutputStream() {
            if ()
                throw .usedWriterAfterOutputStream();
             = true;
            return ;
        }
        
        
Has no effect.
        public void setContentType(String x) {
            // ignore
        }
        
        
Has no effect.
        public void setLocale(Locale x) {
            // ignore
        }
        
        public void setStatus(int status) {
            this. = status;
        }
        
        public int getStatus() {
            return ;
        }
        
        public String getCharEncoding(){
            return this.;
        }
        
        public void setCharEncoding(String ce){
            this. = ce;
        }
        
        public String getString() throws UnsupportedEncodingException {
            if ()
                return .toString();
            else if () {
                if (this. != null && !this..equals(""))
                    return .toString();
                else
                    return .toString("ISO-8859-1");
            } else
                return "";		// target didn't write anything
        }
    }
    
New to GrepCode? Check out our FAQ X