idx
int64
0
41.2k
question
stringlengths
73
5.81k
target
stringlengths
5
918
4,400
public static < T > void fire ( final HasSlideStopHandlers < T > source , final T value ) { if ( TYPE != null ) { SlideStopEvent < T > event = new SlideStopEvent < T > ( value ) ; source . fireEvent ( event ) ; } }
Fires a slide stop event on all registered handlers in the handler manager . If no such handlers exist this method will do nothing .
4,401
public static void fire ( final HasSummernoteImageUploadHandlers source , JsArray < ImageFile > images ) { if ( TYPE != null ) { SummernoteImageUploadEvent event = new SummernoteImageUploadEvent ( images ) ; source . fireEvent ( event ) ; } }
Fires a summernote image upload event on all registered handlers in the handler manager . If no such handlers exist this method will do nothing .
4,402
public static void fire ( final HasSummernoteKeyDownHandlers source , NativeEvent nativeEvent ) { if ( TYPE != null ) { SummernoteKeyDownEvent event = new SummernoteKeyDownEvent ( nativeEvent ) ; source . fireEvent ( event ) ; } }
Fires a summernote key down event on all registered handlers in the handler manager . If no such handlers exist this method will do nothing .
4,403
public static void fire ( final HasSummernoteInitHandlers source ) { if ( TYPE != null ) { SummernoteInitEvent event = new SummernoteInitEvent ( ) ; source . fireEvent ( event ) ; } }
Fires a summernote init event on all registered handlers in the handler manager . If no such handlers exist this method will do nothing .
4,404
public static void fire ( final HasSummernotePasteHandlers source ) { if ( TYPE != null ) { SummernotePasteEvent event = new SummernotePasteEvent ( ) ; source . fireEvent ( event ) ; } }
Fires a summernote paste event on all registered handlers in the handler manager . If no such handlers exist this method will do nothing .
4,405
public static void fire ( final HasShownHandlers source ) { if ( TYPE != null ) { ShownEvent event = new ShownEvent ( ) ; source . fireEvent ( event ) ; } }
Fires a shown event on all registered handlers in the handler manager . If no such handlers exist this method will do nothing .
4,406
public static void fire ( final HasRefreshedHandlers source ) { if ( TYPE != null ) { RefreshedEvent event = new RefreshedEvent ( ) ; source . fireEvent ( event ) ; } }
Fires a refreshed event on all registered handlers in the handler manager . If no such handlers exist this method will do nothing .
4,407
public final void setAnimation ( Animation enter , Animation exit ) { setAnimation ( ( enter != null ) ? enter . getCssName ( ) : Animation . NO_ANIMATION . getCssName ( ) , ( exit != null ) ? exit . getCssName ( ) : Animation . NO_ANIMATION . getCssName ( ) ) ; }
Set Animation to Notify when it enters and exit the screen .
4,408
public static < T > void fire ( final HasBeforeItemAddHandlers < T > source , T item ) { if ( TYPE != null ) { BeforeItemAddEvent < T > event = new BeforeItemAddEvent < T > ( item ) ; source . fireEvent ( event ) ; } }
Fires a tagsinput beforeItemAdd event on all registered handlers in the handler manager . If no such handlers exist this method will do nothing .
4,409
public static void fire ( final HasHideHandlers source ) { if ( TYPE != null ) { HideEvent event = new HideEvent ( ) ; source . fireEvent ( event ) ; } }
Fires a hide event on all registered handlers in the handler manager . If no such handlers exist this method will do nothing .
4,410
public String getValue ( ) { String value = attrMixin . getAttribute ( VALUE ) ; return value . isEmpty ( ) ? getText ( ) : value ; }
Returns the value of the option . If no value fall - back to the displayed option text .
4,411
public void setTokens ( final String tokens ) { if ( tokens != null ) attrMixin . setAttribute ( TOKENS , tokens ) ; else attrMixin . removeAttribute ( TOKENS ) ; }
Adds key words to improve the searchability .
4,412
public String getTokens ( ) { String tokens = attrMixin . getAttribute ( TOKENS ) ; return tokens . isEmpty ( ) ? null : tokens ; }
Returns the search key words .
4,413
public void setDivider ( final boolean divider ) { if ( divider ) attrMixin . setAttribute ( DIVIDER , Boolean . toString ( true ) ) ; else attrMixin . removeAttribute ( DIVIDER ) ; }
Turns the option into a divider .
4,414
public void setSubtext ( final String subtext ) { if ( subtext != null ) attrMixin . setAttribute ( SUBTEXT , subtext ) ; else attrMixin . removeAttribute ( SUBTEXT ) ; }
Set the specified sub - text to the option .
4,415
public String getSubtext ( ) { String subtext = attrMixin . getAttribute ( SUBTEXT ) ; return subtext . isEmpty ( ) ? null : subtext ; }
Returns the sub - text of the option .
4,416
public void setIcon ( final IconType iconType ) { if ( iconType != null ) attrMixin . setAttribute ( ICON , iconType . getCssName ( ) ) ; else attrMixin . removeAttribute ( ICON ) ; }
Add an icon to the option .
4,417
public void setContent ( final String content ) { if ( content != null ) attrMixin . setAttribute ( CONTENT , content ) ; else attrMixin . removeAttribute ( CONTENT ) ; }
Inserts custom HTML into the option .
4,418
public List < T > getItems ( ) { JsArray < JavaScriptObject > js_items = getItems ( getElement ( ) ) ; List < T > items = new ArrayList < T > ( ) ; for ( int i = 0 ; i < js_items . length ( ) ; i ++ ) { @ SuppressWarnings ( "unchecked" ) T item = ( T ) js_items . get ( i ) ; items . add ( item ) ; } return items ; }
Returns list of items contained in the
4,419
public void add ( List < T > tags ) { if ( tags != null ) for ( T tag : tags ) add ( tag ) ; }
Adds list of tags
4,420
public final void updateIcon ( final IconType type ) { if ( type != null ) updateIcon ( Styles . FONT_AWESOME_BASE + " " + type . getCssName ( ) ) ; }
Updates Icon parameter of once displayed Notify . This method is shortcut when using FONT AWESOME iconic font .
4,421
public static void fire ( final HasSlideEnabledHandlers source ) { if ( TYPE != null ) { SlideEnabledEvent event = new SlideEnabledEvent ( ) ; source . fireEvent ( event ) ; } }
Fires a slide enabled event on all registered handlers in the handler manager . If no such handlers exist this method will do nothing .
4,422
public static < T > void fire ( final HasSlideHandlers < T > source , T newValue ) { if ( TYPE != null ) { SlideEvent < T > event = new SlideEvent < T > ( newValue ) ; source . fireEvent ( event ) ; } }
Fires a slide event on all registered handlers in the handler manager . If no such handlers exist this method will do nothing .
4,423
public static void fire ( final HasSummernoteKeyUpHandlers source , NativeEvent nativeEvent ) { if ( TYPE != null ) { SummernoteKeyUpEvent event = new SummernoteKeyUpEvent ( nativeEvent ) ; source . fireEvent ( event ) ; } }
Fires a summernote key up event on all registered handlers in the handler manager . If no such handlers exist this method will do nothing .
4,424
public static void fire ( final HasSummernoteChangeHandlers source ) { if ( TYPE != null ) { SummernoteChangeEvent event = new SummernoteChangeEvent ( ) ; source . fireEvent ( event ) ; } }
Fires a summernote change event on all registered handlers in the handler manager . If no such handlers exist this method will do nothing .
4,425
public static void fire ( final HasSlideDisabledHandlers source ) { if ( TYPE != null ) { SlideDisabledEvent event = new SlideDisabledEvent ( ) ; source . fireEvent ( event ) ; } }
Fires a slide disabled event on all registered handlers in the handler manager . If no such handlers exist this method will do nothing .
4,426
public List < Option > getSelectedItems ( ) { final List < Option > items = new ArrayList < > ( 0 ) ; for ( Entry < OptionElement , Option > entry : itemMap . entrySet ( ) ) { Option opt = entry . getValue ( ) ; if ( opt . isSelected ( ) ) items . add ( opt ) ; } return items ; }
Returns the selected items list . If no item is selected this method returns an empty list .
4,427
public void setFontNames ( final SummernoteFontName ... fontNames ) { JsArrayString array = JavaScriptObject . createArray ( ) . cast ( ) ; for ( SummernoteFontName fontName : fontNames ) { array . push ( fontName . getName ( ) ) ; } options . setFontNames ( array ) ; }
Set customized font names .
4,428
public void setCode ( final String code ) { if ( isAttached ( ) ) { setCode ( getElement ( ) , code ) ; } else { getElement ( ) . setInnerHTML ( code ) ; } }
Sets the given HTML code to the editor .
4,429
public final void addButton ( String label , String className ) { addButton ( label , className , SimpleCallback . DEFAULT_SIMPLE_CALLBACK ) ; }
Adds a custom button with a class name .
4,430
public final void addButton ( String label , String className , SimpleCallback callback ) { addButton ( BUTTON_PREFIX + BUTTON_INDEX ++ , label , className , callback != null ? callback : SimpleCallback . DEFAULT_SIMPLE_CALLBACK ) ; }
Adds a custom button with a class name and a callback .
4,431
private static String toBootstrapDateFormat ( final String format ) { String bootstrap_format = format ; bootstrap_format = bootstrap_format . replace ( "EEEE" , "DD" ) ; bootstrap_format = bootstrap_format . replaceAll ( "E{1,3}" , "D" ) ; bootstrap_format = bootstrap_format . replaceAll ( "m" , "i" ) ; bootstrap_format = bootstrap_format . replaceAll ( "H" , "Q" ) ; bootstrap_format = bootstrap_format . replaceAll ( "h" , "H" ) ; bootstrap_format = bootstrap_format . replaceAll ( "Q" , "h" ) ; bootstrap_format = bootstrap_format . replaceAll ( "a" , "P" ) ; if ( bootstrap_format . contains ( "MMM" ) ) { bootstrap_format = bootstrap_format . replace ( "MMMM" , "MM" ) ; bootstrap_format = bootstrap_format . replace ( "MMM" , "M" ) ; } else { bootstrap_format = bootstrap_format . replace ( "MM" , "mm" ) ; bootstrap_format = bootstrap_format . replace ( "M" , "m" ) ; } if ( ! bootstrap_format . contains ( "yy" ) ) { bootstrap_format = bootstrap_format . replace ( "y" , "yyyy" ) ; } return bootstrap_format ; }
Convert GWT date time format to bootstrap date time format
4,432
public void setGWTFormat ( final String format ) { this . format = toBootstrapDateFormat ( format ) ; final Date oldValue = getValue ( ) ; this . dateTimeFormat = DateTimeFormat . getFormat ( format ) ; if ( oldValue != null ) { setValue ( oldValue ) ; } }
Sets format of the date using GWT notation
4,433
public Toolbar addGroup ( ToolbarButton ... buttons ) { groups . add ( SummernoteOptions . newToolbarGroup ( GROUP_PREFIX + GROUP_INDEX ++ , buttons ) ) ; return this ; }
Add a new toolbar group with the specified buttons .
4,434
public void setFormatter ( final FormatterCallback < T > formatterCallback ) { this . formatterCallback = formatterCallback ; if ( isAttached ( ) ) { setFormatter ( getElement ( ) ) ; refresh ( ) ; } }
Sets the formatter callback .
4,435
public static void fire ( final HasRenderedHandlers source ) { if ( TYPE != null ) { RenderedEvent event = new RenderedEvent ( ) ; source . fireEvent ( event ) ; } }
Fires a rendered event on all registered handlers in the handler manager . If no such handlers exist this method will do nothing .
4,436
public static void fire ( final HasSummernoteEnterHandlers source ) { if ( TYPE != null ) { SummernoteEnterEvent event = new SummernoteEnterEvent ( ) ; source . fireEvent ( event ) ; } }
Fires a summernote enter event on all registered handlers in the handler manager . If no such handlers exist this method will do nothing .
4,437
public JsArrayNumber toJsArray ( ) { JsArrayNumber array = JavaScriptObject . createArray ( ) . cast ( ) ; array . push ( minValue ) ; array . push ( maxValue ) ; return array ; }
Converts the range to a JavaScript number array .
4,438
public static < T > void fire ( final HasBeforeItemRemoveHandlers < T > source , T item ) { if ( TYPE != null ) { BeforeItemRemoveEvent < T > event = new BeforeItemRemoveEvent < T > ( item ) ; source . fireEvent ( event ) ; } }
Fires a tagsinput beforeItemRemove event on all registered handlers in the handler manager . If no such handlers exist this method will do nothing .
4,439
public static void fire ( final HasShowHandlers source ) { if ( TYPE != null ) { ShowEvent event = new ShowEvent ( ) ; source . fireEvent ( event ) ; } }
Fires a show event on all registered handlers in the handler manager . If no such handlers exist this method will do nothing .
4,440
public static < T > void fire ( final HasItemRemovedHandlers < T > source , T item ) { if ( TYPE != null ) { ItemRemovedEvent < T > event = new ItemRemovedEvent < T > ( item ) ; source . fireEvent ( event ) ; } }
Fires a tagsinput itemRemoved event on all registered handlers in the handler manager . If no such handlers exist this method will do nothing .
4,441
public static final < T extends UIObject > void removeAnimationOnEnd ( final T widget , final String animation ) { if ( widget != null && animation != null ) { removeAnimationOnEnd ( widget . getElement ( ) , animation ) ; } }
Removes custom animation class on animation end .
4,442
public static final < T extends UIObject > void stopAnimation ( final T widget , final String animation ) { if ( widget != null && animation != null ) { stopAnimation ( widget . getElement ( ) , animation ) ; } }
Removes custom animation class and stops animation .
4,443
private static String getStyleNameFromAnimation ( final String animation , int count , int duration , int delay ) { if ( count < 0 ) count = - 1 ; if ( duration < 0 ) duration = - 1 ; if ( delay < 0 ) delay = - 1 ; String styleName = "" ; if ( animation != null && ! animation . isEmpty ( ) && animation . split ( " " ) . length > 1 ) { styleName += animation . split ( " " ) [ 1 ] + "-" + count + "-" + duration + "-" + delay ; } else if ( animation != null && ! animation . isEmpty ( ) && animation . split ( " " ) . length == 1 ) { styleName += animation + "-" + count + "-" + duration + "-" + delay ; } return styleName ; }
Helper method which returns unique class name for combination of animation and it s settings .
4,444
public static void fire ( final HasHiddenHandlers source ) { if ( TYPE != null ) { HiddenEvent event = new HiddenEvent ( ) ; source . fireEvent ( event ) ; } }
Fires a hidden event on all registered handlers in the handler manager . If no such handlers exist this method will do nothing .
4,445
public void setContainer ( final String container ) { if ( container != null ) attrMixin . setAttribute ( CONTAINER , container ) ; else attrMixin . removeAttribute ( CONTAINER ) ; }
Sets a container to which the select will be appended .
4,446
public void setWidth ( final String cssWidth ) { if ( cssWidth != null ) attrMixin . setAttribute ( WIDTH , cssWidth ) ; else attrMixin . removeAttribute ( WIDTH ) ; }
Set the select width witch is forced inline to the given value .
4,447
public void setWindowPaddingTopRightBottomLeft ( final int top , final int right , final int bottom , final int left ) { JsArrayNumber array = JavaScriptObject . createArray ( 4 ) . cast ( ) ; array . push ( top ) ; array . push ( right ) ; array . push ( bottom ) ; array . push ( left ) ; attrMixin . setAttribute ( WINDOW_PADDING , JsonUtils . stringify ( array ) ) ; }
Sets the window padding to top right bottom and right sides . This is useful in cases where the window has areas that the drop - down menu should not cover - for instance a fixed header .
4,448
public List < Option > getItems ( ) { List < Option > selectedItems = new ArrayList < > ( 0 ) ; NodeList < OptionElement > items = selectElement . getOptions ( ) ; for ( int i = 0 ; i < items . getLength ( ) ; i ++ ) { OptionElement item = items . getItem ( i ) ; Option option = itemMap . get ( item ) ; if ( option != null ) selectedItems . add ( option ) ; } return selectedItems ; }
Returns the item list .
4,449
public static void setLocale ( final BootboxLocale locale ) { BootboxLocale l = ( locale != null ) ? locale : BootboxLocale . getDefault ( ) ; setLocale ( l . getLocale ( ) ) ; }
Sets a locale .
4,450
static final JsArrayMixed newToolbarGroup ( String name , ToolbarButton ... buttons ) { JsArrayString arr = JavaScriptObject . createArray ( ) . cast ( ) ; for ( ToolbarButton button : buttons ) { arr . push ( button . getId ( ) ) ; } return getToolbarGroup ( name , arr ) ; }
Creates a new toolbar group .
4,451
public static < T > void fire ( final HasItemAddedOnInitHandlers < T > source , T item ) { if ( TYPE != null ) { ItemAddedOnInitEvent < T > event = new ItemAddedOnInitEvent < T > ( item ) ; source . fireEvent ( event ) ; } }
Fires a tagsinput itemAddedOnInit event on all registered handlers in the handler manager . If no such handlers exist this method will do nothing .
4,452
public static void fire ( final HasLoadedHandlers source ) { if ( TYPE != null ) { LoadedEvent event = new LoadedEvent ( ) ; source . fireEvent ( event ) ; } }
Fires a loaded event on all registered handlers in the handler manager . If no such handlers exist this method will do nothing .
4,453
public static < T > void fire ( final HasItemAddedHandlers < T > source , T item ) { if ( TYPE != null ) { ItemAddedEvent < T > event = new ItemAddedEvent < T > ( item ) ; source . fireEvent ( event ) ; } }
Fires a tagsinput itemAdded event on all registered handlers in the handler manager . If no such handlers exist this method will do nothing .
4,454
public static < T > void fire ( final HasSlideStartHandlers < T > source , final T value ) { if ( TYPE != null ) { SlideStartEvent < T > event = new SlideStartEvent < T > ( value ) ; source . fireEvent ( event ) ; } }
Fires a slide start event on all registered handlers in the handler manager . If no such handlers exist this method will do nothing .
4,455
public void setLabel ( final String label ) { if ( label != null ) attrMixin . setAttribute ( LABEL , label ) ; else attrMixin . removeAttribute ( LABEL ) ; }
Set the label of the option group .
4,456
public static void fire ( final HasSummernoteFocusHandlers source ) { if ( TYPE != null ) { SummernoteFocusEvent event = new SummernoteFocusEvent ( ) ; source . fireEvent ( event ) ; } }
Fires a summernote focus event on all registered handlers in the handler manager . If no such handlers exist this method will do nothing .
4,457
public static void fire ( final HasSummernoteBlurHandlers source ) { if ( TYPE != null ) { SummernoteBlurEvent event = new SummernoteBlurEvent ( ) ; source . fireEvent ( event ) ; } }
Fires a summernote blur event on all registered handlers in the handler manager . If no such handlers exist this method will do nothing .
4,458
private static String toBootstrapDateFormat ( final String format ) { String bootstrap_format = format ; bootstrap_format = bootstrap_format . replace ( "EEEE" , "DD" ) ; bootstrap_format = bootstrap_format . replaceAll ( "E{1,3}" , "D" ) ; if ( bootstrap_format . contains ( "MMM" ) ) { bootstrap_format = bootstrap_format . replace ( "MMMM" , "MM" ) ; bootstrap_format = bootstrap_format . replace ( "MMM" , "M" ) ; } else { bootstrap_format = bootstrap_format . replace ( "MM" , "mm" ) ; bootstrap_format = bootstrap_format . replace ( "M" , "m" ) ; } if ( ! bootstrap_format . contains ( "yy" ) ) { bootstrap_format = bootstrap_format . replace ( "y" , "yyyy" ) ; } return bootstrap_format ; }
Convert GWT date format to bootstrap date format
4,459
public void localize ( final String [ ] longNames , final String [ ] shortNames ) { assert longNames != null && longNames . length == 12 ; assert shortNames != null && shortNames . length == 12 ; final JsArrayString longOnes = ( JsArrayString ) JsArrayString . createArray ( ) ; for ( final String name : longNames ) { longOnes . push ( name ) ; } final JsArrayString shortOnes = ( JsArrayString ) JsArrayString . createArray ( ) ; for ( final String name : shortNames ) { shortOnes . push ( name ) ; } localize ( longOnes , shortOnes ) ; }
To pass in localized names directly
4,460
public void execute ( ) throws HelloSignException { HttpURLConnection connection = getConnection ( ) ; try { lastHttpStatusCode = connection . getResponseCode ( ) ; if ( lastHttpStatusCode >= 200 && lastHttpStatusCode < 300 ) { logger . debug ( "OK!" ) ; lastResponseStream = connection . getInputStream ( ) ; } else { logger . error ( "Error! HTTP Code = " + lastHttpStatusCode ) ; lastResponseStream = connection . getErrorStream ( ) ; } } catch ( Exception ex ) { throw new HelloSignException ( ex ) ; } }
Executes this HTTP request and preserves the response stream and HTTP response code for processing .
4,461
public String getResponseBody ( ) { String responseStr = "" ; if ( lastResponseStream == null ) { logger . error ( "Unable to parse JSON from empty response!" ) ; } else { Scanner s = new Scanner ( lastResponseStream ) ; s . useDelimiter ( "\\A" ) ; responseStr = ( s . hasNext ( ) ) ? s . next ( ) : "" ; s . close ( ) ; } return responseStr ; }
Returns the last response stream as a string .
4,462
protected static HttpURLConnection getProxiedConnection ( String url ) throws MalformedURLException , IOException { HttpURLConnection conn = null ; Proxy proxy = null ; String proxyUrlStr = System . getProperty ( "hellosign.proxy.url" ) ; String proxyPortStr = System . getProperty ( "hellosign.proxy.port" ) ; Integer proxyPort = 80 ; if ( proxyPortStr != null ) { proxyPort = Integer . parseInt ( proxyPortStr ) ; } if ( proxyUrlStr != null ) { proxy = new Proxy ( Proxy . Type . HTTP , new InetSocketAddress ( proxyUrlStr , proxyPort ) ) ; } if ( proxy == null ) { conn = ( HttpURLConnection ) new URL ( url ) . openConnection ( ) ; } else { conn = ( HttpURLConnection ) new URL ( url ) . openConnection ( proxy ) ; } return conn ; }
Creates an HTTP connection .
4,463
public long getResponseAsFile ( File f ) throws HelloSignException { long bytesWritten = 0 ; try { bytesWritten = Files . copy ( lastResponseStream , f . toPath ( ) , StandardCopyOption . REPLACE_EXISTING ) ; } catch ( Exception e ) { throw new HelloSignException ( e ) ; } return bytesWritten ; }
Write the last response to a file .
4,464
protected HttpURLConnection getConnection ( ) throws HelloSignException { if ( fields != null ) { for ( String key : fields . keySet ( ) ) { if ( fields . get ( key ) instanceof File ) { return postWithFile ( ) ; } } } return postQuery ( ) ; }
Helper method to make an HTTP POST request . Intelligently detects whether Files have been attached and sends as an multipart form request .
4,465
private HttpURLConnection postQuery ( ) throws HelloSignException { logger . debug ( this . method + ": " + url ) ; HttpURLConnection connection ; try { connection = getProxiedConnection ( url ) ; if ( ! this . method . equals ( "POST" ) ) { connection . setRequestMethod ( method ) ; } } catch ( Exception e ) { throw new HelloSignException ( e ) ; } connection . setDoOutput ( true ) ; connection . setRequestProperty ( "user-agent" , USER_AGENT ) ; connection . setRequestProperty ( "accept-encoding" , DEFAULT_ENCODING ) ; auth . authenticate ( connection , url ) ; StringBuffer sb = new StringBuffer ( ) ; if ( fields != null ) { Iterator < String > keys = fields . keySet ( ) . iterator ( ) ; while ( keys . hasNext ( ) ) { String key = keys . next ( ) ; Serializable val = fields . get ( key ) ; if ( val == null ) { throw new HelloSignException ( "POST value for key '" + key + "' is null" ) ; } String value ; String encodedKey ; try { value = URLEncoder . encode ( val . toString ( ) , DEFAULT_ENCODING ) ; encodedKey = URLEncoder . encode ( key , DEFAULT_ENCODING ) ; } catch ( UnsupportedEncodingException e ) { throw new HelloSignException ( e ) ; } logger . debug ( "\t" + key + " = " + val . toString ( ) ) ; sb . append ( encodedKey + "=" + value ) ; if ( keys . hasNext ( ) ) { sb . append ( "&" ) ; } } } try { OutputStream output = connection . getOutputStream ( ) ; try { output . write ( sb . toString ( ) . getBytes ( DEFAULT_ENCODING ) ) ; } finally { try { output . close ( ) ; } catch ( IOException logOrIgnore ) { } } } catch ( Exception ex ) { ex . printStackTrace ( ) ; throw new HelloSignException ( ex . getMessage ( ) ) ; } return connection ; }
Helper method to make an HTTP POST request .
4,466
public List < TemplateRole > getSignerRoles ( ) { List < TemplateRole > masterList = getList ( TemplateRole . class , TEMPLATE_SIGNER_ROLES ) ; if ( masterList == null || masterList . size ( ) == 0 ) { return masterList ; } if ( masterList . get ( 0 ) . getOrder ( ) == null ) { return masterList ; } List < TemplateRole > sortedList = new ArrayList < TemplateRole > ( masterList . size ( ) ) ; for ( TemplateRole r : masterList ) { sortedList . add ( r . getOrder ( ) , r ) ; } return sortedList ; }
Returns a list of SignerRoles . If they are ordered the list is returned in order .
4,467
private void validate ( JSONObject json ) throws HelloSignException { if ( json . has ( "error" ) ) { try { JSONObject error = json . getJSONObject ( "error" ) ; String message = error . getString ( "error_msg" ) ; String type = error . getString ( "error_name" ) ; throw new HelloSignException ( message , getLastResponseCode ( ) , type ) ; } catch ( JSONException ex ) { throw new HelloSignException ( ex ) ; } } }
Inspects the JSONObject response for errors and throws an exception if found .
4,468
public JSONObject asJson ( ) throws HelloSignException { JSONObject json = null ; String response = getLastResponse ( ) ; logger . debug ( "Response body: " + response ) ; try { json = new JSONObject ( response ) ; validate ( json ) ; } catch ( HelloSignException e ) { throw e ; } catch ( JSONException e ) { throw new HelloSignException ( e ) ; } finally { reset ( ) ; } return json ; }
Executes the request and returns the response as a JSONObject .
4,469
public File asFile ( String fileName ) throws HelloSignException { Integer lastResponseCode = getLastResponseCode ( ) ; File f = null ; try { if ( lastResponseCode != null && lastResponseCode != HttpURLConnection . HTTP_OK ) { this . asJson ( ) ; } f = createTemporaryFile ( fileName ) ; if ( getLastResponseAsFile ( f ) == 0 ) { logger . warn ( "No bytes written to file: " + fileName ) ; } } catch ( HelloSignException ex ) { throw ex ; } finally { reset ( ) ; } return f ; }
Executes the request and returns the response as a File .
4,470
private File createTemporaryFile ( String filename ) throws HelloSignException { String prefix = filename . substring ( 0 , filename . indexOf ( "." ) ) ; String postfix = filename . substring ( filename . indexOf ( "." ) + 1 , filename . length ( ) ) ; if ( prefix == null || postfix == null ) { throw new HelloSignException ( "Invalid file name: " + prefix + "." + postfix ) ; } File f = null ; try { f = File . createTempFile ( prefix , "." + postfix ) ; } catch ( Exception ex ) { throw new HelloSignException ( ex ) ; } return f ; }
Helper method to create a temporary file .
4,471
public int asHttpCode ( ) throws HelloSignException { Integer code = getLastResponseCode ( ) ; if ( code == null ) { throw new HelloSignException ( "No request performed" ) ; } if ( code >= 200 && code < 300 ) { reset ( ) ; return code ; } throw new HelloSignException ( "HTTP Code " + code , code ) ; }
Executes the request and returns the HTTP response code .
4,472
public HttpClient get ( String url ) throws HelloSignException { if ( postFields != null ) { logger . warn ( "POST fields set for a GET request, they will be ignored" ) ; } request = new HttpGetRequest ( url , getParams , auth ) ; request . execute ( ) ; return this ; }
Initializes a GET request to the given URL .
4,473
public HttpClient post ( String url ) throws HelloSignException { if ( getParams != null ) { logger . warn ( "GET parameters set for a POST request, they will be ignored" ) ; } request = new HttpPostRequest ( url , postFields , auth ) ; request . execute ( ) ; return this ; }
Initializes a POST request to the given URL .
4,474
public HttpClient delete ( String url ) throws HelloSignException { request = new HttpDeleteRequest ( url , auth ) ; request . execute ( ) ; return this ; }
Initializes a DELETE request to the given URL .
4,475
public HttpClient put ( String url ) throws HelloSignException { request = new HttpPutRequest ( url , postFields , auth ) ; request . execute ( ) ; return this ; }
Makes a PUT request to the given URL
4,476
public HttpClient options ( String url ) throws HelloSignException { request = new HttpOptionsRequest ( url ) ; request . execute ( ) ; return this ; }
Makes an OPTIONS request to the given URL
4,477
private void disableStrictSSL ( ) { TrustManager [ ] trustAllCerts = new TrustManager [ ] { new X509TrustManager ( ) { public X509Certificate [ ] getAcceptedIssuers ( ) { return new X509Certificate [ 0 ] ; } public void checkClientTrusted ( X509Certificate [ ] certs , String authType ) { } public void checkServerTrusted ( X509Certificate [ ] certs , String authType ) { } } } ; HostnameVerifier hv = new HostnameVerifier ( ) { public boolean verify ( String hostname , SSLSession session ) { return true ; } } ; try { SSLContext sc = SSLContext . getInstance ( "SSL" ) ; sc . init ( null , trustAllCerts , new SecureRandom ( ) ) ; HttpsURLConnection . setDefaultSSLSocketFactory ( sc . getSocketFactory ( ) ) ; HttpsURLConnection . setDefaultHostnameVerifier ( hv ) ; } catch ( Exception e ) { } }
Helper method that allows this client to ignore SSL certificates when making API requests .
4,478
public void removeSigner ( String email ) throws HelloSignException { if ( email == null ) { throw new HelloSignException ( "Cannot remove null signer" ) ; } for ( int i = 0 ; i < signers . size ( ) ; i ++ ) { if ( email . equalsIgnoreCase ( signers . get ( i ) . getEmail ( ) ) ) { signers . remove ( i ) ; } } }
Removes the signer from the list . If that user does not exist this will throw a HelloSignException .
4,479
private void setColor ( String key , String color ) throws HelloSignException { if ( ! validateColor ( color ) ) { throw new HelloSignException ( "Invalid color: " + color ) ; } set ( key , color ) ; }
Helper method to validate and set a color .
4,480
public static String serializeMergeFields ( Map < String , FieldType > mergeFields ) throws HelloSignException { if ( mergeFields == null || mergeFields . isEmpty ( ) ) { return null ; } JSONArray mergeFieldArray = new JSONArray ( ) ; for ( String key : mergeFields . keySet ( ) ) { FieldType type = mergeFields . get ( key ) ; JSONObject mergeFieldObj = new JSONObject ( ) ; try { mergeFieldObj . put ( "name" , key ) ; mergeFieldObj . put ( "type" , type . toString ( ) ) ; } catch ( JSONException e ) { throw new HelloSignException ( e ) ; } mergeFieldArray . put ( mergeFieldObj ) ; } return mergeFieldArray . toString ( ) ; }
Helper method to convert a Java Map into the JSON string required by the HelloSign API .
4,481
public Map < String , Serializable > getPostFields ( ) throws HelloSignException { Map < String , Serializable > fields = super . getPostFields ( ) ; try { if ( hasTitle ( ) ) { fields . put ( REQUEST_TITLE , getTitle ( ) ) ; } if ( hasSubject ( ) ) { fields . put ( REQUEST_SUBJECT , getSubject ( ) ) ; } if ( hasMessage ( ) ) { fields . put ( REQUEST_MESSAGE , getMessage ( ) ) ; } List < String > signerRoles = getSignerRoles ( ) ; for ( int i = 0 ; i < signerRoles . size ( ) ; i ++ ) { String s = signerRoles . get ( i ) ; fields . put ( "signer_roles[" + i + "][name]" , s ) ; if ( getOrderMatters ( ) ) { fields . put ( "signer_roles[" + i + "][order]" , i ) ; } } List < String > ccRoles = getCCRoles ( ) ; for ( int i = 0 ; i < ccRoles . size ( ) ; i ++ ) { String cc = ccRoles . get ( i ) ; fields . put ( "cc_roles[" + i + "]" , cc ) ; } List < Document > docs = getDocuments ( ) ; for ( int i = 0 ; i < docs . size ( ) ; i ++ ) { Document d = docs . get ( i ) ; fields . put ( "file[" + i + "]" , d . getFile ( ) ) ; } List < String > fileUrls = getFileUrls ( ) ; for ( int i = 0 ; i < fileUrls . size ( ) ; i ++ ) { fields . put ( "file_url[" + i + "]" , fileUrls . get ( i ) ) ; } String mergeFieldStr = TemplateDraft . serializeMergeFields ( getMergeFields ( ) ) ; if ( mergeFieldStr != null ) { fields . put ( "merge_fields" , mergeFieldStr ) ; } if ( hasUsePreexistingFields ( ) ) { fields . put ( REQUEST_USE_PREEXISTING_FIELDS , true ) ; } if ( isTestMode ( ) ) { fields . put ( REQUEST_TEST_MODE , true ) ; } } catch ( Exception ex ) { throw new HelloSignException ( "Could not extract form fields from TemplateDraft." , ex ) ; } return fields ; }
Internal method used to retrieve the necessary POST fields .
4,482
public String getAccountId ( ) throws HelloSignException { JSONObject metadata = ( JSONObject ) get ( EVENT_METADATA ) ; String id = null ; try { id = metadata . getString ( REPORTED_FOR_ACCOUNT_ID ) ; } catch ( JSONException ex ) { throw new HelloSignException ( ex ) ; } return id ; }
Returns the account ID that this event is reporting for .
4,483
public String getAppId ( ) throws HelloSignException { JSONObject metadata = ( JSONObject ) get ( EVENT_METADATA ) ; String id = null ; try { id = metadata . getString ( REPORTED_FOR_APP_ID ) ; } catch ( JSONException ex ) { throw new HelloSignException ( ex ) ; } return id ; }
Returns the API app ID for which this event is reported .
4,484
public String getEventMessage ( ) throws HelloSignException { JSONObject metadata = ( JSONObject ) get ( EVENT_METADATA ) ; String eventMessage = null ; try { eventMessage = metadata . getString ( EVENT_MESSAGE ) ; } catch ( JSONException ex ) { throw new HelloSignException ( ex ) ; } return eventMessage ; }
Returns the message if any from the event
4,485
public String getRelatedSignatureId ( ) throws HelloSignException { JSONObject metadata = ( JSONObject ) get ( EVENT_METADATA ) ; if ( metadata == null ) { return null ; } String id = null ; try { id = metadata . getString ( RELATED_SIGNATURE_ID ) ; } catch ( JSONException ex ) { } return id ; }
Returns the signature ID to which this event is associated .
4,486
public boolean hasRelatedSignatureId ( ) { JSONObject metadata = ( JSONObject ) get ( EVENT_METADATA ) ; if ( metadata == null ) { return false ; } return metadata . has ( RELATED_SIGNATURE_ID ) && ! metadata . isNull ( RELATED_SIGNATURE_ID ) ; }
Utility method to determine if this event has a related signature ID .
4,487
public Signature getRelatedSignature ( ) throws HelloSignException { String id = getRelatedSignatureId ( ) ; if ( id == null ) { return null ; } for ( Signature sig : ( ( SignatureRequest ) resource ) . getSignatures ( ) ) { if ( id . equals ( sig . getId ( ) ) ) { return sig ; } } return null ; }
Returns the associated Signature object with this event if the event is associated with a Signature Request .
4,488
public EventType getType ( ) { String typeStr = getTypeString ( ) ; EventType type = null ; try { type = EventType . valueOf ( typeStr ) ; } catch ( Exception ex ) { logger . warn ( "Unexpected type: " + typeStr ) ; } return type ; }
Returns the EventType for this event .
4,489
public boolean isValid ( String apiKey ) throws HelloSignException { if ( apiKey == null || apiKey == "" ) { return false ; } try { Mac sha256HMAC = Mac . getInstance ( HASH_ALGORITHM ) ; SecretKeySpec secretKey = new SecretKeySpec ( apiKey . getBytes ( ) , HASH_ALGORITHM ) ; sha256HMAC . init ( secretKey ) ; String data = String . valueOf ( getLong ( EVENT_TIME ) ) + getType ( ) ; String computedHash = bytesToHex ( sha256HMAC . doFinal ( data . getBytes ( ) ) ) ; String providedHash = getString ( EVENT_HASH ) ; return computedHash . equalsIgnoreCase ( providedHash ) ; } catch ( InvalidKeyException e ) { throw new HelloSignException ( "Invalid API Key (" + e . getMessage ( ) + "): " + apiKey ) ; } catch ( IllegalArgumentException e ) { throw new HelloSignException ( "Invalid API Key (" + e . getMessage ( ) + "): " + apiKey ) ; } catch ( NoSuchAlgorithmException e ) { throw new HelloSignException ( "Unable to process API key" , e ) ; } }
Returns true if the event hash matches the computed hash using the provided API key .
4,490
public Integer getEstimatedTextLines ( ) { if ( ! dataObj . has ( CUSTOM_FIELD_AVG_TEXT_LENGTH ) ) { return null ; } Integer numLines = null ; try { JSONObject obj = dataObj . getJSONObject ( CUSTOM_FIELD_AVG_TEXT_LENGTH ) ; numLines = obj . getInt ( CUSTOM_FIELD_NUM_LINES ) ; } catch ( JSONException e ) { } return numLines ; }
Once processed with a position height and width HelloSign will estimate the number of lines a custom field can contain along with the number of characters per line . This method will return the estimated average number of lines of text this field can hold .
4,491
public Integer getEstimatedCharsPerLine ( ) { if ( ! dataObj . has ( CUSTOM_FIELD_AVG_TEXT_LENGTH ) ) { return null ; } Integer numLines = null ; try { JSONObject obj = dataObj . getJSONObject ( CUSTOM_FIELD_AVG_TEXT_LENGTH ) ; numLines = obj . getInt ( CUSTOM_FIELD_NUM_CHARS_PER_LINE ) ; } catch ( JSONException e ) { } return numLines ; }
Once processed with a position height and width HelloSign will estimate the number of lines a custom field can contain along with the number of characters per line . This method will return the estimated average number of characters per line this field can hold .
4,492
public void addFile ( File file , Integer order ) throws HelloSignException { Document doc = new Document ( ) ; doc . setFile ( file ) ; if ( order == null ) { addDocument ( doc ) ; } else { addDocument ( doc , order ) ; } }
Adds the file to the request in the given order .
4,493
public void addDocument ( Document doc ) throws HelloSignException { if ( doc == null ) { throw new HelloSignException ( "Document cannot be null" ) ; } documents . add ( doc ) ; }
Adds a Document to the signature request .
4,494
public void addDocument ( Document doc , int order ) throws HelloSignException { if ( doc == null ) { throw new HelloSignException ( "Document cannot be null" ) ; } try { documents . add ( order , doc ) ; } catch ( Exception ex ) { throw new HelloSignException ( ex ) ; } }
Adds a Document to the signature request at the specific order .
4,495
public void setClientId ( String clientId ) throws HelloSignException { if ( clientId == null ) { throw new HelloSignException ( "Client ID cannot be null" ) ; } this . clientId = clientId . trim ( ) ; }
Associates this request with an API app .
4,496
public List < E > filterCurrentPageBy ( String columnName , Serializable filterValue ) throws HelloSignException { ParameterizedType genericSuperclass = ( ParameterizedType ) getClass ( ) . getGenericSuperclass ( ) ; @ SuppressWarnings ( "unchecked" ) Class < E > clazz = ( Class < E > ) genericSuperclass . getActualTypeArguments ( ) [ 0 ] ; return getList ( clazz , listKey , filterValue , columnName ) ; }
Filters the current page of results by the given column and value .
4,497
public Account getAccount ( ) throws HelloSignException { return new Account ( httpClient . withAuth ( auth ) . get ( BASE_URI + ACCOUNT_URI ) . asJson ( ) ) ; }
Returns the current user s account information .
4,498
public boolean isAccountValid ( String email ) throws HelloSignException { if ( email == null || email . isEmpty ( ) ) { return false ; } Account account = new Account ( httpClient . withAuth ( auth ) . withPostField ( Account . ACCOUNT_EMAIL_ADDRESS , email ) . post ( BASE_URI + VALIDATE_ACCOUNT_URI ) . asJson ( ) ) ; return ( account . hasEmail ( ) && email . equalsIgnoreCase ( account . getEmail ( ) ) ) ; }
Returns true if an account exists with the provided email address . Note this is limited to the visibility of the currently authenticated user .
4,499
public Account setCallback ( String callback ) throws HelloSignException { return new Account ( httpClient . withAuth ( auth ) . withPostField ( Account . ACCOUNT_CALLBACK_URL , callback ) . post ( BASE_URI + ACCOUNT_URI ) . asJson ( ) ) ; }
Update your account callback URL .