idx int64 0 165k | question stringlengths 73 4.15k | target stringlengths 5 918 | len_question int64 21 890 | len_target int64 3 255 |
|---|---|---|---|---|
22,200 | public static String getFullPath ( String filename ) { if ( filename == null ) { return null ; } int index = indexOfLastSeparator ( filename ) ; if ( index < 0 ) { return StringUtils . EMPTY ; } return filename . substring ( 0 , index ) ; } | Gets the path from a full filename . | 63 | 9 |
22,201 | public static boolean isValidFileExtension ( String filename , String allowedFileExtensions , String deniedFileExtensions ) { if ( filename == null ) { return false ; } String ext = getExtension ( filename ) . toLowerCase ( ) ; if ( allowedFileExtensions != null && ! allowedFileExtensions . isEmpty ( ) ) { if ( ext . length ( ) == 0 ) { return false ; } StringTokenizer st = new StringTokenizer ( allowedFileExtensions . toLowerCase ( ) , EXTENSIONS_SEPARATORS ) ; while ( st . hasMoreTokens ( ) ) { String ext2 = st . nextToken ( ) ; if ( ext . equals ( ext2 ) ) { return true ; } } return false ; } if ( deniedFileExtensions != null && ! deniedFileExtensions . isEmpty ( ) ) { if ( ext . length ( ) == 0 ) { return true ; } StringTokenizer st = new StringTokenizer ( deniedFileExtensions . toLowerCase ( ) , EXTENSIONS_SEPARATORS ) ; while ( st . hasMoreTokens ( ) ) { String ext2 = st . nextToken ( ) ; if ( ext . equals ( ext2 ) ) { return false ; } } return true ; } return true ; } | Checks whether the extension of the filename is valid . The extension check is case - sensitive on all platforms . | 274 | 22 |
22,202 | public static File getUniqueFile ( File srcFile , char extSeparator ) throws IOException { if ( srcFile == null ) { throw new IllegalArgumentException ( "srcFile must not be null" ) ; } String path = getFullPath ( srcFile . getCanonicalPath ( ) ) ; String name = removeExtension ( srcFile . getName ( ) ) ; String ext = getExtension ( srcFile . getName ( ) ) ; String newName ; if ( ext != null && ! ext . isEmpty ( ) ) { newName = name + extSeparator + ext ; } else { newName = name ; } int count = 0 ; File destFile = new File ( path , newName ) ; while ( destFile . exists ( ) ) { count ++ ; if ( ext != null && ! ext . isEmpty ( ) ) { newName = name + "-" + count + extSeparator + ext ; } else { newName = name + "-" + count ; } destFile = new File ( path , newName ) ; } return ( count == 0 ? srcFile : destFile ) ; } | Returns a file name that does not overlap in the specified directory . If a duplicate file name exists it is returned by appending a number after the file name . | 242 | 32 |
22,203 | private void execute ( Command command , CommandLineParser lineParser ) { ConsoleWrapper wrappedConsole = new ConsoleWrapper ( console ) ; PrintWriter outputWriter = null ; try { ParsedOptions options = lineParser . parseOptions ( command . getOptions ( ) ) ; outputWriter = OutputRedirection . determineOutputWriter ( lineParser . getRedirectionList ( ) , wrappedConsole ) ; wrappedConsole . setWriter ( outputWriter ) ; command . execute ( options , wrappedConsole ) ; } catch ( ConsoleTerminatedException e ) { throw e ; } catch ( OptionParserException e ) { wrappedConsole . writeError ( e . getMessage ( ) ) ; command . printHelp ( wrappedConsole ) ; } catch ( Exception e ) { log . error ( "Failed to execute command: " + lineParser . getCommandLine ( ) , e ) ; } finally { if ( outputWriter != null ) { outputWriter . close ( ) ; } } } | Executes a command built into Aspectran Shell . | 199 | 11 |
22,204 | private void execute ( TransletCommandLine transletCommandLine ) { if ( transletCommandLine . getRequestName ( ) != null ) { try { service . translate ( transletCommandLine , console ) ; } catch ( TransletNotFoundException e ) { console . writeError ( "No command or translet mapped to '" + e . getTransletName ( ) + "'" ) ; } catch ( ConsoleTerminatedException e ) { throw e ; } catch ( Exception e ) { log . error ( "Failed to execute command: " + transletCommandLine . getLineParser ( ) . getCommandLine ( ) , e ) ; } } else { console . writeError ( "No command or translet mapped to '" + transletCommandLine . getLineParser ( ) . getCommandLine ( ) + "'" ) ; } } | Executes a Translet defined in Aspectran . | 180 | 11 |
22,205 | public void setBeanClass ( Class < ? > beanClass ) { this . beanClass = beanClass ; this . className = beanClass . getName ( ) ; this . factoryBean = FactoryBean . class . isAssignableFrom ( beanClass ) ; this . disposableBean = DisposableBean . class . isAssignableFrom ( beanClass ) ; this . initializableBean = InitializableBean . class . isAssignableFrom ( beanClass ) ; this . initializableTransletBean = InitializableTransletBean . class . isAssignableFrom ( beanClass ) ; } | Sets the bean class . | 135 | 6 |
22,206 | public ItemRule newConstructorArgumentItemRule ( ) { ItemRule itemRule = new ItemRule ( ) ; itemRule . setAutoNamed ( true ) ; addConstructorArgumentItemRule ( itemRule ) ; return itemRule ; } | Adds a new constructor argument item rule and returns it . | 52 | 11 |
22,207 | public void addConstructorArgumentItemRule ( ItemRule constructorArgumentItemRule ) { if ( constructorArgumentItemRuleMap == null ) { constructorArgumentItemRuleMap = new ItemRuleMap ( ) ; } constructorArgumentItemRuleMap . putItemRule ( constructorArgumentItemRule ) ; } | Adds the constructor argument item rule . | 65 | 7 |
22,208 | public ItemRule newPropertyItemRule ( String propertyName ) { ItemRule itemRule = new ItemRule ( ) ; itemRule . setName ( propertyName ) ; addPropertyItemRule ( itemRule ) ; return itemRule ; } | Adds a new property rule with the specified name and returns it . | 48 | 13 |
22,209 | public void addPropertyItemRule ( ItemRule propertyItemRule ) { if ( propertyItemRuleMap == null ) { propertyItemRuleMap = new ItemRuleMap ( ) ; } propertyItemRuleMap . putItemRule ( propertyItemRule ) ; } | Adds the property item rule . | 52 | 6 |
22,210 | public void speak ( String text ) { if ( voice == null ) { throw new IllegalStateException ( "Cannot find a voice named " + voiceName ) ; } voice . speak ( text ) ; } | Synthesizes speech of the given text and plays immediately . | 43 | 13 |
22,211 | protected ActivityContext createActivityContext ( ContextRuleAssistant assistant ) throws BeanReferenceException , IllegalRuleException { initContextEnvironment ( assistant ) ; AspectranActivityContext activityContext = new AspectranActivityContext ( assistant . getContextEnvironment ( ) ) ; AspectRuleRegistry aspectRuleRegistry = assistant . getAspectRuleRegistry ( ) ; BeanRuleRegistry beanRuleRegistry = assistant . getBeanRuleRegistry ( ) ; beanRuleRegistry . postProcess ( assistant ) ; BeanReferenceInspector beanReferenceInspector = assistant . getBeanReferenceInspector ( ) ; beanReferenceInspector . inspect ( beanRuleRegistry ) ; initAspectRuleRegistry ( assistant ) ; BeanProxifierType beanProxifierType = BeanProxifierType . resolve ( ( String ) assistant . getSetting ( DefaultSettingType . BEAN_PROXIFIER ) ) ; ContextBeanRegistry contextBeanRegistry = new ContextBeanRegistry ( activityContext , beanRuleRegistry , beanProxifierType ) ; TemplateRuleRegistry templateRuleRegistry = assistant . getTemplateRuleRegistry ( ) ; ContextTemplateRenderer contextTemplateRenderer = new ContextTemplateRenderer ( activityContext , templateRuleRegistry ) ; ScheduleRuleRegistry scheduleRuleRegistry = assistant . getScheduleRuleRegistry ( ) ; TransletRuleRegistry transletRuleRegistry = assistant . getTransletRuleRegistry ( ) ; activityContext . setAspectRuleRegistry ( aspectRuleRegistry ) ; activityContext . setContextBeanRegistry ( contextBeanRegistry ) ; activityContext . setScheduleRuleRegistry ( scheduleRuleRegistry ) ; activityContext . setContextTemplateRenderer ( contextTemplateRenderer ) ; activityContext . setTransletRuleRegistry ( transletRuleRegistry ) ; activityContext . setDescription ( assistant . getAssistantLocal ( ) . getDescription ( ) ) ; return activityContext ; } | Returns a new instance of ActivityContext . | 421 | 8 |
22,212 | private void initAspectRuleRegistry ( ContextRuleAssistant assistant ) { AspectRuleRegistry aspectRuleRegistry = assistant . getAspectRuleRegistry ( ) ; BeanRuleRegistry beanRuleRegistry = assistant . getBeanRuleRegistry ( ) ; TransletRuleRegistry transletRuleRegistry = assistant . getTransletRuleRegistry ( ) ; AspectAdviceRulePostRegister sessionScopeAspectAdviceRulePostRegister = new AspectAdviceRulePostRegister ( ) ; for ( AspectRule aspectRule : aspectRuleRegistry . getAspectRules ( ) ) { PointcutRule pointcutRule = aspectRule . getPointcutRule ( ) ; if ( pointcutRule != null ) { Pointcut pointcut = PointcutFactory . createPointcut ( pointcutRule ) ; aspectRule . setPointcut ( pointcut ) ; } if ( aspectRule . getJoinpointTargetType ( ) == JoinpointTargetType . SESSION ) { sessionScopeAspectAdviceRulePostRegister . register ( aspectRule ) ; } } AspectAdviceRulePreRegister preRegister = new AspectAdviceRulePreRegister ( aspectRuleRegistry ) ; preRegister . register ( beanRuleRegistry ) ; preRegister . register ( transletRuleRegistry ) ; // check invalid pointcut pattern boolean pointcutPatternVerifiable = assistant . isPointcutPatternVerifiable ( ) ; if ( pointcutPatternVerifiable || log . isDebugEnabled ( ) ) { int invalidPointcutPatterns = 0 ; for ( AspectRule aspectRule : aspectRuleRegistry . getAspectRules ( ) ) { Pointcut pointcut = aspectRule . getPointcut ( ) ; if ( pointcut != null ) { List < PointcutPatternRule > pointcutPatternRuleList = pointcut . getPointcutPatternRuleList ( ) ; if ( pointcutPatternRuleList != null ) { for ( PointcutPatternRule ppr : pointcutPatternRuleList ) { if ( ppr . getBeanIdPattern ( ) != null && ppr . getMatchedBeanCount ( ) == 0 ) { invalidPointcutPatterns ++ ; String msg = "No beans matching to '" + ppr . getBeanIdPattern ( ) + "'; aspectRule " + aspectRule ; if ( pointcutPatternVerifiable ) { log . error ( msg ) ; } else { log . debug ( msg ) ; } } if ( ppr . getClassNamePattern ( ) != null && ppr . getMatchedClassCount ( ) == 0 ) { invalidPointcutPatterns ++ ; String msg = "No beans matching to '@class:" + ppr . getClassNamePattern ( ) + "'; aspectRule " + aspectRule ; if ( pointcutPatternVerifiable ) { log . error ( msg ) ; } else { log . debug ( msg ) ; } } if ( ppr . getMethodNamePattern ( ) != null && ppr . getMatchedMethodCount ( ) == 0 ) { invalidPointcutPatterns ++ ; String msg = "No beans have methods matching to '^" + ppr . getMethodNamePattern ( ) + "'; aspectRule " + aspectRule ; if ( pointcutPatternVerifiable ) { log . error ( msg ) ; } else { log . debug ( msg ) ; } } } } } } if ( invalidPointcutPatterns > 0 ) { String msg = "Invalid pointcut detected: " + invalidPointcutPatterns + "; Please check the logs for more information" ; if ( pointcutPatternVerifiable ) { log . error ( msg ) ; throw new InvalidPointcutPatternException ( msg ) ; } else { log . debug ( msg ) ; } } } AspectAdviceRuleRegistry sessionScopeAarr = sessionScopeAspectAdviceRulePostRegister . getAspectAdviceRuleRegistry ( ) ; if ( sessionScopeAarr != null ) { aspectRuleRegistry . setSessionAspectAdviceRuleRegistry ( sessionScopeAarr ) ; } } | Initialize the aspect rule registry . | 852 | 7 |
22,213 | public String getPath ( Activity activity ) { if ( pathTokens != null && pathTokens . length > 0 ) { TokenEvaluator evaluator = new TokenExpression ( activity ) ; return evaluator . evaluateAsString ( pathTokens ) ; } else { return path ; } } | Gets the redirect path . | 62 | 6 |
22,214 | public void setPath ( String path ) { this . path = path ; List < Token > tokens = Tokenizer . tokenize ( path , true ) ; int tokenCount = 0 ; for ( Token t : tokens ) { if ( t . getType ( ) != TokenType . TEXT ) { tokenCount ++ ; } } if ( tokenCount > 0 ) { this . pathTokens = tokens . toArray ( new Token [ 0 ] ) ; } else { this . pathTokens = null ; } } | Sets the redirect path . | 104 | 6 |
22,215 | public ItemRule newParameterItemRule ( String parameterName ) { ItemRule itemRule = new ItemRule ( ) ; itemRule . setName ( parameterName ) ; addParameterItemRule ( itemRule ) ; return itemRule ; } | Adds a new parameter rule with the specified name and returns it . | 48 | 13 |
22,216 | public void addParameterItemRule ( ItemRule parameterItemRule ) { if ( parameterItemRuleMap == null ) { parameterItemRuleMap = new ItemRuleMap ( ) ; } parameterItemRuleMap . putItemRule ( parameterItemRule ) ; } | Adds the parameter item rule . | 52 | 6 |
22,217 | public void setParameters ( Map < String , String > parameters ) { if ( parameters == null || parameters . isEmpty ( ) ) { this . parameterItemRuleMap = null ; } else { ItemRuleMap itemRuleMap = new ItemRuleMap ( ) ; for ( Map . Entry < String , String > entry : parameters . entrySet ( ) ) { ItemRule ir = new ItemRule ( ) ; ir . setTokenize ( false ) ; ir . setName ( entry . getKey ( ) ) ; ir . setValue ( entry . getValue ( ) ) ; itemRuleMap . putItemRule ( ir ) ; } this . parameterItemRuleMap = itemRuleMap ; } } | Sets the parameter map . | 144 | 6 |
22,218 | protected String formatMessage ( String msg , Object [ ] args , Locale locale ) { if ( msg == null || ( ! this . alwaysUseMessageFormat && ( args == null || args . length == 0 ) ) ) { return msg ; } MessageFormat messageFormat = null ; synchronized ( this . messageFormatsPerMessage ) { Map < Locale , MessageFormat > messageFormatsPerLocale = this . messageFormatsPerMessage . get ( msg ) ; if ( messageFormatsPerLocale != null ) { messageFormat = messageFormatsPerLocale . get ( locale ) ; } else { messageFormatsPerLocale = new HashMap <> ( ) ; this . messageFormatsPerMessage . put ( msg , messageFormatsPerLocale ) ; } if ( messageFormat == null ) { try { messageFormat = createMessageFormat ( msg , locale ) ; } catch ( IllegalArgumentException ex ) { // invalid message format - probably not intended for formatting, // rather using a message structure with no arguments involved if ( this . alwaysUseMessageFormat ) { throw ex ; } // silently proceed with raw message if format not enforced messageFormat = INVALID_MESSAGE_FORMAT ; } messageFormatsPerLocale . put ( locale , messageFormat ) ; } } if ( messageFormat == INVALID_MESSAGE_FORMAT ) { return msg ; } synchronized ( messageFormat ) { return messageFormat . format ( args ) ; } } | Format the given message String using cached MessageFormats . By default invoked for passed - in default messages to resolve any argument placeholders found in them . | 312 | 30 |
22,219 | protected MessageFormat createMessageFormat ( String msg , Locale locale ) { return new MessageFormat ( ( msg != null ? msg : "" ) , locale ) ; } | Create a MessageFormat for the given message and Locale . | 34 | 12 |
22,220 | public static < T > T createInstance ( Class < T > cls ) { Constructor < T > ctor ; try { ctor = findConstructor ( cls ) ; } catch ( NoSuchMethodException e ) { throw new IllegalArgumentException ( "Class " + cls . getName ( ) + " has no default (no arg) constructor" ) ; } try { return ctor . newInstance ( ) ; } catch ( Exception e ) { ExceptionUtils . unwrapAndThrowAsIAE ( e , "Unable to instantiate class " + cls . getName ( ) + ": " + e . getMessage ( ) ) ; throw new IllegalArgumentException ( e ) ; } } | Method that can be called to try to create an instantiate of specified type . Instantiation is done using default no - argument constructor . | 153 | 27 |
22,221 | public static < T > T createInstance ( Class < T > cls , Object ... args ) { Class < ? > [ ] argTypes = new Class < ? > [ args . length ] ; for ( int i = 0 ; i < args . length ; i ++ ) { argTypes [ i ] = args [ i ] . getClass ( ) ; } return createInstance ( cls , args , argTypes ) ; } | Method that can be called to try to create an instantiate of specified type . | 89 | 16 |
22,222 | public static < T > Constructor < T > findConstructor ( Class < T > cls , Class < ? > ... argTypes ) throws NoSuchMethodException { Constructor < T > ctor ; try { ctor = cls . getDeclaredConstructor ( argTypes ) ; } catch ( NoSuchMethodException e ) { throw e ; } catch ( Exception e ) { throw new IllegalArgumentException ( "Unable to find constructor of class " + cls . getName ( ) + ", problem: " + e . getMessage ( ) , ExceptionUtils . getRootCause ( e ) ) ; } // must be public if ( ! Modifier . isPublic ( ctor . getModifiers ( ) ) ) { throw new IllegalArgumentException ( "Constructor for " + cls . getName ( ) + " is not accessible (non-public?): not allowed to try modify access via Reflection: can not instantiate type" ) ; } return ctor ; } | Obtain an accessible constructor for the given class and parameters . | 210 | 12 |
22,223 | private static boolean isLoadable ( Class < ? > clazz , ClassLoader classLoader ) { try { return ( clazz == classLoader . loadClass ( clazz . getName ( ) ) ) ; // Else: different class with same name found } catch ( ClassNotFoundException ex ) { // No corresponding class found at all return false ; } } | Check whether the given class is loadable in the given ClassLoader . | 74 | 14 |
22,224 | public static Object invokeExactStaticMethod ( Class < ? > objectClass , String methodName ) throws NoSuchMethodException , IllegalAccessException , InvocationTargetException { return invokeExactStaticMethod ( objectClass , methodName , EMPTY_OBJECT_ARRAY , EMPTY_CLASS_PARAMETERS ) ; } | Invoke a static method that has no parameters . | 69 | 10 |
22,225 | private RequestContext createRequestContext ( final HttpServletRequest req ) { return new RequestContext ( ) { @ Override public String getCharacterEncoding ( ) { return req . getCharacterEncoding ( ) ; } @ Override public String getContentType ( ) { return req . getContentType ( ) ; } @ Override @ Deprecated public int getContentLength ( ) { return req . getContentLength ( ) ; } @ Override public InputStream getInputStream ( ) throws IOException { return req . getInputStream ( ) ; } } ; } | Creates a RequestContext needed by Jakarta Commons Upload . | 119 | 11 |
22,226 | public boolean matches ( CharSequence input ) { separatorCount = - 1 ; separatorIndex = 0 ; if ( input == null ) { this . input = null ; separatorFlags = null ; return false ; } this . input = input ; separatorFlags = new int [ input . length ( ) ] ; boolean result = matches ( pattern , input , separatorFlags ) ; if ( result ) { for ( int i = separatorFlags . length - 1 ; i >= 0 ; i -- ) { if ( separatorFlags [ i ] > 0 ) { separatorCount = separatorFlags [ i ] ; break ; } } } return result ; } | Checks whether a string matches a given wildcard pattern . | 138 | 12 |
22,227 | private boolean isProfileActive ( String profile ) { validateProfile ( profile ) ; Set < String > currentActiveProfiles = doGetActiveProfiles ( ) ; return ( currentActiveProfiles . contains ( profile ) || ( currentActiveProfiles . isEmpty ( ) && doGetDefaultProfiles ( ) . contains ( profile ) ) ) ; } | Returns whether the given profile is active or if active profiles are empty whether the profile should be active by default . | 72 | 22 |
22,228 | protected void indent ( ) throws IOException { if ( prettyPrint ) { for ( int i = 0 ; i < indentDepth ; i ++ ) { writer . write ( indentString ) ; } } } | Write a tab character to a character stream . | 42 | 9 |
22,229 | public JsonWriter writeName ( String name ) throws IOException { indent ( ) ; writer . write ( escape ( name ) ) ; writer . write ( ":" ) ; if ( prettyPrint ) { writer . write ( " " ) ; } willWriteValue = true ; return this ; } | Writes a key name to a character stream . | 61 | 10 |
22,230 | public JsonWriter openSquareBracket ( ) throws IOException { if ( ! willWriteValue ) { indent ( ) ; } writer . write ( "[" ) ; nextLine ( ) ; indentDepth ++ ; willWriteValue = false ; return this ; } | Open a single square bracket . | 54 | 6 |
22,231 | public static String stringify ( Object object , boolean prettyPrint ) throws IOException { if ( prettyPrint ) { return stringify ( object , DEFAULT_INDENT_STRING ) ; } else { return stringify ( object , null ) ; } } | Converts an object to a JSON formatted string . If pretty - printing is enabled includes spaces tabs and new - lines to make the format more readable . The default indentation string is a tab character . | 53 | 40 |
22,232 | public static String stringify ( Object object , String indentString ) throws IOException { if ( object == null ) { return null ; } Writer out = new StringWriter ( ) ; JsonWriter jsonWriter = new JsonWriter ( out , indentString ) ; jsonWriter . write ( object ) ; jsonWriter . close ( ) ; return out . toString ( ) ; } | Converts an object to a JSON formatted string . If pretty - printing is enabled includes spaces tabs and new - lines to make the format more readable . | 78 | 30 |
22,233 | public void putSetting ( String name , String value ) throws IllegalRuleException { if ( StringUtils . isEmpty ( name ) ) { throw new IllegalRuleException ( "Default setting name can not be null" ) ; } DefaultSettingType settingType = DefaultSettingType . resolve ( name ) ; if ( settingType == null ) { throw new IllegalRuleException ( "No such default setting name as '" + name + "'" ) ; } settings . put ( settingType , value ) ; } | Puts the setting value . | 104 | 6 |
22,234 | public String resolveAliasType ( String alias ) { String type = getAliasedType ( alias ) ; return ( type == null ? alias : type ) ; } | Returns a type of an aliased type that is defined by assigning the type to the alias . If aliased type is not found it returns alias . | 33 | 30 |
22,235 | private void setAssistantLocal ( AssistantLocal newAssistantLocal ) { this . assistantLocal = newAssistantLocal ; scheduleRuleRegistry . setAssistantLocal ( newAssistantLocal ) ; transletRuleRegistry . setAssistantLocal ( newAssistantLocal ) ; templateRuleRegistry . setAssistantLocal ( newAssistantLocal ) ; } | Sets the assistant local . | 66 | 6 |
22,236 | public AssistantLocal backupAssistantLocal ( ) { AssistantLocal oldAssistantLocal = assistantLocal ; AssistantLocal newAssistantLocal = assistantLocal . replicate ( ) ; setAssistantLocal ( newAssistantLocal ) ; return oldAssistantLocal ; } | Backup the assistant local . | 46 | 6 |
22,237 | public void resolveAdviceBeanClass ( AspectRule aspectRule ) throws IllegalRuleException { String beanIdOrClass = aspectRule . getAdviceBeanId ( ) ; if ( beanIdOrClass != null ) { Class < ? > beanClass = resolveBeanClass ( beanIdOrClass , aspectRule ) ; if ( beanClass != null ) { aspectRule . setAdviceBeanClass ( beanClass ) ; reserveBeanReference ( beanClass , aspectRule ) ; } else { reserveBeanReference ( beanIdOrClass , aspectRule ) ; } } } | Resolve bean class for the aspect rule . | 123 | 9 |
22,238 | public void resolveActionBeanClass ( BeanMethodActionRule beanMethodActionRule ) throws IllegalRuleException { String beanIdOrClass = beanMethodActionRule . getBeanId ( ) ; if ( beanIdOrClass != null ) { Class < ? > beanClass = resolveBeanClass ( beanIdOrClass , beanMethodActionRule ) ; if ( beanClass != null ) { beanMethodActionRule . setBeanClass ( beanClass ) ; reserveBeanReference ( beanClass , beanMethodActionRule ) ; } else { reserveBeanReference ( beanIdOrClass , beanMethodActionRule ) ; } } } | Resolve bean class for bean method action rule . | 131 | 10 |
22,239 | public void resolveFactoryBeanClass ( BeanRule beanRule ) throws IllegalRuleException { String beanIdOrClass = beanRule . getFactoryBeanId ( ) ; if ( beanRule . isFactoryOffered ( ) && beanIdOrClass != null ) { Class < ? > beanClass = resolveBeanClass ( beanIdOrClass , beanRule ) ; if ( beanClass != null ) { beanRule . setFactoryBeanClass ( beanClass ) ; reserveBeanReference ( beanClass , beanRule ) ; } else { reserveBeanReference ( beanIdOrClass , beanRule ) ; } } } | Resolve bean class for factory bean rule . | 129 | 9 |
22,240 | public void resolveBeanClass ( ItemRule itemRule ) throws IllegalRuleException { Iterator < Token [ ] > it = ItemRule . tokenIterator ( itemRule ) ; if ( it != null ) { while ( it . hasNext ( ) ) { Token [ ] tokens = it . next ( ) ; if ( tokens != null ) { for ( Token token : tokens ) { resolveBeanClass ( token ) ; } } } } } | Resolve bean class . | 92 | 5 |
22,241 | public void resolveBeanClass ( Token [ ] tokens ) throws IllegalRuleException { if ( tokens != null ) { for ( Token token : tokens ) { resolveBeanClass ( token ) ; } } } | Resolve bean class for token . | 43 | 7 |
22,242 | public void resolveBeanClass ( AutowireRule autowireRule ) throws IllegalRuleException { if ( autowireRule . getTargetType ( ) == AutowireTargetType . FIELD ) { if ( autowireRule . isRequired ( ) ) { Class < ? > [ ] types = autowireRule . getTypes ( ) ; String [ ] qualifiers = autowireRule . getQualifiers ( ) ; reserveBeanReference ( qualifiers [ 0 ] , types [ 0 ] , autowireRule ) ; } } else if ( autowireRule . getTargetType ( ) == AutowireTargetType . FIELD_VALUE ) { Token token = autowireRule . getToken ( ) ; resolveBeanClass ( token , autowireRule ) ; } else if ( autowireRule . getTargetType ( ) == AutowireTargetType . METHOD || autowireRule . getTargetType ( ) == AutowireTargetType . CONSTRUCTOR ) { if ( autowireRule . isRequired ( ) ) { Class < ? > [ ] types = autowireRule . getTypes ( ) ; String [ ] qualifiers = autowireRule . getQualifiers ( ) ; for ( int i = 0 ; i < types . length ; i ++ ) { reserveBeanReference ( qualifiers [ i ] , types [ i ] , autowireRule ) ; } } } } | Resolve bean class for the autowire rule . | 301 | 11 |
22,243 | public void resolveBeanClass ( ScheduleRule scheduleRule ) throws IllegalRuleException { String beanId = scheduleRule . getSchedulerBeanId ( ) ; if ( beanId != null ) { Class < ? > beanClass = resolveBeanClass ( beanId , scheduleRule ) ; if ( beanClass != null ) { scheduleRule . setSchedulerBeanClass ( beanClass ) ; reserveBeanReference ( beanClass , scheduleRule ) ; } else { reserveBeanReference ( beanId , scheduleRule ) ; } } } | Resolve bean class for the schedule rule . | 114 | 9 |
22,244 | public void resolveBeanClass ( TemplateRule templateRule ) throws IllegalRuleException { String beanId = templateRule . getEngineBeanId ( ) ; if ( beanId != null ) { Class < ? > beanClass = resolveBeanClass ( beanId , templateRule ) ; if ( beanClass != null ) { templateRule . setEngineBeanClass ( beanClass ) ; reserveBeanReference ( beanClass , templateRule ) ; } else { reserveBeanReference ( beanId , templateRule ) ; } } else { resolveBeanClass ( templateRule . getTemplateTokens ( ) ) ; } } | Resolve bean class for the template rule . | 128 | 9 |
22,245 | public Collection < BeanRule > getBeanRules ( ) { Collection < BeanRule > idBasedBeanRules = beanRuleRegistry . getIdBasedBeanRules ( ) ; Collection < Set < BeanRule > > typeBasedBeanRules = beanRuleRegistry . getTypeBasedBeanRules ( ) ; Collection < BeanRule > configurableBeanRules = beanRuleRegistry . getConfigurableBeanRules ( ) ; int capacity = idBasedBeanRules . size ( ) ; for ( Set < BeanRule > brs : typeBasedBeanRules ) { capacity += brs . size ( ) ; } capacity += configurableBeanRules . size ( ) ; capacity = ( int ) ( capacity / 0.9f ) + 1 ; Set < BeanRule > beanRuleSet = new HashSet <> ( capacity , 0.9f ) ; beanRuleSet . addAll ( idBasedBeanRules ) ; for ( Set < BeanRule > brs : typeBasedBeanRules ) { beanRuleSet . addAll ( brs ) ; } beanRuleSet . addAll ( configurableBeanRules ) ; return beanRuleSet ; } | Returns all bean rules . | 245 | 5 |
22,246 | @ Override protected MessageFormat resolveCode ( String code , Locale locale ) { MessageFormat messageFormat = null ; for ( int i = 0 ; messageFormat == null && i < this . basenames . length ; i ++ ) { ResourceBundle bundle = getResourceBundle ( this . basenames [ i ] , locale ) ; if ( bundle != null ) { messageFormat = getMessageFormat ( bundle , code , locale ) ; } } return messageFormat ; } | Resolves the given message code as key in the registered resource bundles using a cached MessageFormat instance per message code . | 100 | 23 |
22,247 | protected ResourceBundle getResourceBundle ( String basename , Locale locale ) { if ( this . cacheMillis >= 0 ) { // Fresh ResourceBundle.getBundle call in order to let ResourceBundle // do its native caching, at the expense of more extensive lookup steps. return doGetBundle ( basename , locale ) ; } else { // Cache forever: prefer locale cache over repeated getBundle calls. Map < Locale , ResourceBundle > localeMap = this . cachedResourceBundles . get ( basename ) ; if ( localeMap != null ) { ResourceBundle bundle = localeMap . get ( locale ) ; if ( bundle != null ) { return bundle ; } } try { ResourceBundle bundle = doGetBundle ( basename , locale ) ; if ( localeMap == null ) { localeMap = new ConcurrentHashMap <> ( ) ; Map < Locale , ResourceBundle > existing = this . cachedResourceBundles . putIfAbsent ( basename , localeMap ) ; if ( existing != null ) { localeMap = existing ; } } localeMap . put ( locale , bundle ) ; return bundle ; } catch ( MissingResourceException ex ) { log . warn ( "ResourceBundle [" + basename + "] not found for MessageSource: " + ex . getMessage ( ) ) ; // Assume bundle not found // -> do NOT throw the exception to allow for checking parent message source. return null ; } } } | Return a ResourceBundle for the given basename and code fetching already generated MessageFormats from the cache . | 313 | 23 |
22,248 | protected ResourceBundle doGetBundle ( String basename , Locale locale ) throws MissingResourceException { return ResourceBundle . getBundle ( basename , locale , getClassLoader ( ) , new MessageSourceControl ( ) ) ; } | Obtain the resource bundle for the given basename and Locale . | 51 | 14 |
22,249 | protected MessageFormat getMessageFormat ( ResourceBundle bundle , String code , Locale locale ) throws MissingResourceException { Map < String , Map < Locale , MessageFormat > > codeMap = this . cachedBundleMessageFormats . get ( bundle ) ; Map < Locale , MessageFormat > localeMap = null ; if ( codeMap != null ) { localeMap = codeMap . get ( code ) ; if ( localeMap != null ) { MessageFormat result = localeMap . get ( locale ) ; if ( result != null ) { return result ; } } } String msg = getStringOrNull ( bundle , code ) ; if ( msg != null ) { if ( codeMap == null ) { codeMap = new ConcurrentHashMap <> ( ) ; Map < String , Map < Locale , MessageFormat > > existing = this . cachedBundleMessageFormats . putIfAbsent ( bundle , codeMap ) ; if ( existing != null ) { codeMap = existing ; } } if ( localeMap == null ) { localeMap = new ConcurrentHashMap <> ( ) ; Map < Locale , MessageFormat > existing = codeMap . putIfAbsent ( code , localeMap ) ; if ( existing != null ) { localeMap = existing ; } } MessageFormat result = createMessageFormat ( msg , locale ) ; localeMap . put ( locale , result ) ; return result ; } return null ; } | Return a MessageFormat for the given bundle and code fetching already generated MessageFormats from the cache . | 299 | 21 |
22,250 | public void addNodelet ( String xpath , NodeletAdder nodeletAdder ) { nodeletAdder . add ( xpath , this ) ; setXpath ( xpath ) ; } | Adds the nodelet . | 42 | 5 |
22,251 | private void parseMultipartFormData ( ) { String multipartFormDataParser = getSetting ( MULTIPART_FORM_DATA_PARSER_SETTING_NAME ) ; if ( multipartFormDataParser == null ) { throw new MultipartRequestParseException ( "The setting name 'multipartFormDataParser' for multipart " + "form data parsing is not specified. Please specify 'multipartFormDataParser' via Aspect so " + "that Translet can parse multipart form data." ) ; } MultipartFormDataParser parser = getBean ( multipartFormDataParser ) ; if ( parser == null ) { throw new MultipartRequestParseException ( "No bean named '" + multipartFormDataParser + "' is defined" ) ; } parser . parse ( getRequestAdapter ( ) ) ; } | Parse the multipart form data . | 183 | 8 |
22,252 | @ Override public String getHeader ( String name ) { return ( headers != null ? headers . getFirst ( name ) : null ) ; } | Returns the value of the response header with the given name . | 30 | 12 |
22,253 | @ Override public Collection < String > getHeaders ( String name ) { return ( headers != null ? headers . get ( name ) : null ) ; } | Returns the values of the response header with the given name . | 33 | 12 |
22,254 | @ Override public void setHeader ( String name , String value ) { touchHeaders ( ) . set ( name , value ) ; } | Set the given single header value under the given header name . | 29 | 12 |
22,255 | @ Override public void addHeader ( String name , String value ) { touchHeaders ( ) . add ( name , value ) ; } | Add the given single header value to the current list of values for the given header . | 29 | 17 |
22,256 | private void setInactivityTimer ( long ms ) { if ( sessionInactivityTimer == null ) { sessionInactivityTimer = new SessionInactivityTimer ( sessionHandler . getScheduler ( ) , this ) ; } sessionInactivityTimer . setIdleTimeout ( ms ) ; } | Set the session inactivity timer . | 60 | 7 |
22,257 | protected void stopInactivityTimer ( ) { try ( Lock ignored = locker . lockIfNotHeld ( ) ) { if ( sessionInactivityTimer != null ) { sessionInactivityTimer . setIdleTimeout ( - 1 ) ; sessionInactivityTimer = null ; if ( log . isDebugEnabled ( ) ) { log . debug ( "Session inactivity timer stopped" ) ; } } } } | Stop the session inactivity timer . | 84 | 7 |
22,258 | protected boolean isExpiredAt ( long time ) { try ( Lock ignored = locker . lockIfNotHeld ( ) ) { checkValidForRead ( ) ; return sessionData . isExpiredAt ( time ) ; } } | Check to see if session has expired as at the time given . | 48 | 13 |
22,259 | protected boolean isIdleLongerThan ( int sec ) { long now = System . currentTimeMillis ( ) ; try ( Lock ignored = locker . lockIfNotHeld ( ) ) { return ( ( sessionData . getAccessedTime ( ) + ( sec * 1000 ) ) <= now ) ; } } | Check if the Session has been idle longer than a number of seconds . | 67 | 14 |
22,260 | protected void checkValidForWrite ( ) throws IllegalStateException { checkLocked ( ) ; if ( state == State . INVALID ) { throw new IllegalStateException ( "Not valid for write: session " + this ) ; } if ( state == State . INVALIDATING ) { return ; // in the process of being invalidated, listeners may try to remove attributes } if ( ! isResident ( ) ) { throw new IllegalStateException ( "Not valid for write: session " + this ) ; } } | Check that the session can be modified . | 109 | 8 |
22,261 | protected void checkValidForRead ( ) throws IllegalStateException { checkLocked ( ) ; if ( state == State . INVALID ) { throw new IllegalStateException ( "Invalid for read: session " + this ) ; } if ( state == State . INVALIDATING ) { return ; } if ( ! isResident ( ) ) { throw new IllegalStateException ( "Invalid for read: session " + this ) ; } } | Check that the session data can be read . | 92 | 9 |
22,262 | public void setName ( String name ) { if ( name . endsWith ( ARRAY_SUFFIX ) ) { this . name = name . substring ( 0 , name . length ( ) - 2 ) ; type = ItemType . ARRAY ; } else if ( name . endsWith ( MAP_SUFFIX ) ) { this . name = name . substring ( 0 , name . length ( ) - 2 ) ; type = ItemType . MAP ; } else { this . name = name ; if ( type == null ) { type = ItemType . SINGLE ; } } } | Sets the name of the item . | 125 | 8 |
22,263 | public List < String > getValueList ( ) { if ( tokensList == null ) { return null ; } if ( tokensList . isEmpty ( ) ) { return new ArrayList <> ( ) ; } else { List < String > list = new ArrayList <> ( tokensList . size ( ) ) ; for ( Token [ ] tokens : tokensList ) { list . add ( TokenParser . toString ( tokens ) ) ; } return list ; } } | Returns a list of string values of this item . | 97 | 10 |
22,264 | public Map < String , String > getValueMap ( ) { if ( tokensMap == null ) { return null ; } if ( tokensMap . isEmpty ( ) ) { return new LinkedHashMap <> ( ) ; } else { Map < String , String > map = new LinkedHashMap <> ( tokensMap . size ( ) ) ; for ( Map . Entry < String , Token [ ] > entry : tokensMap . entrySet ( ) ) { map . put ( entry . getKey ( ) , TokenParser . toString ( entry . getValue ( ) ) ) ; } return map ; } } | Returns a map of string values of this item . | 129 | 10 |
22,265 | public void setValue ( Map < String , Token [ ] > tokensMap ) { if ( type == null ) { type = ItemType . MAP ; } if ( ! isMappableType ( ) ) { throw new IllegalArgumentException ( "The type of this item must be 'map' or 'properties'" ) ; } this . tokensMap = tokensMap ; } | Sets a value to this Map type item . | 78 | 10 |
22,266 | public void setValue ( Properties properties ) { if ( properties == null ) { throw new IllegalArgumentException ( "properties must not be null" ) ; } if ( type == null ) { type = ItemType . PROPERTIES ; } if ( ! isMappableType ( ) ) { throw new IllegalArgumentException ( "The type of this item must be 'properties' or 'map'" ) ; } tokensMap = new LinkedHashMap <> ( ) ; for ( String key : properties . stringPropertyNames ( ) ) { Object o = properties . get ( key ) ; if ( o instanceof Token [ ] ) { tokensMap . put ( key , ( Token [ ] ) o ) ; } else if ( o instanceof Token ) { Token [ ] tokens = new Token [ ] { ( Token ) o } ; tokensMap . put ( key , tokens ) ; } else { Token [ ] tokens = TokenParser . makeTokens ( o . toString ( ) , isTokenize ( ) ) ; putValue ( name , tokens ) ; } } } | Sets a value to this Properties type item . | 225 | 10 |
22,267 | public void setValue ( List < Token [ ] > tokensList ) { if ( type == null ) { type = ItemType . LIST ; } if ( ! isListableType ( ) ) { throw new IllegalArgumentException ( "The item type must be 'array', 'list' or 'set' for this item " + this ) ; } this . tokensList = tokensList ; } | Sets a value to this List type item . | 82 | 10 |
22,268 | public void setValue ( Set < Token [ ] > tokensSet ) { if ( tokensSet == null ) { throw new IllegalArgumentException ( "tokensSet must not be null" ) ; } if ( type == null ) { type = ItemType . SET ; } if ( ! isListableType ( ) ) { throw new IllegalArgumentException ( "The type of this item must be 'set', 'array' or 'list'" ) ; } tokensList = new ArrayList <> ( tokensSet ) ; } | Sets a value to this Set type item . | 111 | 10 |
22,269 | public boolean isListableType ( ) { return ( type == ItemType . ARRAY || type == ItemType . LIST || type == ItemType . SET ) ; } | Return whether this item is listable type . | 35 | 9 |
22,270 | public static ItemRule newInstance ( String type , String name , String valueType , String defaultValue , Boolean tokenize , Boolean mandatory , Boolean secret ) throws IllegalRuleException { ItemRule itemRule = new ItemRule ( ) ; ItemType itemType = ItemType . resolve ( type ) ; if ( type != null && itemType == null ) { throw new IllegalRuleException ( "No item type for '" + type + "'" ) ; } if ( itemType != null ) { itemRule . setType ( itemType ) ; } else { itemRule . setType ( ItemType . SINGLE ) ; //default } if ( ! StringUtils . isEmpty ( name ) ) { itemRule . setName ( name ) ; } else { itemRule . setAutoNamed ( true ) ; } if ( tokenize != null ) { itemRule . setTokenize ( tokenize ) ; } if ( valueType != null ) { ItemValueType itemValueType = ItemValueType . resolve ( valueType ) ; if ( itemValueType == null ) { throw new IllegalRuleException ( "No item value type for '" + valueType + "'" ) ; } itemRule . setValueType ( itemValueType ) ; } if ( defaultValue != null ) { itemRule . setDefaultValue ( defaultValue ) ; } if ( mandatory != null ) { itemRule . setMandatory ( mandatory ) ; } if ( secret != null ) { itemRule . setSecret ( secret ) ; } return itemRule ; } | Returns a new derived instance of ItemRule . | 319 | 9 |
22,271 | public static Token makeReferenceToken ( String bean , String template , String parameter , String attribute , String property ) { Token token ; if ( bean != null ) { token = new Token ( TokenType . BEAN , bean ) ; } else if ( template != null ) { token = new Token ( TokenType . TEMPLATE , template ) ; } else if ( parameter != null ) { token = new Token ( TokenType . PARAMETER , parameter ) ; } else if ( attribute != null ) { token = new Token ( TokenType . ATTRIBUTE , attribute ) ; } else if ( property != null ) { token = new Token ( TokenType . PROPERTY , property ) ; } else { token = null ; } return token ; } | Returns a made reference token . | 158 | 6 |
22,272 | @ Override public InputStream getInputStream ( ) throws IOException { InputStream inputStream = fileItem . getInputStream ( ) ; return ( inputStream != null ? inputStream : new ByteArrayInputStream ( new byte [ 0 ] ) ) ; } | Return an InputStream to read the contents of the file from . | 54 | 13 |
22,273 | @ Override public File saveAs ( File destFile , boolean overwrite ) throws IOException { if ( destFile == null ) { throw new IllegalArgumentException ( "destFile can not be null" ) ; } validateFile ( ) ; try { destFile = determineDestinationFile ( destFile , overwrite ) ; fileItem . write ( destFile ) ; } catch ( FileUploadException e ) { throw new IllegalStateException ( e . getMessage ( ) ) ; } catch ( Exception e ) { throw new IOException ( "Could not save as file " + destFile , e ) ; } setSavedFile ( destFile ) ; return destFile ; } | Save an uploaded file as a given destination file . | 139 | 10 |
22,274 | private static String makeMessage ( int lineNumber , String line , String tline , String msg ) { int columnNumber = ( tline != null ? line . indexOf ( tline ) : 0 ) ; StringBuilder sb = new StringBuilder ( ) ; if ( msg != null ) { sb . append ( msg ) ; } sb . append ( " [lineNumber: " ) . append ( lineNumber ) ; if ( columnNumber != - 1 ) { String lspace = line . substring ( 0 , columnNumber ) ; int tabCnt = StringUtils . search ( lspace , "\t" ) ; if ( tline != null && tline . length ( ) > 33 ) { tline = tline . substring ( 0 , 30 ) + "..." ; } sb . append ( ", columnNumber: " ) . append ( columnNumber + 1 ) ; if ( tabCnt != 0 ) { sb . append ( " (" ) ; sb . append ( "Tabs " ) . append ( tabCnt ) ; sb . append ( ", Spaces " ) . append ( columnNumber - tabCnt ) ; sb . append ( ")" ) ; } sb . append ( "] " ) . append ( tline ) ; } return sb . toString ( ) ; } | Create a detail message . | 280 | 5 |
22,275 | private void prepare ( String requestName , MethodType requestMethod , TransletRule transletRule , Translet parentTranslet ) { try { if ( log . isDebugEnabled ( ) ) { log . debug ( "Translet " + transletRule ) ; } newTranslet ( requestMethod , requestName , transletRule , parentTranslet ) ; if ( parentTranslet == null ) { if ( isIncluded ( ) ) { backupCurrentActivity ( ) ; saveCurrentActivity ( ) ; } else { saveCurrentActivity ( ) ; } adapt ( ) ; } prepareAspectAdviceRule ( transletRule , ( parentTranslet != null ) ) ; parseRequest ( ) ; parsePathVariables ( ) ; if ( parentTranslet == null ) { resolveLocale ( ) ; } } catch ( ActivityTerminatedException e ) { throw e ; } catch ( Exception e ) { throw new ActivityPrepareException ( "Failed to prepare activity for translet " + transletRule , e ) ; } } | Prepares a new activity for the Translet Rule by taking the results of the process that was created earlier . | 214 | 22 |
22,276 | private void produce ( ) { ContentList contentList = getTransletRule ( ) . getContentList ( ) ; if ( contentList != null ) { ProcessResult processResult = translet . getProcessResult ( ) ; if ( processResult == null ) { processResult = new ProcessResult ( contentList . size ( ) ) ; processResult . setName ( contentList . getName ( ) ) ; processResult . setExplicit ( contentList . isExplicit ( ) ) ; translet . setProcessResult ( processResult ) ; } for ( ActionList actionList : contentList ) { execute ( actionList ) ; if ( isResponseReserved ( ) ) { break ; } } } Response res = getResponse ( ) ; if ( res != null ) { ActionList actionList = res . getActionList ( ) ; if ( actionList != null ) { execute ( actionList ) ; } } } | Produce the result of the content and its subordinate actions . | 190 | 12 |
22,277 | protected String resolveRequestEncoding ( ) { String encoding = getRequestRule ( ) . getEncoding ( ) ; if ( encoding == null ) { encoding = getSetting ( RequestRule . CHARACTER_ENCODING_SETTING_NAME ) ; } return encoding ; } | Determines the request encoding . | 58 | 7 |
22,278 | protected String resolveResponseEncoding ( ) { String encoding = getRequestRule ( ) . getEncoding ( ) ; if ( encoding == null ) { encoding = resolveRequestEncoding ( ) ; } return encoding ; } | Determines the response encoding . | 45 | 7 |
22,279 | protected LocaleResolver resolveLocale ( ) { LocaleResolver localeResolver = null ; String localeResolverBeanId = getSetting ( RequestRule . LOCALE_RESOLVER_SETTING_NAME ) ; if ( localeResolverBeanId != null ) { localeResolver = getBean ( localeResolverBeanId , LocaleResolver . class ) ; localeResolver . resolveLocale ( getTranslet ( ) ) ; localeResolver . resolveTimeZone ( getTranslet ( ) ) ; } return localeResolver ; } | Resolve the current locale . | 120 | 6 |
22,280 | protected void parseDeclaredParameters ( ) { ItemRuleMap parameterItemRuleMap = getRequestRule ( ) . getParameterItemRuleMap ( ) ; if ( parameterItemRuleMap != null && ! parameterItemRuleMap . isEmpty ( ) ) { ItemEvaluator evaluator = null ; ItemRuleList missingItemRules = null ; for ( ItemRule itemRule : parameterItemRuleMap . values ( ) ) { Token [ ] tokens = itemRule . getTokens ( ) ; if ( tokens != null ) { if ( evaluator == null ) { evaluator = new ItemExpression ( this ) ; } String [ ] values = evaluator . evaluateAsStringArray ( itemRule ) ; String [ ] oldValues = getRequestAdapter ( ) . getParameterValues ( itemRule . getName ( ) ) ; if ( values != oldValues ) { getRequestAdapter ( ) . setParameter ( itemRule . getName ( ) , values ) ; } } if ( itemRule . isMandatory ( ) ) { String [ ] values = getRequestAdapter ( ) . getParameterValues ( itemRule . getName ( ) ) ; if ( values == null ) { if ( missingItemRules == null ) { missingItemRules = new ItemRuleList ( ) ; } missingItemRules . add ( itemRule ) ; } } } if ( missingItemRules != null ) { throw new MissingMandatoryParametersException ( missingItemRules ) ; } } } | Parses the declared parameters . | 306 | 7 |
22,281 | protected void parseDeclaredAttributes ( ) { ItemRuleMap attributeItemRuleMap = getRequestRule ( ) . getAttributeItemRuleMap ( ) ; if ( attributeItemRuleMap != null && ! attributeItemRuleMap . isEmpty ( ) ) { ItemEvaluator evaluator = new ItemExpression ( this ) ; for ( ItemRule itemRule : attributeItemRuleMap . values ( ) ) { Object value = evaluator . evaluate ( itemRule ) ; getRequestAdapter ( ) . setAttribute ( itemRule . getName ( ) , value ) ; } } } | Parses the declared attributes . | 122 | 7 |
22,282 | protected void execute ( ActionList actionList ) { ProcessResult processResult = translet . getProcessResult ( ) ; if ( processResult == null ) { processResult = new ProcessResult ( 1 ) ; translet . setProcessResult ( processResult ) ; } ContentResult contentResult = processResult . getContentResult ( actionList . getName ( ) , actionList . isExplicit ( ) ) ; if ( contentResult == null ) { contentResult = new ContentResult ( processResult , actionList . size ( ) ) ; contentResult . setName ( actionList . getName ( ) ) ; if ( ! processResult . isExplicit ( ) ) { contentResult . setExplicit ( actionList . isExplicit ( ) ) ; } } for ( Executable action : actionList ) { execute ( action , contentResult ) ; if ( isResponseReserved ( ) ) { break ; } } } | Execute actions . | 190 | 4 |
22,283 | private void execute ( Executable action , ContentResult contentResult ) { try { ChooseWhenRule chooseWhenRule = null ; if ( action . getCaseNo ( ) > 0 ) { ChooseRuleMap chooseRuleMap = getTransletRule ( ) . getChooseRuleMap ( ) ; if ( chooseRuleMap == null || chooseRuleMap . isEmpty ( ) ) { throw new IllegalRuleException ( "No defined choose rules" ) ; } ChooseRule chooseRule = chooseRuleMap . getChooseRule ( action . getCaseNo ( ) ) ; if ( chooseRule == null ) { throw new IllegalRuleException ( "No choose rule with case number: " + ChooseRule . toCaseGroupNo ( action . getCaseNo ( ) ) ) ; } chooseWhenRule = chooseRule . getChooseWhenRule ( action . getCaseNo ( ) ) ; if ( chooseWhenRule == null ) { throw new IllegalRuleException ( "No choose rule with case number: " + action . getCaseNo ( ) ) ; } if ( processedChooses != null && processedChooses . contains ( chooseRule . getCaseNo ( ) ) ) { return ; } if ( processedChooses == null || ! processedChooses . contains ( chooseWhenRule . getCaseNo ( ) ) ) { BooleanExpression expression = new BooleanExpression ( this ) ; if ( expression . evaluate ( chooseWhenRule ) ) { if ( processedChooses == null ) { processedChooses = new HashSet <> ( ) ; } processedChooses . add ( chooseRule . getCaseNo ( ) ) ; processedChooses . add ( chooseWhenRule . getCaseNo ( ) ) ; } else { return ; } } } if ( log . isDebugEnabled ( ) ) { log . debug ( "Action " + action ) ; } Object resultValue = action . execute ( this ) ; if ( ! action . isHidden ( ) && contentResult != null && resultValue != ActionResult . NO_RESULT ) { if ( resultValue instanceof ProcessResult ) { contentResult . addActionResult ( action , ( ProcessResult ) resultValue ) ; } else { contentResult . addActionResult ( action , resultValue ) ; } } if ( action . isLastInChooseWhen ( ) && chooseWhenRule != null && chooseWhenRule . getResponse ( ) != null ) { reserveResponse ( chooseWhenRule . getResponse ( ) ) ; } } catch ( ActionExecutionException e ) { throw e ; } catch ( Exception e ) { setRaisedException ( e ) ; throw new ActionExecutionException ( "Failed to execute action " + action , e ) ; } } | Execute action . | 556 | 4 |
22,284 | public void scanConfigurableBeans ( String ... basePackages ) throws BeanRuleException { if ( basePackages == null || basePackages . length == 0 ) { return ; } log . info ( "Auto component scanning on packages [" + StringUtils . joinCommaDelimitedList ( basePackages ) + "]" ) ; for ( String basePackage : basePackages ) { BeanClassScanner scanner = new BeanClassScanner ( classLoader ) ; List < BeanRule > beanRules = new ArrayList <> ( ) ; scanner . scan ( basePackage + ".**" , ( resourceName , targetClass ) -> { if ( targetClass . isAnnotationPresent ( Component . class ) ) { BeanRule beanRule = new BeanRule ( ) ; beanRule . setBeanClass ( targetClass ) ; beanRule . setScopeType ( ScopeType . SINGLETON ) ; beanRules . add ( beanRule ) ; } } ) ; for ( BeanRule beanRule : beanRules ) { saveConfigurableBeanRule ( beanRule ) ; } } } | Scans for annotated components . | 228 | 7 |
22,285 | public void addBeanRule ( final BeanRule beanRule ) throws IllegalRuleException { PrefixSuffixPattern prefixSuffixPattern = PrefixSuffixPattern . parse ( beanRule . getId ( ) ) ; String scanPattern = beanRule . getScanPattern ( ) ; if ( scanPattern != null ) { BeanClassScanner scanner = createBeanClassScanner ( beanRule ) ; List < BeanRule > beanRules = new ArrayList <> ( ) ; scanner . scan ( scanPattern , ( resourceName , targetClass ) -> { BeanRule beanRule2 = beanRule . replicate ( ) ; if ( prefixSuffixPattern != null ) { beanRule2 . setId ( prefixSuffixPattern . join ( resourceName ) ) ; } else { if ( beanRule . getId ( ) != null ) { beanRule2 . setId ( beanRule . getId ( ) + resourceName ) ; } else if ( beanRule . getMaskPattern ( ) != null ) { beanRule2 . setId ( resourceName ) ; } } beanRule2 . setBeanClass ( targetClass ) ; beanRules . add ( beanRule2 ) ; } ) ; for ( BeanRule beanRule2 : beanRules ) { dissectBeanRule ( beanRule2 ) ; } } else { if ( ! beanRule . isFactoryOffered ( ) ) { String className = beanRule . getClassName ( ) ; if ( prefixSuffixPattern != null ) { beanRule . setId ( prefixSuffixPattern . join ( className ) ) ; } Class < ? > beanClass ; try { beanClass = classLoader . loadClass ( className ) ; } catch ( ClassNotFoundException e ) { throw new BeanRuleException ( "Failed to load bean class" , beanRule , e ) ; } beanRule . setBeanClass ( beanClass ) ; } dissectBeanRule ( beanRule ) ; } } | Adds a bean rule . | 414 | 5 |
22,286 | protected String getMessageFromParent ( String code , Object [ ] args , Locale locale ) { MessageSource parent = getParentMessageSource ( ) ; if ( parent != null ) { if ( parent instanceof AbstractMessageSource ) { // Call internal method to avoid getting the default code back // in case of "useCodeAsDefaultMessage" being activated. return ( ( AbstractMessageSource ) parent ) . getMessageInternal ( code , args , locale ) ; } else { // Check parent MessageSource, returning null if not found there. return parent . getMessage ( code , args , null , locale ) ; } } // Not found in parent either. return null ; } | Try to retrieve the given message from the parent MessageSource if any . | 138 | 14 |
22,287 | public void reserve ( String beanId , Class < ? > beanClass , BeanReferenceable referenceable , RuleAppender ruleAppender ) { RefererKey key = new RefererKey ( beanClass , beanId ) ; Set < RefererInfo > refererInfoSet = refererInfoMap . get ( key ) ; if ( refererInfoSet == null ) { refererInfoSet = new LinkedHashSet <> ( ) ; refererInfoSet . add ( new RefererInfo ( referenceable , ruleAppender ) ) ; refererInfoMap . put ( key , refererInfoSet ) ; } else { refererInfoSet . add ( new RefererInfo ( referenceable , ruleAppender ) ) ; } } | Reserves to bean reference inspection . | 154 | 7 |
22,288 | public void inspect ( BeanRuleRegistry beanRuleRegistry ) throws BeanReferenceException , BeanRuleException { Set < Object > brokenReferences = new LinkedHashSet <> ( ) ; for ( Map . Entry < RefererKey , Set < RefererInfo > > entry : refererInfoMap . entrySet ( ) ) { RefererKey refererKey = entry . getKey ( ) ; String beanId = refererKey . getQualifier ( ) ; Class < ? > beanClass = refererKey . getType ( ) ; Set < RefererInfo > refererInfoSet = entry . getValue ( ) ; BeanRule beanRule = null ; BeanRule [ ] beanRules = null ; if ( beanClass != null ) { beanRules = beanRuleRegistry . getBeanRules ( beanClass ) ; if ( beanRules != null ) { if ( beanRules . length == 1 ) { if ( beanId != null ) { if ( beanId . equals ( beanRules [ 0 ] . getId ( ) ) ) { beanRule = beanRules [ 0 ] ; } } else { beanRule = beanRules [ 0 ] ; } } else { if ( beanId != null ) { for ( BeanRule br : beanRules ) { if ( beanId . equals ( br . getId ( ) ) ) { beanRule = br ; break ; } } } } } if ( beanRule == null && beanRules == null ) { beanRule = beanRuleRegistry . getBeanRuleForConfig ( beanClass ) ; } } else if ( beanId != null ) { beanRule = beanRuleRegistry . getBeanRule ( beanId ) ; } if ( beanRule == null ) { if ( beanRules != null && beanRules . length > 1 ) { for ( RefererInfo refererInfo : refererInfoSet ) { if ( beanId != null ) { log . error ( "Cannot resolve reference to bean " + refererKey + "; Referer: " + refererInfo ) ; } else { log . error ( "No unique bean of type [" + beanClass + "] is defined: " + "expected single matching bean but found " + beanRules . length + ": [" + NoUniqueBeanException . getBeanDescriptions ( beanRules ) + "]; Referer: " + refererInfo ) ; } } brokenReferences . add ( refererKey ) ; } else { int count = 0 ; for ( RefererInfo refererInfo : refererInfoSet ) { if ( ! isStaticMethodReference ( refererInfo ) ) { count ++ ; log . error ( "Cannot resolve reference to bean " + refererKey + "; Referer: " + refererInfo ) ; } } if ( count > 0 ) { brokenReferences . add ( refererKey ) ; } } } else { for ( RefererInfo refererInfo : refererInfoSet ) { if ( refererInfo . getBeanRefererType ( ) == BeanRefererType . BEAN_METHOD_ACTION_RULE ) { checkTransletActionParameter ( ( BeanMethodActionRule ) refererInfo . getReferenceable ( ) , beanRule , refererInfo ) ; } } } } if ( ! brokenReferences . isEmpty ( ) ) { throw new BeanReferenceException ( brokenReferences ) ; } } | Inspect bean reference . | 707 | 5 |
22,289 | public ItemRule putItemRule ( ItemRule itemRule ) { if ( itemRule . isAutoNamed ( ) ) { autoNaming ( itemRule ) ; } return put ( itemRule . getName ( ) , itemRule ) ; } | Adds a item rule . | 51 | 5 |
22,290 | protected void rejectRequest ( Translet translet , CorsException ce ) throws CorsException { HttpServletResponse res = translet . getResponseAdaptee ( ) ; res . setStatus ( ce . getHttpStatusCode ( ) ) ; translet . setAttribute ( CORS_HTTP_STATUS_CODE , ce . getHttpStatusCode ( ) ) ; translet . setAttribute ( CORS_HTTP_STATUS_TEXT , ce . getMessage ( ) ) ; throw ce ; } | Invoked when one of the CORS checks failed . The default implementation sets the response status to 403 . | 105 | 21 |
22,291 | private boolean isAllowedAddress ( String ipAddress ) { if ( allowedAddresses == null ) { return false ; } // IPv4 int offset = ipAddress . lastIndexOf ( ' ' ) ; if ( offset == - 1 ) { // IPv6 offset = ipAddress . lastIndexOf ( ' ' ) ; if ( offset == - 1 ) { return false ; } } String ipAddressClass = ipAddress . substring ( 0 , offset + 1 ) + ' ' ; return ( allowedAddresses . contains ( ipAddressClass ) || allowedAddresses . contains ( ipAddress ) ) ; } | Returns whether IP address is valid . | 125 | 7 |
22,292 | public byte [ ] getBytes ( ) throws IOException { InputStream input = getInputStream ( ) ; ByteArrayOutputStream output = new ByteArrayOutputStream ( ) ; final byte [ ] buffer = new byte [ DEFAULT_BUFFER_SIZE ] ; int len ; try { while ( ( len = input . read ( buffer ) ) != - 1 ) { output . write ( buffer , 0 , len ) ; } } finally { try { output . close ( ) ; } catch ( IOException e ) { // ignore } try { input . close ( ) ; } catch ( IOException e ) { // ignore } } return output . toByteArray ( ) ; } | Returns the contents of the file in a byte array . Can not use a large array of memory than the JVM Heap deal . | 140 | 27 |
22,293 | public File saveAs ( File destFile , boolean overwrite ) throws IOException { if ( destFile == null ) { throw new IllegalArgumentException ( "destFile can not be null" ) ; } try { destFile = determineDestinationFile ( destFile , overwrite ) ; final byte [ ] buffer = new byte [ DEFAULT_BUFFER_SIZE ] ; int len ; try ( InputStream input = getInputStream ( ) ; OutputStream output = new FileOutputStream ( destFile ) ) { while ( ( len = input . read ( buffer ) ) != - 1 ) { output . write ( buffer , 0 , len ) ; } } } catch ( Exception e ) { throw new IOException ( "Could not save as file " + destFile , e ) ; } setSavedFile ( destFile ) ; return destFile ; } | Save an file as a given destination file . | 176 | 9 |
22,294 | public void release ( ) { if ( file != null ) { file . setWritable ( true ) ; } if ( savedFile != null ) { savedFile . setWritable ( true ) ; } } | Sets the access permission that allow write operations on the file associated with this FileParameter . | 43 | 18 |
22,295 | public static ActivityContext getActivityContext ( ServletContext servletContext ) { ActivityContext activityContext = getActivityContext ( servletContext , ROOT_WEB_SERVICE_ATTRIBUTE ) ; if ( activityContext == null ) { throw new IllegalStateException ( "No Root AspectranWebService found; " + "No AspectranServiceListener registered?" ) ; } return activityContext ; } | Find the root ActivityContext for this web aspectran service . | 87 | 12 |
22,296 | public static ActivityContext getActivityContext ( HttpServlet servlet ) { ServletContext servletContext = servlet . getServletContext ( ) ; String attrName = STANDALONE_WEB_SERVICE_ATTRIBUTE_PREFIX + servlet . getServletName ( ) ; ActivityContext activityContext = getActivityContext ( servletContext , attrName ) ; if ( activityContext != null ) { return activityContext ; } else { return getActivityContext ( servletContext ) ; } } | Find the standalone ActivityContext for this web aspectran service . | 112 | 12 |
22,297 | private static ActivityContext getActivityContext ( ServletContext servletContext , String attrName ) { Object attr = servletContext . getAttribute ( attrName ) ; if ( attr == null ) { return null ; } if ( ! ( attr instanceof AspectranWebService ) ) { throw new IllegalStateException ( "Context attribute [" + attr + "] is not of type [" + AspectranWebService . class . getName ( ) + "]" ) ; } return ( ( CoreService ) attr ) . getActivityContext ( ) ; } | Find the ActivityContext for this web aspectran service . | 122 | 11 |
22,298 | private boolean deleteFile ( String filename ) throws Exception { if ( filename == null ) { return false ; } File file = new File ( storeDir , filename ) ; return Files . deleteIfExists ( file . toPath ( ) ) ; } | Delete the file associated with a session | 51 | 7 |
22,299 | @ Override public Set < String > doGetExpired ( final Set < String > candidates ) { final long now = System . currentTimeMillis ( ) ; Set < String > expired = new HashSet <> ( ) ; // iterate over the files and work out which have expired for ( String filename : sessionFileMap . values ( ) ) { try { long expiry = getExpiryFromFilename ( filename ) ; if ( expiry > 0 && expiry < now ) { expired . add ( getIdFromFilename ( filename ) ) ; } } catch ( Exception e ) { log . warn ( e . getMessage ( ) , e ) ; } } // check candidates that were not found to be expired, perhaps // because they no longer exist and they should be expired for ( String c : candidates ) { if ( ! expired . contains ( c ) ) { // if it doesn't have a file then the session doesn't exist String filename = sessionFileMap . get ( c ) ; if ( filename == null ) { expired . add ( c ) ; } } } // Infrequently iterate over all files in the store, and delete those // that expired a long time ago. // If the graceperiod is disabled, don't do the sweep! if ( gracePeriodSec > 0 && ( lastSweepTime == 0L || ( ( now - lastSweepTime ) >= ( 5 * TimeUnit . SECONDS . toMillis ( gracePeriodSec ) ) ) ) ) { lastSweepTime = now ; sweepDisk ( ) ; } return expired ; } | Check to see which sessions have expired . | 331 | 8 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.