idx
int64
0
41.2k
question
stringlengths
83
4.15k
target
stringlengths
5
715
11,300
protected void configureDatabaseIdent ( String dbident ) { _dbident = dbident ; try { executeUpdate ( new Operation < Object > ( ) { public Object invoke ( Connection conn , DatabaseLiaison liaison ) throws SQLException , PersistenceException { migrateSchema ( conn , liaison ) ; return null ; } } ) ; } catch ( PersistenceException pe ) { log . warning ( "Failure migrating schema" , "dbident" , _dbident , pe ) ; } }
This is called automatically if a dbident is provided at construct time but a derived class can pass null to its constructor and then call this method itself later if it wishes to obtain its database identifier from an overridable method which could not otherwise be called at construct time .
11,301
protected < V > V execute ( Operation < V > op ) throws PersistenceException { return execute ( op , true , true ) ; }
Executes the supplied read - only operation . In the event of a transient failure the repository will attempt to reestablish the database connection and try the operation again .
11,302
protected < V > V executeUpdate ( Operation < V > op ) throws PersistenceException { return execute ( op , true , false ) ; }
Executes the supplied read - write operation . In the event of a transient failure the repository will attempt to reestablish the database connection and try the operation again .
11,303
protected int update ( final String query ) throws PersistenceException { return executeUpdate ( new Operation < Integer > ( ) { public Integer invoke ( Connection conn , DatabaseLiaison liaison ) throws SQLException , PersistenceException { Statement stmt = null ; try { stmt = conn . createStatement ( ) ; return stmt . executeUpdate ( query ) ; } finally { JDBCUtil . close ( stmt ) ; } } } ) ; }
Executes the supplied update query in this repository returning the number of rows modified .
11,304
protected void checkedUpdate ( final String query , final int count ) throws PersistenceException { executeUpdate ( new Operation < Object > ( ) { public Object invoke ( Connection conn , DatabaseLiaison liaison ) throws SQLException , PersistenceException { Statement stmt = null ; try { stmt = conn . createStatement ( ) ; JDBCUtil . checkedUpdate ( stmt , query , 1 ) ; } finally { JDBCUtil . close ( stmt ) ; } return null ; } } ) ; }
Executes the supplied update query in this repository throwing an exception if the modification count is not equal to the specified count .
11,305
protected void maintenance ( final String action , final String table ) throws PersistenceException { executeUpdate ( new Operation < Object > ( ) { public Object invoke ( Connection conn , DatabaseLiaison liaison ) throws SQLException , PersistenceException { Statement stmt = null ; try { stmt = conn . createStatement ( ) ; ResultSet rs = stmt . executeQuery ( action + " table " + table ) ; while ( rs . next ( ) ) { String result = rs . getString ( "Msg_text" ) ; if ( result == null || ( result . indexOf ( "up to date" ) == - 1 && ! result . equals ( "OK" ) ) ) { log . info ( "Table maintenance [" + SimpleRepository . toString ( rs ) + "]." ) ; } } } finally { JDBCUtil . close ( stmt ) ; } return null ; } } ) ; }
Instructs MySQL to perform table maintenance on the specified table .
11,306
public static String loadAndGet ( File propFile , String key ) { try { return load ( propFile ) . getProperty ( key ) ; } catch ( IOException ioe ) { return null ; } }
Loads up the supplied properties file and returns the specified key . Clearly this is an expensive operation and you should load a properties file separately if you plan to retrieve multiple keys from it . This method however is convenient for say extracting a value from a properties file that contains only one key like a build timestamp properties file for example .
11,307
public boolean add ( int [ ] values ) { boolean modified = false ; int vlength = values . length ; for ( int i = 0 ; i < vlength ; i ++ ) { modified = ( add ( values [ i ] ) || modified ) ; } return modified ; }
Add all of the values in the supplied array to the set .
11,308
public boolean remove ( int [ ] values ) { boolean modified = false ; int vcount = values . length ; for ( int i = 0 ; i < vcount ; i ++ ) { modified = ( remove ( values [ i ] ) || modified ) ; } return modified ; }
Removes all values in the supplied array from the set . Any values that are in the array but not in the set are simply ignored .
11,309
public void setSelectedIndex ( int selidx ) { updateSelection ( selidx ) ; Object item = ( selidx == - 1 ) ? null : _model . getElementAt ( selidx ) ; _model . setSelectedItem ( item ) ; }
Sets the index of the selected component . A value of - 1 will clear the selection .
11,310
protected void fireActionPerformed ( ) { Object [ ] listeners = listenerList . getListenerList ( ) ; for ( int i = listeners . length - 2 ; i >= 0 ; i -= 2 ) { if ( listeners [ i ] == ActionListener . class ) { if ( _actionEvent == null ) { _actionEvent = new ActionEvent ( this , ActionEvent . ACTION_PERFORMED , _actionCommand ) ; } ( ( ActionListener ) listeners [ i + 1 ] ) . actionPerformed ( _actionEvent ) ; } } }
Notifies our listeners when the selection changed .
11,311
protected void addButtons ( int start , int count ) { Object selobj = _model . getSelectedItem ( ) ; for ( int i = start ; i < count ; i ++ ) { Object elem = _model . getElementAt ( i ) ; if ( selobj == elem ) { _selectedIndex = i ; } JLabel ibut = null ; if ( elem instanceof Image ) { ibut = new JLabel ( new ImageIcon ( ( Image ) elem ) ) ; } else { ibut = new JLabel ( elem . toString ( ) ) ; } ibut . putClientProperty ( "element" , elem ) ; ibut . addMouseListener ( this ) ; ibut . setBorder ( ( _selectedIndex == i ) ? SELECTED_BORDER : DESELECTED_BORDER ) ; add ( ibut , i ) ; } SwingUtil . refresh ( this ) ; }
Adds buttons for the specified range of model elements .
11,312
protected void removeButtons ( int start , int count ) { while ( count -- > 0 ) { remove ( start ) ; } if ( _selectedIndex >= start ) { if ( start + count > _selectedIndex ) { _selectedIndex = - 1 ; } else { _selectedIndex -= count ; } } }
Removes the buttons in the specified interval .
11,313
protected void updateSelection ( int selidx ) { if ( selidx == _selectedIndex ) { return ; } if ( _selectedIndex != - 1 ) { JLabel but = ( JLabel ) getComponent ( _selectedIndex ) ; but . setBorder ( DESELECTED_BORDER ) ; } _selectedIndex = selidx ; if ( _selectedIndex != - 1 ) { JLabel but = ( JLabel ) getComponent ( _selectedIndex ) ; but . setBorder ( SELECTED_BORDER ) ; } fireActionPerformed ( ) ; repaint ( ) ; }
Sets the selection to the specified index and updates the buttons to reflect the change . This does not update the model .
11,314
protected void layout ( Graphics2D gfx , int iconPadding , int extraPadding ) { int sqwid , sqhei ; if ( _icon == null ) { sqwid = sqhei = 0 ; } else { sqwid = _icon . getIconWidth ( ) ; sqhei = _icon . getIconHeight ( ) ; _label . setTargetHeight ( sqhei ) ; } _label . layout ( gfx ) ; Dimension lsize = _label . getSize ( ) ; if ( _icon == null ) { sqhei = lsize . height + extraPadding * 2 ; sqwid = extraPadding * 2 ; } int hhei = sqhei / 2 ; int hwid = sqwid / 2 ; _dia = ( int ) ( Math . sqrt ( hwid * hwid + hhei * hhei ) * 2 ) ; _xoff = ( _dia - sqwid ) / 2 ; _yoff = ( _dia - sqhei ) / 2 ; _lxoff = _dia - _xoff ; _lyoff = ( _dia - lsize . height ) / 2 ; _size . height = _dia ; _size . width = _dia + lsize . width + _xoff ; if ( _icon != null ) { _size . width += _xoff + ( iconPadding * 2 ) ; _xoff += iconPadding ; _lxoff += iconPadding * 2 ; } }
Lays out the label sausage . It is assumed that the desired label font is already set in the label .
11,315
protected void paint ( Graphics2D gfx , int x , int y , Color background , Object cliData ) { Object oalias = SwingUtil . activateAntiAliasing ( gfx ) ; gfx . setColor ( background ) ; drawBase ( gfx , x , y ) ; drawIcon ( gfx , x , y , cliData ) ; drawLabel ( gfx , x , y ) ; drawBorder ( gfx , x , y ) ; drawExtras ( gfx , x , y , cliData ) ; SwingUtil . restoreAntiAliasing ( gfx , oalias ) ; }
Paints the label sausage .
11,316
protected void drawBase ( Graphics2D gfx , int x , int y ) { gfx . fillRoundRect ( x , y , _size . width - 1 , _size . height - 1 , _dia , _dia ) ; }
Draws the base sausage within which all the other decorations are added .
11,317
protected void drawIcon ( Graphics2D gfx , int x , int y , Object cliData ) { if ( _icon != null ) { _icon . paintIcon ( null , gfx , x + _xoff , y + _yoff ) ; } }
Draws the icon if applicable .
11,318
protected void drawLabel ( Graphics2D gfx , int x , int y ) { _label . render ( gfx , x + _lxoff , y + _lyoff ) ; }
Draws the label .
11,319
protected void drawBorder ( Graphics2D gfx , int x , int y ) { gfx . setColor ( Color . black ) ; gfx . drawRoundRect ( x , y , _size . width - 1 , _size . height - 1 , _dia , _dia ) ; }
Draws the black outer border .
11,320
public static String getFullColumnClassName ( String className ) { if ( className . startsWith ( "java." ) ) { return className ; } if ( "String" . equals ( className ) ) { return "java.lang.String" ; } else if ( "Int" . equals ( className ) ) { return "java.lang.Integer" ; } else if ( "Double" . equals ( className ) ) { return "java.lang.Double" ; } else if ( "Date" . equals ( className ) ) { return "java.util.Date" ; } else if ( "Long" . equals ( className ) ) { return "java.lang.Long" ; } else if ( "Float" . equals ( className ) ) { return "java.lang.Float" ; } else if ( "Boolean" . equals ( className ) ) { return "java.lang.Boolean" ; } else { return "java.lang.Object" ; } }
CsvJdbc driver className is not a full java class name
11,321
public static void centerWindow ( Window window ) { Rectangle bounds ; try { bounds = GraphicsEnvironment . getLocalGraphicsEnvironment ( ) . getDefaultScreenDevice ( ) . getDefaultConfiguration ( ) . getBounds ( ) ; } catch ( Throwable t ) { Toolkit tk = window . getToolkit ( ) ; Dimension ss = tk . getScreenSize ( ) ; bounds = new Rectangle ( ss ) ; } int width = window . getWidth ( ) , height = window . getHeight ( ) ; window . setBounds ( bounds . x + ( bounds . width - width ) / 2 , bounds . y + ( bounds . height - height ) / 2 , width , height ) ; }
Center the given window within the screen boundaries .
11,322
public static void drawStringCentered ( Graphics g , String str , int x , int y , int width , int height ) { FontMetrics fm = g . getFontMetrics ( g . getFont ( ) ) ; int xpos = x + ( ( width - fm . stringWidth ( str ) ) / 2 ) ; int ypos = y + ( ( height + fm . getAscent ( ) ) / 2 ) ; g . drawString ( str , xpos , ypos ) ; }
Draw a string centered within a rectangle . The string is drawn using the graphics context s current font and color .
11,323
public static Point fitRectInRect ( Rectangle rect , Rectangle bounds ) { return new Point ( Math . min ( bounds . x + bounds . width - rect . width , Math . max ( rect . x , bounds . x ) ) , Math . min ( bounds . y + bounds . height - rect . height , Math . max ( rect . y , bounds . y ) ) ) ; }
Returns the most reasonable position for the specified rectangle to be placed at so as to maximize its containment by the specified bounding rectangle while still placing it as near its original coordinates as possible .
11,324
public static boolean positionRect ( Rectangle r , Rectangle bounds , Collection < ? extends Shape > avoidShapes ) { Point origPos = r . getLocation ( ) ; Comparator < Point > comp = createPointComparator ( origPos ) ; SortableArrayList < Point > possibles = new SortableArrayList < Point > ( ) ; possibles . add ( fitRectInRect ( r , bounds ) ) ; Area dead = new Area ( ) ; CHECKPOSSIBLES : while ( ! possibles . isEmpty ( ) ) { r . setLocation ( possibles . remove ( 0 ) ) ; if ( ( ! bounds . contains ( r ) ) || dead . intersects ( r ) ) { continue ; } for ( Iterator < ? extends Shape > iter = avoidShapes . iterator ( ) ; iter . hasNext ( ) ; ) { Shape shape = iter . next ( ) ; if ( shape . intersects ( r ) ) { iter . remove ( ) ; dead . add ( new Area ( shape ) ) ; Rectangle pusher = shape . getBounds ( ) ; possibles . add ( new Point ( pusher . x - r . width , r . y ) ) ; possibles . add ( new Point ( r . x , pusher . y - r . height ) ) ; possibles . add ( new Point ( pusher . x + pusher . width , r . y ) ) ; possibles . add ( new Point ( r . x , pusher . y + pusher . height ) ) ; possibles . sort ( comp ) ; continue CHECKPOSSIBLES ; } } return true ; } r . setLocation ( origPos ) ; return false ; }
Position the specified rectangle as closely as possible to its current position but make sure it is within the specified bounds and that it does not overlap any of the Shapes contained in the avoid list .
11,325
public static < P extends Point2D > Comparator < P > createPointComparator ( final P origin ) { return new Comparator < P > ( ) { public int compare ( P p1 , P p2 ) { double dist1 = origin . distance ( p1 ) ; double dist2 = origin . distance ( p2 ) ; return ( dist1 > dist2 ) ? 1 : ( ( dist1 < dist2 ) ? - 1 : 0 ) ; } } ; }
Create a comparator that compares against the distance from the specified point .
11,326
public static void applyToHierarchy ( Component comp , ComponentOp op ) { applyToHierarchy ( comp , Integer . MAX_VALUE , op ) ; }
Apply the specified ComponentOp to the supplied component and then all its descendants .
11,327
public static void applyToHierarchy ( Component comp , int depth , ComponentOp op ) { if ( comp == null ) { return ; } op . apply ( comp ) ; if ( comp instanceof Container && -- depth >= 0 ) { Container c = ( Container ) comp ; int ccount = c . getComponentCount ( ) ; for ( int ii = 0 ; ii < ccount ; ii ++ ) { applyToHierarchy ( c . getComponent ( ii ) , depth , op ) ; } } }
Apply the specified ComponentOp to the supplied component and then all its descendants up to the specified maximum depth .
11,328
public static Object activateAntiAliasing ( Graphics2D gfx ) { RenderingHints ohints = gfx . getRenderingHints ( ) , nhints = new RenderingHints ( null ) ; nhints . add ( ohints ) ; nhints . put ( RenderingHints . KEY_ANTIALIASING , RenderingHints . VALUE_ANTIALIAS_ON ) ; nhints . put ( RenderingHints . KEY_TEXT_ANTIALIASING , RenderingHints . VALUE_TEXT_ANTIALIAS_ON ) ; gfx . setRenderingHints ( nhints ) ; return ohints ; }
Activates anti - aliasing in the supplied graphics context on both text and 2D drawing primitives .
11,329
public static void restoreAntiAliasing ( Graphics2D gfx , Object rock ) { if ( rock != null ) { gfx . setRenderingHints ( ( RenderingHints ) rock ) ; } }
Restores anti - aliasing in the supplied graphics context to its original setting .
11,330
public static void sizeToContents ( JTable table ) { TableModel model = table . getModel ( ) ; TableColumn column = null ; Component comp = null ; int ccount = table . getColumnModel ( ) . getColumnCount ( ) , rcount = model . getRowCount ( ) , cellHeight = 0 ; for ( int cc = 0 ; cc < ccount ; cc ++ ) { int headerWidth = 0 , cellWidth = 0 ; column = table . getColumnModel ( ) . getColumn ( cc ) ; try { comp = column . getHeaderRenderer ( ) . getTableCellRendererComponent ( null , column . getHeaderValue ( ) , false , false , 0 , 0 ) ; headerWidth = comp . getPreferredSize ( ) . width ; } catch ( NullPointerException e ) { } for ( int rr = 0 ; rr < rcount ; rr ++ ) { Object cellValue = model . getValueAt ( rr , cc ) ; comp = table . getDefaultRenderer ( model . getColumnClass ( cc ) ) . getTableCellRendererComponent ( table , cellValue , false , false , 0 , cc ) ; Dimension psize = comp . getPreferredSize ( ) ; cellWidth = Math . max ( psize . width , cellWidth ) ; cellHeight = Math . max ( psize . height , cellHeight ) ; } column . setPreferredWidth ( Math . max ( headerWidth , cellWidth ) ) ; } if ( cellHeight > 0 ) { table . setRowHeight ( cellHeight ) ; } }
Adjusts the widths and heights of the cells of the supplied table to fit their contents .
11,331
public static Cursor createImageCursor ( Image img , Point hotspot ) { Toolkit tk = Toolkit . getDefaultToolkit ( ) ; int w = img . getWidth ( null ) ; int h = img . getHeight ( null ) ; Dimension d = tk . getBestCursorSize ( w , h ) ; if ( ( ( w < d . width ) && ( h <= d . height ) ) || ( ( w <= d . width ) && ( h < d . height ) ) ) { Image padder = GraphicsEnvironment . getLocalGraphicsEnvironment ( ) . getDefaultScreenDevice ( ) . getDefaultConfiguration ( ) . createCompatibleImage ( d . width , d . height , Transparency . BITMASK ) ; Graphics g = padder . getGraphics ( ) ; g . drawImage ( img , 0 , 0 , null ) ; g . dispose ( ) ; img = padder ; d . width = w ; d . height = h ; } if ( hotspot == null ) { hotspot = new Point ( d . width / 2 , d . height / 2 ) ; } else { hotspot . x = Math . min ( d . width - 1 , Math . max ( 0 , hotspot . x ) ) ; hotspot . y = Math . min ( d . height - 1 , Math . max ( 0 , hotspot . y ) ) ; } return tk . createCustomCursor ( img , hotspot , "samskivertDnDCursor" ) ; }
Create a custom cursor out of the specified image with the specified hotspot .
11,332
public static void addDebugBorders ( JPanel panel ) { Color bcolor = new Color ( _rando . nextInt ( 256 ) , _rando . nextInt ( 256 ) , _rando . nextInt ( 256 ) ) ; panel . setBorder ( BorderFactory . createLineBorder ( bcolor ) ) ; for ( int ii = 0 ; ii < panel . getComponentCount ( ) ; ii ++ ) { Object child = panel . getComponent ( ii ) ; if ( child instanceof JPanel ) { addDebugBorders ( ( JPanel ) child ) ; } } }
Adds a one pixel border of random color to this and all panels contained in this panel s child hierarchy .
11,333
public static void setFrameIcons ( Frame frame , List < ? extends Image > icons ) { try { Method m = frame . getClass ( ) . getMethod ( "setIconImages" , List . class ) ; m . invoke ( frame , icons ) ; return ; } catch ( SecurityException e ) { } catch ( NoSuchMethodException e ) { } catch ( Exception e ) { log . warning ( "Error setting frame icons" , "frame" , frame , "icons" , icons , "e" , e ) ; } frame . setIconImage ( icons . get ( 0 ) ) ; }
Sets the frame s icons . Unfortunately the ability to pass multiple icons so the OS can choose the most size - appropriate one was added in 1 . 6 ; before that you can only set one icon .
11,334
public static JComponent createAdjustEditor ( ) { VGroupLayout layout = new VGroupLayout ( VGroupLayout . NONE , VGroupLayout . STRETCH , 3 , VGroupLayout . TOP ) ; layout . setOffAxisJustification ( VGroupLayout . LEFT ) ; JTabbedPane editor = new EditorPane ( ) ; Font font = editor . getFont ( ) ; Font smaller = font . deriveFont ( font . getSize ( ) - 1f ) ; String library = null ; JPanel lpanel = null ; String pkgname = null ; CollapsiblePanel pkgpanel = null ; int acount = _adjusts . size ( ) ; for ( int ii = 0 ; ii < acount ; ii ++ ) { Adjust adjust = _adjusts . get ( ii ) ; if ( ! adjust . getLibrary ( ) . equals ( library ) ) { library = adjust . getLibrary ( ) ; pkgname = null ; lpanel = new JPanel ( layout ) ; lpanel . setBorder ( BorderFactory . createEmptyBorder ( 3 , 3 , 3 , 3 ) ) ; editor . addTab ( library , lpanel ) ; } if ( ! adjust . getPackage ( ) . equals ( pkgname ) ) { pkgname = adjust . getPackage ( ) ; pkgpanel = new CollapsiblePanel ( ) ; JCheckBox pkgcheck = new JCheckBox ( pkgname ) ; pkgcheck . setSelected ( true ) ; pkgpanel . setTrigger ( pkgcheck , null , null ) ; pkgpanel . setTriggerContainer ( pkgcheck ) ; pkgpanel . getContent ( ) . setLayout ( layout ) ; pkgpanel . setCollapsed ( false ) ; lpanel . add ( pkgpanel ) ; } pkgpanel . getContent ( ) . add ( new JSeparator ( ) ) ; JPanel aeditor = adjust . getEditor ( ) ; aeditor . setFont ( smaller ) ; pkgpanel . getContent ( ) . add ( aeditor ) ; } return editor ; }
Creates a Swing user interface that can be used to adjust all registered runtime adjustments .
11,335
public Object get ( Object array , int index ) { return ( array == null ) ? null : Array . get ( array , index ) ; }
Returns the object in the array at index . Wrapped as an object if it is a primitive .
11,336
public static String httpPost ( final URL url , final String submission , int timeout , final Map < String , String > requestProps ) throws IOException , ServiceWaiter . TimeoutException { final ServiceWaiter < String > waiter = new ServiceWaiter < String > ( ( timeout < 0 ) ? ServiceWaiter . NO_TIMEOUT : timeout ) ; Thread tt = new Thread ( ) { public void run ( ) { try { HttpURLConnection conn = ( HttpURLConnection ) url . openConnection ( ) ; conn . setDoInput ( true ) ; conn . setDoOutput ( true ) ; conn . setUseCaches ( false ) ; for ( Map . Entry < String , String > entry : requestProps . entrySet ( ) ) { conn . setRequestProperty ( entry . getKey ( ) , entry . getValue ( ) ) ; } DataOutputStream out = new DataOutputStream ( conn . getOutputStream ( ) ) ; out . writeBytes ( submission ) ; out . flush ( ) ; out . close ( ) ; BufferedReader reader = new BufferedReader ( new InputStreamReader ( conn . getInputStream ( ) ) ) ; StringBuilder buf = new StringBuilder ( ) ; for ( String s ; null != ( s = reader . readLine ( ) ) ; ) { buf . append ( s ) ; } reader . close ( ) ; waiter . postSuccess ( buf . toString ( ) ) ; } catch ( IOException e ) { waiter . postFailure ( e ) ; } } } ; tt . start ( ) ; if ( waiter . waitForResponse ( ) ) { return waiter . getArgument ( ) ; } else { throw ( IOException ) waiter . getError ( ) ; } }
Return the results of a form post . Note that the http request takes place on another thread but this thread blocks until the results are returned or it times out .
11,337
protected String [ ] inferCaller ( ) { String self = getClass ( ) . getName ( ) ; StackTraceElement [ ] stack = ( new Throwable ( ) ) . getStackTrace ( ) ; int ii = 0 ; for ( ; ii < stack . length ; ii ++ ) { if ( self . equals ( stack [ ii ] . getClassName ( ) ) ) { break ; } } System . err . println ( "Found self at " + ii ) ; for ( ; ii < stack . length ; ii ++ ) { String cname = stack [ ii ] . getClassName ( ) ; if ( ! cname . equals ( self ) ) { System . err . println ( "Found non-self at " + ii + " " + cname ) ; return new String [ ] { cname , stack [ ii ] . getMethodName ( ) } ; } } System . err . println ( "Failed to find non-self." ) ; return new String [ ] { null , null } ; }
Infers the caller of a Logger method from the current stack trace . This can be used by wrappers to provide the correct calling class and method information to their underlying log implementation .
11,338
public boolean isSourceModified ( Resource resource ) { SiteKey skey = new SiteKey ( resource . getName ( ) ) ; if ( skey . siteId == SiteIdentifier . DEFAULT_SITE_ID ) { return false ; } else { try { return ( resource . getLastModified ( ) < _loader . getLastModified ( skey . siteId ) ) ; } catch ( IOException ioe ) { Log . log . warning ( "Failure obtaining last modified time of site-specific jar file" , "siteId" , skey . siteId , "error" , ioe ) ; return false ; } } }
Things won t ever be modified when loaded from the servlet context because they came from the webapp . war file and if that is reloaded everything will be thrown away and started afresh .
11,339
public Series setType ( SeriesType type ) { if ( type != null ) { this . type = type . name ( ) . toLowerCase ( ) ; } else { this . type = null ; } return this ; }
The type of series
11,340
private void populateDependentParameters ( Report nextReport , QueryParameter parameter ) { Map < String , QueryParameter > childParams = ParameterUtil . getChildDependentParameters ( nextReport , parameter ) ; for ( QueryParameter childParam : childParams . values ( ) ) { if ( ! parameters . contains ( childParam ) ) { continue ; } int index = parameters . indexOf ( childParam ) ; JComponent childComponent = getParameterComponent ( index ) ; List < IdName > values = new ArrayList < IdName > ( ) ; Map < String , QueryParameter > allParentParams = ParameterUtil . getParentDependentParameters ( nextReport , childParam ) ; if ( ( childParam . getSource ( ) != null ) && ( childParam . getSource ( ) . trim ( ) . length ( ) > 0 ) ) { try { Map < String , Serializable > allParameterValues = new HashMap < String , Serializable > ( ) ; for ( String name : allParentParams . keySet ( ) ) { QueryParameter parent = allParentParams . get ( name ) ; index = parameters . indexOf ( parent ) ; JComponent parentComponent = getParameterComponent ( index ) ; allParameterValues . put ( name , ( Serializable ) getParameterValue ( parentComponent , parent ) ) ; } values = ParameterUtil . getParameterValues ( connection , childParam , ParameterUtil . toMap ( parameters ) , allParameterValues ) ; setValues ( childComponent , values ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } } } }
and set their values too
11,341
public static boolean equalsText ( String s1 , String s2 ) { if ( s1 == null ) { if ( s2 != null ) { return false ; } } else { if ( s2 == null ) { return false ; } } if ( ( s1 != null ) && ( s2 != null ) ) { s1 = s1 . replaceAll ( "\\s" , "" ) . toLowerCase ( ) ; s2 = s2 . replaceAll ( "\\s" , "" ) . toLowerCase ( ) ; if ( ! s1 . equals ( s2 ) ) { return false ; } } return true ; }
functional compare for two strings as ignore - case text
11,342
private static boolean isImage ( String hexString ) { boolean isImage = false ; if ( hexString . startsWith ( "89504e470d0a1a0a" ) ) { isImage = true ; } else if ( hexString . startsWith ( "474946383761" ) || hexString . startsWith ( "474946383961" ) ) { isImage = true ; } else if ( hexString . startsWith ( "ffd8ffe0" ) ) { isImage = true ; } return isImage ; }
JPEGs start with FF D8 FF E0 xx xx 4A 46 49 46 00
11,343
public void layout ( Graphics2D gfx , Font font ) { _label . setFont ( font ) ; layout ( gfx , BORDER_THICKNESS ) ; openBounds . width = _size . width ; openBounds . height = _size . height ; closedBounds . height = closedBounds . width = _size . height ; }
Computes the dimensions of this label based on the specified font and in the specified graphics context .
11,344
protected void drawBase ( Graphics2D gfx , int x , int y ) { if ( _active ) { super . drawBase ( gfx , x , y ) ; } else { gfx . fillOval ( x , y , closedBounds . width - 1 , closedBounds . height - 1 ) ; } }
Draw the base circle or sausage within which all the other decorations are added .
11,345
protected void paint ( Graphics2D gfx , int x , int y , RadialMenu menu ) { paint ( gfx , x , y , UIManager . getColor ( "RadialLabelSausage.background" ) , menu ) ; }
Paints the radial label sausage .
11,346
public static int nextPowerOfTwo ( int value ) { return ( int ) Math . pow ( 2 , Math . ceil ( Math . log ( value ) / Math . log ( 2 ) ) ) ; }
Rounds the specified value up to the next nearest power of two .
11,347
public static Object [ ] add ( Object [ ] list , int startIdx , Object element ) { requireNotNull ( element ) ; if ( list == null ) { list = new Object [ DEFAULT_LIST_SIZE ] ; } int llength = list . length ; int index = llength ; for ( int i = startIdx ; i < llength ; i ++ ) { if ( list [ i ] == null ) { index = i ; break ; } } if ( index >= llength ) { list = accomodate ( list , index ) ; } list [ index ] = element ; return list ; }
Adds the specified element to the next empty slot in the specified list . Begins searching for empty slots at the specified index . This can be used to quickly add elements to a list that preserves consecutivity by calling it with the size of the list as the first index to check .
11,348
public static Object [ ] insert ( Object [ ] list , int index , Object element ) { requireNotNull ( element ) ; if ( list == null ) { list = new Object [ DEFAULT_LIST_SIZE ] ; } int size = list . length ; if ( list [ size - 1 ] != null ) { list = accomodate ( list , size ) ; } else { size -- ; } System . arraycopy ( list , index , list , index + 1 , size - index ) ; list [ index ] = element ; return list ; }
Inserts the supplied element at the specified position in the array shifting the remaining elements down . The array will be expanded if necessary .
11,349
public static int indexOfNull ( Object [ ] list ) { if ( list != null ) { for ( int ii = 0 , nn = list . length ; ii < nn ; ii ++ ) { if ( list [ ii ] == null ) { return ii ; } } } return - 1 ; }
Returns the lowest index in the array that contains null or - 1 if there is no room to add elements without expanding the array .
11,350
public static Object remove ( Object [ ] list , int index ) { if ( list == null ) { return null ; } int llength = list . length ; if ( llength <= index || index < 0 ) { return null ; } Object elem = list [ index ] ; System . arraycopy ( list , index + 1 , list , index , llength - ( index + 1 ) ) ; list [ llength - 1 ] = null ; return elem ; }
Removes the element at the specified index . The elements after the removed element will be slid down the array one spot to fill the place of the removed element . If a null array is supplied or one that is not large enough to accomodate this index null is returned .
11,351
public static int size ( Object [ ] list ) { if ( list == null ) { return 0 ; } int llength = list . length ; for ( int ii = 0 ; ii < llength ; ii ++ ) { if ( list [ ii ] == null ) { return ii ; } } return llength ; }
Returns the number of elements prior to the first null in the supplied list .
11,352
public static int getSize ( Object [ ] list ) { int size = 0 ; for ( int ii = 0 , nn = ( list == null ) ? 0 : list . length ; ii < nn ; ii ++ ) { if ( list [ ii ] != null ) { size ++ ; } } return size ; }
Returns the number of non - null elements in the supplied list .
11,353
public static void main ( String [ ] args ) { Object [ ] list = null ; String foo = "foo" ; String bar = "bar" ; list = ListUtil . add ( list , foo ) ; System . out . println ( "add(foo): " + StringUtil . toString ( list ) ) ; list = ListUtil . add ( list , bar ) ; System . out . println ( "add(bar): " + StringUtil . toString ( list ) ) ; ListUtil . clearRef ( list , foo ) ; System . out . println ( "clear(foo): " + StringUtil . toString ( list ) ) ; String newBar = new String ( "bar" ) ; System . out . println ( "containsRef(newBar): " + ListUtil . containsRef ( list , newBar ) ) ; System . out . println ( "contains(newBar): " + ListUtil . contains ( list , newBar ) ) ; ListUtil . clear ( list , newBar ) ; System . out . println ( "clear(newBar): " + StringUtil . toString ( list ) ) ; list = ListUtil . add ( list , 0 , foo ) ; list = ListUtil . add ( list , 1 , bar ) ; System . out . println ( "Added foo+bar: " + StringUtil . toString ( list ) ) ; ListUtil . removeRef ( list , foo ) ; System . out . println ( "removeRef(foo): " + StringUtil . toString ( list ) ) ; list = ListUtil . add ( list , 0 , foo ) ; list = ListUtil . add ( list , 1 , bar ) ; System . out . println ( "Added foo+bar: " + StringUtil . toString ( list ) ) ; ListUtil . remove ( list , 0 ) ; System . out . println ( "remove(0): " + StringUtil . toString ( list ) ) ; ListUtil . remove ( list , 0 ) ; System . out . println ( "remove(0): " + StringUtil . toString ( list ) ) ; Object [ ] tl = ListUtil . testAndAddRef ( list , bar ) ; if ( tl == null ) { System . out . println ( "testAndAddRef(bar): failed: " + StringUtil . toString ( list ) ) ; } else { list = tl ; System . out . println ( "testAndAddRef(bar): added: " + StringUtil . toString ( list ) ) ; } String biz = "biz" ; tl = ListUtil . testAndAddRef ( list , biz ) ; if ( tl == null ) { System . out . println ( "testAndAddRef(biz): failed: " + StringUtil . toString ( list ) ) ; } else { list = tl ; System . out . println ( "testAndAddRef(biz): added: " + StringUtil . toString ( list ) ) ; } }
Run some tests .
11,354
public int getOrElse ( int key , int defval ) { Record rec = locateRecord ( key ) ; return ( rec == null ) ? defval : rec . value ; }
Returns the value mapped to the specified key or the supplied default value if there is no mapping .
11,355
public int removeOrElse ( int key , int defval ) { _modCount ++ ; int removed = removeImpl ( key , defval ) ; checkShrink ( ) ; return removed ; }
Removes the value mapped for the specified key .
11,356
public void clear ( ) { _modCount ++ ; for ( int i = 0 ; i < _buckets . length ; i ++ ) { _buckets [ i ] = null ; } _size = 0 ; }
Clears all mappings .
11,357
public void ensureCapacity ( int minCapacity ) { int size = _buckets . length ; while ( minCapacity > ( int ) ( size * _loadFactor ) ) { size *= 2 ; } if ( size != _buckets . length ) { resizeBuckets ( size ) ; } }
Ensure that the hash can comfortably hold the specified number of elements . Calling this method is not necessary but can improve performance if done prior to adding many elements .
11,358
protected Record locateRecord ( int key ) { int index = Math . abs ( key ) % _buckets . length ; for ( Record rec = _buckets [ index ] ; rec != null ; rec = rec . next ) { if ( rec . key == key ) { return rec ; } } return null ; }
Internal method to locate the record for the specified key .
11,359
protected int removeImpl ( int key , int defval ) { int index = Math . abs ( key ) % _buckets . length ; Record prev = null ; for ( Record rec = _buckets [ index ] ; rec != null ; rec = rec . next ) { if ( rec . key == key ) { if ( prev == null ) { _buckets [ index ] = rec . next ; } else { prev . next = rec . next ; } _size -- ; return rec . value ; } prev = rec ; } return defval ; }
Internal method for removing a mapping .
11,360
protected void checkShrink ( ) { if ( ( _buckets . length > DEFAULT_BUCKETS ) && ( _size < ( int ) ( _buckets . length * _loadFactor * .125 ) ) ) { resizeBuckets ( Math . max ( DEFAULT_BUCKETS , _buckets . length >> 1 ) ) ; } }
Check to see if we want to shrink the table .
11,361
public Set < IntIntEntry > entrySet ( ) { return new AbstractSet < IntIntEntry > ( ) { public int size ( ) { return _size ; } public Iterator < IntIntEntry > iterator ( ) { return new IntEntryIterator ( ) ; } } ; }
Get a set of all the entries in this map .
11,362
public void addComponent ( BaseComponent comp ) { if ( comp instanceof InitComponent ) { if ( _initers == null ) { throw new IllegalStateException ( "Too late to register InitComponent." ) ; } _initers . add ( ( InitComponent ) comp ) ; } if ( comp instanceof ShutdownComponent ) { if ( _downers == null ) { throw new IllegalStateException ( "Too late to register ShutdownComponent." ) ; } _downers . add ( ( ShutdownComponent ) comp ) ; } }
Registers a component with the lifecycle . This should be done during dependency resolution by injecting the Lifecycle into your constructor and calling this method there .
11,363
public void removeComponent ( BaseComponent comp ) { if ( _initers != null && comp instanceof InitComponent ) { _initers . remove ( ( InitComponent ) comp ) ; } if ( _downers != null && comp instanceof ShutdownComponent ) { _downers . remove ( ( ShutdownComponent ) comp ) ; } }
Removes a component from the lifecycle . This is generally not used .
11,364
public void addInitConstraint ( InitComponent lhs , Constraint constraint , InitComponent rhs ) { if ( lhs == null || rhs == null ) { throw new IllegalArgumentException ( "Cannot add constraint about null component." ) ; } InitComponent before = ( constraint == Constraint . RUNS_BEFORE ) ? lhs : rhs ; InitComponent after = ( constraint == Constraint . RUNS_BEFORE ) ? rhs : lhs ; _initers . addDependency ( after , before ) ; }
Adds a constraint that a certain component must be initialized before another .
11,365
public void addShutdownConstraint ( ShutdownComponent lhs , Constraint constraint , ShutdownComponent rhs ) { if ( lhs == null || rhs == null ) { throw new IllegalArgumentException ( "Cannot add constraint about null component." ) ; } ShutdownComponent before = ( constraint == Constraint . RUNS_BEFORE ) ? lhs : rhs ; ShutdownComponent after = ( constraint == Constraint . RUNS_BEFORE ) ? rhs : lhs ; _downers . addDependency ( after , before ) ; }
Adds a constraint that a certain component must be shutdown before another .
11,366
public void init ( ) { if ( _initers == null ) { log . warning ( "Refusing repeat init() request." ) ; return ; } ObserverList < InitComponent > list = _initers . toObserverList ( ) ; _initers = null ; list . apply ( new ObserverList . ObserverOp < InitComponent > ( ) { public boolean apply ( InitComponent comp ) { log . debug ( "Initializing component" , "comp" , comp ) ; comp . init ( ) ; return true ; } } ) ; }
Initializes all components immediately on the caller s thread .
11,367
public void shutdown ( ) { if ( _downers == null ) { log . warning ( "Refusing repeat shutdown() request." ) ; return ; } ObserverList < ShutdownComponent > list = _downers . toObserverList ( ) ; _downers = null ; list . apply ( new ObserverList . ObserverOp < ShutdownComponent > ( ) { public boolean apply ( ShutdownComponent comp ) { log . debug ( "Shutting down component" , "comp" , comp ) ; comp . shutdown ( ) ; return true ; } } ) ; }
Shuts down all components immediately on the caller s thread .
11,368
protected Record < V > getImpl ( int key ) { for ( Record < V > rec = _buckets [ keyToIndex ( key ) ] ; rec != null ; rec = rec . next ) { if ( rec . key == key ) { return rec ; } } return null ; }
Locate the record with the specified key .
11,369
protected Record < V > removeImpl ( int key , boolean checkShrink ) { int index = keyToIndex ( key ) ; for ( Record < V > prev = null , rec = _buckets [ index ] ; rec != null ; rec = rec . next ) { if ( rec . key == key ) { if ( prev == null ) { _buckets [ index ] = rec . next ; } else { prev . next = rec . next ; } _size -- ; if ( checkShrink ) { checkShrink ( ) ; } return rec ; } prev = rec ; } return null ; }
Remove an element with optional checking to see if we should shrink . When this is called from our iterator checkShrink == false to avoid booching the buckets .
11,370
protected final int keyToIndex ( int key ) { key += ~ ( key << 9 ) ; key ^= ( key >>> 14 ) ; key += ( key << 4 ) ; key ^= ( key >>> 10 ) ; return key & ( _buckets . length - 1 ) ; }
Turn the specified key into an index .
11,371
public IntSet intKeySet ( ) { if ( _keySet == null ) { _keySet = new AbstractIntSet ( ) { public Interator interator ( ) { return new AbstractInterator ( ) { public boolean hasNext ( ) { return i . hasNext ( ) ; } public int nextInt ( ) { return i . next ( ) . getIntKey ( ) ; } public void remove ( ) { i . remove ( ) ; } private Iterator < IntEntry < V > > i = intEntrySet ( ) . iterator ( ) ; } ; } public int size ( ) { return HashIntMap . this . size ( ) ; } public boolean contains ( int t ) { return HashIntMap . this . containsKey ( t ) ; } public boolean remove ( int value ) { Record < V > removed = removeImpl ( value , true ) ; return ( removed != null ) ; } } ; } return _keySet ; }
documentation inherited from interface IntMap
11,372
public static String rehostLocation ( HttpServletRequest req , String servername ) { StringBuffer buf = req . getRequestURL ( ) ; String csname = req . getServerName ( ) ; int csidx = buf . indexOf ( csname ) ; if ( csidx != - 1 ) { buf . delete ( csidx , csidx + csname . length ( ) ) ; buf . insert ( csidx , servername ) ; } String query = req . getQueryString ( ) ; if ( ! StringUtil . isBlank ( query ) ) { buf . append ( "?" ) . append ( query ) ; } return buf . toString ( ) ; }
Recreates the URL used to make the supplied request replacing the server part of the URL with the supplied server name .
11,373
public static String getServletURL ( HttpServletRequest req , String path ) { StringBuffer buf = req . getRequestURL ( ) ; String sname = req . getServletPath ( ) ; buf . delete ( buf . length ( ) - sname . length ( ) , buf . length ( ) ) ; if ( ! path . startsWith ( "/" ) ) { buf . append ( "/" ) ; } buf . append ( path ) ; return buf . toString ( ) ; }
Prepends the server port and servlet context path to the supplied path resulting in a fully - formed URL for requesting a servlet .
11,374
public void insertDatum ( Object element , int row ) { _data . add ( row , element ) ; _model . fireTableRowsInserted ( row , row ) ; }
Insert the specified element at the specified row .
11,375
public void updateDatum ( Object element , int row ) { _data . set ( row , element ) ; _model . fireTableRowsUpdated ( row , row ) ; }
Change the value of the specified row .
11,376
public void removeDatum ( Object element ) { int dex = _data . indexOf ( element ) ; if ( dex != - 1 ) { removeDatum ( dex ) ; } }
Remove the specified element from the set of data .
11,377
public String getErrorMessage ( ) { String msg = getMessage ( ) ; return String . valueOf ( _errorCode ) . equals ( msg ) ? null : msg ; }
Returns the textual error message supplied with this exception or null if only an error code was supplied .
11,378
public static String [ ] getCanonicalPathElements ( File file ) throws IOException { file = file . getCanonicalFile ( ) ; if ( ! file . isDirectory ( ) ) { file = file . getParentFile ( ) ; } return file . getPath ( ) . split ( File . separator ) ; }
Gets the individual path elements building up the canonical path to the given file .
11,379
public static String computeRelativePath ( File file , File relativeTo ) throws IOException { String [ ] realDirs = getCanonicalPathElements ( file ) ; String [ ] relativeToDirs = getCanonicalPathElements ( relativeTo ) ; int common = 0 ; for ( ; common < realDirs . length && common < relativeToDirs . length ; common ++ ) { if ( ! realDirs [ common ] . equals ( relativeToDirs [ common ] ) ) { break ; } } String relativePath = "" ; for ( int ii = 0 ; ii < ( realDirs . length - common ) ; ii ++ ) { relativePath += ".." + File . separator ; } for ( ; common < relativeToDirs . length ; common ++ ) { relativePath += relativeToDirs [ common ] + File . separator ; } return relativePath ; }
Computes a relative path between to Files
11,380
public static int getRunPriority ( ) { String s = System . getProperty ( RUN_PRIORITY_PROPERTY ) ; int priority = Thread . NORM_PRIORITY ; if ( s != null ) { try { priority = Integer . parseInt ( s ) ; } catch ( NumberFormatException ex ) { } } return priority ; }
Get priority for running next reports queries and exporters
11,381
public static int getRecordsYield ( ) { String s = System . getProperty ( RECORDS_YIELD_PROPERTY ) ; int records = Integer . MAX_VALUE ; if ( s != null ) { try { records = Integer . parseInt ( s ) ; } catch ( NumberFormatException ex ) { } } return records ; }
Get number of query records after the exporter waits a little to degrevate the processor
11,382
public static int getMillisYield ( ) { String s = System . getProperty ( MILLIS_YIELD_PROPERTY ) ; int millis = DEFAULT_MILLIS_YIELD ; if ( s != null ) { try { millis = Integer . parseInt ( s ) ; } catch ( NumberFormatException ex ) { } } return millis ; }
Get number of milliseconds the exporter will wait after RECORDS_YIELD are exported
11,383
public static void createSummaryInformation ( String filePath , String title ) { if ( filePath == null ) { return ; } try { File poiFilesystem = new File ( filePath ) ; InputStream is = new FileInputStream ( poiFilesystem ) ; POIFSFileSystem poifs = new POIFSFileSystem ( is ) ; is . close ( ) ; DirectoryEntry dir = poifs . getRoot ( ) ; SummaryInformation si = PropertySetFactory . newSummaryInformation ( ) ; si . setTitle ( title ) ; si . setAuthor ( ReleaseInfoAdapter . getCompany ( ) ) ; si . setApplicationName ( "NextReports " + ReleaseInfoAdapter . getVersionNumber ( ) ) ; si . setSubject ( "Created by NextReports Designer" + ReleaseInfoAdapter . getVersionNumber ( ) ) ; si . setCreateDateTime ( new Date ( ) ) ; si . setKeywords ( ReleaseInfoAdapter . getHome ( ) ) ; si . write ( dir , SummaryInformation . DEFAULT_STREAM_NAME ) ; OutputStream out = new FileOutputStream ( poiFilesystem ) ; poifs . writeFilesystem ( out ) ; out . close ( ) ; } catch ( Exception ex ) { ex . printStackTrace ( ) ; } }
is called also on the server
11,384
public ClassLoader getSiteClassLoader ( int siteId ) throws IOException { synchronized ( getLock ( siteId ) ) { ClassLoader loader = _loaders . get ( siteId ) ; if ( loader == null ) { final SiteResourceBundle bundle = getBundle ( siteId ) ; if ( bundle == null ) { return null ; } loader = AccessController . doPrivileged ( new PrivilegedAction < SiteClassLoader > ( ) { public SiteClassLoader run ( ) { return new SiteClassLoader ( bundle ) ; } } ) ; _loaders . put ( siteId , loader ) ; } return loader ; } }
Returns a class loader that loads resources from the site - specific jar file for the specified site . If no site - specific jar file exists for the specified site null will be returned .
11,385
protected Object getLock ( int siteId ) { Object lock = null ; synchronized ( _locks ) { lock = _locks . get ( siteId ) ; if ( lock == null ) { _locks . put ( siteId , lock = new Object ( ) ) ; } } return lock ; }
We synchronize on a per - site basis but we use a separate lock object for each site so that the process of loading a bundle for the first time does not require blocking access to resources from other sites .
11,386
protected SiteResourceBundle getBundle ( int siteId ) throws IOException { SiteResourceBundle bundle = _bundles . get ( siteId ) ; if ( bundle == null ) { String ident = _siteIdent . getSiteString ( siteId ) ; File file = new File ( _jarPath , ident + JAR_EXTENSION ) ; bundle = new SiteResourceBundle ( file ) ; _bundles . put ( siteId , bundle ) ; } return bundle ; }
Obtains the site - specific jar file for the specified site . This should only be called when the lock for this site is held .
11,387
public static Interval create ( RunQueue runQueue , final Runnable onExpired ) { return new Interval ( runQueue ) { public void expired ( ) { onExpired . run ( ) ; } public String toString ( ) { return onExpired . toString ( ) ; } } ; }
Creates an interval that executes the supplied runnable on the specified RunQueue when it expires .
11,388
public final void cancel ( ) { IntervalTask task = _task ; if ( task != null ) { _task = null ; task . cancel ( ) ; } }
Cancel the current schedule and ensure that any expirations that are queued up but have not yet run do not run .
11,389
public static void deliverMail ( String recipient , String sender , String subject , String body ) throws IOException { deliverMail ( new String [ ] { recipient } , sender , subject , body ) ; }
Delivers the supplied mail message using the machine s local mail SMTP server which must be listening on port 25 .
11,390
public static void deliverMail ( String [ ] recipients , String sender , String subject , String body , String [ ] headers , String [ ] values ) throws IOException { if ( recipients == null || recipients . length < 1 ) { throw new IOException ( "Must specify one or more recipients." ) ; } try { MimeMessage message = createEmptyMessage ( ) ; int hcount = ( headers == null ) ? 0 : headers . length ; for ( int ii = 0 ; ii < hcount ; ii ++ ) { message . addHeader ( headers [ ii ] , values [ ii ] ) ; } message . setText ( body ) ; deliverMail ( recipients , sender , subject , message ) ; } catch ( Exception e ) { String errmsg = "Failure sending mail [from=" + sender + ", to=" + StringUtil . toString ( recipients ) + ", subject=" + subject + "]" ; IOException ioe = new IOException ( errmsg ) ; ioe . initCause ( e ) ; throw ioe ; } }
Delivers the supplied mail with the specified additional headers .
11,391
public static void deliverMail ( String [ ] recipients , String sender , String subject , MimeMessage message ) throws IOException { checkCreateSession ( ) ; try { message . setFrom ( new InternetAddress ( sender ) ) ; for ( String recipient : recipients ) { message . addRecipient ( Message . RecipientType . TO , new InternetAddress ( recipient ) ) ; } if ( subject != null ) { message . setSubject ( subject ) ; } message . saveChanges ( ) ; Address [ ] recips = message . getAllRecipients ( ) ; if ( recips == null || recips . length == 0 ) { log . info ( "Not sending mail to zero recipients" , "subject" , subject , "message" , message ) ; return ; } Transport t = _defaultSession . getTransport ( recips [ 0 ] ) ; try { t . addTransportListener ( _listener ) ; t . connect ( ) ; t . sendMessage ( message , recips ) ; } finally { t . close ( ) ; } } catch ( Exception e ) { String errmsg = "Failure sending mail [from=" + sender + ", to=" + StringUtil . toString ( recipients ) + ", subject=" + subject + "]" ; IOException ioe = new IOException ( errmsg ) ; ioe . initCause ( e ) ; throw ioe ; } }
Delivers an already - formed message to the specified recipients . This message can be any mime type including multipart .
11,392
protected static void checkCreateSession ( ) { if ( _defaultSession == null ) { Properties props = System . getProperties ( ) ; if ( props . getProperty ( "mail.smtp.host" ) == null ) { props . put ( "mail.smtp.host" , "localhost" ) ; } _defaultSession = Session . getDefaultInstance ( props , null ) ; } }
Create our default session if not already created .
11,393
public Template getTemplate ( String path , String encoding ) throws Exception { Object siteId = get ( "__siteid__" ) ; if ( siteId != null ) { path = siteId + ":" + path ; } if ( encoding == null ) { return RuntimeSingleton . getRuntimeServices ( ) . getTemplate ( path ) ; } else { return RuntimeSingleton . getRuntimeServices ( ) . getTemplate ( path , encoding ) ; } }
Fetches a Velocity template that can be used for later formatting . The template is read with the specified encoding or the default encoding if encoding is null .
11,394
public void putAllParameters ( ) { Enumeration < ? > e = _req . getParameterNames ( ) ; while ( e . hasMoreElements ( ) ) { String param = ( String ) e . nextElement ( ) ; put ( param , _req . getParameter ( param ) ) ; } }
Don t use this method . It is terribly unsafe and was written by a lazy engineer .
11,395
public String encodeAllParameters ( ) { StringBuilder buf = new StringBuilder ( ) ; Enumeration < ? > e = _req . getParameterNames ( ) ; while ( e . hasMoreElements ( ) ) { if ( buf . length ( ) > 0 ) { buf . append ( '&' ) ; } String param = ( String ) e . nextElement ( ) ; buf . append ( StringUtil . encode ( param ) ) ; buf . append ( '=' ) ; buf . append ( StringUtil . encode ( _req . getParameter ( param ) ) ) ; } return buf . toString ( ) ; }
Encodes all the request params so they can be slapped onto a different URL which is useful when doing redirects .
11,396
public static DatabaseLiaison getLiaison ( String url ) { if ( url == null ) throw new NullPointerException ( "URL must not be null" ) ; DatabaseLiaison liaison = _mappings . get ( url ) ; if ( liaison == null ) { for ( DatabaseLiaison candidate : _liaisons ) { if ( candidate . matchesURL ( url ) ) { liaison = candidate ; break ; } } if ( liaison == null ) { log . warning ( "Unable to match liaison for database. Using default." , "url" , url ) ; liaison = new DefaultLiaison ( ) ; } _mappings . put ( url , liaison ) ; } return liaison ; }
Fetch the appropriate database liaison for the supplied URL which should be the same string that would be used to configure a connection to the database .
11,397
private XSSFCellStyle updateSubreportBandElementStyle ( XSSFCellStyle cellStyle , BandElement bandElement , Object value , int gridRow , int gridColumn , int colSpan ) { if ( subreportCellStyle == null ) { return cellStyle ; } if ( gridColumn == 0 ) { cellStyle . setBorderLeft ( subreportCellStyle . getBorderLeft ( ) ) ; cellStyle . setLeftBorderColor ( subreportCellStyle . getLeftBorderColor ( ) ) ; } else if ( gridColumn + colSpan - 1 == bean . getReportLayout ( ) . getColumnCount ( ) - 1 ) { cellStyle . setBorderRight ( subreportCellStyle . getBorderRight ( ) ) ; cellStyle . setRightBorderColor ( subreportCellStyle . getRightBorderColor ( ) ) ; } if ( pageRow == 0 ) { cellStyle . setBorderTop ( subreportCellStyle . getBorderTop ( ) ) ; cellStyle . setTopBorderColor ( subreportCellStyle . getTopBorderColor ( ) ) ; } else if ( ( pageRow + 1 ) == getRowsCount ( ) ) { cellStyle . setBorderBottom ( subreportCellStyle . getBorderBottom ( ) ) ; cellStyle . setBottomBorderColor ( subreportCellStyle . getBottomBorderColor ( ) ) ; } return cellStyle ; }
If a border style is set on a ReportBandElement we must apply it to all subreport cells
11,398
public V get ( K key ) { V value = null ; SoftReference < V > ref = _map . get ( key ) ; if ( ref != null ) { value = ref . get ( ) ; if ( value == null ) { _map . remove ( key ) ; } } return value ; }
Looks up and returns the value associated with the supplied key .
11,399
public V remove ( K key ) { SoftReference < V > ref = _map . remove ( key ) ; return ( ref == null ) ? null : ref . get ( ) ; }
Removes the specified key from the map . Returns the value to which the key was previously mapped or null .