SilverStream
Application Server 3.5

com.sssw.rt.form
Class AgcFileAttachment

java.lang.Object
 |
 +--java.awt.Component
       |
       +--java.awt.Container
             |
             +--javax.swing.JComponent
                   |
                   +--javax.swing.JPanel
                         |
                         +--com.sssw.rt.atlas.AtPanel
                               |
                               +--com.sssw.rt.atlas.AtCanvas
                                     |
                                     +--com.sssw.rt.form.PvBaseCanvas
                                           |
                                           +--com.sssw.rt.form.PvInvisibleControlBase
                                                 |
                                                 +--com.sssw.rt.form.AgcFileAttachment
All Implemented Interfaces:
Accessible, AgiControl, AgiHelpInfo, ImageObserver, MenuContainer, Serializable

public class AgcFileAttachment
extends com.sssw.rt.form.PvInvisibleControlBase

The File Attachment Control (AgcFileAttachment) is a databound control for storing file attachments in a database.

This control must be bound to a database column. The contents of the file attachment must be stored in a long varbinary column. The control is visible while in the Form Designer, but it is not at runtime.

Because of Java security restrictions, AgcFileAttachment can only be used with applications deployed using SilverJRunner.

Note: The ancestor methods in this class, that is all methods inherited from the non-public PvInvisibleControlBase (including JComponent and Component) are not visible at run time, and are primarily for use by SilverStream. The useful methods are contained in the AgcFileAttachment class itself.

Properties:
Control Type, Database Column, Name
Events:
validationFailed, validationTest, valueChanged
See Also:
Serialized Form

Inner classes inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
 
Inner classes inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Fields inherited from class com.sssw.rt.atlas.AtPanel
BGIMAGE_DRAW_CENTERED, BGIMAGE_DRAW_NORMAL, BGIMAGE_DRAW_STRETCH, BGIMAGE_DRAW_TILED
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Constructor Summary
AgcFileAttachment()
           
 
Method Summary
 File chooseFile(String caption, File defaultFile, boolean forSaving)
          Displays a dialog box to the user which prompts for a local file or filename.
 void deleteFile(File file)
          Displays a dialog box that warns the user that the named file will be deleted, then deletes it.
 void download(File localFile, boolean launch)
          Displays a warning dialog box to the user, stores the referenced resource in a local file, and then optionally launches the application for that file.
 Object getContents()
          Gets the contents of the attachment as an object.
 void launchFile(File file)
          Notifies the user then launches the registered program for the specified file.
 InputStream readAndDeleteFile(File file)
          Notifies the user (once), returns an InputStream to the specified file, then deletes the file when the stream is closed.
 InputStream readFile(File file)
          Returns an input stream from the referenced file.
 void setContents(Object contents)
          Updates or inserts the Object to the field to which the AgcFileAttachment is bound.
 void upload(File localFile, boolean delete)
          Uploades the local file to the database column to which the AgcFileAttachment is bound.
 OutputStream writeAndLaunchFile(File file)
          Notifies the user, creates a local file, then launches its associated application.
 OutputStream writeFile(File file)
          Notifies the user then writes to a local file.
 
Methods inherited from class com.sssw.rt.form.PvInvisibleControlBase
setBounds, setLocation, setSize
 
Methods inherited from class com.sssw.rt.form.PvBaseCanvas
getBackgroundColor, getFontIdentifier, setBackgroundColor, setFontIdentifier
 
Methods inherited from class com.sssw.rt.atlas.AtPanel
addImpl, addNotify, clientPaint, clientPaint, deliverMouseEvent, deliverMouseMoveEvent, doAtCommand, drawTiledImage, enableAtCommands, getBackgroundImage, getBackgroundImageMode, getHelper, getTransparent, hide, hideToolTip, imageUpdate, isFocusTraversable, isOptimizedDrawingEnabled, ownedImage, paintBorder, paintComponent, paintImmediately, paintImmediately, paintNow, preprocessKeyEvent, processEvent, reshape, setBackgroundImage, setBackgroundImageMode, setTransparent, show, showToolTip
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUIClassID, paramString, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getAlignmentX, getAlignmentY, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getGraphics, getHeight, getInsets, getInsets, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getVisibleRect, getWidth, getX, getY, grabFocus, hasFocus, isDoubleBuffered, isFocusCycleRoot, isLightweightComponent, isManagingFocus, isOpaque, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintChildren, print, printAll, processComponentKeyEvent, processFocusEvent, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, revalidate, scrollRectToVisible, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDoubleBuffered, setEnabled, setFont, setForeground, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setUI, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getLayout, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, remove, remove, removeAll, removeContainerListener, setCursor, setLayout, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, inside, isDisplayable, isEnabled, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processInputMethodEvent, processMouseEvent, remove, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, repaint, repaint, repaint, resize, resize, setBounds, setComponentOrientation, setDropTarget, setLocale, setLocation, setName, setSize, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods implemented from interface com.sssw.rt.form.AgiControl
getComponent, getHelpInfo, setHelpInfo
 

Constructor Detail

AgcFileAttachment

public AgcFileAttachment()
Method Detail

getContents

public Object getContents()
Gets the contents of the attachment as an object.
Example:
  Object contents;
      contents = attachment1.getContents();
 

setContents

public void setContents(Object contents)
                 throws AgoSecurityException,
                        AgoTransientSystemException,
                        AgoUnrecoverableSystemException,
                        AgoInvalidDataException,
                        AgoMissingDataException,
                        AgoDataConcurrencyException,
                        AgoApplicationException
Updates or inserts the Object to the field to which the AgcFileAttachment is bound.
Parameters:
contents -  
Usage:

The AgcFileAttachment submits the update request directly to the SilverStream Server and bypasses the form's data buffering and transaction handling. If a record exists, then the record is updated. If the record does not exist, then a new record is inserted.

If setContents() is called before calling updateRows() on the form's agData, a 'duplicate key' error might result because setContents() has updated the database directly.

Example:
 Object newContents;
 newContents = new byte[50];
 
    // populate the byte array with binary data
    try {
 	    attachment1.setContents(newContents);
    }
    catch (AgoApiException e) {
          agDialog.displayError(e);
    }
 
See Also:
AgoSecurityException, AgoTransientSystemException, AgoUnrecoverableSystemException, AgoInvalidDataException, AgoMissingDataException, AgoDataConcurrencyException

download

public void download(File localFile,
                     boolean launch)
              throws AgoSecurityException,
                     IOException
Displays a warning dialog box to the user, stores the referenced resource in a local file, and then optionally launches the application for that file.
Parameters:
localfile - specifies the file and path for the file to download.
launch - specifies whether to launch the file (true) or not (false).
Usage:

SilverStream launches an application for the file based on the registry entry for the file's extension.

Example:
  File storageFile;
  storageFile = new File("c:\\directory\\file");
     try {
          attachment1.download(storageFile,true);
  	    }
     catch (Exception e) {
          agDialog.displayError(e);
         }
 
See Also:
AgoSecurityException

upload

public void upload(File localFile,
                   boolean delete)
            throws AgoSecurityException,
                   AgoTransientSystemException,
                   AgoUnrecoverableSystemException,
                   AgoInvalidDataException,
                   AgoMissingDataException,
                   AgoDataConcurrencyException,
                   IOException
Uploades the local file to the database column to which the AgcFileAttachment is bound. It notifies the user (using a dialog box) before performing the upload operation.
Parameters:
localfile - specifies the file and path for the file to upload.
delete - specifies whether to delete (true) the local file or not (false) after uploading it.
Usage:

The AgcFileAttachment submits the request directly to the SilverStream Server and bypasses the form's data buffering and transaction handling. If a record exists, then the record is updated. If a record does not exist, then a new record is inserted.

If delete is set to true, SilverStream deletes the local file once the upload is completed. If upload() is called before calling updateRows() on the form's agData, a 'duplicate key' error might result because upload() updates the database directly.

Example:
  File fileToUpload;
  fileToUpload = new File("c:\\directory\\file");
     try {
          attachment1.upload(fileToUpload,true);
     }
    catch (Exception e) {
                agDialog.displayError(e);
     }
 
See Also:
AgoSecurityException, AgoTransientSystemException, AgoUnrecoverableSystemException, AgoInvalidDataException, AgoMissingDataException, AgoDataConcurrencyException

writeFile

public OutputStream writeFile(File file)
                       throws AgoSecurityException,
                              IOException
Notifies the user then writes to a local file.
Parameters:
file - specifies the file and path for the file to create.
Example:
 File fileToWrite;
 fileToWrite = new File("c:\\directory\\file");
 OutputStream output;
 try {
      output = attachment1.writeFile(fileToWrite);
     }
    catch (Exception e) {
     agDialog.displayError(e);
     }
 
See Also:
AgoSecurityException

readFile

public InputStream readFile(File file)
                     throws AgoSecurityException,
                            IOException
Returns an input stream from the referenced file.
Parameters:
file - specifies the file and path for the file to read.
Example:
  File fileToRead;
  fileToRead = new File("c:\\directory\\file");
  InputStream input;
    try {
        input = attachment1.readFile(fileToRead);
        }
    catch (Exception e) {
         agDialog.displayError(e);
        }
 
See Also:
AgoSecurityException

deleteFile

public void deleteFile(File file)
                throws AgoSecurityException,
                       IOException
Displays a dialog box that warns the user that the named file will be deleted, then deletes it.
Parameters:
file - specifies the file to delete.
Example:
  File fileToDelete;
       try {
            fileToDelete = attachment1.chooseFile("Choose a File to Delete",null,false);
            attachment1.deleteFile(fileToDelete);
           }
       catch (Exception e) {
            agDialog.displayError(e);
           }
 
See Also:
AgoSecurityException

launchFile

public void launchFile(File file)
                throws AgoSecurityException,
                       IOException
Notifies the user then launches the registered program for the specified file.
Parameters:
file - specifies the file and path for the file to launch.
Usage:

SilverStream launches an application for the file based on the registry entry for the file's extension.

Example:
  File fileToLaunch;
  fileToLaunch = new File("c:\\directory\\file");
  try {
       attachment1.launchFile(fileToLaunch);
      }
  catch (Exception e) {
      agDialog.displayError(e);
      }
 
See Also:
AgoSecurityException

chooseFile

public File chooseFile(String caption,
                       File defaultFile,
                       boolean forSaving)
                throws AgoSecurityException
Displays a dialog box to the user which prompts for a local file or filename.
Parameters:
caption - specifies a message to display on the Choose File dialog.
defaultFile - specifies the default for a path and file name to display in the Choose File dialog.
forSaving - specifies a boolean value that indicates whether the file is being chosen for saving or for reading.
Example:
  File defaultFile;
  defaultFile = new File("c:\\Directory\\File");
  File chosenFile;
 
  try {
       chosenFile = attachment1.chooseFile("Choose a File",defaultFile,false);
 
      }
  catch (AgoSecurityException e) {
 
      agDialog.displayError(e);
      }
 
See Also:
AgoSecurityException

writeAndLaunchFile

public OutputStream writeAndLaunchFile(File file)
                                throws AgoSecurityException,
                                       IOException
Notifies the user, creates a local file, then launches its associated application.
Parameters:
file - specifies the file and path for the file.
Usage:

SilverStream launches an application for the file based on the registry entry for the file's extension. The file is launched when the OutputStream is closed.

Example:
  File fileToWrite;
  fileToWrite = new File("c:\\directory\\file");
  OutputStream output;
    try {
        output = AgcFileAttachment.writeAndLaunch(fileToWrite);
        }
    catch (Exception e) {
          agDialog.displayError(e);
        }
 
 	// Write the contents of the file to the OutputStream
 
See Also:
AgoSecurityException

readAndDeleteFile

public InputStream readAndDeleteFile(File file)
                              throws AgoSecurityException,
                                     IOException
Notifies the user (once), returns an InputStream to the specified file, then deletes the file when the stream is closed.
Parameters:
file - specifies the file and path for the file to read and delete.
Example:
  File fileToRead;
  InputStream dataFromFile;
     try {
          fileToRead = attachment1.chooseFile("Choose a File to Read and Delete",null,false);
            dataFromFile = attachment1.readAndDeleteFile(fileToRead);
         }
     catch (Exception e) {
             agDialog.displayError(e);
         }
 
See Also:
AgoSecurityException

SilverStream
Application Server 3.5