idx
int64
0
41.2k
question
stringlengths
74
4.04k
target
stringlengths
7
750
40,800
private void tryToEliminateTheScope ( ) { for ( int i = 0 ; i < _statements . length ; i ++ ) { Statement statement = _statements [ i ] ; if ( statement instanceof VarStatement || ( ! ( statement instanceof StatementList ) && statement . getContainedParsedElementsByType ( EvalExpression . class , null ) ) ) { return ; ...
A statement - list needs to push a new scope on the symbol table to provide a for local variable scoping . Since this is a relatively expensive operation we avoid pushing the scope if we know none of the statements declare variables .
40,801
public static String escapeAttribute ( String string ) { if ( string == null || string . length ( ) == 0 ) { return string ; } StringBuilder resultBuffer = null ; for ( int i = 0 , length = string . length ( ) ; i < length ; i ++ ) { String entity = null ; char ch = string . charAt ( i ) ; switch ( ch ) { case '"' : en...
Escape a string for use as an HTML attribute by replacing all double quotes and & .
40,802
public static Map < String , ISettings > makeDefaultSettings ( Experiment experiment ) { Map < String , ISettings > settings = new TreeMap < > ( ) ; CompilerSettings compilerSettings = new CompilerSettings ( ) ; compilerSettings . resetToDefaultSettings ( experiment ) ; settings . put ( compilerSettings . getPath ( ) ,...
Reset Experiment - specific settings to defaults .
40,803
public static Map < String , ISettings > makeDefaultSettings ( ) { Map < String , ISettings > settings = new TreeMap < > ( ) ; AppearanceSettings appearanceSettings = new AppearanceSettings ( ) ; appearanceSettings . resetToDefaultSettings ( null ) ; settings . put ( appearanceSettings . getPath ( ) , appearanceSetting...
Reset Gosu Lab application - level settings to defaults .
40,804
public static Map < String , ISettings > mergeSettings ( Map < String , ISettings > old , Experiment experiment ) { Map < String , ISettings > defaultSettings = makeDefaultSettings ( experiment ) ; old . keySet ( ) . forEach ( key -> defaultSettings . put ( key , old . get ( key ) ) ) ; return defaultSettings ; }
Assumes settings map is ordered top - down in tree order
40,805
public void setSrcdir ( Path srcDir ) { if ( _src == null ) { _src = srcDir ; } else { _src . append ( srcDir ) ; } }
Set the source directories to find the source Gosu files .
40,806
public Curve25519KeyPair generateKeyPair ( ) { byte [ ] privateKey = provider . generatePrivateKey ( ) ; byte [ ] publicKey = provider . generatePublicKey ( privateKey ) ; return new Curve25519KeyPair ( publicKey , privateKey ) ; }
Generates a Curve25519 keypair .
40,807
public byte [ ] calculateAgreement ( byte [ ] publicKey , byte [ ] privateKey ) { if ( publicKey == null || privateKey == null ) { throw new IllegalArgumentException ( "Keys must not be null!" ) ; } if ( publicKey . length != 32 || privateKey . length != 32 ) { throw new IllegalArgumentException ( "Keys must be 32 byte...
Calculates an ECDH agreement .
40,808
public boolean verifySignature ( byte [ ] publicKey , byte [ ] message , byte [ ] signature ) { if ( publicKey == null || publicKey . length != 32 ) { throw new IllegalArgumentException ( "Invalid public key!" ) ; } if ( message == null || signature == null || signature . length != 64 ) { return false ; } return provid...
Verify a Curve25519 signature .
40,809
public byte [ ] calculateVrfSignature ( byte [ ] privateKey , byte [ ] message ) { if ( privateKey == null || privateKey . length != 32 ) { throw new IllegalArgumentException ( "Invalid private key!" ) ; } byte [ ] random = provider . getRandom ( 64 ) ; return provider . calculateVrfSignature ( random , privateKey , me...
Calculates a Unique Curve25519 signature .
40,810
public byte [ ] verifyVrfSignature ( byte [ ] publicKey , byte [ ] message , byte [ ] signature ) throws VrfSignatureVerificationFailedException { if ( publicKey == null || publicKey . length != 32 ) { throw new IllegalArgumentException ( "Invalid public key!" ) ; } if ( message == null || signature == null || signatur...
Verify a Unique Curve25519 signature .
40,811
private Record setDefault ( Record record ) { int size = record . size ( ) ; for ( int i = 0 ; i < size ; i ++ ) if ( record . get ( i ) == null ) { @ SuppressWarnings ( "unchecked" ) Field < Object > field = ( Field < Object > ) record . field ( i ) ; if ( ! field . getDataType ( ) . nullable ( ) && ! field . getDataT...
Defaults fields that have a default value and are nullable .
40,812
protected Object convertToAsyncDriverTypes ( Object object ) { if ( object instanceof Enum ) { return ( ( Enum ) object ) . name ( ) ; } else if ( object instanceof LocalDateTime ) { LocalDateTime convert = ( LocalDateTime ) object ; return new org . joda . time . LocalDateTime ( convert . getYear ( ) , convert . getMo...
Async - driver uses joda - time instead of java - time so we need to convert it .
40,813
public void sql ( BindingSQLContext < JsonArray > ctx ) { RenderContext context = ctx . render ( ) . visit ( DSL . val ( ctx . convert ( converter ( ) ) . value ( ) ) ) ; if ( SQLDialect . POSTGRES . equals ( ctx . configuration ( ) . dialect ( ) . family ( ) ) ) { context . sql ( "::json" ) ; } }
Rending a bind variable for the binding context s value and casting it to the json type
40,814
public void register ( BindingRegisterContext < JsonArray > ctx ) throws SQLException { ctx . statement ( ) . registerOutParameter ( ctx . index ( ) , Types . VARCHAR ) ; }
Registering VARCHAR types for JDBC CallableStatement OUT parameters
40,815
public void set ( BindingSetStatementContext < JsonArray > ctx ) throws SQLException { ctx . statement ( ) . setString ( ctx . index ( ) , Objects . toString ( ctx . convert ( converter ( ) ) . value ( ) , null ) ) ; }
Converting the JsonArray to a String value and setting that on a JDBC PreparedStatement
40,816
public void get ( BindingGetResultSetContext < JsonArray > ctx ) throws SQLException { ctx . convert ( converter ( ) ) . value ( ctx . resultSet ( ) . getString ( ctx . index ( ) ) ) ; }
Getting a String value from a JDBC ResultSet and converting that to a JsonArray
40,817
protected Collection < JavaWriter > writeExtraData ( SchemaDefinition definition , Function < File , JavaWriter > writerGenerator ) { return Collections . emptyList ( ) ; }
Write some extra data during code generation
40,818
protected void generateDao ( TableDefinition table , JavaWriter out1 ) { UniqueKeyDefinition key = table . getPrimaryKey ( ) ; if ( key == null ) { logger . info ( "Skipping DAO generation" , out1 . file ( ) . getName ( ) ) ; return ; } VertxJavaWriter out = ( VertxJavaWriter ) out1 ; generateDAO ( key , table , out ) ...
copied from jOOQ s JavaGenerator
40,819
public void get ( BindingGetStatementContext < JsonObject > ctx ) throws SQLException { ctx . convert ( converter ( ) ) . value ( ctx . statement ( ) . getString ( ctx . index ( ) ) ) ; }
Getting a String value from a JDBC CallableStatement and converting that to a JsonObject
40,820
boolean startsWith ( final Literal literal ) { final int index = literal . getIndex ( ) ; final Boolean cached = myPrefixCache . get ( index ) ; if ( cached != null ) { return cached . booleanValue ( ) ; } final boolean result = literal . matches ( myChars , 0 ) ; myPrefixCache . set ( index , result ) ; return result ...
Indicates whether this instance starts with the specified prefix .
40,821
boolean endsWith ( final Literal literal ) { final int index = literal . getIndex ( ) ; final Boolean cached = myPostfixCache . get ( index ) ; if ( cached != null ) { return cached . booleanValue ( ) ; } final boolean result = literal . matches ( myChars , myChars . length - literal . getLength ( ) ) ; myPostfixCache ...
Indicates whether this instance ends with the specified postfix .
40,822
int [ ] getIndices ( final Literal literal ) { final int index = literal . getIndex ( ) ; final int [ ] cached = myIndices [ index ] ; if ( cached != null ) { return cached ; } final int [ ] values = findIndices ( literal ) ; myIndices [ index ] = values ; return values ; }
Returns all indices where the literal argument can be found in this String . Results are cached for better performance .
40,823
private int [ ] findIndices ( final Literal literal ) { int count = 0 ; final char s = literal . getFirstChar ( ) ; for ( int i = 0 ; i < myChars . length ; i ++ ) { if ( ( myChars [ i ] == s || s == '?' ) && literal . matches ( myChars , i ) ) { myBuffer [ count ] = i ; count ++ ; } } if ( count == 0 ) { return EMPTY ...
Returns all indices where the literal argument can be found in this String .
40,824
boolean matches ( final char [ ] value , final int from ) { final int len = myCharacters . length ; if ( len + from > value . length || from < 0 ) { return false ; } for ( int i = 0 ; i < len ; i ++ ) { if ( myCharacters [ i ] != value [ i + from ] && myCharacters [ i ] != '?' ) { return false ; } } return true ; }
Checks whether the value represents a complete substring from the from index .
40,825
boolean requires ( final String value ) { if ( requires ( myPrefix , value ) || requires ( myPostfix , value ) ) { return true ; } if ( mySuffixes == null ) { return false ; } for ( final Literal suffix : mySuffixes ) { if ( requires ( suffix , value ) ) { return true ; } } return false ; }
Tests whether this rule needs a specific string in the useragent to match .
40,826
private static int checkWildCard ( final SearchableString value , final Literal suffix , final int start ) { for ( final int index : value . getIndices ( suffix ) ) { if ( index >= start ) { return index ; } } return - 1 ; }
Return found index or - 1
40,827
String getPattern ( ) { final StringBuilder result = new StringBuilder ( ) ; if ( myPrefix != null ) { result . append ( myPrefix ) ; } if ( mySuffixes != null ) { result . append ( "*" ) ; for ( final Literal sub : mySuffixes ) { result . append ( sub ) ; result . append ( "*" ) ; } } if ( myPostfix != null ) { result...
Returns the reconstructed original pattern .
40,828
static Rule [ ] getOrderedRules ( final Rule [ ] rules ) { final Comparator < Rule > c = Comparator . comparing ( Rule :: getSize ) . reversed ( ) . thenComparing ( Rule :: getPattern ) ; final Rule [ ] result = Arrays . copyOf ( rules , rules . length ) ; parallelSort ( result , c ) ; return result ; }
Sort by size and alphabet so the first match can be returned immediately
40,829
public static UserAgentParser parse ( final Reader input , final Collection < BrowsCapField > fields ) throws IOException , ParseException { return new UserAgentFileParser ( fields ) . parse ( input ) ; }
Parses a csv stream of rules .
40,830
public UserAgentParser loadParser ( ) throws IOException , ParseException { final Set < BrowsCapField > defaultFields = Stream . of ( BrowsCapField . values ( ) ) . filter ( BrowsCapField :: isDefault ) . collect ( toSet ( ) ) ; return createParserWithFields ( defaultFields ) ; }
Returns a parser based on the bundled BrowsCap version
40,831
private InputStream getCsvFileStream ( ) throws FileNotFoundException { if ( myZipFileStream == null ) { if ( myZipFilePath == null ) { final String csvFileName = getBundledCsvFileName ( ) ; return getClass ( ) . getClassLoader ( ) . getResourceAsStream ( csvFileName ) ; } else { return new FileInputStream ( myZipFileP...
Returns the InputStream to the CSV file . This is either the bundled ZIP file or the one passed in the constructor .
40,832
public static long sizeOfInstance ( Class < ? > type ) { long size = SPEC . getObjectHeaderSize ( ) + sizeOfDeclaredFields ( type ) ; while ( ( type = type . getSuperclass ( ) ) != Object . class && type != null ) size += roundTo ( sizeOfDeclaredFields ( type ) , SPEC . getSuperclassFieldPadding ( ) ) ; return roundTo ...
sizeOfInstanceWithUnsafe is safe against this miscounting
40,833
public static long sizeOfInstanceWithUnsafe ( Class < ? > type ) { while ( type != null ) { long size = 0 ; for ( Field f : declaredFieldsOf ( type ) ) size = Math . max ( size , unsafe . objectFieldOffset ( f ) + sizeOf ( f ) ) ; if ( size > 0 ) return roundTo ( size , SPEC . getObjectPadding ( ) ) ; type = type . get...
attemps to use sun . misc . Unsafe to find the maximum object offset this work around helps deal with long alignment
40,834
public static long sizeOfArray ( int length , long elementSize ) { return roundTo ( SPEC . getArrayHeaderSize ( ) + length * elementSize , SPEC . getObjectPadding ( ) ) ; }
Memory an array will consume
40,835
private static int getAlignment ( ) { RuntimeMXBean runtimeMxBean = ManagementFactory . getRuntimeMXBean ( ) ; for ( String arg : runtimeMxBean . getInputArguments ( ) ) { if ( arg . startsWith ( "-XX:ObjectAlignmentInBytes=" ) ) { try { return Integer . parseInt ( arg . substring ( "-XX:ObjectAlignmentInBytes=" . leng...
check if we have a non - standard object alignment we need to round to
40,836
public void configure ( Object obj , Element cfg , int startIdx ) throws Exception { String id = getAttribute ( cfg , "id" ) ; if ( id != null ) { _idMap . put ( id , obj ) ; } Element [ ] children = getChildren ( cfg ) ; for ( int i = startIdx ; i < children . length ; i ++ ) { Element node = children [ i ] ; try { St...
Recursive configuration step . This method applies the remaining Set Put and Call elements to the current object .
40,837
protected void scanJspConfig ( ) throws IOException , SAXException { JspConfigDescriptor jspConfigDescriptor = context . getJspConfigDescriptor ( ) ; if ( jspConfigDescriptor == null ) { return ; } Collection < TaglibDescriptor > descriptors = jspConfigDescriptor . getTaglibs ( ) ; for ( TaglibDescriptor descriptor : d...
Scan for TLDs defined in &lt ; jsp - config&gt ; .
40,838
protected void scanResourcePaths ( String startPath ) throws IOException , SAXException { Set < String > dirList = context . getResourcePaths ( startPath ) ; if ( dirList != null ) { for ( String path : dirList ) { if ( path . startsWith ( "/WEB-INF/classes/" ) ) { } else if ( path . startsWith ( "/WEB-INF/lib/" ) ) { ...
Scan web application resources for TLDs recursively .
40,839
private void trackHttpContexts ( final BundleContext bundleContext , ExtendedHttpServiceRuntime httpServiceRuntime ) { final ServiceTracker < HttpContext , HttpContextElement > httpContextTracker = HttpContextTracker . createTracker ( extenderContext , bundleContext , httpServiceRuntime ) ; httpContextTracker . open ( ...
Track http contexts .
40,840
private void trackResources ( final BundleContext bundleContext ) { ServiceTracker < Object , ResourceWebElement > resourceTracker = ResourceTracker . createTracker ( extenderContext , bundleContext ) ; resourceTracker . open ( ) ; trackers . add ( 0 , resourceTracker ) ; final ServiceTracker < ResourceMapping , Resour...
Track resources .
40,841
private void trackFilters ( final BundleContext bundleContext ) { final ServiceTracker < Filter , FilterWebElement > filterTracker = FilterTracker . createTracker ( extenderContext , bundleContext ) ; filterTracker . open ( ) ; trackers . add ( 0 , filterTracker ) ; final ServiceTracker < FilterMapping , FilterMappingW...
Track filters .
40,842
private void trackListeners ( final BundleContext bundleContext ) { final ServiceTracker < EventListener , ListenerWebElement > listenerTracker = ListenerTracker . createTracker ( extenderContext , bundleContext ) ; listenerTracker . open ( ) ; trackers . add ( 0 , listenerTracker ) ; final ServiceTracker < ListenerMap...
Track listeners .
40,843
private void trackJspMappings ( final BundleContext bundleContext ) { final ServiceTracker < JspMapping , JspWebElement > jspMappingTracker = JspMappingTracker . createTracker ( extenderContext , bundleContext ) ; jspMappingTracker . open ( ) ; trackers . add ( 0 , jspMappingTracker ) ; }
Track JSPs .
40,844
private void trackWelcomeFiles ( final BundleContext bundleContext ) { final ServiceTracker < WelcomeFileMapping , WelcomeFileWebElement > welcomeFileTracker = WelcomeFileMappingTracker . createTracker ( extenderContext , bundleContext ) ; welcomeFileTracker . open ( ) ; trackers . add ( 0 , welcomeFileTracker ) ; }
Track welcome files
40,845
private void trackErrorPages ( final BundleContext bundleContext ) { final ServiceTracker < ErrorPageMapping , ErrorPageWebElement > errorPagesTracker = ErrorPageMappingTracker . createTracker ( extenderContext , bundleContext ) ; errorPagesTracker . open ( ) ; trackers . add ( 0 , errorPagesTracker ) ; }
Track error pages
40,846
public void sessionCreated ( final HttpSessionEvent event ) { counter ++ ; final HttpSession session = event . getSession ( ) ; final String id = session . getId ( ) ; SESSIONS . put ( id , session ) ; }
Fires whenever a new session is created .
40,847
public void sessionDestroyed ( final HttpSessionEvent event ) { final HttpSession session = event . getSession ( ) ; final String id = session . getId ( ) ; SESSIONS . remove ( id ) ; counter -- ; }
Fires whenever a session is destroyed .
40,848
public static synchronized List < Object > getAttributes ( final String name ) { final List < Object > data = new ArrayList < > ( ) ; for ( final String id : SESSIONS . keySet ( ) ) { final HttpSession session = SESSIONS . get ( id ) ; try { final Object o = session . getAttribute ( name ) ; data . add ( o ) ; } catch ...
Return a list with all session values for a given attribute name .
40,849
public void start ( BundleContext bc ) throws Exception { httpServiceRef = bc . getServiceReference ( HttpService . class ) ; if ( httpServiceRef != null ) { httpService = ( HttpService ) bc . getService ( httpServiceRef ) ; httpService . registerServlet ( "/status" , new StatusServlet ( ) , null , null ) ; httpService...
Called whenever the OSGi framework starts our bundle
40,850
public void stop ( BundleContext bc ) throws Exception { if ( httpService != null ) { bc . ungetService ( httpServiceRef ) ; httpServiceRef = null ; httpService = null ; } }
Called whenever the OSGi framework stops our bundle
40,851
public void setAttribute ( final String name , Object value ) { if ( HttpContext . AUTHENTICATION_TYPE . equals ( name ) ) { handleAuthenticationType ( value ) ; } else if ( HttpContext . REMOTE_USER . equals ( name ) ) { handleRemoteUser ( value ) ; } super . setAttribute ( name , value ) ; }
Filter the setting of authentication related attributes . If one of HttpContext . AUTHENTICATION_TYPE or HTTPContext . REMOTE_USER set the corresponding values in original request .
40,852
private void handleAuthenticationType ( final Object authenticationType ) { if ( request != null ) { if ( authenticationType != null ) { if ( ! ( authenticationType instanceof String ) ) { final String message = "Attribute " + HttpContext . AUTHENTICATION_TYPE + " expected to be a String but was an [" + authenticationT...
Handles setting of authentication type attribute .
40,853
private void handleRemoteUser ( final Object remoteUser ) { if ( request != null ) { Principal userPrincipal = null ; if ( remoteUser != null ) { if ( ! ( remoteUser instanceof String ) ) { final String message = "Attribute " + HttpContext . REMOTE_USER + " expected to be a String but was an [" + remoteUser . getClass ...
Handles setting of remote user attribute .
40,854
public Compiler createCompiler ( ) { if ( jspCompiler != null ) { return jspCompiler ; } jspCompiler = null ; if ( options . getCompilerClassName ( ) != null ) { jspCompiler = createCompiler ( options . getCompilerClassName ( ) ) ; } else { if ( options . getCompiler ( ) == null ) { jspCompiler = createCompiler ( "org....
Create a Compiler object based on some init param data . This is not done yet . Right now we re just hardcoding the actual compilers that are created .
40,855
public String resolveRelativeUri ( String uri ) { if ( uri . startsWith ( "/" ) || uri . startsWith ( File . separator ) ) { return uri ; } else { return baseURI + uri ; } }
Get the full value of a URI relative to this compilations context uses current file as the base .
40,856
public String getRealPath ( String path ) { if ( context != null ) { return context . getRealPath ( path ) ; } return path ; }
Gets the actual path of a URI relative to the context of the compilation .
40,857
public String getServletPackageName ( ) { if ( isTagFile ( ) ) { String className = tagInfo . getTagClassName ( ) ; int lastIndex = className . lastIndexOf ( '.' ) ; String pkgName = "" ; if ( lastIndex != - 1 ) { pkgName = className . substring ( 0 , lastIndex ) ; } return pkgName ; } else { String dPackageName = getD...
Package name for the generated class is make up of the base package name which is user settable and the derived package name . The derived package name directly mirrors the file hierarchy of the JSP page .
40,858
public void visit ( final WebAppServlet webAppServlet ) { NullArgumentException . validateNotNull ( webAppServlet , "Web app servlet" ) ; final String [ ] urlPatterns = webAppServlet . getAliases ( ) ; if ( urlPatterns == null || urlPatterns . length == 0 ) { LOG . warn ( "Servlet [" + webAppServlet + "] does not have ...
Registers servlets with web container .
40,859
public void visit ( final WebAppFilter webAppFilter ) { NullArgumentException . validateNotNull ( webAppFilter , "Web app filter" ) ; LOG . debug ( "registering filter: {}" , webAppFilter ) ; final String [ ] urlPatterns = webAppFilter . getUrlPatterns ( ) ; final String [ ] servletNames = webAppFilter . getServletName...
Registers filters with web container .
40,860
public void visit ( final WebAppListener webAppListener ) { NullArgumentException . validateNotNull ( webAppListener , "Web app listener" ) ; try { final EventListener listener = RegisterWebAppVisitorHS . newInstance ( EventListener . class , bundleClassLoader , webAppListener . getListenerClass ( ) ) ; webAppListener ...
Registers listeners with web container .
40,861
public void visit ( final WebAppErrorPage webAppErrorPage ) { NullArgumentException . validateNotNull ( webAppErrorPage , "Web app error page" ) ; try { webContainer . registerErrorPage ( webAppErrorPage . getError ( ) , webAppErrorPage . getLocation ( ) , httpContext ) ; } catch ( Exception ignore ) { LOG . error ( RE...
Registers error pages with web container .
40,862
private static void parseContextParams ( final ParamValueType contextParam , final WebApp webApp ) { final WebAppInitParam initParam = new WebAppInitParam ( ) ; initParam . setParamName ( contextParam . getParamName ( ) . getValue ( ) ) ; initParam . setParamValue ( contextParam . getParamValue ( ) . getValue ( ) ) ; w...
Parses context params out of web . xml .
40,863
private static void parseSessionConfig ( final SessionConfigType sessionConfigType , final WebApp webApp ) { if ( sessionConfigType . getSessionTimeout ( ) != null ) { webApp . setSessionTimeout ( sessionConfigType . getSessionTimeout ( ) . getValue ( ) . toString ( ) ) ; } if ( sessionConfigType . getCookieConfig ( ) ...
Parses session config out of web . xml .
40,864
private static void parseServlets ( final ServletType servletType , final WebApp webApp ) { final WebAppServlet servlet = new WebAppServlet ( ) ; servlet . setServletName ( servletType . getServletName ( ) . getValue ( ) ) ; if ( servletType . getServletClass ( ) != null ) { servlet . setServletClassName ( servletType ...
Parses servlets and servlet mappings out of web . xml .
40,865
private static void parseFilters ( final FilterType filterType , final WebApp webApp ) { final WebAppFilter filter = new WebAppFilter ( ) ; if ( filterType . getFilterName ( ) != null ) { filter . setFilterName ( filterType . getFilterName ( ) . getValue ( ) ) ; } if ( filterType . getFilterClass ( ) != null ) { filter...
Parses filters and filter mappings out of web . xml .
40,866
private static void parseErrorPages ( final ErrorPageType errorPageType , final WebApp webApp ) { final WebAppErrorPage errorPage = new WebAppErrorPage ( ) ; if ( errorPageType . getErrorCode ( ) != null ) { errorPage . setErrorCode ( errorPageType . getErrorCode ( ) . getValue ( ) . toString ( ) ) ; } if ( errorPageTy...
Parses error pages out of web . xml .
40,867
private static void parseWelcomeFiles ( final WelcomeFileListType welcomeFileList , final WebApp webApp ) { if ( welcomeFileList != null && welcomeFileList . getWelcomeFile ( ) != null && ! welcomeFileList . getWelcomeFile ( ) . isEmpty ( ) ) { welcomeFileList . getWelcomeFile ( ) . forEach ( webApp :: addWelcomeFile )...
Parses welcome files out of web . xml .
40,868
private static void parseMimeMappings ( final MimeMappingType mimeMappingType , final WebApp webApp ) { final WebAppMimeMapping mimeMapping = new WebAppMimeMapping ( ) ; mimeMapping . setExtension ( mimeMappingType . getExtension ( ) . getValue ( ) ) ; mimeMapping . setMimeType ( mimeMappingType . getMimeType ( ) . get...
Parses mime mappings out of web . xml .
40,869
private static String getTextContent ( final Element element ) { if ( element != null ) { String content = element . getTextContent ( ) ; if ( content != null ) { content = content . trim ( ) ; } return content ; } return null ; }
Returns the text content of an element or null if the element is null .
40,870
public static int parseInt ( byte [ ] b , int offset , int length , int base ) { int value = 0 ; if ( length < 0 ) { length = b . length - offset ; } for ( int i = 0 ; i < length ; i ++ ) { char c = ( char ) ( _0XFF & b [ offset + i ] ) ; int digit = c - '0' ; if ( digit < 0 || digit >= base || digit >= TEN ) { digit =...
Parse an int from a byte array of ascii characters . Negative numbers are not handled .
40,871
public HttpService addingService ( final ServiceReference < HttpService > serviceReference ) { LOG . debug ( "HttpService available {}" , serviceReference ) ; lock . lock ( ) ; HttpService addedHttpService = null ; try { if ( httpService != null ) { return super . addingService ( serviceReference ) ; } httpService = su...
Gets the service if one is not already available and notify listeners .
40,872
public void removedService ( final ServiceReference < HttpService > serviceReference , final HttpService service ) { LOG . debug ( "HttpService removed {}" , serviceReference ) ; lock . lock ( ) ; HttpService removedHttpService = null ; try { if ( context != null ) { super . removedService ( serviceReference , service ...
Notify listeners that the http service became unavailable . Then looks for another one and if available notifies listeners .
40,873
public void start ( BundleContext bc ) throws Exception { int counter = 0 ; boolean started = false ; while ( ! started ) { webContainerRef = bc . getServiceReference ( WebContainer . class ) ; started = webContainerRef != null ; if ( started ) { final WebContainer webContainer = ( WebContainer ) bc . getService ( webC...
Called when the OSGi framework starts our bundle .
40,874
private static void printAttribute ( final PrintWriter writer , final HttpServletRequest request , final String attribute ) { writer . println ( "<tr><td>" + attribute + "</td><td>" + ( request . getAttribute ( attribute ) != null ? request . getAttribute ( attribute ) : "" ) + "</td></tr>" ) ; }
Prints an error request attribute .
40,875
public Enumeration < URL > getResources ( String name ) throws IOException { return bundleClassLoader . getResources ( name ) ; }
Delegate to bundle class loader .
40,876
public List < URL > scanBundlesInClassSpace ( String directory , String filePattern , boolean recursive ) { Set < Bundle > bundlesInClassSpace = ClassPathUtil . getBundlesInClassSpace ( bundleClassLoader . getBundle ( ) , new HashSet < > ( ) ) ; List < URL > matching = new ArrayList < > ( ) ; for ( Bundle bundle : bund...
Scans the imported and required bundles for matching resources . Can be used to obtain references to TLD files XML definition files etc .
40,877
public BindingInfo bindingInfo ( String socketBindingName ) { SocketBinding sb = socketBinding ( socketBindingName ) ; if ( sb == null ) { throw new IllegalArgumentException ( "Can't find socket binding with name \"" + socketBindingName + "\"" ) ; } Interface iface = interfaceRef ( sb . getInterfaceRef ( ) ) ; if ( ifa...
Returns valid information about interfaces + port to listen on
40,878
public void configureWelcomeFiles ( List < String > welcomePages ) { this . welcomePages = welcomePages ; ( ( ResourceHandler ) handler ) . setWelcomeFiles ( ) ; ( ( ResourceHandler ) handler ) . addWelcomeFiles ( welcomePages . toArray ( new String [ welcomePages . size ( ) ] ) ) ; }
Reconfigures default welcome pages with ones provided externally
40,879
public static String getStringProperty ( final ServiceReference < ? > serviceReference , final String key ) { NullArgumentException . validateNotNull ( serviceReference , "Service reference" ) ; NullArgumentException . validateNotEmpty ( key , true , "Property key" ) ; Object value = serviceReference . getProperty ( ke...
Returns a property as String .
40,880
public static Integer getIntegerProperty ( final ServiceReference < ? > serviceReference , final String key ) { NullArgumentException . validateNotNull ( serviceReference , "Service reference" ) ; NullArgumentException . validateNotEmpty ( key , true , "Property key" ) ; final Object value = serviceReference . getPrope...
Returns a property as Integer .
40,881
public static Map < String , Object > getSubsetStartingWith ( final ServiceReference < ? > serviceReference , final String prefix ) { final Map < String , Object > subset = new HashMap < > ( ) ; for ( String key : serviceReference . getPropertyKeys ( ) ) { if ( key != null && key . startsWith ( prefix ) && key . trim (...
Returns the subset of properties that start with the prefix . The returned dictionary will have as keys the original key without the prefix .
40,882
public static String extractHttpContextId ( final ServiceReference < ? > serviceReference ) { String httpContextId = getStringProperty ( serviceReference , ExtenderConstants . PROPERTY_HTTP_CONTEXT_ID ) ; if ( httpContextId == null ) { String httpContextSelector = getStringProperty ( serviceReference , HttpWhiteboardCo...
Utility method to extract the httpContextID from the service reference . This can either be included with the old Pax - Web style or the new OSGi R6 Whiteboard style .
40,883
public static Boolean extractSharedHttpContext ( final ServiceReference < ? > serviceReference ) { Boolean sharedHttpContext = Boolean . parseBoolean ( ( String ) serviceReference . getProperty ( ExtenderConstants . PROPERTY_HTTP_CONTEXT_SHARED ) ) ; if ( serviceReference . getProperty ( HttpWhiteboardConstants . HTTP_...
Utility method to extract the shared state of the HttpContext
40,884
public void addInitParam ( final WebAppInitParam param ) { NullArgumentException . validateNotNull ( param , "Init param" ) ; NullArgumentException . validateNotNull ( param . getParamName ( ) , "Init param name" ) ; NullArgumentException . validateNotNull ( param . getParamValue ( ) , "Init param value" ) ; initParams...
Add a init param for filter .
40,885
public Extension createExtension ( final Bundle bundle ) { NullArgumentException . validateNotNull ( bundle , "Bundle" ) ; if ( bundle . getState ( ) != Bundle . ACTIVE ) { LOG . debug ( "Bundle is not in ACTIVE state, ignore it!" ) ; return null ; } Boolean canSeeServletClass = canSeeClass ( bundle , Servlet . class )...
Parse the web app and create the extension that will be managed by the extender .
40,886
public static String normalizeResourcePath ( final String path ) { if ( path == null ) { return null ; } String normalizedPath = replaceSlashes ( path . trim ( ) ) ; if ( normalizedPath . startsWith ( "/" ) && normalizedPath . length ( ) > 1 ) { normalizedPath = normalizedPath . substring ( 1 ) ; } return normalizedPat...
Normalize the path for accesing a resource meaning that will replace consecutive slashes and will remove a leading slash if present .
40,887
public static String [ ] normalizePatterns ( final String [ ] urlPatterns ) { String [ ] normalized = null ; if ( urlPatterns != null ) { normalized = new String [ urlPatterns . length ] ; for ( int i = 0 ; i < urlPatterns . length ; i ++ ) { normalized [ i ] = normalizePattern ( urlPatterns [ i ] ) ; } } return normal...
Normalize an array of patterns .
40,888
public static URL [ ] getClassPathJars ( final Bundle bundle ) { final List < URL > urls = new ArrayList < > ( ) ; final String bundleClasspath = ( String ) bundle . getHeaders ( ) . get ( "Bundle-ClassPath" ) ; if ( bundleClasspath != null ) { String [ ] segments = bundleClasspath . split ( "," ) ; for ( String segmen...
Returns a list of urls to jars that composes the Bundle - ClassPath .
40,889
public static Set < Bundle > getBundlesInClassSpace ( Bundle bundle , Set < Bundle > bundleSet ) { return getBundlesInClassSpace ( bundle . getBundleContext ( ) , bundle , bundleSet ) ; }
Gets a list of bundles that are imported or required by this bundle .
40,890
public void addServletModel ( final ServletModel model ) throws NamespaceException , ServletException { servletLock . writeLock ( ) . lock ( ) ; try { associateBundle ( model . getContextModel ( ) . getVirtualHosts ( ) , model . getContextModel ( ) . getBundle ( ) ) ; for ( String virtualHost : resolveVirtualHosts ( mo...
Registers a servlet model .
40,891
public void removeServletModel ( final ServletModel model ) { servletLock . writeLock ( ) . lock ( ) ; try { deassociateBundle ( model . getContextModel ( ) . getVirtualHosts ( ) , model . getContextModel ( ) . getBundle ( ) ) ; for ( String virtualHost : resolveVirtualHosts ( model ) ) { if ( model . getAlias ( ) != n...
Unregisters a servlet model .
40,892
public void addFilterModel ( final FilterModel model ) { if ( model . getUrlPatterns ( ) != null ) { try { filterLock . writeLock ( ) . lock ( ) ; associateBundle ( model . getContextModel ( ) . getVirtualHosts ( ) , model . getContextModel ( ) . getBundle ( ) ) ; for ( String virtualHost : resolveVirtualHosts ( model ...
Registers a filter model .
40,893
public void removeFilterModel ( final FilterModel model ) { if ( model . getUrlPatterns ( ) != null ) { try { deassociateBundle ( model . getContextModel ( ) . getVirtualHosts ( ) , model . getContextModel ( ) . getBundle ( ) ) ; filterLock . writeLock ( ) . lock ( ) ; for ( String virtualHost : resolveVirtualHosts ( m...
Unregister a filter model .
40,894
public void associateHttpContext ( final WebContainerContext httpContext , final Bundle bundle , final boolean allowReAsssociation ) { List < String > virtualHosts = resolveVirtualHosts ( bundle ) ; for ( String virtualHost : virtualHosts ) { ConcurrentMap < WebContainerContext , Bundle > virtualHostHttpContexts = http...
Associates a http context with a bundle if the http service is not already associated to another bundle . This is done in order to prevent sharing http context between bundles . The implementation is not 100% correct as it can be that at a certain moment in time when this method is called another thread is processing a...
40,895
protected final ServiceTracker < T , W > create ( String filter ) { try { return new ServiceTracker < > ( bundleContext , bundleContext . createFilter ( filter ) , this ) ; } catch ( InvalidSyntaxException e ) { throw new IllegalArgumentException ( "Unexpected InvalidSyntaxException: " + e . getMessage ( ) ) ; } }
Creates a new tracker that tracks services by generic filter
40,896
public void visit ( final WebApp webApp ) { NullArgumentException . validateNotNull ( webApp , "Web app" ) ; bundleClassLoader = new BundleClassLoader ( webApp . getBundle ( ) ) ; httpContext = new WebAppHttpContext ( httpService . createDefaultHttpContext ( ) , webApp . getRootPath ( ) , webApp . getBundle ( ) , webAp...
Creates a default context that will be used for all following registrations and registers a resource for root of war .
40,897
public void visit ( final WebAppServlet webAppServlet ) { NullArgumentException . validateNotNull ( webAppServlet , "Web app servlet" ) ; final String [ ] aliases = webAppServlet . getAliases ( ) ; if ( aliases != null && aliases . length > 0 ) { for ( final String alias : aliases ) { try { final Servlet servlet = newI...
Registers servlets with http context .
40,898
public static < T > T newInstance ( final Class < T > clazz , final ClassLoader classLoader , final String className ) throws ClassNotFoundException , IllegalAccessException , InstantiationException { return loadClass ( clazz , classLoader , className ) . newInstance ( ) ; }
Creates an instance of a class from class name .
40,899
@ SuppressWarnings ( "unchecked" ) public static < T > Class < ? extends T > loadClass ( final Class < T > clazz , final ClassLoader classLoader , final String className ) throws ClassNotFoundException , IllegalAccessException { NullArgumentException . validateNotNull ( clazz , "Class" ) ; NullArgumentException . valid...
Load a class from class name .