com.webmethods.caf.jcr.faces.data
Class JcrAttachmentsProvider

java.lang.Object
  extended by com.webmethods.caf.faces.bean.PageFlowScopeAdapter
      extended by com.webmethods.caf.jcr.faces.data.JcrAttachmentsProvider
All Implemented Interfaces:
IPageFlowScopeAdapter, IAttachmentsProvider, IWebDavAwareAttachmentsProvider, Serializable
Direct Known Subclasses:
SubFolderJcrAttachmentsProvider, TaskJcrAttachmentsProvider

public class JcrAttachmentsProvider
extends PageFlowScopeAdapter
implements IWebDavAwareAttachmentsProvider, Serializable

Content provider for exposing the children of a JCR node for use with the CAF AttachmentsPanel control.

Since:
8.0
See Also:
Serialized Form

Nested Class Summary
protected static class JcrAttachmentsProvider.ErrorReportingMode
          Used to affect how errors are reported
protected  class JcrAttachmentsProvider.JcrAttachmentItem
          Implementation of IAttachmentItem to wrap a JCR file node.
static class JcrAttachmentsProvider.JcrFileItem
          Implementation of FileItem to wrap a JCR file node.
 
Field Summary
protected  boolean autoSave
          True if the attachment changes are automatically saved.
protected  String iconBaseUrl
          Holds the base Url for attachment icons.
protected  String jcrFileServletPath
          Holds the path of the JCR File download servlet
protected  Session jcrSession
          Reference to the current JCR session
protected  String parentId
          Holds the parent node id
protected  Node parentNode
          Reference to the parent Node where the attachments are stored
protected  String parentPath
          Holds the parent node path
protected  boolean useWebDav
          true to use WebDAV urls, false otherwise
 
Fields inherited from class com.webmethods.caf.faces.bean.PageFlowScopeAdapter
fExpireWithPageFlow
 
Constructor Summary
JcrAttachmentsProvider()
           
 
Method Summary
 void addAttachment(FileItem fileItem, String fileEncoding)
          Add Attachment
 boolean getHasAttachments()
          Returns whether the attachment provider has any attachments
 String getIconBaseUrl()
          Returns the icon base URL which is prepended to all the icon URLs
 String getJcrFileServletPath()
          Returns the servlet path to the JCR file streaming servlet
 Session getJcrSession()
          Returns the active JCR session
 String getParentId()
          Returns the id of the parent JCR node
 Node getParentNode()
          Returns a reference to the JCR Node that is the parent of the attachments.
 String getParentPath()
          Returns the path of the parent Node
protected  String getSafeFileName(String filePath)
          Gets a normalized file name from the supplied file path.
 boolean isAddAttachmentsAvailable()
          Returns whether attachments can be added
 boolean isAutoSave()
          Returns whether auto-save is enabled.
 boolean isUseWebDav()
          Returns whether to use WebDAV urls
 List listAttachments()
          Returns a list of the current attachments
 void refresh()
          Does nothing
 void removeAttachment(String attachmentID)
          Remove Attachment
protected  void reportError(JcrAttachmentsProvider.ErrorReportingMode mode, String msg)
          Report an error
protected  void safeNodeSave(Node node)
          Saves changes to the supplied nodes
protected  boolean sanityCheck(JcrAttachmentsProvider.ErrorReportingMode mode)
          Validates that the JCR session is alive and that the parent node has been configured correctly
 void setAutoSave(boolean autoSave)
          Sets whether autoSave is enabled
 void setIconBaseUrl(String iconBaseUrl)
          Sets the base URL to prepend to all the icon URLs
 void setJcrFileServletPath(String jcrFileServletPath)
          Sets the servlet path to the JCR file streaming servlet
 void setJcrSession(Session jcrSession)
          Sets the active JCR session
 void setParentId(String id)
          Sets the id of the parent JCR node to use
 void setParentPath(String path)
          Sets the path of the parent JCR Node to use.
 void setUseWebDav(boolean useWebDav)
          Sets whether to use WebDAV urls
 void updateAttachment(String attachmentID, FileItem fileItem, String fileEncoding)
          Update an Attachment
 
Methods inherited from class com.webmethods.caf.faces.bean.PageFlowScopeAdapter
getExpireWithPageFlow, setExpireWithPageFlow
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

jcrSession

protected transient Session jcrSession
Reference to the current JCR session


parentNode

protected transient Node parentNode
Reference to the parent Node where the attachments are stored


autoSave

protected boolean autoSave
True if the attachment changes are automatically saved. Defaults to true.


jcrFileServletPath

protected String jcrFileServletPath
Holds the path of the JCR File download servlet


iconBaseUrl

protected String iconBaseUrl
Holds the base Url for attachment icons. Defaults to the MWS front end url.


parentId

protected String parentId
Holds the parent node id


parentPath

protected String parentPath
Holds the parent node path


useWebDav

protected boolean useWebDav
true to use WebDAV urls, false otherwise

Constructor Detail

JcrAttachmentsProvider

public JcrAttachmentsProvider()
Method Detail

getIconBaseUrl

public String getIconBaseUrl()
Returns the icon base URL which is prepended to all the icon URLs

Returns:
the base URL to prepend to all the icon URLs

setIconBaseUrl

public void setIconBaseUrl(String iconBaseUrl)
Sets the base URL to prepend to all the icon URLs

Parameters:
iconBaseUrl - the baseURL to use

getParentId

public String getParentId()
Returns the id of the parent JCR node

Returns:
the uuid of the parent JCR node

setParentId

public void setParentId(String id)
Sets the id of the parent JCR node to use

Parameters:
id - the uuid of the JCR node to use as the attachments parent

setParentPath

public void setParentPath(String path)
Sets the path of the parent JCR Node to use. NOTE: if a parentId is supplied, the path is not used.

Parameters:
path - the path of the JCR node to use as the attachments parent

getParentPath

public String getParentPath()
Returns the path of the parent Node

Returns:
the path of the JCR node being used as the attachments parent

getJcrSession

public Session getJcrSession()
Returns the active JCR session

Returns:
the JCR Session

setJcrSession

public void setJcrSession(Session jcrSession)
Sets the active JCR session

Parameters:
jcrSession - the JCR session to use

isAutoSave

public boolean isAutoSave()
Returns whether auto-save is enabled. If autoSave is true, then whenever an attachment is added/updated/deleted the JCR session is automatically saved. Otherwise the changes will only get persisted when someone else invokes the jcrSession.save() API.

Returns:
the autoSave value

setAutoSave

public void setAutoSave(boolean autoSave)
Sets whether autoSave is enabled

Parameters:
autoSave - the autoSave to set

getJcrFileServletPath

public String getJcrFileServletPath()
Returns the servlet path to the JCR file streaming servlet

Returns:
the jcrFileServletPath

setJcrFileServletPath

public void setJcrFileServletPath(String jcrFileServletPath)
Sets the servlet path to the JCR file streaming servlet

Parameters:
jcrFileServletPath - the jcrFileServletPath to set

getParentNode

public Node getParentNode()
Returns a reference to the JCR Node that is the parent of the attachments.

Returns:
the parentNode

reportError

protected void reportError(JcrAttachmentsProvider.ErrorReportingMode mode,
                           String msg)
Report an error

Parameters:
mode - the error reporting mode to use
msg - the error message

sanityCheck

protected boolean sanityCheck(JcrAttachmentsProvider.ErrorReportingMode mode)
Validates that the JCR session is alive and that the parent node has been configured correctly

Parameters:
mode - the error reporting mode
Returns:
true if everything is ok, false otherwise

addAttachment

public void addAttachment(FileItem fileItem,
                          String fileEncoding)
Description copied from interface: IAttachmentsProvider
Add Attachment

Specified by:
addAttachment in interface IAttachmentsProvider
Parameters:
fileItem - the attachment content
fileEncoding - the encoding of the attachment file (if known)

safeNodeSave

protected void safeNodeSave(Node node)
                     throws RepositoryException
Saves changes to the supplied nodes

Parameters:
node - the node to save
Throws:
RepositoryException

isAddAttachmentsAvailable

public boolean isAddAttachmentsAvailable()
Description copied from interface: IAttachmentsProvider
Returns whether attachments can be added

Specified by:
isAddAttachmentsAvailable in interface IAttachmentsProvider
Returns:
true or false

listAttachments

public List listAttachments()
Description copied from interface: IAttachmentsProvider
Returns a list of the current attachments

Specified by:
listAttachments in interface IAttachmentsProvider
Returns:
collection of AttachmentItems

getHasAttachments

public boolean getHasAttachments()
Description copied from interface: IAttachmentsProvider
Returns whether the attachment provider has any attachments

Specified by:
getHasAttachments in interface IAttachmentsProvider
Returns:
true or false

removeAttachment

public void removeAttachment(String attachmentID)
Description copied from interface: IAttachmentsProvider
Remove Attachment

Specified by:
removeAttachment in interface IAttachmentsProvider
Parameters:
attachmentID - the id of the attachment to remove

updateAttachment

public void updateAttachment(String attachmentID,
                             FileItem fileItem,
                             String fileEncoding)
Description copied from interface: IAttachmentsProvider
Update an Attachment

Specified by:
updateAttachment in interface IAttachmentsProvider
Parameters:
attachmentID - the id of the attachment to update
fileItem - the new attachment content
fileEncoding - the encoding of the attachment file (if known)

getSafeFileName

protected String getSafeFileName(String filePath)
Gets a normalized file name from the supplied file path. Illegal charactgers are escaped

Parameters:
filePath - the file path to process
Returns:
safe file name

isUseWebDav

public boolean isUseWebDav()
Returns whether to use WebDAV urls

Specified by:
isUseWebDav in interface IWebDavAwareAttachmentsProvider
Returns:
true or false

setUseWebDav

public void setUseWebDav(boolean useWebDav)
Sets whether to use WebDAV urls

Specified by:
setUseWebDav in interface IWebDavAwareAttachmentsProvider

refresh

public void refresh()
Does nothing

Specified by:
refresh in interface IWebDavAwareAttachmentsProvider