idx
int64
0
165k
question
stringlengths
73
4.15k
target
stringlengths
5
918
len_question
int64
21
890
len_target
int64
3
255
18,500
private void buildTargetPanel ( ) { setUpUtilBar ( ) ; panel . add ( utilBar ) ; panel . add ( heading ) ; panel . add ( panelContentRO ) ; panel . add ( menu ) ; }
Set up the target panel contents .
48
7
18,501
private void setUpUtilBar ( ) { utilBar . setLayout ( new ListLayout ( ListLayout . Type . FLAT , ListLayout . Alignment . RIGHT , ListLayout . Separator . NONE , false ) ) ; WTextField selectOther = new WTextField ( ) ; selectOther . setToolTip ( "Enter text." ) ; utilBar . add ( selectOther ) ; utilBar . add ( new WButton ( "Go" ) ) ; utilBar . add ( new WButton ( "A" ) ) ; utilBar . add ( new WButton ( "B" ) ) ; utilBar . add ( new WButton ( "C" ) ) ; utilBar . setVisible ( false ) ; }
Add some UI to a utility bar type structure .
156
10
18,502
@ Override public void serviceRequest ( final Request request ) { // Get trigger id String triggerId = request . getParameter ( WServlet . AJAX_TRIGGER_PARAM_NAME ) ; if ( triggerId == null ) { throw new SystemException ( "No AJAX trigger id to on request" ) ; } // Find the Component for this trigger ComponentWithContext trigger = WebUtilities . getComponentById ( triggerId , true ) ; if ( trigger == null ) { throw new SystemException ( "No component found for AJAX trigger " + triggerId + "." ) ; } WComponent triggerComponent = trigger . getComponent ( ) ; // Check for an internal AJAX request (if client has flagged it as internal) boolean internal = request . getParameter ( WServlet . AJAX_TRIGGER_INTERNAL_PARAM_NAME ) != null ; AjaxOperation ajaxOperation = null ; if ( internal ) { if ( ! ( triggerComponent instanceof AjaxInternalTrigger ) ) { throw new SystemException ( "AJAX trigger [" + triggerId + "] does not support internal actions." ) ; } // Create internal operation ajaxOperation = new AjaxOperation ( triggerId ) ; } else { // Check for a registered AJAX operation ajaxOperation = AjaxHelper . getAjaxOperation ( triggerId ) ; // Override registered operation if it is a GET and trigger supports Internal AJAX // TODO This is only required until all components start using the Internal param flag if ( ajaxOperation != null && "GET" . equals ( request . getMethod ( ) ) && triggerComponent instanceof AjaxInternalTrigger ) { // Create internal operation ajaxOperation = new AjaxOperation ( triggerId ) ; } } // If no operation registered, check if the trigger supports internal AJAX then assume it is an Internal Action if ( ajaxOperation == null && trigger . getComponent ( ) instanceof AjaxInternalTrigger ) { // Create internal operation ajaxOperation = new AjaxOperation ( triggerId ) ; } // No Valid operation if ( ajaxOperation == null ) { throw new SystemException ( "No AJAX operation has been registered for trigger " + triggerId + "." ) ; } // Set current operation AjaxHelper . setCurrentOperationDetails ( ajaxOperation , trigger ) ; // Process Service Request super . serviceRequest ( request ) ; }
Setup the AJAX operation details .
501
7
18,503
@ Override public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WDecoratedLabel label = ( WDecoratedLabel ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; WComponent head = label . getHead ( ) ; WComponent body = label . getBody ( ) ; WComponent tail = label . getTail ( ) ; xml . appendTagOpen ( "ui:decoratedlabel" ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendOptionalAttribute ( "class" , component . getHtmlClass ( ) ) ; xml . appendOptionalAttribute ( "track" , component . isTracking ( ) , "true" ) ; xml . appendOptionalAttribute ( "hidden" , label . isHidden ( ) , "true" ) ; xml . appendClose ( ) ; if ( head != null && head . isVisible ( ) ) { xml . appendTagOpen ( "ui:labelhead" ) ; xml . appendAttribute ( "id" , label . getId ( ) + "-head" ) ; xml . appendClose ( ) ; head . paint ( renderContext ) ; xml . appendEndTag ( "ui:labelhead" ) ; } xml . appendTagOpen ( "ui:labelbody" ) ; xml . appendAttribute ( "id" , label . getId ( ) + "-body" ) ; xml . appendClose ( ) ; body . paint ( renderContext ) ; xml . appendEndTag ( "ui:labelbody" ) ; if ( tail != null && tail . isVisible ( ) ) { xml . appendTagOpen ( "ui:labeltail" ) ; xml . appendAttribute ( "id" , label . getId ( ) + "-tail" ) ; xml . appendClose ( ) ; tail . paint ( renderContext ) ; xml . appendEndTag ( "ui:labeltail" ) ; } xml . appendEndTag ( "ui:decoratedlabel" ) ; }
Paints the given WDecoratedLabel .
435
10
18,504
public List < Comment > getComments ( Reference reference ) { return getResourceFactory ( ) . getApiResource ( "/comment/" + reference . getType ( ) + "/" + reference . getId ( ) ) . get ( new GenericType < List < Comment > > ( ) { } ) ; }
Used to retrieve all the comments that have been made on an object of the given type and with the given id . It returns a list of all the comments sorted in ascending order by time created .
64
39
18,505
public int addComment ( Reference reference , CommentCreate comment , boolean silent , boolean hook ) { return getResourceFactory ( ) . getApiResource ( "/comment/" + reference . getType ( ) + "/" + reference . getId ( ) ) . queryParam ( "silent" , silent ? "1" : "0" ) . queryParam ( "hook" , hook ? "1" : "0" ) . entity ( comment , MediaType . APPLICATION_JSON_TYPE ) . post ( CommentCreateResponse . class ) . getId ( ) ; }
Adds a new comment to the object of the given type and id f . ex . item 1 .
120
20
18,506
public void updateComment ( int commentId , CommentUpdate comment ) { getResourceFactory ( ) . getApiResource ( "/comment/" + commentId ) . entity ( comment , MediaType . APPLICATION_JSON_TYPE ) . put ( ) ; }
Updates an already created comment . This should only be used to correct spelling and grammatical mistakes in the comment .
53
23
18,507
@ Override public void render ( final WComponent component , final RenderContext context ) { PrintWriter out = ( ( WebXmlRenderContext ) context ) . getWriter ( ) ; // If we are debugging the layout, write markers so that the html // designer can see where templates start and end. boolean debugLayout = ConfigurationProperties . getDeveloperVelocityDebug ( ) ; if ( debugLayout ) { String templateUrl = url ; if ( url == null && component instanceof AbstractWComponent ) { templateUrl = ( ( AbstractWComponent ) component ) . getTemplate ( ) ; } out . println ( "<!-- Start " + templateUrl + " -->" ) ; paintXml ( component , out ) ; out . println ( "<!-- End " + templateUrl + " -->" ) ; } else { paintXml ( component , out ) ; } }
Paints the component in HTML using the Velocity Template .
179
11
18,508
public void paintXml ( final WComponent component , final Writer writer ) { if ( LOG . isDebugEnabled ( ) ) { LOG . debug ( "paintXml called for component class " + component . getClass ( ) ) ; } String templateText = null ; if ( component instanceof AbstractWComponent ) { AbstractWComponent abstractComp = ( ( AbstractWComponent ) component ) ; templateText = abstractComp . getTemplateMarkUp ( ) ; } try { Map < String , WComponent > componentsByKey = new HashMap <> ( ) ; VelocityContext context = new VelocityContext ( ) ; fillContext ( component , context , componentsByKey ) ; VelocityWriter velocityWriter = new VelocityWriter ( writer , componentsByKey , UIContextHolder . getCurrent ( ) ) ; if ( templateText != null ) { VelocityEngine engine = VelocityEngineFactory . getVelocityEngine ( ) ; engine . evaluate ( context , velocityWriter , component . getClass ( ) . getSimpleName ( ) , templateText ) ; } else { Template template = getTemplate ( component ) ; if ( template == null ) { LOG . warn ( "VelocityRenderer invoked for a component with no template: " + component . getClass ( ) . getName ( ) ) ; } else { template . merge ( context , velocityWriter ) ; } } velocityWriter . close ( ) ; if ( component instanceof VelocityProperties ) { ( ( VelocityProperties ) component ) . mapUsed ( ) ; } } catch ( ResourceNotFoundException rnfe ) { LOG . error ( "Could not find template '" + url + "' for component " + component . getClass ( ) . getName ( ) , rnfe ) ; } catch ( ParseErrorException pee ) { // syntax error : problem parsing the template LOG . error ( "Parse problems" , pee ) ; } catch ( MethodInvocationException mie ) { // something invoked in the template // threw an exception Throwable wrapped = mie . getWrappedThrowable ( ) ; LOG . error ( "Problems with velocity" , mie ) ; if ( wrapped != null ) { LOG . error ( "Wrapped exception..." , wrapped ) ; } } catch ( Exception e ) { LOG . error ( "Problems with velocity" , e ) ; } }
Paints the component in XML using the Velocity Template .
489
11
18,509
private void fillContext ( final WComponent component , final VelocityContext context , final Map < String , WComponent > componentsByKey ) { // Also make the component available under the "this" key. context . put ( "this" , component ) ; // Make the UIContext available under the "uicontext" key. UIContext uic = UIContextHolder . getCurrent ( ) ; context . put ( "uicontext" , uic ) ; context . put ( "uic" , uic ) ; if ( component instanceof VelocityProperties ) { Map < ? , ? > map = ( ( VelocityProperties ) component ) . getVelocityMap ( ) ; for ( Map . Entry < ? , ? > entry : map . entrySet ( ) ) { String key = ( String ) entry . getKey ( ) ; Object value = entry . getValue ( ) ; context . put ( key , value ) ; } } if ( LOG . isDebugEnabled ( ) ) { LOG . debug ( "Handling children" ) ; } // As well as going into their own named slots, visible children are also // placed into a list called children ArrayList < String > children = new ArrayList <> ( ) ; if ( component instanceof Container ) { Container container = ( Container ) component ; for ( int i = 0 ; i < container . getChildCount ( ) ; i ++ ) { WComponent child = container . getChildAt ( i ) ; String tag = child . getTag ( ) ; if ( tag != null || child . isVisible ( ) ) { // The key needs to be something which would never be output by a Velocity template. String key = "<VelocityLayout" + child . getId ( ) + "/>" ; componentsByKey . put ( key , child ) ; if ( tag != null ) { if ( LOG . isDebugEnabled ( ) ) { LOG . debug ( "Adding child " + tag + " to context" ) ; } addToContext ( context , tag , key ) ; } if ( child . isVisible ( ) ) { children . add ( key ) ; } } } context . put ( "children" , children ) ; } // Put the context in the context context . put ( "context" , context ) ; }
Fills the given velocity context with data from the component which is being rendered . A map of components is also built up in order to support deferred rendering .
485
31
18,510
@ Deprecated protected void noTemplatePaintHtml ( final WComponent component , final Writer writer ) { try { writer . write ( "<!-- Start " + url + " not found -->\n" ) ; new VelocityRenderer ( NO_TEMPLATE_LAYOUT ) . paintXml ( component , writer ) ; writer . write ( "<!-- End " + url + " (template not found) -->\n" ) ; } catch ( IOException e ) { LOG . error ( "Failed to paint component" , e ) ; } }
Paints the component in HTML using the NoTemplateLayout .
119
12
18,511
private Template getTemplate ( final WComponent component ) { String templateUrl = url ; if ( templateUrl == null && component instanceof AbstractWComponent ) { templateUrl = ( ( AbstractWComponent ) component ) . getTemplate ( ) ; } if ( templateUrl != null ) { try { return VelocityEngineFactory . getVelocityEngine ( ) . getTemplate ( templateUrl ) ; } catch ( Exception ex ) { // If the resource is not available (eg if the template does not // exist), paint using a default layout and inform the user // of what's going on in the html comments. LOG . warn ( "Could not open " + templateUrl , ex ) ; try { return VelocityEngineFactory . getVelocityEngine ( ) . getTemplate ( NO_TEMPLATE_LAYOUT ) ; } catch ( Exception e ) { LOG . error ( "Failed to read no template layout" , e ) ; } } } return null ; }
Retrieves the Velocity template for the given component .
199
11
18,512
public List < StreamObject > getGlobalStream ( Integer limit , Integer offset , DateTime dateFrom , DateTime dateTo ) { return getStream ( "/stream/" , limit , offset , dateFrom , dateTo ) ; }
Returns the global stream . This includes items and statuses with comments ratings files and edits .
47
18
18,513
public List < StreamObjectV2 > getGlobalStreamV2 ( Integer limit , Integer offset , DateTime dateFrom , DateTime dateTo ) { return getStreamV2 ( "/stream/v2/" , limit , offset , dateFrom , dateTo ) ; }
Returns the global stream . The types of objects in the stream can be either item status or task .
56
20
18,514
public List < StreamObjectV2 > getAppStream ( int appId , Integer limit , Integer offset ) { return getStreamV2 ( "/stream/app/" + appId + "/" , limit , offset , null , null ) ; }
Returns the stream for the app . Is identical to the global stream but only returns objects in the app .
51
21
18,515
@ Override protected void preparePaintComponent ( final Request request ) { super . preparePaintComponent ( request ) ; //To change body of generated methods, choose Tools | Templates. if ( ! isInitialised ( ) ) { setInitialised ( true ) ; setupVideo ( ) ; } }
Set up the initial state of the video component .
63
10
18,516
private void setupVideo ( ) { video . setAutoplay ( cbAutoPlay . isSelected ( ) ) ; video . setLoop ( cbLoop . isSelected ( ) ) ; video . setMuted ( ! cbMute . isDisabled ( ) && cbMute . isSelected ( ) ) ; video . setControls ( cbControls . isSelected ( ) ? WVideo . Controls . PLAY_PAUSE : WVideo . Controls . NATIVE ) ; video . setDisabled ( cbControls . isSelected ( ) && cbDisable . isSelected ( ) ) ; }
Set the video configuration options .
137
6
18,517
@ Override public List < String > getHeadLines ( final String type ) { ArrayList < String > lines = headers . get ( type ) ; return lines == null ? null : Collections . unmodifiableList ( lines ) ; }
Gets the head lines of a specified type .
50
10
18,518
public void append ( final Object text ) { if ( text instanceof Message ) { append ( translate ( text ) , true ) ; } else if ( text != null ) { append ( text . toString ( ) , true ) ; } }
Appends the given text to this XmlStringBuilder . XML values are escaped .
50
17
18,519
public void append ( final String string , final boolean encode ) { if ( encode ) { appendOptional ( WebUtilities . encode ( string ) ) ; } else { // unescaped content still has to be XML compliant. write ( HtmlToXMLUtil . unescapeToXML ( string ) ) ; } }
Appends the string to this XmlStringBuilder . XML values are not escaped .
68
17
18,520
private String translate ( final Object messageObject ) { if ( messageObject instanceof Message ) { Message message = ( Message ) messageObject ; return I18nUtilities . format ( locale , message . getMessage ( ) , ( Object [ ] ) message . getArgs ( ) ) ; } else if ( messageObject != null ) { return I18nUtilities . format ( locale , messageObject . toString ( ) ) ; } return null ; }
Translates the given message into the appropriate user text . This takes the current locale into consideration if set .
94
22
18,521
public static void addFileItem ( final Map < String , FileItem [ ] > files , final String name , final FileItem item ) { if ( files . containsKey ( name ) ) { // This field contains multiple values, append the new value to the existing values. FileItem [ ] oldValues = files . get ( name ) ; FileItem [ ] newValues = new FileItem [ oldValues . length + 1 ] ; System . arraycopy ( oldValues , 0 , newValues , 0 , oldValues . length ) ; newValues [ newValues . length - 1 ] = item ; files . put ( name , newValues ) ; } else { files . put ( name , new FileItem [ ] { item } ) ; } }
Add the file data to the files collection . If a file already exists with the given name then the value for this name will be an array of all registered files .
154
33
18,522
public static void addParameter ( final Map < String , String [ ] > parameters , final String name , final String value ) { if ( parameters . containsKey ( name ) ) { // This field contains multiple values, append the new value to the existing values. String [ ] oldValues = parameters . get ( name ) ; String [ ] newValues = new String [ oldValues . length + 1 ] ; System . arraycopy ( oldValues , 0 , newValues , 0 , oldValues . length ) ; newValues [ newValues . length - 1 ] = value ; parameters . put ( name , newValues ) ; } else { parameters . put ( name , new String [ ] { value } ) ; } }
Add the request parameter to the parameters collection . If a parameter already exists with the given name then the Map will contain an array of all registered values .
147
30
18,523
protected static void renderTagOpen ( final WImage imageComponent , final XmlStringBuilder xml ) { // Check for alternative text on the image String alternativeText = imageComponent . getAlternativeText ( ) ; if ( alternativeText == null ) { alternativeText = "" ; } else { alternativeText = I18nUtilities . format ( null , alternativeText ) ; } xml . appendTagOpen ( "img" ) ; xml . appendAttribute ( "id" , imageComponent . getId ( ) ) ; xml . appendOptionalAttribute ( "class" , imageComponent . getHtmlClass ( ) ) ; xml . appendOptionalAttribute ( "track" , imageComponent . isTracking ( ) , "true" ) ; xml . appendUrlAttribute ( "src" , imageComponent . getTargetUrl ( ) ) ; xml . appendAttribute ( "alt" , alternativeText ) ; xml . appendOptionalAttribute ( "hidden" , imageComponent . isHidden ( ) , "hidden" ) ; // Check for size information on the image Dimension size = imageComponent . getSize ( ) ; if ( size != null ) { if ( size . getHeight ( ) >= 0 ) { xml . appendAttribute ( "height" , size . height ) ; } if ( size . getWidth ( ) >= 0 ) { xml . appendAttribute ( "width" , size . width ) ; } } }
Builds the open tag part of the XML that is the tagname and attributes .
288
17
18,524
public static void issue ( final WComponent comp , final String message ) { String debugMessage = message + ' ' + comp ; if ( ConfigurationProperties . getIntegrityErrorMode ( ) ) { throw new IntegrityException ( debugMessage ) ; } else { LogFactory . getLog ( Integrity . class ) . warn ( debugMessage ) ; } }
Raises an integrity issue .
72
6
18,525
@ Override public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { AbstractWFieldIndicator fieldIndicator = ( AbstractWFieldIndicator ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; WComponent validationTarget = fieldIndicator . getTargetComponent ( ) ; // no need to render an indicator for nothing. // Diagnosables takes care of thieir own messaging. if ( validationTarget == null || ( validationTarget instanceof Diagnosable && ! ( validationTarget instanceof Input ) ) ) { return ; } if ( validationTarget instanceof Input && ! ( ( Input ) validationTarget ) . isReadOnly ( ) ) { return ; } List < Diagnostic > diags = fieldIndicator . getDiagnostics ( ) ; if ( diags != null && ! diags . isEmpty ( ) ) { xml . appendTagOpen ( "ui:fieldindicator" ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendOptionalAttribute ( "track" , component . isTracking ( ) , "true" ) ; switch ( fieldIndicator . getFieldIndicatorType ( ) ) { case INFO : xml . appendAttribute ( "type" , "info" ) ; break ; case WARN : xml . appendAttribute ( "type" , "warn" ) ; break ; case ERROR : xml . appendAttribute ( "type" , "error" ) ; break ; default : throw new SystemException ( "Cannot paint field indicator due to an invalid field indicator type: " + fieldIndicator . getFieldIndicatorType ( ) ) ; } xml . appendAttribute ( "for" , fieldIndicator . getRelatedFieldId ( ) ) ; xml . appendClose ( ) ; for ( Diagnostic diag : diags ) { xml . appendTag ( "ui:message" ) ; xml . appendEscaped ( diag . getDescription ( ) ) ; xml . appendEndTag ( "ui:message" ) ; } xml . appendEndTag ( "ui:fieldindicator" ) ; } }
Paints the given AbstractWFieldIndicator .
447
10
18,526
@ Override protected void preparePaintComponent ( final Request request ) { super . preparePaintComponent ( request ) ; if ( ! isInitialised ( ) ) { // Check project versions for Wcomponents-examples and WComponents match String egVersion = Config . getInstance ( ) . getString ( "wcomponents-examples.version" ) ; String wcVersion = WebUtilities . getProjectVersion ( ) ; if ( egVersion != null && ! egVersion . equals ( wcVersion ) ) { String msg = "WComponents-Examples version (" + egVersion + ") does not match WComponents version (" + wcVersion + ")." ; LOG . error ( msg ) ; messages . addMessage ( new Message ( Message . ERROR_MESSAGE , msg ) ) ; } setInitialised ( true ) ; } }
Override preparePaint in order to set up the resources on first access by a user .
182
18
18,527
public void setInputWidth ( final int inputWidth ) { if ( inputWidth > 100 ) { throw new IllegalArgumentException ( "inputWidth (" + inputWidth + ") cannot be greater than 100 percent." ) ; } getOrCreateComponentModel ( ) . inputWidth = Math . max ( 0 , inputWidth ) ; }
Sets the desired width of the input field as a percentage of the available space .
69
17
18,528
private void setUp ( ) { addExamples ( "AJAX" , ExampleData . AJAX_EXAMPLES ) ; addExamples ( "Form controls" , ExampleData . FORM_CONTROLS ) ; addExamples ( "Feedback and indicators" , ExampleData . FEEDBACK_AND_INDICATORS ) ; addExamples ( "Layout" , ExampleData . LAYOUT_EXAMPLES ) ; addExamples ( "Menus" , ExampleData . MENU_EXAMPLES ) ; addExamples ( "Links" , ExampleData . LINK_EXAMPLES ) ; addExamples ( "Popups / dialogs" , ExampleData . POPUP_EXAMPLES ) ; addExamples ( "Subordinate" , ExampleData . SUBORDINATE_EXAMPLES ) ; addExamples ( "Tabs" , ExampleData . TABSET_EXAMPLES ) ; addExamples ( "Tables" , ExampleData . WTABLE_EXAMPLES ) ; addExamples ( "Validation" , ExampleData . VALIDATION_EXAMPLES ) ; addExamples ( "Other examples (uncategorised)" , ExampleData . MISC_EXAMPLES ) ; addExamples ( "DataTable (deprecated)" , ExampleData . WDATATABLE_EXAMPLES ) ; }
Add the examples as data in the tree .
287
9
18,529
public void addExamples ( final String groupName , final ExampleData [ ] entries ) { data . add ( new ExampleMenuList ( groupName , entries ) ) ; }
Add a set of examples to the WTree .
35
10
18,530
public final ExampleData getSelectedExampleData ( ) { Set < String > allSelectedItems = getSelectedRows ( ) ; if ( allSelectedItems == null || allSelectedItems . isEmpty ( ) ) { return null ; } for ( String selectedItem : allSelectedItems ) { // Only interested in the first selected item as it is a single select list. List < Integer > rowIndex = TreeItemUtil . rowIndexStringToList ( selectedItem ) ; return getTreeModel ( ) . getExampleData ( rowIndex ) ; } return null ; }
Get the example which is selected in the tree .
123
10
18,531
@ Override protected void preparePaintComponent ( final Request request ) { super . preparePaintComponent ( request ) ; if ( ! isInitialised ( ) ) { setInitialised ( true ) ; setTreeModel ( new MenuTreeModel ( data ) ) ; } }
Set the tree model on first use .
57
8
18,532
private WPanel createPanelWithText ( final String title , final String text ) { WPanel panel = new WPanel ( WPanel . Type . CHROME ) ; panel . setTitleText ( title ) ; WText textComponent = new WText ( text ) ; textComponent . setEncodeText ( false ) ; panel . add ( textComponent ) ; return panel ; }
Convenience method to create a WPanel with the given title and text .
78
16
18,533
public void setErrors ( final List < Diagnostic > errors ) { if ( errors != null ) { ValidationErrorsModel model = getOrCreateComponentModel ( ) ; for ( Diagnostic error : errors ) { if ( error . getSeverity ( ) == Diagnostic . ERROR ) { model . errors . add ( error ) ; } } } }
Sets the errors for a given user .
76
9
18,534
public List < GroupedDiagnositcs > getGroupedErrors ( ) { List < GroupedDiagnositcs > grouped = new ArrayList <> ( ) ; Diagnostic previousError = null ; GroupedDiagnositcs group = null ; for ( Diagnostic theError : getErrors ( ) ) { boolean isNewField = ( ( previousError == null ) || ( previousError . getContext ( ) != theError . getContext ( ) ) || ( previousError . getComponent ( ) != theError . getComponent ( ) ) ) ; if ( group == null || isNewField ) { group = new GroupedDiagnositcs ( ) ; grouped . add ( group ) ; } group . addDiagnostic ( theError ) ; previousError = theError ; } return Collections . unmodifiableList ( grouped ) ; }
Groups the errors by their source field .
179
9
18,535
@ Override public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WDateField dateField = ( WDateField ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; boolean readOnly = dateField . isReadOnly ( ) ; Date date = dateField . getDate ( ) ; xml . appendTagOpen ( "ui:datefield" ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendOptionalAttribute ( "class" , component . getHtmlClass ( ) ) ; xml . appendOptionalAttribute ( "track" , component . isTracking ( ) , "true" ) ; xml . appendOptionalAttribute ( "hidden" , dateField . isHidden ( ) , "true" ) ; if ( readOnly ) { xml . appendAttribute ( "readOnly" , "true" ) ; } else { xml . appendOptionalAttribute ( "disabled" , dateField . isDisabled ( ) , "true" ) ; xml . appendOptionalAttribute ( "required" , dateField . isMandatory ( ) , "true" ) ; xml . appendOptionalAttribute ( "toolTip" , dateField . getToolTip ( ) ) ; xml . appendOptionalAttribute ( "accessibleText" , dateField . getAccessibleText ( ) ) ; WComponent submitControl = dateField . getDefaultSubmitButton ( ) ; String submitControlId = submitControl == null ? null : submitControl . getId ( ) ; xml . appendOptionalAttribute ( "buttonId" , submitControlId ) ; Date minDate = dateField . getMinDate ( ) ; Date maxDate = dateField . getMaxDate ( ) ; if ( minDate != null ) { xml . appendAttribute ( "min" , new SimpleDateFormat ( INTERNAL_DATE_FORMAT ) . format ( minDate ) ) ; } if ( maxDate != null ) { xml . appendAttribute ( "max" , new SimpleDateFormat ( INTERNAL_DATE_FORMAT ) . format ( maxDate ) ) ; } String autocomplete = dateField . getAutocomplete ( ) ; xml . appendOptionalAttribute ( "autocomplete" , ! Util . empty ( autocomplete ) , autocomplete ) ; } if ( date != null ) { xml . appendAttribute ( "date" , new SimpleDateFormat ( INTERNAL_DATE_FORMAT ) . format ( date ) ) ; } xml . appendClose ( ) ; if ( date == null ) { xml . appendEscaped ( dateField . getText ( ) ) ; } if ( ! readOnly ) { DiagnosticRenderUtil . renderDiagnostics ( dateField , renderContext ) ; } xml . appendEndTag ( "ui:datefield" ) ; }
Paints the given WDateField .
599
8
18,536
public void updateUser ( UserUpdate update ) { getResourceFactory ( ) . getApiResource ( "/user/" ) . entity ( update , MediaType . APPLICATION_JSON_TYPE ) . put ( ) ; }
Updates the active user . The old and new password can be left out in which case the password will not be changed . If the mail is changed the old password has to be supplied as well .
46
40
18,537
public < T , R > List < T > getProfileField ( ProfileField < T , R > field ) { List < R > values = getResourceFactory ( ) . getApiResource ( "/user/profile/" + field . getName ( ) ) . get ( new GenericType < List < R > > ( ) { } ) ; List < T > formatted = new ArrayList < T > ( ) ; for ( R value : values ) { formatted . add ( field . parse ( value ) ) ; } return formatted ; }
Returns the field of the profile for the given key from the active user .
112
15
18,538
public void updateProfile ( ProfileUpdate profile ) { getResourceFactory ( ) . getApiResource ( "/user/profile/" ) . entity ( profile , MediaType . APPLICATION_JSON_TYPE ) . put ( ) ; }
Updates the fields of an existing profile . All fields must be filled out as any fields not included will not be part of the new revision .
48
29
18,539
public void updateProfile ( ProfileFieldValues values ) { getResourceFactory ( ) . getApiResource ( "/user/profile/" ) . entity ( values , MediaType . APPLICATION_JSON_TYPE ) . put ( ) ; }
Updates the fields of an existing profile . Will only update the fields in the values .
49
18
18,540
public void setProperty ( String key , boolean value ) { getResourceFactory ( ) . getApiResource ( "/user/property/" + key ) . entity ( new PropertyValue ( value ) , MediaType . APPLICATION_JSON_TYPE ) . put ( ) ; }
Sets the value of the property for the active user with the given name . The property is specific to the auth client used .
57
26
18,541
@ Override public final TableTreeNode getNodeAtLine ( final int row ) { TableTreeNode node = root . next ( ) ; // the root node is never used for ( int index = 0 ; node != null && index < row ; index ++ ) { node = node . next ( ) ; } return node ; }
Returns the node at the given line .
68
8
18,542
@ Override public void handleRequest ( final Request request ) { if ( isDisabled ( ) ) { // Protect against client-side tampering of disabled/read-only fields. return ; } if ( isPresent ( request ) ) { List < MenuItemSelectable > selectedItems = new ArrayList <> ( ) ; // Unfortunately, we need to recurse through all the menu/sub-menus findSelections ( request , this , selectedItems ) ; setSelectedMenuItems ( selectedItems ) ; } }
Override handleRequest in order to perform processing specific to WMenu .
108
13
18,543
private void findSelections ( final Request request , final MenuSelectContainer selectContainer , final List < MenuItemSelectable > selections ) { // Don't bother checking disabled or invisible containers if ( ! selectContainer . isVisible ( ) || ( selectContainer instanceof Disableable && ( ( Disableable ) selectContainer ) . isDisabled ( ) ) ) { return ; } // Get any selectable children of this container List < MenuItemSelectable > selectableItems = getSelectableItems ( selectContainer ) ; // Now add the selections (if in the request) for ( MenuItemSelectable selectableItem : selectableItems ) { // Check if the item is on the request if ( request . getParameter ( selectableItem . getId ( ) + ".selected" ) != null ) { selections . add ( selectableItem ) ; if ( SelectionMode . SINGLE . equals ( selectContainer . getSelectionMode ( ) ) ) { // Only select the first item at this level. // We still need to check other levels of the menu for selection. break ; } } } // We need to recurse through and check for other selectable containers for ( MenuItem item : selectContainer . getMenuItems ( ) ) { if ( item instanceof MenuItemGroup ) { for ( MenuItem groupItem : ( ( MenuItemGroup ) item ) . getMenuItems ( ) ) { if ( groupItem instanceof MenuSelectContainer ) { findSelections ( request , ( MenuSelectContainer ) groupItem , selections ) ; } } } else if ( item instanceof MenuSelectContainer ) { findSelections ( request , ( MenuSelectContainer ) item , selections ) ; } } }
Finds the selected items in a menu for a request .
350
12
18,544
private List < MenuItemSelectable > getSelectableItems ( final MenuSelectContainer selectContainer ) { List < MenuItemSelectable > result = new ArrayList <> ( selectContainer . getMenuItems ( ) . size ( ) ) ; SelectionMode selectionMode = selectContainer . getSelectionMode ( ) ; for ( MenuItem item : selectContainer . getMenuItems ( ) ) { if ( item instanceof MenuItemGroup ) { for ( MenuItem groupItem : ( ( MenuItemGroup ) item ) . getMenuItems ( ) ) { if ( isSelectable ( groupItem , selectionMode ) ) { result . add ( ( MenuItemSelectable ) groupItem ) ; } } } else if ( isSelectable ( item , selectionMode ) ) { result . add ( ( MenuItemSelectable ) item ) ; } } return result ; }
Retrieves the selectable items for the given container .
178
12
18,545
private boolean isSelectable ( final MenuItem item , final SelectionMode selectionMode ) { if ( ! ( item instanceof MenuItemSelectable ) || ! item . isVisible ( ) || ( item instanceof Disableable && ( ( Disableable ) item ) . isDisabled ( ) ) ) { return false ; } // SubMenus are only selectable in a column menu type if ( item instanceof WSubMenu && ! MenuType . COLUMN . equals ( getType ( ) ) ) { return false ; } // Item is specificially set to selectable/unselectable Boolean itemSelectable = ( ( MenuItemSelectable ) item ) . getSelectability ( ) ; if ( itemSelectable != null ) { return itemSelectable ; } // Container has selection turned on return SelectionMode . SINGLE . equals ( selectionMode ) || SelectionMode . MULTIPLE . equals ( selectionMode ) ; }
Indicates whether the given menu item is selectable .
194
11
18,546
@ SafeVarargs public final R in ( T ... values ) { expr ( ) . in ( _name , ( Object [ ] ) values ) ; return _root ; }
Is in a list of values .
36
7
18,547
@ Override public void write ( final char [ ] cbuf , final int off , final int len ) throws IOException { if ( buffer == null ) { // Nothing to replace, just pass the data through backing . write ( cbuf , off , len ) ; } else { for ( int i = off ; i < off + len ; i ++ ) { buffer [ bufferLen ++ ] = cbuf [ i ] ; if ( bufferLen == buffer . length ) { writeBuf ( buffer . length / 2 ) ; } } } }
Implementation of Writer s write method .
113
8
18,548
private void writeBuf ( final int endPos ) throws IOException { // If the stream is not closed, we only process half the buffer at once. String searchTerm ; int pos = 0 ; int lastWritePos = 0 ; while ( pos < endPos ) { searchTerm = findSearchStrings ( pos ) ; if ( searchTerm != null ) { if ( lastWritePos != pos ) { backing . write ( buffer , lastWritePos , pos - lastWritePos ) ; } doReplace ( searchTerm , backing ) ; pos += searchTerm . length ( ) ; lastWritePos = pos ; } else { pos ++ ; } } // Write the remaining characters that weren't matched if ( lastWritePos != pos ) { backing . write ( buffer , lastWritePos , pos - lastWritePos ) ; } // Shuffle the buffer System . arraycopy ( buffer , pos , buffer , 0 , buffer . length - pos ) ; bufferLen -= pos ; }
Writes the current contents of the buffer up to the given position . More data may be written from the buffer when there is a search string that crosses over endPos .
202
34
18,549
private String findSearchStrings ( final int start ) { String longestMatch = null ; // Loop for each string for ( int i = 0 ; i < search . length ; i ++ ) { // No point checking a String that's too long if ( start + search [ i ] . length ( ) > bufferLen ) { continue ; } boolean found = true ; // Loop for each character in range for ( int j = 0 ; j < search [ i ] . length ( ) && ( start + j < bufferLen ) ; j ++ ) { int diff = buffer [ start + j ] - search [ i ] . charAt ( j ) ; if ( diff < 0 ) { // Since the strings are all sorted, we can abort if // the character is less than the corresponding character in // the current search string. return longestMatch ; } else if ( diff != 0 ) { found = false ; break ; } } if ( found && ( longestMatch == null || longestMatch . length ( ) < search [ i ] . length ( ) ) ) { longestMatch = search [ i ] ; } } return longestMatch ; }
Searches for any search strings in the buffer that start between the specified offsets .
233
17
18,550
public int createStatus ( int spaceId , StatusCreate status ) { return getResourceFactory ( ) . getApiResource ( "/status/space/" + spaceId + "/" ) . entity ( status , MediaType . APPLICATION_JSON_TYPE ) . post ( StatusCreateResponse . class ) . getId ( ) ; }
Creates a new status message for a user on a specific space . A status update is simply a short text message that the user wishes to share with the rest of the space .
69
36
18,551
public void updateStatus ( int statusId , StatusUpdate update ) { getResourceFactory ( ) . getApiResource ( "/status/" + statusId ) . entity ( update , MediaType . APPLICATION_JSON_TYPE ) . put ( ) ; }
This will update an existing status message . This will normally only be used to correct spelling and grammatical mistakes .
53
22
18,552
@ Override public synchronized void register ( final String key , final WComponent ui ) { if ( isRegistered ( key ) ) { throw new SystemException ( "Cannot re-register a component. Key = " + key ) ; } registry . put ( key , ui ) ; }
Registers the given user interface with the given key .
61
11
18,553
private static Object loadUI ( final String key ) { String classname = key . trim ( ) ; try { Class < ? > clas = Class . forName ( classname ) ; if ( WComponent . class . isAssignableFrom ( clas ) ) { Object instance = clas . newInstance ( ) ; LOG . debug ( "WComponent successfully loaded with class name \"" + classname + "\"." ) ; return instance ; } else { LOG . error ( "The resource with the name \"" + classname + "\" is not a WComponent." ) ; } } catch ( Exception ex ) { LOG . error ( "Unable to load a WComponent using the resource name \"" + classname + "\"" , ex ) ; } return Boolean . FALSE ; }
Attemps to load a ui using the key as a class name .
167
16
18,554
@ Override public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WComponentGroup group = ( WComponentGroup ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; List < WComponent > components = group . getComponents ( ) ; if ( components != null && ! components . isEmpty ( ) ) { xml . appendTagOpen ( "ui:componentGroup" ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendOptionalAttribute ( "track" , component . isTracking ( ) , "true" ) ; xml . appendClose ( ) ; for ( WComponent comp : components ) { xml . appendTagOpen ( "ui:component" ) ; xml . appendAttribute ( "id" , comp . getId ( ) ) ; xml . appendEnd ( ) ; } xml . appendEndTag ( "ui:componentGroup" ) ; } }
Paints the given WComponentGroup .
203
8
18,555
@ Override public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WSection section = ( WSection ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; boolean renderChildren = isRenderContent ( section ) ; xml . appendTagOpen ( "ui:section" ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendOptionalAttribute ( "class" , component . getHtmlClass ( ) ) ; xml . appendOptionalAttribute ( "track" , component . isTracking ( ) , "true" ) ; if ( SectionMode . LAZY . equals ( section . getMode ( ) ) ) { xml . appendOptionalAttribute ( "hidden" , ! renderChildren , "true" ) ; } else { xml . appendOptionalAttribute ( "hidden" , component . isHidden ( ) , "true" ) ; } SectionMode mode = section . 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 section mode: " + section . getMode ( ) ) ; } } xml . appendClose ( ) ; // Render margin MarginRendererUtil . renderMargin ( section , renderContext ) ; if ( renderChildren ) { // Label section . getDecoratedLabel ( ) . paint ( renderContext ) ; // Content section . getContent ( ) . paint ( renderContext ) ; } xml . appendEndTag ( "ui:section" ) ; }
Paints the given WSection .
369
7
18,556
@ Override public void remove ( final WComponent aChild ) { super . remove ( aChild ) ; PanelModel model = getOrCreateComponentModel ( ) ; if ( model . layoutConstraints == null ) { Map < WComponent , Serializable > defaultConstraints = ( ( PanelModel ) getDefaultModel ( ) ) . layoutConstraints ; if ( defaultConstraints != null ) { model . layoutConstraints = new HashMap <> ( defaultConstraints ) ; } } if ( model . layoutConstraints != null ) { model . layoutConstraints . remove ( aChild ) ; // Deallocate constraints list if possible, to reduce session size. if ( model . layoutConstraints . isEmpty ( ) ) { model . layoutConstraints = null ; } } }
Removes the given component from this component s list of children . This method has been overriden to remove any associated layout constraints .
173
27
18,557
public Serializable getLayoutConstraints ( final WComponent child ) { PanelModel model = getComponentModel ( ) ; if ( model . layoutConstraints != null ) { return model . layoutConstraints . get ( child ) ; } return null ; }
Retrieves the layout constraints for the given component if they have been set .
55
16
18,558
@ Override public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WDefinitionList list = ( WDefinitionList ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; xml . appendTagOpen ( "ui:definitionlist" ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendOptionalAttribute ( "class" , component . getHtmlClass ( ) ) ; xml . appendOptionalAttribute ( "track" , component . isTracking ( ) , "true" ) ; switch ( list . getType ( ) ) { case FLAT : xml . appendAttribute ( "type" , "flat" ) ; break ; case COLUMN : xml . appendAttribute ( "type" , "column" ) ; break ; case STACKED : xml . appendAttribute ( "type" , "stacked" ) ; break ; case NORMAL : break ; default : throw new SystemException ( "Unknown layout type: " + list . getType ( ) ) ; } xml . appendClose ( ) ; // Render margin MarginRendererUtil . renderMargin ( list , renderContext ) ; for ( Duplet < String , ArrayList < WComponent > > term : list . getTerms ( ) ) { xml . appendTagOpen ( "ui:term" ) ; xml . appendAttribute ( "text" , I18nUtilities . format ( null , term . getFirst ( ) ) ) ; xml . appendClose ( ) ; for ( WComponent data : term . getSecond ( ) ) { xml . appendTag ( "ui:data" ) ; data . paint ( renderContext ) ; xml . appendEndTag ( "ui:data" ) ; } xml . appendEndTag ( "ui:term" ) ; } xml . appendEndTag ( "ui:definitionlist" ) ; }
Paints the given definition list .
403
7
18,559
private void addAlignedExample ( ) { add ( new WHeading ( HeadingLevel . H2 , "WRow / WCol with column alignment" ) ) ; WRow alignedColsRow = new WRow ( ) ; add ( alignedColsRow ) ; WColumn alignedCol = new WColumn ( ) ; alignedCol . setAlignment ( WColumn . Alignment . LEFT ) ; alignedCol . setWidth ( 25 ) ; alignedColsRow . add ( alignedCol ) ; WPanel box = new WPanel ( Type . BOX ) ; box . add ( new WText ( "Left" ) ) ; alignedCol . add ( box ) ; alignedCol = new WColumn ( ) ; alignedCol . setAlignment ( WColumn . Alignment . CENTER ) ; alignedCol . setWidth ( 25 ) ; alignedColsRow . add ( alignedCol ) ; box = new WPanel ( Type . BOX ) ; box . add ( new WText ( "Center" ) ) ; alignedCol . add ( box ) ; alignedCol = new WColumn ( ) ; alignedCol . setAlignment ( WColumn . Alignment . RIGHT ) ; alignedCol . setWidth ( 25 ) ; alignedColsRow . add ( alignedCol ) ; box = new WPanel ( Type . BOX ) ; box . add ( new WText ( "Right" ) ) ; alignedCol . add ( box ) ; alignedCol = new WColumn ( ) ; alignedCol . setWidth ( 25 ) ; alignedColsRow . add ( alignedCol ) ; box = new WPanel ( Type . BOX ) ; box . add ( new WText ( "Undefined" ) ) ; alignedCol . add ( box ) ; }
Add an example showing column alignment .
361
7
18,560
private WRow createRow ( final int hgap , final int [ ] colWidths ) { WRow row = new WRow ( hgap ) ; for ( int i = 0 ; i < colWidths . length ; i ++ ) { WColumn col = new WColumn ( colWidths [ i ] ) ; WPanel box = new WPanel ( WPanel . Type . BOX ) ; box . add ( new WText ( colWidths [ i ] + "%" ) ) ; col . add ( box ) ; row . add ( col ) ; } return row ; }
Creates a row containing columns with the given widths .
122
12
18,561
@ Override public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WTextField textField = ( WTextField ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; boolean readOnly = textField . isReadOnly ( ) ; xml . appendTagOpen ( "ui:textfield" ) ; 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" ) ; } else { int cols = textField . getColumns ( ) ; int minLength = textField . getMinLength ( ) ; int maxLength = textField . getMaxLength ( ) ; String pattern = textField . getPattern ( ) ; WSuggestions suggestions = textField . getSuggestions ( ) ; String suggestionsId = suggestions == null ? null : suggestions . getId ( ) ; WComponent submitControl = textField . getDefaultSubmitButton ( ) ; String submitControlId = submitControl == null ? null : submitControl . getId ( ) ; xml . appendOptionalAttribute ( "disabled" , textField . isDisabled ( ) , "true" ) ; xml . appendOptionalAttribute ( "required" , textField . isMandatory ( ) , "true" ) ; xml . appendOptionalAttribute ( "minLength" , minLength > 0 , minLength ) ; xml . appendOptionalAttribute ( "maxLength" , maxLength > 0 , maxLength ) ; xml . appendOptionalAttribute ( "toolTip" , textField . getToolTip ( ) ) ; xml . appendOptionalAttribute ( "accessibleText" , textField . getAccessibleText ( ) ) ; xml . appendOptionalAttribute ( "size" , cols > 0 , cols ) ; xml . appendOptionalAttribute ( "buttonId" , submitControlId ) ; xml . appendOptionalAttribute ( "pattern" , ! Util . empty ( pattern ) , pattern ) ; xml . appendOptionalAttribute ( "list" , suggestionsId ) ; String placeholder = textField . getPlaceholder ( ) ; xml . appendOptionalAttribute ( "placeholder" , ! Util . empty ( placeholder ) , placeholder ) ; String autocomplete = textField . getAutocomplete ( ) ; xml . appendOptionalAttribute ( "autocomplete" , ! Util . empty ( autocomplete ) , autocomplete ) ; } xml . appendClose ( ) ; xml . appendEscaped ( textField . getText ( ) ) ; if ( ! readOnly ) { DiagnosticRenderUtil . renderDiagnostics ( textField , renderContext ) ; } xml . appendEndTag ( "ui:textfield" ) ; }
Paints the given WTextField .
643
8
18,562
private String getTag ( final BorderLayoutConstraint constraint ) { switch ( constraint ) { case EAST : return "ui:east" ; case NORTH : return "ui:north" ; case SOUTH : return "ui:south" ; case WEST : return "ui:west" ; case CENTER : default : return "ui:center" ; } }
Retrieves the name of the element that will contain components with the given constraint .
78
17
18,563
private void paintChildrenWithConstraint ( final List < Duplet < WComponent , BorderLayoutConstraint > > children , final WebXmlRenderContext renderContext , final BorderLayoutConstraint constraint ) { String containingTag = null ; XmlStringBuilder xml = renderContext . getWriter ( ) ; final int size = children . size ( ) ; for ( int i = 0 ; i < size ; i ++ ) { Duplet < WComponent , BorderLayoutConstraint > child = children . get ( i ) ; if ( constraint . equals ( child . getSecond ( ) ) ) { if ( containingTag == null ) { containingTag = getTag ( constraint ) ; xml . appendTag ( containingTag ) ; } child . getFirst ( ) . paint ( renderContext ) ; } } if ( containingTag != null ) { xml . appendEndTag ( containingTag ) ; } }
Paints all the child components with the given constraint .
188
11
18,564
@ Override public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WTextArea textArea = ( WTextArea ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; boolean readOnly = textArea . isReadOnly ( ) ; xml . appendTagOpen ( "ui:textarea" ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendOptionalAttribute ( "class" , component . getHtmlClass ( ) ) ; xml . appendOptionalAttribute ( "track" , component . isTracking ( ) , "true" ) ; xml . appendOptionalAttribute ( "hidden" , textArea . isHidden ( ) , "true" ) ; if ( readOnly ) { xml . appendAttribute ( "readOnly" , "true" ) ; } else { int cols = textArea . getColumns ( ) ; int rows = textArea . getRows ( ) ; int minLength = textArea . getMinLength ( ) ; int maxLength = textArea . getMaxLength ( ) ; WComponent submitControl = textArea . getDefaultSubmitButton ( ) ; String submitControlId = submitControl == null ? null : submitControl . getId ( ) ; xml . appendOptionalAttribute ( "disabled" , textArea . isDisabled ( ) , "true" ) ; xml . appendOptionalAttribute ( "required" , textArea . isMandatory ( ) , "true" ) ; xml . appendOptionalAttribute ( "minLength" , minLength > 0 , minLength ) ; xml . appendOptionalAttribute ( "maxLength" , maxLength > 0 , maxLength ) ; xml . appendOptionalAttribute ( "toolTip" , textArea . getToolTip ( ) ) ; xml . appendOptionalAttribute ( "accessibleText" , textArea . getAccessibleText ( ) ) ; xml . appendOptionalAttribute ( "rows" , rows > 0 , rows ) ; xml . appendOptionalAttribute ( "cols" , cols > 0 , cols ) ; xml . appendOptionalAttribute ( "buttonId" , submitControlId ) ; String placeholder = textArea . getPlaceholder ( ) ; xml . appendOptionalAttribute ( "placeholder" , ! Util . empty ( placeholder ) , placeholder ) ; String autocomplete = textArea . getAutocomplete ( ) ; xml . appendOptionalAttribute ( "autocomplete" , ! Util . empty ( autocomplete ) , autocomplete ) ; } xml . appendClose ( ) ; if ( textArea . isRichTextArea ( ) ) { /* * This is a nested element instead of an attribute to cater for future enhancements * such as turning rich text features on or off, or specifying JSON config either as * a URL attribute or a nested CDATA section. */ xml . append ( "<ui:rtf />" ) ; } String textString = textArea . getText ( ) ; if ( textString != null ) { if ( textArea . isReadOnly ( ) && textArea . isRichTextArea ( ) ) { // read only we want to output unescaped, but it must still be XML valid. xml . write ( HtmlToXMLUtil . unescapeToXML ( textString ) ) ; } else { xml . appendEscaped ( textString ) ; } } if ( ! readOnly ) { DiagnosticRenderUtil . renderDiagnostics ( textArea , renderContext ) ; } xml . appendEndTag ( "ui:textarea" ) ; }
Paints the given WTextArea .
752
8
18,565
private StringBuilder extractJavaDoc ( final String source ) { int docStart = source . indexOf ( "/**" ) ; int docEnd = source . indexOf ( "*/" , docStart ) ; int classStart = source . indexOf ( "public class" ) ; int author = source . indexOf ( "@author" ) ; int since = source . indexOf ( "@since" ) ; if ( classStart == - 1 ) { classStart = docEnd ; } if ( docEnd == - 1 || classStart < docStart ) { return new StringBuilder ( "No JavaDoc provided" ) ; } if ( author != - 1 && author < docEnd ) { docEnd = author ; } if ( since != - 1 && since < docEnd ) { docEnd = since ; } return new StringBuilder ( source . substring ( docStart + 3 , docEnd ) . trim ( ) ) ; }
extracts the javadoc . It assumes that the java doc for the class is the first javadoc in the file .
192
29
18,566
private void stripAsterisk ( final StringBuilder javaDoc ) { int index = javaDoc . indexOf ( "*" ) ; while ( index != - 1 ) { javaDoc . replace ( index , index + 1 , "" ) ; index = javaDoc . indexOf ( "*" ) ; } }
This method removes the additional astrisks from the java doc .
65
13
18,567
private String parseLink ( final String link ) { String [ ] tokens = link . substring ( 7 , link . length ( ) - 1 ) . split ( "\\s" ) ; if ( tokens . length == 1 ) { return tokens [ 0 ] ; } StringBuilder result = new StringBuilder ( ) ; boolean parametersSeen = false ; boolean inParameters = false ; for ( int index = 0 ; index < tokens . length ; index ++ ) { result . append ( " " ) . append ( tokens [ index ] ) ; if ( tokens [ index ] . indexOf ( ' ' ) != - 1 && ! parametersSeen ) { inParameters = true ; } if ( index == 1 && ! inParameters ) { result = new StringBuilder ( tokens [ index ] ) ; } if ( tokens [ index ] . indexOf ( ' ' ) != - 1 && ! parametersSeen ) { parametersSeen = true ; if ( index != tokens . length - 1 ) { result = new StringBuilder ( ) ; } } } return result . toString ( ) . trim ( ) ; }
a helper method to process the links as they are found .
228
12
18,568
private WButton newVisibilityToggleForTab ( final int idx ) { WButton toggleButton = new WButton ( "Toggle visibility of tab " + ( idx + 1 ) ) ; toggleButton . setAction ( new Action ( ) { @ Override public void execute ( final ActionEvent event ) { boolean tabVisible = tabset . isTabVisible ( idx ) ; tabset . setTabVisible ( idx , ! tabVisible ) ; } } ) ; return toggleButton ; }
Creates a button to toggle the visibility of a tab .
109
12
18,569
private < T extends Enum < T > > EnumerationRadioButtonSelect < T > createRadioButtonGroup ( final T [ ] options ) { EnumerationRadioButtonSelect < T > rbSelect = new EnumerationRadioButtonSelect <> ( options ) ; rbSelect . setButtonLayout ( EnumerationRadioButtonSelect . Layout . FLAT ) ; rbSelect . setFrameless ( true ) ; return rbSelect ; }
Create a radio button select containing the options .
95
9
18,570
private void displaySelected ( ) { copySelection ( table1 , selected1 ) ; copySelection ( table2 , selected2 ) ; copySelection ( table3 , selected3 ) ; }
Display the rows that have been selected .
42
8
18,571
private BigDecimal convertValue ( final Object value ) { if ( value == null ) { return null ; } else if ( value instanceof BigDecimal ) { return ( BigDecimal ) value ; } // Try and convert "String" value String dataString = value . toString ( ) ; if ( Util . empty ( dataString ) ) { return null ; } try { return new BigDecimal ( dataString ) ; } catch ( NumberFormatException ex ) { throw new SystemException ( "Could not convert data of type " + value . getClass ( ) + " with String value " + dataString + " to BigDecimal" , ex ) ; } }
Attempts to convert a value to a BigDecimal . Throws a SystemException on error .
141
19
18,572
public void setMinValue ( final BigDecimal minValue ) { BigDecimal currMin = getMinValue ( ) ; if ( ! Objects . equals ( minValue , currMin ) ) { getOrCreateComponentModel ( ) . minValue = minValue ; } }
Sets the minimum allowable value for this number field .
59
11
18,573
public void setMaxValue ( final BigDecimal maxValue ) { BigDecimal currMax = getMaxValue ( ) ; if ( ! Objects . equals ( maxValue , currMax ) ) { getOrCreateComponentModel ( ) . maxValue = maxValue ; } }
Sets the maximum allowable value for this number field .
59
11
18,574
@ Override protected void validateComponent ( final List < Diagnostic > diags ) { if ( isValidNumber ( ) ) { super . validateComponent ( diags ) ; validateNumber ( diags ) ; } else { diags . add ( createErrorDiagnostic ( InternalMessages . DEFAULT_VALIDATION_ERROR_INVALID , this ) ) ; } }
Override WInput s validateComponent to perform futher validation on email addresses .
80
15
18,575
private static boolean containsError ( final List < Diagnostic > diags ) { if ( diags == null || diags . isEmpty ( ) ) { return false ; } for ( Diagnostic diag : diags ) { if ( diag . getSeverity ( ) == Diagnostic . ERROR ) { return true ; } } return false ; }
Indicates whether the given list of diagnostics contains any errors .
74
13
18,576
@ Override protected boolean doHandleRequest ( final Request request ) { String value = getRequestValue ( request ) ; String current = getValue ( ) ; boolean changed = ! Util . equals ( value , current ) ; if ( changed ) { setData ( value ) ; } return changed ; }
Override handleRequest in order to perform processing for this component . This implementation updates the text field s text if it has changed .
62
25
18,577
@ Override public void preparePaint ( final Request request ) { UIContext uic = UIContextHolder . getCurrent ( ) ; Headers headers = uic . getUI ( ) . getHeaders ( ) ; headers . reset ( ) ; headers . setContentType ( WebUtilities . CONTENT_TYPE_XML ) ; super . preparePaint ( request ) ; }
Override to set the content type of the response and reset the headers .
86
14
18,578
@ Override public void paint ( final RenderContext renderContext ) { WebXmlRenderContext webRenderContext = ( WebXmlRenderContext ) renderContext ; XmlStringBuilder xml = webRenderContext . getWriter ( ) ; AjaxOperation operation = AjaxHelper . getCurrentOperation ( ) ; if ( operation == null ) { // the request attribute that we place in the ui contenxt in the action phase can't be null throw new SystemException ( "Can't paint AJAX response. Couldn't find the expected reference to the AjaxOperation." ) ; } UIContext uic = UIContextHolder . getCurrent ( ) ; String focusId = uic . getFocussedId ( ) ; xml . append ( XMLUtil . getXMLDeclarationWithThemeXslt ( uic ) ) ; xml . appendTagOpen ( "ui:ajaxresponse" ) ; xml . append ( XMLUtil . STANDARD_NAMESPACES ) ; xml . appendOptionalAttribute ( "defaultFocusId" , uic . isFocusRequired ( ) && ! Util . empty ( focusId ) , focusId ) ; xml . appendClose ( ) ; getBackingComponent ( ) . paint ( renderContext ) ; xml . appendEndTag ( "ui:ajaxresponse" ) ; }
Paints the targeted ajax regions . The format of the response is an agreement between the server and the client side handling our AJAX response .
279
30
18,579
@ Deprecated @ Override public void add ( final WComponent component , final String tag ) { super . add ( component , tag ) ; }
Add the given component as a child of this component . The tag is used to identify the child in this component s velocity template .
30
26
18,580
@ Override public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WAudio audioComponent = ( WAudio ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; Audio [ ] audio = audioComponent . getAudio ( ) ; if ( audio == null || audio . length == 0 ) { return ; } WAudio . Controls controls = audioComponent . getControls ( ) ; int duration = audio [ 0 ] . getDuration ( ) ; // Check for alternative text String alternativeText = audioComponent . getAltText ( ) ; if ( alternativeText == null ) { LOG . warn ( "Audio should have a description." ) ; alternativeText = null ; } else { alternativeText = I18nUtilities . format ( null , alternativeText ) ; } xml . appendTagOpen ( "ui:audio" ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendOptionalAttribute ( "class" , component . getHtmlClass ( ) ) ; xml . appendOptionalAttribute ( "track" , component . isTracking ( ) , "true" ) ; xml . appendOptionalAttribute ( "alt" , alternativeText ) ; xml . appendOptionalAttribute ( "autoplay" , audioComponent . isAutoplay ( ) , "true" ) ; xml . appendOptionalAttribute ( "mediagroup" , audioComponent . getMediaGroup ( ) ) ; xml . appendOptionalAttribute ( "loop" , audioComponent . isLoop ( ) , "true" ) ; xml . appendOptionalAttribute ( "hidden" , audioComponent . isHidden ( ) , "true" ) ; xml . appendOptionalAttribute ( "disabled" , audioComponent . isDisabled ( ) , "true" ) ; xml . appendOptionalAttribute ( "toolTip" , audioComponent . getToolTip ( ) ) ; xml . appendOptionalAttribute ( "duration" , duration > 0 , duration ) ; switch ( audioComponent . getPreload ( ) ) { case NONE : xml . appendAttribute ( "preload" , "none" ) ; break ; case META_DATA : xml . appendAttribute ( "preload" , "metadata" ) ; break ; case AUTO : default : break ; } if ( controls != null && ! WAudio . Controls . NATIVE . equals ( controls ) ) { switch ( controls ) { case NONE : xml . appendAttribute ( "controls" , "none" ) ; break ; case ALL : xml . appendAttribute ( "controls" , "all" ) ; break ; case PLAY_PAUSE : xml . appendAttribute ( "controls" , "play" ) ; break ; case DEFAULT : xml . appendAttribute ( "controls" , "default" ) ; break ; default : LOG . error ( "Unknown control type: " + controls ) ; } } xml . appendClose ( ) ; String [ ] urls = audioComponent . getAudioUrls ( ) ; for ( int i = 0 ; i < urls . length ; i ++ ) { xml . appendTagOpen ( "ui:src" ) ; xml . appendUrlAttribute ( "uri" , urls [ i ] ) ; xml . appendOptionalAttribute ( "type" , audio [ i ] . getMimeType ( ) ) ; xml . appendEnd ( ) ; } xml . appendEndTag ( "ui:audio" ) ; }
Paints the given WAudio .
724
7
18,581
private void addResponsiveExample ( ) { add ( new WHeading ( HeadingLevel . H2 , "Default responsive design" ) ) ; add ( new ExplanatoryText ( "This example applies the theme's default responsive design rules for ColumnLayout.\n " + "The columns have width and alignment and there is also a hgap and a vgap." ) ) ; WPanel panel = new WPanel ( ) ; panel . setLayout ( new ColumnLayout ( new int [ ] { 33 , 33 , 33 } , new Alignment [ ] { Alignment . LEFT , Alignment . CENTER , Alignment . RIGHT } , 12 , 18 ) ) ; panel . setHtmlClass ( HtmlClassProperties . RESPOND ) ; add ( panel ) ; panel . add ( new BoxComponent ( "Left" ) ) ; panel . add ( new BoxComponent ( "Center" ) ) ; panel . add ( new BoxComponent ( "Right" ) ) ; panel . add ( new BoxComponent ( "Left" ) ) ; panel . add ( new BoxComponent ( "Center" ) ) ; panel . add ( new BoxComponent ( "Right" ) ) ; }
Add a column layout which will change its rendering on small screens .
248
13
18,582
private static String getTitle ( final int [ ] widths ) { StringBuffer buf = new StringBuffer ( "Column widths: " ) ; for ( int i = 0 ; i < widths . length ; i ++ ) { if ( i > 0 ) { buf . append ( ", " ) ; } buf . append ( widths [ i ] ) ; } return buf . toString ( ) ; }
Concatenates column widths to form the heading text for the example .
85
16
18,583
private void addHgapVGapExample ( final Size hgap , final Size vgap ) { add ( new WHeading ( HeadingLevel . H2 , "Column Layout: hgap=" + hgap . toString ( ) + " vgap=" + vgap . toString ( ) ) ) ; WPanel panel = new WPanel ( ) ; panel . setLayout ( new ColumnLayout ( new int [ ] { 25 , 25 , 25 , 25 } , hgap , vgap ) ) ; add ( panel ) ; for ( int i = 0 ; i < 8 ; i ++ ) { panel . add ( new BoxComponent ( "25%" ) ) ; } add ( new WHorizontalRule ( ) ) ; }
Build an example using hgap and vgap .
153
10
18,584
@ Override public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WTableRowRenderer renderer = ( WTableRowRenderer ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; WTable table = renderer . getTable ( ) ; TableModel dataModel = table . getTableModel ( ) ; int [ ] columnOrder = table . getColumnOrder ( ) ; final int numCols = columnOrder == null ? table . getColumnCount ( ) : columnOrder . length ; // Get current row details RowIdWrapper wrapper = renderer . getCurrentRowIdWrapper ( ) ; List < Integer > rowIndex = wrapper . getRowIndex ( ) ; boolean tableSelectable = table . getSelectMode ( ) != SelectMode . NONE ; boolean rowSelectable = tableSelectable && dataModel . isSelectable ( rowIndex ) ; boolean rowSelected = rowSelectable && table . getSelectedRows ( ) . contains ( wrapper . getRowKey ( ) ) ; boolean tableExpandable = table . getExpandMode ( ) != WTable . ExpandMode . NONE ; boolean rowExpandable = tableExpandable && dataModel . isExpandable ( rowIndex ) && wrapper . hasChildren ( ) ; boolean rowExpanded = rowExpandable && table . getExpandedRows ( ) . contains ( wrapper . getRowKey ( ) ) ; String rowIndexAsString = TableUtil . rowIndexListToString ( rowIndex ) ; xml . appendTagOpen ( "ui:tr" ) ; xml . appendAttribute ( "rowIndex" , rowIndexAsString ) ; xml . appendOptionalAttribute ( "unselectable" , ! rowSelectable , "true" ) ; xml . appendOptionalAttribute ( "selected" , rowSelected , "true" ) ; xml . appendOptionalAttribute ( "expandable" , rowExpandable && ! rowExpanded , "true" ) ; xml . appendClose ( ) ; // wrote the column cell. boolean isRowHeader = table . isRowHeaders ( ) ; // need this before we get into the loop for ( int i = 0 ; i < numCols ; i ++ ) { int colIndex = columnOrder == null ? i : columnOrder [ i ] ; WTableColumn col = table . getColumn ( colIndex ) ; String cellTag = "ui:td" ; if ( col . isVisible ( ) ) { if ( isRowHeader ) { // The first rendered column will be the row header. cellTag = "ui:th" ; isRowHeader = false ; // only set one col as the row header. } xml . appendTag ( cellTag ) ; renderer . getRenderer ( colIndex ) . paint ( renderContext ) ; xml . appendEndTag ( cellTag ) ; } } if ( rowExpandable ) { xml . appendTagOpen ( "ui:subtr" ) ; xml . appendOptionalAttribute ( "open" , rowExpanded , "true" ) ; xml . appendClose ( ) ; if ( rowExpanded || table . getExpandMode ( ) == ExpandMode . CLIENT ) { renderChildren ( renderer , renderContext , wrapper . getChildren ( ) ) ; } xml . appendEndTag ( "ui:subtr" ) ; } xml . appendEndTag ( "ui:tr" ) ; }
Paints the given WTableRowRenderer .
732
11
18,585
public static Policy createPolicy ( final String resourceName ) { if ( StringUtils . isBlank ( resourceName ) ) { throw new SystemException ( "AntiSamy Policy resourceName cannot be null " ) ; } URL resource = HtmlSanitizerUtil . class . getClassLoader ( ) . getResource ( resourceName ) ; if ( resource == null ) { throw new SystemException ( "Could not find AntiSamy Policy XML resource." ) ; } try { return Policy . getInstance ( resource ) ; } catch ( PolicyException ex ) { throw new SystemException ( "Could not create AntiSamy Policy" + ex . getMessage ( ) , ex ) ; } }
Create a Policy from a named local resource .
144
9
18,586
@ Override public void handleRequest ( final Request request ) { // Let the wcomponent gather data from the request. super . handleRequest ( request ) ; Object data = getData ( ) ; if ( data != null ) { // Now update the data object (bound to this wcomponent) by copying // values from this wcomponent and its children into the data object. updateData ( data ) ; } }
The handleRequest method has been overridden to keep the data object bound to this wcomponent in sync with any changes the user has entered .
84
28
18,587
@ Override protected void doGet ( final HttpServletRequest req , final HttpServletResponse resp ) throws ServletException , IOException { ServletUtil . handleThemeResourceRequest ( req , resp ) ; }
Serves up a file from the theme .
48
9
18,588
@ Override public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WCollapsibleToggle toggle = ( WCollapsibleToggle ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; xml . appendTagOpen ( "ui:collapsibletoggle" ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendOptionalAttribute ( "class" , component . getHtmlClass ( ) ) ; xml . appendOptionalAttribute ( "track" , component . isTracking ( ) , "true" ) ; xml . appendAttribute ( "groupName" , toggle . getGroupName ( ) ) ; xml . appendEnd ( ) ; }
Paints the given WCollapsibleToggle .
158
11
18,589
public static boolean empty ( final String aString ) { if ( aString != null ) { final int len = aString . length ( ) ; for ( int i = 0 ; i < len ; i ++ ) { // This mirrors String.trim(), which removes ASCII // control characters as well as whitespace. if ( aString . charAt ( i ) > ' ' ) { return false ; } } } return true ; }
Determines whether the given string is null or empty .
90
12
18,590
public static int compareAllowNull ( final Comparable c1 , final Comparable c2 ) { if ( c1 == null && c2 == null ) { return 0 ; } else if ( c1 == null ) { return - 1 ; } else if ( c2 == null ) { return 1 ; } else { return c1 . compareTo ( c2 ) ; } }
Compares two comparable objects where either may be null . Null is regarded as the smallest value and 2 nulls are considered equal .
79
26
18,591
public static String rightTrim ( final String aString ) { if ( aString == null ) { return null ; } int end = aString . length ( ) - 1 ; while ( ( end >= 0 ) && ( aString . charAt ( end ) <= ' ' ) ) { end -- ; } if ( end == aString . length ( ) - 1 ) { return aString ; } return aString . substring ( 0 , end + 1 ) ; }
Copies this String removing white space characters from the end of the string .
98
15
18,592
public static String leftTrim ( final String aString ) { if ( aString == null ) { return null ; } int start = 0 ; while ( ( start < aString . length ( ) ) && ( aString . charAt ( start ) <= ' ' ) ) { start ++ ; } if ( start == 0 ) { return aString ; } return aString . substring ( start ) ; }
Copies this String removing white space characters from the beginning of the string .
85
15
18,593
public static UIContext getCurrent ( ) { Stack < UIContext > stack = CONTEXT_STACK . get ( ) ; if ( stack == null || stack . isEmpty ( ) ) { return null ; } return getStack ( ) . peek ( ) ; }
Retrieves the current effective UIContext . Note that this method will return null if called from outside normal request processing for example during the intial application UI construction .
59
35
18,594
private static Stack < UIContext > getStack ( ) { Stack < UIContext > stack = CONTEXT_STACK . get ( ) ; if ( stack == null ) { stack = new Stack <> ( ) ; CONTEXT_STACK . set ( stack ) ; } return stack ; }
Retrieves the internal stack creating it if necessary .
65
11
18,595
public static List getAllFields ( final Object obj , final boolean excludeStatic , final boolean excludeTransient ) { List fieldList = new ArrayList ( ) ; for ( Class clazz = obj . getClass ( ) ; clazz != null ; clazz = clazz . getSuperclass ( ) ) { Field [ ] declaredFields = clazz . getDeclaredFields ( ) ; for ( int i = 0 ; i < declaredFields . length ; i ++ ) { int mods = declaredFields [ i ] . getModifiers ( ) ; if ( ( ! excludeStatic || ! Modifier . isStatic ( mods ) ) && ( ! excludeTransient || ! Modifier . isTransient ( mods ) ) ) { declaredFields [ i ] . setAccessible ( true ) ; fieldList . add ( declaredFields [ i ] ) ; } } } return fieldList ; }
Retrieves all the fields contained in the given object and its superclasses .
190
16
18,596
public static void setProperty ( final Object object , final String property , final Class propertyType , final Object value ) { Class [ ] paramTypes = new Class [ ] { propertyType } ; Object [ ] params = new Object [ ] { value } ; String methodName = "set" + property . substring ( 0 , 1 ) . toUpperCase ( ) + property . substring ( 1 ) ; ReflectionUtil . invokeMethod ( object , methodName , params , paramTypes ) ; }
This method sets a property on an object via reflection .
105
11
18,597
public static Object getProperty ( final Object object , final String property ) { Class [ ] paramTypes = new Class [ ] { } ; Object [ ] params = new Object [ ] { } ; String methodName = "get" + property . substring ( 0 , 1 ) . toUpperCase ( ) + property . substring ( 1 ) ; return ReflectionUtil . invokeMethod ( object , methodName , params , paramTypes ) ; }
This method gets a property from an object via reflection .
94
11
18,598
public int createRating ( Reference reference , RatingType type , int value ) { return getResourceFactory ( ) . getApiResource ( "/rating/" + reference . toURLFragment ( ) + type ) . entity ( Collections . singletonMap ( "value" , value ) , MediaType . APPLICATION_JSON_TYPE ) . post ( RatingCreateResponse . class ) . getId ( ) ; }
Add a new rating of the user to the object . The rating can be one of many different types . For more details see the area .
85
28
18,599
public void deleteRating ( Reference reference , RatingType type ) { getResourceFactory ( ) . getApiResource ( "/rating/" + reference . toURLFragment ( ) + type ) . delete ( ) ; }
Deletes the rating of the given type on the object by the active user
45
15