idx int64 0 165k | question stringlengths 73 4.15k | target stringlengths 5 918 | len_question int64 21 890 | len_target int64 3 255 |
|---|---|---|---|---|
18,700 | @ Override public void write ( final String string , final int off , final int len ) { for ( int i = off ; i < off + len ; i ++ ) { write ( string . charAt ( i ) ) ; } } | Writes the given String to the underlying output stream filtering as necessary . | 50 | 14 |
18,701 | @ Override protected boolean execute ( final Request request ) { for ( Condition condition : conditions ) { if ( condition . isTrue ( request ) ) { return true ; } } return false ; } | Evaluates the condition using values on the Request . Note that this uses the short - circuit or operator so condition b will not necessarily be evaluated . | 40 | 30 |
18,702 | public R fetch ( String properties ) { ( ( TQRootBean ) _root ) . query ( ) . fetch ( _name , properties ) ; return _root ; } | Eagerly fetch this association with the properties specified . | 37 | 11 |
18,703 | public R fetchQuery ( String properties ) { ( ( TQRootBean ) _root ) . query ( ) . fetchQuery ( _name , properties ) ; return _root ; } | Eagerly fetch this association using a query join with the properties specified . | 39 | 15 |
18,704 | protected R fetchProperties ( TQProperty < ? > ... props ) { ( ( TQRootBean ) _root ) . query ( ) . fetch ( _name , properties ( props ) ) ; return _root ; } | Eagerly fetch this association fetching some of the properties . | 48 | 13 |
18,705 | protected String properties ( TQProperty < ? > ... props ) { StringBuilder selectProps = new StringBuilder ( 50 ) ; for ( int i = 0 ; i < props . length ; i ++ ) { if ( i > 0 ) { selectProps . append ( "," ) ; } selectProps . append ( props [ i ] . propertyName ( ) ) ; } return selectProps . toString ( ) ; } | Append the properties as a comma delimited string . | 91 | 11 |
18,706 | public R filterMany ( ExpressionList < T > filter ) { @ SuppressWarnings ( "unchecked" ) ExpressionList < T > expressionList = ( ExpressionList < T > ) expr ( ) . filterMany ( _name ) ; expressionList . addAll ( filter ) ; return _root ; } | Apply a filter when fetching these beans . | 65 | 9 |
18,707 | public List < Event > getApp ( int appId , LocalDate dateFrom , LocalDate dateTo , ReferenceType ... types ) { return getCalendar ( "app/" + appId , dateFrom , dateTo , null , types ) ; } | Returns the items and tasks that are related to the given app . | 52 | 13 |
18,708 | public List < Event > getSpace ( int spaceId , LocalDate dateFrom , LocalDate dateTo , ReferenceType ... types ) { return getCalendar ( "space/" + spaceId , dateFrom , dateTo , null , types ) ; } | Returns all items and tasks that the user have access to in the given space . Tasks with reference to other spaces are not returned or tasks with no reference . | 52 | 32 |
18,709 | public List < Event > getGlobal ( LocalDate dateFrom , LocalDate dateTo , List < Integer > spaceIds , ReferenceType ... types ) { return getCalendar ( "" , dateFrom , dateTo , spaceIds , types ) ; } | Returns all items that the user have access to and all tasks that are assigned to the user . The items and tasks can be filtered by a list of space ids but tasks without a reference will always be returned . | 53 | 43 |
18,710 | @ Override public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WPasswordField field = ( WPasswordField ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; boolean readOnly = field . 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 ; } int cols = field . getColumns ( ) ; int minLength = field . getMinLength ( ) ; int maxLength = field . getMaxLength ( ) ; WComponent submitControl = field . getDefaultSubmitButton ( ) ; String submitControlId = submitControl == null ? null : submitControl . getId ( ) ; xml . appendOptionalAttribute ( "disabled" , field . isDisabled ( ) , "true" ) ; xml . appendOptionalAttribute ( "required" , field . isMandatory ( ) , "true" ) ; xml . appendOptionalAttribute ( "minLength" , minLength > 0 , minLength ) ; xml . appendOptionalAttribute ( "maxLength" , maxLength > 0 , maxLength ) ; xml . appendOptionalAttribute ( "toolTip" , field . getToolTip ( ) ) ; xml . appendOptionalAttribute ( "accessibleText" , field . getAccessibleText ( ) ) ; xml . appendOptionalAttribute ( "size" , cols > 0 , cols ) ; xml . appendOptionalAttribute ( "buttonId" , submitControlId ) ; String placeholder = field . getPlaceholder ( ) ; xml . appendOptionalAttribute ( "placeholder" , ! Util . empty ( placeholder ) , placeholder ) ; String autocomplete = field . getAutocomplete ( ) ; xml . appendOptionalAttribute ( "autocomplete" , ! Util . empty ( autocomplete ) , autocomplete ) ; List < Diagnostic > diags = field . getDiagnostics ( Diagnostic . ERROR ) ; if ( diags == null || diags . isEmpty ( ) ) { xml . appendEnd ( ) ; return ; } xml . appendClose ( ) ; DiagnosticRenderUtil . renderDiagnostics ( field , renderContext ) ; xml . appendEndTag ( TAG_NAME ) ; } | Paints the given WPasswordField . | 576 | 8 |
18,711 | @ Override public void handleRequest ( final Request request ) { if ( ! isInitialised ( ) ) { getOrCreateComponentModel ( ) . delegate = new SafetyContainerDelegate ( UIContextHolder . getCurrent ( ) ) ; setInitialised ( true ) ; } try { UIContext delegate = getComponentModel ( ) . delegate ; UIContextHolder . pushContext ( delegate ) ; try { for ( int i = 0 ; i < shim . getChildCount ( ) ; i ++ ) { shim . getChildAt ( i ) . serviceRequest ( request ) ; } delegate . doInvokeLaters ( ) ; } finally { UIContextHolder . popContext ( ) ; } } catch ( final ActionEscape e ) { // We don't want to catch ActionEscapes (e.g. ForwardExceptions) throw e ; } catch ( final Exception e ) { if ( isAjaxOrTargetedRequest ( request ) ) { throw new SystemException ( e . getMessage ( ) , e ) ; } else { setAttribute ( ERROR_KEY , e ) ; } } } | Override handleRequest in order to safely process the example component which has been excluded from normal WComponent processing . | 242 | 21 |
18,712 | public void resetContent ( ) { for ( int i = 0 ; i < shim . getChildCount ( ) ; i ++ ) { WComponent child = shim . getChildAt ( i ) ; child . reset ( ) ; } removeAttribute ( SafetyContainer . ERROR_KEY ) ; } | Resets the contents . | 62 | 5 |
18,713 | @ Override public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WRadioButton button = ( WRadioButton ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; boolean readOnly = button . isReadOnly ( ) ; String value = button . getValue ( ) ; xml . appendTagOpen ( "ui:radiobutton" ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendOptionalAttribute ( "class" , component . getHtmlClass ( ) ) ; xml . appendOptionalAttribute ( "track" , component . isTracking ( ) , "true" ) ; xml . appendOptionalAttribute ( "hidden" , button . isHidden ( ) , "true" ) ; xml . appendAttribute ( "groupName" , button . getGroupName ( ) ) ; xml . appendAttribute ( "value" , WebUtilities . encode ( value ) ) ; if ( readOnly ) { xml . appendAttribute ( "readOnly" , "true" ) ; } else { xml . appendOptionalAttribute ( "disabled" , button . isDisabled ( ) , "true" ) ; xml . appendOptionalAttribute ( "required" , button . isMandatory ( ) , "true" ) ; xml . appendOptionalAttribute ( "submitOnChange" , button . isSubmitOnChange ( ) , "true" ) ; xml . appendOptionalAttribute ( "toolTip" , button . getToolTip ( ) ) ; xml . appendOptionalAttribute ( "accessibleText" , button . getAccessibleText ( ) ) ; // Check for null option (ie null or empty). Match isEmpty() logic. boolean isNull = value == null ? true : ( value . length ( ) == 0 ) ; xml . appendOptionalAttribute ( "isNull" , isNull , "true" ) ; } xml . appendOptionalAttribute ( "selected" , button . isSelected ( ) , "true" ) ; xml . appendEnd ( ) ; } | Paints the given WRadioButton . | 434 | 9 |
18,714 | @ Override public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WTabGroup group = ( WTabGroup ) component ; paintChildren ( group , renderContext ) ; } | Paints the given WTabGroup . | 45 | 8 |
18,715 | private String getApplicationTitle ( final UIContext uic ) { WComponent root = uic . getUI ( ) ; String title = root instanceof WApplication ? ( ( WApplication ) root ) . getTitle ( ) : null ; Map < String , String > params = uic . getEnvironment ( ) . getHiddenParameters ( ) ; String target = params . get ( WWindow . WWINDOW_REQUEST_PARAM_KEY ) ; if ( target != null ) { ComponentWithContext targetComp = WebUtilities . getComponentById ( target , true ) ; if ( targetComp != null && targetComp . getComponent ( ) instanceof WWindow ) { try { UIContextHolder . pushContext ( targetComp . getContext ( ) ) ; title = ( ( WWindow ) targetComp . getComponent ( ) ) . getTitle ( ) ; } finally { UIContextHolder . popContext ( ) ; } } } return title == null ? "" : title ; } | Retrieves the application title for the given context . This mess is required due to WWindow essentially existing as a separate UI root . If WWindow is eventually removed then we can just retrieve the title from the root WApplication . | 212 | 46 |
18,716 | private String getFilterValues ( final TableDataModel dataModel , final int rowIndex ) { List < String > filterValues = dataModel . getFilterValues ( rowIndex ) ; if ( filterValues == null || filterValues . isEmpty ( ) ) { return null ; } StringBuffer buf = new StringBuffer ( filterValues . get ( 0 ) ) ; for ( int i = 1 ; i < filterValues . size ( ) ; i ++ ) { buf . append ( ", " ) ; buf . append ( filterValues . get ( i ) ) ; } return buf . toString ( ) ; } | Retrieves the filter values for the given row in the data model as a comma - separated string . | 125 | 21 |
18,717 | public static Renderer getRenderer ( final WComponent component , final RenderContext context ) { Class < ? extends WComponent > clazz = component . getClass ( ) ; Duplet < String , Class < ? > > key = new Duplet < String , Class < ? > > ( context . getRenderPackage ( ) , clazz ) ; Renderer renderer = INSTANCE . renderers . get ( key ) ; if ( renderer == null ) { renderer = INSTANCE . findRenderer ( component , key ) ; } else if ( renderer == NULL_RENDERER ) { return null ; } return renderer ; } | Retrieves a renderer which can renderer the given component to the context . | 137 | 17 |
18,718 | @ Deprecated public static Renderer getTemplateRenderer ( final RenderContext context ) { String packageName = context . getRenderPackage ( ) ; Renderer renderer = INSTANCE . templateRenderers . get ( packageName ) ; if ( renderer == null ) { renderer = INSTANCE . findTemplateRenderer ( packageName ) ; } else if ( renderer == NULL_RENDERER ) { return null ; } return renderer ; } | Retrieves a renderer which can renderer templates for the given context . | 98 | 16 |
18,719 | @ Deprecated private synchronized Renderer findTemplateRenderer ( final String packageName ) { RendererFactory factory = INSTANCE . findRendererFactory ( packageName ) ; Renderer renderer = factory . getTemplateRenderer ( ) ; if ( renderer == null ) { templateRenderers . put ( packageName , NULL_RENDERER ) ; } else { templateRenderers . put ( packageName , renderer ) ; } return renderer ; } | Retrieves the template renderer for the given package . | 101 | 12 |
18,720 | @ Deprecated public static Renderer getDefaultRenderer ( final WComponent component ) { LOG . warn ( "The getDefaultRenderer() method is deprecated. Do not obtain renderers directly." ) ; return getRenderer ( component , new WebXmlRenderContext ( new PrintWriter ( new NullWriter ( ) ) ) ) ; } | Retrieves the default LayoutManager for the given component . This method must no longer be used as it will only ever return a web - xml renderer . | 73 | 32 |
18,721 | private synchronized Renderer findRenderer ( final WComponent component , final Duplet < String , Class < ? > > key ) { LOG . info ( "Looking for layout for " + key . getSecond ( ) . getName ( ) + " in " + key . getFirst ( ) ) ; Renderer renderer = findConfiguredRenderer ( component , key . getFirst ( ) ) ; if ( renderer == null ) { renderers . put ( key , NULL_RENDERER ) ; } else { renderers . put ( key , renderer ) ; } return renderer ; } | Finds the layout for the given theme and component . | 128 | 11 |
18,722 | private synchronized RendererFactory findRendererFactory ( final String packageName ) { RendererFactory factory = factoriesByPackage . get ( packageName ) ; if ( factory == null ) { try { factory = ( RendererFactory ) Class . forName ( packageName + ".RendererFactoryImpl" ) . newInstance ( ) ; factoriesByPackage . put ( packageName , factory ) ; } catch ( Exception e ) { throw new SystemException ( "Failed to create layout manager factory for " + packageName , e ) ; } } return factory ; } | Finds the renderer factory for the given package . | 117 | 11 |
18,723 | private Renderer findConfiguredRenderer ( final WComponent component , final String rendererPackage ) { Renderer renderer = null ; // We loop for each WComponent in the class hierarchy, as the // Renderer may have been specified at a higher level. for ( Class < ? > c = component . getClass ( ) ; renderer == null && c != null && ! AbstractWComponent . class . equals ( c ) ; c = c . getSuperclass ( ) ) { String qualifiedClassName = c . getName ( ) ; // Is there an override for this class? String rendererName = ConfigurationProperties . getRendererOverride ( qualifiedClassName ) ; if ( rendererName != null ) { renderer = createRenderer ( rendererName ) ; if ( renderer == null ) { LOG . warn ( "Layout Manager \"" + rendererName + "\" specified for " + qualifiedClassName + " was not found" ) ; } else { return renderer ; } } renderer = findRendererFactory ( rendererPackage ) . getRenderer ( c ) ; } return renderer ; } | Attempts to find the configured renderer for the given output format and component . | 241 | 15 |
18,724 | private static Renderer createRenderer ( final String rendererName ) { if ( rendererName . endsWith ( ".vm" ) ) { // This is a velocity template, so use a VelocityLayout return new VelocityRenderer ( rendererName ) ; } try { Class < ? > managerClass = Class . forName ( rendererName ) ; Object manager = managerClass . newInstance ( ) ; if ( ! ( manager instanceof Renderer ) ) { throw new SystemException ( rendererName + " is not a Renderer" ) ; } return ( Renderer ) manager ; } catch ( ClassNotFoundException e ) { // Legal - there might not a manager implementation in a given theme return null ; } catch ( InstantiationException e ) { throw new SystemException ( "Failed to instantiate " + rendererName , e ) ; } catch ( IllegalAccessException e ) { throw new SystemException ( "Failed to access " + rendererName , e ) ; } } | Attempts to create a Renderer with the given name . | 209 | 11 |
18,725 | private void fakeServiceCall ( ) { poller . enablePoll ( ) ; Cache . getCache ( ) . invalidate ( DATA_KEY ) ; new Thread ( ) { @ Override public void run ( ) { try { Thread . sleep ( SERVICE_TIME ) ; Cache . getCache ( ) . put ( DATA_KEY , "SUCCESS!" ) ; } catch ( InterruptedException e ) { LOG . error ( "Timed out calling service" , e ) ; Cache . getCache ( ) . put ( DATA_KEY , "Timed out!" ) ; } } } . start ( ) ; } | Fakes a service call using the WorkManager for threading . | 129 | 13 |
18,726 | public void analyseWC ( final WComponent comp ) { if ( comp == null ) { return ; } statsByWCTree . put ( comp , createWCTreeStats ( comp ) ) ; } | Creates statistics for the given WComponent within the uicontext being analysed . | 42 | 16 |
18,727 | private void addStats ( final Map < WComponent , Stat > statsMap , final WComponent comp ) { Stat stat = createStat ( comp ) ; statsMap . put ( comp , stat ) ; if ( comp instanceof Container ) { Container container = ( Container ) comp ; int childCount = container . getChildCount ( ) ; for ( int i = 0 ; i < childCount ; i ++ ) { WComponent child = container . getChildAt ( i ) ; addStats ( statsMap , child ) ; } } } | Recursively adds statistics for a component and its children to the stats map . | 110 | 16 |
18,728 | private Stat createStat ( final WComponent comp ) { Stat stat = new Stat ( ) ; stat . setClassName ( comp . getClass ( ) . getName ( ) ) ; stat . setName ( comp . getId ( ) ) ; if ( stat . getName ( ) == null ) { stat . setName ( "Unknown" ) ; } if ( comp instanceof AbstractWComponent ) { Object obj = AbstractWComponent . replaceWComponent ( ( AbstractWComponent ) comp ) ; if ( obj instanceof AbstractWComponent . WComponentRef ) { stat . setRef ( obj . toString ( ) ) ; } } ComponentModel model = ( ComponentModel ) uic . getModel ( comp ) ; stat . setModelState ( Stat . MDL_NONE ) ; if ( model != null ) { if ( comp . isDefaultState ( ) ) { stat . setModelState ( Stat . MDL_DEFAULT ) ; } else { addSerializationStat ( model , stat ) ; } } return stat ; } | Creates statistics for a component in the given context . | 216 | 11 |
18,729 | private int getSerializationSize ( final Object obj ) { try { ByteArrayOutputStream bos = new ByteArrayOutputStream ( ) ; ObjectOutputStream oos = new ObjectOutputStream ( bos ) ; oos . writeObject ( obj ) ; oos . close ( ) ; byte [ ] bytes = bos . toByteArray ( ) ; return bytes . length ; } catch ( IOException ex ) { // Unable to serialize so cannot determine size. return - 1 ; } } | Determines the serialized size of an object by serializng it to a byte array . | 100 | 20 |
18,730 | private WDataTable createTable ( ) { WDataTable tbl = new WDataTable ( ) ; tbl . addColumn ( new WTableColumn ( "First name" , new WTextField ( ) ) ) ; tbl . addColumn ( new WTableColumn ( "Last name" , new WTextField ( ) ) ) ; tbl . addColumn ( new WTableColumn ( "DOB" , new WDateField ( ) ) ) ; return tbl ; } | Creates and configures the table to be used by the example . | 102 | 14 |
18,731 | @ Override protected void preparePaintComponent ( final Request request ) { if ( ! isInitialised ( ) ) { MyData data = new MyData ( "Homer" ) ; basic . setData ( data ) ; List < MyData > dataList = new ArrayList <> ( ) ; dataList . add ( new MyData ( "Homer" ) ) ; dataList . add ( new MyData ( "Marge" ) ) ; dataList . add ( new MyData ( "Bart" ) ) ; repeated . setBeanList ( dataList ) ; dataList = new ArrayList <> ( ) ; dataList . add ( new MyData ( "Greg" ) ) ; dataList . add ( new MyData ( "Jeff" ) ) ; dataList . add ( new MyData ( "Anthony" ) ) ; dataList . add ( new MyData ( "Murray" ) ) ; repeatedLink . setData ( dataList ) ; List < List < MyData > > rootList = new ArrayList <> ( ) ; List < MyData > subList = new ArrayList <> ( ) ; subList . add ( new MyData ( "Ernie" ) ) ; subList . add ( new MyData ( "Bert" ) ) ; rootList . add ( subList ) ; subList = new ArrayList <> ( ) ; subList . add ( new MyData ( "Starsky" ) ) ; subList . add ( new MyData ( "Hutch" ) ) ; rootList . add ( subList ) ; nestedRepeaterTab . setData ( rootList ) ; setInitialised ( true ) ; } } | Override preparePaint to initialise the data the first time through . | 352 | 14 |
18,732 | private int getSize ( final String fieldType , final Object fieldValue ) { Integer fieldSize = SIMPLE_SIZES . get ( fieldType ) ; if ( fieldSize != null ) { if ( PRIMITIVE_TYPES . contains ( fieldType ) ) { return fieldSize ; } return OBJREF_SIZE + fieldSize ; } else if ( fieldValue instanceof String ) { return ( OBJREF_SIZE + OBJECT_SHELL_SIZE ) * 2 // One for the String Object itself, and one for the char[] value + INT_FIELD_SIZE * 3 // offset, count, hash + ( ( String ) fieldValue ) . length ( ) * CHAR_FIELD_SIZE ; } else if ( fieldValue != null ) { return OBJECT_SHELL_SIZE + OBJREF_SIZE ; // plus the size of any nested nodes. } else { // Null return OBJREF_SIZE ; } } | Calculates the size of a field value obtained using the reflection API . | 199 | 15 |
18,733 | private void toFlatSummary ( final String indent , final StringBuffer buffer ) { buffer . append ( indent ) ; ObjectGraphNode root = ( ObjectGraphNode ) getRoot ( ) ; double pct = 100.0 * getSize ( ) / root . getSize ( ) ; buffer . append ( getSize ( ) ) . append ( " (" ) ; buffer . append ( new DecimalFormat ( "0.0" ) . format ( pct ) ) ; buffer . append ( "%) - " ) . append ( getFieldName ( ) ) . append ( " - " ) ; if ( getRefNode ( ) != null ) { buffer . append ( "ref (" ) . append ( getRefNode ( ) . getValue ( ) . getClass ( ) . getName ( ) ) . append ( ' ' ) ; } else if ( getValue ( ) == null ) { buffer . append ( "null (" ) . append ( getType ( ) ) . append ( ' ' ) ; } else { buffer . append ( getType ( ) ) ; } buffer . append ( ' ' ) ; String newIndent = indent + " " ; for ( int i = 0 ; i < getChildCount ( ) ; i ++ ) { ( ( ObjectGraphNode ) getChildAt ( i ) ) . toFlatSummary ( newIndent , buffer ) ; } } | Generates a flat format summary XML representation of this ObjectGraphNode . | 288 | 14 |
18,734 | private void toXml ( final String indent , final StringBuffer xml ) { String primitiveString = formatSimpleValue ( ) ; xml . append ( indent ) ; xml . append ( isPrimitive ( ) ? "<primitive" : "<object" ) ; if ( refNode == null ) { xml . append ( " id=\"" ) . append ( id ) . append ( ' ' ) ; if ( fieldName != null ) { xml . append ( " field=\"" ) . append ( fieldName ) . append ( ' ' ) ; } if ( primitiveString != null ) { primitiveString = WebUtilities . encode ( primitiveString ) ; xml . append ( " value=\"" ) . append ( primitiveString ) . append ( ' ' ) ; } if ( type != null ) { xml . append ( " type=\"" ) . append ( type ) . append ( ' ' ) ; } xml . append ( " size=\"" ) . append ( getSize ( ) ) . append ( ' ' ) ; if ( getChildCount ( ) == 0 ) { xml . append ( "/>\n" ) ; } else { xml . append ( ">\n" ) ; String newIndent = indent + " " ; for ( int i = 0 ; i < getChildCount ( ) ; i ++ ) { ( ( ObjectGraphNode ) getChildAt ( i ) ) . toXml ( newIndent , xml ) ; } xml . append ( indent ) ; xml . append ( isPrimitive ( ) ? "</primitive>\n" : "</object>\n" ) ; } } else { if ( fieldName != null ) { xml . append ( " field=\"" ) . append ( fieldName ) . append ( ' ' ) ; } xml . append ( " refId=\"" ) . append ( refNode . id ) . append ( ' ' ) ; if ( refNode . value == null ) { xml . append ( " type=\"" ) . append ( refNode . type ) . append ( ' ' ) ; } else { xml . append ( " type=\"" ) . append ( refNode . value . getClass ( ) . getName ( ) ) . append ( ' ' ) ; } xml . append ( " size=\"" ) . append ( OBJREF_SIZE ) . append ( ' ' ) ; xml . append ( "/>\n" ) ; } } | Emits an XML representation of this ObjectGraphNode . | 506 | 11 |
18,735 | private void addClientOnlyExamples ( ) { // client command button add ( new WHeading ( HeadingLevel . H2 , "Client command buttons" ) ) ; add ( new ExplanatoryText ( "These examples show buttons which do not submit the form" ) ) ; //client command buttons witho a command WButton nothingButton = new WButton ( "Do nothing" ) ; add ( nothingButton ) ; nothingButton . setClientCommandOnly ( true ) ; nothingButton = new WButton ( "Do nothing link" ) ; add ( nothingButton ) ; nothingButton . setRenderAsLink ( true ) ; nothingButton . setClientCommandOnly ( true ) ; // client command buttons with command. HelloButton helloButton = new HelloButton ( "Hello" ) ; add ( helloButton ) ; helloButton = new HelloButton ( "Hello link" ) ; helloButton . setRenderAsLink ( true ) ; add ( helloButton ) ; } | Examples showing use of client only buttons . | 197 | 8 |
18,736 | private void addDefaultSubmitButtonExample ( ) { add ( new WHeading ( HeadingLevel . H3 , "Default submit button" ) ) ; add ( new ExplanatoryText ( "This example shows how to use an image as the only content of a WButton. " + "In addition this text field submits the entire screen using the image button to the right of the field." ) ) ; // We use WFieldLayout to lay out a label:input pair. In this case the input is a //compound control of a WTextField and a WButton. WFieldLayout imageButtonFieldLayout = new WFieldLayout ( ) ; imageButtonFieldLayout . setLabelWidth ( 25 ) ; add ( imageButtonFieldLayout ) ; // the text field and the button both need to be defined explicitly to be able to add them into a wrapper WTextField textFld = new WTextField ( ) ; //and finally we get to the actual button WButton button = new WButton ( "Flag this record for follow-up" ) ; button . setImage ( "/image/flag.png" ) ; button . getImageHolder ( ) . setCacheKey ( "eg-button-flag" ) ; button . setActionObject ( button ) ; button . setAction ( new ExampleButtonAction ( ) ) ; //we can set the image button to be the default submit button for the text field. textFld . setDefaultSubmitButton ( button ) ; //There are many way of putting multiple controls in to a WField's input. //We are using a WContainer is the one which is lowest impact in the UI. WContainer imageButtonFieldContainer = new WContainer ( ) ; imageButtonFieldContainer . add ( textFld ) ; //Use a WText to push the button off of the text field by an appropriate (user-agent determined) amount. imageButtonFieldContainer . add ( new WText ( "\u2002" ) ) ; //an en space is half an em. a none-breaking space \u00a0 could also be used but will have no effect on inter-node wrapping imageButtonFieldContainer . add ( button ) ; //Finally add the input wrapper to the WFieldLayout imageButtonFieldLayout . addField ( "Enter record ID" , imageButtonFieldContainer ) ; } | Examples showing how to set a WButton as the default submit button for an input control . | 485 | 18 |
18,737 | private void addDisabledExamples ( ) { add ( new WHeading ( HeadingLevel . H2 , "Examples of disabled buttons" ) ) ; WPanel disabledButtonLayoutPanel = new WPanel ( WPanel . Type . BOX ) ; disabledButtonLayoutPanel . setLayout ( new FlowLayout ( FlowLayout . LEFT , 6 , 0 , FlowLayout . ContentAlignment . BASELINE ) ) ; add ( disabledButtonLayoutPanel ) ; WButton button = new WButton ( "Disabled button" ) ; button . setDisabled ( true ) ; disabledButtonLayoutPanel . add ( button ) ; button = new WButton ( "Disabled button as link" ) ; button . setDisabled ( true ) ; button . setRenderAsLink ( true ) ; disabledButtonLayoutPanel . add ( button ) ; add ( new WHeading ( HeadingLevel . H3 , "Examples of disabled buttons displaying only an image" ) ) ; disabledButtonLayoutPanel = new WPanel ( WPanel . Type . BOX ) ; disabledButtonLayoutPanel . setLayout ( new FlowLayout ( FlowLayout . LEFT , 6 , 0 , FlowLayout . ContentAlignment . BASELINE ) ) ; add ( disabledButtonLayoutPanel ) ; button = new WButton ( "Disabled button" ) ; button . setDisabled ( true ) ; button . setImage ( "/image/tick.png" ) ; button . setToolTip ( "Checking currently disabled" ) ; disabledButtonLayoutPanel . add ( button ) ; button = new WButton ( "Disabled button as link" ) ; button . setDisabled ( true ) ; button . setRenderAsLink ( true ) ; button . setImage ( "/image/tick.png" ) ; button . setToolTip ( "Checking currently disabled" ) ; disabledButtonLayoutPanel . add ( button ) ; add ( new WHeading ( HeadingLevel . H3 , "Examples of disabled buttons displaying an image with imagePosition EAST" ) ) ; disabledButtonLayoutPanel = new WPanel ( WPanel . Type . BOX ) ; disabledButtonLayoutPanel . setLayout ( new FlowLayout ( FlowLayout . LEFT , 6 , 0 , FlowLayout . ContentAlignment . BASELINE ) ) ; add ( disabledButtonLayoutPanel ) ; button = new WButton ( "Disabled button" ) ; button . setDisabled ( true ) ; button . setImage ( "/image/tick.png" ) ; button . setToolTip ( "Checking currently disabled" ) ; button . setImagePosition ( ImagePosition . EAST ) ; disabledButtonLayoutPanel . add ( button ) ; button = new WButton ( "Disabled button as link" ) ; button . setDisabled ( true ) ; button . setRenderAsLink ( true ) ; button . setImage ( "/image/tick.png" ) ; button . setToolTip ( "Checking currently disabled" ) ; button . setImagePosition ( ImagePosition . EAST ) ; disabledButtonLayoutPanel . add ( button ) ; } | Examples of disabled buttons in various guises . | 641 | 9 |
18,738 | private void addAntiPatternExamples ( ) { add ( new WHeading ( HeadingLevel . H2 , "WButton anti-pattern examples" ) ) ; add ( new WMessageBox ( WMessageBox . WARN , "These examples are purposely bad and should not be used as samples of how to use WComponents but samples of how NOT to use them." ) ) ; add ( new WHeading ( HeadingLevel . H3 , "WButton without a good label" ) ) ; add ( new WButton ( "\u2002" ) ) ; add ( new ExplanatoryText ( "A button without a text label is very bad" ) ) ; add ( new WHeading ( HeadingLevel . H3 , "WButton with a WImage but without a good label" ) ) ; WButton button = new WButton ( "" ) ; button . setImage ( "/image/help.png" ) ; add ( button ) ; add ( new ExplanatoryText ( "A button without a text label is very bad, even if you think the image is sufficient. The text label becomes the image alt text." ) ) ; } | Examples of what not to do when using WButton . | 238 | 11 |
18,739 | @ Override public void handleRequest ( final Request request ) { if ( plainBtn . isPressed ( ) ) { WMessages . getInstance ( this ) . info ( "Plain button pressed." ) ; } if ( linkBtn . isPressed ( ) ) { WMessages . getInstance ( this ) . info ( "Link button pressed." ) ; } } | Override handleRequest in order to perform processing specific to this example . Normally you would attach actions to a button rather than calling isPressed on each button . | 81 | 31 |
18,740 | public static boolean containsOption ( final List < ? > options , final Object findOption ) { if ( options != null ) { for ( Object option : options ) { if ( option instanceof OptionGroup ) { List < ? > groupOptions = ( ( OptionGroup ) option ) . getOptions ( ) ; if ( groupOptions != null ) { for ( Object nestedOption : groupOptions ) { if ( Util . equals ( nestedOption , findOption ) ) { return true ; } } } } else if ( Util . equals ( option , findOption ) ) { return true ; } } } return false ; } | Iterate through the options to determine if an option exists . | 128 | 12 |
18,741 | public static Object getFirstOption ( final List < ? > options ) { if ( options != null ) { for ( Object option : options ) { if ( option instanceof OptionGroup ) { List < ? > groupOptions = ( ( OptionGroup ) option ) . getOptions ( ) ; if ( groupOptions != null && ! groupOptions . isEmpty ( ) ) { return groupOptions . get ( 0 ) ; } } else { return option ; } } } return null ; } | Retrieve the first option . The first option maybe within an option group . | 99 | 15 |
18,742 | @ Deprecated private static boolean isLegacyMatch ( final Object option , final Object data ) { // Support legacy matching, which supported setSelected using String representations... String optionAsString = String . valueOf ( option ) ; String matchAsString = String . valueOf ( data ) ; boolean equal = Util . equals ( optionAsString , matchAsString ) ; return equal ; } | Check for legacy matching which supported setSelected using String representations . | 81 | 13 |
18,743 | @ Override public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WTemplate template = ( WTemplate ) component ; // Setup the context Map < String , Object > context = new HashMap <> ( ) ; // Make the component available under the "wc" key. context . put ( "wc" , template ) ; // Load the parameters context . putAll ( template . getParameters ( ) ) ; // Get template renderer for the engine String engine = template . getEngineName ( ) ; if ( Util . empty ( engine ) ) { engine = ConfigurationProperties . getDefaultRenderingEngine ( ) ; } TemplateRenderer templateRenderer = TemplateRendererFactory . newInstance ( engine ) ; // Render if ( ! Util . empty ( template . getTemplateName ( ) ) ) { // Render the template templateRenderer . renderTemplate ( template . getTemplateName ( ) , context , template . getTaggedComponents ( ) , renderContext . getWriter ( ) , template . getEngineOptions ( ) ) ; } else if ( ! Util . empty ( template . getInlineTemplate ( ) ) ) { // Render inline templateRenderer . renderInline ( template . getInlineTemplate ( ) , context , template . getTaggedComponents ( ) , renderContext . getWriter ( ) , template . getEngineOptions ( ) ) ; } } | Paints the given WTemplate . | 304 | 7 |
18,744 | @ Override public void updateComponent ( final Object data ) { MyData myData = ( MyData ) data ; name . setText ( "<B>" + myData . getName ( ) + "</B>" ) ; count . setText ( String . valueOf ( myData . getCount ( ) ) ) ; } | Copies data from the Model into the View . | 68 | 10 |
18,745 | @ Override public void paint ( final RenderContext renderContext ) { if ( ! doTransform ) { super . paint ( renderContext ) ; return ; } if ( ! ( renderContext instanceof WebXmlRenderContext ) ) { LOG . warn ( "Unable to transform a " + renderContext ) ; super . paint ( renderContext ) ; return ; } LOG . debug ( "Transform XML Interceptor: Start" ) ; UIContext uic = UIContextHolder . getCurrent ( ) ; // Set up a render context to buffer the XML payload. StringWriter xmlBuffer = new StringWriter ( ) ; PrintWriter xmlWriter = new PrintWriter ( xmlBuffer ) ; WebXmlRenderContext xmlContext = new WebXmlRenderContext ( xmlWriter , uic . getLocale ( ) ) ; super . paint ( xmlContext ) ; // write the XML to the buffer // Get a handle to the true PrintWriter. WebXmlRenderContext webRenderContext = ( WebXmlRenderContext ) renderContext ; PrintWriter writer = webRenderContext . getWriter ( ) ; /* * Switch the response content-type to HTML. * In theory the transformation could be to ANYTHING (not just HTML) so perhaps it would make more sense to * write a new interceptor "ContentTypeInterceptor" which attempts to sniff payloads and choose the correct * content-type. This is exactly the kind of thing IE6 loved to do, so perhaps it's a bad idea. */ Response response = getResponse ( ) ; response . setContentType ( WebUtilities . CONTENT_TYPE_HTML ) ; String xml = xmlBuffer . toString ( ) ; if ( isAllowCorruptCharacters ( ) && ! Util . empty ( xml ) ) { // Remove illegal HTML characters from the content before transforming it. xml = removeCorruptCharacters ( xml ) ; } // Double encode template tokens in the XML xml = WebUtilities . doubleEncodeBrackets ( xml ) ; // Setup temp writer StringWriter tempBuffer = new StringWriter ( ) ; PrintWriter tempWriter = new PrintWriter ( tempBuffer ) ; // Perform the transformation and write the result. transform ( xml , uic , tempWriter ) ; // Decode Double Encoded Brackets String tempResp = tempBuffer . toString ( ) ; tempResp = WebUtilities . doubleDecodeBrackets ( tempResp ) ; // Write response writer . write ( tempResp ) ; LOG . debug ( "Transform XML Interceptor: Finished" ) ; } | Override paint to perform XML to HTML transformation . | 526 | 9 |
18,746 | private void transform ( final String xml , final UIContext uic , final PrintWriter writer ) { Transformer transformer = newTransformer ( ) ; Source inputXml ; try { inputXml = new StreamSource ( new ByteArrayInputStream ( xml . getBytes ( "utf-8" ) ) ) ; StreamResult result = new StreamResult ( writer ) ; if ( debugRequested ) { transformer . setParameter ( "isDebug" , 1 ) ; } transformer . transform ( inputXml , result ) ; } catch ( UnsupportedEncodingException | TransformerException ex ) { throw new SystemException ( "Could not transform xml" , ex ) ; } } | Transform the UI XML to HTML using the correct XSLT from the classpath . | 142 | 17 |
18,747 | private static Templates initTemplates ( ) { try { URL xsltURL = ThemeUtil . class . getResource ( RESOURCE_NAME ) ; if ( xsltURL != null ) { Source xsltSource = new StreamSource ( xsltURL . openStream ( ) , xsltURL . toExternalForm ( ) ) ; TransformerFactory factory = new net . sf . saxon . TransformerFactoryImpl ( ) ; Templates templates = factory . newTemplates ( xsltSource ) ; LOG . debug ( "Generated XSLT templates for: " + RESOURCE_NAME ) ; return templates ; } else { // Server-side XSLT enabled but theme resource not on classpath. throw new IllegalStateException ( RESOURCE_NAME + " not on classpath" ) ; } } catch ( IOException | TransformerConfigurationException ex ) { throw new SystemException ( "Could not create transformer for " + RESOURCE_NAME , ex ) ; } } | Statically initialize the XSLT templates that are cached for all future transforms . | 211 | 16 |
18,748 | private static String removeCorruptCharacters ( final String input ) { if ( Util . empty ( input ) ) { return input ; } return ESCAPE_BAD_XML10 . translate ( input ) ; } | Remove bad characters in XML . | 45 | 6 |
18,749 | public int create ( Reference object , HookCreate create ) { return getResourceFactory ( ) . getApiResource ( "/hook/" + object . getType ( ) + "/" + object . getId ( ) + "/" ) . entity ( create , MediaType . APPLICATION_JSON ) . post ( HookCreateResponse . class ) . getId ( ) ; } | Create a new hook on the given object . | 77 | 9 |
18,750 | public List < Hook > get ( Reference object ) { return getResourceFactory ( ) . getApiResource ( "/hook/" + object . getType ( ) + "/" + object . getId ( ) + "/" ) . get ( new GenericType < List < Hook > > ( ) { } ) ; } | Returns the hooks on the object . | 66 | 7 |
18,751 | public void requestVerification ( int id ) { getResourceFactory ( ) . getApiResource ( "/hook/" + id + "/verify/request" ) . entity ( new Empty ( ) , MediaType . APPLICATION_JSON_TYPE ) . post ( ) ; } | Request the hook to be validated . This will cause the hook to send a request to the URL with the parameter type set to hook . verify and code set to the verification code . The endpoint must then call the validate method with the code to complete the verification . | 58 | 52 |
18,752 | public void validateVerification ( int id , String code ) { getResourceFactory ( ) . getApiResource ( "/hook/" + id + "/verify/validate" ) . entity ( new HookValidate ( code ) , MediaType . APPLICATION_JSON ) . post ( ) ; } | Validates the hook using the code received from the verify call . On successful validation the hook will become active . | 63 | 22 |
18,753 | @ Override public void handleRequest ( final Request request ) { // Protect against client-side tampering of disabled/read-only fields. if ( isDisabled ( ) || isReadOnly ( ) ) { return ; } RadioButtonGroup currentGroup = getGroup ( ) ; // Check if the group is not on the request (do nothing) if ( ! currentGroup . isPresent ( request ) ) { return ; } // Check if the group has a null value (will be handled by the group handle request) if ( request . getParameter ( currentGroup . getId ( ) ) == null ) { return ; } // Get the groups value on the request String requestValue = currentGroup . getRequestValue ( request ) ; // Check if this button's value matches the request boolean onRequest = Util . equals ( requestValue , getValue ( ) ) ; if ( onRequest ) { boolean changed = currentGroup . handleButtonOnRequest ( request ) ; if ( changed && ( UIContextHolder . getCurrent ( ) != null ) && ( UIContextHolder . getCurrent ( ) . getFocussed ( ) == null ) && currentGroup . isCurrentAjaxTrigger ( ) ) { setFocussed ( ) ; } } } | This method will only process the request if the value for the group matches the button s value . | 264 | 19 |
18,754 | public void setSelected ( final boolean selected ) { if ( selected ) { if ( isDisabled ( ) ) { throw new IllegalStateException ( "Cannot select a disabled radio button" ) ; } getGroup ( ) . setSelectedValue ( getValue ( ) ) ; } else if ( isSelected ( ) ) { // Clear selection getGroup ( ) . setData ( null ) ; } } | Sets whether the radio button is selected . | 86 | 9 |
18,755 | public ApplicationResource addJsUrl ( final String url ) { if ( Util . empty ( url ) ) { throw new IllegalArgumentException ( "A URL must be provided." ) ; } ApplicationResource res = new ApplicationResource ( url ) ; addJsResource ( res ) ; return res ; } | Add custom javaScript located at the specified URL to be used by the Application . | 62 | 16 |
18,756 | public ApplicationResource addJsFile ( final String fileName ) { if ( Util . empty ( fileName ) ) { throw new IllegalArgumentException ( "A file name must be provided." ) ; } InternalResource resource = new InternalResource ( fileName , fileName ) ; ApplicationResource res = new ApplicationResource ( resource ) ; addJsResource ( res ) ; return res ; } | Add custom JavaScript held as an internal resource to be used by the application . | 80 | 15 |
18,757 | public void addJsResource ( final ApplicationResource resource ) { WApplicationModel model = getOrCreateComponentModel ( ) ; if ( model . jsResources == null ) { model . jsResources = new ArrayList <> ( ) ; } else if ( model . jsResources . contains ( resource ) ) { return ; } model . jsResources . add ( resource ) ; MemoryUtil . checkSize ( model . jsResources . size ( ) , this . getClass ( ) . getSimpleName ( ) ) ; } | Add a custom javaScript resource that is to be loaded and used by the application . | 107 | 17 |
18,758 | public void removeJsResource ( final ApplicationResource resource ) { WApplicationModel model = getOrCreateComponentModel ( ) ; if ( model . jsResources != null ) { model . jsResources . remove ( resource ) ; } } | Remove a custom JavaScript resource . | 47 | 6 |
18,759 | public ApplicationResource addCssUrl ( final String url ) { if ( Util . empty ( url ) ) { throw new IllegalArgumentException ( "A URL must be provided." ) ; } ApplicationResource res = new ApplicationResource ( url ) ; addCssResource ( res ) ; return res ; } | Add custom CSS located at the specified URL to be used by the Application . | 64 | 15 |
18,760 | public ApplicationResource addCssFile ( final String fileName ) { if ( Util . empty ( fileName ) ) { throw new IllegalArgumentException ( "A file name must be provided." ) ; } InternalResource resource = new InternalResource ( fileName , fileName ) ; ApplicationResource res = new ApplicationResource ( resource ) ; addCssResource ( res ) ; return res ; } | Add custom CSS held as an internal resource to be used by the Application . | 82 | 15 |
18,761 | public void addCssResource ( final ApplicationResource resource ) { WApplicationModel model = getOrCreateComponentModel ( ) ; if ( model . cssResources == null ) { model . cssResources = new ArrayList <> ( ) ; } else if ( model . cssResources . contains ( resource ) ) { return ; } model . cssResources . add ( resource ) ; MemoryUtil . checkSize ( model . cssResources . size ( ) , this . getClass ( ) . getSimpleName ( ) ) ; } | Add a custom CSS resource that will be loaded and used by this application . | 113 | 15 |
18,762 | public void removeCssResource ( final ApplicationResource resource ) { WApplicationModel model = getOrCreateComponentModel ( ) ; if ( model . cssResources != null ) { model . cssResources . remove ( resource ) ; } } | Remove a custom CSS resource . | 50 | 6 |
18,763 | @ Override protected void validateComponent ( final List < Diagnostic > diags ) { // Mandatory validation if ( isMandatory ( ) && isEmpty ( ) ) { diags . add ( createMandatoryDiagnostic ( ) ) ; } // Other validations List < FieldValidator > validators = getComponentModel ( ) . validators ; if ( validators != null ) { for ( FieldValidator validator : validators ) { validator . validate ( diags ) ; } } } | Override WComponent s validatorComponent in order to use the validators which have been added to this input field . Subclasses may still override this method but it is suggested to call super . validateComponent to ensure that the validators are still used . | 105 | 50 |
18,764 | protected void setChangedInLastRequest ( final boolean changed ) { if ( isChangedInLastRequest ( ) != changed ) { InputModel model = getOrCreateComponentModel ( ) ; model . changedInLastRequest = changed ; } } | Set the changed flag to indicate if the component changed in the last request . | 49 | 15 |
18,765 | @ Override public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WHiddenComment hiddenComponent = ( WHiddenComment ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; String hiddenText = hiddenComponent . getText ( ) ; if ( ! Util . empty ( hiddenText ) ) { xml . appendTag ( "ui:comment" ) ; xml . appendEscaped ( hiddenText ) ; xml . appendEndTag ( "ui:comment" ) ; } } | Paints the given WHiddenComment . | 112 | 8 |
18,766 | public void setComparator ( final int col , final Comparator comparator ) { synchronized ( this ) { if ( comparators == null ) { comparators = new HashMap <> ( ) ; } } if ( comparator == null ) { comparators . remove ( col ) ; } else { comparators . put ( col , comparator ) ; } } | Sets the comparator for the given column to enable sorting . | 75 | 13 |
18,767 | private void updateRegion ( ) { actMessage . setVisible ( false ) ; String state = ( String ) stateSelector . getSelected ( ) ; if ( STATE_ACT . equals ( state ) ) { actMessage . setVisible ( true ) ; regionSelector . setOptions ( new String [ ] { null , "Belconnen" , "City" , "Woden" } ) ; } else if ( STATE_NSW . equals ( state ) ) { regionSelector . setOptions ( new String [ ] { null , "Hunter" , "Riverina" , "Southern Tablelands" } ) ; } else if ( STATE_VIC . equals ( state ) ) { regionSelector . setOptions ( new String [ ] { null , "Gippsland" , "Melbourne" , "Mornington Peninsula" } ) ; } else { regionSelector . setOptions ( new Object [ ] { null } ) ; } } | Updates the options present in the region selector depending on the state selector s value . | 203 | 17 |
18,768 | public static InterceptorComponent replaceInterceptor ( final Class match , final InterceptorComponent replacement , final InterceptorComponent chain ) { if ( chain == null ) { return null ; } InterceptorComponent current = chain ; InterceptorComponent previous = null ; InterceptorComponent updatedChain = null ; while ( updatedChain == null ) { if ( match . isInstance ( current ) ) { // Found the interceptor that needs to be replaced. replacement . setBackingComponent ( current . getBackingComponent ( ) ) ; if ( previous == null ) { updatedChain = replacement ; } else { previous . setBackingComponent ( replacement ) ; updatedChain = chain ; } } else { previous = current ; WebComponent next = current . getBackingComponent ( ) ; if ( next instanceof InterceptorComponent ) { current = ( InterceptorComponent ) next ; } else { // Reached the end of the chain. No replacement done. updatedChain = chain ; } } } return updatedChain ; } | Utility method for replacing an individual interceptor within an existing chain . | 204 | 14 |
18,769 | protected static String render ( final WebComponent component ) { StringWriter stringWriter = new StringWriter ( ) ; PrintWriter printWriter = new PrintWriter ( stringWriter ) ; component . paint ( new WebXmlRenderContext ( printWriter ) ) ; printWriter . flush ( ) ; String content = stringWriter . toString ( ) ; return content ; } | Renders the given component to a web - XML String and returns it . This occurs outside the context of a Servlet . | 73 | 25 |
18,770 | public void attachUI ( final WComponent ui ) { if ( backing == null || backing instanceof WComponent ) { backing = ui ; } else if ( backing instanceof InterceptorComponent ) { ( ( InterceptorComponent ) backing ) . attachUI ( ui ) ; } else { throw new IllegalStateException ( "Unable to attachUI. Unknown type of WebComponent encountered. " + backing . getClass ( ) . getName ( ) ) ; } } | Add the WComponent to the end of the interceptor chain . | 98 | 13 |
18,771 | public void setAlignment ( final int col , final Alignment alignment ) { columnAlignments [ col ] = alignment == null ? Alignment . LEFT : alignment ; } | Sets the alignment of the given column . An IndexOutOfBoundsException will be thrown if col is out of bounds . | 37 | 26 |
18,772 | public static void copy ( final InputStream in , final OutputStream out ) throws IOException { copy ( in , out , DEFAULT_BUFFER_SIZE ) ; } | Copies information from the input stream to the output stream using the default copy buffer size . | 35 | 18 |
18,773 | public static void copy ( final InputStream in , final OutputStream out , final int bufferSize ) throws IOException { final byte [ ] buf = new byte [ bufferSize ] ; int bytesRead = in . read ( buf ) ; while ( bytesRead != - 1 ) { out . write ( buf , 0 , bytesRead ) ; bytesRead = in . read ( buf ) ; } out . flush ( ) ; } | Copies information from the input stream to the output stream using a specified buffer size . | 87 | 17 |
18,774 | public static void safeClose ( final Closeable stream ) { if ( stream != null ) { try { stream . close ( ) ; } catch ( IOException e ) { LOG . error ( "Failed to close resource stream" , e ) ; } } } | Closes an OutputStream logging any exceptions . | 54 | 9 |
18,775 | public void applySettings ( ) { messageList . clear ( ) ; messageList . add ( "" ) ; for ( int i = 1 ; messageBox . getMessages ( ) . size ( ) >= i ; i ++ ) { messageList . add ( String . valueOf ( i ) ) ; } selRemove . setOptions ( messageList ) ; selRemove . resetData ( ) ; btnRemove . setDisabled ( messageList . isEmpty ( ) ) ; btnRemoveAll . setDisabled ( messageList . isEmpty ( ) ) ; messageBox . setType ( ( com . github . bordertech . wcomponents . WMessageBox . Type ) messageBoxTypeSelect . getSelected ( ) ) ; messageBox . setVisible ( cbVisible . isSelected ( ) ) ; if ( tfTitle . getText ( ) != null && ! "" . equals ( tfTitle . getText ( ) ) ) { messageBox . setTitleText ( tfTitle . getText ( ) ) ; } else { messageBox . setTitleText ( null ) ; } } | applySettings is used to apply the setting to the various controls on the page . | 231 | 16 |
18,776 | @ Override public void escape ( ) throws IOException { LOG . debug ( "...ContentEscape escape()" ) ; if ( contentAccess == null ) { LOG . warn ( "No content to output" ) ; } else { String mimeType = contentAccess . getMimeType ( ) ; Response response = getResponse ( ) ; response . setContentType ( mimeType ) ; if ( isCacheable ( ) ) { getResponse ( ) . setHeader ( "Cache-Control" , CacheType . CONTENT_CACHE . getSettings ( ) ) ; } else { getResponse ( ) . setHeader ( "Cache-Control" , CacheType . CONTENT_NO_CACHE . getSettings ( ) ) ; } if ( contentAccess . getDescription ( ) != null ) { String fileName = WebUtilities . encodeForContentDispositionHeader ( contentAccess . getDescription ( ) ) ; if ( displayInline ) { response . setHeader ( "Content-Disposition" , "inline; filename=" + fileName ) ; } else { response . setHeader ( "Content-Disposition" , "attachment; filename=" + fileName ) ; } } if ( contentAccess instanceof ContentStreamAccess ) { InputStream stream = null ; try { stream = ( ( ContentStreamAccess ) contentAccess ) . getStream ( ) ; if ( stream == null ) { throw new SystemException ( "ContentAccess returned null stream, access=" + contentAccess ) ; } StreamUtil . copy ( stream , response . getOutputStream ( ) ) ; } finally { StreamUtil . safeClose ( stream ) ; } } else { byte [ ] bytes = contentAccess . getBytes ( ) ; if ( bytes == null ) { throw new SystemException ( "ContentAccess returned null data, access=" + contentAccess ) ; } response . getOutputStream ( ) . write ( bytes ) ; } } } | Writes the content to the response . | 404 | 8 |
18,777 | public Embed createEmbed ( String url ) { return getResourceFactory ( ) . getApiResource ( "/embed/" ) . entity ( new EmbedCreate ( url ) , MediaType . APPLICATION_JSON_TYPE ) . post ( Embed . class ) ; } | Grabs metadata and returns metadata for the given url such as title description and thumbnails . | 58 | 18 |
18,778 | @ Override public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WField field = ( WField ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; int inputWidth = field . getInputWidth ( ) ; xml . appendTagOpen ( "ui:field" ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendOptionalAttribute ( "class" , component . getHtmlClass ( ) ) ; xml . appendOptionalAttribute ( "track" , component . isTracking ( ) , "true" ) ; xml . appendOptionalAttribute ( "hidden" , field . isHidden ( ) , "true" ) ; xml . appendOptionalAttribute ( "inputWidth" , inputWidth > 0 , inputWidth ) ; xml . appendClose ( ) ; // Label WLabel label = field . getLabel ( ) ; if ( label != null ) { label . paint ( renderContext ) ; } // Field if ( field . getField ( ) != null ) { xml . appendTag ( "ui:input" ) ; field . getField ( ) . paint ( renderContext ) ; if ( field . getErrorIndicator ( ) != null ) { field . getErrorIndicator ( ) . paint ( renderContext ) ; } if ( field . getWarningIndicator ( ) != null ) { field . getWarningIndicator ( ) . paint ( renderContext ) ; } xml . appendEndTag ( "ui:input" ) ; } xml . appendEndTag ( "ui:field" ) ; } | Paints the given WField . | 337 | 7 |
18,779 | @ Override public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { XmlStringBuilder xml = renderContext . getWriter ( ) ; xml . appendTagOpen ( "hr" ) ; xml . appendOptionalAttribute ( "class" , component . getHtmlClass ( ) ) ; xml . appendEnd ( ) ; } | Paints the given WHorizontalRule . | 76 | 9 |
18,780 | private void addMenuItem ( final WComponent parent , final String text , final WText selectedMenuText ) { WMenuItem menuItem = new WMenuItem ( text , new ExampleMenuAction ( selectedMenuText ) ) ; menuItem . setActionObject ( text ) ; if ( parent instanceof WSubMenu ) { ( ( WSubMenu ) parent ) . add ( menuItem ) ; } else { ( ( WMenuItemGroup ) parent ) . add ( menuItem ) ; } } | Adds an example menu item with the given text and an example action to the a parent component . | 103 | 19 |
18,781 | private WMenuItem createImageMenuItem ( final String resource , final String desc , final String cacheKey , final WText selectedMenuText ) { WImage image = new WImage ( resource , desc ) ; image . setCacheKey ( cacheKey ) ; WDecoratedLabel label = new WDecoratedLabel ( image , new WText ( desc ) , null ) ; WMenuItem menuItem = new WMenuItem ( label , new ExampleMenuAction ( selectedMenuText ) ) ; menuItem . setActionObject ( desc ) ; return menuItem ; } | Creates an example menu item using an image . | 118 | 10 |
18,782 | @ Deprecated public void setPaddingChar ( final char paddingChar ) { if ( Character . isDigit ( paddingChar ) ) { throw new IllegalArgumentException ( "Padding character should not be a digit." ) ; } getOrCreateComponentModel ( ) . paddingChar = paddingChar ; } | The padding character used in the partial date value . The default padding character is a space . If the padding character is a space then the date value will be right trimmed to remove the trailing spaces . | 64 | 39 |
18,783 | @ Override protected void validateComponent ( final List < Diagnostic > diags ) { if ( isValidDate ( ) ) { super . validateComponent ( diags ) ; } else { diags . add ( createErrorDiagnostic ( getComponentModel ( ) . errorMessage , this ) ) ; } } | Override WInput s validateComponent to perform further validation on the date . A partial date is invalid if there was text submitted but no date components were parsed . | 65 | 31 |
18,784 | public void setDate ( final Date date ) { if ( date == null ) { setPartialDate ( null , null , null ) ; } else { Calendar cal = Calendar . getInstance ( ) ; cal . setTime ( date ) ; Integer year = cal . get ( Calendar . YEAR ) ; Integer month = cal . get ( Calendar . MONTH ) + 1 ; Integer day = cal . get ( Calendar . DAY_OF_MONTH ) ; setPartialDate ( day , month , year ) ; } } | Set the WPartialDateField with the given java date . | 108 | 13 |
18,785 | public Integer getDay ( ) { String dateValue = getValue ( ) ; if ( dateValue != null && dateValue . length ( ) == DAY_END ) { return parseDateComponent ( dateValue . substring ( DAY_START , DAY_END ) , getPaddingChar ( ) ) ; } else { return null ; } } | Returns the day of the month value . | 72 | 8 |
18,786 | public Integer getMonth ( ) { String dateValue = getValue ( ) ; if ( dateValue != null && dateValue . length ( ) >= MONTH_END ) { return parseDateComponent ( dateValue . substring ( MONTH_START , MONTH_END ) , getPaddingChar ( ) ) ; } else { return null ; } } | Returns the month value . | 75 | 5 |
18,787 | public Integer getYear ( ) { String dateValue = getValue ( ) ; if ( dateValue != null && dateValue . length ( ) >= YEAR_END ) { return parseDateComponent ( dateValue . substring ( YEAR_START , YEAR_END ) , getPaddingChar ( ) ) ; } else { return null ; } } | Returns the year value . | 72 | 5 |
18,788 | public Date getDate ( ) { if ( getYear ( ) != null && getMonth ( ) != null && getDay ( ) != null ) { return DateUtilities . createDate ( getDay ( ) , getMonth ( ) , getYear ( ) ) ; } return null ; } | Returns the java date value else null if the value cannot be parsed . | 60 | 14 |
18,789 | private boolean isValidCharacters ( final String component , final char padding ) { // Check the component is either all padding chars or all digit chars boolean paddingChars = false ; boolean digitChars = false ; for ( int i = 0 ; i < component . length ( ) ; i ++ ) { char chr = component . charAt ( i ) ; // Padding if ( chr == padding ) { if ( digitChars ) { return false ; } paddingChars = true ; } else if ( chr >= ' ' && chr <= ' ' ) { // Digit if ( paddingChars ) { return false ; } digitChars = true ; } else { return false ; } } return true ; } | Check the component is either all padding chars or all digit chars . | 150 | 13 |
18,790 | public static String getPathToRoot ( final WComponent component ) { StringBuffer buf = new StringBuffer ( ) ; for ( WComponent node = component ; node != null ; node = node . getParent ( ) ) { if ( buf . length ( ) != 0 ) { buf . insert ( 0 , ' ' ) ; } buf . insert ( 0 , node . getClass ( ) . getName ( ) ) ; } return buf . toString ( ) ; } | Retrieves a path of component classes from the given component to the root node . The path is formatted with one component on each line with the first line being the root node . | 97 | 36 |
18,791 | public static < T > T getAncestorOfClass ( final Class < T > clazz , final WComponent comp ) { if ( comp == null || clazz == null ) { return null ; } WComponent parent = comp . getParent ( ) ; while ( parent != null ) { if ( clazz . isInstance ( parent ) ) { return ( T ) parent ; } parent = parent . getParent ( ) ; } return null ; } | Attempts to find a component which is an ancestor of the given component and that is assignable to the given class . | 94 | 23 |
18,792 | public static WComponent getTop ( final WComponent comp ) { WComponent top = comp ; for ( WComponent parent = top . getParent ( ) ; parent != null ; parent = parent . getParent ( ) ) { top = parent ; } return top ; } | Retrieves the top - level WComponent in the tree . | 55 | 13 |
18,793 | public static String encodeUrl ( final String urlStr ) { if ( Util . empty ( urlStr ) ) { return urlStr ; } // Percent Encode String percentEncode = percentEncodeUrl ( urlStr ) ; // XML Enocde return encode ( percentEncode ) ; } | Encode URL for XML . | 61 | 6 |
18,794 | public static String percentEncodeUrl ( final String urlStr ) { if ( Util . empty ( urlStr ) ) { return urlStr ; } try { // Avoid double encoding String decode = URIUtil . decode ( urlStr ) ; URI uri = new URI ( decode , false ) ; return uri . getEscapedURIReference ( ) ; } catch ( Exception e ) { return urlStr ; } } | Percent encode a URL to include in HTML . | 89 | 9 |
18,795 | public static String escapeForUrl ( final String input ) { if ( input == null || input . length ( ) == 0 ) { return input ; } final StringBuilder buffer = new StringBuilder ( input . length ( ) * 2 ) ; // worst-case char [ ] characters = input . toCharArray ( ) ; for ( int i = 0 , len = input . length ( ) ; i < len ; ++ i ) { final char ch = characters [ i ] ; // Section 2.3 - Unreserved chars if ( ( ch >= ' ' && ch <= ' ' ) || ( ch >= ' ' && ch <= ' ' ) || ( ch >= ' ' && ch <= ' ' ) || ch == ' ' || ch == ' ' || ch == ' ' || ch == ' ' ) { buffer . append ( ch ) ; } else if ( ch <= 127 ) { // Other ASCII characters must be escaped final String hexString = Integer . toHexString ( ch ) ; if ( hexString . length ( ) == 1 ) { buffer . append ( "%0" ) . append ( hexString ) ; } else { buffer . append ( ' ' ) . append ( hexString ) ; } } else if ( ch <= 0x07FF ) { // Other non-ASCII chars must be UTF-8 encoded buffer . append ( ' ' ) . append ( Integer . toHexString ( 0xc0 | ( ch >> 6 ) ) ) ; buffer . append ( ' ' ) . append ( Integer . toHexString ( 0x80 | ( ch & 0x3F ) ) ) ; } else { buffer . append ( ' ' ) . append ( Integer . toHexString ( 0xe0 | ( ch >> 12 ) ) ) ; buffer . append ( ' ' ) . append ( Integer . toHexString ( 0x80 | ( ( ch >> 6 ) & 0x3F ) ) ) ; buffer . append ( ' ' ) . append ( Integer . toHexString ( 0x80 | ( ch & 0x3F ) ) ) ; } } return buffer . toString ( ) ; } | Escapes the given string to make it presentable in a URL . This follows RFC 3986 with some extensions for UTF - 8 . | 447 | 27 |
18,796 | public static String encode ( final String input ) { if ( input == null || input . length ( ) == 0 ) { return input ; } return ENCODE . translate ( input ) ; } | Encode all the special characters found in the given string to their escape sequences according to the XML specification and returns the resultant string . Eg . cat& ; dog > ; ant becomes cat& ; amp ; dog & ; gt ; ant . | 40 | 53 |
18,797 | public static String decode ( final String encoded ) { if ( encoded == null || encoded . length ( ) == 0 || encoded . indexOf ( ' ' ) == - 1 ) { return encoded ; } return DECODE . translate ( encoded ) ; } | This method is required on occasion because WebSphere Portal by default escapes < ; and > ; characters for security reasons . | 51 | 25 |
18,798 | public static String encodeBrackets ( final String input ) { if ( input == null || input . length ( ) == 0 ) { // For performance reasons don't use Util.empty return input ; } return ENCODE_BRACKETS . translate ( input ) ; } | Encode open or closed brackets in the input String . | 57 | 11 |
18,799 | public static String decodeBrackets ( final String input ) { if ( input == null || input . length ( ) == 0 ) { // For performance reasons don't use Util.empty return input ; } return DECODE_BRACKETS . translate ( input ) ; } | Decode open or closed brackets in the input String . | 56 | 11 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.