idx
int64 0
41.2k
| question
stringlengths 74
4.04k
| target
stringlengths 7
750
|
|---|---|---|
38,200
|
public static Ellipsoid of ( final String name , final double a , final double b , final double f ) { return new Ellipsoid ( name , a , b , f ) ; }
|
Create a new earth ellipsoid with the given parameters .
|
38,201
|
public static Builder builder ( final String version , final String creator ) { return new Builder ( Version . of ( version ) , creator ) ; }
|
Create a new GPX builder with the given GPX version and creator string .
|
38,202
|
public static Reader reader ( final Version version , final Mode mode ) { return new Reader ( GPX . xmlReader ( version ) , mode ) ; }
|
Return a GPX reader reading GPX files with the given version and in the given reading mode .
|
38,203
|
public static Reader reader ( final Version version ) { return new Reader ( GPX . xmlReader ( version ) , Mode . STRICT ) ; }
|
Return a GPX reader reading GPX files with the given version and in strict reading mode .
|
38,204
|
public static Reader reader ( final Mode mode ) { return new Reader ( GPX . xmlReader ( Version . V11 ) , mode ) ; }
|
Return a GPX reader reading GPX files with version 1 . 1 and in the given reading mode .
|
38,205
|
public String toPattern ( ) { return _formats . stream ( ) . map ( Objects :: toString ) . collect ( Collectors . joining ( ) ) ; }
|
Return the pattern string represented by this formatter .
|
38,206
|
static String readString ( final DataInput in ) throws IOException { final byte [ ] bytes = new byte [ readInt ( in ) ] ; in . readFully ( bytes ) ; return new String ( bytes , "UTF-8" ) ; }
|
Reads a string value from the given data input .
|
38,207
|
static < T > void writes ( final Collection < ? extends T > elements , final Writer < ? super T > writer , final DataOutput out ) throws IOException { writeInt ( elements . size ( ) , out ) ; for ( T element : elements ) { writer . write ( element , out ) ; } }
|
Write the given elements to the data output .
|
38,208
|
static < T > List < T > reads ( final Reader < ? extends T > reader , final DataInput in ) throws IOException { final int length = readInt ( in ) ; final List < T > elements = new ArrayList < > ( length ) ; for ( int i = 0 ; i < length ; ++ i ) { elements . add ( reader . read ( in ) ) ; } return elements ; }
|
Reads a list of elements from the given data input .
|
38,209
|
public double to ( final Unit unit ) { requireNonNull ( unit ) ; return unit . convert ( _value , Unit . METERS_PER_SECOND ) ; }
|
Return the GPS speed value in the desired unit .
|
38,210
|
public static < T extends Serializable > Flowable < T > write ( final Flowable < T > source , final File file ) { return write ( source , file , false , DEFAULT_BUFFER_SIZE ) ; }
|
Writes the source stream to the given file in given append mode and using the a buffer size of 8192 bytes .
|
38,211
|
static Method getMethod ( Class < ? > cls , String name , Class < ? > ... params ) { Method m ; try { m = cls . getDeclaredMethod ( name , params ) ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } m . setAccessible ( true ) ; return m ; }
|
Bundle reflection calls to get access to the given method
|
38,212
|
private void mapAndSetOffset ( ) { try { final RandomAccessFile backingFile = new RandomAccessFile ( this . file , "rw" ) ; backingFile . setLength ( this . size ) ; final FileChannel ch = backingFile . getChannel ( ) ; this . addr = ( Long ) mmap . invoke ( ch , 1 , 0L , this . size ) ; ch . close ( ) ; backingFile . close ( ) ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } }
|
for the given length and set this . addr to the returned offset
|
38,213
|
public void getBytes ( long pos , byte [ ] data , long offset , long length ) { unsafe . copyMemory ( null , pos + addr , data , BYTE_ARRAY_OFFSET + offset , length ) ; }
|
May want to have offset & length within data as well for both of these
|
38,214
|
public Phrase put ( String key , CharSequence value ) { if ( ! keys . contains ( key ) ) { throw new IllegalArgumentException ( "Invalid key: " + key ) ; } if ( value == null ) { throw new IllegalArgumentException ( "Null value for '" + key + "'" ) ; } keysToValues . put ( key , value ) ; formatted = null ; return this ; }
|
Replaces the given key with a non - null value . You may reuse Phrase instances and replace keys with new values .
|
38,215
|
public Phrase putOptional ( String key , CharSequence value ) { return keys . contains ( key ) ? put ( key , value ) : this ; }
|
Silently ignored if the key is not in the pattern .
|
38,216
|
public CharSequence format ( ) { if ( formatted == null ) { if ( ! keysToValues . keySet ( ) . containsAll ( keys ) ) { Set < String > missingKeys = new HashSet < String > ( keys ) ; missingKeys . removeAll ( keysToValues . keySet ( ) ) ; throw new IllegalArgumentException ( "Missing keys: " + missingKeys ) ; } SpannableStringBuilder sb = new SpannableStringBuilder ( pattern ) ; for ( Token t = head ; t != null ; t = t . next ) { t . expand ( sb , keysToValues ) ; } formatted = sb ; } return formatted ; }
|
Returns the text after replacing all keys with values .
|
38,217
|
private Token token ( Token prev ) { if ( curChar == EOF ) { return null ; } if ( curChar == '{' ) { char nextChar = lookahead ( ) ; if ( nextChar == '{' ) { return leftCurlyBracket ( prev ) ; } else if ( nextChar >= 'a' && nextChar <= 'z' ) { return key ( prev ) ; } else { throw new IllegalArgumentException ( "Unexpected first character '" + nextChar + "'; must be lower case a-z." ) ; } } return text ( prev ) ; }
|
Returns the next token from the input pattern or null when finished parsing .
|
38,218
|
private TextToken text ( Token prev ) { int startIndex = curCharIndex ; while ( curChar != '{' && curChar != EOF ) { consume ( ) ; } return new TextToken ( prev , curCharIndex - startIndex ) ; }
|
Consumes and returns a token for a sequence of text .
|
38,219
|
private void consume ( ) { curCharIndex ++ ; curChar = ( curCharIndex == pattern . length ( ) ) ? EOF : pattern . charAt ( curCharIndex ) ; }
|
Advances the current character position without any error checking . Consuming beyond the end of the string can only happen if this parser contains a bug .
|
38,220
|
private String determineLanguage ( FacesContext fc , DataTable dataTable ) { final List < String > availableLanguages = Arrays . asList ( "de" , "en" , "es" , "fr" , "hu" , "it" , "nl" , "pl" , "pt" , "ru" ) ; if ( BsfUtils . isStringValued ( dataTable . getCustomLangUrl ( ) ) ) { return dataTable . getCustomLangUrl ( ) ; } else if ( BsfUtils . isStringValued ( dataTable . getLang ( ) ) ) { String lang = dataTable . getLang ( ) ; if ( availableLanguages . contains ( lang ) ) { return determineLanguageUrl ( fc , lang ) ; } } else { String lang = fc . getViewRoot ( ) . getLocale ( ) . getLanguage ( ) ; if ( availableLanguages . contains ( lang ) ) { return determineLanguageUrl ( fc , lang ) ; } } return null ; }
|
Determine if the user specify a lang Otherwise return null to avoid language settings .
|
38,221
|
public String getType ( ) { String mode = A . asString ( getAttributes ( ) . get ( "mode" ) , "badge" ) ; return mode . equals ( "edit" ) ? "text" : "hidden" ; }
|
Method added to prevent AngularFaces from setting the type
|
38,222
|
protected void renderPassThruAttributes ( FacesContext context , UIComponent component , String [ ] attrs , boolean shouldRenderDataAttributes ) throws IOException { ResponseWriter writer = context . getResponseWriter ( ) ; if ( ( attrs == null || attrs . length <= 0 ) && shouldRenderDataAttributes == false ) return ; for ( String attribute : component . getAttributes ( ) . keySet ( ) ) { boolean attributeToRender = false ; if ( shouldRenderDataAttributes && attribute . startsWith ( "data-" ) ) { attributeToRender = true ; } if ( ! attributeToRender && attrs != null ) { for ( String ca : attrs ) { if ( attribute . equals ( ca ) ) { attributeToRender = true ; break ; } } } if ( attributeToRender ) { Object value = component . getAttributes ( ) . get ( attribute ) ; if ( shouldRenderAttribute ( value ) ) writer . writeAttribute ( attribute , value . toString ( ) , attribute ) ; } } }
|
Method that provide ability to render pass through attributes .
|
38,223
|
protected void generateErrorAndRequiredClass ( UIInput input , ResponseWriter rw , String clientId , String additionalClass1 , String additionalClass2 , String additionalClass3 ) throws IOException { String styleClass = getErrorAndRequiredClass ( input , clientId ) ; if ( null != additionalClass1 ) { additionalClass1 = additionalClass1 . trim ( ) ; if ( additionalClass1 . trim ( ) . length ( ) > 0 ) { styleClass += " " + additionalClass1 ; } } if ( null != additionalClass2 ) { additionalClass2 = additionalClass2 . trim ( ) ; if ( additionalClass2 . trim ( ) . length ( ) > 0 ) { styleClass += " " + additionalClass2 ; } } if ( null != additionalClass3 ) { additionalClass3 = additionalClass3 . trim ( ) ; if ( additionalClass3 . trim ( ) . length ( ) > 0 ) { styleClass += " " + additionalClass3 ; } } rw . writeAttribute ( "class" , styleClass , "class" ) ; }
|
Renders the CSS pseudo classes for required fields and for the error levels .
|
38,224
|
public static Converter getConverter ( FacesContext fc , ValueHolder vh ) { Converter converter = vh . getConverter ( ) ; if ( converter == null ) { ValueExpression expr = ( ( UIComponent ) vh ) . getValueExpression ( "value" ) ; if ( expr != null ) { Class < ? > valueType = expr . getType ( fc . getELContext ( ) ) ; if ( valueType != null ) { converter = fc . getApplication ( ) . createConverter ( valueType ) ; } } } return converter ; }
|
Finds the appropriate converter for a given value holder
|
38,225
|
public static String getRequestParameter ( FacesContext context , String name ) { return context . getExternalContext ( ) . getRequestParameterMap ( ) . get ( name ) ; }
|
Returns request parameter value for the provided parameter name .
|
38,226
|
public static boolean beginDisabledFieldset ( IContentDisabled component , ResponseWriter rw ) throws IOException { if ( component . isContentDisabled ( ) ) { rw . startElement ( "fieldset" , ( UIComponent ) component ) ; rw . writeAttribute ( "disabled" , "disabled" , "null" ) ; return true ; } return false ; }
|
Renders the code disabling every input field and every button within a container .
|
38,227
|
protected String getFormGroupWithFeedback ( String additionalClass , String clientId ) { if ( BsfUtils . isLegacyFeedbackClassesEnabled ( ) ) { return additionalClass ; } return additionalClass + " " + FacesMessages . getErrorSeverityClass ( clientId ) ; }
|
Get the main field container
|
38,228
|
public static String getValueAsString ( Object value , FacesContext ctx , DateTimePicker dtp ) { if ( value == null ) { return null ; } Locale sloc = BsfUtils . selectLocale ( ctx . getViewRoot ( ) . getLocale ( ) , dtp . getLocale ( ) , dtp ) ; String javaFormatString = BsfUtils . selectJavaDateTimeFormatFromMomentJSFormatOrDefault ( sloc , dtp . getFormat ( ) , dtp . isShowDate ( ) , dtp . isShowTime ( ) ) ; return getDateAsString ( ctx , dtp , value , javaFormatString , sloc ) ; }
|
Yields the value which is displayed in the input field of the date picker .
|
38,229
|
public static String getDateAsString ( FacesContext fc , DateTimePicker dtp , Object value , String javaFormatString , Locale locale ) { if ( value == null ) { return null ; } Converter converter = dtp . getConverter ( ) ; return converter == null ? getInternalDateAsString ( value , javaFormatString , locale ) : converter . getAsString ( fc , dtp , value ) ; }
|
Get date in string format
|
38,230
|
private void encodeSeverityMessage ( FacesContext facesContext , Growl uiGrowl , FacesMessage msg ) throws IOException { ResponseWriter writer = facesContext . getResponseWriter ( ) ; String summary = msg . getSummary ( ) != null ? msg . getSummary ( ) : "" ; String detail = msg . getDetail ( ) != null ? msg . getDetail ( ) : summary ; if ( uiGrowl . isEscape ( ) ) { summary = BsfUtils . escapeHtml ( summary ) ; detail = BsfUtils . escapeHtml ( detail ) ; } summary = summary . replace ( "'" , "\\\'" ) ; detail = detail . replace ( "'" , "\\\'" ) ; String messageType = getMessageType ( msg ) ; String icon = uiGrowl . getIcon ( ) != null ? "fa fa-" + uiGrowl . getIcon ( ) : getSeverityIcon ( msg ) ; String template = null ; if ( uiGrowl . getStyle ( ) != null ) { template = TEMPLATE . replace ( "{8}" , "style='" + uiGrowl . getStyle ( ) + "'" ) ; } if ( uiGrowl . getStyleClass ( ) != null ) { if ( null == template ) { template = TEMPLATE ; } template = template . replace ( "{9}" , uiGrowl . getStyleClass ( ) ) ; } if ( null == template ) { template = "" ; } else { template = ", template: \"" + template . replace ( "{8}" , "" ) . replace ( "{9}" , "" ) . replace ( "\n" , "" ) + "\"" ; System . out . println ( template ) ; } writer . writeText ( "" + "$.notify({" + " title: '" + ( uiGrowl . isShowSummary ( ) ? summary : "" ) + "', " + " message: '" + ( uiGrowl . isShowDetail ( ) ? detail : "" ) + "', " + " icon: '" + icon + "'" + "}, {" + " position: null, " + " type: '" + messageType + "', " + " allow_dismiss: " + uiGrowl . isAllowDismiss ( ) + ", " + " newest_on_top: " + uiGrowl . isNewestOnTop ( ) + ", " + " delay: " + uiGrowl . getDelay ( ) + ", " + " timer: " + uiGrowl . getTimer ( ) + ", " + " placement: { " + " from: '" + uiGrowl . getPlacementFrom ( ) + "'," + " align: '" + uiGrowl . getPlacementAlign ( ) + "'" + " }, " + " animate: { " + " enter: '" + uiGrowl . getAnimationEnter ( ) + "', " + " exit: '" + uiGrowl . getAnimationExit ( ) + "' " + " } " + " " + template + " }); " + "" , null ) ; }
|
Encode single faces message as growl
|
38,231
|
private String getSeverityIcon ( FacesMessage message ) { if ( message . getSeverity ( ) . equals ( FacesMessage . SEVERITY_WARN ) ) return "fa fa-exclamation-triangle" ; else if ( message . getSeverity ( ) . equals ( FacesMessage . SEVERITY_ERROR ) ) return "fa fa-times-circle" ; else if ( message . getSeverity ( ) . equals ( FacesMessage . SEVERITY_FATAL ) ) return "fa fa-ban" ; return "fa fa-info-circle" ; }
|
Get severity related icons . We use FA icons because future version of Bootstrap does not support glyphicons anymore
|
38,232
|
private String getMessageType ( FacesMessage message ) { if ( message . getSeverity ( ) . equals ( FacesMessage . SEVERITY_WARN ) ) return "warning" ; else if ( message . getSeverity ( ) . equals ( FacesMessage . SEVERITY_ERROR ) ) return "danger" ; else if ( message . getSeverity ( ) . equals ( FacesMessage . SEVERITY_FATAL ) ) return "danger" ; else if ( message . getSeverity ( ) . equals ( FacesMessage . SEVERITY_INFO ) ) return "info" ; return "success" ; }
|
Translate severity type to growl style class
|
38,233
|
public static void printNodeData ( Node rootNode , String tab ) { tab = tab == null ? "" : tab + " " ; for ( Node n : rootNode . getChilds ( ) ) { printNodeData ( n , tab ) ; } }
|
Debug method to print tree node structure
|
38,234
|
public static Node searchNodeById ( Node rootNode , int nodeId ) { if ( rootNode . getNodeId ( ) == nodeId ) { return rootNode ; } Node foundNode = null ; for ( Node n : rootNode . getChilds ( ) ) { foundNode = searchNodeById ( n , nodeId ) ; if ( foundNode != null ) { break ; } } return foundNode ; }
|
Basic implementation of recursive node search by id It works only on a DefaultNodeImpl
|
38,235
|
public static String renderModelAsJson ( Node rootNode , boolean renderRoot ) { if ( renderRoot ) { return renderSubnodes ( rootNode == null ? new ArrayList < Node > ( ) : new ArrayList < Node > ( Arrays . asList ( rootNode ) ) ) ; } else if ( rootNode != null && rootNode . hasChild ( ) ) { return renderSubnodes ( rootNode . getChilds ( ) ) ; } return "" ; }
|
Render the node model as JSON
|
38,236
|
public static void encodeDropMenuStart ( DropMenu c , ResponseWriter rw , String l ) throws IOException { rw . startElement ( "ul" , c ) ; if ( c . getContentClass ( ) != null ) rw . writeAttribute ( "class" , "dropdown-menu " + c . getContentClass ( ) , "class" ) ; else rw . writeAttribute ( "class" , "dropdown-menu" , "class" ) ; if ( null != c . getContentStyle ( ) ) rw . writeAttribute ( "style" , c . getContentStyle ( ) , "style" ) ; rw . writeAttribute ( "role" , "menu" , null ) ; rw . writeAttribute ( "aria-labelledby" , l , null ) ; }
|
Renders the Drop Menu .
|
38,237
|
private static void drawClearDiv ( ResponseWriter writer , UIComponent tabView ) throws IOException { writer . startElement ( "div" , tabView ) ; writer . writeAttribute ( "style" , "clear:both;" , "style" ) ; writer . endElement ( "div" ) ; }
|
Draw a clear div
|
38,238
|
private static void encodeTabLinks ( FacesContext context , ResponseWriter writer , TabView tabView , int currentlyActiveIndex , List < UIComponent > tabs , String clientId , String hiddenInputFieldID ) throws IOException { writer . startElement ( "ul" , tabView ) ; writer . writeAttribute ( "id" , clientId , "id" ) ; Tooltip . generateTooltip ( context , tabView , writer ) ; String classes = "nav " ; if ( "left" . equalsIgnoreCase ( tabView . getTabPosition ( ) ) || "right" . equalsIgnoreCase ( tabView . getTabPosition ( ) ) ) { classes += " nav-pills nav-stacked" ; } else { classes = classes + ( tabView . isPills ( ) ? " nav-pills" : " nav-tabs" ) ; } if ( tabView . getStyleClass ( ) != null ) { classes += " " ; classes += tabView . getStyleClass ( ) ; } writer . writeAttribute ( "class" , classes , "class" ) ; String role = "tablist" ; AJAXRenderer . generateBootsFacesAJAXAndJavaScript ( context , tabView , writer , false ) ; R . encodeHTML4DHTMLAttrs ( writer , tabView . getAttributes ( ) , new String [ ] { "style" } ) ; if ( tabView . getRole ( ) != null ) { role = tabView . getRole ( ) ; } writer . writeAttribute ( "role" , role , "role" ) ; encodeTabs ( context , writer , tabs , currentlyActiveIndex , hiddenInputFieldID , tabView . isDisabled ( ) ) ; writer . endElement ( "ul" ) ; }
|
Encode the list of links that render the tabs
|
38,239
|
private static void encodeTabContentPanes ( final FacesContext context , final ResponseWriter writer , final TabView tabView , final int currentlyActiveIndex , final List < UIComponent > tabs ) throws IOException { writer . startElement ( "div" , tabView ) ; String classes = "tab-content" ; if ( tabView . getContentClass ( ) != null ) { classes += " " ; classes += tabView . getContentClass ( ) ; } writer . writeAttribute ( "class" , classes , "class" ) ; if ( tabView . getContentStyle ( ) != null ) { String inlineCSS = tabView . getContentStyle ( ) ; writer . writeAttribute ( "style" , inlineCSS , "style" ) ; } String role = "tablist" ; if ( tabView . getRole ( ) != null ) { role = tabView . getRole ( ) ; } writer . writeAttribute ( "role" , role , "role" ) ; if ( null != tabs ) { int numberOfTabsRendered = 0 ; for ( int index = 0 ; index < tabs . size ( ) ; index ++ ) { final Tab tab = ( Tab ) tabs . get ( index ) ; if ( tab . isRendered ( ) ) { final int currentIndex = numberOfTabsRendered ; Runnable r = new Runnable ( ) { int offset = 0 ; public void run ( ) { try { encodeTabPane ( context , writer , tab , ( currentIndex + offset == currentlyActiveIndex ) && ( ! tabView . isDisabled ( ) ) ) ; offset ++ ; } catch ( IOException ex ) { LOGGER . log ( Level . SEVERE , "An exception occurred while rendering a tab." , ex ) ; } } } ; if ( tab . getValue ( ) == null ) { r . run ( ) ; numberOfTabsRendered ++ ; } else { numberOfTabsRendered += ( ( Tab ) tabs . get ( currentIndex ) ) . encodeTabs ( context , r ) ; } } } } writer . endElement ( "div" ) ; }
|
Generates the HTML of the tab panes .
|
38,240
|
private static void encodeTabs ( final FacesContext context , final ResponseWriter writer , final List < UIComponent > children , final int currentlyActiveIndex , final String hiddenInputFieldID , final boolean disabled ) throws IOException { if ( null != children ) { int tabIndex = 0 ; for ( int index = 0 ; index < children . size ( ) ; index ++ ) { final int loopIndex = index ; final int currentIndex = tabIndex ; final Tab tab = ( Tab ) children . get ( loopIndex ) ; Runnable r = new Runnable ( ) { int offset = 0 ; public void run ( ) { try { encodeTab ( context , writer , tab , currentIndex + offset == currentlyActiveIndex , hiddenInputFieldID , currentIndex + offset , disabled ) ; offset ++ ; } catch ( IOException ex ) { LOGGER . log ( Level . SEVERE , "An exception occurred while rendering a tab." , ex ) ; } } } ; if ( ( ( Tab ) children . get ( index ) ) . getValue ( ) == null ) { r . run ( ) ; tabIndex ++ ; } else { tabIndex += tab . encodeTabs ( context , r ) ; } } } }
|
Generates the HTML of the tabs .
|
38,241
|
private static void encodeTabAnchorTag ( FacesContext context , ResponseWriter writer , Tab tab , String hiddenInputFieldID , int tabindex , boolean disabled ) throws IOException { writer . startElement ( "a" , tab ) ; writer . writeAttribute ( "id" , tab . getClientId ( ) . replace ( ":" , "_" ) + "_tab" , "id" ) ; writer . writeAttribute ( "role" , "tab" , "role" ) ; if ( tab . isDisabled ( ) || disabled ) { writer . writeAttribute ( "onclick" , "event.preventDefault(); return false;" , null ) ; } else { writer . writeAttribute ( "data-toggle" , "tab" , "data-toggle" ) ; writer . writeAttribute ( "href" , "#" + tab . getClientId ( ) . replace ( ":" , "_" ) + "_pane" , "href" ) ; String onclick = "document.getElementById('" + hiddenInputFieldID + "').value='" + String . valueOf ( tabindex ) + "';" ; AJAXRenderer . generateBootsFacesAJAXAndJavaScript ( context , tab , writer , "click" , onclick , false , true ) ; } R . encodeHTML4DHTMLAttrs ( writer , tab . getAttributes ( ) , new String [ ] { "style" , "tabindex" } ) ; UIComponent iconFacet = tab . getFacet ( "anchor" ) ; if ( null != iconFacet ) { iconFacet . encodeAll ( FacesContext . getCurrentInstance ( ) ) ; if ( null != tab . getTitle ( ) ) { writer . writeText ( " " + tab . getTitle ( ) , null ) ; } } else { writer . writeText ( tab . getTitle ( ) , null ) ; } writer . endElement ( "a" ) ; }
|
Generate the clickable entity of the tab .
|
38,242
|
public static int toInt ( Object val ) { if ( val == null ) { return 0 ; } if ( val instanceof Number ) { return ( ( Number ) val ) . intValue ( ) ; } if ( val instanceof String ) { return Integer . parseInt ( ( String ) val ) ; } throw new IllegalArgumentException ( "Cannot convert " + val ) ; }
|
Converts the parameter to an integer value if possible . Throws an IllegalArgumentException if the parameter cannot be converted to an integer .
|
38,243
|
private String encodeClick ( FacesContext context , Button button ) { String js ; String userClick = button . getOnclick ( ) ; if ( userClick != null ) { js = userClick ; } else { js = "" ; } String fragment = button . getFragment ( ) ; String outcome = button . getOutcome ( ) ; if ( null != outcome && outcome . contains ( "#" ) ) { if ( null != fragment && fragment . length ( ) > 0 ) { throw new FacesException ( "Please define the URL fragment either in the fragment attribute or in the outcome attribute, but not both" ) ; } int pos = outcome . indexOf ( "#" ) ; fragment = outcome . substring ( pos ) ; outcome = outcome . substring ( 0 , pos ) ; } if ( outcome == null || outcome . equals ( "" ) ) { if ( null != fragment && fragment . length ( ) > 0 ) { if ( ! fragment . startsWith ( "#" ) ) { fragment = "#" + fragment ; } js += "window.open('" + fragment + "', '" ; if ( button . getTarget ( ) != null ) js += button . getTarget ( ) ; else js += "_self" ; js += "');" ; return js ; } } if ( outcome == null || outcome . equals ( "" ) || outcome . equals ( "@none" ) ) return js ; if ( canOutcomeBeRendered ( button , fragment , outcome ) ) { String url = determineTargetURL ( context , button , outcome ) ; if ( url != null ) { if ( url . startsWith ( "alert(" ) ) { js = url ; } else { if ( fragment != null ) { if ( fragment . startsWith ( "#" ) ) { url += fragment ; } else { url += "#" + fragment ; } } js += "window.open('" + url + "', '" ; if ( button . getTarget ( ) != null ) js += button . getTarget ( ) ; else js += "_self" ; js += "');" ; } } } return js ; }
|
Renders the Javascript code dealing with the click event . If the developer provides their own onclick handler is precedes the generated Javascript code .
|
38,244
|
private boolean canOutcomeBeRendered ( Button button , String fragment , String outcome ) { boolean renderOutcome = true ; if ( null == outcome && button . getAttributes ( ) != null && button . getAttributes ( ) . containsKey ( "ng-click" ) ) { String ngClick = ( String ) button . getAttributes ( ) . get ( "ng-click" ) ; if ( null != ngClick && ( ngClick . length ( ) > 0 ) ) { if ( fragment == null ) { renderOutcome = false ; } } } return renderOutcome ; }
|
Do we have to suppress the target URL?
|
38,245
|
private String determineTargetURL ( FacesContext context , Button button , String outcome ) { ConfigurableNavigationHandler cnh = ( ConfigurableNavigationHandler ) context . getApplication ( ) . getNavigationHandler ( ) ; NavigationCase navCase = cnh . getNavigationCase ( context , null , outcome ) ; if ( navCase == null ) { if ( FacesContext . getCurrentInstance ( ) . getApplication ( ) . getProjectStage ( ) . equals ( ProjectStage . Development ) ) { return "alert('WARNING! " + C . W_NONAVCASE_BUTTON + "');" ; } else { return "" ; } } String vId = navCase . getToViewId ( context ) ; Map < String , List < String > > params = getParams ( navCase , button ) ; String url ; url = context . getApplication ( ) . getViewHandler ( ) . getBookmarkableURL ( context , vId , params , button . isIncludeViewParams ( ) || navCase . isIncludeViewParams ( ) ) ; return url ; }
|
Translate the outcome attribute value to the target URL .
|
38,246
|
private static String getStyleClasses ( Button button , boolean isResponsive ) { StringBuilder sb ; sb = new StringBuilder ( 40 ) ; sb . append ( "btn" ) ; String size = button . getSize ( ) ; if ( size != null ) { sb . append ( " btn-" ) . append ( size ) ; } String look = button . getLook ( ) ; if ( look != null ) { sb . append ( " btn-" ) . append ( look ) ; } else { sb . append ( " btn-default" ) ; } if ( button . isDisabled ( ) ) { sb . append ( " disabled" ) ; } if ( isResponsive ) { sb . append ( " btn-block" ) ; } String sclass = button . getStyleClass ( ) ; if ( sclass != null ) { sb . append ( " " ) . append ( sclass ) ; } return sb . toString ( ) . trim ( ) ; }
|
Collects the CSS classes of the button .
|
38,247
|
public List < UIComponent > resolve ( UIComponent component , List < UIComponent > parentComponents , String currentId , String originalExpression , String [ ] parameters ) { List < UIComponent > result = new ArrayList < UIComponent > ( ) ; for ( UIComponent parent : parentComponents ) { UIComponent grandparent = component . getParent ( ) ; for ( int i = 0 ; i < grandparent . getChildCount ( ) ; i ++ ) { if ( grandparent . getChildren ( ) . get ( i ) == parent ) { if ( i == 0 ) throw new FacesException ( ERROR_MESSAGE + originalExpression ) ; while ( ( -- i ) >= 0 ) { result . add ( grandparent . getChildren ( ) . get ( i ) ) ; } return result ; } } } throw new FacesException ( ERROR_MESSAGE + originalExpression ) ; }
|
Collects everything preceding the current JSF node within the same branch of the tree . It s like
|
38,248
|
public void encodeEnd ( FacesContext context , UIComponent component ) throws IOException { if ( ! component . isRendered ( ) ) { return ; } PanelGrid panelGrid = ( PanelGrid ) component ; ResponseWriter writer = context . getResponseWriter ( ) ; boolean idHasBeenRendered = false ; String responsiveStyle = Responsive . getResponsiveStyleClass ( panelGrid , false ) ; if ( null != responsiveStyle ) { writer . startElement ( "div" , panelGrid ) ; writer . writeAttribute ( "class" , responsiveStyle . trim ( ) , null ) ; String clientId = panelGrid . getClientId ( ) ; writer . writeAttribute ( "id" , clientId , "id" ) ; idHasBeenRendered = true ; } generateContainerStart ( writer , panelGrid , idHasBeenRendered ) ; beginDisabledFieldset ( panelGrid , writer ) ; int [ ] columns = getColSpanArray ( panelGrid ) ; String [ ] columnClasses = getColumnClasses ( panelGrid , columns ) ; String [ ] rowClasses = getRowClasses ( panelGrid ) ; int row = 0 ; int column = 0 ; List < UIComponent > children = panelGrid . getChildren ( ) ; for ( UIComponent child : children ) { if ( 0 == column ) { generateRowStart ( writer , row , rowClasses , panelGrid ) ; } generateColumnStart ( child , columnClasses [ column ] , writer ) ; child . encodeAll ( context ) ; generateColumnEnd ( writer , columns [ column ] ) ; column ++ ; if ( column >= columns . length ) { generateRowEnd ( writer , row , rowClasses ) ; column = 0 ; row ++ ; } } if ( column != 0 ) { generateRowEnd ( writer , row , rowClasses ) ; column = 0 ; row ++ ; } endDisabledFieldset ( panelGrid , writer ) ; generateContainerEnd ( writer ) ; if ( null != responsiveStyle ) { writer . endElement ( "div" ) ; } Tooltip . activateTooltips ( context , panelGrid ) ; }
|
Renders the grid component and its children .
|
38,249
|
protected String [ ] getRowClasses ( PanelGrid grid ) { String rowClasses = grid . getRowClasses ( ) ; if ( null == rowClasses || rowClasses . trim ( ) . length ( ) == 0 ) return null ; String [ ] rows = rowClasses . split ( "," ) ; return rows ; }
|
Extract the option row classes from the JSF file .
|
38,250
|
protected int [ ] getColSpanArray ( PanelGrid panelGrid ) { String columnsCSV = panelGrid . getColSpans ( ) ; if ( null == columnsCSV || columnsCSV . trim ( ) . length ( ) == 0 ) { columnsCSV = panelGrid . getColumns ( ) ; if ( "1" . equals ( columnsCSV ) ) { columnsCSV = "12" ; } else if ( "2" . equals ( columnsCSV ) ) { columnsCSV = "6,6" ; } else if ( "3" . equals ( columnsCSV ) ) { columnsCSV = "4,4,4" ; } else if ( "4" . equals ( columnsCSV ) ) { columnsCSV = "3,3,3,3" ; } else if ( "6" . equals ( columnsCSV ) ) { columnsCSV = "2,2,2,2,2,2" ; } else if ( "12" . equals ( columnsCSV ) ) { columnsCSV = "1,1,1,1,1,1,1,1,1,1,1,1" ; } else { throw new FacesException ( "Error at " + panelGrid . getClientId ( ) + ". PanelGrid.columns attribute: Got " + columnsCSV + ". Legal values are 1, 2, 3, 4, 6 and 12. If you need a different number of columns, please use the attribute 'col-spans'." ) ; } } if ( null == columnsCSV || columnsCSV . trim ( ) . length ( ) == 0 ) { throw new FacesException ( "PanelGrid.colSpans attribute: Please provide a comma-separated list of integer values" ) ; } String [ ] columnList = columnsCSV . replaceAll ( " " , "" ) . split ( "," ) ; int [ ] columns = new int [ columnList . length ] ; int sum = 0 ; for ( int i = 0 ; i < columnList . length ; i ++ ) { try { columns [ i ] = ( int ) Integer . valueOf ( columnList [ i ] ) ; sum += columns [ i ] ; } catch ( NumberFormatException error ) { throw new FacesException ( "PanelGrid.colSpans attribute: the list has to consists of integer values" ) ; } } if ( sum != 12 ) { throw new FacesException ( "PanelGrid.colSpans attribute: The columns don't add up to 12" ) ; } return columns ; }
|
Read the colSpans attribute .
|
38,251
|
protected String [ ] getColumnClasses ( PanelGrid panelGrid , int [ ] colSpans ) { String columnsCSV = panelGrid . getColumnClasses ( ) ; String [ ] columnClasses ; if ( null == columnsCSV || columnsCSV . trim ( ) . length ( ) == 0 ) columnClasses = null ; else { columnClasses = columnsCSV . split ( "," ) ; if ( columnClasses . length > colSpans . length ) { throw new FacesException ( "PanelGrid: You defined more columnClasses than columns or colSpans" ) ; } } String size = panelGrid . getSize ( ) ; if ( null == size || size . trim ( ) . equals ( "" ) ) { size = "lg" ; } else { size = Responsive . translateSize ( size , true ) ; } String [ ] result = new String [ colSpans . length ] ; for ( int i = 0 ; i < colSpans . length ; i ++ ) { if ( columnClasses == null ) { result [ i ] = "col-" + size + "-" + colSpans [ i ] ; } else { String current = columnClasses [ i % columnClasses . length ] ; if ( current . contains ( "col-" ) ) { result [ i ] = current ; } else { result [ i ] = "col-" + size + "-" + colSpans [ i ] + " " + current ; } } } return result ; }
|
Merge the column span information and the optional columnClasses attribute .
|
38,252
|
protected void generateColumnStart ( UIComponent child , String colStyleClass , ResponseWriter writer ) throws IOException { writer . startElement ( "div" , child ) ; writer . writeAttribute ( "class" , colStyleClass , "class" ) ; }
|
Generates the start of each Bootstrap column .
|
38,253
|
protected void generateRowStart ( ResponseWriter writer , int row , String [ ] rowClasses , PanelGrid panelGrid ) throws IOException { writer . startElement ( "div" , panelGrid ) ; if ( null == rowClasses ) writer . writeAttribute ( "class" , "row" , "class" ) ; else writer . writeAttribute ( "class" , "row " + rowClasses [ row % rowClasses . length ] , "class" ) ; }
|
Generates the start of each Bootstrap row .
|
38,254
|
protected void generateContainerStart ( ResponseWriter writer , PanelGrid panelGrid , boolean idHasBeenRendered ) throws IOException { writer . startElement ( "div" , panelGrid ) ; if ( ! idHasBeenRendered ) { String clientId = panelGrid . getClientId ( ) ; writer . writeAttribute ( "id" , clientId , "id" ) ; } writeAttribute ( writer , "dir" , panelGrid . getDir ( ) , "dir" ) ; Tooltip . generateTooltip ( FacesContext . getCurrentInstance ( ) , panelGrid , writer ) ; String styleclass = panelGrid . getStyleClass ( ) ; if ( null != styleclass && styleclass . trim ( ) . length ( ) > 0 ) writer . writeAttribute ( "class" , styleclass , "class" ) ; String style = panelGrid . getStyle ( ) ; if ( null != style && style . trim ( ) . length ( ) > 0 ) writer . writeAttribute ( "style" , style , "style" ) ; }
|
Generates the start of the entire Bootstrap container .
|
38,255
|
protected void renderInputTag ( FacesContext context , ResponseWriter rw , String clientId , SelectBooleanCheckbox selectBooleanCheckbox ) throws IOException { int numberOfDivs = 0 ; String responsiveStyleClass = Responsive . getResponsiveStyleClass ( selectBooleanCheckbox , false ) . trim ( ) ; if ( responsiveStyleClass . length ( ) > 0 && isHorizontalForm ( selectBooleanCheckbox ) ) { rw . startElement ( "div" , selectBooleanCheckbox ) ; rw . writeAttribute ( "class" , responsiveStyleClass , "class" ) ; numberOfDivs ++ ; } renderInputTag ( rw , context , selectBooleanCheckbox , clientId ) ; renderInputTagAttributes ( rw , clientId , selectBooleanCheckbox ) ; AJAXRenderer . generateBootsFacesAJAXAndJavaScript ( FacesContext . getCurrentInstance ( ) , selectBooleanCheckbox , rw , false ) ; renderInputTagValue ( context , rw , selectBooleanCheckbox ) ; renderInputTagEnd ( rw , selectBooleanCheckbox ) ; renderInputTagHelper ( rw , context , selectBooleanCheckbox , clientId ) ; while ( numberOfDivs > 0 ) { rw . endElement ( "div" ) ; numberOfDivs -- ; } }
|
Renders the input tag .
|
38,256
|
protected void renderInputTagEnd ( ResponseWriter rw , SelectBooleanCheckbox selectBooleanCheckbox ) throws IOException { rw . endElement ( "input" ) ; String caption = selectBooleanCheckbox . getCaption ( ) ; if ( null != caption ) { if ( selectBooleanCheckbox . isEscape ( ) ) { rw . writeText ( " " + caption , null ) ; } else { rw . append ( " " + caption ) ; } } rw . endElement ( "label" ) ; rw . endElement ( "div" ) ; }
|
Closes the input tag . This method is protected in order to allow third - party frameworks to derive from it .
|
38,257
|
protected void renderInputTagValue ( FacesContext context , ResponseWriter rw , SelectBooleanCheckbox selectBooleanCheckbox ) throws IOException { String v = getValue2Render ( context , selectBooleanCheckbox ) ; if ( v != null && "true" . equals ( v ) ) { rw . writeAttribute ( "checked" , v , null ) ; } }
|
Renders the value of the input tag . This method is protected in order to allow third - party frameworks to derive from it .
|
38,258
|
public void setMask ( String mask ) { if ( mask != null && ! mask . isEmpty ( ) ) { AddResourcesListener . addResourceToHeadButAfterJQuery ( C . BSF_LIBRARY , "js/jquery.inputmask.bundle.min.js" ) ; } getStateHelper ( ) . put ( PropertyKeys . mask , mask ) ; }
|
Sets input mask and triggers JavaScript to be loaded .
|
38,259
|
private static String getStyleClasses ( AbstractNavLink link , boolean isResponsive ) { StringBuilder sb ; sb = new StringBuilder ( 20 ) ; String look = null ; if ( link instanceof Link ) { look = ( ( Link ) link ) . getLook ( ) ; } else if ( link instanceof CommandLink ) { look = ( ( CommandLink ) link ) . getLook ( ) ; } if ( look != null ) { sb . append ( "btn btn-" ) . append ( look ) ; if ( isResponsive ) { sb . append ( " btn-block" ) ; } } return sb . toString ( ) . trim ( ) ; }
|
Collects the CSS classes of the link .
|
38,260
|
public static boolean isValued ( Object obj ) { if ( obj == null ) return false ; if ( obj instanceof String ) return isStringValued ( ( String ) obj ) ; return true ; }
|
Check if a generic object is valued
|
38,261
|
public static String stringOrDefault ( String str , String defaultValue ) { if ( isStringValued ( str ) ) return str ; return defaultValue ; }
|
Get the string if is not null or empty otherwise return the default value
|
38,262
|
public static String snakeCaseToCamelCase ( String snakeCase ) { if ( snakeCase . contains ( "-" ) ) { StringBuilder camelCaseStr = new StringBuilder ( snakeCase . length ( ) ) ; boolean toUpperCase = false ; for ( char c : snakeCase . toCharArray ( ) ) { if ( c == '-' ) toUpperCase = true ; else { if ( toUpperCase ) { toUpperCase = false ; c = Character . toUpperCase ( c ) ; } camelCaseStr . append ( c ) ; } } snakeCase = camelCaseStr . toString ( ) ; } return snakeCase ; }
|
Transform a snake - case string to a camel - case one .
|
38,263
|
public static String camelCaseToSnakeCase ( String camelCase ) { if ( null == camelCase || camelCase . length ( ) == 0 ) return camelCase ; StringBuilder snakeCase = new StringBuilder ( camelCase . length ( ) + 3 ) ; snakeCase . append ( camelCase . charAt ( 0 ) ) ; boolean hasCamelCase = false ; for ( int i = 1 ; i < camelCase . length ( ) ; i ++ ) { char c = camelCase . charAt ( i ) ; if ( Character . isUpperCase ( c ) ) { snakeCase . append ( "-" ) ; c = Character . toLowerCase ( c ) ; hasCamelCase = true ; } snakeCase . append ( c ) ; } if ( ! hasCamelCase ) return camelCase ; return snakeCase . toString ( ) ; }
|
Transform a snake - case string to a camelCase one .
|
38,264
|
public static String escapeHtml ( String htmlString ) { StringBuffer sb = new StringBuffer ( htmlString . length ( ) ) ; boolean lastWasBlankChar = false ; int len = htmlString . length ( ) ; char c ; for ( int i = 0 ; i < len ; i ++ ) { c = htmlString . charAt ( i ) ; if ( c == ' ' ) { if ( lastWasBlankChar ) { lastWasBlankChar = false ; sb . append ( " " ) ; } else { lastWasBlankChar = true ; sb . append ( ' ' ) ; } } else { lastWasBlankChar = false ; if ( c == '"' ) sb . append ( """ ) ; else if ( c == '&' ) sb . append ( "&" ) ; else if ( c == '<' ) sb . append ( "<" ) ; else if ( c == '>' ) sb . append ( ">" ) ; else if ( c == '/' ) sb . append ( "-" ) ; else if ( c == '\\' ) sb . append ( "-" ) ; else if ( c == '\n' ) sb . append ( "<br/>" ) ; else { int ci = 0xffff & c ; if ( ci < 160 ) sb . append ( c ) ; else { sb . append ( "&#" ) ; sb . append ( String . valueOf ( ci ) ) ; sb . append ( ';' ) ; } } } } return sb . toString ( ) ; }
|
Escape html special chars from string
|
38,265
|
public static String escapeJQuerySpecialCharsInSelector ( String selector ) { String jQuerySpecialChars = "!\"#$%&'()*+,./:;<=>?@[]^`{|}~;" ; String [ ] jsc = jQuerySpecialChars . split ( "(?!^)" ) ; for ( String c : jsc ) { selector = selector . replace ( c , "\\\\" + c ) ; } return selector ; }
|
Escape special jQuery chars in selector query
|
38,266
|
public static UIForm getClosestForm ( UIComponent component ) { while ( component != null ) { if ( component instanceof UIForm ) { return ( UIForm ) component ; } component = component . getParent ( ) ; } return null ; }
|
Get the related form
|
38,267
|
public static String getComponentClientId ( final String componentId ) { FacesContext context = FacesContext . getCurrentInstance ( ) ; UIViewRoot root = context . getViewRoot ( ) ; UIComponent c = findComponent ( root , componentId ) ; if ( c == null ) { return null ; } return c . getClientId ( context ) ; }
|
Returns the clientId for a component with id = foo .
|
38,268
|
public static UIComponent findComponent ( UIComponent c , String id ) { if ( id . equals ( c . getId ( ) ) ) { return c ; } Iterator < UIComponent > kids = c . getFacetsAndChildren ( ) ; while ( kids . hasNext ( ) ) { UIComponent found = findComponent ( kids . next ( ) , id ) ; if ( found != null ) { return found ; } } return null ; }
|
Finds component with the given id
|
38,269
|
public static String getInitParam ( String param , FacesContext context ) { return context . getExternalContext ( ) . getInitParameter ( param ) ; }
|
Shortcut for getting context parameters using an already obtained FacesContext .
|
38,270
|
public static String resolveSearchExpressions ( String refItem ) { if ( refItem != null ) { if ( refItem . contains ( "@" ) || refItem . contains ( "*" ) ) { refItem = ExpressionResolver . getComponentIDs ( FacesContext . getCurrentInstance ( ) , FacesContext . getCurrentInstance ( ) . getViewRoot ( ) , refItem ) ; } } return refItem ; }
|
Resolve the search expression
|
38,271
|
public static boolean isLegacyFeedbackClassesEnabled ( ) { String legacyErrorClasses = getInitParam ( "net.bootsfaces.legacy_error_classes" ) ; legacyErrorClasses = evalELIfPossible ( legacyErrorClasses ) ; return legacyErrorClasses . equalsIgnoreCase ( "true" ) || legacyErrorClasses . equalsIgnoreCase ( "yes" ) ; }
|
It checks where the framework should place BS feedback classes .
|
38,272
|
private void encodeDefaultLanguageJS ( FacesContext fc ) throws IOException { ResponseWriter rw = fc . getResponseWriter ( ) ; rw . startElement ( "script" , null ) ; rw . write ( "$.datepicker.setDefaults($.datepicker.regional['" + fc . getViewRoot ( ) . getLocale ( ) . getLanguage ( ) + "']);" ) ; rw . endElement ( "script" ) ; }
|
Generates the default language for the date picker . Originally implemented in the HeadRenderer this code has been moved here to provide better compatibility to PrimeFaces . If multiple date pickers are on the page the script is generated redundantly but this shouldn t do no harm .
|
38,273
|
public static String convertFormat ( String format ) { if ( format == null ) return null ; else { format = format . replaceAll ( "EEE" , "D" ) ; format = format . replaceAll ( "yy" , "y" ) ; if ( format . indexOf ( "MMM" ) != - 1 ) { format = format . replaceAll ( "MMM" , "M" ) ; } else { format = format . replaceAll ( "M" , "m" ) ; } return format ; } }
|
Converts a java Date format to a jQuery date format
|
38,274
|
private static String encodeVisibility ( IResponsive r , String value , String prefix ) { if ( value == null ) return "" ; if ( "true" . equals ( value ) || "false" . equals ( value ) ) { throw new FacesException ( "The attributes 'visible' and 'hidden' don't accept boolean values. If you want to show or hide the element conditionally, use the attribute 'rendered' instead." ) ; } List < String > str = wonderfulTokenizer ( value , delimiters ) ; return evaluateExpression ( str , delimiters , validValues , prefix , r . getDisplay ( ) ) ; }
|
Encode the visible field
|
38,275
|
private static String getSize ( IResponsiveLabel r , Sizes size ) { String colSize = "-1" ; switch ( size ) { case xs : colSize = r . getLabelColXs ( ) ; if ( colSize . equals ( "-1" ) ) colSize = r . getLabelTinyScreen ( ) ; break ; case sm : colSize = r . getLabelColSm ( ) ; if ( colSize . equals ( "-1" ) ) colSize = r . getLabelSmallScreen ( ) ; break ; case md : colSize = r . getLabelColMd ( ) ; if ( colSize . equals ( "-1" ) ) colSize = r . getLabelMediumScreen ( ) ; break ; case lg : colSize = r . getLabelColLg ( ) ; if ( colSize . equals ( "-1" ) ) colSize = r . getLabelLargeScreen ( ) ; break ; } return colSize ; }
|
Decode col sizes between two way of definition
|
38,276
|
private static int sizeToInt ( String size ) { if ( size == null ) return - 1 ; if ( "full" . equals ( size ) ) return 12 ; if ( "full-size" . equals ( size ) ) return 12 ; if ( "fullSize" . equals ( size ) ) return 12 ; if ( "full-width" . equals ( size ) ) return 12 ; if ( "fullWidth" . equals ( size ) ) return 12 ; if ( "half" . equals ( size ) ) return 6 ; if ( "one-third" . equals ( size ) ) return 4 ; if ( "oneThird" . equals ( size ) ) return 4 ; if ( "two-thirds" . equals ( size ) ) return 8 ; if ( "twoThirds" . equals ( size ) ) return 8 ; if ( "one-fourth" . equals ( size ) ) return 3 ; if ( "oneFourth" . equals ( size ) ) return 3 ; if ( "three-fourths" . equals ( size ) ) return 9 ; if ( "threeFourths" . equals ( size ) ) return 9 ; if ( size . length ( ) > 2 ) { size = size . replace ( "columns" , "" ) ; size = size . replace ( "column" , "" ) ; size = size . trim ( ) ; } return new Integer ( size ) . intValue ( ) ; }
|
Convert the specified size to int value
|
38,277
|
private static List < String > getSizeRange ( String operation , String size ) { return getSizeRange ( operation , size , null ) ; }
|
Get the size ranges
|
38,278
|
public static List < String > wonderfulTokenizer ( String tokenString , String [ ] delimiters ) { List < String > tokens = new ArrayList < String > ( ) ; String currentToken = "" ; for ( int i = 0 ; i < tokenString . length ( ) ; i ++ ) { String _currItem = String . valueOf ( tokenString . charAt ( i ) ) ; if ( _currItem . trim ( ) . isEmpty ( ) ) continue ; String delimiterFound = "" ; for ( String d : delimiters ) { if ( d . startsWith ( _currItem ) ) { if ( d . length ( ) > 1 ) { if ( d . equals ( tokenString . substring ( i , i + d . length ( ) ) ) ) { delimiterFound = d ; i = i + ( d . length ( ) - 1 ) ; } } else delimiterFound = d ; } if ( ! delimiterFound . isEmpty ( ) ) break ; } if ( ! delimiterFound . isEmpty ( ) ) { if ( ! currentToken . isEmpty ( ) ) { tokens . add ( currentToken ) ; currentToken = "" ; } tokens . add ( delimiterFound ) ; } else currentToken += _currItem ; } if ( ! currentToken . isEmpty ( ) ) tokens . add ( currentToken ) ; return tokens ; }
|
Tokenize string based on rules
|
38,279
|
public static String getResponsiveLabelClass ( IResponsiveLabel r ) { if ( ! shouldRenderResponsiveClasses ( r ) ) { return "" ; } int colxs = sizeToInt ( getSize ( r , Sizes . xs ) ) ; int colsm = sizeToInt ( getSize ( r , Sizes . sm ) ) ; int colmd = sizeToInt ( getSize ( r , Sizes . md ) ) ; int collg = sizeToInt ( getSize ( r , Sizes . lg ) ) ; StringBuilder sb = new StringBuilder ( ) ; if ( colmd > 0 ) { sb . append ( "col-md-" ) ; sb . append ( colmd ) ; sb . append ( ' ' ) ; } if ( colxs > 0 ) { sb . append ( "col-xs-" ) ; sb . append ( colxs ) ; sb . append ( ' ' ) ; } if ( colsm > 0 ) { sb . append ( "col-sm-" ) ; sb . append ( colsm ) ; sb . append ( ' ' ) ; } if ( collg > 0 ) { sb . append ( "col-lg-" ) ; sb . append ( collg ) ; sb . append ( ' ' ) ; } if ( sb . length ( ) > 0 ) { return sb . substring ( 0 , sb . length ( ) - 1 ) ; } return null ; }
|
Create the responsive class combination
|
38,280
|
private static boolean shouldRenderResponsiveClasses ( Object r ) { if ( r instanceof UIComponent && r instanceof IResponsiveLabel ) { UIForm form = AJAXRenderer . getSurroundingForm ( ( UIComponent ) r , true ) ; if ( form instanceof Form ) { if ( ( ( Form ) form ) . isInline ( ) ) { return false ; } } } return true ; }
|
Temporal and ugly hack to prevent responsive classes to be applied to inputs inside inline forms .
|
38,281
|
public String getSeverityName ( Severity severity ) { if ( severity . equals ( FacesMessage . SEVERITY_INFO ) ) { return "info" ; } else if ( severity . equals ( FacesMessage . SEVERITY_WARN ) ) { return "warn" ; } else if ( severity . equals ( FacesMessage . SEVERITY_ERROR ) ) { return "error" ; } else if ( severity . equals ( FacesMessage . SEVERITY_FATAL ) ) { return "fatal" ; } throw new IllegalStateException ( ) ; }
|
Returns name of the given severity in lower case .
|
38,282
|
public static ValueExpression createValueExpression ( String p_expression ) { FacesContext context = FacesContext . getCurrentInstance ( ) ; ExpressionFactory expressionFactory = context . getApplication ( ) . getExpressionFactory ( ) ; ELContext elContext = context . getELContext ( ) ; ValueExpression vex = expressionFactory . createValueExpression ( elContext , p_expression , Object . class ) ; return vex ; }
|
Utility method to create a JSF Value expression from the p_expression string
|
38,283
|
public static ValueExpression createValueExpression ( String p_expression , Class < ? > expectedType ) { FacesContext context = FacesContext . getCurrentInstance ( ) ; ExpressionFactory expressionFactory = context . getApplication ( ) . getExpressionFactory ( ) ; ELContext elContext = context . getELContext ( ) ; if ( null == expectedType ) { LOGGER . severe ( "The expected type of " + p_expression + " is null. Defaulting to String." ) ; expectedType = String . class ; } ValueExpression vex = expressionFactory . createValueExpression ( elContext , p_expression , expectedType ) ; return vex ; }
|
Utility method to create a JSF Value expression from p_expression with exprectedType class as return
|
38,284
|
public static MethodExpression createMethodExpression ( String p_expression , Class < ? > returnType , Class < ? > ... parameterTypes ) { FacesContext context = FacesContext . getCurrentInstance ( ) ; ExpressionFactory expressionFactory = context . getApplication ( ) . getExpressionFactory ( ) ; ELContext elContext = context . getELContext ( ) ; MethodExpression mex = expressionFactory . createMethodExpression ( elContext , p_expression , returnType , parameterTypes ) ; return mex ; }
|
Utility method to create a JSF Method expression
|
38,285
|
public static NGBeanAttributeInfo getBeanAttributeInfos ( UIComponent c ) { String core = getCoreValueExpression ( c ) ; synchronized ( beanAttributeInfos ) { if ( beanAttributeInfos . containsKey ( c ) ) { return beanAttributeInfos . get ( c ) ; } } NGBeanAttributeInfo info = new NGBeanAttributeInfo ( c ) ; synchronized ( beanAttributeInfos ) { beanAttributeInfos . put ( core , info ) ; } return info ; }
|
Get the bean attributes info
|
38,286
|
public static String getCoreValueExpression ( UIComponent component ) { ValueExpression valueExpression = component . getValueExpression ( "value" ) ; if ( null != valueExpression ) { String v = valueExpression . getExpressionString ( ) ; if ( null != v ) { Matcher matcher = EL_EXPRESSION . matcher ( v ) ; if ( matcher . find ( ) ) { String exp = matcher . group ( ) ; return exp . substring ( 2 , exp . length ( ) - 1 ) ; } return v ; } } return null ; }
|
Return the core value expression of a specified component
|
38,287
|
public static Annotation [ ] readAnnotations ( UIComponent p_component ) { ValueExpression valueExpression = p_component . getValueExpression ( "value" ) ; if ( valueExpression != null && valueExpression . getExpressionString ( ) != null && valueExpression . getExpressionString ( ) . length ( ) > 0 ) { return readAnnotations ( valueExpression , p_component ) ; } return null ; }
|
Which annotations are given to an object displayed by a JSF component?
|
38,288
|
public void processEvent ( SystemEvent event ) throws AbortProcessingException { FacesContext context = FacesContext . getCurrentInstance ( ) ; UIViewRoot root = context . getViewRoot ( ) ; if ( ensureExistBootsfacesComponent ( root , context ) ) { addCSS ( root , context ) ; addJavascript ( root , context ) ; addMetaTags ( root , context ) ; } }
|
Trigger adding the resources if and only if the event has been fired by UIViewRoot .
|
38,289
|
private boolean ensureExistBootsfacesComponent ( UIViewRoot root , FacesContext context ) { Map < String , Object > viewMap = root . getViewMap ( ) ; if ( viewMap . get ( RESOURCE_KEY ) != null ) return true ; if ( viewMap . get ( THEME_RESOURCE_KEY ) != null ) return true ; if ( viewMap . get ( EXT_RESOURCE_KEY ) != null ) return true ; if ( findBsfComponent ( root , C . BSF_LIBRARY ) != null ) return true ; return false ; }
|
Check if there is almost one bootsfaces component in page . If yes load the correct items .
|
38,290
|
public static UIComponent findBsfComponent ( UIComponent parent , String targetLib ) { if ( targetLib . equalsIgnoreCase ( ( String ) parent . getAttributes ( ) . get ( "library" ) ) ) { return parent ; } Iterator < UIComponent > kids = parent . getFacetsAndChildren ( ) ; while ( kids . hasNext ( ) ) { UIComponent found = findBsfComponent ( kids . next ( ) , targetLib ) ; if ( found != null ) { return found ; } } return null ; }
|
Check all components in page to find one that has as resource library the target library . I use this method to check existence of a BsF component because at this level the getComponentResource returns always null
|
38,291
|
private void addMetaTags ( UIViewRoot root , FacesContext context ) { String viewportParam = BsfUtils . getInitParam ( C . P_VIEWPORT , context ) ; viewportParam = evalELIfPossible ( viewportParam ) ; String content = "width=device-width, initial-scale=1" ; if ( ! viewportParam . isEmpty ( ) && isFalseOrNo ( viewportParam ) ) return ; if ( ! viewportParam . isEmpty ( ) && ! isTrueOrYes ( viewportParam ) ) content = viewportParam ; String viewportMeta = "<meta name=\"viewport\" content=\"" + content + "\"/>" ; UIOutput viewport = new UIOutput ( ) ; viewport . setRendererType ( "javax.faces.Text" ) ; viewport . getAttributes ( ) . put ( "escape" , false ) ; viewport . setValue ( viewportMeta ) ; UIComponent header = findHeader ( root ) ; if ( header != null ) { header . getChildren ( ) . add ( 0 , viewport ) ; } }
|
Add the viewport meta tag if not disabled from context - param
|
38,292
|
private void addCSS ( UIViewRoot root , FacesContext context ) { String theme = loadTheme ( root , context ) ; UIComponent header = findHeader ( root ) ; boolean useCDNImportForFontAwesome = ( null == header ) || ( null == header . getFacet ( "no-fa" ) ) ; if ( useCDNImportForFontAwesome ) { String useCDN = BsfUtils . getInitParam ( P_GET_FONTAWESOME_FROM_CDN ) ; if ( null != useCDN ) { useCDN = ELTools . evalAsString ( useCDN ) ; } if ( null != useCDN ) { useCDNImportForFontAwesome = ! isFalseOrNo ( useCDN ) ; } } List < UIComponent > availableResources = root . getComponentResources ( context , "head" ) ; for ( UIComponent ava : availableResources ) { String name = ( String ) ava . getAttributes ( ) . get ( "name" ) ; if ( null != name ) { name = name . toLowerCase ( ) ; if ( ( name . contains ( "font-awesome" ) || name . contains ( "fontawesome" ) ) && name . endsWith ( "css" ) ) useCDNImportForFontAwesome = false ; } } if ( useCDNImportForFontAwesome ) { InternalFALink output = new InternalFALink ( ) ; Map < String , Object > viewMap = root . getViewMap ( ) ; if ( viewMap . containsKey ( FONTAWESOME_USED ) ) { String version = ( String ) viewMap . get ( FONTAWESOME_VERSION ) ; if ( version != null ) { output . setVersion ( version ) ; output . setNeedsVersion4 ( needsFontAwesome4 ( ) ) ; } else { output . setVersion ( "4" ) ; output . setNeedsVersion4 ( needsFontAwesome4 ( ) ) ; } addResourceIfNecessary ( root , context , output ) ; } } @ SuppressWarnings ( "unchecked" ) List < String > extCSSMap = ( List < String > ) root . getViewMap ( ) . get ( EXT_RESOURCE_KEY ) ; if ( extCSSMap != null ) { for ( String file : extCSSMap ) { String name = "css/" + file ; createAndAddComponent ( root , context , CSS_RENDERER , name , C . BSF_LIBRARY ) ; } } @ SuppressWarnings ( "unchecked" ) List < String > themedCSSMap = ( List < String > ) root . getViewMap ( ) . get ( THEME_RESOURCE_KEY ) ; if ( themedCSSMap != null ) { for ( String file : themedCSSMap ) { String name = "css/" + theme + "/" + file ; createAndAddComponent ( root , context , CSS_RENDERER , name , C . BSF_LIBRARY ) ; } } if ( theme . equals ( "patternfly" ) ) { createAndAddComponent ( root , context , CSS_RENDERER , "css/patternfly/bootstrap-switch.css" , C . BSF_LIBRARY ) ; } createAndAddComponent ( root , context , CSS_RENDERER , "css/bsf.css" , C . BSF_LIBRARY ) ; boolean loadBootstrap = shouldLibraryBeLoaded ( P_GET_BOOTSTRAP_FROM_CDN , true ) ; if ( ! loadBootstrap ) { removeBootstrapResources ( root , context ) ; } }
|
Add the required CSS files and the FontAwesome CDN link .
|
38,293
|
private void addJavascript ( UIViewRoot root , FacesContext context ) { boolean loadJQuery = shouldLibraryBeLoaded ( P_GET_JQUERY_FROM_CDN , true ) ; boolean loadJQueryUI = shouldLibraryBeLoaded ( P_GET_JQUERYUI_FROM_CDN , true ) ; List < UIComponent > availableResources = root . getComponentResources ( context , "head" ) ; for ( UIComponent ava : availableResources ) { String name = ( String ) ava . getAttributes ( ) . get ( "name" ) ; if ( null != name ) { name = name . toLowerCase ( ) ; if ( ( name . contains ( "/jquery-ui" ) || name . startsWith ( "jquery-ui" ) ) && name . endsWith ( ".js" ) ) loadJQueryUI = false ; else if ( ( name . contains ( "/jquery" ) || name . startsWith ( "jquery" ) ) && name . endsWith ( ".js" ) ) loadJQuery = false ; } } addMandatoryLibraries ( root , context , loadJQuery , loadJQueryUI ) ; String blockUI = BsfUtils . getInitParam ( P_BLOCK_UI , context ) ; if ( null != blockUI ) blockUI = ELTools . evalAsString ( blockUI ) ; if ( null != blockUI && isTrueOrYes ( blockUI ) ) { createAndAddComponent ( root , context , SCRIPT_RENDERER , "js/jquery.blockUI.js" , C . BSF_LIBRARY ) ; } removeDuplicateResources ( root , context ) ; addResourceIfNecessary ( root , context , new InternalIE8CompatiblityLinks ( ) ) ; enforceCorrectLoadOrder ( root , context ) ; }
|
Add the required Javascript files and the FontAwesome CDN link .
|
38,294
|
private void removeDuplicateResources ( UIViewRoot root , FacesContext context ) { List < UIComponent > resourcesToRemove = new ArrayList < UIComponent > ( ) ; Map < String , UIComponent > alreadyThere = new HashMap < String , UIComponent > ( ) ; List < UIComponent > components = new ArrayList < UIComponent > ( root . getComponentResources ( context , "head" ) ) ; Collections . sort ( components , new Comparator < UIComponent > ( ) { public int compare ( UIComponent o1 , UIComponent o2 ) { return o1 . getClientId ( ) . compareTo ( o2 . getClientId ( ) ) ; } } ) ; for ( UIComponent resource : components ) { String name = ( String ) resource . getAttributes ( ) . get ( "name" ) ; String library = ( String ) resource . getAttributes ( ) . get ( "library" ) ; String url = ( String ) resource . getAttributes ( ) . get ( "url" ) ; String key ; if ( null != url ) { key = url ; } else { key = library + "/" + name + "/" + resource . getClass ( ) . getName ( ) ; } if ( alreadyThere . containsKey ( key ) ) { resourcesToRemove . add ( resource ) ; continue ; } alreadyThere . put ( key , resource ) ; } for ( UIComponent c : resourcesToRemove ) { c . setInView ( false ) ; root . removeComponentResource ( context , c ) ; } }
|
Remove duplicate resource files . For some reason many resource files are added more than once especially when AJAX is used . The method removes the duplicate files .
|
38,295
|
private void enforceCorrectLoadOrder ( UIViewRoot root , FacesContext context ) { List < UIComponent > resources = new ArrayList < UIComponent > ( ) ; List < UIComponent > first = new ArrayList < UIComponent > ( ) ; List < UIComponent > middle = new ArrayList < UIComponent > ( ) ; List < UIComponent > last = new ArrayList < UIComponent > ( ) ; List < UIComponent > datatable = new ArrayList < UIComponent > ( ) ; for ( UIComponent resource : root . getComponentResources ( context , "head" ) ) { String name = ( String ) resource . getAttributes ( ) . get ( "name" ) ; String position = ( String ) resource . getAttributes ( ) . get ( "position" ) ; if ( "first" . equals ( position ) ) { first . add ( resource ) ; } else if ( "last" . equals ( position ) ) { last . add ( resource ) ; } else if ( "middle" . equals ( position ) ) { middle . add ( resource ) ; } else { if ( resource instanceof InternalJavaScriptResource ) { datatable . add ( resource ) ; } else if ( name != null && ( name . endsWith ( ".js" ) ) ) { if ( name . contains ( "dataTables" ) ) { datatable . add ( resource ) ; } else { resources . add ( resource ) ; } } } } Collections . sort ( resources , new ResourceFileComparator ( ) ) ; for ( UIComponent c : first ) { root . removeComponentResource ( context , c ) ; } for ( UIComponent c : resources ) { root . removeComponentResource ( context , c ) ; } for ( UIComponent c : last ) { root . removeComponentResource ( context , c ) ; } for ( UIComponent c : datatable ) { root . removeComponentResource ( context , c ) ; } for ( UIComponent c : root . getComponentResources ( context , "head" ) ) { middle . add ( c ) ; } for ( UIComponent c : middle ) { root . removeComponentResource ( context , c ) ; } for ( UIComponent c : first ) { root . addComponentResource ( context , c , "head" ) ; } for ( UIComponent c : middle ) { root . addComponentResource ( context , c , "head" ) ; } for ( UIComponent c : resources ) { root . addComponentResource ( context , c , "head" ) ; } for ( UIComponent c : last ) { root . addComponentResource ( context , c , "head" ) ; } for ( UIComponent c : datatable ) { root . addComponentResource ( context , c , "head" ) ; } }
|
Make sure jQuery is loaded before jQueryUI and that every other Javascript is loaded later . Also make sure that the BootsFaces resource files are loaded prior to other resource files giving the developer the opportunity to overwrite a CSS or JS file .
|
38,296
|
private UIComponent findHeader ( UIViewRoot root ) { for ( UIComponent c : root . getChildren ( ) ) { if ( c instanceof HtmlHead ) return c ; } for ( UIComponent c : root . getChildren ( ) ) { if ( c instanceof HtmlBody ) return null ; if ( c instanceof UIOutput ) if ( c . getFacets ( ) != null ) return c ; } return null ; }
|
Looks for the header in the JSF tree .
|
38,297
|
public static void addResourceToHeadButAfterJQuery ( String library , String resource ) { addResource ( resource , library , library + "#" + resource , RESOURCE_KEY ) ; }
|
Registers a JS file that needs to be included in the header of the HTML file but after jQuery and AngularJS .
|
38,298
|
public static void addBasicJSResource ( String library , String resource ) { addResource ( resource , library , resource , BASIC_JS_RESOURCE_KEY ) ; }
|
Registers a core JS file that needs to be included in the header of the HTML file but after jQuery and AngularJS .
|
38,299
|
public static void addThemedCSSResource ( String resource ) { Map < String , Object > viewMap = FacesContext . getCurrentInstance ( ) . getViewRoot ( ) . getViewMap ( ) ; @ SuppressWarnings ( "unchecked" ) List < String > resourceList = ( List < String > ) viewMap . get ( THEME_RESOURCE_KEY ) ; if ( null == resourceList ) { resourceList = new ArrayList < String > ( ) ; viewMap . put ( THEME_RESOURCE_KEY , resourceList ) ; } if ( ! resourceList . contains ( resource ) ) { resourceList . add ( resource ) ; } }
|
Registers a themed CSS file that needs to be included in the header of the HTML file .
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.