signature:
public class TldScanner { /** * Scans the given JarURLConnection for TLD files located in META - INF
 * ( or a subdirectory of it ) . If the scanning in is done as part of the
 * ServletContextInitializer , the listeners in the tlds in this jar file
 * are added to the servlet context , and for any TLD that has a < uri >
 * element , an implicit map entry is added to the taglib map .
 * @ param conn The JarURLConnection to the JAR file to scan
 * @ param tldNames the list of tld element to scan . The null value
 * indicates all the tlds in this case .
 * @ param isLocal True if the jar file is under WEB - INF
 * false otherwise */
private void scanJar ( JarURLConnection conn , List < String > tldNames , boolean isLocal ) throws JasperException { } }

implementation:
String resourcePath = conn . getJarFileURL ( ) . toString ( ) ; TldInfo [ ] tldInfos = jarTldCacheLocal . get ( resourcePath ) ; // Optimize for most common cases : jars known to NOT have tlds
if ( tldInfos != null && tldInfos . length == 0 ) { try { conn . getJarFile ( ) . close ( ) ; } catch ( IOException ex ) { // ignored
} return ; } // scan the tld if the jar has not been cached .
if ( tldInfos == null ) { JarFile jarFile = null ; ArrayList < TldInfo > tldInfoA = new ArrayList < TldInfo > ( ) ; try { jarFile = conn . getJarFile ( ) ; if ( tldNames != null ) { for ( String tldName : tldNames ) { JarEntry entry = jarFile . getJarEntry ( tldName ) ; InputStream stream = jarFile . getInputStream ( entry ) ; tldInfoA . add ( scanTld ( resourcePath , tldName , stream ) ) ; } } else { Enumeration < JarEntry > entries = jarFile . entries ( ) ; while ( entries . hasMoreElements ( ) ) { JarEntry entry = entries . nextElement ( ) ; String name = entry . getName ( ) ; if ( ! name . startsWith ( "META-INF/" ) ) continue ; if ( ! name . endsWith ( ".tld" ) ) continue ; InputStream stream = jarFile . getInputStream ( entry ) ; tldInfoA . add ( scanTld ( resourcePath , name , stream ) ) ; } } } catch ( IOException ex ) { if ( resourcePath . startsWith ( FILE_PROTOCOL ) && ! ( ( new File ( resourcePath ) ) . exists ( ) ) ) { if ( log . isLoggable ( Level . WARNING ) ) { log . log ( Level . WARNING , Localizer . getMessage ( "jsp.warn.nojar" , resourcePath ) , ex ) ; } } else { throw new JasperException ( Localizer . getMessage ( "jsp.error.jar.io" , resourcePath ) , ex ) ; } } finally { if ( jarFile != null ) { try { jarFile . close ( ) ; } catch ( Throwable t ) { // ignore
} } } // Update the jar TLD cache
tldInfos = tldInfoA . toArray ( new TldInfo [ tldInfoA . size ( ) ] ) ; jarTldCacheLocal . put ( resourcePath , tldInfos ) ; if ( ! isLocal ) { // Also update the global cache ;
jarTldCache . put ( resourcePath , tldInfos ) ; } } // Iterate over tldinfos to add listeners or to map tldlocations
for ( TldInfo tldInfo : tldInfos ) { if ( scanListeners ) { addListener ( tldInfo , isLocal ) ; } mapTldLocation ( resourcePath , tldInfo , isLocal ) ; }


signature:
public class TldScanner { /** * Searches the filesystem under / WEB - INF for any TLD files , and scans
 * them for < uri > and < listener > elements . */
private void processTldsInFileSystem ( String startPath ) throws JasperException { } }

implementation:
Set dirList = ctxt . getResourcePaths ( startPath ) ; if ( dirList != null ) { Iterator it = dirList . iterator ( ) ; while ( it . hasNext ( ) ) { String path = ( String ) it . next ( ) ; if ( path . endsWith ( "/" ) ) { processTldsInFileSystem ( path ) ; } if ( ! path . endsWith ( ".tld" ) ) { continue ; } if ( path . startsWith ( "/WEB-INF/tags/" ) && ! path . endsWith ( "implicit.tld" ) ) { throw new JasperException ( Localizer . getMessage ( "jsp.error.tldinit.tldInWebInfTags" , path ) ) ; } InputStream stream = ctxt . getResourceAsStream ( path ) ; TldInfo tldInfo = scanTld ( path , null , stream ) ; // Add listeners or to map tldlocations for this TLD
if ( scanListeners ) { addListener ( tldInfo , true ) ; } mapTldLocation ( path , tldInfo , true ) ; } }


signature:
public class TldScanner { /** * Scan the given TLD for uri and listeners elements .
 * @ param resourcePath the resource path for the jar file or the tld file .
 * @ param entryName If the resource path is a jar file , then the name of
 * the tld file in the jar , else should be null .
 * @ param stream The input stream for the tld
 * @ return The TldInfo for this tld */
private TldInfo scanTld ( String resourcePath , String entryName , InputStream stream ) throws JasperException { } }

implementation:
try { // Parse the tag library descriptor at the specified resource path
TreeNode tld = new ParserUtils ( ) . parseXMLDocument ( resourcePath , stream , isValidationEnabled ) ; String uri = null ; TreeNode uriNode = tld . findChild ( "uri" ) ; if ( uriNode != null ) { uri = uriNode . getBody ( ) ; } ArrayList < String > listeners = new ArrayList < String > ( ) ; Iterator < TreeNode > listenerNodes = tld . findChildren ( "listener" ) ; while ( listenerNodes . hasNext ( ) ) { TreeNode listener = listenerNodes . next ( ) ; TreeNode listenerClass = listener . findChild ( "listener-class" ) ; if ( listenerClass != null ) { String listenerClassName = listenerClass . getBody ( ) ; if ( listenerClassName != null ) { listeners . add ( listenerClassName ) ; } } } return new TldInfo ( uri , entryName , listeners . toArray ( new String [ listeners . size ( ) ] ) ) ; } finally { if ( stream != null ) { try { stream . close ( ) ; } catch ( Throwable t ) { // do nothing
} } }


signature:
public class TldScanner { /** * Scans all JARs accessible to the webapp ' s classloader and its
 * parent classloaders for TLDs .
 * The list of JARs always includes the JARs under WEB - INF / lib , as well as
 * all shared JARs in the classloader delegation chain of the webapp ' s
 * classloader .
 * Considering JARs in the classloader delegation chain constitutes a
 * Tomcat - specific extension to the TLD search
 * order defined in the JSP spec . It allows tag libraries packaged as JAR
 * files to be shared by web applications by simply dropping them in a
 * location that all web applications have access to ( e . g . ,
 * < CATALINA _ HOME > / common / lib ) . */
private void scanJars ( ) throws Exception { } }

implementation:
ClassLoader webappLoader = Thread . currentThread ( ) . getContextClassLoader ( ) ; ClassLoader loader = webappLoader ; Map < URI , List < String > > tldMap ; if ( scanListeners ) { tldMap = getTldListenerMap ( ) ; } else { tldMap = getTldMap ( ) ; } Boolean isStandalone = ( Boolean ) ctxt . getAttribute ( IS_STANDALONE_ATTRIBUTE_NAME ) ; while ( loader != null ) { if ( loader instanceof URLClassLoader ) { boolean isLocal = ( loader == webappLoader ) ; URL [ ] urls = ( ( URLClassLoader ) loader ) . getURLs ( ) ; List < String > extraJars = new ArrayList < String > ( ) ; for ( int i = 0 ; i < urls . length ; i ++ ) { URLConnection conn = urls [ i ] . openConnection ( ) ; JarURLConnection jconn = null ; if ( conn instanceof JarURLConnection ) { jconn = ( JarURLConnection ) conn ; } else { String urlStr = urls [ i ] . toString ( ) ; if ( urlStr . startsWith ( FILE_PROTOCOL ) && urlStr . endsWith ( JAR_FILE_SUFFIX ) ) { URL jarURL = new URL ( "jar:" + urlStr + "!/" ) ; jconn = ( JarURLConnection ) jarURL . openConnection ( ) ; } } if ( jconn != null ) { jconn . setUseCaches ( false ) ; if ( isLocal ) { // For local jars , collect the jar files in the
// Manifest Class - Path , to be scanned later .
addManifestClassPath ( null , extraJars , jconn ) ; } scanJar ( jconn , null , isLocal ) ; } } // Scan the jars collected from manifest class - path . Expand
// the list to include jar files from their manifest classpath .
if ( extraJars . size ( ) > 0 ) { List < String > newJars ; do { newJars = new ArrayList < String > ( ) ; for ( String jar : extraJars ) { URL jarURL = new URL ( "jar:" + jar + "!/" ) ; JarURLConnection jconn = ( JarURLConnection ) jarURL . openConnection ( ) ; jconn . setUseCaches ( false ) ; if ( addManifestClassPath ( extraJars , newJars , jconn ) ) { scanJar ( jconn , null , true ) ; } } extraJars . addAll ( newJars ) ; } while ( newJars . size ( ) != 0 ) ; } } if ( tldMap != null && isStandalone != null ) { if ( isStandalone . booleanValue ( ) ) { break ; } else { if ( EAR_LIB_CLASSLOADER . equals ( loader . getClass ( ) . getName ( ) ) ) { // Do not walk up classloader delegation chain beyond
// EarLibClassLoader
break ; } } } loader = loader . getParent ( ) ; } if ( tldMap != null ) { for ( URI uri : tldMap . keySet ( ) ) { URL jarURL = new URL ( "jar:" + uri . toString ( ) + "!/" ) ; scanJar ( ( JarURLConnection ) jarURL . openConnection ( ) , tldMap . get ( uri ) , false ) ; } }


signature:
public class TldScanner { /** * Add the jars in the manifest Class - Path to the list " jars "
 * @ param scannedJars List of jars that has been previously scanned
 * @ param newJars List of jars from Manifest Class - Path
 * @ return true is the jar file exists */
private boolean addManifestClassPath ( List < String > scannedJars , List < String > newJars , JarURLConnection jconn ) { } }

implementation:
Manifest manifest ; try { manifest = jconn . getManifest ( ) ; } catch ( IOException ex ) { // Maybe non existing jar , ignored
return false ; } String file = jconn . getJarFileURL ( ) . toString ( ) ; if ( ! file . contains ( "WEB-INF" ) ) { // Only jar in WEB - INF is considered here
return true ; } if ( manifest == null ) return true ; java . util . jar . Attributes attrs = manifest . getMainAttributes ( ) ; String cp = ( String ) attrs . getValue ( "Class-Path" ) ; if ( cp == null ) return true ; String [ ] paths = cp . split ( " " ) ; int lastIndex = file . lastIndexOf ( '/' ) ; if ( lastIndex < 0 ) { lastIndex = file . lastIndexOf ( '\\' ) ; } String baseDir = "" ; if ( lastIndex > 0 ) { baseDir = file . substring ( 0 , lastIndex + 1 ) ; } for ( String path : paths ) { String p ; if ( path . startsWith ( "/" ) || path . startsWith ( "\\" ) ) { p = "file:" + path ; } else { p = baseDir + path ; } if ( ( scannedJars == null || ! scannedJars . contains ( p ) ) && ! newJars . contains ( p ) ) { newJars . add ( p ) ; } } return true ;


signature:
public class JspRuntimeContext { /** * Add a new JspServletWrapper .
 * @ param jspUri JSP URI
 * @ param jsw Servlet wrapper for JSP */
public void addWrapper ( String jspUri , JspServletWrapper jsw ) { } }

implementation: jsps . remove ( jspUri ) ; jsps . put ( jspUri , jsw ) ;


signature:
public class JspRuntimeContext { /** * Get the parent class loader .
 * @ return ClassLoader parent */
public ClassLoader getParentClassLoader ( ) { } }

implementation: ClassLoader parentClassLoader = Thread . currentThread ( ) . getContextClassLoader ( ) ; if ( parentClassLoader == null ) { parentClassLoader = this . getClass ( ) . getClassLoader ( ) ; } return parentClassLoader ;


signature:
public class JspRuntimeContext { /** * Save the bytecode for the class in a map . The current time is noted .
 * @ param name The name of the class
 * @ param bytecode The bytecode in byte array */
public void setBytecode ( String name , byte [ ] bytecode ) { } }

implementation: if ( bytecode == null ) { bytecodes . remove ( name ) ; bytecodeBirthTimes . remove ( name ) ; return ; } bytecodes . put ( name , bytecode ) ; bytecodeBirthTimes . put ( name , Long . valueOf ( System . currentTimeMillis ( ) ) ) ;


signature:
public class JspRuntimeContext { /** * Retrieve the time the bytecode for a class was created */
public long getBytecodeBirthTime ( String name ) { } }

implementation: Long time = bytecodeBirthTimes . get ( name ) ; return ( time != null ? time . longValue ( ) : 0 ) ;


signature:
public class JspRuntimeContext { /** * Save the bytecode for a class to disk . */
public void saveBytecode ( String className , String classFileName ) { } }

implementation: byte [ ] bytecode = getBytecode ( className ) ; if ( bytecode != null ) { try { FileOutputStream fos = new FileOutputStream ( classFileName ) ; fos . write ( bytecode ) ; fos . close ( ) ; } catch ( IOException ex ) { context . log ( "Error in saving bytecode for " + className + " to " + classFileName , ex ) ; } }


signature:
public class JspRuntimeContext { /** * Method used by background thread to check the JSP dependencies
 * registered with this class for JSP ' s . */
private void checkCompile ( ) { } }

implementation:
for ( JspServletWrapper jsw : jsps . values ( ) ) { if ( jsw . isTagFile ( ) ) { // Skip tag files in background compiliations , since modified
// tag files will be recompiled anyway when their client JSP
// pages are compiled . This also avoids problems when the
// tag files and their clients are not modified simultaneously .
continue ; } JspCompilationContext ctxt = jsw . getJspEngineContext ( ) ; // JspServletWrapper also synchronizes on this when
// it detects it has to do a reload
synchronized ( jsw ) { try { ctxt . compile ( ) ; } catch ( FileNotFoundException ex ) { ctxt . incrementRemoved ( ) ; } catch ( Throwable t ) { jsw . getServletContext ( ) . log ( Localizer . getMessage ( "jsp.error.background.compile" ) , t ) ; } } }


signature:
public class JspRuntimeContext { /** * Method used to initialize classpath for compiles . */
private void initClassPath ( ) { } }

implementation:
/* Classpath can be specified in one of two ways , depending on
 whether the compilation is embedded or invoked from Jspc .
 1 . Calculated by the web container , and passed to Jasper in the
 context attribute .
 2 . Jspc directly invoke JspCompilationContext . setClassPath , in
 case the classPath initialzed here is ignored . */
StringBuilder cpath = new StringBuilder ( ) ; String sep = System . getProperty ( "path.separator" ) ; cpath . append ( options . getScratchDir ( ) + sep ) ; String cp = ( String ) context . getAttribute ( Constants . SERVLET_CLASSPATH ) ; if ( cp == null || cp . equals ( "" ) ) { cp = options . getClassPath ( ) ; } if ( cp != null ) { classpath = cpath . toString ( ) + cp ; } // START GlassFish Issue 845
if ( classpath != null ) { try { classpath = URLDecoder . decode ( classpath , "UTF-8" ) ; } catch ( UnsupportedEncodingException e ) { if ( log . isLoggable ( Level . FINE ) ) log . log ( Level . FINE , "Exception decoding classpath : " + classpath , e ) ; } } // END GlassFish Issue 845


signature:
public class JspRuntimeContext { /** * Method used to initialize SecurityManager data . */
private void initSecurity ( ) { } }

implementation:
// Setup the PermissionCollection for this web app context
// based on the permissions configured for the root of the
// web app context directory , then add a file read permission
// for that directory .
Policy policy = Policy . getPolicy ( ) ; if ( policy != null ) { try { // Get the permissions for the web app context
String docBase = context . getRealPath ( "/" ) ; if ( docBase == null ) { docBase = options . getScratchDir ( ) . toString ( ) ; } String codeBase = docBase ; if ( ! codeBase . endsWith ( File . separator ) ) { codeBase = codeBase + File . separator ; } File contextDir = new File ( codeBase ) ; URL url = contextDir . getCanonicalFile ( ) . toURL ( ) ; codeSource = new CodeSource ( url , ( Certificate [ ] ) null ) ; permissionCollection = policy . getPermissions ( codeSource ) ; // Create a file read permission for web app context directory
if ( ! docBase . endsWith ( File . separator ) ) { permissionCollection . add ( new FilePermission ( docBase , "read" ) ) ; docBase = docBase + File . separator ; } else { permissionCollection . add ( new FilePermission ( docBase . substring ( 0 , docBase . length ( ) - 1 ) , "read" ) ) ; } docBase = docBase + "-" ; permissionCollection . add ( new FilePermission ( docBase , "read" ) ) ; // Create a file read permission for web app tempdir ( work )
// directory
String workDir = options . getScratchDir ( ) . toString ( ) ; if ( ! workDir . endsWith ( File . separator ) ) { permissionCollection . add ( new FilePermission ( workDir , "read" ) ) ; workDir = workDir + File . separator ; } workDir = workDir + "-" ; permissionCollection . add ( new FilePermission ( workDir , "read" ) ) ; // Allow the JSP to access org . apache . jasper . runtime . HttpJspBase
permissionCollection . add ( new RuntimePermission ( "accessClassInPackage.org.apache.jasper.runtime" ) ) ; ClassLoader parentClassLoader = getParentClassLoader ( ) ; if ( parentClassLoader instanceof URLClassLoader ) { URL [ ] urls = ( ( URLClassLoader ) parentClassLoader ) . getURLs ( ) ; String jarUrl = null ; String jndiUrl = null ; for ( int i = 0 ; i < urls . length ; i ++ ) { if ( jndiUrl == null && urls [ i ] . toString ( ) . startsWith ( "jndi:" ) ) { jndiUrl = urls [ i ] . toString ( ) + "-" ; } if ( jarUrl == null && urls [ i ] . toString ( ) . startsWith ( "jar:jndi:" ) ) { jarUrl = urls [ i ] . toString ( ) ; jarUrl = jarUrl . substring ( 0 , jarUrl . length ( ) - 2 ) ; jarUrl = jarUrl . substring ( 0 , jarUrl . lastIndexOf ( '/' ) ) + "/-" ; } } if ( jarUrl != null ) { permissionCollection . add ( new FilePermission ( jarUrl , "read" ) ) ; permissionCollection . add ( new FilePermission ( jarUrl . substring ( 4 ) , "read" ) ) ; } if ( jndiUrl != null ) permissionCollection . add ( new FilePermission ( jndiUrl , "read" ) ) ; } } catch ( Exception e ) { context . log ( "Security Init for context failed" , e ) ; } }


signature:
public class JspRuntimeContext { /** * Start the background thread that will periodically check for
 * changes to compile time included files in a JSP .
 * @ exception IllegalStateException if we should not be starting
 * a background thread now */
protected void threadStart ( ) { } }

implementation:
// Has the background thread already been started ?
if ( thread != null ) { return ; } // Start the background thread
threadDone = false ; thread = new Thread ( this , threadName ) ; thread . setDaemon ( true ) ; thread . start ( ) ;


signature:
public class JspRuntimeContext { /** * Stop the background thread that is periodically checking for
 * changes to compile time included files in a JSP . */
protected void threadStop ( ) { } }

implementation: if ( thread == null ) { return ; } threadDone = true ; thread . interrupt ( ) ; try { thread . join ( ) ; } catch ( InterruptedException e ) { ; } thread = null ;


signature:
public class JspRuntimeContext { /** * The background thread that checks for changes to files
 * included by a JSP and flags that a recompile is required . */
public void run ( ) { } }

implementation:
// Loop until the termination semaphore is set
while ( ! threadDone ) { // Wait for our check interval
threadSleep ( ) ; // Check for included files which are newer than the
// JSP which uses them .
try { checkCompile ( ) ; } catch ( Throwable t ) { t . printStackTrace ( ) ; log . log ( Level . SEVERE , Localizer . getMessage ( "jsp.error.recompile" ) , t ) ; } }


signature:
public class ChannelServiceImpl { /** * Find by the locator
 * This method does not acquire the read lock , this has to be done by the
 * caller
 * @ param by
 * the locator
 * @ return the result */
protected Optional < ChannelInstance > find ( final By by ) { } }

implementation: switch ( by . getType ( ) ) { case ID : return findById ( ( String ) by . getQualifier ( ) ) ; case NAME : return findByName ( ( String ) by . getQualifier ( ) ) ; case COMPOSITE : { final By [ ] bys = ( By [ ] ) by . getQualifier ( ) ; for ( final By oneBy : bys ) { final Optional < ChannelInstance > result = find ( oneBy ) ; if ( result . isPresent ( ) ) { return result ; } } return Optional . empty ( ) ; } default : throw new IllegalArgumentException ( String . format ( "Unknown locator type: %s" , by . getType ( ) ) ) ; }


signature:
public class ChannelServiceImpl { /** * Find a channel by name
 * @ param name
 * the channel name to look for
 * @ return the optional channel entry , never returns { @ code null } but my
 * return { @ link Optional # empty ( ) } . */
private Optional < ChannelInstance > findByName ( final String name ) { } }

implementation: if ( name == null ) { return empty ( ) ; } final String id = this . manager . accessCall ( KEY_STORAGE , ChannelServiceAccess . class , channels -> { return channels . mapToId ( name ) ; } ) ; return findById ( id ) ;


signature:
public class ChannelServiceImpl { /** * Find a channel
 * @ param by
 * the search criteria
 * @ return the found channel , never returns { @ code null }
 * @ throws ChannelNotFoundException
 * if there was no channel found */
private ChannelInstance findChannel ( final By by ) { } }

implementation: final Optional < ChannelInstance > channel ; try ( Locked l = lock ( this . readLock ) ) { channel = find ( by ) ; } if ( ! channel . isPresent ( ) ) { throw new ChannelNotFoundException ( by . toString ( ) ) ; } return channel . get ( ) ;


signature:
public class ChannelServiceImpl { /** * Update the channel to deploy group cache map
 * @ param model
 * the model to fill the cache from */
private void updateDeployGroupCache ( final ChannelServiceAccess model ) { } }

implementation:
// this will simply rebuild the complete map
// clear first
this . deployKeysMap . clear ( ) ; // fill afterwards
for ( final Map . Entry < String , Set < String > > entry : model . getDeployGroupMap ( ) . entrySet ( ) ) { final String channelId = entry . getKey ( ) ; final List < DeployGroup > groups = entry . getValue ( ) . stream ( ) . map ( groupId -> model . getDeployGroup ( groupId ) ) . collect ( Collectors . toList ( ) ) ; this . deployKeysMap . putAll ( channelId , groups ) ; }


signature:
public class ChannelServiceImpl { /** * methods of DeployAuthService */
@ Override public List < DeployGroup > listGroups ( final int position , final int count ) { } }

implementation: return this . manager . accessCall ( KEY_STORAGE , ChannelServiceAccess . class , model -> { return split ( model . getDeployGroups ( ) , position , count ) ; } ) ;


signature:
public class ChannelServiceImpl { /** * statistics */
@ Override public ChannelStatistics getStatistics ( ) { } }

implementation: final ChannelStatistics cs = new ChannelStatistics ( ) ; try ( Locked l = lock ( this . readLock ) ) { final Collection < ChannelInformation > cis = list ( ) ; cs . setTotalNumberOfArtifacts ( cis . stream ( ) . mapToLong ( ci -> ci . getState ( ) . getNumberOfArtifacts ( ) ) . sum ( ) ) ; cs . setTotalNumberOfBytes ( cis . stream ( ) . mapToLong ( ci -> ci . getState ( ) . getNumberOfBytes ( ) ) . sum ( ) ) ; } return cs ;


signature:
public class Streams { /** * Copy the remaining content of one stream to the other
 * @ param in
 * the input stream
 * @ param out
 * the output stream
 * @ return the number of bytes copied
 * @ throws IOException
 * if any I / O error occurs */
public static long copy ( final InputStream in , final OutputStream out ) throws IOException { } }

implementation: Objects . requireNonNull ( in ) ; Objects . requireNonNull ( out ) ; final byte [ ] buffer = new byte [ COPY_BUFFER_SIZE ] ; long result = 0 ; int rc ; while ( ( rc = in . read ( buffer ) ) >= 0 ) { result += rc ; out . write ( buffer , 0 , rc ) ; } return result ;


signature:
public class Streams { /** * Copy the remaining content of one reader to the { @ link Appendable } ( or
 * { @ link Writer }
 * @ param readable
 * the input readable
 * @ param appendable
 * the output appendable
 * @ return the number of characters copied
 * @ throws IOException
 * if any I / O error occurs */
public static long copy ( final Readable readable , final Appendable appendable ) throws IOException { } }

implementation: final CharBuffer buffer = CharBuffer . allocate ( COPY_BUFFER_SIZE ) ; long total = 0 ; while ( readable . read ( buffer ) >= 0 ) { buffer . flip ( ) ; appendable . append ( buffer ) ; total += buffer . remaining ( ) ; buffer . clear ( ) ; } return total ;


signature:
public class Parser { /** * The main entry for Parser
 * @ param pc The ParseController , use for getting other objects in compiler
 * and for parsing included pages
 * @ param reader To read the page
 * @ param parent The parent node to this page , null for top level page
 * @ return list of nodes representing the parsed page */
public static Node . Nodes parse ( ParserController pc , String path , JspReader reader , Node parent , boolean isTagFile , boolean directivesOnly , URL jarFileUrl , String pageEnc , String jspConfigPageEnc , boolean isDefaultPageEncoding , boolean hasBom ) throws JasperException { } }

implementation:
Parser parser = new Parser ( pc , reader , isTagFile , directivesOnly , jarFileUrl , hasBom ) ; Node . Root root = new Node . Root ( reader . mark ( ) , parent , false ) ; root . setPageEncoding ( pageEnc ) ; root . setJspConfigPageEncoding ( jspConfigPageEnc ) ; root . setIsDefaultPageEncoding ( isDefaultPageEncoding ) ; root . setHasBom ( hasBom ) ; if ( hasBom ) { // Consume ( remove ) BOM , so it won ' t appear in page output
char bomChar = ( char ) reader . nextChar ( ) ; if ( bomChar != 0xFEFF ) { parser . err . jspError ( reader . mark ( ) , "jsp.error.invalidBom" , Integer . toHexString ( bomChar ) . toUpperCase ( ) ) ; } } if ( directivesOnly ) { parser . parseTagFileDirectives ( root ) ; return new Node . Nodes ( root ) ; } // For the Top level page , add inlcude - prelude and include - coda
PageInfo pageInfo = pc . getCompiler ( ) . getPageInfo ( ) ; if ( parent == null ) { parser . addInclude ( root , pageInfo . getIncludePrelude ( ) ) ; } while ( reader . hasMoreInput ( ) ) { parser . parseElements ( root ) ; } if ( parent == null ) { parser . addInclude ( root , pageInfo . getIncludeCoda ( ) ) ; parser . pageInfo . setRootPath ( path ) ; } Node . Nodes page = new Node . Nodes ( root ) ; return page ;


signature:
public class Parser { /** * Attributes : : = ( S Attribute ) * S ? */
Attributes parseAttributes ( ) throws JasperException { } }

implementation: AttributesImpl attrs = new AttributesImpl ( ) ; reader . skipSpaces ( ) ; while ( parseAttribute ( attrs ) ) reader . skipSpaces ( ) ; return attrs ;


signature:
public class Parser { /** * Parse Attributes for a reader , provided for external use */
public static Attributes parseAttributes ( ParserController pc , JspReader reader ) throws JasperException { } }

implementation: Parser tmpParser = new Parser ( pc , reader , false , false , null , false ) ; return tmpParser . parseAttributes ( ) ;


signature:
public class Parser { /** * Attribute : : = Name S ? Eq S ?
 * ( ' " < % = ' RTAttributeValueDouble
 * | ' " ' AttributeValueDouble
 * | " ' < % = " RTAttributeValueSingle
 * | " ' " AttributeValueSingle
 * Note : JSP and XML spec does not allow while spaces around Eq . It is
 * added to be backward compatible with Tomcat , and with other xml parsers . */
private boolean parseAttribute ( AttributesImpl attrs ) throws JasperException { } }

implementation:
// Get the qualified name
String qName = parseName ( ) ; if ( qName == null ) return false ; // Determine prefix and local name components
String localName = qName ; String uri = "" ; int index = qName . indexOf ( ':' ) ; if ( index != - 1 ) { String prefix = qName . substring ( 0 , index ) ; uri = pageInfo . getURI ( prefix ) ; if ( uri == null ) { err . jspError ( reader . mark ( ) , "jsp.error.attribute.invalidPrefix" , prefix ) ; } localName = qName . substring ( index + 1 ) ; } reader . skipSpaces ( ) ; if ( ! reader . matches ( "=" ) ) err . jspError ( reader . mark ( ) , "jsp.error.attribute.noequal" ) ; reader . skipSpaces ( ) ; char quote = ( char ) reader . nextChar ( ) ; if ( quote != '\'' && quote != '"' ) err . jspError ( reader . mark ( ) , "jsp.error.attribute.noquote" ) ; String watchString = "" ; if ( reader . matches ( "<%=" ) ) watchString = "%>" ; watchString = watchString + quote ; String attrValue = parseAttributeValue ( watchString ) ; attrs . addAttribute ( uri , localName , qName , "CDATA" , attrValue ) ; return true ;


signature:
public class Parser { /** * Name : : = ( Letter | ' _ ' | ' : ' ) ( Letter | Digit | ' . ' | ' _ ' | ' - ' | ' : ' ) * */
private String parseName ( ) throws JasperException { } }

implementation: char ch = ( char ) reader . peekChar ( ) ; if ( Character . isLetter ( ch ) || ch == '_' || ch == ':' ) { StringBuilder buf = new StringBuilder ( ) ; buf . append ( ch ) ; reader . nextChar ( ) ; ch = ( char ) reader . peekChar ( ) ; while ( Character . isLetter ( ch ) || Character . isDigit ( ch ) || ch == '.' || ch == '_' || ch == '-' || ch == ':' ) { buf . append ( ch ) ; reader . nextChar ( ) ; ch = ( char ) reader . peekChar ( ) ; } return buf . toString ( ) ; } return null ;


signature:
public class Parser { /** * AttributeValueDouble : : = ( QuotedChar - ' " ' ) *
 * ( ' " ' | < TRANSLATION _ ERROR > )
 * RTAttributeValueDouble : : = ( ( QuotedChar - ' " ' ) * - ( ( QuotedChar - ' " ' ) ' % > " ' )
 * ( ' % > " ' | TRANSLATION _ ERROR ) */
private String parseAttributeValue ( String watch ) throws JasperException { } }

implementation:
Mark start = reader . mark ( ) ; Mark stop = reader . skipUntilIgnoreEsc ( watch ) ; if ( stop == null ) { err . jspError ( start , "jsp.error.attribute.unterminated" , watch ) ; } String ret = parseQuoted ( reader . getText ( start , stop ) ) ; if ( watch . length ( ) == 1 ) // quote
return ret ; // putback delimiter ' < % = ' and ' % > ' , since they are needed if the
// attribute does not allow RTexpression .
return "<%=" + ret + "%>" ;


signature:
public class Parser { /** * may be send to EL processor . */
private String parseQuoted ( String tx ) { } }

implementation: StringBuilder buf = new StringBuilder ( ) ; int size = tx . length ( ) ; int i = 0 ; while ( i < size ) { char ch = tx . charAt ( i ) ; if ( ch == '&' ) { if ( i + 5 < size && tx . charAt ( i + 1 ) == 'a' && tx . charAt ( i + 2 ) == 'p' && tx . charAt ( i + 3 ) == 'o' && tx . charAt ( i + 4 ) == 's' && tx . charAt ( i + 5 ) == ';' ) { buf . append ( '\'' ) ; i += 6 ; } else if ( i + 5 < size && tx . charAt ( i + 1 ) == 'q' && tx . charAt ( i + 2 ) == 'u' && tx . charAt ( i + 3 ) == 'o' && tx . charAt ( i + 4 ) == 't' && tx . charAt ( i + 5 ) == ';' ) { buf . append ( '"' ) ; i += 6 ; } else { buf . append ( ch ) ; ++ i ; } } else if ( ch == '\\' && i + 1 < size ) { ch = tx . charAt ( i + 1 ) ; if ( ch == '\\' || ch == '\"' || ch == '\'' || ch == '>' ) { buf . append ( ch ) ; i += 2 ; } else { buf . append ( '\\' ) ; ++ i ; } } else { buf . append ( ch ) ; ++ i ; } } return buf . toString ( ) ;


signature:
public class Parser { /** * Invokes parserController to parse the included page */
private void processIncludeDirective ( String file , Node parent ) throws JasperException { } }

implementation: if ( file == null ) { return ; } try { parserController . parse ( file , parent , jarFileUrl ) ; } catch ( FileNotFoundException ex ) { err . jspError ( start , "jsp.error.file.not.found" , file ) ; } catch ( Exception ex ) { err . jspError ( start , ex ) ; }


signature:
public class Parser { /** * Parses a page directive with the following syntax :
 * PageDirective : : = ( S Attribute ) * */
private void parsePageDirective ( Node parent ) throws JasperException { } }

implementation:
Attributes attrs = parseAttributes ( ) ; Node . PageDirective n = new Node . PageDirective ( attrs , start , parent ) ; /* * A page directive may contain multiple ' import ' attributes , each of
 * which consists of a comma - separated list of package names .
 * Store each list with the node , where it is parsed . */
for ( int i = 0 ; i < attrs . getLength ( ) ; i ++ ) { if ( "import" . equals ( attrs . getQName ( i ) ) ) { n . addImport ( attrs . getValue ( i ) ) ; } }


signature:
public class Parser { /** * Parses an include directive with the following syntax :
 * IncludeDirective : : = ( S Attribute ) * */
private void parseIncludeDirective ( Node parent ) throws JasperException { } }

implementation:
Attributes attrs = parseAttributes ( ) ; // Included file expanded here
Node includeNode = new Node . IncludeDirective ( attrs , start , parent ) ; processIncludeDirective ( attrs . getValue ( "file" ) , includeNode ) ;


signature:
public class Parser { /** * Add a list of files . This is used for implementing include - prelude
 * and include - coda of jsp - config element in web . xml */
private void addInclude ( Node parent , List files ) throws JasperException { } }

implementation:
if ( files != null ) { Iterator iter = files . iterator ( ) ; while ( iter . hasNext ( ) ) { String file = ( String ) iter . next ( ) ; AttributesImpl attrs = new AttributesImpl ( ) ; attrs . addAttribute ( "" , "file" , "file" , "CDATA" , file ) ; // Create a dummy Include directive node
Node includeNode = new Node . IncludeDirective ( attrs , reader . mark ( ) , parent ) ; processIncludeDirective ( file , includeNode ) ; } }


signature:
public class Parser { /** * Parses a taglib directive with the following syntax :
 * Directive : : = ( S Attribute ) * */
private void parseTaglibDirective ( Node parent ) throws JasperException { } }

implementation:
Attributes attrs = parseAttributes ( ) ; String uri = attrs . getValue ( "uri" ) ; String prefix = attrs . getValue ( "prefix" ) ; if ( prefix != null ) { Mark prevMark = pageInfo . getNonCustomTagPrefix ( prefix ) ; if ( prevMark != null ) { err . jspError ( reader . mark ( ) , "jsp.error.prefix.use_before_dcl" , prefix , prevMark . getFile ( ) , "" + prevMark . getLineNumber ( ) ) ; } if ( uri != null ) { String uriPrev = pageInfo . getURI ( prefix ) ; if ( uriPrev != null && ! uriPrev . equals ( uri ) ) { err . jspError ( reader . mark ( ) , "jsp.error.prefix.refined" , prefix , uri , uriPrev ) ; } /* GlassFish 750
 if ( pageInfo . getTaglib ( uri ) = = null ) {
 String [ ] location = ctxt . getTldLocation ( uri ) ;
 TagLibraryInfoImpl taglib = null ;
 try {
 taglib = new TagLibraryInfoImpl ( ctxt ,
 parserController ,
 prefix ,
 uri ,
 location ,
 err ) ;
 } catch ( JasperException je ) {
 err . throwException ( reader . mark ( ) , je ) ;
 pageInfo . addTaglib ( uri , taglib ) ; */
// START GlassFish 750
ConcurrentHashMap < String , TagLibraryInfoImpl > taglibs = ctxt . getTaglibs ( ) ; TagLibraryInfoImpl taglib = taglibs . get ( uri ) ; if ( taglib == null ) { synchronized ( taglibs ) { taglib = taglibs . get ( uri ) ; if ( taglib == null ) { String [ ] location = ctxt . getTldLocation ( uri ) ; try { taglib = new TagLibraryInfoImpl ( ctxt , parserController , prefix , uri , location , err ) ; } catch ( JasperException je ) { err . throwException ( reader . mark ( ) , je ) ; } ctxt . addTaglib ( uri , taglib ) ; pageInfo . addTaglib ( uri , taglib ) ; } } } if ( pageInfo . getTaglib ( uri ) == null ) { pageInfo . addTaglib ( uri , new TagLibraryInfoImpl ( prefix , uri , taglib , pageInfo ) ) ; } // END GlassFish 750
pageInfo . addPrefixMapping ( prefix , uri ) ; } else { String tagdir = attrs . getValue ( "tagdir" ) ; if ( tagdir != null ) { String urnTagdir = URN_JSPTAGDIR + tagdir ; if ( pageInfo . getTaglib ( urnTagdir ) == null ) { pageInfo . addTaglib ( urnTagdir , new ImplicitTagLibraryInfo ( ctxt , parserController , prefix , tagdir , err ) ) ; } pageInfo . addPrefixMapping ( prefix , urnTagdir ) ; } } } new Node . TaglibDirective ( attrs , start , parent ) ;


signature:
public class Parser { /** * Parses a directive with the following syntax :
 * Directive : : = S ? ( ' page ' PageDirective
 * | ' include ' IncludeDirective
 * | ' taglib ' TagLibDirective )
 * TagDirective : : = S ? ( ' tag ' PageDirective
 * | ' include ' IncludeDirective
 * | ' taglib ' TagLibDirective )
 * | ' attribute AttributeDirective
 * | ' variable VariableDirective */
private void parseDirective ( Node parent ) throws JasperException { } }

implementation:
reader . skipSpaces ( ) ; String directive = null ; if ( reader . matches ( "page" ) ) { directive = "<%@ page" ; if ( isTagFile ) { err . jspError ( reader . mark ( ) , "jsp.error.directive.istagfile" , directive ) ; } parsePageDirective ( parent ) ; } else if ( reader . matches ( "include" ) ) { directive = "<%@ include" ; parseIncludeDirective ( parent ) ; } else if ( reader . matches ( "taglib" ) ) { if ( directivesOnly ) { // No need to get the tagLibInfo objects . This alos suppresses
// parsing of any tag files used in this tag file .
return ; } directive = "<%@ taglib" ; parseTaglibDirective ( parent ) ; } else if ( reader . matches ( "tag" ) ) { directive = "<%@ tag" ; if ( ! isTagFile ) { err . jspError ( reader . mark ( ) , "jsp.error.directive.isnottagfile" , directive ) ; } parseTagDirective ( parent ) ; } else if ( reader . matches ( "attribute" ) ) { directive = "<%@ attribute" ; if ( ! isTagFile ) { err . jspError ( reader . mark ( ) , "jsp.error.directive.isnottagfile" , directive ) ; } parseAttributeDirective ( parent ) ; } else if ( reader . matches ( "variable" ) ) { directive = "<%@ variable" ; if ( ! isTagFile ) { err . jspError ( reader . mark ( ) , "jsp.error.directive.isnottagfile" , directive ) ; } parseVariableDirective ( parent ) ; } else { err . jspError ( reader . mark ( ) , "jsp.error.invalid.directive" , reader . parseToken ( false ) ) ; } reader . skipSpaces ( ) ; if ( ! reader . matches ( "%>" ) ) { err . jspError ( start , "jsp.error.unterminated" , directive ) ; }


signature:
public class Parser { /** * Parses a directive with the following syntax :
 * XMLJSPDirectiveBody : : = S ? ( ( ' page ' PageDirectiveAttrList
 * S ? ( ' / > ' | ( ' > ' S ? ETag ) )
 * | ( ' include ' IncludeDirectiveAttrList
 * S ? ( ' / > ' | ( ' > ' S ? ETag ) )
 * | < TRANSLATION _ ERROR >
 * XMLTagDefDirectiveBody : : = ( ( ' tag ' TagDirectiveAttrList
 * S ? ( ' / > ' | ( ' > ' S ? ETag ) )
 * | ( ' include ' IncludeDirectiveAttrList
 * S ? ( ' / > ' | ( ' > ' S ? ETag ) )
 * | ( ' attribute ' AttributeDirectiveAttrList
 * S ? ( ' / > ' | ( ' > ' S ? ETag ) )
 * | ( ' variable ' VariableDirectiveAttrList
 * S ? ( ' / > ' | ( ' > ' S ? ETag ) )
 * | < TRANSLATION _ ERROR > */
private void parseXMLDirective ( Node parent ) throws JasperException { } }

implementation: reader . skipSpaces ( ) ; String eTag = null ; if ( reader . matches ( "page" ) ) { eTag = "jsp:directive.page" ; if ( isTagFile ) { err . jspError ( reader . mark ( ) , "jsp.error.directive.istagfile" , "<" + eTag ) ; } parsePageDirective ( parent ) ; } else if ( reader . matches ( "include" ) ) { eTag = "jsp:directive.include" ; parseIncludeDirective ( parent ) ; } else if ( reader . matches ( "tag" ) ) { eTag = "jsp:directive.tag" ; if ( ! isTagFile ) { err . jspError ( reader . mark ( ) , "jsp.error.directive.isnottagfile" , "<" + eTag ) ; } parseTagDirective ( parent ) ; } else if ( reader . matches ( "attribute" ) ) { eTag = "jsp:directive.attribute" ; if ( ! isTagFile ) { err . jspError ( reader . mark ( ) , "jsp.error.directive.isnottagfile" , "<" + eTag ) ; } parseAttributeDirective ( parent ) ; } else if ( reader . matches ( "variable" ) ) { eTag = "jsp:directive.variable" ; if ( ! isTagFile ) { err . jspError ( reader . mark ( ) , "jsp.error.directive.isnottagfile" , "<" + eTag ) ; } parseVariableDirective ( parent ) ; } else { err . jspError ( reader . mark ( ) , "jsp.error.invalid.directive" , reader . parseToken ( false ) ) ; } reader . skipSpaces ( ) ; if ( reader . matches ( ">" ) ) { reader . skipSpaces ( ) ; if ( ! reader . matchesETag ( eTag ) ) { err . jspError ( start , "jsp.error.unterminated" , "<" + eTag ) ; } } else if ( ! reader . matches ( "/>" ) ) { err . jspError ( start , "jsp.error.unterminated" , "<" + eTag ) ; }


signature:
public class Parser { /** * Parses a tag directive with the following syntax :
 * PageDirective : : = ( S Attribute ) * */
private void parseTagDirective ( Node parent ) throws JasperException { } }

implementation:
Attributes attrs = parseAttributes ( ) ; Node . TagDirective n = new Node . TagDirective ( attrs , start , parent ) ; /* * A page directive may contain multiple ' import ' attributes , each of
 * which consists of a comma - separated list of package names .
 * Store each list with the node , where it is parsed . */
for ( int i = 0 ; i < attrs . getLength ( ) ; i ++ ) { if ( "import" . equals ( attrs . getQName ( i ) ) ) { n . addImport ( attrs . getValue ( i ) ) ; } }


signature:
public class Parser { /** * Parses a attribute directive with the following syntax :
 * AttributeDirective : : = ( S Attribute ) * */
private void parseAttributeDirective ( Node parent ) throws JasperException { } }

implementation: Attributes attrs = parseAttributes ( ) ; new Node . AttributeDirective ( attrs , start , parent ) ;


signature:
public class Parser { /** * Parses a variable directive with the following syntax :
 * PageDirective : : = ( S Attribute ) * */
private void parseVariableDirective ( Node parent ) throws JasperException { } }

implementation: Attributes attrs = parseAttributes ( ) ; new Node . VariableDirective ( attrs , start , parent ) ;


signature:
public class Parser { /** * JSPCommentBody : : = ( Char * - ( Char * ' - - % > ' ) ) ' - - % > ' */
private void parseComment ( Node parent ) throws JasperException { } }

implementation: start = reader . mark ( ) ; Mark stop = reader . skipUntil ( "--%>" ) ; if ( stop == null ) { err . jspError ( start , "jsp.error.unterminated" , "<%--" ) ; } new Node . Comment ( reader . getText ( start , stop ) , start , parent ) ;


signature:
public class Parser { /** * DeclarationBody : : = ( Char * - ( char * ' % > ' ) ) ' % > ' */
private void parseDeclaration ( Node parent ) throws JasperException { } }

implementation: start = reader . mark ( ) ; Mark stop = reader . skipUntil ( "%>" ) ; if ( stop == null ) { err . jspError ( start , "jsp.error.unterminated" , "<%!" ) ; } new Node . Declaration ( parseScriptText ( reader . getText ( start , stop ) ) , start , parent ) ;


signature:
public class Parser { /** * XMLDeclarationBody : : = ( S ? ' / > ' )
 * | ( S ? ' > ' ( Char * - ( char * ' < ' ) ) CDSect ? ) * ETag
 * | < TRANSLATION _ ERROR >
 * CDSect : : = CDStart CData CDEnd
 * CDStart : : = ' < ! [ CDATA [ '
 * CData : : = ( Char * - ( Char * ' ] ] > ' Char * ) )
 * CDEnd : : = ' ] ] > ' */
private void parseXMLDeclaration ( Node parent ) throws JasperException { } }

implementation: reader . skipSpaces ( ) ; if ( ! reader . matches ( "/>" ) ) { if ( ! reader . matches ( ">" ) ) { err . jspError ( start , "jsp.error.unterminated" , "<jsp:declaration>" ) ; } Mark stop ; String text ; while ( true ) { start = reader . mark ( ) ; stop = reader . skipUntil ( "<" ) ; if ( stop == null ) { err . jspError ( start , "jsp.error.unterminated" , "<jsp:declaration>" ) ; } text = parseScriptText ( reader . getText ( start , stop ) ) ; new Node . Declaration ( text , start , parent ) ; if ( reader . matches ( "![CDATA[" ) ) { start = reader . mark ( ) ; stop = reader . skipUntil ( "]]>" ) ; if ( stop == null ) { err . jspError ( start , "jsp.error.unterminated" , "CDATA" ) ; } text = parseScriptText ( reader . getText ( start , stop ) ) ; new Node . Declaration ( text , start , parent ) ; } else { break ; } } if ( ! reader . matchesETagWithoutLessThan ( "jsp:declaration" ) ) { err . jspError ( start , "jsp.error.unterminated" , "<jsp:declaration>" ) ; } }


signature:
public class Parser { /** * ExpressionBody : : = ( Char * - ( char * ' % > ' ) ) ' % > ' */
private void parseExpression ( Node parent ) throws JasperException { } }

implementation: start = reader . mark ( ) ; Mark stop = reader . skipUntil ( "%>" ) ; if ( stop == null ) { err . jspError ( start , "jsp.error.unterminated" , "<%=" ) ; } new Node . Expression ( parseScriptText ( reader . getText ( start , stop ) ) , start , parent ) ;


signature:
public class Parser { /** * ELExpressionBody
 * ( following " $ { " or " # { " to first unquoted " } " )
 * / / XXX add formal production and confirm implementation against it ,
 * / / once it ' s decided */
private void parseELExpression ( Node parent , String typeEL ) throws JasperException { } }

implementation:
start = reader . mark ( ) ; boolean singleQuoted = false , doubleQuoted = false ; int curl = 0 ; int currentChar ; do { // XXX could move this logic to JspReader
currentChar = reader . nextChar ( ) ; if ( currentChar == '\\' && ( singleQuoted || doubleQuoted ) ) { // skip character following ' \ ' within quotes
reader . nextChar ( ) ; currentChar = reader . nextChar ( ) ; } if ( currentChar == - 1 ) err . jspError ( start , "jsp.error.unterminated" , typeEL ) ; if ( currentChar == '"' ) doubleQuoted = ! doubleQuoted ; else if ( currentChar == '\'' ) singleQuoted = ! singleQuoted ; else if ( currentChar == '{' ) curl ++ ; else if ( currentChar == '}' ) curl -- ; } while ( currentChar != '}' || curl >= 0 || singleQuoted || doubleQuoted ) ; String text = typeEL + reader . getText ( start , reader . mark ( ) ) ; new Node . ELExpression ( text , start , parent ) ;


signature:
public class Parser { /** * ScriptletBody : : = ( Char * - ( char * ' % > ' ) ) ' % > ' */
private void parseScriptlet ( Node parent ) throws JasperException { } }

implementation: start = reader . mark ( ) ; Mark stop = reader . skipUntil ( "%>" ) ; if ( stop == null ) { err . jspError ( start , "jsp.error.unterminated" , "<%" ) ; } new Node . Scriptlet ( parseScriptText ( reader . getText ( start , stop ) ) , start , parent ) ;


signature:
public class Parser { /** * Param : : = ' < jsp : param ' S Attributes S ? EmptyBody S ? */
private void parseParam ( Node parent ) throws JasperException { } }

implementation: if ( ! reader . matches ( "<jsp:param" ) ) { err . jspError ( reader . mark ( ) , "jsp.error.paramexpected" ) ; } Attributes attrs = parseAttributes ( ) ; reader . skipSpaces ( ) ; Node paramActionNode = new Node . ParamAction ( attrs , start , parent ) ; parseEmptyBody ( paramActionNode , "jsp:param" ) ; reader . skipSpaces ( ) ;


signature:
public class Parser { /** * For Include :
 * StdActionContent : : = Attributes ParamBody
 * ParamBody : : = EmptyBody
 * | ( ' > ' S ? ( ' < jsp : attribute ' NamedAttributes ) ?
 * ' < jsp : body '
 * ( JspBodyParam | < TRANSLATION _ ERROR > )
 * S ? ETag
 * | ( ' > ' S ? Param * ETag )
 * EmptyBody : : = ' / > '
 * | ( ' > ' ETag )
 * | ( ' > ' S ? ' < jsp : attribute ' NamedAttributes ETag )
 * JspBodyParam : : = S ? ' > ' Param * ' < / jsp : body > ' */
private void parseInclude ( Node parent ) throws JasperException { } }

implementation: Attributes attrs = parseAttributes ( ) ; reader . skipSpaces ( ) ; Node includeNode = new Node . IncludeAction ( attrs , start , parent ) ; parseOptionalBody ( includeNode , "jsp:include" , JAVAX_BODY_CONTENT_PARAM ) ;


signature:
public class Parser { /** * For Forward :
 * StdActionContent : : = Attributes ParamBody */
private void parseForward ( Node parent ) throws JasperException { } }

implementation: Attributes attrs = parseAttributes ( ) ; reader . skipSpaces ( ) ; Node forwardNode = new Node . ForwardAction ( attrs , start , parent ) ; parseOptionalBody ( forwardNode , "jsp:forward" , JAVAX_BODY_CONTENT_PARAM ) ;


signature:
public class Parser { /** * For GetProperty :
 * StdActionContent : : = Attributes EmptyBody */
private void parseGetProperty ( Node parent ) throws JasperException { } }

implementation: Attributes attrs = parseAttributes ( ) ; reader . skipSpaces ( ) ; Node getPropertyNode = new Node . GetProperty ( attrs , start , parent ) ; parseOptionalBody ( getPropertyNode , "jsp:getProperty" , TagInfo . BODY_CONTENT_EMPTY ) ;


signature:
public class Parser { /** * For SetProperty :
 * StdActionContent : : = Attributes EmptyBody */
private void parseSetProperty ( Node parent ) throws JasperException { } }

implementation: Attributes attrs = parseAttributes ( ) ; reader . skipSpaces ( ) ; Node setPropertyNode = new Node . SetProperty ( attrs , start , parent ) ; parseOptionalBody ( setPropertyNode , "jsp:setProperty" , TagInfo . BODY_CONTENT_EMPTY ) ;


signature:
public class Parser { /** * EmptyBody : : = ' / > '
 * | ( ' > ' ETag )
 * | ( ' > ' S ? ' < jsp : attribute ' NamedAttributes ETag ) */
private void parseEmptyBody ( Node parent , String tag ) throws JasperException { } }

implementation:
if ( reader . matches ( "/>" ) ) { // Done
} else if ( reader . matches ( ">" ) ) { if ( reader . matchesETag ( tag ) ) { // Done
} else if ( reader . matchesOptionalSpacesFollowedBy ( "<jsp:attribute" ) ) { // Parse the one or more named attribute nodes
parseNamedAttributes ( parent ) ; if ( ! reader . matchesETag ( tag ) ) { // Body not allowed
err . jspError ( reader . mark ( ) , "jsp.error.jspbody.emptybody.only" , "<" + tag ) ; } } else { err . jspError ( reader . mark ( ) , "jsp.error.jspbody.emptybody.only" , "<" + tag ) ; } } else { err . jspError ( reader . mark ( ) , "jsp.error.unterminated" , "<" + tag ) ; }


signature:
public class Parser { /** * For UseBean :
 * StdActionContent : : = Attributes OptionalBody */
private void parseUseBean ( Node parent ) throws JasperException { } }

implementation: Attributes attrs = parseAttributes ( ) ; reader . skipSpaces ( ) ; Node useBeanNode = new Node . UseBean ( attrs , start , parent ) ; parseOptionalBody ( useBeanNode , "jsp:useBean" , TagInfo . BODY_CONTENT_JSP ) ;


signature:
public class Parser { /** * Parses OptionalBody , but also reused to parse bodies for plugin
 * and param since the syntax is identical ( the only thing that
 * differs substantially is how to process the body , and thus
 * we accept the body type as a parameter ) .
 * OptionalBody : : = EmptyBody | ActionBody
 * ScriptlessOptionalBody : : = EmptyBody | ScriptlessActionBody
 * TagDependentOptionalBody : : = EmptyBody | TagDependentActionBody
 * EmptyBody : : = ' / > '
 * | ( ' > ' ETag )
 * | ( ' > ' S ? ' < jsp : attribute ' NamedAttributes ETag )
 * ActionBody : : = JspAttributeAndBody
 * | ( ' > ' Body ETag )
 * ScriptlessActionBody : : = JspAttributeAndBody
 * | ( ' > ' ScriptlessBody ETag )
 * TagDependentActionBody : : = JspAttributeAndBody
 * | ( ' > ' TagDependentBody ETag ) */
private void parseOptionalBody ( Node parent , String tag , String bodyType ) throws JasperException { } }

implementation:
if ( reader . matches ( "/>" ) ) { // EmptyBody
return ; } if ( ! reader . matches ( ">" ) ) { err . jspError ( reader . mark ( ) , "jsp.error.unterminated" , "<" + tag ) ; } if ( reader . matchesETag ( tag ) ) { // EmptyBody
return ; } if ( ! parseJspAttributeAndBody ( parent , tag , bodyType ) ) { // Must be ( ' > ' # Body ETag )
parseBody ( parent , tag , bodyType ) ; }


signature:
public class Parser { /** * Attempts to parse ' JspAttributeAndBody ' production . Returns true if
 * it matched , or false if not . Assumes EmptyBody is okay as well .
 * JspAttributeAndBody : : =
 * ( ' > ' # S ? ( ' < jsp : attribute ' NamedAttributes ) ?
 * ' < jsp : body '
 * ( JspBodyBody | < TRANSLATION _ ERROR > )
 * S ? ETag */
private boolean parseJspAttributeAndBody ( Node parent , String tag , String bodyType ) throws JasperException { } }

implementation:
boolean result = false ; if ( reader . matchesOptionalSpacesFollowedBy ( "<jsp:attribute" ) ) { // May be an EmptyBody , depending on whether
// There ' s a " < jsp : body " before the ETag
// First , parse < jsp : attribute > elements :
parseNamedAttributes ( parent ) ; result = true ; } if ( reader . matchesOptionalSpacesFollowedBy ( "<jsp:body" ) ) { // ActionBody
parseJspBody ( parent , bodyType ) ; reader . skipSpaces ( ) ; if ( ! reader . matchesETag ( tag ) ) { err . jspError ( reader . mark ( ) , "jsp.error.unterminated" , "<" + tag ) ; } result = true ; } else if ( result && ! reader . matchesETag ( tag ) ) { // If we have < jsp : attribute > but something other than
// < jsp : body > or the end tag , translation error .
err . jspError ( reader . mark ( ) , "jsp.error.jspbody.required" , "<" + tag ) ; } return result ;


signature:
public class Parser { /** * Params : : = ` > ' S ?
 * ( ( ` < jsp : body > '
 * ( ( S ? Param + S ? ` < / jsp : body > ' )
 * | < TRANSLATION _ ERROR >
 * | Param +
 * ' < / jsp : params > ' */
private void parseJspParams ( Node parent ) throws JasperException { } }

implementation: Node jspParamsNode = new Node . ParamsAction ( start , parent ) ; parseOptionalBody ( jspParamsNode , "jsp:params" , JAVAX_BODY_CONTENT_PARAM ) ;


signature:
public class Parser { /** * Fallback : : = ' / > '
 * | ( ` > ' S ? ` < jsp : body > '
 * ( Char * - ( Char * ` < / jsp : body > ' ) )
 * ` < / jsp : body > ' S ?
 * | < TRANSLATION _ ERROR >
 * ` < / jsp : fallback > '
 * ( Char * - ( Char * ' < / jsp : fallback > ' ) )
 * ' < / jsp : fallback > ' */
private void parseFallBack ( Node parent ) throws JasperException { } }

implementation: Node fallBackNode = new Node . FallBackAction ( start , parent ) ; parseOptionalBody ( fallBackNode , "jsp:fallback" , JAVAX_BODY_CONTENT_TEMPLATE_TEXT ) ;


signature:
public class Parser { /** * For Plugin :
 * StdActionContent : : = Attributes PluginBody
 * PluginBody : : = EmptyBody
 * | ( ' > ' S ? ( ' < jsp : attribute ' NamedAttributes ) ?
 * ' < jsp : body '
 * ( JspBodyPluginTags | < TRANSLATION _ ERROR > )
 * S ? ETag
 * | ( ' > ' S ? PluginTags ETag )
 * EmptyBody : : = ' / > '
 * | ( ' > ' ETag )
 * | ( ' > ' S ? ' < jsp : attribute ' NamedAttributes ETag ) */
private void parsePlugin ( Node parent ) throws JasperException { } }

implementation: Attributes attrs = parseAttributes ( ) ; reader . skipSpaces ( ) ; Node pluginNode = new Node . PlugIn ( attrs , start , parent ) ; parseOptionalBody ( pluginNode , "jsp:plugin" , JAVAX_BODY_CONTENT_PLUGIN ) ;


signature:
public class Parser { /** * PluginTags : : = ( ' < jsp : params ' Params S ? ) ?
 * ( ' < jsp : fallback ' Fallback ? S ? ) ? */
private void parsePluginTags ( Node parent ) throws JasperException { } }

implementation: reader . skipSpaces ( ) ; if ( reader . matches ( "<jsp:params" ) ) { parseJspParams ( parent ) ; reader . skipSpaces ( ) ; } if ( reader . matches ( "<jsp:fallback" ) ) { parseFallBack ( parent ) ; reader . skipSpaces ( ) ; }


signature:
public class Parser { /** * StandardAction : : = ' include ' StdActionContent
 * | ' forward ' StdActionContent
 * | ' invoke ' StdActionContent
 * | ' doBody ' StdActionContent
 * | ' getProperty ' StdActionContent
 * | ' setProperty ' StdActionContent
 * | ' useBean ' StdActionContent
 * | ' plugin ' StdActionContent
 * | ' element ' StdActionContent */
private void parseStandardAction ( Node parent ) throws JasperException { } }

implementation: Mark start = reader . mark ( ) ; if ( reader . matches ( INCLUDE_ACTION ) ) { parseInclude ( parent ) ; } else if ( reader . matches ( FORWARD_ACTION ) ) { parseForward ( parent ) ; } else if ( reader . matches ( INVOKE_ACTION ) ) { if ( ! isTagFile ) { err . jspError ( reader . mark ( ) , "jsp.error.action.isnottagfile" , "<jsp:invoke" ) ; } parseInvoke ( parent ) ; } else if ( reader . matches ( DOBODY_ACTION ) ) { if ( ! isTagFile ) { err . jspError ( reader . mark ( ) , "jsp.error.action.isnottagfile" , "<jsp:doBody" ) ; } parseDoBody ( parent ) ; } else if ( reader . matches ( GET_PROPERTY_ACTION ) ) { parseGetProperty ( parent ) ; } else if ( reader . matches ( SET_PROPERTY_ACTION ) ) { parseSetProperty ( parent ) ; } else if ( reader . matches ( USE_BEAN_ACTION ) ) { parseUseBean ( parent ) ; } else if ( reader . matches ( PLUGIN_ACTION ) ) { parsePlugin ( parent ) ; } else if ( reader . matches ( ELEMENT_ACTION ) ) { parseElement ( parent ) ; } else if ( reader . matches ( ATTRIBUTE_ACTION ) ) { err . jspError ( start , "jsp.error.namedAttribute.invalidUse" ) ; } else if ( reader . matches ( BODY_ACTION ) ) { err . jspError ( start , "jsp.error.jspbody.invalidUse" ) ; } else if ( reader . matches ( FALLBACK_ACTION ) ) { err . jspError ( start , "jsp.error.fallback.invalidUse" ) ; } else if ( reader . matches ( PARAMS_ACTION ) ) { err . jspError ( start , "jsp.error.params.invalidUse" ) ; } else if ( reader . matches ( PARAM_ACTION ) ) { err . jspError ( start , "jsp.error.param.invalidUse" ) ; } else if ( reader . matches ( OUTPUT_ACTION ) ) { err . jspError ( start , "jsp.error.jspoutput.invalidUse" ) ; } else { err . jspError ( start , "jsp.error.badStandardAction" ) ; }


signature:
public class Parser { /** * # ' < ' CustomAction CustomActionBody
 * CustomAction : : = TagPrefix ' : ' CustomActionName
 * TagPrefix : : = Name
 * CustomActionName : : = Name
 * CustomActionBody : : = ( Attributes CustomActionEnd )
 * | < TRANSLATION _ ERROR >
 * Attributes : : = ( S Attribute ) * S ?
 * CustomActionEnd : : = CustomActionTagDependent
 * | CustomActionJSPContent
 * | CustomActionScriptlessContent
 * CustomActionTagDependent : : = TagDependentOptionalBody
 * CustomActionJSPContent : : = OptionalBody
 * CustomActionScriptlessContent : : = ScriptlessOptionalBody */
private boolean parseCustomTag ( Node parent ) throws JasperException { } }

implementation:
if ( reader . peekChar ( ) != '<' ) { return false ; } // Parse ' CustomAction ' production ( tag prefix and custom action name )
reader . nextChar ( ) ; // skip ' < '
String tagName = reader . parseToken ( false ) ; int i = tagName . indexOf ( ':' ) ; if ( i == - 1 ) { reader . reset ( start ) ; return false ; } String prefix = tagName . substring ( 0 , i ) ; String shortTagName = tagName . substring ( i + 1 ) ; // Check if this is a user - defined tag .
String uri = pageInfo . getURI ( prefix ) ; if ( uri == null ) { // If error - on - undeclared - namespace is set to true in
// jsp - property - group , then it is an error
if ( pageInfo . errorOnUndeclaredNamespace ( ) ) { err . jspError ( start , "jsp.error.undeclared.namespace" , prefix ) ; } reader . reset ( start ) ; // Remember the prefix for later error checking
pageInfo . putNonCustomTagPrefix ( prefix , reader . mark ( ) ) ; return false ; } TagLibraryInfo tagLibInfo = pageInfo . getTaglib ( uri ) ; TagInfo tagInfo = tagLibInfo . getTag ( shortTagName ) ; TagFileInfo tagFileInfo = tagLibInfo . getTagFile ( shortTagName ) ; if ( tagInfo == null && tagFileInfo == null ) { err . jspError ( start , "jsp.error.bad_tag" , shortTagName , prefix ) ; } Class tagHandlerClass = null ; if ( tagInfo != null ) { // Must be a classic tag , load it here .
// tag files will be loaded later , in TagFileProcessor
String handlerClassName = tagInfo . getTagClassName ( ) ; try { tagHandlerClass = ctxt . getClassLoader ( ) . loadClass ( handlerClassName ) ; } catch ( Exception e ) { err . jspError ( start , "jsp.error.loadclass.taghandler" , handlerClassName , tagName ) ; } } // Parse ' CustomActionBody ' production :
// At this point we are committed - if anything fails , we produce
// a translation error .
// Parse ' Attributes ' production :
Attributes attrs = parseAttributes ( ) ; reader . skipSpaces ( ) ; // Parse ' CustomActionEnd ' production :
if ( reader . matches ( "/>" ) ) { if ( tagInfo != null ) { new Node . CustomTag ( tagLibInfo . getRequiredVersion ( ) , tagName , prefix , shortTagName , uri , attrs , start , parent , tagInfo , tagHandlerClass ) ; } else { new Node . CustomTag ( tagLibInfo . getRequiredVersion ( ) , tagName , prefix , shortTagName , uri , attrs , start , parent , tagFileInfo ) ; } return true ; } // Now we parse one of ' CustomActionTagDependent ' ,
// ' CustomActionJSPContent ' , or ' CustomActionScriptlessContent ' .
// depending on body - content in TLD .
// Looking for a body , it still can be empty ; but if there is a
// a tag body , its syntax would be dependent on the type of
// body content declared in the TLD .
String bc ; if ( tagInfo != null ) { bc = tagInfo . getBodyContent ( ) ; } else { bc = tagFileInfo . getTagInfo ( ) . getBodyContent ( ) ; } Node tagNode = null ; if ( tagInfo != null ) { tagNode = new Node . CustomTag ( tagLibInfo . getRequiredVersion ( ) , tagName , prefix , shortTagName , uri , attrs , start , parent , tagInfo , tagHandlerClass ) ; } else { tagNode = new Node . CustomTag ( tagLibInfo . getRequiredVersion ( ) , tagName , prefix , shortTagName , uri , attrs , start , parent , tagFileInfo ) ; } parseOptionalBody ( tagNode , tagName , bc ) ; return true ;


signature:
public class Parser { /** * Parse for a template text string until ' < ' or " $ { " is encountered ,
 * recognizing escape sequences " \ % " , " \ $ " , and \ # . */
private void parseTemplateText ( Node parent ) throws JasperException { } }

implementation:
if ( ! reader . hasMoreInput ( ) ) return ; CharArrayWriter ttext = new CharArrayWriter ( ) ; // Output the first character
int ch = reader . nextChar ( ) ; if ( ch == '\\' ) { reader . pushChar ( ) ; } else { ttext . write ( ch ) ; } while ( reader . hasMoreInput ( ) ) { ch = reader . nextChar ( ) ; if ( ch == '<' ) { reader . pushChar ( ) ; break ; } else if ( ch == '$' || ch == '#' ) { if ( ! reader . hasMoreInput ( ) ) { ttext . write ( ch ) ; break ; } if ( reader . nextChar ( ) == '{' ) { reader . pushChar ( ) ; reader . pushChar ( ) ; break ; } ttext . write ( ch ) ; reader . pushChar ( ) ; continue ; } else if ( ch == '\\' ) { if ( ! reader . hasMoreInput ( ) ) { ttext . write ( '\\' ) ; break ; } char next = ( char ) reader . peekChar ( ) ; // Looking for \ % or \ $
// Note that this behavior can be altered by the attributes
// el - ignored and deferred - syntax - allowed - as - literal and
// similar attributes in a page directive . However , since
// the page direcitve may appear later in the same page , the
// ' \ ' will be regenerated in Generator . java .
if ( next == '%' || next == '$' || next == '#' ) { ch = reader . nextChar ( ) ; } } ttext . write ( ch ) ; } new Node . TemplateText ( ttext . toString ( ) , start , parent ) ;


signature:
public class Parser { /** * XMLTemplateText : : = ( S ? ' / > ' )
 * ( ( Char * - ( Char * ( ' < ' | ' $ { ' ) ) )
 * ( ' $ { ' ELExpressionBody ) ?
 * CDSect ?
 * ) * ETag
 * | < TRANSLATION _ ERROR > */
private void parseXMLTemplateText ( Node parent ) throws JasperException { } }

implementation:
reader . skipSpaces ( ) ; if ( ! reader . matches ( "/>" ) ) { if ( ! reader . matches ( ">" ) ) { err . jspError ( start , "jsp.error.unterminated" , "<jsp:text>" ) ; } CharArrayWriter ttext = new CharArrayWriter ( ) ; while ( reader . hasMoreInput ( ) ) { int ch = reader . nextChar ( ) ; if ( ch == '<' ) { // Check for < ! [ CDATA [
if ( ! reader . matches ( "![CDATA[" ) ) { break ; } start = reader . mark ( ) ; Mark stop = reader . skipUntil ( "]]>" ) ; if ( stop == null ) { err . jspError ( start , "jsp.error.unterminated" , "CDATA" ) ; } String text = reader . getText ( start , stop ) ; ttext . write ( text , 0 , text . length ( ) ) ; } else if ( ch == '\\' ) { if ( ! reader . hasMoreInput ( ) ) { ttext . write ( '\\' ) ; break ; } ch = reader . nextChar ( ) ; if ( ch != '$' && ch != '#' ) { ttext . write ( '\\' ) ; } ttext . write ( ch ) ; } else if ( ch == '$' || ch == '#' ) { if ( ! reader . hasMoreInput ( ) ) { ttext . write ( ch ) ; break ; } if ( reader . nextChar ( ) != '{' ) { ttext . write ( ch ) ; reader . pushChar ( ) ; continue ; } // Create a template text node
new Node . TemplateText ( ttext . toString ( ) , start , parent ) ; // Mark and parse the EL expression and create its node :
start = reader . mark ( ) ; parseELExpression ( parent , ( ch == '$' ) ? "${" : "#{" ) ; start = reader . mark ( ) ; ttext = new CharArrayWriter ( ) ; } else { ttext . write ( ch ) ; } } new Node . TemplateText ( ttext . toString ( ) , start , parent ) ; if ( ! reader . hasMoreInput ( ) ) { err . jspError ( start , "jsp.error.unterminated" , "<jsp:text>" ) ; } else if ( ! reader . matchesETagWithoutLessThan ( "jsp:text" ) ) { err . jspError ( start , "jsp.error.jsptext.badcontent" ) ; } }


signature:
public class Parser { /** * AllBody : : = ( ' < % - - ' JSPCommentBody )
 * | ( ' < % @ ' DirectiveBody )
 * | ( ' < jsp : directive . ' XMLDirectiveBody )
 * | ( ' < % ! ' DeclarationBody )
 * | ( ' < jsp : declaration ' XMLDeclarationBody )
 * | ( ' < % = ' ExpressionBody )
 * | ( ' < jsp : expression ' XMLExpressionBody )
 * | ( ' $ { ' ELExpressionBody )
 * | ( ' < % ' ScriptletBody )
 * | ( ' < jsp : scriptlet ' XMLScriptletBody )
 * | ( ' < jsp : text ' XMLTemplateText )
 * | ( ' < jsp : ' StandardAction )
 * | ( ' < ' CustomAction
 * CustomActionBody )
 * | TemplateText */
private void parseElements ( Node parent ) throws JasperException { } }

implementation:
if ( scriptlessCount > 0 ) { // vc : ScriptlessBody
// We must follow the ScriptlessBody production if one of
// our parents is ScriptlessBody .
parseElementsScriptless ( parent ) ; return ; } start = reader . mark ( ) ; if ( reader . matches ( "<%--" ) ) { parseComment ( parent ) ; } else if ( reader . matches ( "<%@" ) ) { parseDirective ( parent ) ; } else if ( reader . matches ( "<jsp:directive." ) ) { parseXMLDirective ( parent ) ; } else if ( reader . matches ( "<%!" ) ) { parseDeclaration ( parent ) ; } else if ( reader . matches ( "<jsp:declaration" ) ) { parseXMLDeclaration ( parent ) ; } else if ( reader . matches ( "<%=" ) ) { parseExpression ( parent ) ; } else if ( reader . matches ( "<jsp:expression" ) ) { parseXMLExpression ( parent ) ; } else if ( reader . matches ( "<%" ) ) { parseScriptlet ( parent ) ; } else if ( reader . matches ( "<jsp:scriptlet" ) ) { parseXMLScriptlet ( parent ) ; } else if ( reader . matches ( "<jsp:text" ) ) { parseXMLTemplateText ( parent ) ; } else if ( reader . matches ( "${" ) ) { parseELExpression ( parent , "${" ) ; } else if ( reader . matches ( "#{" ) ) { parseELExpression ( parent , "#{" ) ; } else if ( reader . matches ( "<jsp:" ) ) { parseStandardAction ( parent ) ; } else if ( ! parseCustomTag ( parent ) ) { checkUnbalancedEndTag ( ) ; parseTemplateText ( parent ) ; }


signature:
public class Parser { /** * ScriptlessBody : : = ( ' < % - - ' JSPCommentBody )
 * | ( ' < % @ ' DirectiveBody )
 * | ( ' < jsp : directive . ' XMLDirectiveBody )
 * | ( ' < % ! ' < TRANSLATION _ ERROR > )
 * | ( ' < jsp : declaration ' < TRANSLATION _ ERROR > )
 * | ( ' < % = ' < TRANSLATION _ ERROR > )
 * | ( ' < jsp : expression ' < TRANSLATION _ ERROR > )
 * | ( ' < % ' < TRANSLATION _ ERROR > )
 * | ( ' < jsp : scriptlet ' < TRANSLATION _ ERROR > )
 * | ( ' < jsp : text ' XMLTemplateText )
 * | ( ' $ { ' ELExpressionBody )
 * | ( ' < jsp : ' StandardAction )
 * | ( ' < ' CustomAction
 * CustomActionBody )
 * | TemplateText */
private void parseElementsScriptless ( Node parent ) throws JasperException { } }

implementation:
// Keep track of how many scriptless nodes we ' ve encountered
// so we know whether our child nodes are forced scriptless
scriptlessCount ++ ; start = reader . mark ( ) ; if ( reader . matches ( "<%--" ) ) { parseComment ( parent ) ; } else if ( reader . matches ( "<%@" ) ) { parseDirective ( parent ) ; } else if ( reader . matches ( "<jsp:directive." ) ) { parseXMLDirective ( parent ) ; } else if ( reader . matches ( "<%!" ) ) { err . jspError ( reader . mark ( ) , "jsp.error.no.scriptlets" ) ; } else if ( reader . matches ( "<jsp:declaration" ) ) { err . jspError ( reader . mark ( ) , "jsp.error.no.scriptlets" ) ; } else if ( reader . matches ( "<%=" ) ) { err . jspError ( reader . mark ( ) , "jsp.error.no.scriptlets" ) ; } else if ( reader . matches ( "<jsp:expression" ) ) { err . jspError ( reader . mark ( ) , "jsp.error.no.scriptlets" ) ; } else if ( reader . matches ( "<%" ) ) { err . jspError ( reader . mark ( ) , "jsp.error.no.scriptlets" ) ; } else if ( reader . matches ( "<jsp:scriptlet" ) ) { err . jspError ( reader . mark ( ) , "jsp.error.no.scriptlets" ) ; } else if ( reader . matches ( "<jsp:text" ) ) { parseXMLTemplateText ( parent ) ; } else if ( reader . matches ( "${" ) ) { parseELExpression ( parent , "${" ) ; } else if ( reader . matches ( "#{" ) ) { parseELExpression ( parent , "#{" ) ; } else if ( reader . matches ( "<jsp:" ) ) { parseStandardAction ( parent ) ; } else if ( ! parseCustomTag ( parent ) ) { checkUnbalancedEndTag ( ) ; parseTemplateText ( parent ) ; } scriptlessCount -- ;


signature:
public class Parser { /** * TemplateTextBody : : = ( ' < % - - ' JSPCommentBody )
 * | ( ' < % @ ' DirectiveBody )
 * | ( ' < jsp : directive . ' XMLDirectiveBody )
 * | ( ' < % ! ' < TRANSLATION _ ERROR > )
 * | ( ' < jsp : declaration ' < TRANSLATION _ ERROR > )
 * | ( ' < % = ' < TRANSLATION _ ERROR > )
 * | ( ' < jsp : expression ' < TRANSLATION _ ERROR > )
 * | ( ' < % ' < TRANSLATION _ ERROR > )
 * | ( ' < jsp : scriptlet ' < TRANSLATION _ ERROR > )
 * | ( ' < jsp : text ' < TRANSLATION _ ERROR > )
 * | ( ' $ { ' < TRANSLATION _ ERROR > )
 * | ( ' < jsp : ' < TRANSLATION _ ERROR > )
 * | TemplateText */
private void parseElementsTemplateText ( Node parent ) throws JasperException { } }

implementation: start = reader . mark ( ) ; if ( reader . matches ( "<%--" ) ) { parseComment ( parent ) ; } else if ( reader . matches ( "<%@" ) ) { parseDirective ( parent ) ; } else if ( reader . matches ( "<jsp:directive." ) ) { parseXMLDirective ( parent ) ; } else if ( reader . matches ( "<%!" ) ) { err . jspError ( reader . mark ( ) , "jsp.error.not.in.template" , "Declarations" ) ; } else if ( reader . matches ( "<jsp:declaration" ) ) { err . jspError ( reader . mark ( ) , "jsp.error.not.in.template" , "Declarations" ) ; } else if ( reader . matches ( "<%=" ) ) { err . jspError ( reader . mark ( ) , "jsp.error.not.in.template" , "Expressions" ) ; } else if ( reader . matches ( "<jsp:expression" ) ) { err . jspError ( reader . mark ( ) , "jsp.error.not.in.template" , "Expressions" ) ; } else if ( reader . matches ( "<%" ) ) { err . jspError ( reader . mark ( ) , "jsp.error.not.in.template" , "Scriptlets" ) ; } else if ( reader . matches ( "<jsp:scriptlet" ) ) { err . jspError ( reader . mark ( ) , "jsp.error.not.in.template" , "Scriptlets" ) ; } else if ( reader . matches ( "<jsp:text" ) ) { err . jspError ( reader . mark ( ) , "jsp.error.not.in.template" , "<jsp:text" ) ; } else if ( reader . matches ( "${" ) || reader . matches ( "#{" ) ) { err . jspError ( reader . mark ( ) , "jsp.error.not.in.template" , "Expression language" ) ; } else if ( reader . matches ( "<jsp:" ) ) { err . jspError ( reader . mark ( ) , "jsp.error.not.in.template" , "Standard actions" ) ; } else if ( parseCustomTag ( parent ) ) { err . jspError ( reader . mark ( ) , "jsp.error.not.in.template" , "Custom actions" ) ; } else { checkUnbalancedEndTag ( ) ; parseTemplateText ( parent ) ; }


signature:
public class Parser { /** * Flag as error if an unbalanced end tag appears by itself . */
private void checkUnbalancedEndTag ( ) throws JasperException { } }

implementation:
if ( ! reader . matches ( "</" ) ) { return ; } // Check for unbalanced standard actions
if ( reader . matches ( "jsp:" ) ) { err . jspError ( start , "jsp.error.unbalanced.endtag" , "jsp:" ) ; } // Check for unbalanced custom actions
String tagName = reader . parseToken ( false ) ; int i = tagName . indexOf ( ':' ) ; if ( i == - 1 || pageInfo . getURI ( tagName . substring ( 0 , i ) ) == null ) { reader . reset ( start ) ; return ; } err . jspError ( start , "jsp.error.unbalanced.endtag" , tagName ) ;


signature:
public class Parser { /** * TagDependentBody : = */
private void parseTagDependentBody ( Node parent , String tag ) throws JasperException { } }

implementation: Mark bodyStart = reader . mark ( ) ; Mark bodyEnd = reader . skipUntilETag ( tag ) ; if ( bodyEnd == null ) { err . jspError ( start , "jsp.error.unterminated" , "<" + tag ) ; } new Node . TemplateText ( reader . getText ( bodyStart , bodyEnd ) , bodyStart , parent ) ;


signature:
public class Parser { /** * Parses jsp : body action . */
private void parseJspBody ( Node parent , String bodyType ) throws JasperException { } }

implementation: Mark start = reader . mark ( ) ; Node bodyNode = new Node . JspBody ( start , parent ) ; reader . skipSpaces ( ) ; if ( ! reader . matches ( "/>" ) ) { if ( ! reader . matches ( ">" ) ) { err . jspError ( start , "jsp.error.unterminated" , "<jsp:body" ) ; } parseBody ( bodyNode , "jsp:body" , bodyType ) ; }


signature:
public class Parser { /** * Parse the body as JSP content .
 * @ param tag The name of the tag whose end tag would terminate the body
 * @ param bodyType One of the TagInfo body types */
private void parseBody ( Node parent , String tag , String bodyType ) throws JasperException { } }

implementation:
if ( bodyType . equalsIgnoreCase ( TagInfo . BODY_CONTENT_TAG_DEPENDENT ) ) { parseTagDependentBody ( parent , tag ) ; } else if ( bodyType . equalsIgnoreCase ( TagInfo . BODY_CONTENT_EMPTY ) ) { if ( ! reader . matchesETag ( tag ) ) { err . jspError ( start , "jasper.error.emptybodycontent.nonempty" , tag ) ; } } else if ( bodyType == JAVAX_BODY_CONTENT_PLUGIN ) { // ( note the = = since we won ' t recognize JAVAX _ *
// from outside this module ) .
parsePluginTags ( parent ) ; if ( ! reader . matchesETag ( tag ) ) { err . jspError ( reader . mark ( ) , "jsp.error.unterminated" , "<" + tag ) ; } } else if ( bodyType . equalsIgnoreCase ( TagInfo . BODY_CONTENT_JSP ) || bodyType . equalsIgnoreCase ( TagInfo . BODY_CONTENT_SCRIPTLESS ) || ( bodyType == JAVAX_BODY_CONTENT_PARAM ) || ( bodyType == JAVAX_BODY_CONTENT_TEMPLATE_TEXT ) ) { while ( reader . hasMoreInput ( ) ) { if ( reader . matchesETag ( tag ) ) { return ; } // Check for nested jsp : body or jsp : attribute
if ( tag . equals ( "jsp:body" ) || tag . equals ( "jsp:attribute" ) ) { if ( reader . matches ( "<jsp:attribute" ) ) { err . jspError ( reader . mark ( ) , "jsp.error.nested.jspattribute" ) ; } else if ( reader . matches ( "<jsp:body" ) ) { err . jspError ( reader . mark ( ) , "jsp.error.nested.jspbody" ) ; } } if ( bodyType . equalsIgnoreCase ( TagInfo . BODY_CONTENT_JSP ) ) { parseElements ( parent ) ; } else if ( bodyType . equalsIgnoreCase ( TagInfo . BODY_CONTENT_SCRIPTLESS ) ) { parseElementsScriptless ( parent ) ; } else if ( bodyType == JAVAX_BODY_CONTENT_PARAM ) { // ( note the = = since we won ' t recognize JAVAX _ *
// from outside this module ) .
reader . skipSpaces ( ) ; parseParam ( parent ) ; } else if ( bodyType == JAVAX_BODY_CONTENT_TEMPLATE_TEXT ) { parseElementsTemplateText ( parent ) ; } } err . jspError ( start , "jsp.error.unterminated" , "<" + tag ) ; } else { err . jspError ( start , "jsp.error.tld.badbodycontent" , bodyType , tag ) ; }


signature:
public class Parser { /** * Parses named attributes . */
private void parseNamedAttributes ( Node parent ) throws JasperException { } }

implementation: do { Mark start = reader . mark ( ) ; Attributes attrs = parseAttributes ( ) ; if ( attrs == null || attrs . getValue ( "name" ) == null ) { err . jspError ( start , "jsp.error.jspAttribute.missing.name" ) ; } Node . NamedAttribute namedAttributeNode = new Node . NamedAttribute ( attrs , start , parent ) ; reader . skipSpaces ( ) ; if ( ! reader . matches ( "/>" ) ) { if ( ! reader . matches ( ">" ) ) { err . jspError ( start , "jsp.error.unterminated" , "<jsp:attribute" ) ; } if ( namedAttributeNode . isTrim ( ) ) { reader . skipSpaces ( ) ; } parseBody ( namedAttributeNode , "jsp:attribute" , getAttributeBodyType ( parent , attrs . getValue ( "name" ) ) ) ; if ( namedAttributeNode . isTrim ( ) ) { Node . Nodes subElems = namedAttributeNode . getBody ( ) ; if ( subElems != null ) { Node lastNode = subElems . getNode ( subElems . size ( ) - 1 ) ; if ( lastNode instanceof Node . TemplateText ) { ( ( Node . TemplateText ) lastNode ) . rtrim ( ) ; } } } } reader . skipSpaces ( ) ; } while ( reader . matches ( "<jsp:attribute" ) ) ;


signature:
public class Parser { /** * Determine the body type of < jsp : attribute > from the enclosing node */
private String getAttributeBodyType ( Node n , String name ) { } }

implementation: if ( n instanceof Node . CustomTag ) { TagInfo tagInfo = ( ( Node . CustomTag ) n ) . getTagInfo ( ) ; TagAttributeInfo [ ] tldAttrs = tagInfo . getAttributes ( ) ; for ( int i = 0 ; i < tldAttrs . length ; i ++ ) { if ( name . equals ( tldAttrs [ i ] . getName ( ) ) ) { if ( tldAttrs [ i ] . isFragment ( ) ) { return TagInfo . BODY_CONTENT_SCRIPTLESS ; } if ( tldAttrs [ i ] . canBeRequestTime ( ) ) { return TagInfo . BODY_CONTENT_JSP ; } } } if ( tagInfo . hasDynamicAttributes ( ) ) { return TagInfo . BODY_CONTENT_JSP ; } } else if ( n instanceof Node . IncludeAction ) { if ( "page" . equals ( name ) ) { return TagInfo . BODY_CONTENT_JSP ; } } else if ( n instanceof Node . ForwardAction ) { if ( "page" . equals ( name ) ) { return TagInfo . BODY_CONTENT_JSP ; } } else if ( n instanceof Node . SetProperty ) { if ( "value" . equals ( name ) ) { return TagInfo . BODY_CONTENT_JSP ; } } else if ( n instanceof Node . UseBean ) { if ( "beanName" . equals ( name ) ) { return TagInfo . BODY_CONTENT_JSP ; } } else if ( n instanceof Node . PlugIn ) { if ( "width" . equals ( name ) || "height" . equals ( name ) ) { return TagInfo . BODY_CONTENT_JSP ; } } else if ( n instanceof Node . ParamAction ) { if ( "value" . equals ( name ) ) { return TagInfo . BODY_CONTENT_JSP ; } } else if ( n instanceof Node . JspElement ) { return TagInfo . BODY_CONTENT_JSP ; } return JAVAX_BODY_CONTENT_TEMPLATE_TEXT ;


signature:
public class Node { /** * Get the attribute that is non request time expression , either
 * from the attribute of the node , or from a jsp : attrbute */
public String getTextAttribute ( String name ) { } }

implementation: String attr = getAttributeValue ( name ) ; if ( attr != null ) { return attr ; } NamedAttribute namedAttribute = getNamedAttributeNode ( name ) ; if ( namedAttribute == null ) { return null ; } return namedAttribute . getText ( ) ;


signature:
public class Node { /** * Searches all subnodes of this node for jsp : attribute standard
 * actions with the given name , and returns the NamedAttribute node
 * of the matching named attribute , nor null if no such node is found .
 * This should always be called and only be called for nodes that
 * accept dynamic runtime attribute expressions . */
public NamedAttribute getNamedAttributeNode ( String name ) { } }

implementation:
NamedAttribute result = null ; // Look for the attribute in NamedAttribute children
Nodes nodes = getNamedAttributeNodes ( ) ; int numChildNodes = nodes . size ( ) ; for ( int i = 0 ; i < numChildNodes ; i ++ ) { NamedAttribute na = ( NamedAttribute ) nodes . getNode ( i ) ; boolean found = false ; int index = name . indexOf ( ':' ) ; if ( index != - 1 ) { // qualified name
found = na . getName ( ) . equals ( name ) ; } else { found = na . getLocalName ( ) . equals ( name ) ; } if ( found ) { result = na ; break ; } } return result ;


signature:
public class Node { /** * Searches all subnodes of this node for jsp : attribute standard
 * actions , and returns that set of nodes as a Node . Nodes object .
 * @ return Possibly empty Node . Nodes object containing any jsp : attribute
 * subnodes of this Node */
public Node . Nodes getNamedAttributeNodes ( ) { } }

implementation:
if ( namedAttributeNodes != null ) { return namedAttributeNodes ; } Node . Nodes result = new Node . Nodes ( ) ; // Look for the attribute in NamedAttribute children
Nodes nodes = getBody ( ) ; if ( nodes != null ) { int numChildNodes = nodes . size ( ) ; for ( int i = 0 ; i < numChildNodes ; i ++ ) { Node n = nodes . getNode ( i ) ; if ( n instanceof NamedAttribute ) { result . add ( n ) ; } else if ( ! ( n instanceof Comment ) ) { // Nothing can come before jsp : attribute , and only
// jsp : body can come after it .
break ; } } } namedAttributeNodes = result ; return result ;


signature:
public class Node { /** * Adds this Node to the body of the given parent . */
private void addToParent ( Node parent ) { } }

implementation: if ( parent != null ) { this . parent = parent ; Nodes parentBody = parent . getBody ( ) ; if ( parentBody == null ) { parentBody = new Nodes ( ) ; parent . setBody ( parentBody ) ; } parentBody . add ( this ) ; }


signature:
public class ProcessorFactoryTracker { /** * Get a list of matching factories
 * The returned list is a copy of the current state . The list may be
 * modified by the caller , but will not be updated by this tracker when the
 * state changes .
 * @ param contextClasses
 * the provided context classes
 * @ return a list of matching processor factors , never returns { @ code null } */
public List < ProcessorFactoryInformation > getFactoriesFor ( final Class < ? > [ ] contextClasses ) { } }

implementation: requireNonNull ( contextClasses ) ; final List < ProcessorFactoryInformation > result = new ArrayList < > ( ) ; this . tracker . consumeAll ( stream -> stream . filter ( service -> isMatch ( service , contextClasses ) ) . forEach ( result :: add ) ) ; return result ;


signature:
public class TreeNode { /** * Add an attribute to this node , replacing any existing attribute
 * with the same name .
 * @ param name The attribute name to add
 * @ param value The new attribute value */
public void addAttribute ( String name , String value ) { } }

implementation: if ( attributes == null ) attributes = new HashMap < String , String > ( ) ; attributes . put ( name , value ) ;


signature:
public class TreeNode { /** * Add a new child node to this node .
 * @ param node The new child node */
public void addChild ( TreeNode node ) { } }

implementation: if ( children == null ) children = new ArrayList < TreeNode > ( ) ; children . add ( node ) ;


signature:
public class TreeNode { /** * Return the value of the specified node attribute if it exists , or
 * < code > null < / code > otherwise .
 * @ param name Name of the requested attribute */
public String findAttribute ( String name ) { } }

implementation: if ( attributes == null ) return ( null ) ; else return ( attributes . get ( name ) ) ;


signature:
public class TreeNode { /** * Return an Iterator of the attribute names of this node . If there are
 * no attributes , an empty Iterator is returned . */
public Iterator < String > findAttributes ( ) { } }

implementation: Set < String > attrs ; if ( attributes == null ) attrs = Collections . emptySet ( ) ; else attrs = attributes . keySet ( ) ; return attrs . iterator ( ) ;


signature:
public class TreeNode { /** * Return the first child node of this node with the specified name ,
 * if there is one ; otherwise , return < code > null < / code > .
 * @ param name Name of the desired child element */
public TreeNode findChild ( String name ) { } }

implementation: if ( children == null ) return ( null ) ; for ( TreeNode item : children ) { if ( name . equals ( item . getName ( ) ) ) return ( item ) ; } return ( null ) ;


signature:
public class TreeNode { /** * Return an Iterator of all children of this node . If there are no
 * children , an empty Iterator is returned . */
public Iterator < TreeNode > findChildren ( ) { } }

implementation: List < TreeNode > nodes ; if ( children == null ) nodes = Collections . emptyList ( ) ; else nodes = children ; return nodes . iterator ( ) ;


signature:
public class TreeNode { /** * Return an Iterator over all children of this node that have the
 * specified name . If there are no such children , an empty Iterator
 * is returned .
 * @ param name Name used to select children */
public Iterator < TreeNode > findChildren ( String name ) { } }

implementation: List < TreeNode > results ; if ( children == null ) results = Collections . emptyList ( ) ; else { results = new ArrayList < TreeNode > ( ) ; for ( TreeNode item : children ) { if ( name . equals ( item . getName ( ) ) ) results . add ( item ) ; } } return results . iterator ( ) ;


signature:
public class MavenCoordinates { /** * Create a new instance without classifier and extension */
public MavenCoordinates toBase ( ) { } }

implementation: if ( this . classifier == null && this . extension == null ) { return this ; } return new MavenCoordinates ( this . groupId , this . artifactId , this . version ) ;


signature:
public class JspContextWrapper { /** * Checks to see if the given variable name is used as an alias , and if so ,
 * returns the variable name for which it is used as an alias .
 * @ param varName The variable name to check
 * @ return The variable name for which varName is used as an alias , or
 * varName if it is not being used as an alias */
private String findAlias ( String varName ) { } }

implementation: if ( aliases == null ) return varName ; String alias = aliases . get ( varName ) ; if ( alias == null ) { return varName ; } return alias ;


signature:
public class SystemLogHandler { /** * Start capturing thread ' s output . */
public static void setThread ( ) { } }

implementation: ByteArrayOutputStream baos = new ByteArrayOutputStream ( ) ; data . set ( baos ) ; streams . set ( new PrintStream ( baos ) ) ;


signature:
public class SystemLogHandler { /** * Stop capturing thread ' s output and return captured data as a String . */
public static String unsetThread ( ) { } }

implementation: ByteArrayOutputStream baos = ( ByteArrayOutputStream ) data . get ( ) ; if ( baos == null ) { return null ; } streams . set ( null ) ; data . set ( null ) ; return baos . toString ( ) ;


signature:
public class SystemLogHandler { /** * Find PrintStream to which the output must be written to . */
protected PrintStream findStream ( ) { } }

implementation: PrintStream ps = ( PrintStream ) streams . get ( ) ; if ( ps == null ) { ps = wrapped ; } return ps ;


signature:
public class RepoBuilder { /** * Write field only when the value is set
 * @ param writer
 * the writer to use
 * @ param fieldName
 * the name of field
 * @ param value
 * the value */
protected static void writeOptional ( final StringWriter writer , final String fieldName , final String value ) { } }

implementation: if ( value != null ) { write ( writer , fieldName , value ) ; }


signature:
public class RepoBuilder { /** * Write a field
 * @ param writer
 * the writer to use
 * @ param fieldName
 * the field name
 * @ param value
 * the value , should not be < code > null < / code > since this would
 * cause the string < q > null < / q > in the file . */
protected static void write ( final StringWriter writer , final String fieldName , final String value ) { } }

implementation: writer . write ( fieldName + ": " + value + "\n" ) ;


signature:
public class XmlHelper { /** * Create a new element and add it as the last child
 * @ param parent
 * the parent of the new element
 * @ param name
 * the name of the element
 * @ return the new element */
public static Element addElement ( final Element parent , final String name ) { } }

implementation: final Element ele = parent . getOwnerDocument ( ) . createElement ( name ) ; parent . appendChild ( ele ) ; return ele ;


signature:
public class XmlHelper { /** * Create a new element and add it as the first child
 * @ param parent
 * the parent to which to add the element
 * @ param name
 * the name of the element
 * @ return the new element */
public static Element addElementFirst ( final Element parent , final String name ) { } }

implementation: final Element ele = parent . getOwnerDocument ( ) . createElement ( name ) ; parent . insertBefore ( ele , null ) ; return ele ;


signature:
public class XmlHelper { /** * Get the text value of the first element with the matching name
 * Assuming you have an XML file :
 * < pre >
 * & lt ; parent & gt ;
 * & nbsp ; & nbsp ; & lt ; foo & gt ; bar & lt ; / foo & gt ;
 * & nbsp ; & nbsp ; & lt ; hello & gt ; world & lt ; / hello & gt ;
 * & lt ; / parent & gt ;
 * < / pre >
 * Calling { @ link # getText ( Element , String ) } with " parent " as element and
 * " hello " as name , it would return " world " .
 * @ param ele
 * the element to check
 * @ param name
 * the name of the child element
 * @ return the text value of the element */
public static String getText ( final Element ele , final String name ) { } }

implementation: for ( final Node child : iter ( ele . getChildNodes ( ) ) ) { if ( ! ( child instanceof Element ) ) { continue ; } final Element childEle = ( Element ) child ; if ( ! childEle . getNodeName ( ) . equals ( name ) ) { continue ; } return childEle . getTextContent ( ) ; } return null ;


signature:
public class BodyContentImpl { /** * Write a single character . */
public void write ( int c ) throws IOException { } }

implementation: if ( writer != null ) { writer . write ( c ) ; } else { ensureOpen ( ) ; if ( nextChar >= bufferSize ) { reAllocBuff ( 1 ) ; } cb [ nextChar ++ ] = ( char ) c ; }


signature:
public class BodyContentImpl { /** * Write a portion of an array of characters .
 * < p > Ordinarily this method stores characters from the given array into
 * this stream ' s buffer , flushing the buffer to the underlying stream as
 * needed . If the requested length is at least as large as the buffer ,
 * however , then this method will flush the buffer and write the characters
 * directly to the underlying stream . Thus redundant
 * < code > DiscardableBufferedWriter < / code > s will not copy data
 * unnecessarily .
 * @ param cbuf A character array
 * @ param off Offset from which to start reading characters
 * @ param len Number of characters to write */
public void write ( char [ ] cbuf , int off , int len ) throws IOException { } }

implementation: if ( writer != null ) { writer . write ( cbuf , off , len ) ; } else { ensureOpen ( ) ; if ( ( off < 0 ) || ( off > cbuf . length ) || ( len < 0 ) || ( ( off + len ) > cbuf . length ) || ( ( off + len ) < 0 ) ) { throw new IndexOutOfBoundsException ( ) ; } else if ( len == 0 ) { return ; } if ( len >= bufferSize - nextChar ) reAllocBuff ( len ) ; System . arraycopy ( cbuf , off , cb , nextChar , len ) ; nextChar += len ; }


signature:
public class BodyContentImpl { /** * Write a portion of a String .
 * @ param s String to be written
 * @ param off Offset from which to start reading characters
 * @ param len Number of characters to be written */
public void write ( String s , int off , int len ) throws IOException { } }

implementation: if ( writer != null ) { writer . write ( s , off , len ) ; } else { ensureOpen ( ) ; if ( len >= bufferSize - nextChar ) reAllocBuff ( len ) ; s . getChars ( off , off + len , cb , nextChar ) ; nextChar += len ; }


signature:
public class BodyContentImpl { /** * Close the stream , flushing it first . Once a stream has been closed ,
 * further write ( ) or flush ( ) invocations will cause an IOException to be
 * thrown . Closing a previously - closed stream , however , has no effect .
 * @ throws IOException If an I / O error occurs */
public void close ( ) throws IOException { } }

implementation: if ( writer != null ) { writer . close ( ) ; } else { cb = null ; closed = true ; }


signature:
public class BodyContentImpl { /** * Write the contents of this BodyJspWriter into a Writer .
 * Subclasses are likely to do interesting things with the
 * implementation so some things are extra efficient .
 * @ param out The writer into which to place the contents of this body
 * evaluation */
public void writeOut ( Writer out ) throws IOException { } }

implementation:
if ( writer == null ) { out . write ( cb , 0 , nextChar ) ; // Flush not called as the writer passed could be a BodyContent and
// it doesn ' t allow to flush .
}


signature:
public class BodyContentImpl { /** * Sets the writer to which all output is written . */
void setWriter ( Writer writer ) { } }

implementation:
this . writer = writer ; if ( writer != null ) { // According to the spec , the JspWriter returned by
// JspContext . pushBody ( java . io . Writer writer ) must behave as
// though it were unbuffered . This means that its getBufferSize ( )
// must always return 0 . The implementation of
// JspWriter . getBufferSize ( ) returns the value of JspWriter ' s
// ' bufferSize ' field , which is inherited by this class .
// Therefore , we simply save the current ' bufferSize ' ( so we can
// later restore it should this BodyContentImpl ever be reused by
// a call to PageContext . pushBody ( ) ) before setting it to 0.
if ( bufferSize != 0 ) { bufferSizeSave = bufferSize ; bufferSize = 0 ; } } else { bufferSize = bufferSizeSave ; clearBody ( ) ; }


signature:
public class BodyContentImpl { /** * Reallocates buffer since the spec requires it to be unbounded . */
private void reAllocBuff ( int len ) { } }

implementation: if ( bufferSize + len <= cb . length ) { bufferSize = cb . length ; return ; } if ( len < cb . length ) { len = cb . length ; } bufferSize = cb . length + len ; char [ ] tmp = new char [ bufferSize ] ; System . arraycopy ( cb , 0 , tmp , 0 , cb . length ) ; cb = tmp ; tmp = null ;


signature:
public class ELFunctionMapper { /** * Creates the functions mappers for all EL expressions in the JSP page .
 * @ param compiler Current compiler , mainly for accessing error dispatcher .
 * @ param page The current compilation unit . */
public static void map ( Compiler compiler , Node . Nodes page ) throws JasperException { } }

implementation:
ELFunctionMapper map = new ELFunctionMapper ( ) ; map . ds = new StringBuilder ( ) ; map . ss = new StringBuilder ( ) ; page . visit ( map . new ELFunctionVisitor ( ) ) ; // Append the declarations to the root node
String ds = map . ds . toString ( ) ; if ( ds . length ( ) > 0 ) { Node root = page . getRoot ( ) ; new Node . Declaration ( map . ss . toString ( ) , null , root ) ; new Node . Declaration ( "static {\n" + ds + "}\n" , null , root ) ; }


signature:
public class StorageManager { /** * Traverse up from the provided parent and find the first which uses the
 * same key
 * @ param parent
 * the first parent candidate
 * @ param key
 * the key to look for
 * @ return the first parent ( which may be the input parameter ) , which uses
 * the same key */
private static State getSameParent ( final State parent , final MetaKey key ) { } }

implementation: State current = parent ; while ( current != null ) { if ( current . key . equals ( key ) ) { return current ; } current = current . parent ; } return null ;


signature:
public class StorageManager { /** * Register a new model with the storage manager
 * @ param lockPriority
 * the priority of the lock , lower numbers must be locked before
 * higher numbers
 * @ param key
 * the model key
 * @ param storageProvider
 * the storage provider
 * @ return a handle for unregistering the model
 * @ throws ModelInitializationException
 * if the { @ link StorageModelProvider # start ( StorageContext ) }
 * method fails */
public StorageRegistration registerModel ( final long lockPriority , final MetaKey key , final StorageModelProvider < ? , ? > storageProvider ) throws ModelInitializationException { } }

implementation: this . modelLock . writeLock ( ) . lock ( ) ; try { testClosed ( ) ; if ( this . modelKeyMap . containsKey ( key ) ) { throw new IllegalArgumentException ( String . format ( "A provider for '%s' is already registered" , key ) ) ; } try { storageProvider . start ( this . context ) ; } catch ( final Exception e ) { throw new ModelInitializationException ( "Failed to start model provider: " + key , e ) ; } final long id = this . counter ++ ; final Entry entry = new Entry ( id , lockPriority , key , storageProvider ) ; this . modelIdMap . put ( id , entry ) ; this . modelKeyMap . put ( key , entry ) ; return new StorageRegistration ( ) { @ Override public void unregister ( ) { unregisterModel ( id ) ; } } ; } finally { this . modelLock . writeLock ( ) . unlock ( ) ; }


signature:
public class CacheStore { /** * Stream directly from the storage */
public boolean stream ( final MetaKey key , final IOConsumer < InputStream > consumer ) throws IOException { } }

implementation: return streamFrom ( this . dataPath , key , consumer ) ;


signature:
public class JobController { /** * Monitor the job , only produces an HTML fragment of the current job state
 * @ param id
 * the job id
 * @ return the view */
@ RequestMapping ( "/{id}/monitor" ) public ModelAndView monitor ( @ PathVariable ( "id" ) final String id ) { } }

implementation: final JobHandle job = this . manager . getJob ( id ) ; if ( job != null ) { logger . debug ( "Job: {} - {}" , job . getId ( ) , job . getState ( ) ) ; } else { logger . debug ( "No job: {}" , id ) ; } final Map < String , Object > model = new HashMap < > ( 1 ) ; model . put ( "job" , job ) ; return new ModelAndView ( "monitor" , model ) ;


signature:
public class DebianPackageWriter { /** * clean up the path so that is looks like " . / usr / local / file " */
private String cleanupPath ( String fileName ) { } }

implementation:
if ( fileName == null ) { return null ; } fileName = fileName . replace ( "\\" , "/" ) ; // just in case we get windows paths
fileName = fileName . replace ( "/+" , "/" ) ; if ( fileName . startsWith ( "./" ) ) { return fileName ; } if ( fileName . startsWith ( "/" ) ) { return "." + fileName ; } return "./" + fileName ;


signature:
public class AbstractChannelServiceServlet { /** * Authenticate the request is authenticated against the deploy keys
 * If the request could not be authenticated a basic authentication request
 * is sent back and the { @ link HttpServletResponse } will be committed .
 * @ param by
 * the channel locator
 * @ param request
 * the request
 * @ param response
 * the response
 * @ return < code > false < / code > if the request was not authenticated and the
 * response got committed , < code > true < / code > otherwise
 * @ throws IOException
 * in case on a IO error */
protected boolean authenticate ( final By by , final HttpServletRequest request , final HttpServletResponse response ) throws IOException { } }

implementation: if ( isAuthenticated ( by , request ) ) { return true ; } BasicAuthentication . request ( response , "channel" , "Please authenticate" ) ; return false ;


signature:
public class AbstractChannelServiceServlet { /** * Simply test if the request is authenticated against the channels deploy
 * keys
 * @ param by
 * the channel locator
 * @ param request
 * the request
 * @ return < code > true < / code > if the request could be authenticated against
 * the channels deploy keys , < code > false < / code > otherwise */
protected boolean isAuthenticated ( final By by , final HttpServletRequest request ) { } }

implementation:
final String [ ] authToks = parseAuthorization ( request ) ; if ( authToks == null ) { return false ; } // we don ' t enforce the " deploy " user name anymore
final String deployKey = authToks [ 1 ] ; logger . debug ( "Deploy key: '{}'" , deployKey ) ; final ChannelService service = getService ( request ) ; if ( service == null ) { logger . info ( "Called 'isAuthenticated' without service" ) ; return false ; } return service . getChannelDeployKeyStrings ( by ) . orElse ( Collections . emptySet ( ) ) . contains ( deployKey ) ;