signature:
public class OperationVisit { /** * Method to call the visitor for the supplied { @ link Operation } and recursively calls itself , if the
 * { @ link Operation } is a { @ link CompositeOperation } . */
private void visit ( Operation operation , Visitor < Operation > visitor ) { } }

implementation: visitor . visit ( operation ) ; if ( operation instanceof CompositeOperation ) { if ( ( ( CompositeOperation ) operation ) . getOperations ( ) != null ) { for ( Operation child : ( ( CompositeOperation ) operation ) . getOperations ( ) ) { visit ( child , visitor ) ; } } }


signature:
public class ByteCodeFilter { /** * Checks whether that supplied { @ link InputStream } contains a Java class file that might contain references to
 * specific annotation types .
 * The caller of this method is responsible to close the supplied { @ link InputStream } . This method won ' t do it !
 * @ param classFileStream The stream to read the class file from .
 * @ return < code > true < / code > for files that contain at least one reference to one of the " interesting " annotations
 * @ throws IOException for any kind of IO problem */
@ SuppressWarnings ( "unused" ) public boolean accept ( InputStream classFileStream ) throws IOException { } }

implementation:
// open a DataInputStream
DataInputStream in = new DataInputStream ( classFileStream ) ; // read magic and abort if it doesn ' t match
int magic = in . readInt ( ) ; if ( magic != CLASS_FILE_MAGIC ) { if ( log . isDebugEnabled ( ) ) { log . debug ( "Magic not found! Not a valid class file!" ) ; } return false ; } // check for at least JDK 1.5
int minor = in . readUnsignedShort ( ) ; int major = in . readUnsignedShort ( ) ; if ( major < 49 ) { // JDK 1.4 or less
if ( log . isTraceEnabled ( ) ) { log . trace ( "Not a JDK5 class! It cannot contain annotations!" ) ; } return false ; } // this values is equal to the number entries in the constants pool + 1
int constantPoolEntries = in . readUnsignedShort ( ) - 1 ; // loop over all entries in the constants pool
for ( int i = 0 ; i < constantPoolEntries ; i ++ ) { // the tag to identify the record type
int tag = in . readUnsignedByte ( ) ; // process record according to its type
switch ( tag ) { case CONSTANT_Class : /* * CONSTANT _ Class _ info {
 * u1 tag ;
 * u2 name _ index ; */
in . readUnsignedShort ( ) ; break ; case CONSTANT_Fieldref : case CONSTANT_Methodref : case CONSTANT_InterfaceMethodref : /* * CONSTANT _ [ Fieldref | Methodref | InterfaceMethodref ] _ info {
 * u1 tag ;
 * u2 class _ index ;
 * u2 name _ and _ type _ index ; */
in . readUnsignedShort ( ) ; in . readUnsignedShort ( ) ; break ; case CONSTANT_String : /* * CONSTANT _ String _ info {
 * u1 tag ;
 * u2 string _ index ; */
in . readUnsignedShort ( ) ; break ; case CONSTANT_Integer : case CONSTANT_Float : /* * CONSTANT _ [ Integer | Float ] _ info {
 * u1 tag ;
 * u4 bytes ; */
in . readInt ( ) ; break ; case CONSTANT_Long : case CONSTANT_Double : /* * CONSTANT _ Long _ info {
 * u1 tag ;
 * u4 high _ bytes ;
 * u4 low _ bytes ; */
in . readLong ( ) ; /* * We must increase the constant pool index because this tag
 * type takes two entries */
i ++ ; break ; case CONSTANT_NameAndType : /* * CONSTANT _ NameAndType _ info {
 * u1 tag ;
 * u2 name _ index ;
 * u2 descriptor _ index ; */
in . readUnsignedShort ( ) ; in . readUnsignedShort ( ) ; break ; case CONSTANT_Utf8 : /* * CONSTANT _ Utf8 _ info {
 * u1 tag ;
 * u2 length ;
 * u1 bytes [ length ] ; */
String str = in . readUTF ( ) ; // check if this string sounds interesting
if ( containsFieldDescriptor ( str ) ) { if ( log . isTraceEnabled ( ) ) { log . trace ( "Found interesting annotation reference in constant pool: " + str ) ; } return true ; } break ; case CONSTANT_MethodHandle : /* * CONSTANT _ MethodHandle _ info {
 * u1 tag ;
 * u1 reference _ kind ;
 * u2 reference _ index ; */
in . readByte ( ) ; in . readShort ( ) ; break ; case CONSTANT_MethodType : /* * CONSTANT _ MethodType _ info {
 * u1 tag ;
 * u2 descriptor _ index ; */
in . readShort ( ) ; break ; case CONSTANT_InvokeDynamic : /* * CONSTANT _ InvokeDynamic _ info {
 * u1 tag ;
 * u2 bootstrap _ method _ attr _ index ;
 * u2 name _ and _ type _ index ; */
in . readShort ( ) ; in . readShort ( ) ; break ; default : /* * Unknown tag ! Should not happen ! We will scan the class in this case . */
if ( log . isDebugEnabled ( ) ) { log . debug ( "Unknown constant pool tag found: " + tag ) ; } return true ; } } return false ;


signature:
public class ByteCodeFilter { /** * Returns true if the given string contains a field descriptor of one of the annotations we are looking for . */
private boolean containsFieldDescriptor ( String str ) { } }

implementation: for ( String descriptor : fieldDescriptors ) { if ( str . contains ( descriptor ) ) { return true ; } } return false ;


signature:
public class URL { /** * Create a { @ link Condition } that inspects the entire value of the current { @ link Address } , comparing against the
 * given pattern .
 * The given pattern may be parameterized :
 * < b > INBOUND : < / b > < br >
 * < code >
 * / path / store ? item = 1436
 * / path / store ? item = { itemId } < br >
 * / path / { store } ? item = { itemId } & category = { catId } < br >
 * < / code >
 * < b > OUTBOUND : < / b > < br >
 * < code >
 * http : / / domain . com / path / store . html ? item = 1436
 * http : / / domain . com / path / store ? item = { itemId } < br >
 * / path / { store } ? item = { itemId } & category = { catId } < br >
 * < / code >
 * @ param url { @ link ParameterizedPattern } to which the current { @ link Address } must match .
 * @ see { @ link ConfigurationRuleParameterBuilder # where ( String ) } */
public static URL matches ( final String pattern ) { } }

implementation: return new URL ( pattern ) { @ Override public String toString ( ) { return "URL.matches(\"" + pattern + "\")" ; } } ;


signature:
public class URL { /** * Create a { @ link Condition } to capture the entire value of the current { @ link Address } into the given
 * { @ link Parameter } name . This { @ link Parameter } may be referenced in other { @ link Condition } and { @ link Operation }
 * instances within the current { @ link Rule } .
 * @ see ConfigurationRuleParameterBuilder # where ( String ) */
public static URL captureIn ( final String param ) { } }

implementation: URL path = new URL ( "{" + param + "}" ) { @ Override public String toString ( ) { return "URL.captureIn(\"" + param + "\")" ; } } ; return path ;


signature:
public class Path { /** * Create a { @ link Condition } that compares the current { @ link Address # getPath ( ) } to the given pattern .
 * The given pattern may be parameterized :
 * < code >
 * / example / { param } < br >
 * / example / { param1 } / sub / { param2 } < br >
 * < / code >
 * @ param pattern { @ link ParameterizedPattern } matching the path .
 * @ see ConfigurationRuleParameterBuilder # where ( String ) */
public static Path matches ( final String pattern ) { } }

implementation: return new Path ( pattern ) { @ Override public String toString ( ) { return "Path.matches(\"" + pattern + "\")" ; } } ;


signature:
public class Path { /** * Capture the entire path portion of the { @ link Address } into the given { @ link Parameter } .
 * @ param param the name of the { @ link Parameter } to which the entire path portion of the { @ link Address } will be
 * bound . */
public static Path captureIn ( final String param ) { } }

implementation: Path path = new Path ( "{" + param + "}" ) { @ Override public String toString ( ) { return "Path.captureIn(\"" + param + "\")" ; } } ; path . captureIn = param ; return path ;


signature:
public class PrettyConfigReloader { /** * Detects the PrettyFaces development mode using the { @ link DevelopmentModeDetector } SPI . */
private boolean isDevelopmentModeActive ( ServletContext servletContext ) { } }

implementation:
// create the ServiceLoader for the SPI
ServiceLoader < DevelopmentModeDetector > serviceLoader = ServiceLoader . loadTypesafe ( DevelopmentModeDetector . class ) ; // we need a list to be able to sort it
List < DevelopmentModeDetector > detectors = new ArrayList < DevelopmentModeDetector > ( ) ; for ( DevelopmentModeDetector detector : serviceLoader ) { detectors . add ( detector ) ; } // sort them by priority
Collections . sort ( detectors , new Comparator < DevelopmentModeDetector > ( ) { public int compare ( DevelopmentModeDetector left , DevelopmentModeDetector right ) { return left . getPriority ( ) - right . getPriority ( ) ; } } ) ; // process the detectors until one returns a result ! = null
for ( DevelopmentModeDetector detector : detectors ) { Boolean result = detector . isDevelopmentMode ( servletContext ) ; if ( log . isDebugEnabled ( ) ) { log . debug ( "Detector " + detector . getClass ( ) . getSimpleName ( ) + " returned: " + result ) ; } if ( result != null ) { return result . booleanValue ( ) ; } } // default value
return false ;


signature:
public class AddressBuilderDomain { /** * Set a parameter name and value or values . The supplied values will be stored without additional encoding . */
public AddressBuilderDomain set ( CharSequence name , Object ... values ) { } }

implementation: parent . set ( name , values ) ; return this ;


signature:
public class AddressBuilderDomain { /** * Set a parameter name and value or values . The values will be decoded before they are stored . */
public AddressBuilderDomain setDecoded ( CharSequence name , Object ... values ) { } }

implementation: parent . setDecoded ( name , values ) ; return this ;


signature:
public class AddressBuilderDomain { /** * Set a parameter name and value or values . The values will be encoded before they are stored . */
public AddressBuilderDomain setEncoded ( CharSequence name , Object ... values ) { } }

implementation: parent . setEncoded ( name , values ) ; return this ;


signature:
public class ProxyServlet { /** * Copy proxied response headers back to the servlet client . */
protected void copyResponseHeaders ( HttpResponse proxyResponse , HttpServletResponse servletResponse ) { } }

implementation: for ( Header header : proxyResponse . getAllHeaders ( ) ) { if ( hopByHopHeaders . containsHeader ( header . getName ( ) ) ) continue ; servletResponse . addHeader ( header . getName ( ) , header . getValue ( ) ) ; }


signature:
public class ProxyServlet { /** * Copy response body data ( the entity ) from the proxy to the servlet client . */
protected void copyResponseEntity ( HttpResponse proxyResponse , HttpServletResponse servletResponse ) throws IOException { } }

implementation: HttpEntity entity = proxyResponse . getEntity ( ) ; if ( entity != null ) { OutputStream servletOutputStream = servletResponse . getOutputStream ( ) ; try { entity . writeTo ( servletOutputStream ) ; } finally { closeQuietly ( servletOutputStream ) ; } }


signature:
public class ProxyServlet { /** * For a redirect response from the target server , this translates { @ code theUrl } to redirect to and translates it to
 * one the original client can use . */
protected String rewriteUrlFromResponse ( HttpServletRequest servletRequest , String theUrl ) { } }

implementation:
/* * TODO document example paths */
if ( theUrl . startsWith ( targetUri ) ) { String curUrl = servletRequest . getRequestURL ( ) . toString ( ) ; // no query
String pathInfo = servletRequest . getPathInfo ( ) ; if ( pathInfo != null ) { assert curUrl . endsWith ( pathInfo ) ; curUrl = curUrl . substring ( 0 , curUrl . length ( ) - pathInfo . length ( ) ) ; // take pathInfo off
} theUrl = curUrl + theUrl . substring ( targetUri . length ( ) ) ; } return theUrl ;


signature:
public class ProxyServlet { /** * Encodes characters in the query or fragment part of the URI .
 * Unfortunately , an incoming URI sometimes has characters disallowed by the spec . HttpClient insists that the
 * outgoing proxied request has a valid URI because it uses Java ' s { @ link URI } . To be more forgiving , we must escape
 * the problematic characters . See the URI class for the spec .
 * @ param in example : name = value & foo = bar # fragment */
protected static CharSequence encodeUriQuery ( CharSequence in ) { } }

implementation:
/* * Note that I can ' t simply use URI . java to encode because it will escape pre - existing escaped things . TODO :
 * replace / compare to with Rewrite Encoding */
StringBuilder outBuf = null ; Formatter formatter = null ; for ( int i = 0 ; i < in . length ( ) ; i ++ ) { char c = in . charAt ( i ) ; boolean escape = true ; if ( c < 128 ) { if ( asciiQueryChars . get ( c ) ) { escape = false ; } } else if ( ! Character . isISOControl ( c ) && ! Character . isSpaceChar ( c ) ) { /* * not - ascii */
escape = false ; } if ( ! escape ) { if ( outBuf != null ) outBuf . append ( c ) ; } else { /* * escape */
if ( outBuf == null ) { outBuf = new StringBuilder ( in . length ( ) + 5 * 3 ) ; outBuf . append ( in , 0 , i ) ; formatter = new Formatter ( outBuf ) ; } /* * leading % , 0 padded , width 2 , capital hex */
formatter . format ( "%%%02X" , ( int ) c ) ; // TODO
} } return outBuf != null ? outBuf : in ;


signature:
public class CdiExpressionLanguageProvider { /** * Helpers */
private Class < ? > getExpectedType ( final ELContext context , final ExpressionFactory factory , final String expression ) throws ELException { } }

implementation: ValueExpression ve = factory . createValueExpression ( context , expression , Object . class ) ; return ve . getType ( context ) ;


signature:
public class URLBuilder { /** * Create a new instance of { @ link URLBuilder } from the given URL segments , { @ link Metadata } , and
 * { @ link QueryStringBuilder } . */
public static URLBuilder createFrom ( final List < String > segments , final Metadata metadata , final QueryStringBuilder query ) { } }

implementation: return URLBuilder . createNew ( ) . appendPathSegments ( segments ) . setMetadata ( metadata ) . setQueryString ( query ) ;


signature:
public class URLBuilder { /** * Create a new instance of { @ link URLBuilder } from the given URL path segments and { @ link Metadata } . */
public static URLBuilder createFrom ( final List < String > segments , final Metadata metadata ) { } }

implementation: return URLBuilder . createNew ( ) . appendPathSegments ( segments ) . setMetadata ( metadata ) ;


signature:
public class URLBuilder { /** * Create a new instance of { @ link URLBuilder } from the given URL path segments . */
public static URLBuilder createFrom ( final String segments ) { } }

implementation: if ( segments == null ) { throw new IllegalArgumentException ( "URL cannot be null." ) ; } if ( segments . contains ( "?" ) ) { String [ ] parts = segments . split ( "\\?" , - 1 ) ; String path = parts [ 0 ] ; String query = parts [ 1 ] ; if ( parts . length > 2 ) { query = Strings . join ( Arrays . asList ( Arrays . copyOfRange ( parts , 1 , parts . length ) ) , "?" ) ; } return new URLBuilder ( ) . appendPathSegments ( path ) . addQueryParameters ( query ) ; } return new URLBuilder ( ) . appendPathSegments ( segments ) ;


signature:
public class URLBuilder { /** * Append additional path segments to the end of this URL . When called the first time , this method will also
 * initialize the { @ link Metadata } for this { @ link URLBuilder } based on the parsed segments given . */
public URLBuilder appendPathSegments ( final String segments ) { } }

implementation:
if ( segments != null ) { String temp = segments . trim ( ) ; // Only initialize the leading slash when adding the first path segments
if ( temp . startsWith ( "/" ) && this . segments . isEmpty ( ) ) { metadata . setLeadingSlash ( true ) ; } if ( temp . endsWith ( "/" ) ) { metadata . setTrailingSlash ( true ) ; } String trimmedUrl = trimSurroundingSlashes ( segments ) ; // We reproduce this when building the URL by storing a single empty segment
if ( ! trimmedUrl . isEmpty ( ) || "//" . equals ( segments ) ) { String [ ] newSegments = trimmedUrl . split ( "/" , - 1 ) ; this . segments . addAll ( Arrays . asList ( newSegments ) ) ; } } else { throw new IllegalArgumentException ( "URL cannot be null." ) ; } return this ;


signature:
public class URLBuilder { /** * Return a URI representation of this URL including path and query string */
public URI toURI ( ) { } }

implementation: try { URI uri = new URI ( toURL ( ) ) ; return uri ; } catch ( URISyntaxException e ) { throw new IllegalStateException ( "URL cannot be parsed." , e ) ; }


signature:
public class URLBuilder { /** * Helpers */
private String trimSurroundingSlashes ( final String url ) { } }

implementation: String result = null ; if ( url != null ) { result = url . trim ( ) ; if ( result . startsWith ( "/" ) ) { result = result . substring ( 1 ) ; } if ( result . endsWith ( "/" ) ) { result = result . substring ( 0 , result . length ( ) - 1 ) ; } } return result ;


signature:
public class PhaseOperation { /** * Create an { @ link Operation } that will enqueue a given { @ link Operation } to be performed before or after one or
 * more JavaServer Faces { @ link PhaseId } instances specified via { @ link # before ( PhaseId . . . ) } or
 * { @ link # after ( PhaseId . . . ) } . */
@ SuppressWarnings ( "rawtypes" ) public static PhaseOperation < ? > enqueue ( final Operation operation , final int priority ) { } }

implementation: return new PhaseOperation ( ) { @ Override public int priority ( ) { return priority ; } @ Override public void performOperation ( HttpServletRewrite event , EvaluationContext context ) { operation . perform ( event , context ) ; } @ Override public String toString ( ) { return "PhaseOperation.enqueue(" + operation + ", " + priority + ")" ; } } ;


signature:
public class PhaseOperation { /** * Perform this { @ link PhaseOperation } before the given phases ( Except { @ link PhaseId # RESTORE _ VIEW } ) . The deferred
 * { @ link Operation } will be performed once for each { @ link PhaseId } provided . */
@ SuppressWarnings ( "unchecked" ) public T before ( final PhaseId ... phases ) { } }

implementation: if ( phases != null ) this . beforePhases . addAll ( Arrays . asList ( phases ) ) ; return ( T ) this ;


signature:
public class PhaseOperation { /** * Perform this { @ link PhaseOperation } after the given phases ( Except { @ link PhaseId # RENDER _ RESPONSE } ) . The deferred
 * { @ link Operation } will be performed once for each { @ link PhaseId } provided . */
@ SuppressWarnings ( "unchecked" ) public T after ( final PhaseId ... phases ) { } }

implementation: if ( phases != null ) this . afterPhases . addAll ( Arrays . asList ( phases ) ) ; return ( T ) this ;


signature:
public class Expressions { /** * Evaluate a { @ link ValueExpression } .
 * A { @ link ValueExpression } is created by calling
 * { @ link ExpressionFactory # createValueExpression ( ELContext , String , Class ) } and then
 * { @ link ValueExpression # getValue ( ELContext ) } is called to obtain the value . For more details on the semantics of
 * EL , refer to the javadoc for these classes and methods .
 * @ param < T > the type of the evaluated expression
 * @ param expression the expression to evaluate
 * @ param expectedType the expected type of the evaluated expression
 * @ return the result of evaluating the expression
 * @ throws NullPointerException if expectedType is < code > null < / code >
 * @ throws ELException if there are syntactical errors in the provided expression or if an exception was thrown while
 * performing property or variable resolution . The thrown exception will be included as the cause property
 * of this exception , if available .
 * @ throws PropertyNotFoundException if one of the property resolutions failed because a specified variable or
 * property does not exist or is not readable .
 * @ throws ClassCastException if the result cannot be cast to the expected type
 * @ see ExpressionFactory # createValueExpression ( ELContext , String , Class )
 * @ see ValueExpression # getValue ( ELContext ) */
public < T > T evaluateValueExpression ( String expression , Class < T > expectedType ) { } }

implementation: Object result = expressionFactory . createValueExpression ( context , expression , expectedType ) . getValue ( context ) ; if ( result != null ) { return expectedType . cast ( result ) ; } else { return null ; }


signature:
public class Expressions { /** * Evaluate a { @ link ValueExpression } inferring the return type .
 * A { @ link ValueExpression } is created by calling
 * { @ link ExpressionFactory # createValueExpression ( ELContext , String , Class ) } and then
 * { @ link ValueExpression # getValue ( ELContext ) } is called to obtain the value . For more details on the semantics of
 * EL , refer to the javadoc for these methods .
 * @ param < T > the type of the evaluated expression
 * @ param expression expression the expression to evaluate
 * @ return the result of evaluating the expression
 * @ throws ELException if there are syntactical errors in the provided expression
 * @ throws ELException if an exception was thrown while performing property or variable resolution . The thrown
 * exception will be included as the cause property of this exception , if available .
 * @ throws PropertyNotFoundException if one of the property resolutions failed because a specified variable or
 * property does not exist or is not readable
 * @ throws ClassCastException if the result cannot be cast to < code > T < / code >
 * @ see ExpressionFactory # createValueExpression ( ELContext , String , Class )
 * @ see ValueExpression # getValue ( ELContext ) */
public < T > T evaluateValueExpression ( String expression ) { } }

implementation: Object result = evaluateValueExpression ( expression , Object . class ) ; if ( result != null ) { return Reflections . < T > cast ( result ) ; } else { return null ; }


signature:
public class Expressions { /** * Evaluate a { @ link MethodExpression } , passing arguments and argument types to the method .
 * A { @ link MethodExpression } is created by calling
 * { @ link ExpressionFactory # createMethodExpression ( ELContext , String , Class , Class [ ] ) } and then
 * { @ link MethodExpression # invoke ( ELContext , Object [ ] ) } is called to obtain the value . For more details on the
 * semantics of EL , refer to the javadoc for these methods .
 * @ param < T > the type of the evaluated expression
 * @ param expression expression the expression to evaluate
 * @ param expectedReturnType the expected return type of the evaluated expression
 * @ param params arguments to the method
 * @ param expectedParamTypes of the arguments to the method
 * @ return the result of evaluating the expression
 * @ throws ClassCastException if the result cannot be cast to < code > expectedReturnType < / code >
 * @ throws ELException if there are syntactical errors in the provided expression .
 * @ throws NullPointerException if < code > expectedParamTypes < / code > is < code > null < / code > .
 * @ throws PropertyNotFoundException if one of the property resolutions failed because a specified variable or
 * property does not exist or is not readable .
 * @ throws MethodNotFoundException if no suitable method can be found .
 * @ throws ELException if a String literal is specified and expectedReturnType of the MethodExpression is void or if
 * the coercion of the String literal to the expectedReturnType yields an error ( see Section
 * " 1.18 Type Conversion " ) .
 * @ throws ELException if an exception was thrown while performing property or variable resolution . The thrown
 * exception must be included as the cause property of this exception , if available . If the exception
 * thrown is an < code > InvocationTargetException < / code > , extract its < code > cause < / code > and pass it to the
 * < code > ELException < / code > constructor .
 * @ see MethodExpression # invoke ( ELContext , Object [ ] )
 * @ see ExpressionFactory # createMethodExpression ( ELContext , String , Class , Class [ ] ) */
public < T > T evaluateMethodExpression ( String expression , Class < T > expectedReturnType , Object [ ] params , Class < ? > [ ] expectedParamTypes ) { } }

implementation: Object result = expressionFactory . createMethodExpression ( context , expression , expectedReturnType , expectedParamTypes ) . invoke ( context , params ) ; if ( result != null ) { return expectedReturnType . cast ( result ) ; } else { return null ; }


signature:
public class Expressions { /** * Evaluate a { @ link MethodExpression } with no parameters .
 * A { @ link MethodExpression } is created by calling
 * { @ link ExpressionFactory # createMethodExpression ( ELContext , String , Class , Class [ ] ) } and then
 * { @ link MethodExpression # invoke ( ELContext , Object [ ] ) } is called to obtain the value . For more details on the
 * semantics of EL , refer to the javadoc for these methods .
 * @ param < T > the type of the evaluated expression
 * @ param expression expression the expression to evaluate
 * @ param expectedReturnType the expected return type of the evaluated expression
 * @ return the result of evaluating the expression
 * @ throws ClassCastException if the result cannot be cast to < code > expectedReturnType < / code >
 * @ throws ELException if there are syntactical errors in the provided expression .
 * @ throws NullPointerException if < code > expectedParamTypes < / code > is < code > null < / code > .
 * @ throws PropertyNotFoundException if one of the property resolutions failed because a specified variable or
 * property does not exist or is not readable .
 * @ throws MethodNotFoundException if no suitable method can be found .
 * @ throws ELException if a String literal is specified and expectedReturnType of the MethodExpression is void or if
 * the coercion of the String literal to the expectedReturnType yields an error ( see Section
 * " 1.18 Type Conversion " ) .
 * @ throws ELException if an exception was thrown while performing property or variable resolution . The thrown
 * exception must be included as the cause property of this exception , if available . If the exception
 * thrown is an < code > InvocationTargetException < / code > , extract its < code > cause < / code > and pass it to the
 * < code > ELException < / code > constructor .
 * @ see MethodExpression # invoke ( ELContext , Object [ ] )
 * @ see ExpressionFactory # createMethodExpression ( ELContext , String , Class , Class [ ] ) */
public < T > T evaluateMethodExpression ( String expression , Class < T > expectedReturnType ) { } }

implementation: return evaluateMethodExpression ( expression , expectedReturnType , new Object [ 0 ] , new Class [ 0 ] ) ;


signature:
public class Expressions { /** * Evaluate a { @ link MethodExpression } , passing arguments to the method . The types of the arguments are discoverted
 * from the arguments , and the return type is inferred .
 * A { @ link MethodExpression } is created by calling
 * { @ link ExpressionFactory # createMethodExpression ( ELContext , String , Class , Class [ ] ) } and then
 * { @ link MethodExpression # invoke ( ELContext , Object [ ] ) } is called to obtain the value . For more details on the
 * semantics of EL , refer to the javadoc for these methods .
 * @ param < T > the type of the evaluated expression
 * @ param expression expression the expression to evaluate
 * @ param params arguments to the method
 * @ return the result of evaluating the expression
 * @ throws ClassCastException if the result cannot be cast to < code > T < / code >
 * @ throws ELException if there are syntactical errors in the provided expression .
 * @ throws NullPointerException if < code > expectedParamTypes < / code > is < code > null < / code > .
 * @ throws PropertyNotFoundException if one of the property resolutions failed because a specified variable or
 * property does not exist or is not readable .
 * @ throws MethodNotFoundException if no suitable method can be found .
 * @ throws ELException if a String literal is specified and expectedReturnType of the MethodExpression is void or if
 * the coercion of the String literal to the expectedReturnType yields an error ( see Section
 * " 1.18 Type Conversion " ) .
 * @ throws ELException if an exception was thrown while performing property or variable resolution . The thrown
 * exception must be included as the cause property of this exception , if available . If the exception
 * thrown is an < code > InvocationTargetException < / code > , extract its < code > cause < / code > and pass it to the
 * < code > ELException < / code > constructor .
 * @ see MethodExpression # invoke ( ELContext , Object [ ] )
 * @ see ExpressionFactory # createMethodExpression ( ELContext , String , Class , Class [ ] ) */
public < T > T evaluateMethodExpression ( String expression , Object ... params ) { } }

implementation: Object result = evaluateMethodExpression ( expression , Object . class , params , new Class [ params . length ] ) ; if ( result != null ) { return Reflections . < T > cast ( result ) ; } else { return null ; }


signature:
public class QueryString { /** * Build a query string from the given map of name = value pairs . For parameters with more than one value , each value
 * will be appended using the same name . */
public static QueryString build ( final Map < String , String [ ] > params ) { } }

implementation: QueryString queryString = new QueryString ( ) ; queryString . addParameters ( params ) ; return queryString ;


signature:
public class QueryString { /** * Build a query string from the given list of { @ link RequestParameter } objects . */
public static < T extends RequestParameter > QueryString build ( final List < T > params ) { } }


signature:
public class QueryString { /** * Build a query string from the given URL . If a ' ? ' character is encountered in the URL , the any characters up to
 * and including the first ' ? ' will be ignored . */
public static QueryString build ( final String url ) { } }

implementation: QueryString queryString = new QueryString ( ) ; queryString . addParameters ( url ) ; return queryString ;


signature:
public class QueryString { /** * Get the first value of given parameter name .
 * @ return The value of the parameter , null if the parameter does not exist , or " " if the parameter exists but has no
 * values . */
public String getParameter ( final String name ) { } }

implementation: List < String > values = parameters . get ( name ) ; if ( values == null ) { return null ; } if ( values . size ( ) == 0 ) { return "" ; } return values . get ( 0 ) ;


signature:
public class QueryString { /** * Get the array of values for a given parameter name .
 * @ return The values of the parameter , null if the parameter does not exist . */
public String [ ] getParameterValues ( final String name ) { } }

implementation: List < String > values = parameters . get ( name ) ; if ( values == null ) { return null ; } return values . toArray ( new String [ values . size ( ) ] ) ;


signature:
public class QueryString { /** * Get the name , values [ ] map representing this query string . */
public Map < String , String [ ] > getParameterMap ( ) { } }

implementation: Map < String , String [ ] > map = new TreeMap < String , String [ ] > ( ) ; for ( Map . Entry < String , List < String > > entry : parameters . entrySet ( ) ) { List < String > list = entry . getValue ( ) ; String [ ] values ; if ( list == null ) { values = null ; } else { values = list . toArray ( new String [ list . size ( ) ] ) ; } map . put ( entry . getKey ( ) , values ) ; } return map ;


signature:
public class QueryString { /** * Add query parameters from the given list of { @ link RequestParameter } objects . If a parameter already exists ,
 * append new values to the existing list of values for that parameter . */
public < T extends RequestParameter > void addParameters ( final List < T > params ) { } }

implementation: for ( RequestParameter rp : params ) { String value = rp . getValue ( ) ; String name = rp . getName ( ) ; if ( ! parameters . containsKey ( name ) ) { ArrayList < String > values = new ArrayList < String > ( ) ; if ( value != null ) { values . add ( value ) ; } parameters . put ( name , values ) ; } else { parameters . get ( name ) . add ( value ) ; } }


signature:
public class QueryString { /** * Add parameters from the given map of name = value pairs . For parameters with more than one value , each value will be
 * appended using the same name . If a parameter already exists , append new values to the existing list of values for
 * that parameter . */
public void addParameters ( final Map < String , String [ ] > params ) { } }

implementation: if ( params != null ) { for ( Entry < String , String [ ] > entry : params . entrySet ( ) ) { List < String > values = null ; if ( entry . getValue ( ) != null ) { values = Arrays . asList ( entry . getValue ( ) ) ; } parameters . put ( entry . getKey ( ) , values ) ; } }


signature:
public class QueryString { /** * Add parameters from the given URL . If a ' ? ' character is encountered in the URL , the any characters up to and
 * including the first ' ? ' will be ignored . If a parameter already exists , append new values to the existing list of
 * values for that parameter . */
public void addParameters ( String url ) { } }

implementation:
if ( ( url != null ) && ! "" . equals ( url ) ) { url = url . trim ( ) ; if ( url . length ( ) > 1 ) { if ( url . contains ( "?" ) ) { url = url . substring ( url . indexOf ( '?' ) + 1 ) ; } String pairs [ ] = url . split ( "&(amp;)?" ) ; for ( String pair : pairs ) { String name ; String value ; int pos = pair . indexOf ( '=' ) ; // for " n = " , the value is " " , for " n " , the value is null
if ( pos == - 1 ) { name = pair ; value = null ; } else { try { // FIXME This probably shouldn ' t be happening here .
name = URLDecoder . decode ( pair . substring ( 0 , pos ) , "UTF-8" ) ; value = URLDecoder . decode ( pair . substring ( pos + 1 , pair . length ( ) ) , "UTF-8" ) ; } catch ( IllegalArgumentException e ) { // thrown by URLDecoder if character decoding fails
log . warn ( "Ignoring invalid query parameter: " + pair ) ; continue ; } catch ( UnsupportedEncodingException e ) { throw new PrettyException ( "UTF-8 encoding not supported. Something is seriously wrong with your environment." ) ; } } List < String > list = parameters . get ( name ) ; if ( list == null ) { list = new ArrayList < String > ( ) ; parameters . put ( name , list ) ; } list . add ( value ) ; } } } return ;


signature:
public class QueryString { /** * Convert the current parameters to a valid query string , including the leading ' ? ' character . This method
 * automatically URLEncodes query - parameter values
 * For example , a { @ link QueryString } with the values [ key = > value , name = > value1 , value2 , value3 ] will become :
 * < pre >
 * ? key = value & name = value1 & name = value2 & name = value3
 * < / pre >
 * @ return If parameters exist , return a valid query string with leading ' ? ' character . If no parameters exist ,
 * return an empty string . */
public String toQueryString ( ) { } }

implementation: try { StringBuffer result = new StringBuffer ( ) ; if ( ( null != parameters ) && ! parameters . isEmpty ( ) ) { result . append ( "?" ) ; Iterator < Entry < String , List < String > > > iterator = parameters . entrySet ( ) . iterator ( ) ; while ( iterator . hasNext ( ) ) { Entry < String , List < String > > entry = iterator . next ( ) ; String key = entry . getKey ( ) ; List < String > values = entry . getValue ( ) ; if ( ( key != null ) && ! "" . equals ( key ) ) { key = URLEncoder . encode ( key , "UTF-8" ) ; result . append ( key ) ; if ( ( values != null ) && ! values . isEmpty ( ) ) { for ( int i = 0 ; i < values . size ( ) ; i ++ ) { String value = values . get ( i ) ; if ( ( value != null ) && ! "" . equals ( value ) ) { value = URLEncoder . encode ( value , "UTF-8" ) ; result . append ( "=" + value ) ; } else if ( ( value != null ) && "" . equals ( value ) ) { result . append ( "=" ) ; } if ( i < values . size ( ) - 1 ) { result . append ( "&" + key ) ; } } } } if ( iterator . hasNext ( ) ) { result . append ( "&" ) ; } } } return result . toString ( ) ; } catch ( UnsupportedEncodingException e ) { throw new PrettyException ( "Error building query string." , e ) ; }


signature:
public class SendStatus { /** * Create an { @ link Operation } that will send an HTTP error code to the browser , then call
 * { @ link HttpInboundServletRewrite # abort ( ) } */
public static SendStatus error ( final int code ) { } }

implementation: return new SendError ( code , null ) { @ Override public String toString ( ) { return "SendStatus.error(" + code + ")" ; } } ;


signature:
public class SendStatus { /** * Create an { @ link Operation } that will send an HTTP error code and message to the browser , then call
 * { @ link HttpInboundServletRewrite # abort ( ) } */
public static SendStatus error ( final int code , final String message ) { } }

implementation: return new SendError ( code , message ) { @ Override public String toString ( ) { return "SendStatus.error(" + code + ", \"" + message + "\")" ; } } ;


signature:
public class RewriteViewHandler { /** * < b > NOTE : < / b > This method should only be used by the getBookmarkableURL and getActionURL methods , for the purposes
 * of rewriting form URLs ( which do not include viewParameters . )
 * @ return Bookmarkable state - defaults to false if not previously set ; */
private boolean isBookmarkable ( ) { } }

implementation: Boolean result = bookmarkable . get ( ) ; if ( result == null ) { result = false ; bookmarkable . set ( result ) ; } return result ;


signature:
public class RewriteViewHandler { /** * Canonicalize the given viewId , then pass that viewId to the next ViewHandler in the chain . */
@ Override public String deriveViewId ( final FacesContext context , final String rawViewId ) { } }

implementation: String canonicalViewId = new URLDuplicatePathCanonicalizer ( ) . canonicalize ( rawViewId ) ; return parent . deriveViewId ( context , canonicalViewId ) ;


signature:
public class UrlMapping { /** * Get this patterns pattern parser instance . */
public URLPatternParser getPatternParser ( ) { } }

implementation: if ( ( parser == null ) && ( pattern != null ) ) { this . parser = new URLPatternParser ( pattern ) ; } return parser ;


signature:
public class UrlMapping { /** * Return a list of validators that belong to the given parameter . */
public List < PathValidator > getValidatorsForPathParam ( final PathParameter param ) { } }

implementation: List < PathValidator > result = new ArrayList < PathValidator > ( ) ; for ( PathValidator pv : pathValidators ) { if ( pv . getIndex ( ) == param . getPosition ( ) ) { result . add ( pv ) ; } } return result ;


signature:
public class FacesConverter { /** * Create a { @ link Converter } adapter for the given target type . The converter will use
 * { @ link Application # createConverter ( Class ) } to obtain the underlying JSF converter . */
public static < T > FacesConverter < T > forType ( Class < ? > targetType ) { } }

implementation: return new FacesConverter < T > ( null , targetType ) ;


signature:
public class FacesConverter { /** * Create a { @ link Converter } with the given ID . The converter will use { @ link Application # createConverter ( String ) ) }
 * to obtain the underlying JSF converter . */
public static < T > FacesConverter < T > forId ( String converterId ) { } }

implementation: return new FacesConverter < T > ( converterId , null ) ;


signature:
public class URLDuplicatePathCanonicalizer { /** * Canonicalize a given URL , replacing relative path structures with the
 * condensed path . ( Eg . / xxxx / . . / xxxx / = > / xxxx / )
 * @ return Return the canonicalized URL . If the URL requires no
 * canonicalization , return the original unmodified URL . */
public String canonicalize ( final String url ) { } }

implementation: if ( url != null && url . contains ( "/../" ) ) { StringBuffer result = new StringBuffer ( ) ; Matcher m = pattern . matcher ( url ) ; while ( m . find ( ) ) { if ( m . group ( 1 ) . equals ( m . group ( 2 ) ) ) { m . appendReplacement ( result , m . group ( 1 ) ) ; } m . appendTail ( result ) ; } return result . toString ( ) ; } return url ;


signature:
public class HttpRewriteRequestCycleWrapper { /** * Determines the { @ link DispatcherType } of the current request using the { @ link DispatcherTypeProvider } SPI . */
private DispatcherType getDispatcherType ( HttpServletRequest request , ServletContext context ) { } }

implementation: for ( DispatcherTypeProvider provider : dispatcherProviders ) { DispatcherType dispatcherType = provider . getDispatcherType ( request , context ) ; if ( dispatcherType != null ) { return dispatcherType ; } } throw new IllegalStateException ( "Unable to determine dispatcher type of current request" ) ;


signature:
public class QueryStringBuilder { /** * Build a query string from the given URL . If a ' ? ' character is encountered in the URL , the any characters up to
 * and including the first ' ? ' will be ignored . This method assumes that the given parameters have already been URL
 * encoded . */
public static QueryStringBuilder createFromEncoded ( final String parameters ) { } }

implementation: QueryStringBuilder queryString = new QueryStringBuilder ( ) ; queryString . addParameters ( parameters ) ; return queryString ;


signature:
public class QueryStringBuilder { /** * Build a query string from the given map of name = value pairs . For parameters with more than one value , each value
 * will be appended using the same name . */
public static QueryStringBuilder createFromArrays ( final Map < String , String [ ] > params ) { } }

implementation: return QueryStringBuilder . createNew ( ) . addParameterArrays ( params ) ;


signature:
public class QueryStringBuilder { /** * Build a query string from the given map of name = value pairs . For parameters with more than one value , each value
 * will be appended using the same name . */
public static QueryStringBuilder createFromLists ( final Map < String , List < String > > params ) { } }

implementation: return QueryStringBuilder . createNew ( ) . addParameterLists ( params ) ;


signature:
public class QueryStringBuilder { /** * Get the query string portion of the given URL . If no query string separator character ' ? ' can be found , return the
 * string unchanged . */
public static String extractQuery ( String url ) { } }

implementation: if ( url != null ) { int index = url . indexOf ( '?' ) ; if ( index >= 0 ) { url = url . substring ( index + 1 ) ; } } return url ;


signature:
public class QueryStringBuilder { /** * Add parameters from the given URL . If a ' ? ' character is encountered in the URL , the any characters up to and
 * including the first ' ? ' will be ignored . If a parameter already exists , append new values to the existing list of
 * values for that parameter .
 * < b > Note : < / b > This method assumes that the given string is already URL encoded . */
public QueryStringBuilder addParameters ( final String url ) { } }

implementation:
String temp = extractQuery ( url ) ; if ( temp != null ) { temp = decodeHTMLAmpersands ( temp ) ; int index = 0 ; while ( ( index = temp . indexOf ( '&' ) ) >= 0 || ! temp . isEmpty ( ) ) { String pair = temp ; if ( index >= 0 ) { pair = temp . substring ( 0 , index ) ; temp = temp . substring ( index ) ; if ( ! temp . isEmpty ( ) ) temp = temp . substring ( 1 ) ; } else temp = "" ; String name ; String value ; int pos = pair . indexOf ( '=' ) ; // for " n = " , the value is " " , for " n " , the value is null
if ( pos == - 1 ) { name = pair ; value = null ; } else { name = pair . substring ( 0 , pos ) ; value = pair . substring ( pos + 1 , pair . length ( ) ) ; } List < String > list = parameters . get ( name ) ; if ( list == null ) { list = new ArrayList < String > ( ) ; parameters . put ( name , list ) ; } list . add ( value ) ; } } return this ;


signature:
public class QueryStringBuilder { /** * Add a single parameter with the given values . */
public void addParameter ( final String name , final String ... values ) { } }

implementation: Map < String , String [ ] > parameter = new LinkedHashMap < String , String [ ] > ( ) ; parameter . put ( name , values ) ; addParameterArrays ( parameter ) ;


signature:
public class QueryStringBuilder { /** * Add parameters from the given map of name = value pairs . For parameters with more than one value , each value will be
 * appended using the same name . If a parameter already exists , append new values to the existing list of values for
 * that parameter . */
public QueryStringBuilder addParameterArrays ( final Map < String , String [ ] > params ) { } }

implementation: if ( params != null ) { for ( Entry < String , String [ ] > entry : params . entrySet ( ) ) { List < String > values = null ; if ( entry . getValue ( ) != null ) { List < String > temp = new ArrayList < String > ( ) ; if ( entry . getValue ( ) != null ) { for ( String value : entry . getValue ( ) ) { temp . add ( value ) ; } } values = temp ; } parameters . put ( entry . getKey ( ) , values ) ; } } return this ;


signature:
public class QueryStringBuilder { /** * Add parameters from the given map of name = value pairs . For parameters with more than one value , each value will be
 * appended using the same name . If a parameter already exists , append new values to the existing list of values for
 * that parameter . */
public QueryStringBuilder addParameterLists ( final Map < String , List < String > > params ) { } }

implementation: if ( params != null ) { for ( Entry < String , List < String > > entry : params . entrySet ( ) ) { List < String > values = null ; if ( entry . getValue ( ) != null ) { values = new ArrayList < String > ( entry . getValue ( ) ) ; } parameters . put ( entry . getKey ( ) , values ) ; } } return this ;


signature:
public class QueryStringBuilder { /** * Convert the current parameters to a valid query string , including the leading ' ? ' character .
 * For example , a { @ link QueryStringBuilder } with the values [ key = > value , name = > value1 , value2 , value3 ] will become :
 * < pre >
 * ? key = value & name = value1 & name = value2 & name = value3
 * < / pre >
 * @ return If parameters exist , return a valid query string with leading ' ? ' character . If no parameters exist ,
 * return an empty string . */
public String toQueryString ( ) { } }

implementation: StringBuilder result = new StringBuilder ( ) ; if ( ( null != parameters ) && ! parameters . isEmpty ( ) ) { result . append ( "?" ) ; Iterator < Entry < String , List < String > > > iterator = parameters . entrySet ( ) . iterator ( ) ; while ( iterator . hasNext ( ) ) { Entry < String , List < String > > entry = iterator . next ( ) ; String key = entry . getKey ( ) ; List < String > values = entry . getValue ( ) ; if ( ( key != null ) && ! "" . equals ( key ) ) { result . append ( key ) ; if ( ( values != null ) && ! values . isEmpty ( ) ) { for ( int i = 0 ; i < values . size ( ) ; i ++ ) { String value = values . get ( i ) ; if ( ( value != null ) && ! "" . equals ( value ) ) { result . append ( "=" + value ) ; } else if ( ( value != null ) && "" . equals ( value ) ) { result . append ( "=" ) ; } if ( i < ( values . size ( ) - 1 ) ) { result . append ( "&" + key ) ; } } } } if ( iterator . hasNext ( ) ) { result . append ( "&" ) ; } } } return result . toString ( ) ;


signature:
public class Base64 { /** * Serializes an object and returns the Base64 - encoded version of that serialized object . If the object cannot be
 * serialized or there is another error , the method will return < tt > null < / tt > .
 * Valid options :
 * < pre >
 * GZIP : gzip - compresses object before encoding it .
 * DONT _ BREAK _ LINES : don ' t break lines at 76 characters
 * < i > Note : Technically , this makes your encoding non - compliant . < / i >
 * < / pre >
 * Example : < code > encodeObject ( myObj , Base64 . GZIP ) < / code > or
 * Example : < code > encodeObject ( myObj , Base64 . GZIP | Base64 . DONT _ BREAK _ LINES ) < / code >
 * @ param serializableObject The object to encode
 * @ param options Specified options
 * @ return The Base64 - encoded object
 * @ see Base64 # GZIP
 * @ see Base64 # DONT _ BREAK _ LINES
 * @ since 2.0 */
public static String encodeObject ( final java . io . Serializable serializableObject , final int options ) { } }

implementation:
// Streams
java . io . ByteArrayOutputStream baos = null ; java . io . OutputStream b64os = null ; java . io . ObjectOutputStream oos = null ; java . util . zip . GZIPOutputStream gzos = null ; // Isolate options
int gzip = ( options & GZIP ) ; int dontBreakLines = ( options & DONT_BREAK_LINES ) ; try { // ObjectOutputStream - > ( GZIP ) - > Base64 - > ByteArrayOutputStream
baos = new java . io . ByteArrayOutputStream ( ) ; b64os = new Base64 . OutputStream ( baos , ENCODE | dontBreakLines ) ; // GZip ?
if ( gzip == GZIP ) { gzos = new java . util . zip . GZIPOutputStream ( b64os ) ; oos = new java . io . ObjectOutputStream ( gzos ) ; } // end if : gzip
else oos = new java . io . ObjectOutputStream ( b64os ) ; oos . writeObject ( serializableObject ) ; } // end try
catch ( java . io . IOException e ) { e . printStackTrace ( ) ; return null ; } // end catch
finally { try { oos . close ( ) ; } catch ( Exception e ) { } try { gzos . close ( ) ; } catch ( Exception e ) { } try { b64os . close ( ) ; } catch ( Exception e ) { } try { baos . close ( ) ; } catch ( Exception e ) { } } // end finally
// Return value according to relevant encoding .
try { return new String ( baos . toByteArray ( ) , PREFERRED_ENCODING ) ; } // end try
catch ( java . io . UnsupportedEncodingException uue ) { return new String ( baos . toByteArray ( ) ) ; } // end catch


signature:
public class Base64 { /** * Encodes a byte array into Base64 notation .
 * Valid options :
 * < pre >
 * GZIP : gzip - compresses object before encoding it .
 * DONT _ BREAK _ LINES : don ' t break lines at 76 characters
 * < i > Note : Technically , this makes your encoding non - compliant . < / i >
 * < / pre >
 * Example : < code > encodeBytes ( myData , Base64 . GZIP ) < / code > or
 * Example : < code > encodeBytes ( myData , Base64 . GZIP | Base64 . DONT _ BREAK _ LINES ) < / code >
 * @ param source The data to convert
 * @ param off Offset in array where conversion should begin
 * @ param len Length of data to convert
 * @ param options Specified options
 * @ see Base64 # GZIP
 * @ see Base64 # DONT _ BREAK _ LINES
 * @ return the text node
 * @ since 2.0 */
public static String encodeBytes ( final byte [ ] source , final int off , final int len , final int options ) { } }

implementation:
// Isolate options
int dontBreakLines = ( options & DONT_BREAK_LINES ) ; int gzip = ( options & GZIP ) ; // Compress ?
if ( gzip == GZIP ) { java . io . ByteArrayOutputStream baos = null ; java . util . zip . GZIPOutputStream gzos = null ; Base64 . OutputStream b64os = null ; try { // GZip - > Base64 - > ByteArray
baos = new java . io . ByteArrayOutputStream ( ) ; b64os = new Base64 . OutputStream ( baos , ENCODE | dontBreakLines ) ; gzos = new java . util . zip . GZIPOutputStream ( b64os ) ; gzos . write ( source , off , len ) ; gzos . close ( ) ; } // end try
catch ( java . io . IOException e ) { e . printStackTrace ( ) ; return null ; } // end catch
finally { try { gzos . close ( ) ; } catch ( Exception e ) { } try { b64os . close ( ) ; } catch ( Exception e ) { } try { baos . close ( ) ; } catch ( Exception e ) { } } // end finally
// Return value according to relevant encoding .
try { return new String ( baos . toByteArray ( ) , PREFERRED_ENCODING ) ; } // end try
catch ( java . io . UnsupportedEncodingException uue ) { return new String ( baos . toByteArray ( ) ) ; } // end catch
} // end if : compress
// Else , don ' t compress . Better not to use streams at all then .
else { // Convert option to boolean in way that code likes it .
boolean breakLines = dontBreakLines == 0 ; int len43 = ( len * 4 ) / 3 ; byte [ ] outBuff = new byte [ ( len43 ) // Main 4:3
+ ( ( len % 3 ) > 0 ? 4 : 0 ) // Account for padding
+ ( breakLines ? ( len43 / MAX_LINE_LENGTH ) : 0 ) ] ; // New lines
int d = 0 ; int e = 0 ; int len2 = len - 2 ; int lineLength = 0 ; for ( ; d < len2 ; d += 3 , e += 4 ) { encode3to4 ( source , d + off , 3 , outBuff , e ) ; lineLength += 4 ; if ( breakLines && ( lineLength == MAX_LINE_LENGTH ) ) { outBuff [ e + 4 ] = NEW_LINE ; e ++ ; lineLength = 0 ; } // end if : end of line
} // en dfor : each piece of array
if ( d < len ) { encode3to4 ( source , d + off , len - d , outBuff , e ) ; e += 4 ; } // end if : some padding needed
// Return value according to relevant encoding .
try { return new String ( outBuff , 0 , e , PREFERRED_ENCODING ) ; } // end try
catch ( java . io . UnsupportedEncodingException uue ) { return new String ( outBuff , 0 , e ) ; } // end catch
} // end else : don ' t compress


signature:
public class DispatchType { /** * Simple caching mechanism for the providers on a per request basis */
@ SuppressWarnings ( "unchecked" ) private List < DispatcherTypeProvider > getDispatcherTypeProviders ( HttpServletRewrite event ) { } }

implementation: List < DispatcherTypeProvider > providers = ( List < DispatcherTypeProvider > ) event . getRequest ( ) . getAttribute ( PROVIDER_KEY ) ; if ( providers == null ) { providers = Iterators . asList ( ServiceLoader . loadTypesafe ( DispatcherTypeProvider . class ) . iterator ( ) ) ; Collections . sort ( providers , new WeightedComparator ( ) ) ; event . getRequest ( ) . setAttribute ( PROVIDER_KEY , providers ) ; } return providers ;


signature:
public class ContextUtil { /** * Retrieve the named context - parameter from the given { @ link ServletContext } . If the parameter is not defined ,
 * return false , otherwise return the value as a boolean . If the value cannot be converted to a boolean type , return
 * false . */
public static boolean getInitParamBoolean ( ServletContext context , String name ) { } }

implementation: boolean result = false ; String value = getInitParam ( context , name , null ) ; if ( "true" . equalsIgnoreCase ( value ) ) { result = true ; } return result ;


signature:
public class ContextUtil { /** * Retrieve the named context - parameter from the given { @ link ServletContext } . If the parameter is not defined ,
 * return null . */
public static String getInitParam ( ServletContext context , String name ) { } }

implementation: return getInitParam ( context , name , null ) ;


signature:
public class ContextUtil { /** * Retrieve the named context - parameter from the given { @ link ServletContext } . If the parameter is not defined ,
 * return the default value instead . */
public static String getInitParam ( ServletContext context , String name , String deflt ) { } }

implementation: Assert . notNull ( context , "Servlet context must not be null." ) ; Assert . notNull ( context , "Cookie name must not be null." ) ; String value = context . getInitParameter ( name ) ; if ( value == null ) { value = deflt ; } return value ;


signature:
public class Invoke { /** * Invoke the given { @ link Retrieval } and process { @ link InvocationResultHandler } instances on the result value ( if
 * any . ) */
public static DefaultOperationBuilder binding ( final Retrieval retrieval ) { } }

implementation: return new Invoke ( null , retrieval ) { @ Override public String toString ( ) { return "Invoke.binding(" + retrieval + ")" ; } } ;


signature:
public class AbstractRewrite { /** * Print a log of all { @ link Rule } instances evaluated during the given { @ link Rewrite } event . This method is a no - op
 * if the selected logging { @ link Level } is disabled . */
public static void logEvaluatedRules ( Rewrite event , Level level ) { } }

implementation: switch ( level ) { case INFO : if ( log . isInfoEnabled ( ) ) log . info ( buildLogOutput ( event ) . toString ( ) ) ; break ; case WARN : if ( log . isWarnEnabled ( ) ) log . warn ( buildLogOutput ( event ) . toString ( ) ) ; break ; case ERROR : if ( log . isErrorEnabled ( ) ) log . error ( buildLogOutput ( event ) . toString ( ) ) ; break ; case DEBUG : if ( log . isDebugEnabled ( ) ) log . debug ( buildLogOutput ( event ) . toString ( ) ) ; break ; case TRACE : if ( log . isTraceEnabled ( ) ) log . trace ( buildLogOutput ( event ) . toString ( ) ) ; break ; default : break ; }


signature:
public class ParameterizedPatternSyntaxException { /** * Returns a string containing the description of the syntax error and its location , the erroneous parameterized
 * pattern string , and a visual location of the error index within the pattern ( if possible . ) */
@ Override public String getMessage ( ) { } }

implementation: String nl = System . getProperty ( "line.separator" ) ; StringBuffer sb = new StringBuffer ( ) ; sb . append ( message ) ; if ( index >= 0 ) { sb . append ( " near index " ) ; sb . append ( index ) ; } sb . append ( nl ) ; sb . append ( pattern ) ; if ( index >= 0 ) { sb . append ( nl ) ; for ( int i = 0 ; i < index ; i ++ ) sb . append ( ' ' ) ; sb . append ( '^' ) ; } return sb . toString ( ) ;


signature:
public class ConfigurationLoader { /** * Load all { @ link ConfigurationProvider } instances , sort by { @ link ConfigurationProvider # priority ( ) } , and return a
 * unified , composite { @ link Configuration } object . */
public Configuration loadConfiguration ( Object context ) { } }

implementation: if ( caches . isEmpty ( ) ) { return build ( context ) ; } return buildCached ( context ) ;


signature:
public class RequestParameter { /** * Create a { @ link Condition } that matches against both request parameter names and values .
 * Parameter name and value expressions may be parameterized :
 * < code >
 * RequestParameter . matches ( " username " , " guest " ) < br / >
 * RequestParameter . matches ( " username " , " { name } " ) < br / >
 * RequestParameter . matches ( " { anything } " , " { value } " ) < br / >
 * < / code >
 * @ param name { @ link ParameterizedPattern } matching the request parameter name .
 * @ param value { @ link ParameterizedPattern } matching the request parameter value .
 * @ see ConfigurationRuleParameterBuilder # where ( String ) { @ link HttpServletRequest # getParameterMap ( ) } */
public static RequestParameter matches ( final String name , final String value ) { } }

implementation: return new RequestParameter ( name , value ) { @ Override public String toString ( ) { return "RequestParameter.matches(\"" + name + "\", \"" + value + "\")" ; } } ;


signature:
public class RequestParameter { /** * Creates a { @ link RequestParameter } condition that will capture the value of the the given request parameter if it
 * exists so you can bind to it using < code > . where ( ) < / code > .
 * @ param name The name of the request parameter */
public static RequestParameter captureValue ( final String name ) { } }

implementation: return new RequestParameter ( name , "{" + name + "}" ) { @ Override public String toString ( ) { return "RequestParameter.captureValue(\"" + name + "\")" ; } @ Override public boolean evaluateHttp ( HttpServletRewrite event , EvaluationContext context ) { super . evaluateHttp ( event , context ) ; return true ; } } ;


signature:
public class RequestParameter { /** * Create a { @ link Condition } that matches against the existence of a request parameter with a name matching the
 * given pattern . The parameter value is ignored .
 * Parameter name expressions may be parameterized :
 * < code >
 * RequestParameter . exists ( " username " ) < br / >
 * RequestParameter . exists ( " { name } " ) < br / >
 * < / code >
 * @ param name { @ link ParameterizedPattern } matching the request parameter name .
 * @ see ConfigurationRuleParameterBuilder # where ( String ) { @ link HttpServletRequest # getParameterMap ( ) } */
public static RequestParameter exists ( final String name ) { } }

implementation: return new RequestParameter ( name , "{" + RequestParameter . class . getName ( ) + "_" + name + "_value}" ) { @ Override public String toString ( ) { return "RequestParameter.exists(\"" + name + "\")" ; } } ;


signature:
public class RequestParameter { /** * Create a { @ link Condition } that matches only against the existence of a request parameter value matching the given
 * pattern . The parameter name is ignored .
 * Parameter value expressions may be parameterized :
 * < code >
 * RequestParameter . valueExists ( " guest " ) < br / >
 * RequestParameter . valueExists ( " { username } " ) < br / >
 * < / code >
 * @ param name { @ link ParameterizedPattern } matching the request parameter name .
 * @ see ConfigurationRuleParameterBuilder # where ( String ) { @ link HttpServletRequest # getParameterMap ( ) } */
public static RequestParameter valueExists ( final String value ) { } }

implementation: return new RequestParameter ( "{" + RequestParameter . class . getName ( ) + "_" + value + "_name}" , value ) { @ Override public String toString ( ) { return "RequestParameter.valueExists(\"" + value + "\")" ; } } ;


signature:
public class Conditions { /** * Returns the number of " Not " s that have been evaluated in the current evaluation process .
 * For example , when ( Not . any ( MyCondition ) ) would have a " NotCount " of " 1 " during the evaluation of " MyCondition " .
 * when ( Not . any ( Not . any ( MyCondition ) ) ) would have a " NotCount " of " 2 " during the evaluation of " MyCondition " .
 * This is useful for conditions that may have side effects , as they will know whether or not their condition is being
 * negated . */
public static int getNegationCount ( final EvaluationContext context ) { } }

implementation: if ( context == null ) return 0 ; Integer count = ( Integer ) context . get ( NEGATION_COUNT_KEY ) ; return count == null ? 0 : count ;


signature:
public class Conditions { /** * This increments the number of negations , allowing us to determine ( during evaluation ) whether the results of a particular
 * { @ link Condition } will be negated . */
static void incrementNegationCount ( final EvaluationContext context , int adjustment ) { } }

implementation: if ( context == null ) return ; Integer count = Conditions . getNegationCount ( context ) ; count += adjustment ; context . put ( NEGATION_COUNT_KEY , count ) ;


signature:
public class Conditions { /** * Return a new { @ link DefaultConditionBuilder } that evaluates to { @ link True } when
 * { @ link # evaluate ( Rewrite , EvaluationContext ) } is invoked . */
public static ConditionBuilder create ( ) { } }

implementation: return new DefaultConditionBuilder ( ) { @ Override public boolean evaluate ( Rewrite event , EvaluationContext context ) { return true ; } @ Override public String toString ( ) { return "" ; } } ;


signature:
public class Conditions { /** * Wrap a given { @ link Condition } as a new { @ link DefaultConditionBuilder } that evaluates the the original
 * { @ link Condition } when { @ link # evaluate ( Rewrite , EvaluationContext ) } is invoked . */
public static ConditionBuilder wrap ( final Condition condition ) { } }

implementation: if ( condition == null ) return create ( ) ; if ( condition instanceof ConditionBuilder ) return ( ConditionBuilder ) condition ; return new DefaultConditionBuilderInternal ( condition ) { @ Override public boolean evaluate ( Rewrite event , EvaluationContext context ) { return condition . evaluate ( event , context ) ; } @ Override public String toString ( ) { return condition . toString ( ) ; } @ Override public List < Condition > getConditions ( ) { return Arrays . asList ( condition ) ; } } ;


signature:
public class PackageFilter { /** * Checks whether the supplied packages matches the filter .
 * The method returns < code > true < / code > if one of the following checks succeed :
 * < ul >
 * < li > The supplied package is one of the packages specified in the filter condition . < / li >
 * < li > The supplied package is a sub - package of one of the packages specified in the filter condition . < / li >
 * < / ul >
 * @ param packageName A package name
 * @ return < code > true < / code > if the filter matches */
public boolean isAllowedPackage ( String packageName ) { } }

implementation:
// No packages in set ? Accept all packages .
if ( packageSet . isEmpty ( ) ) { return true ; } // check all valid packages
for ( String validPackage : packageSet ) { // accept if package is a sub - package of a valid package
if ( packageName . startsWith ( validPackage ) ) { return true ; } } // package noch accepted
return false ;


signature:
public class Navigate { /** * Create a new { @ link Navigate } instance that will invoke navigation to the specified { @ link Class } . For instance ,
 * if the class specifies a { @ literal @ } Join rule , this would generate a navigation case targeting the
 * { @ link Address } for the defined resource .
 * Query parameters to be provided to the destination View ID may be supplied via { @ link # with ( CharSequence , Object ) } .
 * @ see ResourcePathResolver
 * @ param clazz the target { @ link Class } */
public static Navigate to ( Class < ? > clazz ) { } }

implementation: Assert . notNull ( clazz , "clazz must not be null" ) ; @ SuppressWarnings ( "unchecked" ) Iterable < ResourcePathResolver > resolvers = ServiceLoader . load ( ResourcePathResolver . class ) ; for ( ResourcePathResolver resolver : resolvers ) { String viewId = resolver . resolveFrom ( clazz ) ; if ( viewId != null ) { return new Navigate ( viewId ) ; } } throw new IllegalArgumentException ( "Unable to find the resource path for: " + clazz . getName ( ) ) ;


signature:
public class Navigate { /** * Set a query parameter to be passed to the specified View Id .
 * @ param The query parameter name .
 * @ param The query parameter value . */
public Navigate with ( CharSequence name , Object value ) { } }

implementation: Assert . notNull ( name , "name must not be null" ) ; if ( value != null ) { parameters . put ( name . toString ( ) , value . toString ( ) ) ; } return this ;


signature:
public class Navigate { /** * Builds a special outcome processed by { @ link RewriteNavigationHandler } */
private String buildRedirectOutcome ( ) { } }

implementation: AddressBuilderPath builderPath = AddressBuilder . begin ( ) . pathEncoded ( viewId ) ; for ( Entry < String , List < String > > param : parameters . entrySet ( ) ) { String [ ] values = param . getValue ( ) . toArray ( new String [ param . getValue ( ) . size ( ) ] ) ; builderPath . queryEncoded ( param . getKey ( ) , ( Object [ ] ) values ) ; } String url = builderPath . toString ( ) ; return RewriteNavigationHandler . REDIRECT_PREFIX + url ;


signature:
public class Navigate { /** * Builds a standard JSF 2.0 implicit navigation outcome */
private String buildStandardOutcome ( ) { } }

implementation: StringBuilder outcome = new StringBuilder ( ) ; outcome . append ( viewId ) ; boolean first = true ; for ( Entry < String , List < String > > param : parameters . entrySet ( ) ) { for ( String value : param . getValue ( ) ) { outcome . append ( first ? '?' : '&' ) ; outcome . append ( param . getKey ( ) ) ; outcome . append ( '=' ) ; outcome . append ( value ) ; first = false ; } } return outcome . toString ( ) ;


signature:
public class WebClassesFinder { /** * Scan for classes in a single directory . This method will call itself recursively if it finds other directories and
 * call { @ link # processClass ( String , InputStream , ClassVisitor ) } when it finds a file ending with " . class " and
 * that is accepted by the { @ link PackageFilter }
 * @ param absoluteUrl The absolute URL of the WEB - INF node to scan
 * @ param relativePath The path of the node inside the WEB - INF
 * @ param visitor The visitor class to call for classes found
 * @ throws MalformedURLException for invalid URLs */
protected void processDirectory ( URL absoluteUrl , String relativePath , ClassVisitor visitor ) throws MalformedURLException { } }

implementation:
// log directory name on trace level
if ( log . isTraceEnabled ( ) ) { log . trace ( "Processing directory: " + relativePath ) ; } // Convert url to string , this will result in a full path of a node in an exploded war archive
// let it be " file : / / opt / server / application / abc / expoded / ear / war / WEB - INF / classes / com / "
String urlAsString = absoluteUrl . toString ( ) ; Set < ? > paths = servletContext . getResourcePaths ( relativePath ) ; if ( paths == null || paths . isEmpty ( ) ) { return ; } // Process child nodes
for ( Object obj : paths ) { // produces " / WEB - INF / classes / com / mycompany / "
String childNodeName = obj . toString ( ) ; // get last part of the node path ( folder or class entry )
// for example for childnode " / WEB - INF / classes / com / mycompany / " returns " mycompany / "
String childNodeRelative = getChildNodeName ( childNodeName ) ; // get the folder of the node inside WEB - INF
// for example for childnode " / WEB - INF / classes / com / mycompany / " returns " / WEB - INF / classes / com / "
String webInfFolder = childNodeName . substring ( 0 , childNodeName . length ( ) - childNodeRelative . length ( ) ) ; // Find relative base folder
// produces " file : / / opt / server / application / abc / expoded / ear / war / "
String urlBase = urlAsString . substring ( 0 , urlAsString . length ( ) - webInfFolder . length ( ) ) ; // Create child node URL
// produces " file : / / opt / server / application / abc / expoded / ear / war / WEB - INF / classes / com / mycompany / "
URL childNodeUrl = new URL ( urlBase + childNodeName ) ; if ( childNodeRelative . endsWith ( "/" ) ) { // Recursive cal
processDirectory ( childNodeUrl , childNodeName , visitor ) ; } if ( childNodeRelative . endsWith ( ".class" ) ) { handleClassEntry ( childNodeName , visitor ) ; } }


signature:
public class WebClassesFinder { /** * Handles class entry in a WEB - INF . */
private void handleClassEntry ( String entryName , ClassVisitor visitor ) { } }

implementation:
// build class name from relative name
String className = getClassName ( entryName . substring ( CLASSES_FOLDER . length ( ) ) ) ; // check filter
if ( mustProcessClass ( className ) && ! processedClasses . contains ( className ) ) { // mark this class as processed
processedClasses . add ( className ) ; // the class file stream
InputStream classFileStream = null ; // close the stream in finally block
try { /* * Try to open the . class file . if this isn ' t possible , we will scan it anyway . */
classFileStream = servletContext . getResourceAsStream ( entryName ) ; if ( classFileStream == null ) { if ( log . isDebugEnabled ( ) ) { log . debug ( "Could not obtain InputStream for class file: " + entryName ) ; } } // analyze the class ( with or without classFileStream )
processClass ( className , classFileStream , visitor ) ; } finally { try { if ( classFileStream != null ) { classFileStream . close ( ) ; } } catch ( IOException e ) { if ( log . isDebugEnabled ( ) ) { log . debug ( "Failed to close input stream: " + e . getMessage ( ) ) ; } } } }


signature:
public class Resource { /** * Create a { @ link Condition } that returns < code > true < / code > if the given resource exists in the
 * { @ link ServletContext # getResourcePaths ( String ) } of the current application .
 * The given resource path may be parameterized :
 * < code >
 * / example / { param } . html < br >
 * / css / { value } . css < br >
 * < / code >
 * @ param location { @ link ParameterizedPattern } specifying the { @ link Address } of the internal resource .
 * @ see { @ link ConfigurationRuleParameterBuilder # where ( String ) } */
public static Resource exists ( final String resource ) { } }

implementation: return new Resource ( resource ) { @ Override public String toString ( ) { return "Resource.exists(\"" + resource + "\")" ; } } ;


signature:
public class RuleVisit { /** * Method to call the { @ link Visitor } for the supplied { @ link Rule } and recursively calls itself , if the { @ link Rule }
 * is a { @ link CompositeRule } . */
private void visit ( Rule rule , Visitor < Rule > visitor ) { } }

implementation: visitor . visit ( rule ) ; if ( rule instanceof CompositeRule ) { if ( ( ( CompositeRule ) rule ) . getRules ( ) != null ) { for ( Rule child : ( ( CompositeRule ) rule ) . getRules ( ) ) { visit ( child , visitor ) ; } } }


signature:
public class AddressBuilder { /** * Create a new { @ link Address } from the given URL . Improperly formatted or encoded URLs are not parse - able and will
 * result in an exception . No builder parameterization is possible using this method .
 * @ see http : / / en . wikipedia . org / wiki / URI _ scheme
 * @ throws IllegalArgumentException when the input URL or URL fragment is not valid . */
public static Address create ( String url ) throws IllegalArgumentException { } }

implementation: try { URI u = new URI ( url ) ; String scheme = u . getScheme ( ) ; String host = u . getHost ( ) ; if ( scheme != null && host == null ) return AddressBuilder . begin ( ) . scheme ( u . getScheme ( ) ) . schemeSpecificPart ( u . getRawSchemeSpecificPart ( ) ) . buildLiteral ( ) ; else return AddressBuilder . begin ( ) . scheme ( scheme ) . domain ( host ) . port ( u . getPort ( ) ) . path ( u . getRawPath ( ) ) . queryLiteral ( u . getRawQuery ( ) ) . anchor ( u . getRawFragment ( ) ) . buildLiteral ( ) ; } catch ( URISyntaxException e ) { throw new IllegalArgumentException ( "[" + url + "] is not a valid URL fragment. Consider encoding relevant portions of the URL with [" + Encoder . class + "], or use the provided builder pattern via this class to specify part encoding." , e ) ; }


signature:
public class AddressBuilder { /** * Set a query - parameter to a value or multiple values . The given name and values will be stored without additional
 * encoding or decoding . */
AddressBuilderQuery query ( CharSequence name , Object ... values ) { } }

implementation: if ( name != null && values != null ) { this . queries . put ( name . toString ( ) , Parameter . create ( name . toString ( ) , values ) ) ; } return new AddressBuilderQuery ( this ) ;


signature:
public class AddressBuilder { /** * Set a query - parameter value or multiple values . The given name and values be decoded before they are stored . */
AddressBuilderQuery queryDecoded ( CharSequence name , Object ... values ) { } }

implementation: if ( name != null && values != null ) { List < Object > encodedValues = new ArrayList < Object > ( values . length ) ; for ( Object value : values ) { if ( value == null ) encodedValues . add ( value ) ; else encodedValues . add ( Decoder . query ( value . toString ( ) ) ) ; } this . queries . put ( Decoder . query ( name . toString ( ) ) , Parameter . create ( name . toString ( ) , encodedValues ) ) ; } return new AddressBuilderQuery ( this ) ;


signature:
public class AddressBuilder { /** * Set a literal query string without additional encoding or decoding . A leading ' ? ' character is optional ; the
 * builder will add one if necessary . */
AddressBuilderQuery queryLiteral ( String query ) { } }

implementation:
if ( query != null ) { if ( query . startsWith ( "?" ) ) query = query . substring ( 1 ) ; /* * Linked hash map is important here in order to retain the order of query parameters . */
Map < CharSequence , List < CharSequence > > params = new LinkedHashMap < CharSequence , List < CharSequence > > ( ) ; query = decodeHTMLAmpersands ( query ) ; int index = 0 ; while ( ( index = query . indexOf ( '&' ) ) >= 0 || ! query . isEmpty ( ) ) { String pair = query ; if ( index >= 0 ) { pair = query . substring ( 0 , index ) ; query = query . substring ( index ) ; if ( ! query . isEmpty ( ) ) query = query . substring ( 1 ) ; } else query = "" ; String name ; String value ; int pos = pair . indexOf ( '=' ) ; // for " n = " , the value is " " , for " n " , the value is null
if ( pos == - 1 ) { name = pair ; value = null ; } else { name = pair . substring ( 0 , pos ) ; value = pair . substring ( pos + 1 , pair . length ( ) ) ; } List < CharSequence > list = params . get ( name ) ; if ( list == null ) { list = new ArrayList < CharSequence > ( ) ; params . put ( name , list ) ; } list . add ( value ) ; } for ( Entry < CharSequence , List < CharSequence > > entry : params . entrySet ( ) ) { query ( entry . getKey ( ) , entry . getValue ( ) . toArray ( ) ) ; } } return new AddressBuilderQuery ( this ) ;


signature:
public class AddressBuilder { /** * Set a parameter name and value or values . The supplied values will be stored without additional encoding . */
void set ( CharSequence name , Object ... values ) { } }

implementation: this . parameters . put ( name . toString ( ) , Parameter . create ( name . toString ( ) , values ) ) ;


signature:
public class AddressBuilder { /** * Set a parameter name and value or values . The values will be decoded before they are stored . */
void setDecoded ( CharSequence name , Object ... values ) { } }

implementation: if ( name != null && values != null ) { List < Object > encodedValues = new ArrayList < Object > ( values . length ) ; for ( Object value : values ) { if ( value == null ) encodedValues . add ( value ) ; else encodedValues . add ( Decoder . path ( value . toString ( ) ) ) ; } this . parameters . put ( name . toString ( ) , Parameter . create ( name . toString ( ) , encodedValues ) ) ; }


signature:
public class Redirect { /** * Create an { @ link Operation } that issues a permanent { @ link Redirect } ( 301
 * { @ link HttpServletResponse # SC _ MOVED _ PERMANENTLY } ) to the given location . If the given location is not the same as
 * { @ link HttpServletRewrite # getAddress ( ) } , this will change the browser { @ link URL } and result in a new request .
 * Note that in order to redirect to a resource within the { @ link ServletContext } , you must prepend the
 * { @ link ServletContext # getContextPath ( ) } .
 * For example : < br / >
 * < code >
 * Redirect . permanent ( contextPath + " / example / location . html " ) < br >
 * < / code >
 * The given location may be parameterized :
 * < code >
 * / store / global
 * / store / { category } < br >
 * / store / { category } / item / { itemId } < br >
 * < / code >
 * @ param location { @ link ParameterizedPattern } specifying the target location .
 * @ see ConfigurationRuleParameterBuilder # where ( String ) */
public static Redirect permanent ( final String location ) { } }

implementation: return new Redirect ( location , RedirectType . PERMANENT ) { @ Override public String toString ( ) { return "Redirect.permanent(\"" + location + "\")" ; } } ;


signature:
public class Redirect { /** * Create an { @ link Operation } that issues a temporary { @ link Redirect } ( 302
 * { @ link HttpServletResponse # SC _ MOVED _ TEMPORARILY } ) to the given location . If the given location is not the same as
 * { @ link HttpServletRewrite # getAddress ( ) } , this will change the browser { @ link URL } and result in a new request .
 * Note that in order to redirect within the { @ link ServletContext } , you must prepend the
 * { @ link ServletContext # getContextPath ( ) } .
 * For example : < br / >
 * < code >
 * Redirect . temporary ( contextPath + " / example / location . html " ) < br >
 * < / code >
 * The given location may be parameterized :
 * < code >
 * / store / global
 * / store / { category } < br >
 * / store / { category } / item / { itemId } < br >
 * < / code >
 * @ param location { @ link ParameterizedPattern } specifying the target location .
 * @ see ConfigurationRuleParameterBuilder # where ( String ) */
public static Redirect temporary ( final String location ) { } }

implementation: return new Redirect ( location , RedirectType . TEMPORARY ) { @ Override public String toString ( ) { return "Redirect.temporary(\"" + location + "\")" ; } } ;


signature:
public class ServerPort { /** * Create a { @ link Condition } to assert that the current { @ link Address # getPort ( ) } matches any of the given ports . */
public static ServerPort is ( final int ... ports ) { } }

implementation: return new ServerPort ( ports ) { @ Override public String toString ( ) { return "ServerPort.is(" + Strings . join ( Arrays . asList ( ports ) , ", " ) + ")" ; } } ;


signature:
public class AddressBuilderScheme { /** * Set a parameter name and value or values . The supplied values will be stored without additional encoding . */
public AddressBuilderScheme set ( CharSequence name , Object ... values ) { } }

implementation: parent . set ( name , values ) ; return this ;


signature:
public class AddressBuilderScheme { /** * Set a parameter name and value or values . The values will be decoded before they are stored . */
public AddressBuilderScheme setDecoded ( CharSequence name , Object ... values ) { } }

implementation: parent . setDecoded ( name , values ) ; return this ;


signature:
public class AddressBuilderScheme { /** * Set a parameter name and value or values . The values will be encoded before they are stored . */
public AddressBuilderScheme setEncoded ( CharSequence name , Object ... values ) { } }

implementation: parent . setEncoded ( name , values ) ; return this ;


signature:
public class Lifecycle { /** * Create an { @ link Operation } that calls { @ link ServletRewrite # abort ( ) } */
public static OperationBuilder abort ( ) { } }

implementation: return new Lifecycle ( ) { @ Override public void performHttp ( HttpServletRewrite event , EvaluationContext context ) { event . abort ( ) ; } @ Override public String toString ( ) { return "Lifecycle.abort()" ; } } ;


signature:
public class RewriteRule { /** * Return true if the < b > match < / b > field contains a regex that matches some
 * or all of the given URL , false if no match is found . */
public boolean matches ( final String url ) { } }

implementation: if ( url != null ) { if ( getMatch ( ) . length ( ) == 0 ) { return true ; } else { Matcher m = pattern . matcher ( url ) . useAnchoringBounds ( outbound ) ; while ( m . find ( ) ) { return true ; } } } return false ;


signature:
public class URLPatternParser { /** * Return true if this parser matches the given URL , otherwise , return false . */
public boolean matches ( final URL target ) { } }

implementation: if ( elPattern ) { return urlElPattern . matcher ( target . toURL ( ) ) . matches ( ) ; } else { return urlPattern . toURL ( ) . equals ( target . toURL ( ) ) ; }


signature:
public class URLPatternParser { /** * Return true if this parser matches the given URL , otherwise , return false . */
@ Deprecated public boolean matches ( final String target ) { } }

implementation: URL url = new URL ( target ) ; return matches ( url ) ;


signature:
public class URLPatternParser { /** * Builds a list of PathParameters for this UrlPattern , extracted from the provided URL ( assuming a match is found ) .
 * This list excludes duplicate named parameters . */
public List < PathParameter > parse ( final URL url ) { } }

implementation: List < PathParameter > result = new ArrayList < PathParameter > ( ) ; String inboundUrl = url . toURL ( ) ; if ( this . matches ( url ) ) { Iterator < Segment > iter = pathSegments . iterator ( ) ; while ( iter . hasNext ( ) ) { Segment segment = iter . next ( ) ; String regex = "" ; if ( url . hasLeadingSlash ( ) && ! "/" . equals ( url . toURL ( ) ) ) { regex += "/" ; } regex += segment . getRegex ( ) ; if ( iter . hasNext ( ) || url . hasTrailingSlash ( ) ) { regex += "/" ; } Matcher segmentMatcher = Pattern . compile ( regex ) . matcher ( inboundUrl ) ; if ( segmentMatcher . find ( ) ) { for ( int j = 0 ; j < segment . numParameters ( ) ; j ++ ) { String value = segmentMatcher . group ( j + 1 ) ; PathParameter param = segment . getParameter ( j ) . copy ( ) ; param . setValue ( value ) ; result . add ( param ) ; } int regionEnd = segmentMatcher . end ( ) ; inboundUrl = inboundUrl . substring ( regionEnd - 1 ) ; } else { throw new PrettyException ( "Error parsing url: <" + url + ">, a parameter did not match compiled segment in pattern: " + originalPattern ) ; } } } else { throw new IllegalArgumentException ( "The given URL: " + url + ", cannot be parsed by the pattern: " + originalPattern ) ; } return result ;


signature:
public class URLPatternParser { /** * URL encoding / decoding is not a concern of this method .
 * @ param params Array of Object parameters , in order , to be substituted for mapping pattern values or el
 * expressions . This method will call the toString ( ) method on each object provided .
 * If only one param is specified and it is an instance of List , the list items will be used as parameters
 * instead . An empty list or a single null parameter are both treated as if no parameters were specified .
 * E . g : getMappedUrl ( 12,55 , " foo " , " bar " ) for a pattern of / # { el . one } / # { el . two } / # { el . three } / # { el . four } / will
 * return the String : " / 12/55 / foo / bar / "
 * @ return A URL based on this object ' s urlPatten , with values substituted for el expressions in the order provided */
public URL getMappedURL ( final Object ... params ) { } }

implementation:
URL result = null ; if ( params != null ) { Object [ ] parameters = params ; /* * Check to see if our parameters were provided as a single List */
if ( ( params . length == 1 ) && ( params [ 0 ] != null ) && ( params [ 0 ] instanceof List < ? > ) ) { List < ? > list = ( List < ? > ) params [ 0 ] ; if ( list . size ( ) == 0 ) { parameters = new Object [ 0 ] ; } else { parameters = list . toArray ( params ) ; } } else if ( ( params . length == 1 ) && ( params [ 0 ] == null ) ) { parameters = new Object [ 0 ] ; } /* * Assert that we have the proper number of parameters . */
if ( getParameterCount ( ) != parameters . length ) { throw new PrettyException ( "Invalid number of path parameters supplied for pattern: " + originalPattern + ", expected <" + getParameterCount ( ) + ">, but got <" + parameters . length + ">" ) ; } /* * Build the result URL */
int paramIndex = 0 ; List < String > resultSegments = new ArrayList < String > ( ) ; for ( Segment segment : pathSegments ) { String template = segment . getTemplate ( ) ; Matcher parameterMatcher = Segment . getTemplateMatcher ( template ) ; StringBuffer sb = new StringBuffer ( ) ; while ( parameterMatcher . find ( ) ) { /* * We need to escape $ and \ because they have a special meaning when
 * used in Matcher # appendReplacement ( ) . From the docs :
 * Note that backslashes ( \ ) and dollar signs ( $ ) in the replacement string
 * may cause the results to be different than if it were being treated as a
 * literal replacement string . Dollar signs may be treated as references to
 * captured subsequences as described above , and backslashes are used to
 * escape literal characters in the replacement string . */
String replacement = parameters [ paramIndex ] . toString ( ) . replace ( "$" , "\\$" ) . replace ( "\\" , "\\\\" ) ; parameterMatcher . appendReplacement ( sb , replacement ) ; paramIndex ++ ; } parameterMatcher . appendTail ( sb ) ; resultSegments . add ( sb . toString ( ) ) ; } result = new URL ( resultSegments , urlPattern . getMetadata ( ) ) ; } else if ( getParameterCount ( ) > 0 ) { throw new PrettyException ( "Invalid number of parameters supplied: " + originalPattern + ", expected <" + getParameterCount ( ) + ">, got <0>" ) ; } return result ;


signature:
public class RequestBinding { /** * Create a { @ link Binding } to the { @ link ServletRequest # setAttribute ( String , Object ) } map . */
public static RequestBinding attribute ( final String property ) { } }

implementation: return new RequestAttributeBinding ( property ) { @ Override public String toString ( ) { return "RequestBinding.attribute(\"" + property + "\")" ; } } ;


signature:
public class RequestBinding { /** * Create a { @ link Binding } to the { @ link ServletRequest # getParameterMap ( ) } . */
public static RequestBinding parameter ( final String property ) { } }

implementation: return new RequestParameterBinding ( property ) { @ Override public String toString ( ) { return "RequestBinding.parameter(\"" + property + "\")" ; } } ;


signature:
public class EncodeQuery { /** * Exclude the given query - parameter names from encoding . */
public EncodeQuery excluding ( final String ... params ) { } }

implementation: if ( ( params != null ) && ( params . length > 0 ) ) this . excludedParams . addAll ( Arrays . asList ( params ) ) ; return this ;


signature:
public class Subset { /** * Executors */
@ Override public void perform ( Rewrite event , EvaluationContext context ) { } }

implementation:
/* * Highly optimized loop - for performance reasons . Think before you change this ! */
List < Rule > rules = config . getRules ( ) ; Rule rule = null ; final EvaluationContextImpl subContext = new EvaluationContextImpl ( ) ; for ( int i = 0 ; i < rules . size ( ) ; i ++ ) { rule = rules . get ( i ) ; event . getEvaluatedRules ( ) . add ( rule ) ; subContext . clear ( ) ; subContext . put ( ParameterStore . class , context . get ( ParameterStore . class ) ) ; ParameterValueStore values = ( ParameterValueStore ) context . get ( ParameterValueStore . class ) ; subContext . put ( ParameterValueStore . class , values ) ; subContext . setState ( RewriteState . EVALUATING ) ; if ( rule . evaluate ( event , subContext ) ) { if ( handleBindings ( event , subContext , values ) ) { subContext . setState ( RewriteState . PERFORMING ) ; if ( log . isDebugEnabled ( ) ) log . debug ( "Rule [" + rule + "] matched and will be performed." ) ; List < Operation > preOperations = subContext . getPreOperations ( ) ; for ( int k = 0 ; k < preOperations . size ( ) ; k ++ ) { preOperations . get ( k ) . perform ( event , subContext ) ; } if ( event . getFlow ( ) . isHandled ( ) ) { break ; } rule . perform ( event , subContext ) ; if ( event . getFlow ( ) . isHandled ( ) ) { break ; } List < Operation > postOperations = subContext . getPostOperations ( ) ; for ( int k = 0 ; k < postOperations . size ( ) ; k ++ ) { postOperations . get ( k ) . perform ( event , subContext ) ; } if ( event . getFlow ( ) . isHandled ( ) ) { break ; } } } else { event . getEvaluatedRules ( ) . remove ( rule ) ; } }


signature:
public class Encoder { /** * Encodes the given string using HTML form encoding as described in RFC 2396.
 * @ throws IllegalArgumentException when illegal URI syntax is attempted . */
public static String path ( CharSequence s ) throws IllegalArgumentException { } }

implementation: try { final URI uri = new URI ( "http" , "0.0.0.0" , "/" + s , null ) ; return uri . toASCIIString ( ) . substring ( 15 ) ; } catch ( URISyntaxException e ) { throw new IllegalArgumentException ( e ) ; }


signature:
public class Encoder { /** * Encodes the given string using HTML form encoding as described in RFC 2396.
 * @ throws IllegalArgumentException when illegal URI syntax is attempted . */
public static String query ( CharSequence s ) throws IllegalArgumentException { } }

implementation: try { return URLEncoder . encode ( s . toString ( ) , UTF8 . name ( ) ) ; } catch ( UnsupportedEncodingException e ) { throw new IllegalArgumentException ( e ) ; }


signature:
public class ExtractedValuesURLBuilder { /** * For all required values of the given PrettyUrlMapping , extract values from their mapped backing beans and create a
 * URL based on the url - pattern .
 * @ param mapping Mapping for which to extract values and generate URL
 * @ return The fully constructed URL */
public URL buildURL ( final UrlMapping mapping ) { } }

implementation:
URL result = null ; String expression = "" ; Object value = null ; try { FacesContext context = FacesContext . getCurrentInstance ( ) ; URLPatternParser parser = mapping . getPatternParser ( ) ; List < PathParameter > parameters = parser . getPathParameters ( ) ; List < String > parameterValues = new ArrayList < String > ( ) ; for ( PathParameter injection : parameters ) { // read value of the path parameter
expression = injection . getExpression ( ) . getELExpression ( ) ; value = elUtils . getValue ( context , expression ) ; if ( value == null ) { throw new PrettyException ( "PrettyFaces: Exception occurred while building URL for MappingId < " + mapping . getId ( ) + " >, Required value " + " < " + expression + " > was null" ) ; } // convert the value to a string using the correct converter
Converter converter = context . getApplication ( ) . createConverter ( value . getClass ( ) ) ; if ( converter != null ) { String convertedValue = converter . getAsString ( context , new NullComponent ( ) , value ) ; if ( convertedValue == null ) { throw new PrettyException ( "PrettyFaces: The converter <" + converter . getClass ( ) . getName ( ) + "> returned null while converting the object <" + value . toString ( ) + ">!" ) ; } value = convertedValue ; } parameterValues . add ( value . toString ( ) ) ; } result = parser . getMappedURL ( parameterValues ) . encode ( ) ; } catch ( ELException e ) { throw new PrettyException ( "PrettyFaces: Exception occurred while building URL for MappingId < " + mapping . getId ( ) + " >, Error occurred while extracting values from backing bean" + " < " + expression + ":" + value + " >" , e ) ; } return result ;


signature:
public class HttpRewriteWrappedResponse { /** * Cause any buffered { @ link ServletResponse } content to be processed and flushed to the client . */
@ Override public void flushBufferedContent ( ) { } }

implementation: if ( isResponseContentIntercepted ( ) ) { try { bufferedResponseContent . close ( ) ; ResponseContent buffer = new ResponseContentImpl ( bufferedResponseContent . toByteArray ( ) , Charset . forName ( getCharacterEncoding ( ) ) ) ; new ResponseContentInterceptorChainImpl ( responseContentInterceptors ) . begin ( new HttpBufferRewriteImpl ( request , this , servletContext ) , buffer ) ; if ( ! Charset . forName ( getCharacterEncoding ( ) ) . equals ( buffer . getCharset ( ) ) ) setCharacterEncoding ( buffer . getCharset ( ) . name ( ) ) ; ServletOutputStream outputStream = isResponseStreamWrapped ( ) ? wrappedOutputStream : super . getOutputStream ( ) ; if ( outputStream != null ) Streams . copy ( new ByteArrayInputStream ( buffer . getContents ( ) ) , outputStream ) ; if ( printWriter != null ) { printWriter . close ( ) ; } } catch ( IOException e ) { throw new RewriteException ( "Error occurred when flushing response content buffered by " + responseContentInterceptors , e ) ; } }


signature:
public class PrettyContext { /** * Get the current PrettyFaces context object , or construct a new one if it
 * does not yet exist for this request . ( Delegates to { @ link FacesContext } to
 * retrieve the current { @ link HttpServletRequest } object )
 * @ return current context instance */
public static PrettyContext getCurrentInstance ( final FacesContext context ) { } }

implementation: Assert . notNull ( context , "FacesContext argument was null." ) ; return getCurrentInstance ( ( HttpServletRequest ) context . getExternalContext ( ) . getRequest ( ) ) ;


signature:
public class PrettyContext { /** * Get the current { @ link PrettyContext } , or construct a new one if it does
 * not yet exist for this request .
 * @ return current context instance */
public static PrettyContext getCurrentInstance ( final HttpServletRequest request ) { } }

implementation: Assert . notNull ( request , "HttpServletRequest argument was null" ) ; PrettyContext prettyContext = ( PrettyContext ) request . getAttribute ( CONTEXT_REQUEST_KEY ) ; if ( prettyContext instanceof PrettyContext ) { log . trace ( "Retrieved PrettyContext from Request" ) ; return prettyContext ; } else { Assert . notNull ( request , "HttpServletRequest argument was null" ) ; prettyContext = newDetachedInstance ( request ) ; log . trace ( "PrettyContext not found in Request - building new instance" ) ; setCurrentContext ( request , prettyContext ) ; return prettyContext ; }


signature:
public class PrettyContext { /** * Return true if there is an instantiated { @ link PrettyContext } contained in
 * the current given request object . */
public static boolean isInstantiated ( final ServletRequest request ) { } }

implementation: Assert . notNull ( request , "HttpServletRequest argument was null" ) ; PrettyContext prettyContext = ( PrettyContext ) request . getAttribute ( CONTEXT_REQUEST_KEY ) ; if ( prettyContext instanceof PrettyContext ) { return true ; } else { return false ; }


signature:
public class PrettyContext { /** * Package private - - only { @ link PrettyFilter } should be calling this method
 * - - it does not overwrite existing contexts in Request object */
public static PrettyContext newDetachedInstance ( final HttpServletRequest request ) { } }

implementation: Assert . notNull ( request , "HttpServletRequest argument was null" ) ; PrettyContext prettyContext = new PrettyContext ( request ) ; return prettyContext ;


signature:
public class PrettyContext { /** * Sends an error response to the client using the specified HTTP status
 * code .
 * Please note that this method can only be called from within the JSF
 * lifecycle as it needs the { @ link FacesContext } to obtain the
 * { @ link HttpServletResponse } . Please use
 * { @ link # sendError ( int , String , HttpServletResponse ) } in all other
 * cases .
 * @ param code the error status code
 * @ param message the descriptive message
 * @ see HttpServletResponse # sendError ( int , String ) */
public void sendError ( int code , String message ) { } }

implementation: FacesContext facesContext = FacesContext . getCurrentInstance ( ) ; Assert . notNull ( facesContext , "FacesContext argument was null." ) ; Object response = facesContext . getExternalContext ( ) . getResponse ( ) ; if ( response instanceof HttpServletResponse ) { sendError ( code , message , ( HttpServletResponse ) response ) ; facesContext . responseComplete ( ) ; }


signature:
public class PrettyContext { /** * Sends an error response to the client using the specified HTTP status
 * code .
 * @ param code the error status code
 * @ param message the descriptive message
 * @ param response
 * @ see HttpServletResponse # sendError ( int , String ) */
public void sendError ( int code , String message , HttpServletResponse response ) { } }

implementation: Assert . notNull ( response , "HttpServletResponse argument was null" ) ; try { if ( message != null ) { response . sendError ( code , message ) ; } else { response . sendError ( code ) ; } } catch ( IOException e ) { throw new IllegalStateException ( "Failed to send error code: " + code , e ) ; }