public static String getWarName ( ServletContext context ) { String [ ] pathSegments = context . getRealPath ( "/WEB-INF/web.xml" ) . split ( "/" ) ; String warName = pathSegments [ pathSegments . length - 3 ] ; if ( ! warName . endsWith ( ".war" ) ) { URL webXml = WarUtils . class . getClassLoader ( ) . getResource ( "/cadmium-version.properties" ) ; if ( webXml != null ) { String urlString = webXml . toString ( ) . substring ( 0 , webXml . toString ( ) . length ( ) - "/WEB-INF/classes/cadmium-version.properties" . length ( ) ) ; File warFile = null ; if ( webXml . getProtocol ( ) . equalsIgnoreCase ( "file" ) ) { warFile = new File ( urlString . substring ( 5 ) ) ; } else if ( webXml . getProtocol ( ) . equalsIgnoreCase ( "vfszip" ) ) { warFile = new File ( urlString . substring ( 7 ) ) ; } else if ( webXml . getProtocol ( ) . equalsIgnoreCase ( "vfsfile" ) ) { warFile = new File ( urlString . substring ( 8 ) ) ; } else if ( webXml . getProtocol ( ) . equalsIgnoreCase ( "vfs" ) && System . getProperty ( JBOSS_7_DEPLOY_DIR ) != null ) { String path = urlString . substring ( "vfs:/" . length ( ) ) ; String deployDir = System . getProperty ( JBOSS_7_DEPLOY_DIR ) ; warFile = new File ( deployDir , path ) ; } if ( warFile != null ) { warName = warFile . getName ( ) ; } } } return warName ; }
Gets the currently deployed war file name from the ServletContext .