Class NetworkSave
- java.lang.Object
-
- org.faceless.pdf2.viewer2.ViewerFeature
-
- org.faceless.pdf2.viewer2.ViewerWidget
-
- org.faceless.pdf2.viewer2.feature.NetworkSave
-
- All Implemented Interfaces:
DocumentPanelListener
public class NetworkSave extends ViewerWidget implements DocumentPanelListener
Create a button that will submit a PDF to a network URL. By default this feature is disabled - to enable it in an application,: you would add a new NetworkSave instance to the list of features passed in to thePDFViewer(java.util.Collection)
constructor:ArrayList f = new ArrayList(ViewerFeature.getAllEnabledFeatures()); NetworkSave save = new NetworkSave(); save.setURL(new URL("http://localhost:8080/savepdf")); f.add(save); PDFViewer viewer = new PDFViewer(f);
The
URL
attribute must be set on this feature before it can be used, either via theurl
initialization parameter or by calling thesetURL(java.net.URL)
method. It may contain a Base64-encoded username and password if necessary. The PDF will be rendered and sent directly to the URL connection'sOutputStream
. If the filename of the PDF is known, it will be submitted via theX-BFOPDF-File
HTTP header - if more customization is required you can override thesetAdditionalHeaders(java.net.URLConnection, org.faceless.pdf2.viewer2.DocumentPanel)
method to modify the PDF and/or the connection headers before the PDF is submittedThe following initialization parameters can be specified to configure this feature.The name of this feature is NetworkSaveurl The URL to submit the save action to premessage The message to display to the user before submission. If not null, the value will be displayed to the user with an "OK" or "Cancel" prompt before saving postmessage The message to display to the user after submission. If not null, the value will be displayed to the user with an "OK" prompt after saving. The special value "response" can be used to display the HMTL response from the server fieldname If set, the PDF will be sent as if submitted via an HTTP Form - "fieldname" would be the name of the field. It null, the PDF will simply be written as the body of the HTTP content (since 2.11.19). filename The filename parameter to send in the submission (defaults to the PDF filename) timeout The connection timeout value in milliseconds (0 is infinite) readTimeout The read timeout value in milliseconds (0 is infinite) This code is copyright the Big Faceless Organization. You're welcome to use, modify and distribute it in any form in your own projects, provided those projects continue to make use of the Big Faceless PDF library.
- Since:
- 2.11.17
-
-
Field Summary
-
Fields inherited from class org.faceless.pdf2.viewer2.ViewerWidget
propertyChangeSupport
-
-
Constructor Summary
Constructors Constructor Description NetworkSave()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
action(ViewerEvent event)
The method that's run when this feature is activated.protected ActionListener
createActionListener()
Return an ActionListener that will be called when this Widget is activated.void
documentUpdated(DocumentPanelEvent event)
Called when anDocumentPanelEvent
is raisedvoid
initialize(PDFViewer viewer)
Called when the feature is first added to a viewerboolean
isEnabledByDefault()
Return true if this feature is enabled by default (the default).void
save(ViewerEvent event, Exporter exporter, URL url)
Save the Document to the networkvoid
setAdditionalHeaders(URLConnection con, DocumentPanel panel)
Set any additional headers on the connection, or modify the PDF if necessary before saving.void
setFieldName(String fieldname)
Set the field name which the PDF will be submitted as (as if it were sent from an HTML Form).void
setFileName(String filename)
Set the file name which the PDF will be submitted as (as if it were sent from an HTML Form).void
setPostMessage(String message)
Set the message which will be displayed to the user after a successful save.void
setPreMessage(String message)
Set the message which will be displayed to the user before saving as a prompt - the save will only continue if the user selects "OK".void
setReadTimeout(int timeout)
Set the timeout in milliseconds that should be used when reading from a URL.void
setTimeout(int timeout)
Set the timeout in milliseconds that should be used when connecting to a URL.void
setURL(URL url)
Set the URL the PDF will be submitted to.-
Methods inherited from class org.faceless.pdf2.viewer2.ViewerWidget
addPropertyChangeListener, firePropertyChange, getComponent, getIcon, getViewer, isButtonEnabledByDefault, isDocumentRequired, isMenuEnabledByDefault, removePropertyChangeListener, setButton, setComponent, setDocumentRequired, setMenu, setMenu, setToolBarEnabled, setToolBarEnabledAlways, setToolBarFloatable, setToolBarFloating, toString
-
Methods inherited from class org.faceless.pdf2.viewer2.ViewerFeature
getAllEnabledFeatures, getAllFeatures, getCustomJavaScript, getFeatureProperty, getFeatureURLProperty, getName, setFeatureName, teardown
-
-
-
-
Method Detail
-
createActionListener
protected ActionListener createActionListener()
Description copied from class:ViewerWidget
Return an ActionListener that will be called when this Widget is activated. Subclasses will typically not need to override this method except in special cases.- Overrides:
createActionListener
in classViewerWidget
- Returns:
- ActionListener the ActionListener to be notified when an event fires
- See Also:
Quit.createActionListener()
-
action
public void action(ViewerEvent event)
Description copied from class:ViewerWidget
The method that's run when this feature is activated. This method is called by theActionListener
returned by the default implementation ofViewerWidget.createActionListener()
, and by default is a no-op.- Overrides:
action
in classViewerWidget
-
isEnabledByDefault
public boolean isEnabledByDefault()
Description copied from class:ViewerFeature
Return true if this feature is enabled by default (the default). Disabled features are excluded from the list returned byViewerFeature.getAllEnabledFeatures()
and byPDFTool
- Overrides:
isEnabledByDefault
in classViewerFeature
-
initialize
public void initialize(PDFViewer viewer)
Description copied from class:ViewerFeature
Called when the feature is first added to a viewer- Overrides:
initialize
in classViewerWidget
-
setTimeout
public void setTimeout(int timeout)
Set the timeout in milliseconds that should be used when connecting to a URL. A value of 0 (the default) means infinite.- Parameters:
timeout
- the number of milliseconds to wait while connecting to a URL before timing out
-
setReadTimeout
public void setReadTimeout(int timeout)
Set the timeout in milliseconds that should be used when reading from a URL. A value of 0 (the default) means infinite.- Parameters:
timeout
- the number of milliseconds to wait while reading from a URL before timing out
-
setURL
public void setURL(URL url)
Set the URL the PDF will be submitted to. This must be set for this feature to work.- Parameters:
url
- the URL
-
setPreMessage
public void setPreMessage(String message)
Set the message which will be displayed to the user before saving as a prompt - the save will only continue if the user selects "OK". Setting this value to null (the default) means no prompt will be given before saving.- Parameters:
message
- the message to display
-
setPostMessage
public void setPostMessage(String message)
Set the message which will be displayed to the user after a successful save. If this is null (the default) no message will be displayed. The special value "response" can be used to display the HTML response from the server.- Parameters:
message
- the message to display
-
setFieldName
public void setFieldName(String fieldname)
Set the field name which the PDF will be submitted as (as if it were sent from an HTML Form). If null (the default), the PDF will simply be written to the HTTP stream.- Parameters:
fieldname
- the field name- Since:
- 2.11.19
-
setFileName
public void setFileName(String filename)
Set the file name which the PDF will be submitted as (as if it were sent from an HTML Form). If null (the default), the filename of the PDF will be used.- Parameters:
filename
- the file name- Since:
- 2.11.19
-
documentUpdated
public void documentUpdated(DocumentPanelEvent event)
Description copied from interface:DocumentPanelListener
Called when anDocumentPanelEvent
is raised- Specified by:
documentUpdated
in interfaceDocumentPanelListener
-
save
public void save(ViewerEvent event, Exporter exporter, URL url)
Save the Document to the network- Parameters:
event
- the ViewerEvent that launched this actionexporter
- theExporter
to use, or null to default to aPDFExporter
url
- the URL to submit the PDF to
-
setAdditionalHeaders
public void setAdditionalHeaders(URLConnection con, DocumentPanel panel)
Set any additional headers on the connection, or modify the PDF if necessary before saving. Called by thesave(org.faceless.pdf2.viewer2.ViewerEvent, org.faceless.pdf2.viewer2.Exporter, java.net.URL)
method just before the PDF is sent, by default this method does nothing.
-
-