idx
int64
0
165k
question
stringlengths
73
4.15k
target
stringlengths
5
918
len_question
int64
21
890
len_target
int64
3
255
19,100
private void changePage ( final int direction ) { int currentPage = pages . indexOf ( cardManager . getVisible ( ) ) ; currentPage = Math . min ( 2 , Math . max ( 0 , currentPage + direction ) ) ; cardManager . makeVisible ( pages . get ( currentPage ) ) ; prevButton . setDisabled ( currentPage == 0 ) ; nextButton . setDisabled ( currentPage == 2 ) ; finishButton . setDisabled ( currentPage != 2 ) ; cancelButton . setUnsavedChanges ( currentPage > 0 ) ; }
Handles a pagination request .
122
7
19,101
private String trackKindToString ( final Track . Kind kind ) { if ( kind == null ) { return null ; } switch ( kind ) { case SUBTITLES : return "subtitles" ; case CAPTIONS : return "captions" ; case DESCRIPTIONS : return "descriptions" ; case CHAPTERS : return "chapters" ; case METADATA : return "metadata" ; default : LOG . error ( "Unknown track kind " + kind ) ; return null ; } }
Converts a Track kind to the client track kind identifier .
108
12
19,102
public void processAction ( ) throws IOException { if ( isDisposed ( ) ) { LOG . error ( "Skipping action phase. Attempt to reuse disposed ContainerHelper instance" ) ; return ; } try { // Check user context has been prepared if ( getNewConversation ( ) == null ) { throw new IllegalStateException ( "User context has not been prepared before the action phase" ) ; } prepareAction ( ) ; UIContext uic = getUIContext ( ) ; if ( uic == null ) { throw new IllegalStateException ( "No user context set for the action phase." ) ; } UIContextHolder . pushContext ( uic ) ; // Make sure maps are cleared up uic . clearScratchMap ( ) ; uic . clearRequestScratchMap ( ) ; prepareRequest ( ) ; Request req = getRequest ( ) ; getInterceptor ( ) . attachResponse ( getResponse ( ) ) ; getInterceptor ( ) . serviceRequest ( req ) ; if ( req . isLogout ( ) ) { handleLogout ( ) ; dispose ( ) ; } } catch ( ActionEscape esc ) { LOG . debug ( "ActionEscape performed." ) ; // Action escapes must be handled in the action phase and then // do nothing if they reach the render phase (which they will in // the servlet implementation) handleEscape ( esc ) ; dispose ( ) ; } catch ( Escape esc ) { LOG . debug ( "Escape performed during action phase." ) ; // We can't handle the escape until the render phase. } catch ( Throwable t ) { // We try not to let any exception propagate to container. String message = "Caught exception during action phase." ; LOG . error ( message , t ) ; // We can't handle the error until the render phase. propogateError ( t ) ; } finally { UIContextHolder . reset ( ) ; } }
Support standard processing of the action phase of a request .
411
11
19,103
public void render ( ) throws IOException { if ( isDisposed ( ) ) { LOG . debug ( "Skipping render phase." ) ; return ; } try { // Check user context has been prepared if ( getNewConversation ( ) == null ) { throw new IllegalStateException ( "User context has not been prepared before the render phase" ) ; } prepareRender ( ) ; UIContext uic = getUIContext ( ) ; if ( uic == null ) { throw new IllegalStateException ( "No user context set for the render phase." ) ; } UIContextHolder . pushContext ( uic ) ; prepareRequest ( ) ; // Handle errors from the action phase now. if ( havePropogatedError ( ) ) { handleError ( getPropogatedError ( ) ) ; return ; } WComponent uiComponent = getUI ( ) ; if ( uiComponent == null ) { throw new SystemException ( "No UI Component exists." ) ; } Environment environment = uiComponent . getEnvironment ( ) ; if ( environment == null ) { throw new SystemException ( "No WEnvironment exists." ) ; } getInterceptor ( ) . attachResponse ( getResponse ( ) ) ; getInterceptor ( ) . preparePaint ( getRequest ( ) ) ; String contentType = getUI ( ) . getHeaders ( ) . getContentType ( ) ; Response response = getResponse ( ) ; response . setContentType ( contentType ) ; addGenericHeaders ( uic , getUI ( ) ) ; PrintWriter writer = getPrintWriter ( ) ; getInterceptor ( ) . paint ( new WebXmlRenderContext ( writer , uic . getLocale ( ) ) ) ; // The following only matters for a Portal context String title = uiComponent instanceof WApplication ? ( ( WApplication ) uiComponent ) . getTitle ( ) : null ; if ( title != null ) { setTitle ( title ) ; } } catch ( Escape esc ) { LOG . debug ( "Escape performed during render phase." ) ; handleEscape ( esc ) ; } catch ( Throwable t ) { // We try not to let any exception propagate to container. String message = "Caught exception during render phase." ; LOG . error ( message , t ) ; handleError ( t ) ; } finally { UIContextHolder . reset ( ) ; dispose ( ) ; } }
Support standard processing of the render phase of a request .
513
11
19,104
protected void cycleUIContext ( ) { boolean cycleIt = ConfigurationProperties . getDeveloperClusterEmulation ( ) ; if ( cycleIt ) { UIContext uic = getUIContext ( ) ; if ( uic instanceof UIContextWrap ) { LOG . info ( "Cycling the UIContext to simulate clustering" ) ; ( ( UIContextWrap ) uic ) . cycle ( ) ; } } }
Call this method to simulate what would happen if the UIContext was serialized due to clustering of servers .
101
24
19,105
protected void prepareRequest ( ) { LOG . debug ( "Preparing for request by adding headers and environment to top wcomponent" ) ; // Configure the UIContext to handle this request. UIContext uiContext = getUIContext ( ) ; // Add WEnvironment if not already done. // If the component is new, then it will not have a WEnvironment yet. Environment env ; if ( uiContext . isDummyEnvironment ( ) ) { env = createEnvironment ( ) ; uiContext . setEnvironment ( env ) ; } else { env = uiContext . getEnvironment ( ) ; } // Update the environment for the current phase of the request // processing. updateEnvironment ( env ) ; // Prepare an implementation of a wcomponent Request suitable to the // type of // container we are running in. if ( getRequest ( ) == null ) { setRequest ( createRequest ( ) ) ; } // Update the wcomponent Request for the current phase of the request // processing. updateRequest ( getRequest ( ) ) ; }
Prepare the session for the current request .
220
9
19,106
private void propogateError ( final Throwable error ) { // Unhandled runtime exceptions from action phase // must be remembered for subsequent renders if ( getRequest ( ) == null ) { LOG . error ( "Unable to remember error from action phase beyond this request" ) ; } else { LOG . debug ( "Remembering error from action phase" ) ; getRequest ( ) . setAttribute ( ACTION_ERROR_KEY , error ) ; } }
Propogates an error from the action phase to the render phase .
93
14
19,107
private boolean havePropogatedError ( ) { Request req = getRequest ( ) ; return req != null && req . getAttribute ( ACTION_ERROR_KEY ) != null ; }
Indicates whether there is an error which has been propogated from the action to the render phase .
38
21
19,108
private Throwable getPropogatedError ( ) { Request req = getRequest ( ) ; if ( req != null ) { return ( Throwable ) req . getAttribute ( ACTION_ERROR_KEY ) ; } return null ; }
Retrieves an error which has been propogated from the action to the render phase .
48
19
19,109
public void handleError ( final Throwable error ) throws IOException { LOG . debug ( "Start handleError..." ) ; // Should the session be removed upon error? boolean terminate = ConfigurationProperties . getTerminateSessionOnError ( ) ; // If we are unfriendly, terminate the session if ( terminate ) { invalidateSession ( ) ; } // Are we in developer friendly error mode? boolean friendly = ConfigurationProperties . getDeveloperErrorHandling ( ) ; FatalErrorPageFactory factory = Factory . newInstance ( FatalErrorPageFactory . class ) ; WComponent errorPage = factory . createErrorPage ( friendly , error ) ; String html = renderErrorPageToHTML ( errorPage ) ; // Setup the response Response response = getResponse ( ) ; response . setContentType ( WebUtilities . CONTENT_TYPE_HTML ) ; // Make sure not cached getResponse ( ) . setHeader ( "Cache-Control" , CacheType . NO_CACHE . getSettings ( ) ) ; getResponse ( ) . setHeader ( "Pragma" , "no-cache" ) ; getResponse ( ) . setHeader ( "Expires" , "-1" ) ; getPrintWriter ( ) . println ( html ) ; LOG . debug ( "End handleError" ) ; }
Last resort error handling .
271
5
19,110
protected String renderErrorPageToHTML ( final WComponent errorPage ) { // Check if using the default error page boolean defaultErrorPage = errorPage instanceof FatalErrorPage ; String html = null ; // If not default implementation of error page, Transform error page to HTML if ( ! defaultErrorPage ) { // Set UIC and Environment (Needed for Theme Paths) UIContext uic = new UIContextImpl ( ) ; uic . setEnvironment ( createEnvironment ( ) ) ; UIContextHolder . pushContext ( uic ) ; try { html = WebUtilities . renderWithTransformToHTML ( errorPage ) ; } catch ( Exception e ) { LOG . warn ( "Could not transform error page." , e ) ; } finally { UIContextHolder . popContext ( ) ; } } // Not transformed. So just render. if ( html == null ) { UIContextHolder . pushContext ( new UIContextImpl ( ) ) ; try { html = WebUtilities . render ( errorPage ) ; } catch ( Exception e ) { LOG . warn ( "Could not render error page." , e ) ; html = "System error occurred but could not render error page." ; } finally { UIContextHolder . popContext ( ) ; } } return html ; }
Render the error page component to HTML .
282
8
19,111
@ Override public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WFieldLayout fieldLayout = ( WFieldLayout ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; int labelWidth = fieldLayout . getLabelWidth ( ) ; String title = fieldLayout . getTitle ( ) ; xml . appendTagOpen ( "ui:fieldlayout" ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendOptionalAttribute ( "class" , component . getHtmlClass ( ) ) ; xml . appendOptionalAttribute ( "track" , component . isTracking ( ) , "true" ) ; xml . appendOptionalAttribute ( "hidden" , fieldLayout . isHidden ( ) , "true" ) ; xml . appendOptionalAttribute ( "labelWidth" , labelWidth > 0 , labelWidth ) ; xml . appendAttribute ( "layout" , fieldLayout . getLayoutType ( ) ) ; xml . appendOptionalAttribute ( "title" , title ) ; // Ordered layout if ( fieldLayout . isOrdered ( ) ) { xml . appendAttribute ( "ordered" , fieldLayout . getOrderedOffset ( ) ) ; } xml . appendClose ( ) ; // Render margin MarginRendererUtil . renderMargin ( fieldLayout , renderContext ) ; // Paint Fields paintChildren ( fieldLayout , renderContext ) ; xml . appendEndTag ( "ui:fieldlayout" ) ; }
Paints the given WFieldLayout .
317
8
19,112
@ Override public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WAbbrText abbrText = ( WAbbrText ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; xml . appendTagOpen ( "abbr" ) ; xml . appendOptionalAttribute ( "title" , abbrText . getToolTip ( ) ) ; xml . appendOptionalAttribute ( "class" , abbrText . getHtmlClass ( ) ) ; xml . appendClose ( ) ; xml . append ( abbrText . getText ( ) , abbrText . isEncodeText ( ) ) ; xml . appendEndTag ( "abbr" ) ; }
Paints the given WAbbrText .
153
9
19,113
@ Override public Cookie [ ] getCookies ( ) { Collection < Cookie > entries = cookies . values ( ) ; return entries . toArray ( new Cookie [ 0 ] ) ; }
Get all the cookies on this request .
39
8
19,114
public void setCookie ( final String name , final String value ) { if ( name != null ) { Cookie cookie = new Cookie ( name , value ) ; cookies . put ( name , cookie ) ; } }
Sets a cookie on this request instance .
44
9
19,115
public void setParameter ( final String name , final String value ) { String [ ] currentValue = ( String [ ] ) parameters . get ( name ) ; if ( currentValue == null ) { currentValue = new String [ ] { value } ; } else { // convert the current values into a new array.. String [ ] newValues = new String [ currentValue . length + 1 ] ; System . arraycopy ( currentValue , 0 , newValues , 0 , currentValue . length ) ; newValues [ newValues . length - 1 ] = value ; currentValue = newValues ; } parameters . put ( name , currentValue ) ; }
Sets a parameter . If the parameter already exists another value will be added to the parameter values .
133
20
19,116
public static < T > T newInstance ( final Class < T > interfaz ) { String classname = ConfigurationProperties . getFactoryImplementation ( interfaz . getName ( ) ) ; if ( classname == null ) { // Hmmm - this is bad. For the time being let's dump the parameters. LOG . fatal ( "No implementing class for " + interfaz . getName ( ) ) ; LOG . fatal ( "There needs to be a parameter defined for " + ConfigurationProperties . FACTORY_PREFIX + interfaz . getName ( ) ) ; throw new SystemException ( "No implementing class for " + interfaz . getName ( ) + "; " + "There needs to be a parameter defined for " + ConfigurationProperties . FACTORY_PREFIX + interfaz . getName ( ) ) ; } try { Class < T > clas = ( Class < T > ) Class . forName ( classname . trim ( ) ) ; return clas . newInstance ( ) ; } catch ( Exception ex ) { throw new SystemException ( "Failed to instantiate object of class " + classname , ex ) ; } }
Given an interface instantiate a class implementing that interface .
247
11
19,117
@ Override public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WMultiSelectPair multiSelectPair = ( WMultiSelectPair ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; boolean readOnly = multiSelectPair . isReadOnly ( ) ; xml . appendTagOpen ( "ui:multiselectpair" ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendOptionalAttribute ( "class" , component . getHtmlClass ( ) ) ; xml . appendOptionalAttribute ( "track" , component . isTracking ( ) , "true" ) ; xml . appendOptionalAttribute ( "hidden" , multiSelectPair . isHidden ( ) , "true" ) ; if ( readOnly ) { xml . appendAttribute ( "readOnly" , "true" ) ; } else { int rows = multiSelectPair . getRows ( ) ; int min = multiSelectPair . getMinSelect ( ) ; int max = multiSelectPair . getMaxSelect ( ) ; xml . appendAttribute ( "size" , rows < 2 ? WMultiSelectPair . DEFAULT_ROWS : rows ) ; xml . appendOptionalAttribute ( "disabled" , multiSelectPair . isDisabled ( ) , "true" ) ; xml . appendOptionalAttribute ( "required" , multiSelectPair . isMandatory ( ) , "true" ) ; xml . appendOptionalAttribute ( "shuffle" , multiSelectPair . isShuffle ( ) , "true" ) ; xml . appendOptionalAttribute ( "fromListName" , multiSelectPair . getAvailableListName ( ) ) ; xml . appendOptionalAttribute ( "toListName" , multiSelectPair . getSelectedListName ( ) ) ; xml . appendOptionalAttribute ( "accessibleText" , multiSelectPair . getAccessibleText ( ) ) ; xml . appendOptionalAttribute ( "min" , min > 0 , min ) ; xml . appendOptionalAttribute ( "max" , max > 0 , max ) ; } xml . appendClose ( ) ; // Options List < ? > options = multiSelectPair . getOptions ( ) ; boolean renderSelectionsOnly = readOnly ; if ( options != null ) { if ( multiSelectPair . isShuffle ( ) ) { // We need to render the selected options in order renderOrderedOptions ( multiSelectPair , options , 0 , xml , renderSelectionsOnly ) ; } else { renderUnorderedOptions ( multiSelectPair , options , 0 , xml , renderSelectionsOnly ) ; } } if ( ! readOnly ) { DiagnosticRenderUtil . renderDiagnostics ( multiSelectPair , renderContext ) ; } xml . appendEndTag ( "ui:multiselectpair" ) ; }
Paints the given WMultiSelectPair .
614
10
19,118
private int renderOrderedOptions ( final WMultiSelectPair multiSelectPair , final List < ? > options , final int startIndex , final XmlStringBuilder xml , final boolean renderSelectionsOnly ) { List < ? > selections = multiSelectPair . getSelected ( ) ; int optionIndex = startIndex ; // We can't just render all the unselected options followed by the selected ones // in the order they are given to us, as unselected/selected may be intermingled // due to the option groups. We therefore recursively render each group. // For each group, we: // - iterate through the options and // - render the unselected ones // - keep track of the selected ones (index within the selection list + index within the option list) // - Once all the unselected items have been rendered, we render the selections // This maps selection indices to option indices for the current group Map < Integer , Integer > currentSelectionIndices = new HashMap <> ( ) ; for ( Object option : options ) { if ( option instanceof OptionGroup ) { xml . appendTagOpen ( "ui:optgroup" ) ; xml . appendAttribute ( "label" , ( ( OptionGroup ) option ) . getDesc ( ) ) ; xml . appendClose ( ) ; // Recurse to render options inside option groups. List < ? > nestedOptions = ( ( OptionGroup ) option ) . getOptions ( ) ; optionIndex += renderOrderedOptions ( multiSelectPair , nestedOptions , optionIndex , xml , renderSelectionsOnly ) ; xml . appendEndTag ( "ui:optgroup" ) ; } else { int index = selections . indexOf ( option ) ; if ( index == - 1 ) { renderOption ( multiSelectPair , option , optionIndex ++ , xml , selections , renderSelectionsOnly ) ; } else { currentSelectionIndices . put ( index , optionIndex ++ ) ; } } } if ( ! currentSelectionIndices . isEmpty ( ) ) { // Now sort the selected item's indices and render them in the correct order. List < Integer > sortedSelectedIndices = new ArrayList <> ( currentSelectionIndices . keySet ( ) ) ; Collections . sort ( sortedSelectedIndices ) ; for ( int selectionIndex : sortedSelectedIndices ) { int selectionOptionIndex = currentSelectionIndices . get ( selectionIndex ) ; renderOption ( multiSelectPair , selections . get ( selectionIndex ) , selectionOptionIndex , xml , selections , renderSelectionsOnly ) ; } } return optionIndex - startIndex ; }
Renders the options in selection order . Note though that this does not support the legacy allowNull or setSelected using String representations .
551
27
19,119
private int renderUnorderedOptions ( final WMultiSelectPair multiSelectPair , final List < ? > options , final int startIndex , final XmlStringBuilder xml , final boolean renderSelectionsOnly ) { List < ? > selections = multiSelectPair . getSelected ( ) ; int optionIndex = startIndex ; for ( Object option : options ) { if ( option instanceof OptionGroup ) { xml . appendTagOpen ( "ui:optgroup" ) ; xml . appendAttribute ( "label" , ( ( OptionGroup ) option ) . getDesc ( ) ) ; xml . appendClose ( ) ; // Recurse to render options inside option groups. List < ? > nestedOptions = ( ( OptionGroup ) option ) . getOptions ( ) ; optionIndex += renderUnorderedOptions ( multiSelectPair , nestedOptions , optionIndex , xml , renderSelectionsOnly ) ; xml . appendEndTag ( "ui:optgroup" ) ; } else { renderOption ( multiSelectPair , option , optionIndex ++ , xml , selections , renderSelectionsOnly ) ; } } return optionIndex - startIndex ; }
Renders the options in list order .
238
8
19,120
public List < Conversation > getConversationsOnObject ( Reference object ) { return getResourceFactory ( ) . getApiResource ( "/conversation/" + object . toURLFragment ( ) ) . get ( new GenericType < List < Conversation > > ( ) { } ) ; }
Returns a list of all the conversations on the object that the active user is part of .
62
18
19,121
public int addReply ( int conversationId , String text ) { return getResourceFactory ( ) . getApiResource ( "/conversation/" + conversationId + "/reply" ) . entity ( new MessageCreate ( text ) , MediaType . APPLICATION_JSON_TYPE ) . get ( MessageCreateResponse . class ) . getMessageId ( ) ; }
Creates a reply to the conversation .
75
8
19,122
@ Override public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WApplication application = ( WApplication ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; UIContext uic = UIContextHolder . getCurrent ( ) ; String focusId = uic . getFocussedId ( ) ; // Check that this is the top level component if ( application . getParent ( ) != null ) { LOG . warn ( "WApplication component should be the top level component." ) ; } xml . appendTagOpen ( "ui:application" ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendOptionalAttribute ( "class" , component . getHtmlClass ( ) ) ; xml . appendUrlAttribute ( "applicationUrl" , uic . getEnvironment ( ) . getPostPath ( ) ) ; xml . appendUrlAttribute ( "ajaxUrl" , uic . getEnvironment ( ) . getWServletPath ( ) ) ; xml . appendOptionalAttribute ( "unsavedChanges" , application . hasUnsavedChanges ( ) , "true" ) ; xml . appendOptionalAttribute ( "title" , application . getTitle ( ) ) ; xml . appendOptionalAttribute ( "defaultFocusId" , uic . isFocusRequired ( ) && ! Util . empty ( focusId ) , focusId ) ; xml . appendOptionalUrlAttribute ( "icon" , WApplication . getIcon ( ) ) ; xml . appendClose ( ) ; // Tracking enabled globally if ( TrackingUtil . isTrackingEnabled ( ) ) { xml . appendTagOpen ( "ui:analytic" ) ; xml . appendAttribute ( "clientId" , TrackingUtil . getClientId ( ) ) ; xml . appendOptionalAttribute ( "cd" , TrackingUtil . getCookieDomain ( ) ) ; xml . appendOptionalAttribute ( "dcd" , TrackingUtil . getDataCollectionDomain ( ) ) ; xml . appendOptionalAttribute ( "name" , TrackingUtil . getApplicationName ( ) ) ; xml . appendEnd ( ) ; } // Hidden fields Map < String , String > hiddenFields = uic . getEnvironment ( ) . getHiddenParameters ( ) ; if ( hiddenFields != null ) { for ( Map . Entry < String , String > entry : hiddenFields . entrySet ( ) ) { xml . appendTagOpen ( "ui:param" ) ; xml . appendAttribute ( "name" , entry . getKey ( ) ) ; xml . appendAttribute ( "value" , entry . getValue ( ) ) ; xml . appendEnd ( ) ; } } // Custom CSS Resources (if any) for ( WApplication . ApplicationResource resource : application . getCssResources ( ) ) { String url = resource . getTargetUrl ( ) ; if ( ! Util . empty ( url ) ) { xml . appendTagOpen ( "ui:css" ) ; xml . appendUrlAttribute ( "url" , url ) ; xml . appendEnd ( ) ; } } // Custom JavaScript Resources (if any) for ( WApplication . ApplicationResource resource : application . getJsResources ( ) ) { String url = resource . getTargetUrl ( ) ; if ( ! Util . empty ( url ) ) { xml . appendTagOpen ( "ui:js" ) ; xml . appendUrlAttribute ( "url" , url ) ; xml . appendEnd ( ) ; } } paintChildren ( application , renderContext ) ; xml . appendEndTag ( "ui:application" ) ; }
Paints the given WApplication .
765
7
19,123
@ Override protected void preparePaintComponent ( final Request request ) { StringBuffer text = new StringBuffer ( "Options: " ) ; for ( Object option : shuffler . getOptions ( ) ) { text . append ( option ) . append ( ", " ) ; } order . setText ( text . toString ( ) ) ; }
Concatenate the options to display in the text field .
71
13
19,124
@ Override public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WMultiTextField textField = ( WMultiTextField ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; boolean readOnly = textField . isReadOnly ( ) ; String [ ] values = textField . getTextInputs ( ) ; xml . appendTagOpen ( "ui:multitextfield" ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendOptionalAttribute ( "class" , component . getHtmlClass ( ) ) ; xml . appendOptionalAttribute ( "track" , component . isTracking ( ) , "true" ) ; xml . appendOptionalAttribute ( "hidden" , textField . isHidden ( ) , "true" ) ; if ( readOnly ) { xml . appendAttribute ( "readOnly" , "true" ) ; } else { int cols = textField . getColumns ( ) ; int minLength = textField . getMinLength ( ) ; int maxLength = textField . getMaxLength ( ) ; int maxInputs = textField . getMaxInputs ( ) ; String pattern = textField . getPattern ( ) ; xml . appendOptionalAttribute ( "disabled" , textField . isDisabled ( ) , "true" ) ; xml . appendOptionalAttribute ( "required" , textField . isMandatory ( ) , "true" ) ; xml . appendOptionalAttribute ( "toolTip" , textField . getToolTip ( ) ) ; xml . appendOptionalAttribute ( "accessibleText" , textField . getAccessibleText ( ) ) ; xml . appendOptionalAttribute ( "size" , cols > 0 , cols ) ; xml . appendOptionalAttribute ( "minLength" , minLength > 0 , minLength ) ; xml . appendOptionalAttribute ( "maxLength" , maxLength > 0 , maxLength ) ; xml . appendOptionalAttribute ( "max" , maxInputs > 0 , maxInputs ) ; xml . appendOptionalAttribute ( "pattern" , ! Util . empty ( pattern ) , pattern ) ; // NOTE: do not use HtmlRenderUtil.getEffectivePlaceholder for placeholder - we do not want to echo "required" in every field. String placeholder = textField . getPlaceholder ( ) ; xml . appendOptionalAttribute ( "placeholder" , ! Util . empty ( placeholder ) , placeholder ) ; xml . appendOptionalAttribute ( "title" , I18nUtilities . format ( null , InternalMessages . DEFAULT_MULTITEXTFIELD_TIP ) ) ; } xml . appendClose ( ) ; if ( values != null ) { for ( String value : values ) { xml . appendTag ( "ui:value" ) ; xml . appendEscaped ( value ) ; xml . appendEndTag ( "ui:value" ) ; } } if ( ! readOnly ) { DiagnosticRenderUtil . renderDiagnostics ( textField , renderContext ) ; } xml . appendEndTag ( "ui:multitextfield" ) ; }
Paints the given WMultiTextField .
669
9
19,125
private static ExampleBean fakeServiceCall ( final String text ) { ExampleBean exampleBean = new ExampleBean ( ) ; exampleBean . setBeanAttribute ( "(beanAttribute) " + text ) ; ExampleBean . DummyInnerBean dummyInnerBean = new ExampleBean . DummyInnerBean ( ) ; dummyInnerBean . setInnerAttribute ( "(innerBean.innerAttribute) " + text ) ; exampleBean . setInnerBean ( dummyInnerBean ) ; return exampleBean ; }
Fakes a service call and just returns dummy data .
123
11
19,126
public static void processRequest ( final HttpServletHelper helper , final WComponent ui , final InterceptorComponent interceptorChain ) throws ServletException , IOException { try { // Tell the support container about the top most web component // that will service the request/response. if ( interceptorChain == null ) { helper . setWebComponent ( ui ) ; } else { interceptorChain . attachUI ( ui ) ; helper . setWebComponent ( interceptorChain ) ; } // Prepare user context UIContext uic = helper . prepareUserContext ( ) ; synchronized ( uic ) { // Process the action phase. helper . processAction ( ) ; // Process the render phase. helper . render ( ) ; } } finally { // We need to ensure that the AJAX operation is cleared // The interceptors can not guarantee this // TODO: Investigate changing to not use a thread-local AjaxHelper . clearCurrentOperationDetails ( ) ; } }
This method does the real work in servicing the http request . It integrates wcomponents into a servlet environment via a servlet specific helper class .
203
30
19,127
public static void handleStaticResourceRequest ( final HttpServletRequest request , final HttpServletResponse response ) { String staticRequest = request . getParameter ( WServlet . STATIC_RESOURCE_PARAM_NAME ) ; try { InternalResource staticResource = InternalResourceMap . getResource ( staticRequest ) ; boolean headersOnly = "HEAD" . equals ( request . getMethod ( ) ) ; if ( staticResource == null ) { LOG . warn ( "Static resource [" + staticRequest + "] not found." ) ; response . setStatus ( HttpServletResponse . SC_NOT_FOUND ) ; return ; } InputStream resourceStream = staticResource . getStream ( ) ; if ( resourceStream == null ) { LOG . warn ( "Static resource [" + staticRequest + "] not found. Stream for content is null." ) ; response . setStatus ( HttpServletResponse . SC_NOT_FOUND ) ; return ; } int size = resourceStream . available ( ) ; String fileName = WebUtilities . encodeForContentDispositionHeader ( staticRequest . substring ( staticRequest . lastIndexOf ( ' ' ) + 1 ) ) ; if ( size > 0 ) { response . setContentLength ( size ) ; } response . setContentType ( WebUtilities . getContentType ( staticRequest ) ) ; response . setHeader ( "Cache-Control" , CacheType . CONTENT_CACHE . getSettings ( ) ) ; String param = request . getParameter ( WContent . URL_CONTENT_MODE_PARAMETER_KEY ) ; if ( "inline" . equals ( param ) ) { response . setHeader ( "Content-Disposition" , "inline; filename=" + fileName ) ; } else if ( "attach" . equals ( param ) ) { response . setHeader ( "Content-Disposition" , "attachment; filename=" + fileName ) ; } else { // added "filename=" to comply with https://tools.ietf.org/html/rfc6266 response . setHeader ( "Content-Disposition" , "filename=" + fileName ) ; } if ( ! headersOnly ) { StreamUtil . copy ( resourceStream , response . getOutputStream ( ) ) ; } } catch ( IOException e ) { LOG . warn ( "Could not process static resource [" + staticRequest + "]. " , e ) ; response . reset ( ) ; response . setStatus ( HttpServletResponse . SC_NOT_FOUND ) ; } }
Handles a request for static resources .
539
8
19,128
public static void handleThemeResourceRequest ( final HttpServletRequest req , final HttpServletResponse resp ) throws ServletException , IOException { if ( req . getHeader ( "If-Modified-Since" ) != null ) { resp . reset ( ) ; resp . setStatus ( HttpServletResponse . SC_NOT_MODIFIED ) ; return ; } String fileName = req . getParameter ( "f" ) ; String path = req . getPathInfo ( ) ; if ( fileName == null && ! Util . empty ( path ) ) { int offset = path . startsWith ( THEME_RESOURCE_PATH_PARAM ) ? THEME_RESOURCE_PATH_PARAM . length ( ) : 1 ; fileName = path . substring ( offset ) ; } if ( fileName == null || ! checkThemeFile ( fileName ) ) { resp . setStatus ( HttpServletResponse . SC_NOT_FOUND ) ; return ; } InputStream resourceStream = null ; try { URL url = null ; // Check for project translation file if ( fileName . startsWith ( THEME_TRANSLATION_RESOURCE_PREFIX ) ) { String resourceFileName = fileName . substring ( THEME_TRANSLATION_RESOURCE_PREFIX . length ( ) ) ; url = ServletUtil . class . getResource ( THEME_PROJECT_TRANSLATION_RESOURCE_PATH + resourceFileName ) ; } // Load from the theme path if ( url == null ) { String resourceName = ThemeUtil . getThemeBase ( ) + fileName ; url = ServletUtil . class . getResource ( resourceName ) ; } if ( url == null ) { resp . setStatus ( HttpServletResponse . SC_NOT_FOUND ) ; } else { URLConnection connection = url . openConnection ( ) ; resourceStream = connection . getInputStream ( ) ; int size = resourceStream . available ( ) ; if ( size > 0 ) { resp . setContentLength ( size ) ; } /* I have commented out the setting of the Content-Disposition on static theme resources because, well why is it there? If this needs to be reinstated please provide a thorough justification comment here so the reasons are clear. Note that setting this header breaks Polymer 1.0 when it is present on HTML imports. String encodedName = WebUtilities.encodeForContentDispositionHeader(fileName. substring(fileName .lastIndexOf('/') + 1)); resp.setHeader("Content-Disposition", "filename=" + encodedName); // "filename=" to comply with https://tools.ietf.org/html/rfc6266 */ resp . setContentType ( WebUtilities . getContentType ( fileName ) ) ; resp . setHeader ( "Cache-Control" , CacheType . THEME_CACHE . getSettings ( ) ) ; resp . setHeader ( "Expires" , "31536000" ) ; resp . setHeader ( "ETag" , "\"" + WebUtilities . getProjectVersion ( ) + "\"" ) ; // resp.setHeader("Last-Modified", "Mon, 02 Jan 2015 01:00:00 GMT"); long modified = connection . getLastModified ( ) ; resp . setDateHeader ( "Last-Modified" , modified ) ; StreamUtil . copy ( resourceStream , resp . getOutputStream ( ) ) ; } } finally { StreamUtil . safeClose ( resourceStream ) ; } }
Serves up a file from the theme . In practice it is generally a bad idea to use this servlet to serve up static resources . Instead it would make more sense to move CSS JS HTML resources to a CDN or similar .
761
47
19,129
private static boolean checkThemeFile ( final String name ) { return ! ( Util . empty ( name ) // name must exist || name . contains ( ".." ) // prevent directory traversal || name . charAt ( 0 ) == ' ' // all theme references should be relative || name . indexOf ( ' ' ) != - 1 // forbid use of protocols such as jar:, http: etc. ) ; }
Performs basic sanity checks on the file being requested .
86
11
19,130
public static InterceptorComponent createInterceptorChain ( final HttpServletRequest request ) { // Allow for multi part parameters Map < String , String [ ] > parameters = getRequestParameters ( request ) ; InterceptorComponent [ ] chain ; if ( parameters . get ( WServlet . DATA_LIST_PARAM_NAME ) != null ) { // Datalist chain = new InterceptorComponent [ ] { new TransformXMLInterceptor ( ) , new DataListInterceptor ( ) } ; } else if ( parameters . get ( WServlet . AJAX_TRIGGER_PARAM_NAME ) != null ) { // AJAX chain = new InterceptorComponent [ ] { new TemplateRenderInterceptor ( ) , new TransformXMLInterceptor ( ) , new ValidateXMLInterceptor ( ) , new AjaxErrorInterceptor ( ) , new SessionTokenAjaxInterceptor ( ) , new ResponseCacheInterceptor ( CacheType . NO_CACHE ) , new UIContextDumpInterceptor ( ) , new AjaxSetupInterceptor ( ) , new WWindowInterceptor ( true ) , new WrongStepAjaxInterceptor ( ) , new ContextCleanupInterceptor ( ) , new WhitespaceFilterInterceptor ( ) , new SubordinateControlInterceptor ( ) , new AjaxPageShellInterceptor ( ) , new AjaxDebugStructureInterceptor ( ) , new AjaxInterceptor ( ) } ; } else if ( parameters . get ( WServlet . TARGET_ID_PARAM_NAME ) != null ) { // Targetted Content chain = new InterceptorComponent [ ] { new TargetableErrorInterceptor ( ) , new SessionTokenContentInterceptor ( ) , new UIContextDumpInterceptor ( ) , new TargetableInterceptor ( ) , new WWindowInterceptor ( false ) , new WrongStepContentInterceptor ( ) } ; } else { chain = new InterceptorComponent [ ] { // Page submit new TemplateRenderInterceptor ( ) , new TransformXMLInterceptor ( ) , new ValidateXMLInterceptor ( ) , new SessionTokenInterceptor ( ) , new ResponseCacheInterceptor ( CacheType . NO_CACHE ) , new UIContextDumpInterceptor ( ) , new WWindowInterceptor ( true ) , new WrongStepServerInterceptor ( ) , new AjaxCleanupInterceptor ( ) , new ContextCleanupInterceptor ( ) , new WhitespaceFilterInterceptor ( ) , new SubordinateControlInterceptor ( ) , new PageShellInterceptor ( ) , new FormInterceptor ( ) , new DebugStructureInterceptor ( ) } ; } // Link the interceptors together in a chain. for ( int i = 0 ; i < chain . length - 1 ; i ++ ) { chain [ i ] . setBackingComponent ( chain [ i + 1 ] ) ; } // Return the top of the chain. return chain [ 0 ] ; }
Creates a new interceptor chain to handle the given request .
616
13
19,131
public static Map < String , String [ ] > getRequestParameters ( final HttpServletRequest request ) { if ( request . getAttribute ( REQUEST_PROCESSED_KEY ) == null ) { setupRequestParameters ( request ) ; } return ( Map < String , String [ ] > ) request . getAttribute ( REQUEST_PARAMETERS_KEY ) ; }
Get a map of request parameters allowing for multi part form fields .
80
13
19,132
public static String getRequestParameterValue ( final HttpServletRequest request , final String key ) { String [ ] values = getRequestParameterValues ( request , key ) ; return values == null || values . length == 0 ? null : values [ 0 ] ; }
Get a value for a request parameter allowing for multi part form fields .
55
14
19,133
public static String [ ] getRequestParameterValues ( final HttpServletRequest request , final String key ) { return getRequestParameters ( request ) . get ( key ) ; }
Get the values for a request parameter allowing for multi part form fields .
37
14
19,134
public static Map < String , FileItem [ ] > getRequestFileItems ( final HttpServletRequest request ) { if ( request . getAttribute ( REQUEST_PROCESSED_KEY ) == null ) { setupRequestParameters ( request ) ; } return ( Map < String , FileItem [ ] > ) request . getAttribute ( REQUEST_FILES_KEY ) ; }
Get a map of file items in the request allowing for multi part form fields .
81
16
19,135
public static FileItem getRequestFileItemValue ( final HttpServletRequest request , final String key ) { FileItem [ ] values = getRequestFileItemValues ( request , key ) ; return values == null || values . length == 0 ? null : values [ 0 ] ; }
Get a file item value from the request allowing for multi part form fields .
59
15
19,136
public static FileItem [ ] getRequestFileItemValues ( final HttpServletRequest request , final String key ) { return getRequestFileItems ( request ) . get ( key ) ; }
Get file item values from the request allowing for multi part form fields .
40
14
19,137
public static void setupRequestParameters ( final HttpServletRequest request ) { // Check already processed if ( request . getAttribute ( REQUEST_PROCESSED_KEY ) != null ) { return ; } Map < String , String [ ] > parameters = new HashMap <> ( ) ; Map < String , FileItem [ ] > files = new HashMap <> ( ) ; extractParameterMap ( request , parameters , files ) ; request . setAttribute ( REQUEST_PROCESSED_KEY , "Y" ) ; request . setAttribute ( REQUEST_PARAMETERS_KEY , Collections . unmodifiableMap ( parameters ) ) ; request . setAttribute ( REQUEST_FILES_KEY , Collections . unmodifiableMap ( files ) ) ; }
Process the request parameters allowing for multi part form fields .
163
11
19,138
public static void extractParameterMap ( final HttpServletRequest request , final Map < String , String [ ] > parameters , final Map < String , FileItem [ ] > files ) { if ( isMultipart ( request ) ) { ServletFileUpload upload = new ServletFileUpload ( ) ; upload . setFileItemFactory ( new DiskFileItemFactory ( ) ) ; try { List fileItems = upload . parseRequest ( request ) ; uploadFileItems ( fileItems , parameters , files ) ; } catch ( FileUploadException ex ) { throw new SystemException ( ex ) ; } // Include Query String Parameters (only if parameters were not included in the form fields) for ( Object entry : request . getParameterMap ( ) . entrySet ( ) ) { Map . Entry < String , String [ ] > param = ( Map . Entry < String , String [ ] > ) entry ; if ( ! parameters . containsKey ( param . getKey ( ) ) ) { parameters . put ( param . getKey ( ) , param . getValue ( ) ) ; } } } else { parameters . putAll ( request . getParameterMap ( ) ) ; } }
Extract the parameters and file items allowing for multi part form fields .
243
14
19,139
public static String extractCookie ( final HttpServletRequest request , final String name ) { for ( Cookie cookie : request . getCookies ( ) ) { if ( cookie . getName ( ) . equals ( name ) ) { return cookie . getValue ( ) ; } } return null ; }
Find the value of a cookie on the request by name .
63
12
19,140
private void updateRegion ( ) { actMessagePanel . setVisible ( false ) ; if ( rbtACT . isSelected ( ) ) { actMessagePanel . setVisible ( true ) ; regionFields . setVisible ( true ) ; regionSelector . setOptions ( new String [ ] { null , "Belconnen" , "City" , "Woden" } ) ; regionSelector . setVisible ( true ) ; } else if ( rbtNSW . isSelected ( ) ) { regionFields . setVisible ( true ) ; regionSelector . setOptions ( new String [ ] { null , "Hunter" , "Riverina" , "Southern Tablelands" } ) ; regionSelector . setVisible ( true ) ; } else if ( rbtVIC . isSelected ( ) ) { regionFields . setVisible ( true ) ; regionSelector . setOptions ( new String [ ] { null , "Gippsland" , "Melbourne" , "Mornington Peninsula" } ) ; regionSelector . setVisible ( true ) ; } else { regionSelector . setOptions ( new Object [ ] { null } ) ; regionSelector . setVisible ( false ) ; regionFields . setVisible ( false ) ; } }
Updates the visibility and options present in the region selector depending on the state selector s value .
280
19
19,141
public void setContent ( final WComponent content ) { WindowModel model = getOrCreateComponentModel ( ) ; // If the previous content had been wrapped, then remove it from the wrapping WApplication. if ( model . wrappedContent != null && model . wrappedContent != model . content ) { model . wrappedContent . removeAll ( ) ; } model . content = content ; // Wrap content in a WApplication if ( content instanceof WApplication ) { model . wrappedContent = ( WApplication ) content ; } else { model . wrappedContent = new WApplication ( ) ; model . wrappedContent . add ( content ) ; } // There should only be one content. holder . removeAll ( ) ; holder . add ( model . wrappedContent ) ; }
Set the WComponent that will handle the content for this pop up window .
155
15
19,142
public void setTitle ( final String title ) { String currTitle = getTitle ( ) ; if ( ! Objects . equals ( title , currTitle ) ) { getOrCreateComponentModel ( ) . title = title ; } }
Sets the window title .
49
6
19,143
public String getUrl ( ) { Environment env = getEnvironment ( ) ; Map < String , String > parameters = env . getHiddenParameters ( ) ; parameters . put ( WWINDOW_REQUEST_PARAM_KEY , getId ( ) ) ; // Override the step count with WWindow step parameters . put ( Environment . STEP_VARIABLE , String . valueOf ( getStep ( ) ) ) ; String url = env . getWServletPath ( ) ; return WebUtilities . getPath ( url , parameters , true ) ; }
Returns a dynamic URL that this wwindow component can be accessed from .
117
14
19,144
@ Override protected void preparePaintComponent ( final Request request ) { super . preparePaintComponent ( request ) ; // Check if window in request (might not have gone through handle request, eg Step error) boolean targeted = isPresent ( request ) ; setTargeted ( targeted ) ; if ( getState ( ) == ACTIVE_STATE && isTargeted ( ) ) { getComponentModel ( ) . wrappedContent . preparePaint ( request ) ; } }
Override preparePaintComponent to clear the scratch map before the window content is being painted .
97
18
19,145
@ Override protected void paintComponent ( final RenderContext renderContext ) { if ( getState ( ) == DISPLAY_STATE ) { setState ( ACTIVE_STATE ) ; showWindow ( renderContext ) ; } else if ( getState ( ) == ACTIVE_STATE && isTargeted ( ) ) { getComponentModel ( ) . wrappedContent . paint ( renderContext ) ; } }
Override paintComponent in order to paint the window or its content depending on the window state .
82
18
19,146
protected void showWindow ( final RenderContext renderContext ) { // Get current step int current = UIContextHolder . getCurrent ( ) . getEnvironment ( ) . getStep ( ) ; // Get window current step (may have already been launched) int window = getStep ( ) ; // Combine step counts to make previous window (if still open) invalid setStep ( window + current ) ; // TODO: This should be in a renderer, not included in this class if ( renderContext instanceof WebXmlRenderContext ) { PrintWriter writer = ( ( WebXmlRenderContext ) renderContext ) . getWriter ( ) ; writer . print ( "\n<ui:popup" ) ; writer . print ( " url=\"" + WebUtilities . encode ( getUrl ( ) ) + ' ' ) ; writer . print ( " width=\"" + getWidth ( ) + ' ' ) ; writer . print ( " height=\"" + getHeight ( ) + ' ' ) ; if ( isResizable ( ) ) { writer . print ( " resizable=\"true\"" ) ; } if ( isScrollable ( ) ) { writer . print ( " showScrollbars=\"true\"" ) ; } if ( isShowMenuBar ( ) ) { writer . print ( " showMenubar=\"true\"" ) ; } if ( isShowToolbar ( ) ) { writer . print ( " showToolbar=\"true\"" ) ; } if ( isShowLocation ( ) ) { writer . print ( " showLocation=\"true\"" ) ; } if ( isShowStatus ( ) ) { writer . print ( " showStatus=\"true\"" ) ; } if ( getTop ( ) >= 0 ) { writer . print ( " top=\"" + getTop ( ) + ' ' ) ; } if ( getLeft ( ) >= 0 ) { writer . print ( " left=\"" + getLeft ( ) + ' ' ) ; } writer . println ( "/>" ) ; } }
Emits the mark - up which pops up the window .
421
12
19,147
@ Override public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WFileWidget fileWidget = ( WFileWidget ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; boolean readOnly = fileWidget . isReadOnly ( ) ; xml . appendTagOpen ( TAG_NAME ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendOptionalAttribute ( "class" , component . getHtmlClass ( ) ) ; xml . appendOptionalAttribute ( "track" , component . isTracking ( ) , "true" ) ; xml . appendOptionalAttribute ( "hidden" , component . isHidden ( ) , "true" ) ; if ( readOnly ) { xml . appendAttribute ( "readOnly" , "true" ) ; xml . appendEnd ( ) ; return ; } xml . appendOptionalAttribute ( "disabled" , fileWidget . isDisabled ( ) , "true" ) ; xml . appendOptionalAttribute ( "required" , fileWidget . isMandatory ( ) , "true" ) ; xml . appendOptionalAttribute ( "toolTip" , fileWidget . getToolTip ( ) ) ; xml . appendOptionalAttribute ( "accessibleText" , fileWidget . getAccessibleText ( ) ) ; xml . appendOptionalAttribute ( "acceptedMimeTypes" , typesToString ( fileWidget . getFileTypes ( ) ) ) ; long maxFileSize = fileWidget . getMaxFileSize ( ) ; xml . appendOptionalAttribute ( "maxFileSize" , maxFileSize > 0 , maxFileSize ) ; List < Diagnostic > diags = fileWidget . getDiagnostics ( Diagnostic . ERROR ) ; if ( diags == null || diags . isEmpty ( ) ) { xml . appendEnd ( ) ; return ; } xml . appendClose ( ) ; DiagnosticRenderUtil . renderDiagnostics ( fileWidget , renderContext ) ; xml . appendEndTag ( TAG_NAME ) ; }
Paints the given WFileWidget .
430
8
19,148
public OrganizationCreateResponse createOrganization ( OrganizationCreate data ) { return getResourceFactory ( ) . getApiResource ( "/org/" ) . entity ( data , MediaType . APPLICATION_JSON_TYPE ) . post ( OrganizationCreateResponse . class ) ; }
Creates a new organization
55
5
19,149
public void updateOrganization ( int orgId , OrganizationCreate data ) { getResourceFactory ( ) . getApiResource ( "/org/" + orgId ) . entity ( data , MediaType . APPLICATION_JSON_TYPE ) . put ( ) ; }
Updates an organization with new name and logo . Note that the URL of the organization will not change even though the name changes .
54
26
19,150
public OrganizationMini getOrganizationByURL ( String url ) { return getResourceFactory ( ) . getApiResource ( "/org/url" ) . queryParam ( "url" , url ) . get ( OrganizationMini . class ) ; }
Returns the organization with the given full URL . The URL does not have to be truncated to the root it can be to any resource on the URL .
51
31
19,151
public List < OrganizationWithSpaces > getSharedOrganizations ( int userId ) { return getResourceFactory ( ) . getApiResource ( "/org/shared/" + userId ) . get ( new GenericType < List < OrganizationWithSpaces > > ( ) { } ) ; }
Returns the organizations and spaces that the logged in user shares with the specified user . The organizations and spaces will be returned sorted by name .
62
27
19,152
public List < Space > getSpaces ( int orgId ) { return getResourceFactory ( ) . getApiResource ( "/org/" + orgId + "/space/" ) . get ( new GenericType < List < Space > > ( ) { } ) ; }
Returns all the spaces for the organization .
56
8
19,153
public EndMemberInfo getEndMemberInfo ( int orgId , int userId ) { return getResourceFactory ( ) . getApiResource ( "/org/" + orgId + "/member/" + userId + "/end_member_info" ) . get ( EndMemberInfo . class ) ; }
Returns information about what would happen if this user would be removed from the org
63
15
19,154
public void setUseCamera ( final boolean useCamera ) { if ( useCamera != getUseCamera ( ) ) { ImageEditModel model = getOrCreateComponentModel ( ) ; model . useCamera = useCamera ; } }
Set to true if you wish to allow the user to capture an image from an attached camera . This feature is completely dependent on browser support and will essentially be ignored if the browser does not provide the necessary APIs .
47
42
19,155
public void setIsFace ( final boolean isFace ) { if ( isFace != getIsFace ( ) ) { ImageEditModel model = getOrCreateComponentModel ( ) ; model . isFace = isFace ; } }
Set to true to turn on face detection .
47
9
19,156
public void setRenderInline ( final boolean renderInline ) { if ( renderInline != getRenderInline ( ) ) { ImageEditModel model = getOrCreateComponentModel ( ) ; model . renderInline = renderInline ; } }
If true then the image editor will render where it is added in the tree instead of in a popup .
53
21
19,157
@ Override public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WFigure figure = ( WFigure ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; boolean renderChildren = isRenderContent ( figure ) ; xml . appendTagOpen ( "ui:figure" ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendOptionalAttribute ( "class" , component . getHtmlClass ( ) ) ; xml . appendOptionalAttribute ( "track" , component . isTracking ( ) , "true" ) ; if ( FigureMode . LAZY . equals ( figure . getMode ( ) ) ) { xml . appendOptionalAttribute ( "hidden" , ! renderChildren , "true" ) ; } else { xml . appendOptionalAttribute ( "hidden" , component . isHidden ( ) , "true" ) ; } FigureMode mode = figure . getMode ( ) ; if ( mode != null ) { switch ( mode ) { case LAZY : xml . appendAttribute ( "mode" , "lazy" ) ; break ; case EAGER : xml . appendAttribute ( "mode" , "eager" ) ; break ; default : throw new SystemException ( "Unknown figure mode: " + figure . getMode ( ) ) ; } } xml . appendClose ( ) ; // Render margin MarginRendererUtil . renderMargin ( figure , renderContext ) ; if ( renderChildren ) { // Label figure . getDecoratedLabel ( ) . paint ( renderContext ) ; // Content xml . appendTagOpen ( "ui:content" ) ; xml . appendAttribute ( "id" , component . getId ( ) + "-content" ) ; xml . appendClose ( ) ; figure . getContent ( ) . paint ( renderContext ) ; xml . appendEndTag ( "ui:content" ) ; } xml . appendEndTag ( "ui:figure" ) ; }
Paints the given WFigure .
423
7
19,158
@ Override public void preparePaintComponent ( final Request request ) { if ( ! this . isInitialised ( ) || resetButton . isPressed ( ) ) { String preferredState = request . getAppPreferenceParameter ( "example.preferred.state" ) ; stateSelector . setSelected ( preferredState ) ; this . setInitialised ( true ) ; } }
Override preparePaintComponent to set the initial selection from the app preferences . The selection is set the first time the example is accessed or when the reset button is used .
81
34
19,159
public void addColumn ( final WTableColumn column ) { columns . add ( column ) ; WDataTableRowRenderer renderer = ( WDataTableRowRenderer ) repeater . getRepeatedComponent ( ) ; renderer . addColumn ( column , columns . getChildCount ( ) - 1 ) ; }
Adds a column to the table .
68
7
19,160
public void setDataModel ( final TableDataModel dataModel ) { getOrCreateComponentModel ( ) . dataModel = dataModel ; getOrCreateComponentModel ( ) . rowIndexMapping = null ; if ( dataModel instanceof BeanTableDataModel ) { ( ( BeanTableDataModel ) dataModel ) . setBeanProvider ( new DataTableBeanProvider ( this ) ) ; ( ( BeanTableDataModel ) dataModel ) . setBeanProperty ( "." ) ; } if ( dataModel instanceof ScrollableTableDataModel ) { int startIndex = getCurrentPage ( ) * getRowsPerPage ( ) ; int endIndex = startIndex + getRowsPerPage ( ) - 1 ; ( ( ScrollableTableDataModel ) dataModel ) . setCurrentRows ( startIndex , endIndex ) ; } // Flush the repeater's row contexts and scratch maps repeater . reset ( ) ; }
Sets the data model .
196
6
19,161
public void setPaginationMode ( final PaginationMode paginationMode ) { getOrCreateComponentModel ( ) . paginationMode = PaginationMode . SERVER . equals ( paginationMode ) ? PaginationMode . DYNAMIC : paginationMode ; }
Sets the pagination mode . Mode . SERVER mapped to Mode . DYNAMIC to overcome accessibility problem .
57
24
19,162
public void setExpandMode ( final ExpandMode expandMode ) { getOrCreateComponentModel ( ) . expandMode = ExpandMode . SERVER . equals ( expandMode ) ? ExpandMode . DYNAMIC : expandMode ; }
Sets the row expansion mode . ExpandMode . SERVER mapped to ExpandMode . DYNAMIC to overcome accessibility problems .
49
26
19,163
@ Override public void handleRequest ( final Request request ) { super . handleRequest ( request ) ; if ( isPresent ( request ) ) { if ( getExpandMode ( ) != ExpandMode . NONE ) { handleExpansionRequest ( request ) ; } if ( getSelectMode ( ) != SelectMode . NONE ) { handleSelectionRequest ( request ) ; } if ( getPaginationMode ( ) != PaginationMode . NONE ) { handlePaginationRequest ( request ) ; } if ( isFilterable ( ) ) { handleFilterRequest ( request ) ; } if ( isSortable ( ) ) { handleSortRequest ( request ) ; } } }
Override handleRequest to add table - specific functionality such as pagination and row selection .
143
17
19,164
private void handleFilterRequest ( final Request request ) { String [ ] paramValues = request . getParameterValues ( getId ( ) + ".filters" ) ; if ( paramValues == null ) { setActiveFilters ( new ArrayList < String > ( 0 ) ) ; } else { List < String > filters = Arrays . asList ( paramValues ) ; setActiveFilters ( filters ) ; } }
Handles a request containing filtering data .
87
8
19,165
private int getCurrentPageStartRow ( ) { int startRow = 0 ; if ( getPaginationMode ( ) != PaginationMode . NONE ) { int rowsPerPage = getRowsPerPage ( ) ; TableDataModel model = getDataModel ( ) ; if ( model instanceof TreeTableDataModel ) { // For tree tables, pagination only occurs on first-level nodes (ie. those // underneath the root node), however they might not be consecutively // numbered. Therefore, the start and end row indices need to be adjusted. TreeTableDataModel treeModel = ( TreeTableDataModel ) model ; TreeNode root = treeModel . getNodeAtLine ( 0 ) . getRoot ( ) ; int startNode = getCurrentPage ( ) * rowsPerPage ; startRow = ( ( TableTreeNode ) root . getChildAt ( startNode ) ) . getRowIndex ( ) - 1 ; // -1 as the root is not included in the table } else { startRow = getCurrentPage ( ) * rowsPerPage ; } } return startRow ; }
Retrieves the starting row index for the current page . Will always return zero for tables which are not paginated .
228
24
19,166
private int getCurrentPageEndRow ( ) { TableDataModel model = getDataModel ( ) ; int rowsPerPage = getRowsPerPage ( ) ; int endRow = model . getRowCount ( ) - 1 ; if ( getPaginationMode ( ) != PaginationMode . NONE ) { if ( model instanceof TreeTableDataModel ) { // For tree tables, pagination only occurs on first-level nodes (ie. those // underneath the root node), however they might not be consecutively // numbered. Therefore, the start and end row indices need to be adjusted. TreeTableDataModel treeModel = ( TreeTableDataModel ) model ; TreeNode root = treeModel . getNodeAtLine ( 0 ) . getRoot ( ) ; int endNode = Math . min ( root . getChildCount ( ) - 1 , ( getCurrentPage ( ) + 1 ) * rowsPerPage - 1 ) ; endRow = ( ( TableTreeNode ) root . getChildAt ( endNode ) ) . getRowIndex ( ) - 1 // -1 as the root is not included in the table + ( ( TableTreeNode ) root . getChildAt ( endNode ) ) . getNodeCount ( ) ; } else { endRow = Math . min ( model . getRowCount ( ) - 1 , ( getCurrentPage ( ) + 1 ) * rowsPerPage - 1 ) ; } } return endRow ; }
Retrieves the ending row index for the current page . Will always return the row count minus 1 for tables which are not paginated .
301
28
19,167
@ Override protected void paintComponent ( final RenderContext renderContext ) { if ( renderContext instanceof WebXmlRenderContext ) { PrintWriter writer = ( ( WebXmlRenderContext ) renderContext ) . getWriter ( ) ; writer . println ( getMessage ( ) ) ; if ( developerFriendly ) { writer . println ( "<pre style=\"background: lightgrey\">" ) ; writer . println ( "Additional details for the developer:" ) ; writer . println ( ) ; error . printStackTrace ( writer ) ; writer . println ( "</pre>" ) ; } } }
Renders this FatalErrorPage .
124
7
19,168
public void setText ( final String text , final Serializable ... args ) { Serializable currText = getComponentModel ( ) . text ; Serializable textToBeSet = I18nUtilities . asMessage ( text , args ) ; if ( ! Objects . equals ( textToBeSet , currText ) ) { getOrCreateComponentModel ( ) . text = textToBeSet ; } }
Sets the label s text .
86
7
19,169
public void setHint ( final String hint , final Serializable ... args ) { Serializable currHint = getComponentModel ( ) . hint ; Serializable hintToBeSet = I18nUtilities . asMessage ( hint , args ) ; if ( ! Objects . equals ( hintToBeSet , currHint ) ) { getOrCreateComponentModel ( ) . hint = hintToBeSet ; } }
Sets the label hint text which can be used to provide additional information to the user .
89
18
19,170
public void setForComponent ( final WComponent forComponent ) { getOrCreateComponentModel ( ) . forComponent = forComponent ; if ( forComponent instanceof AbstractWComponent ) { ( ( AbstractWComponent ) forComponent ) . setLabel ( this ) ; } }
Sets the component that this label is associated with .
56
11
19,171
@ Override protected void preparePaintComponent ( final Request request ) { if ( ! isInitialised ( ) ) { repeat . setData ( getNames ( ) ) ; setInitialised ( true ) ; } }
Initialise the WRepeater data .
45
8
19,172
private void setupUI ( final String labelText ) { WButton dupBtn = new WButton ( "Duplicate" ) ; dupBtn . setAction ( new DuplicateAction ( ) ) ; WButton clrBtn = new WButton ( "Clear" ) ; clrBtn . setAction ( new ClearAction ( ) ) ; add ( new WLabel ( labelText , textFld ) ) ; add ( textFld ) ; add ( dupBtn ) ; add ( clrBtn ) ; add ( new WAjaxControl ( dupBtn , this ) ) ; add ( new WAjaxControl ( clrBtn , this ) ) ; }
Add the controls to the UI .
145
7
19,173
private void addRecentExample ( final String text , final ExampleData data , final boolean select ) { WMenuItem item = new WMenuItem ( text , new SelectExampleAction ( ) ) ; item . setCancel ( true ) ; menu . add ( item ) ; item . setActionObject ( data ) ; if ( select ) { menu . setSelectedMenuItem ( item ) ; } }
Adds an example to the recent subMenu .
83
9
19,174
private ExampleData getMatch ( final WComponent node , final String name , final boolean partial ) { if ( node instanceof WMenuItem ) { ExampleData data = ( ExampleData ) ( ( WMenuItem ) node ) . getActionObject ( ) ; Class < ? extends WComponent > clazz = data . getExampleClass ( ) ; if ( clazz . getName ( ) . equals ( name ) || data . getExampleName ( ) . equals ( name ) || ( partial && clazz . getSimpleName ( ) . toLowerCase ( ) . contains ( name . toLowerCase ( ) ) ) || ( partial && data . getExampleName ( ) . toLowerCase ( ) . contains ( name . toLowerCase ( ) ) ) ) { return data ; } } else if ( node instanceof Container ) { for ( int i = 0 ; i < ( ( Container ) node ) . getChildCount ( ) ; i ++ ) { ExampleData result = getMatch ( ( ( Container ) node ) . getChildAt ( i ) , name , partial ) ; if ( result != null ) { return result ; } } } return null ; }
Recursively searches the menu for a match to a WComponent with the given name .
242
18
19,175
private void loadRecentList ( ) { recent . clear ( ) ; File file = new File ( RECENT_FILE_NAME ) ; if ( file . exists ( ) ) { try { InputStream inputStream = new BufferedInputStream ( new FileInputStream ( file ) ) ; XMLDecoder decoder = new XMLDecoder ( inputStream ) ; List result = ( List ) decoder . readObject ( ) ; decoder . close ( ) ; for ( Object obj : result ) { if ( obj instanceof ExampleData ) { recent . add ( ( ExampleData ) obj ) ; } } } catch ( IOException ex ) { LogFactory . getLog ( getClass ( ) ) . error ( "Unable to load recent list" , ex ) ; } } }
Reads the list of recently selected examples from a file on the file system .
162
16
19,176
private void storeRecentList ( ) { synchronized ( recent ) { try { OutputStream out = new BufferedOutputStream ( new FileOutputStream ( RECENT_FILE_NAME ) ) ; XMLEncoder encoder = new XMLEncoder ( out ) ; encoder . writeObject ( recent ) ; encoder . close ( ) ; } catch ( IOException ex ) { LogFactory . getLog ( getClass ( ) ) . error ( "Unable to save recent list" , ex ) ; } } }
Writes the list of recent selections to a file on the file system .
110
15
19,177
public void addToRecent ( final ExampleData example ) { synchronized ( recent ) { recent . remove ( example ) ; // only add it once recent . add ( 0 , example ) ; // Only keep the last few entries. while ( recent . size ( ) > MAX_RECENT_ITEMS ) { recent . remove ( MAX_RECENT_ITEMS ) ; } storeRecentList ( ) ; setInitialised ( false ) ; } }
Adds an example to the list of recently accessed examples . The list of recently examples will be persisted to the file system .
92
24
19,178
private void updateRecentMenu ( ) { menu . removeAllMenuItems ( ) ; int index = 1 ; boolean first = true ; for ( Iterator < ExampleData > i = recent . iterator ( ) ; i . hasNext ( ) ; ) { ExampleData data = i . next ( ) ; try { StringBuilder builder = new StringBuilder ( Integer . toString ( index ++ ) ) . append ( ". " ) ; if ( data . getExampleGroupName ( ) != null ) { builder . append ( data . getExampleGroupName ( ) ) . append ( " - " ) ; } builder . append ( data . getExampleName ( ) ) ; addRecentExample ( builder . toString ( ) , data , first ) ; first = false ; } catch ( Exception e ) { i . remove ( ) ; LogFactory . getLog ( getClass ( ) ) . error ( "Unable to read recent class: " + data . getExampleName ( ) ) ; } } }
Updates the entries in the Recent sub - menu .
206
11
19,179
public void setContent ( final WComponent content ) { WComponent oldContent = getContent ( ) ; if ( oldContent != null ) { remove ( oldContent ) ; } if ( content != null ) { add ( content ) ; } }
Sets the tab content .
50
6
19,180
@ Override protected void preparePaintComponent ( final Request request ) { super . preparePaintComponent ( request ) ; WComponent content = getContent ( ) ; if ( content != null ) { switch ( getMode ( ) ) { case EAGER : { // Will always be visible content . setVisible ( true ) ; AjaxHelper . registerContainer ( getId ( ) , getId ( ) + "-content" , content . getId ( ) ) ; break ; } case LAZY : { content . setVisible ( isOpen ( ) ) ; if ( ! isOpen ( ) ) { AjaxHelper . registerContainer ( getId ( ) , getId ( ) + "-content" , content . getId ( ) ) ; } break ; } case DYNAMIC : { content . setVisible ( isOpen ( ) ) ; AjaxHelper . registerContainer ( getId ( ) , getId ( ) + "-content" , content . getId ( ) ) ; break ; } case SERVER : { content . setVisible ( isOpen ( ) ) ; break ; } case CLIENT : { // Will always be visible content . setVisible ( true ) ; break ; } default : // do nothing. break ; } } }
Override preparePaintComponent in order to correct the visibility of the tab s content before it is rendered .
261
21
19,181
public SpaceCreateResponse createSpace ( SpaceCreate data ) { return getResourceFactory ( ) . getApiResource ( "/space/" ) . entity ( data , MediaType . APPLICATION_JSON_TYPE ) . post ( SpaceCreateResponse . class ) ; }
Add a new space to an organization .
54
8
19,182
public void updateSpace ( int spaceId , SpaceUpdate data ) { getResourceFactory ( ) . getApiResource ( "/space/" + spaceId ) . entity ( data , MediaType . APPLICATION_JSON_TYPE ) . put ( ) ; }
Updates the space with the given id
53
8
19,183
public SpaceWithOrganization getSpaceByURL ( String url ) { return getResourceFactory ( ) . getApiResource ( "/space/url" ) . queryParam ( "url" , url ) . get ( SpaceWithOrganization . class ) ; }
Returns the space and organization with the given full URL .
54
11
19,184
public SpaceMember getSpaceMembership ( int spaceId , int userId ) { return getResourceFactory ( ) . getApiResource ( "/space/" + spaceId + "/member/" + userId ) . get ( SpaceMember . class ) ; }
Used to get the details of an active users membership of a space .
53
14
19,185
public void updateSpaceMembership ( int spaceId , int userId , Role role ) { getResourceFactory ( ) . getApiResource ( "/space/" + spaceId + "/member/" + userId ) . entity ( new SpaceMemberUpdate ( role ) , MediaType . APPLICATION_JSON_TYPE ) . put ( ) ; }
Updates a space membership with another role
71
8
19,186
public List < SpaceMember > getActiveMembers ( int spaceId ) { return getResourceFactory ( ) . getApiResource ( "/space/" + spaceId + "/member/" ) . get ( new GenericType < List < SpaceMember > > ( ) { } ) ; }
Returns the active members of the given space .
58
9
19,187
public List < SpaceMember > getEndedMembers ( int spaceId ) { return getResourceFactory ( ) . getApiResource ( "/space/" + spaceId + "/member/ended/" ) . get ( new GenericType < List < SpaceMember > > ( ) { } ) ; }
Returns a list of the members that have been removed from the space .
61
14
19,188
public List < SpaceWithOrganization > getTopSpaces ( Integer limit ) { WebResource resource = getResourceFactory ( ) . getApiResource ( "/space/top/" ) ; if ( limit != null ) { resource = resource . queryParam ( "limit" , limit . toString ( ) ) ; } return resource . get ( new GenericType < List < SpaceWithOrganization > > ( ) { } ) ; }
Returns the top spaces for the user
90
7
19,189
public static void registerList ( final String key , final Request request ) { request . setSessionAttribute ( DATA_LIST_UIC_SESSION_KEY , UIContextHolder . getCurrentPrimaryUIContext ( ) ) ; }
Registers a data list with the servlet .
52
10
19,190
public static UIContext getContext ( final String key , final Request request ) { return ( UIContext ) request . getSessionAttribute ( DATA_LIST_UIC_SESSION_KEY ) ; }
Retrieves the UIContext for the given data list .
45
14
19,191
public static List < ComponentWithContext > collateVisibles ( final WComponent comp ) { final List < ComponentWithContext > list = new ArrayList <> ( ) ; WComponentTreeVisitor visitor = new WComponentTreeVisitor ( ) { @ Override public VisitorResult visit ( final WComponent comp ) { // In traversing the tree, special components like WInvisbleContainer, WRepeatRoot are still traversed // (so ignore them) if ( comp . isVisible ( ) ) { list . add ( new ComponentWithContext ( comp , UIContextHolder . getCurrent ( ) ) ) ; } return VisitorResult . CONTINUE ; } } ; traverseVisible ( comp , visitor ) ; return list ; }
Obtains a list of components which are visible in the given tree . Repeated components will be returned multiple times one for each row which they are visible in .
157
32
19,192
public static WComponent getRoot ( final UIContext uic , final WComponent comp ) { UIContextHolder . pushContext ( uic ) ; try { return WebUtilities . getTop ( comp ) ; } finally { UIContextHolder . popContext ( ) ; } }
Retrieves the root component of a WComponent hierarchy .
65
12
19,193
public static List < ComponentWithContext > findComponentsByClass ( final WComponent root , final String className , final boolean includeRoot , final boolean visibleOnly ) { FindComponentsByClassVisitor visitor = new FindComponentsByClassVisitor ( root , className , includeRoot ) ; doTraverse ( root , visibleOnly , visitor ) ; return visitor . getResult ( ) == null ? Collections . EMPTY_LIST : visitor . getResult ( ) ; }
Search for components implementing a particular class name .
99
9
19,194
public static WComponent getComponentWithId ( final WComponent root , final String id , final boolean visibleOnly ) { ComponentWithContext comp = getComponentWithContextForId ( root , id , visibleOnly ) ; return comp == null ? null : comp . getComponent ( ) ; }
Retrieves the component with the given Id .
59
10
19,195
public static UIContext getClosestContextForId ( final WComponent root , final String id , final boolean visibleOnly ) { FindComponentByIdVisitor visitor = new FindComponentByIdVisitor ( id ) { @ Override public VisitorResult visit ( final WComponent comp ) { VisitorResult result = super . visit ( comp ) ; if ( result == VisitorResult . CONTINUE ) { // Save closest UIC as processing tree setResult ( new ComponentWithContext ( comp , UIContextHolder . getCurrent ( ) ) ) ; } return result ; } } ; doTraverse ( root , visibleOnly , visitor ) ; return visitor . getResult ( ) == null ? null : visitor . getResult ( ) . getContext ( ) ; }
Retrieves the closest context for the component with the given Id .
161
14
19,196
private static VisitorResult doTraverse ( final WComponent node , final boolean visibleOnly , final WComponentTreeVisitor visitor ) { if ( visibleOnly ) { // Push through Invisible Containers // Certain components have their visibility altered to implement custom processing. if ( node instanceof WInvisibleContainer ) { WComponent parent = node . getParent ( ) ; // If inside a CardManager, skip the InvisibleContainer and process the visible card. if ( parent instanceof WCardManager ) { WComponent visible = ( ( WCardManager ) node . getParent ( ) ) . getVisible ( ) ; if ( visible == null ) { return VisitorResult . ABORT_BRANCH ; } return doTraverse ( visible , visibleOnly , visitor ) ; } else if ( parent instanceof WWindow ) { // If inside a WWindow, only process if it is Active // Abort branch if WWindow is not in ACTIVE state if ( ( ( WWindow ) parent ) . getState ( ) != WWindow . ACTIVE_STATE ) { return VisitorResult . ABORT_BRANCH ; } } } else if ( node instanceof WRepeatRoot ) { // Let be processed. } else if ( ! node . isVisible ( ) ) { // For most components, we just need to see if they're marked as visible return VisitorResult . ABORT_BRANCH ; } } VisitorResult result = visitor . visit ( node ) ; switch ( result ) { case ABORT_BRANCH : // Continue processing, but not down this branch return VisitorResult . CONTINUE ; case CONTINUE : // Process repeater rows if ( node instanceof WRepeater ) { // Get parent repeater WRepeater repeater = ( WRepeater ) node ; // Get row contexts List < UIContext > rowContextList = repeater . getRowContexts ( ) ; WRepeatRoot repeatRoot = ( WRepeatRoot ) repeater . getRepeatedComponent ( ) . getParent ( ) ; for ( UIContext rowContext : rowContextList ) { UIContextHolder . pushContext ( rowContext ) ; try { result = doTraverse ( repeatRoot , visibleOnly , visitor ) ; } finally { UIContextHolder . popContext ( ) ; } if ( VisitorResult . ABORT . equals ( result ) ) { return VisitorResult . ABORT ; } } } else if ( node instanceof Container ) { Container container = ( Container ) node ; for ( int i = 0 ; i < container . getChildCount ( ) ; i ++ ) { result = doTraverse ( container . getChildAt ( i ) , visibleOnly , visitor ) ; if ( VisitorResult . ABORT . equals ( result ) ) { return VisitorResult . ABORT ; } } } return VisitorResult . CONTINUE ; default : // Abort entire traversal return VisitorResult . ABORT ; } }
Internal implementation of tree traversal method .
622
8
19,197
public void setText ( final String text , final Serializable ... args ) { getOrCreateComponentModel ( ) . text = I18nUtilities . asMessage ( text , args ) ; }
Sets the text displayed on the link .
41
9
19,198
@ Override public void handleRequest ( final Request request ) { // Check if this link was the AJAX Trigger AjaxOperation operation = AjaxHelper . getCurrentOperation ( ) ; boolean pressed = ( operation != null && getId ( ) . equals ( operation . getTriggerId ( ) ) ) ; // Protect against client-side tampering of disabled/read-only fields. if ( isDisabled ( ) && pressed ) { LOG . warn ( "A disabled link has been triggered. " + getText ( ) + ". " + getId ( ) ) ; return ; } // If an action has been supplied then execute it, but only after // handle request has been performed on the entire component tree. final Action action = getAction ( ) ; if ( pressed && action != null ) { final ActionEvent event = new ActionEvent ( this , getActionCommand ( ) , getActionObject ( ) ) ; Runnable later = new Runnable ( ) { @ Override public void run ( ) { action . execute ( event ) ; } } ; invokeLater ( later ) ; } }
Override handleRequest in order to perform processing for this component . This implementation checks whether the link has been pressed via the current ajax operation .
225
29
19,199
@ Override protected void preparePaintComponent ( final Request request ) { super . preparePaintComponent ( request ) ; UIContext uic = UIContextHolder . getCurrent ( ) ; // If the link has an action, register it for AJAX final Action action = getAction ( ) ; final AjaxTarget [ ] actionTargets = getActionTargets ( ) ; if ( action != null && uic . getUI ( ) != null ) { // Register AJAX operation if AJAX targets are set, otherwise rely on InternalAjax request if ( actionTargets != null && actionTargets . length > 0 ) { List < String > targetIds = new ArrayList <> ( ) ; for ( AjaxTarget target : actionTargets ) { targetIds . add ( target . getId ( ) ) ; } // Register the action targets AjaxHelper . registerComponents ( targetIds , getId ( ) ) ; } } }
Override preparePaintComponent to register an AJAX operation if this link has an action .
208
18