Input: Gets the location of the TLD associated with the given taglib uri . [CODESPLIT] @ SuppressWarnings ( "unchecked" ) public String [ ] getLocation ( String uri ) throws JasperException { if ( mappings == null ) { // Recovering the map done in onStart. mappings = ( HashMap < String , String [ ] > ) ctxt . getAttribute ( Constants . JSP_TLD_URI_TO_LOCATION_MAP ) ; } if ( mappings != null && mappings . get ( uri ) != null ) { // if the uri is in, return that, and dont bother to do full scan return mappings . get ( uri ) ; } if ( ! doneScanning ) { scanListeners = false ; scanTlds ( ) ; doneScanning = true ; } if ( mappings == null ) { // Should never happend return null ; } return mappings . get ( uri ) ; }


Input: Scan the all the tlds accessible in the web app . For performance reasons this is done in two stages . At servlet initialization time we only scan the jar files for listeners . The container passes a list of system jar files that are known to contain tlds with listeners . The rest of the jar files will be scanned when a JSP page with a tld referenced is compiled . [CODESPLIT] private void scanTlds ( ) throws JasperException { mappings = new HashMap < String , String [ ] > ( ) ; // Make a local copy of the system jar cache  jarTldCacheLocal . putAll ( jarTldCache ) ; try { processWebDotXml ( ) ; scanJars ( ) ; processTldsInFileSystem ( "/WEB-INF/" ) ; } catch ( JasperException ex ) { throw ex ; } catch ( Exception ex ) { throw new JasperException ( Localizer . getMessage ( "jsp.error.internal.tldinit" ) , ex ) ; } }


Input: / * Populates taglib map described in web . xml . [CODESPLIT] private void processWebDotXml ( ) throws Exception { // Skip if we are only looking for listeners if ( scanListeners ) { return ; } JspConfigDescriptor jspConfig = ctxt . getJspConfigDescriptor ( ) ; if ( jspConfig == null ) { return ; } for ( TaglibDescriptor taglib : jspConfig . getTaglibs ( ) ) { if ( taglib == null ) { continue ; } String tagUri = taglib . getTaglibURI ( ) ; String tagLoc = taglib . getTaglibLocation ( ) ; if ( tagUri == null || tagLoc == null ) { continue ; } // Ignore system tlds in web.xml, for backward compatibility if ( systemUris . contains ( tagUri ) || ( ! useMyFaces && systemUrisJsf . contains ( tagUri ) ) ) { continue ; } // Save this location if appropriate if ( uriType ( tagLoc ) == NOROOT_REL_URI ) tagLoc = "/WEB-INF/" + tagLoc ; String tagLoc2 = null ; if ( tagLoc . endsWith ( JAR_FILE_SUFFIX ) ) { tagLoc = ctxt . getResource ( tagLoc ) . toString ( ) ; tagLoc2 = "META-INF/taglib.tld" ; } if ( log . isLoggable ( Level . FINE ) ) { log . fine ( "Add tld map from web.xml: " + tagUri + "=>" + tagLoc + "," + tagLoc2 ) ; } mappings . put ( tagUri , new String [ ] { tagLoc , tagLoc2 } ) ; } }


Input: 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 . [CODESPLIT] private void scanJar ( JarURLConnection conn , List < String > tldNames , boolean isLocal ) throws JasperException { 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 ) ; } }


Input: / * Searches the filesystem under / WEB - INF for any TLD files and scans them for <uri > and <listener > elements . [CODESPLIT] private void processTldsInFileSystem ( String startPath ) throws JasperException { 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 ) ; } } }


Input: Scan the given TLD for uri and listeners elements . [CODESPLIT] private TldInfo scanTld ( String resourcePath , String entryName , InputStream stream ) throws JasperException { 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 } } } }


Input: / * Scans all JARs accessible to the webapp s classloader and its parent classloaders for TLDs . [CODESPLIT] private void scanJars ( ) throws Exception { 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 ) ; } } }


Input: / * Add the jars in the manifest Class - Path to the list jars [CODESPLIT] private boolean addManifestClassPath ( List < String > scannedJars , List < String > newJars , JarURLConnection jconn ) { 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 ; }


Input: Add a new JspServletWrapper . [CODESPLIT] public void addWrapper ( String jspUri , JspServletWrapper jsw ) { jsps . remove ( jspUri ) ; jsps . put ( jspUri , jsw ) ; }


Input: Get the parent class loader . [CODESPLIT] public ClassLoader getParentClassLoader ( ) { ClassLoader parentClassLoader = Thread . currentThread ( ) . getContextClassLoader ( ) ; if ( parentClassLoader == null ) { parentClassLoader = this . getClass ( ) . getClassLoader ( ) ; } return parentClassLoader ; }


Input: Save the bytecode for the class in a map . The current time is noted . [CODESPLIT] public void setBytecode ( String name , byte [ ] bytecode ) { if ( bytecode == null ) { bytecodes . remove ( name ) ; bytecodeBirthTimes . remove ( name ) ; return ; } bytecodes . put ( name , bytecode ) ; bytecodeBirthTimes . put ( name , Long . valueOf ( System . currentTimeMillis ( ) ) ) ; }


Input: Retrieve the time the bytecode for a class was created [CODESPLIT] public long getBytecodeBirthTime ( String name ) { Long time = bytecodeBirthTimes . get ( name ) ; return ( time != null ? time . longValue ( ) : 0 ) ; }


Input: Save the bytecode for a class to disk . [CODESPLIT] public void saveBytecode ( String className , String classFileName ) { 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 ) ; } } }


Input: Method used by background thread to check the JSP dependencies registered with this class for JSP s . [CODESPLIT] private void checkCompile ( ) { 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 ) ; } } } }


Input:
Method used to initialize classpath for compiles . [CODESPLIT] private void initClassPath ( ) { /* 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 }


Input: Method used to initialize SecurityManager data . [CODESPLIT] private void initSecurity ( ) { // 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 ) ; } } }


Input: Start the background thread that will periodically check for changes to compile time included files in a JSP . [CODESPLIT] protected void threadStart ( ) { // 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 ( ) ; }


Input: Stop the background thread that is periodically checking for changes to compile time included files in a JSP . [CODESPLIT] protected void threadStop ( ) { if ( thread == null ) { return ; } threadDone = true ; thread . interrupt ( ) ; try { thread . join ( ) ; } catch ( InterruptedException e ) { ; } thread = null ; }


Input: The background thread that checks for changes to files included by a JSP and flags that a recompile is required . [CODESPLIT] public void run ( ) { // 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 ) ; } } }


Input: Find by the locator <p > This method does not acquire the read lock this has to be done by the caller < / p > [CODESPLIT] protected Optional < ChannelInstance > find ( final By by ) { 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 ( ) ) ) ; } }


Input: Find a channel by name [CODESPLIT] private Optional < ChannelInstance > findByName ( final String name ) { if ( name == null ) { return empty ( ) ; } final String id = this . manager . accessCall ( KEY_STORAGE , ChannelServiceAccess . class , channels -> { return channels . mapToId ( name ) ; } ) ; return findById ( id ) ; }


Input: Find a channel [CODESPLIT] private ChannelInstance findChannel ( final By by ) { final Optional < ChannelInstance > channel ; try ( Locked l = lock ( this . readLock ) ) { channel = find ( by ) ; } if ( ! channel . isPresent ( ) ) { throw new ChannelNotFoundException ( by . toString ( ) ) ; } return channel . get ( ) ; }


Input: Update the channel to deploy group cache map [CODESPLIT] private void updateDeployGroupCache ( final ChannelServiceAccess model ) { // 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 ) ; } }


Input: methods of DeployAuthService [CODESPLIT] @ Override public List < DeployGroup > listGroups ( final int position , final int count ) { return this . manager . accessCall ( KEY_STORAGE , ChannelServiceAccess . class , model -> { return split ( model . getDeployGroups ( ) , position , count ) ; } ) ; }


Input: statistics [CODESPLIT] @ Override public ChannelStatistics getStatistics ( ) { 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 ; }


Input: Copy the remaining content of one stream to the other [CODESPLIT] public static long copy ( final InputStream in , final OutputStream out ) throws IOException { 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 ; }


Input: Copy the remaining content of one reader to the { @link Appendable } ( or { @link Writer } [CODESPLIT] public static long copy ( final Readable readable , final Appendable appendable ) throws IOException { 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 ; }


Input: The main entry for Parser [CODESPLIT] 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 { 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 ; }


Input: Attributes :: = ( S Attribute ) * S? [CODESPLIT] Attributes parseAttributes ( ) throws JasperException { AttributesImpl attrs = new AttributesImpl ( ) ; reader . skipSpaces ( ) ; while ( parseAttribute ( attrs ) ) reader . skipSpaces ( ) ; return attrs ; }


Input: Parse Attributes for a reader provided for external use [CODESPLIT] public static Attributes parseAttributes ( ParserController pc , JspReader reader ) throws JasperException { Parser tmpParser = new Parser ( pc , reader , false , false , null , false ) ; return tmpParser . parseAttributes ( ) ; }


Input: 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 . [CODESPLIT] private boolean parseAttribute ( AttributesImpl attrs ) throws JasperException { // 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 ; }


Input: Name :: = ( Letter | _ | : ) ( Letter | Digit | . | _ | - | : ) * [CODESPLIT] private String parseName ( ) throws JasperException { 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 ; }


Input: AttributeValueDouble :: = ( QuotedChar - ) * ( | <TRANSLATION_ERROR > ) RTAttributeValueDouble :: = (( QuotedChar - ) * - (( QuotedChar - ) % > ) ( % > | TRANSLATION_ERROR ) [CODESPLIT] private String parseAttributeValue ( String watch ) throws JasperException { 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 + "%>" ; }


Input: may be send to EL processor . [CODESPLIT] private String parseQuoted ( String tx ) { 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 ) == ' ' && tx . charAt ( i + 2 ) == ' ' && tx . charAt ( i + 3 ) == ' ' && tx . charAt ( i + 4 ) == ' ' && tx . charAt ( i + 5 ) == ' ' ) { buf . append ( ' ' ) ; i += 6 ; } else if ( i + 5 < size && tx . charAt ( i + 1 ) == ' ' && tx . charAt ( i + 2 ) == ' ' && tx . charAt ( i + 3 ) == ' ' && tx . charAt ( i + 4 ) == ' ' && 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 ( ) ; }


Input: / * Invokes parserController to parse the included page [CODESPLIT] private void processIncludeDirective ( String file , Node parent ) throws JasperException { 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 ) ; } }


Input:
/ * Parses a page directive with the following syntax : PageDirective :: = ( S Attribute ) * [CODESPLIT] private void parsePageDirective ( Node parent ) throws JasperException { 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 ) ) ; } } }


Input: / * Parses an include directive with the following syntax : IncludeDirective :: = ( S Attribute ) * [CODESPLIT] private void parseIncludeDirective ( Node parent ) throws JasperException { Attributes attrs = parseAttributes ( ) ; // Included file expanded here Node includeNode = new Node . IncludeDirective ( attrs , start , parent ) ; processIncludeDirective ( attrs . getValue ( "file" ) , includeNode ) ; }


Input: Add a list of files . This is used for implementing include - prelude and include - coda of jsp - config element in web . xml [CODESPLIT] private void addInclude ( Node parent , List files ) throws JasperException { 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 ) ; } } }


Input:
/ * Parses a taglib directive with the following syntax : Directive :: = ( S Attribute ) * [CODESPLIT] private void parseTaglibDirective ( Node parent ) throws JasperException { 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 ) ; }


Input: / * Parses a directive with the following syntax : Directive :: = S? ( page PageDirective | include IncludeDirective | taglib TagLibDirective ) S? % > [CODESPLIT] private void parseDirective ( Node parent ) throws JasperException { 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 ) ; } }


Input: / * Parses a directive with the following syntax : [CODESPLIT] private void parseXMLDirective ( Node parent ) throws JasperException { 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 ) ; } }


Input:
/ * Parses a tag directive with the following syntax : PageDirective :: = ( S Attribute ) * [CODESPLIT] private void parseTagDirective ( Node parent ) throws JasperException { 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 ) ) ; } } }


Input: / * Parses a attribute directive with the following syntax : AttributeDirective :: = ( S Attribute ) * [CODESPLIT] private void parseAttributeDirective ( Node parent ) throws JasperException { Attributes attrs = parseAttributes ( ) ; new Node . AttributeDirective ( attrs , start , parent ) ; }


Input: / * Parses a variable directive with the following syntax : PageDirective :: = ( S Attribute ) * [CODESPLIT] private void parseVariableDirective ( Node parent ) throws JasperException { Attributes attrs = parseAttributes ( ) ; new Node . VariableDirective ( attrs , start , parent ) ; }


Input: / * JSPCommentBody :: = ( Char * - ( Char * -- % > )) -- % > [CODESPLIT] private void parseComment ( Node parent ) throws JasperException { 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 ) ; }


Input: / * DeclarationBody :: = ( Char * - ( char * % > )) % > [CODESPLIT] private void parseDeclaration ( Node parent ) throws JasperException { 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 ) ; }


Input: / * XMLDeclarationBody :: = ( S? / > ) | ( S? > ( Char * - ( char * < )) CDSect? ) * ETag | <TRANSLATION_ERROR > CDSect :: = CDStart CData CDEnd CDStart :: = <! [ CDATA [ CData :: = ( Char * - ( Char * ]] > Char * )) CDEnd :: = ]] > [CODESPLIT] private void parseXMLDeclaration ( Node parent ) throws JasperException { 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>" ) ; } } }


Input: / * ExpressionBody :: = ( Char * - ( char * % > )) % > [CODESPLIT] private void parseExpression ( Node parent ) throws JasperException { 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 ) ; }


Input: / * ELExpressionBody ( following $ { or # { to first unquoted } ) // XXX add formal production and confirm implementation against it // once it s decided [CODESPLIT] private void parseELExpression ( Node parent , String typeEL ) throws JasperException { 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 ) ; }


Input: / * ScriptletBody :: = ( Char * - ( char * % > )) % > [CODESPLIT] private void parseScriptlet ( Node parent ) throws JasperException { 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 ) ; }


Input: Param :: = <jsp : param S Attributes S? EmptyBody S? [CODESPLIT] private void parseParam ( Node parent ) throws JasperException { 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 ( ) ; }


Input: / * For Include : StdActionContent :: = Attributes ParamBody [CODESPLIT] private void parseInclude ( Node parent ) throws JasperException { Attributes attrs = parseAttributes ( ) ; reader . skipSpaces ( ) ; Node includeNode = new Node . IncludeAction ( attrs , start , parent ) ; parseOptionalBody ( includeNode , "jsp:include" , JAVAX_BODY_CONTENT_PARAM ) ; }


Input: / * For Forward : StdActionContent :: = Attributes ParamBody [CODESPLIT] private void parseForward ( Node parent ) throws JasperException { Attributes attrs = parseAttributes ( ) ; reader . skipSpaces ( ) ; Node forwardNode = new Node . ForwardAction ( attrs , start , parent ) ; parseOptionalBody ( forwardNode , "jsp:forward" , JAVAX_BODY_CONTENT_PARAM ) ; }


Input: / * For GetProperty : StdActionContent :: = Attributes EmptyBody [CODESPLIT] private void parseGetProperty ( Node parent ) throws JasperException { Attributes attrs = parseAttributes ( ) ; reader . skipSpaces ( ) ; Node getPropertyNode = new Node . GetProperty ( attrs , start , parent ) ; parseOptionalBody ( getPropertyNode , "jsp:getProperty" , TagInfo . BODY_CONTENT_EMPTY ) ; }


Input: / * For SetProperty : StdActionContent :: = Attributes EmptyBody [CODESPLIT] private void parseSetProperty ( Node parent ) throws JasperException { Attributes attrs = parseAttributes ( ) ; reader . skipSpaces ( ) ; Node setPropertyNode = new Node . SetProperty ( attrs , start , parent ) ; parseOptionalBody ( setPropertyNode , "jsp:setProperty" , TagInfo . BODY_CONTENT_EMPTY ) ; }


Input: / * EmptyBody :: = / > | ( > ETag ) | ( > S? <jsp : attribute NamedAttributes ETag ) [CODESPLIT] private void parseEmptyBody ( Node parent , String tag ) throws JasperException { 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 ) ; } }


Input: / * For UseBean : StdActionContent :: = Attributes OptionalBody [CODESPLIT] private void parseUseBean ( Node parent ) throws JasperException { Attributes attrs = parseAttributes ( ) ; reader . skipSpaces ( ) ; Node useBeanNode = new Node . UseBean ( attrs , start , parent ) ; parseOptionalBody ( useBeanNode , "jsp:useBean" , TagInfo . BODY_CONTENT_JSP ) ; }


Input: / * 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 ) . [CODESPLIT] private void parseOptionalBody ( Node parent , String tag , String bodyType ) throws JasperException { 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 ) ; } }


Input: Attempts to parse JspAttributeAndBody production . Returns true if it matched or false if not . Assumes EmptyBody is okay as well . [CODESPLIT] private boolean parseJspAttributeAndBody ( Node parent , String tag , String bodyType ) throws JasperException { 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 ; }


Input: / * Params :: = > S? ( ( <jsp : body > ( ( S? Param + S? < / jsp : body > ) | <TRANSLATION_ERROR > ) ) | Param + ) < / jsp : params > [CODESPLIT] private void parseJspParams ( Node parent ) throws JasperException { Node jspParamsNode = new Node . ParamsAction ( start , parent ) ; parseOptionalBody ( jspParamsNode , "jsp:params" , JAVAX_BODY_CONTENT_PARAM ) ; }


Input: / * Fallback :: = / > | ( > S? <jsp : body > ( ( S? ( Char * - ( Char * < / jsp : body > ) ) < / jsp : body > S? ) | <TRANSLATION_ERROR > ) < / jsp : fallback > ) | ( > ( Char * - ( Char * < / jsp : fallback > ) ) < / jsp : fallback > ) [CODESPLIT] private void parseFallBack ( Node parent ) throws JasperException { Node fallBackNode = new Node . FallBackAction ( start , parent ) ; parseOptionalBody ( fallBackNode , "jsp:fallback" , JAVAX_BODY_CONTENT_TEMPLATE_TEXT ) ; }


Input: / * For Plugin : StdActionContent :: = Attributes PluginBody [CODESPLIT] private void parsePlugin ( Node parent ) throws JasperException { Attributes attrs = parseAttributes ( ) ; reader . skipSpaces ( ) ; Node pluginNode = new Node . PlugIn ( attrs , start , parent ) ; parseOptionalBody ( pluginNode , "jsp:plugin" , JAVAX_BODY_CONTENT_PLUGIN ) ; }


Input: / * PluginTags :: = ( <jsp : params Params S? ) ? ( <jsp : fallback Fallback? S? ) ? [CODESPLIT] private void parsePluginTags ( Node parent ) throws JasperException { reader . skipSpaces ( ) ; if ( reader . matches ( "<jsp:params" ) ) { parseJspParams ( parent ) ; reader . skipSpaces ( ) ; } if ( reader . matches ( "<jsp:fallback" ) ) { parseFallBack ( parent ) ; reader . skipSpaces ( ) ; } }


Input: / * StandardAction :: = include StdActionContent | forward StdActionContent | invoke StdActionContent | doBody StdActionContent | getProperty StdActionContent | setProperty StdActionContent | useBean StdActionContent | plugin StdActionContent | element StdActionContent [CODESPLIT] private void parseStandardAction ( Node parent ) throws JasperException { 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" ) ; } }


Input: / * # < CustomAction CustomActionBody [CODESPLIT] private boolean parseCustomTag ( Node parent ) throws JasperException { 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 ; }


Input: / * Parse for a template text string until < or $ { is encountered recognizing escape sequences \ % \ $ and \ # . [CODESPLIT] private void parseTemplateText ( Node parent ) throws JasperException { 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 ) ; }


Input: / * XMLTemplateText :: = ( S? / > ) | ( S? > ( ( Char * - ( Char * ( < | $ { ) ) ) ( $ { ELExpressionBody ) ? CDSect? ) * ETag ) | <TRANSLATION_ERROR > [CODESPLIT] private void parseXMLTemplateText ( Node parent ) throws JasperException { 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" ) ; } } }


Input: / * AllBody :: = ( <% -- JSPCommentBody ) | ( <% [CODESPLIT] private void parseElements ( Node parent ) throws JasperException { 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 ) ; } }


Input: / * ScriptlessBody :: = ( <% -- JSPCommentBody ) | ( <% [CODESPLIT] private void parseElementsScriptless ( Node parent ) throws JasperException { // 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 -- ; }


Input: / * TemplateTextBody :: = ( <% -- JSPCommentBody ) | ( <% [CODESPLIT] private void parseElementsTemplateText ( Node parent ) throws JasperException { 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 ) ; } }


Input: / * Flag as error if an unbalanced end tag appears by itself . [CODESPLIT] private void checkUnbalancedEndTag ( ) throws JasperException { 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 ) ; }


Input: TagDependentBody : = [CODESPLIT] private void parseTagDependentBody ( Node parent , String tag ) throws JasperException { 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 ) ; }


Input: / * Parses jsp : body action . [CODESPLIT] private void parseJspBody ( Node parent , String bodyType ) throws JasperException { 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 ) ; } }


Input: / * Parse the body as JSP content . [CODESPLIT] private void parseBody ( Node parent , String tag , String bodyType ) throws JasperException { 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 ) ; } }


Input: / * Parses named attributes . [CODESPLIT] private void parseNamedAttributes ( Node parent ) throws JasperException { 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" ) ) ; }


Input: Determine the body type of <jsp : attribute > from the enclosing node [CODESPLIT] private String getAttributeBodyType ( Node n , String name ) { 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 ; }


Input: Get the attribute that is non request time expression either from the attribute of the node or from a jsp : attrbute [CODESPLIT] public String getTextAttribute ( String name ) { String attr = getAttributeValue ( name ) ; if ( attr != null ) { return attr ; } NamedAttribute namedAttribute = getNamedAttributeNode ( name ) ; if ( namedAttribute == null ) { return null ; } return namedAttribute . getText ( ) ; }


Input: 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 . <p > This should always be called and only be called for nodes that accept dynamic runtime attribute expressions . [CODESPLIT] public NamedAttribute getNamedAttributeNode ( String name ) { 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 ; }


Input: Searches all subnodes of this node for jsp : attribute standard actions and returns that set of nodes as a Node . Nodes object . [CODESPLIT] public Node . Nodes getNamedAttributeNodes ( ) { 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 ; }


Input: / * Adds this Node to the body of the given parent . [CODESPLIT] private void addToParent ( Node parent ) { if ( parent != null ) { this . parent = parent ; Nodes parentBody = parent . getBody ( ) ; if ( parentBody == null ) { parentBody = new Nodes ( ) ; parent . setBody ( parentBody ) ; } parentBody . add ( this ) ; } }


Input: Get a list of matching factories <p > 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 . < / p > [CODESPLIT] public List < ProcessorFactoryInformation > getFactoriesFor ( final Class < ? > [ ] contextClasses ) { requireNonNull ( contextClasses ) ; final List < ProcessorFactoryInformation > result = new ArrayList <> ( ) ; this . tracker . consumeAll ( stream -> stream . filter ( service -> isMatch ( service , contextClasses ) ) . forEach ( result :: add ) ) ; return result ; }


Input: Add an attribute to this node replacing any existing attribute with the same name . [CODESPLIT] public void addAttribute ( String name , String value ) { if ( attributes == null ) attributes = new HashMap < String , String > ( ) ; attributes . put ( name , value ) ; }


Input: Add a new child node to this node . [CODESPLIT] public void addChild ( TreeNode node ) { if ( children == null ) children = new ArrayList < TreeNode > ( ) ; children . add ( node ) ; }


Input: Return the value of the specified node attribute if it exists or <code > null< / code > otherwise . [CODESPLIT] public String findAttribute ( String name ) { if ( attributes == null ) return ( null ) ; else return ( attributes . get ( name ) ) ; }


Input: Return an Iterator of the attribute names of this node . If there are no attributes an empty Iterator is returned . [CODESPLIT] public Iterator < String > findAttributes ( ) { Set < String > attrs ; if ( attributes == null ) attrs = Collections . emptySet ( ) ; else attrs = attributes . keySet ( ) ; return attrs . iterator ( ) ; }


Input: Return the first child node of this node with the specified name if there is one ; otherwise return <code > null< / code > . [CODESPLIT] public TreeNode findChild ( String name ) { if ( children == null ) return ( null ) ; for ( TreeNode item : children ) { if ( name . equals ( item . getName ( ) ) ) return ( item ) ; } return ( null ) ; }


Input: Return an Iterator of all children of this node . If there are no children an empty Iterator is returned . [CODESPLIT] public Iterator < TreeNode > findChildren ( ) { List < TreeNode > nodes ; if ( children == null ) nodes = Collections . emptyList ( ) ; else nodes = children ; return nodes . iterator ( ) ; }


Input: 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 . [CODESPLIT] public Iterator < TreeNode > findChildren ( String name ) { 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 ( ) ; }


Input: Create a new instance without classifier and extension [CODESPLIT] public MavenCoordinates toBase ( ) { if ( this . classifier == null && this . extension == null ) { return this ; } return new MavenCoordinates ( this . groupId , this . artifactId , this . version ) ; }


Input: 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 . [CODESPLIT] private String findAlias ( String varName ) { if ( aliases == null ) return varName ; String alias = aliases . get ( varName ) ; if ( alias == null ) { return varName ; } return alias ; }


Input: Start capturing thread s output . [CODESPLIT] public static void setThread ( ) { ByteArrayOutputStream baos = new ByteArrayOutputStream ( ) ; data . set ( baos ) ; streams . set ( new PrintStream ( baos ) ) ; }


Input: Stop capturing thread s output and return captured data as a String . [CODESPLIT] public static String unsetThread ( ) { ByteArrayOutputStream baos = ( ByteArrayOutputStream ) data . get ( ) ; if ( baos == null ) { return null ; } streams . set ( null ) ; data . set ( null ) ; return baos . toString ( ) ; }


Input: Find PrintStream to which the output must be written to . [CODESPLIT] protected PrintStream findStream ( ) { PrintStream ps = ( PrintStream ) streams . get ( ) ; if ( ps == null ) { ps = wrapped ; } return ps ; }


Input: Write field only when the value is set [CODESPLIT] protected static void writeOptional ( final StringWriter writer , final String fieldName , final String value ) { if ( value != null ) { write ( writer , fieldName , value ) ; } }


Input: Write a field [CODESPLIT] protected static void write ( final StringWriter writer , final String fieldName , final String value ) { writer . write ( fieldName + ": " + value + "\n" ) ; }


Input: Create a new element and add it as the last child [CODESPLIT] public static Element addElement ( final Element parent , final String name ) { final Element ele = parent . getOwnerDocument ( ) . createElement ( name ) ; parent . appendChild ( ele ) ; return ele ; }


Input: Create a new element and add it as the first child [CODESPLIT] public static Element addElementFirst ( final Element parent , final String name ) { final Element ele = parent . getOwnerDocument ( ) . createElement ( name ) ; parent . insertBefore ( ele , null ) ; return ele ; }


Input: Get the text value of the first element with the matching name <p > Assuming you have an XML file : [CODESPLIT] public static String getText ( final Element ele , final String name ) { 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 ; }


Input: Write a single character . [CODESPLIT] public void write ( int c ) throws IOException { if ( writer != null ) { writer . write ( c ) ; } else { ensureOpen ( ) ; if ( nextChar >= bufferSize ) { reAllocBuff ( 1 ) ; } cb [ nextChar ++ ] = ( char ) c ; } }


Input: Write a portion of an array of characters . [CODESPLIT] public void write ( char [ ] cbuf , int off , int len ) throws IOException { 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 ; } }


Input: Write a portion of a String . [CODESPLIT] public void write ( String s , int off , int len ) throws IOException { 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 ; } }


Input: 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 . [CODESPLIT] public void close ( ) throws IOException { if ( writer != null ) { writer . close ( ) ; } else { cb = null ; closed = true ; } }


Input: 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 . [CODESPLIT] public void writeOut ( Writer out ) throws IOException { 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. } }


Input: Sets the writer to which all output is written . [CODESPLIT] void setWriter ( Writer writer ) { 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 ( ) ; } }


Input: Reallocates buffer since the spec requires it to be unbounded . [CODESPLIT] private void reAllocBuff ( int len ) { 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 ; }


Input: Creates the functions mappers for all EL expressions in the JSP page . [CODESPLIT] public static void map ( Compiler compiler , Node . Nodes page ) throws JasperException { 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 ) ; } }


Input: Traverse up from the provided parent and find the first which uses the same key [CODESPLIT] private static State getSameParent ( final State parent , final MetaKey key ) { State current = parent ; while ( current != null ) { if ( current . key . equals ( key ) ) { return current ; } current = current . parent ; } return null ; }


Input: Register a new model with the storage manager [CODESPLIT] public StorageRegistration registerModel ( final long lockPriority , final MetaKey key , final StorageModelProvider < ? , ? > storageProvider ) throws ModelInitializationException { 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 ( ) ; } }


Input: Stream directly from the storage [CODESPLIT] public boolean stream ( final MetaKey key , final IOConsumer < InputStream > consumer ) throws IOException { return streamFrom ( this . dataPath , key , consumer ) ; }


Input: Monitor the job only produces an HTML fragment of the current job state [CODESPLIT] @ RequestMapping ( "/{id}/monitor" ) public ModelAndView monitor ( @ PathVariable ( "id" ) final String id ) { 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 ) ; }


Input: clean up the path so that is looks like . / usr / local / file [CODESPLIT] private String cleanupPath ( String fileName ) { 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 ; }


Input: Authenticate the request is authenticated against the deploy keys <p > If the request could not be authenticated a basic authentication request is sent back and the { @link HttpServletResponse } will be committed . < / p > [CODESPLIT] protected boolean authenticate ( final By by , final HttpServletRequest request , final HttpServletResponse response ) throws IOException { if ( isAuthenticated ( by , request ) ) { return true ; } BasicAuthentication . request ( response , "channel" , "Please authenticate" ) ; return false ; }


Input: Simply test if the request is authenticated against the channels deploy keys [CODESPLIT] protected boolean isAuthenticated ( final By by , final HttpServletRequest request ) { 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 ) ; }


Input: Read a single character . This method will block until a character is available an I / O error occurs or the end of the stream is reached . [CODESPLIT] public int read ( ) throws IOException { int b0 = fInputStream . read ( ) & 0xff ; if ( b0 == 0xff ) return - 1 ; int b1 = fInputStream . read ( ) & 0xff ; if ( b1 == 0xff ) return - 1 ; if ( fEncoding >= 4 ) { int b2 = fInputStream . read ( ) & 0xff ; if ( b2 == 0xff ) return - 1 ; int b3 = fInputStream . read ( ) & 0xff ; if ( b3 == 0xff ) return - 1 ; if ( log . isLoggable ( Level . FINE ) ) log . fine ( "b0 is " + ( b0 & 0xff ) + " b1 " + ( b1 & 0xff ) + " b2 " + ( b2 & 0xff ) + " b3 " + ( b3 & 0xff ) ) ; if ( fEncoding == UCS4BE ) return ( b0 << 24 ) + ( b1 << 16 ) + ( b2 << 8 ) + b3 ; else return ( b3 << 24 ) + ( b2 << 16 ) + ( b1 << 8 ) + b0 ; } else { // UCS-2 if ( fEncoding == UCS2BE ) return ( b0 << 8 ) + b1 ; else return ( b1 << 8 ) + b0 ; } }


Input: Complete the document but don t close the underlying writer [CODESPLIT] public void finish ( ) throws IOException { if ( ! this . finished ) { this . finished = true ; writeEnd ( ) ; } try { this . out . close ( ) ; } catch ( final XMLStreamException e ) { throw new IOException ( e ) ; } }


Input: Make an appropriate Gson parser to processing ChannelData instances [CODESPLIT] public static Gson makeGson ( final boolean pretty ) { final GsonBuilder gb = new GsonBuilder ( ) ; if ( pretty ) { gb . setPrettyPrinting ( ) ; } gb . registerTypeAdapter ( Node . class , new NodeAdapter ( ) ) ; gb . registerTypeAdapter ( byte [ ] . class , new ByteArrayAdapter ( ) ) ; return gb . create ( ) ; }


Input: Gets an integer [ 0 63 ] matching the highest two bits of an integer . This is like bit scan reverse ( BSR ) on x86 except that this also cares about the second highest bit . [CODESPLIT] public static int getDistSlot ( int dist ) { if ( dist <= DIST_MODEL_START && dist >= 0 ) return dist ; int n = dist ; int i = 31 ; if ( ( n & 0xFFFF0000 ) == 0 ) { n <<= 16 ; i = 15 ; } if ( ( n & 0xFF000000 ) == 0 ) { n <<= 8 ; i -= 8 ; } if ( ( n & 0xF0000000 ) == 0 ) { n <<= 4 ; i -= 4 ; } if ( ( n & 0xC0000000 ) == 0 ) { n <<= 2 ; i -= 2 ; } if ( ( n & 0x80000000 ) == 0 ) -- i ; return ( i << 1 ) + ( ( dist >>> ( i - 1 ) ) & 1 ) ; }


Input: Compresses for LZMA2 . [CODESPLIT] public boolean encodeForLZMA2 ( ) { // LZMA2 uses RangeEncoderToBuffer so IOExceptions aren't possible. try { if ( ! lz . isStarted ( ) && ! encodeInit ( ) ) return false ; while ( uncompressedSize <= LZMA2_UNCOMPRESSED_LIMIT && rc . getPendingSize ( ) <= LZMA2_COMPRESSED_LIMIT ) if ( ! encodeSymbol ( ) ) return false ; } catch ( IOException e ) { throw new Error ( ) ; } return true ; }


Input: Get a string from meta data <p > If the provided metadata set is <code > null< / code > then the result will also be <code > null< / code > . < / p > [CODESPLIT] public static String getString ( final Map < MetaKey , String > metadata , final String ns , final String key ) { return getString ( metadata , ns , key , null ) ; }


Input: Get a string from meta data <p > If the provided metadata set is <code > null< / code > then the result will also be <code > null< / code > . < / p > [CODESPLIT] public static String getString ( final Map < MetaKey , String > metadata , final String ns , final String key , final String defaultValue ) { if ( metadata == null ) { return defaultValue ; } final String result = metadata . get ( new MetaKey ( ns , key ) ) ; if ( result == null ) { return defaultValue ; } return result ; }


Input: Return an unmodifiable map of provided and extracted meta data [CODESPLIT] public static Map < MetaKey , String > union ( final Map < MetaKey , String > providedMetaData , final Map < MetaKey , String > extractedMetaData ) { final int size1 = providedMetaData != null ? providedMetaData . size ( ) : 0 ; final int size2 = extractedMetaData != null ? extractedMetaData . size ( ) : 0 ; if ( size1 + size2 == 0 ) { return Collections . emptyMap ( ) ; } final Map < MetaKey , String > result = new HashMap <> ( size1 + size2 ) ; if ( extractedMetaData != null ) { result . putAll ( extractedMetaData ) ; } // provided will override if ( providedMetaData != null ) { result . putAll ( providedMetaData ) ; } return Collections . unmodifiableMap ( result ) ; }


Input:
Write out the announce file <br > Writing a file like this seems a little bit strange from a Java perspective . However there seems to be no other way to create a file with a provided set of initial file attributes other than { @link Files#newByteChannel ( java . nio . file . Path Set FileAttribute ... ) } . All other methods don t access file attributes . [CODESPLIT] protected void writeAnnounceFile ( final String adminToken ) { final Path path = ANNOUNCE_FILE . toPath ( ) ; /*
         * Try to delete the file first. We don't care about the result
         * since the next operation will try to create a new file anyway.
         *
         * However by deleting it first, we try to ensure that the initial
         * file permissions are set. If the file exists these would not be
         * changed.
         */ ANNOUNCE_FILE . delete ( ) ; // posix final FileAttribute < ? > [ ] attrs ; if ( ANNOUNCE_FILE_POSIX ) { final Set < PosixFilePermission > perms = EnumSet . of ( PosixFilePermission . OWNER_READ , PosixFilePermission . OWNER_WRITE ) ; attrs = new FileAttribute < ? > [ ] { PosixFilePermissions . asFileAttribute ( perms ) } ; } else { attrs = new FileAttribute < ? > [ 0 ] ; } final Set < ? extends OpenOption > options = EnumSet . of ( StandardOpenOption . CREATE , StandardOpenOption . WRITE , StandardOpenOption . TRUNCATE_EXISTING ) ; try ( SeekableByteChannel sbc = Files . newByteChannel ( path , options , attrs ) ) { final StringWriter sw = new StringWriter ( ) ; final PrintWriter writer = new PrintWriter ( sw ) ; writer . format ( "user=%s%n" , NAME ) ; writer . format ( "password=%s%n" , adminToken ) ; writer . close ( ) ; final ByteBuffer data = ByteBuffer . wrap ( sw . toString ( ) . getBytes ( StandardCharsets . UTF_8 ) ) ; while ( data . hasRemaining ( ) ) { sbc . write ( data ) ; } } catch ( final UnsupportedOperationException e ) { System . err . format ( "WARNING: Failed to write out announce file with secured posix permissions. If you are on a non-posix platform (e.g. Windows), you might need to set the system property '%s' to 'true'%n" , PROP_NOT_POSIX ) ; } catch ( final IOException e ) { System . err . println ( "WARNING: Unable to write announce file: " + ExceptionHelper . getMessage ( e ) ) ; } }


Input:
Returns the value of the javax . servlet . error . exception request attribute value if present otherwise the value of the javax . servlet . jsp . jspException request attribute value . [CODESPLIT] public static Throwable getThrowable ( ServletRequest request ) { Throwable error = ( Throwable ) request . getAttribute ( SERVLET_EXCEPTION ) ; if ( error == null ) { error = ( Throwable ) request . getAttribute ( JSP_EXCEPTION ) ; if ( error != null ) { /*
		 * The only place that sets JSP_EXCEPTION is
		 * PageContextImpl.handlePageException(). It really should set
		 * SERVLET_EXCEPTION, but that would interfere with the
		 * ErrorReportValve. Therefore, if JSP_EXCEPTION is set, we
		 * need to set SERVLET_EXCEPTION.
		 */ request . setAttribute ( SERVLET_EXCEPTION , error ) ; } } return error ; }


Input: __begin introspecthelperMethod [CODESPLIT] public static void introspecthelper ( Object bean , String prop , String value , ServletRequest request , String param , boolean ignoreMethodNF ) throws JasperException { if ( Constants . IS_SECURITY_ENABLED ) { try { PrivilegedIntrospectHelper dp = new PrivilegedIntrospectHelper ( bean , prop , value , request , param , ignoreMethodNF ) ; AccessController . doPrivileged ( dp ) ; } catch ( PrivilegedActionException pe ) { Exception e = pe . getException ( ) ; throw ( JasperException ) e ; } } else { internalIntrospecthelper ( bean , prop , value , request , param , ignoreMethodNF ) ; } }


Input: Create a typed array . This is a special case where params are passed through the request and the property is indexed . [CODESPLIT] public static void createTypedArray ( String propertyName , Object bean , Method method , String [ ] values , Class t , Class propertyEditorClass ) throws JasperException { try { if ( propertyEditorClass != null ) { Object [ ] tmpval = new Integer [ values . length ] ; for ( int i = 0 ; i < values . length ; i ++ ) { tmpval [ i ] = getValueFromBeanInfoPropertyEditor ( t , propertyName , values [ i ] , propertyEditorClass ) ; } method . invoke ( bean , new Object [ ] { tmpval } ) ; } else if ( t . equals ( Integer . class ) ) { Integer [ ] tmpval = new Integer [ values . length ] ; for ( int i = 0 ; i < values . length ; i ++ ) tmpval [ i ] = Integer . valueOf ( values [ i ] ) ; method . invoke ( bean , new Object [ ] { tmpval } ) ; } else if ( t . equals ( Byte . class ) ) { Byte [ ] tmpval = new Byte [ values . length ] ; for ( int i = 0 ; i < values . length ; i ++ ) tmpval [ i ] = Byte . valueOf ( values [ i ] ) ; method . invoke ( bean , new Object [ ] { tmpval } ) ; } else if ( t . equals ( Boolean . class ) ) { Boolean [ ] tmpval = new Boolean [ values . length ] ; for ( int i = 0 ; i < values . length ; i ++ ) tmpval [ i ] = Boolean . valueOf ( values [ i ] ) ; method . invoke ( bean , new Object [ ] { tmpval } ) ; } else if ( t . equals ( Short . class ) ) { Short [ ] tmpval = new Short [ values . length ] ; for ( int i = 0 ; i < values . length ; i ++ ) tmpval [ i ] = Short . valueOf ( values [ i ] ) ; method . invoke ( bean , new Object [ ] { tmpval } ) ; } else if ( t . equals ( Long . class ) ) { Long [ ] tmpval = new Long [ values . length ] ; for ( int i = 0 ; i < values . length ; i ++ ) tmpval [ i ] = Long . valueOf ( values [ i ] ) ; method . invoke ( bean , new Object [ ] { tmpval } ) ; } else if ( t . equals ( Double . class ) ) { Double [ ] tmpval = new Double [ values . length ] ; for ( int i = 0 ; i < values . length ; i ++ ) tmpval [ i ] = Double . valueOf ( values [ i ] ) ; method . invoke ( bean , new Object [ ] { tmpval } ) ; } else if ( t . equals ( Float . class ) ) { Float [ ] tmpval = new Float [ values . length ] ; for ( int i = 0 ; i < values . length ; i ++ ) tmpval [ i ] = Float . valueOf ( values [ i ] ) ; method . invoke ( bean , new Object [ ] { tmpval } ) ; } else if ( t . equals ( Character . class ) ) { Character [ ] tmpval = new Character [ values . length ] ; for ( int i = 0 ; i < values . length ; i ++ ) tmpval [ i ] = Character . valueOf ( values [ i ] . charAt ( 0 ) ) ; method . invoke ( bean , new Object [ ] { tmpval } ) ; } else if ( t . equals ( int . class ) ) { int [ ] tmpval = new int [ values . length ] ; for ( int i = 0 ; i < values . length ; i ++ ) tmpval [ i ] = Integer . parseInt ( values [ i ] ) ; method . invoke ( bean , new Object [ ] { tmpval } ) ; } else if ( t . equals ( byte . class ) ) { byte [ ] tmpval = new byte [ values . length ] ; for ( int i = 0 ; i < values . length ; i ++ ) tmpval [ i ] = Byte . parseByte ( values [ i ] ) ; method . invoke ( bean , new Object [ ] { tmpval } ) ; } else if ( t . equals ( boolean . class ) ) { boolean [ ] tmpval = new boolean [ values . length ] ; for ( int i = 0 ; i < values . length ; i ++ ) tmpval [ i ] = ( Boolean . valueOf ( values [ i ] ) ) . booleanValue ( ) ; method . invoke ( bean , new Object [ ] { tmpval } ) ; } else if ( t . equals ( short . class ) ) { short [ ] tmpval = new short [ values . length ] ; for ( int i = 0 ; i < values . length ; i ++ ) tmpval [ i ] = Short . parseShort ( values [ i ] ) ; method . invoke ( bean , new Object [ ] { tmpval } ) ; } else if ( t . equals ( long . class ) ) { long [ ] tmpval = new long [ values . length ] ; for ( int i = 0 ; i < values . length ; i ++ ) tmpval [ i ] = Long . parseLong ( values [ i ] ) ; method . invoke ( bean , new Object [ ] { tmpval } ) ; } else if ( t . equals ( double . class ) ) { double [ ] tmpval = new double [ values . length ] ; for ( int i = 0 ; i < values . length ; i ++ ) tmpval [ i ] = Double . valueOf ( values [ i ] ) . doubleValue ( ) ; method . invoke ( bean , new Object [ ] { tmpval } ) ; } else if ( t . equals ( float . class ) ) { float [ ] tmpval = new float [ values . length ] ; for ( int i = 0 ; i < values . length ; i ++ ) tmpval [ i ] = Float . valueOf ( values [ i ] ) . floatValue ( ) ; method . invoke ( bean , new Object [ ] { tmpval } ) ; } else if ( t . equals ( char . class ) ) { char [ ] tmpval = new char [ values . length ] ; for ( int i = 0 ; i < values . length ; i ++ ) tmpval [ i ] = values [ i ] . charAt ( 0 ) ; method . invoke ( bean , new Object [ ] { tmpval } ) ; } else { Object [ ] tmpval = new Integer [ values . length ] ; for ( int i = 0 ; i < values . length ; i ++ ) { tmpval [ i ] = getValueFromPropertyEditorManager ( t , propertyName , values [ i ] ) ; } method . invoke ( bean , new Object [ ] { tmpval } ) ; } } catch ( Exception ex ) { throw new JasperException ( "error in invoking method" , ex ) ; } }


Input: __begin lookupReadMethodMethod [CODESPLIT] public static Object handleGetProperty ( Object o , String prop ) throws JasperException { if ( o == null ) { throw new JasperException ( Localizer . getMessage ( "jsp.error.beans.nullbean" ) ) ; } Object value = null ; try { Method method = getReadMethod ( o . getClass ( ) , prop ) ; value = method . invoke ( o , ( Object [ ] ) null ) ; } catch ( Exception ex ) { throw new JasperException ( ex ) ; } return value ; }


Input: Use proprietaryEvaluate public static void handleSetPropertyExpression ( Object bean String prop String expression PageContext pageContext VariableResolver variableResolver FunctionMapper functionMapper ) throws JasperException { try { Method method = getWriteMethod ( bean . getClass () prop ) ; method . invoke ( bean new Object [] { pageContext . getExpressionEvaluator () . evaluate ( expression method . getParameterTypes () [ 0 ] variableResolver functionMapper null ) } ) ; } catch ( Exception ex ) { throw new JasperException ( ex ) ; } } [CODESPLIT] public static void handleSetPropertyExpression ( Object bean , String prop , String expression , PageContext pageContext , ProtectedFunctionMapper functionMapper ) throws JasperException { try { Method method = getWriteMethod ( bean . getClass ( ) , prop ) ; method . invoke ( bean , new Object [ ] { PageContextImpl . evaluateExpression ( expression , method . getParameterTypes ( ) [ 0 ] , pageContext , functionMapper ) } ) ; } catch ( Exception ex ) { throw new JasperException ( ex ) ; } }