info.magnolia.module.exchangesimple
Class ReceiveFilter

java.lang.Object
  extended by info.magnolia.cms.filters.AbstractMgnlFilter
      extended by info.magnolia.module.exchangesimple.ReceiveFilter
All Implemented Interfaces:
info.magnolia.cms.filters.MgnlFilter, javax.servlet.Filter

public class ReceiveFilter
extends info.magnolia.cms.filters.AbstractMgnlFilter

This filter receives activation requests from another instance and applies them.

Author:
Sameer Charles $Id$

Field Summary
static String ROOT_LOCK_NAME
           
static String SYSTEM_REPO
           
 
Constructor Summary
ReceiveFilter(ExchangeSimpleModule module)
           
 
Method Summary
protected  void applyLock(javax.servlet.http.HttpServletRequest request)
          apply lock.
protected  String[] checkAuthenticated(javax.servlet.http.HttpServletRequest request)
           
protected  void cleanUp(javax.servlet.http.HttpServletRequest request, String status)
          cleans temporary store and removes any locks set.
protected  void copyProperties(info.magnolia.cms.core.Content source, info.magnolia.cms.core.Content destination)
          Copy all properties from source to destination (by cleaning the old properties).
 void doFilter(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.FilterChain chain)
           
protected  info.magnolia.cms.core.HierarchyManager getBackupHierarchyManager()
           
protected  info.magnolia.cms.core.HierarchyManager getHierarchyManager(javax.servlet.http.HttpServletRequest request)
          get hierarchy manager.
protected  org.jdom.Element getImportedContentRoot(info.magnolia.cms.beans.runtime.MultipartForm data, String resourceFileName, String resourcesmd5)
           
protected  info.magnolia.cms.core.Content getNode(javax.servlet.http.HttpServletRequest request)
          Returns parent node of the activated node in case of activation or the node itself in case of deactivation.
protected  String getParentPath(javax.servlet.http.HttpServletRequest request)
           
 long getRetryWait()
           
 int getUnlockRetries()
           
protected  String getUser(javax.servlet.http.HttpServletRequest request)
          Deprecated. since 4.5. This method is not used anymore and there is no replacement. Authentication of activation is now handled by exchange of info encrypted by PPKey.
protected  String getUUID(javax.servlet.http.HttpServletRequest request)
           
protected  String getWebappName()
           
protected  void handleChildren(javax.servlet.http.HttpServletRequest request, info.magnolia.cms.core.Content content)
           
protected  String handleMovedContent(String newParentPath, info.magnolia.cms.core.HierarchyManager hm, org.jdom.Element topContentElement, info.magnolia.cms.core.Content content)
           
protected  void importFresh(org.jdom.Element topContentElement, info.magnolia.cms.beans.runtime.MultipartForm data, info.magnolia.cms.core.HierarchyManager hierarchyManager, String parentPath)
          import on non existing tree.
protected  void importOnExisting(org.jdom.Element topContentElement, info.magnolia.cms.beans.runtime.MultipartForm data, info.magnolia.cms.core.HierarchyManager hierarchyManager, info.magnolia.cms.core.Content existingContent)
          import on existing content, making sure that content which is not sent stays as is.
protected  void importResource(info.magnolia.cms.beans.runtime.MultipartForm data, org.jdom.Element resourceElement, info.magnolia.cms.core.HierarchyManager hm, String parentPath)
          import documents.
protected  boolean isAuthorAuthenticated(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
           
protected  void lock(info.magnolia.cms.core.Content node, info.magnolia.cms.core.Content parent)
          Method handling issuing of the lock.
protected  void order(info.magnolia.cms.core.Content parent, String name, String orderBefore)
           
protected  String orderImportedNode(String newParentPath, info.magnolia.cms.core.HierarchyManager hm, org.jdom.Element rootElement, org.jdom.Element topContentElement)
           
protected  String receive(javax.servlet.http.HttpServletRequest request)
          handle activate or deactivate request.
protected  void releaseLock(javax.servlet.http.HttpServletRequest request)
           
protected  String remove(javax.servlet.http.HttpServletRequest request, String md5)
          Deletes (de-activate) the content specified by the request.
protected  void removeChildren(info.magnolia.cms.core.Content content, info.magnolia.cms.core.Content.ContentFilter filter)
          remove children.
protected  void setResponseHeaders(javax.servlet.http.HttpServletResponse response, String statusMessage, String status, String result)
           
 void setRetryWait(int retryWait)
           
 void setUnlockRetries(int unlockRetries)
           
protected  String update(javax.servlet.http.HttpServletRequest request, String resourcesmd5)
          handle update (activate) request.
protected  info.magnolia.cms.core.Content waitForLock(javax.servlet.http.HttpServletRequest request)
          Will wait for predefined amount of time and attempt predefined number of times to obtain unlocked content.
 
Methods inherited from class info.magnolia.cms.filters.AbstractMgnlFilter
acceptsEncoding, acceptsGzipEncoding, addAndVerifyHeader, addBypass, addMapping, bypasses, destroy, doFilter, getBypasses, getDispatching, getMapping, getMappings, getName, headerContains, init, isEnabled, mapsTo, matches, matchesDispatching, setDispatching, setEnabled, setName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SYSTEM_REPO

public static final String SYSTEM_REPO
See Also:
Constant Field Values

ROOT_LOCK_NAME

public static final String ROOT_LOCK_NAME
See Also:
Constant Field Values
Constructor Detail

ReceiveFilter

@Inject
public ReceiveFilter(ExchangeSimpleModule module)
Method Detail

getUnlockRetries

public int getUnlockRetries()

setUnlockRetries

public void setUnlockRetries(int unlockRetries)

getRetryWait

public long getRetryWait()

setRetryWait

public void setRetryWait(int retryWait)

doFilter

public void doFilter(javax.servlet.http.HttpServletRequest request,
                     javax.servlet.http.HttpServletResponse response,
                     javax.servlet.FilterChain chain)
              throws IOException,
                     javax.servlet.ServletException
Specified by:
doFilter in class info.magnolia.cms.filters.AbstractMgnlFilter
Throws:
IOException
javax.servlet.ServletException

isAuthorAuthenticated

protected boolean isAuthorAuthenticated(javax.servlet.http.HttpServletRequest request,
                                        javax.servlet.http.HttpServletResponse response)
                                 throws NoSuchAlgorithmException,
                                        info.magnolia.cms.exchange.ExchangeException
Throws:
NoSuchAlgorithmException
info.magnolia.cms.exchange.ExchangeException

setResponseHeaders

protected void setResponseHeaders(javax.servlet.http.HttpServletResponse response,
                                  String statusMessage,
                                  String status,
                                  String result)

receive

protected String receive(javax.servlet.http.HttpServletRequest request)
                  throws Exception
handle activate or deactivate request.

Parameters:
request -
Throws:
Exception - if fails to update

checkAuthenticated

protected String[] checkAuthenticated(javax.servlet.http.HttpServletRequest request)
                               throws info.magnolia.cms.exchange.ExchangeException
Throws:
info.magnolia.cms.exchange.ExchangeException

getWebappName

protected String getWebappName()

getUser

@Deprecated
protected String getUser(javax.servlet.http.HttpServletRequest request)
Deprecated. since 4.5. This method is not used anymore and there is no replacement. Authentication of activation is now handled by exchange of info encrypted by PPKey.


update

protected String update(javax.servlet.http.HttpServletRequest request,
                        String resourcesmd5)
                 throws Exception
handle update (activate) request.

Parameters:
request - incoming reuqest
resourcesmd5 - signature confirming validity of resource file
Throws:
Exception - if fails to update

getImportedContentRoot

protected org.jdom.Element getImportedContentRoot(info.magnolia.cms.beans.runtime.MultipartForm data,
                                                  String resourceFileName,
                                                  String resourcesmd5)
                                           throws org.jdom.JDOMException,
                                                  IOException
Throws:
org.jdom.JDOMException
IOException

handleChildren

protected void handleChildren(javax.servlet.http.HttpServletRequest request,
                              info.magnolia.cms.core.Content content)

handleMovedContent

protected String handleMovedContent(String newParentPath,
                                    info.magnolia.cms.core.HierarchyManager hm,
                                    org.jdom.Element topContentElement,
                                    info.magnolia.cms.core.Content content)
                             throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

orderImportedNode

protected String orderImportedNode(String newParentPath,
                                   info.magnolia.cms.core.HierarchyManager hm,
                                   org.jdom.Element rootElement,
                                   org.jdom.Element topContentElement)
                            throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

order

protected void order(info.magnolia.cms.core.Content parent,
                     String name,
                     String orderBefore)
              throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

copyProperties

protected void copyProperties(info.magnolia.cms.core.Content source,
                              info.magnolia.cms.core.Content destination)
                       throws javax.jcr.RepositoryException
Copy all properties from source to destination (by cleaning the old properties).

Parameters:
source - the content node to be copied
destination - the destination node
Throws:
javax.jcr.RepositoryException

removeChildren

protected void removeChildren(info.magnolia.cms.core.Content content,
                              info.magnolia.cms.core.Content.ContentFilter filter)
remove children.

Parameters:
content - whose children to be deleted
filter - content filter

importFresh

protected void importFresh(org.jdom.Element topContentElement,
                           info.magnolia.cms.beans.runtime.MultipartForm data,
                           info.magnolia.cms.core.HierarchyManager hierarchyManager,
                           String parentPath)
                    throws info.magnolia.cms.exchange.ExchangeException,
                           javax.jcr.RepositoryException
import on non existing tree.

Parameters:
topContentElement -
data -
hierarchyManager -
parentPath -
Throws:
info.magnolia.cms.exchange.ExchangeException
javax.jcr.RepositoryException

importOnExisting

protected void importOnExisting(org.jdom.Element topContentElement,
                                info.magnolia.cms.beans.runtime.MultipartForm data,
                                info.magnolia.cms.core.HierarchyManager hierarchyManager,
                                info.magnolia.cms.core.Content existingContent)
                         throws info.magnolia.cms.exchange.ExchangeException,
                                javax.jcr.RepositoryException
import on existing content, making sure that content which is not sent stays as is.

Parameters:
topContentElement -
data -
hierarchyManager -
existingContent -
Throws:
info.magnolia.cms.exchange.ExchangeException
javax.jcr.RepositoryException

importResource

protected void importResource(info.magnolia.cms.beans.runtime.MultipartForm data,
                              org.jdom.Element resourceElement,
                              info.magnolia.cms.core.HierarchyManager hm,
                              String parentPath)
                       throws Exception
import documents.

Parameters:
data - as sent
resourceElement - parent file element
hm -
parentPath - Path to the node parent
Throws:
Exception

remove

protected String remove(javax.servlet.http.HttpServletRequest request,
                        String md5)
                 throws Exception
Deletes (de-activate) the content specified by the request.

Parameters:
request -
Throws:
Exception - if fails to update

getHierarchyManager

protected info.magnolia.cms.core.HierarchyManager getHierarchyManager(javax.servlet.http.HttpServletRequest request)
                                                               throws info.magnolia.cms.exchange.ExchangeException
get hierarchy manager.

Parameters:
request -
Throws:
info.magnolia.cms.exchange.ExchangeException

cleanUp

protected void cleanUp(javax.servlet.http.HttpServletRequest request,
                       String status)
cleans temporary store and removes any locks set.

Parameters:
request -
status -

releaseLock

protected void releaseLock(javax.servlet.http.HttpServletRequest request)

applyLock

protected void applyLock(javax.servlet.http.HttpServletRequest request)
                  throws info.magnolia.cms.exchange.ExchangeException
apply lock.

Parameters:
request -
Throws:
info.magnolia.cms.exchange.ExchangeException

waitForLock

protected info.magnolia.cms.core.Content waitForLock(javax.servlet.http.HttpServletRequest request)
                                              throws info.magnolia.cms.exchange.ExchangeException,
                                                     javax.jcr.RepositoryException
Will wait for predefined amount of time and attempt predefined number of times to obtain unlocked content.

Parameters:
request -
Returns:
unlocked content specified by the request or null in case such content doesnt exist
Throws:
info.magnolia.cms.exchange.ExchangeException
javax.jcr.RepositoryException

getBackupHierarchyManager

protected info.magnolia.cms.core.HierarchyManager getBackupHierarchyManager()

getNode

protected info.magnolia.cms.core.Content getNode(javax.servlet.http.HttpServletRequest request)
                                          throws info.magnolia.cms.exchange.ExchangeException,
                                                 javax.jcr.RepositoryException
Returns parent node of the activated node in case of activation or the node itself in case of deactivation.

Throws:
info.magnolia.cms.exchange.ExchangeException
javax.jcr.RepositoryException

getParentPath

protected String getParentPath(javax.servlet.http.HttpServletRequest request)

getUUID

protected String getUUID(javax.servlet.http.HttpServletRequest request)

lock

protected void lock(info.magnolia.cms.core.Content node,
                    info.magnolia.cms.core.Content parent)
             throws info.magnolia.cms.exchange.ExchangeException,
                    javax.jcr.RepositoryException
Method handling issuing of the lock. Magnolia needs to lock not only the updated node, but also the parent node in case activated node is just being moved within same hierarchy or in case of deactivation. Locking of parent is not always possible (e.g. root node is not lockable). This method treats all special cases and can be overridden in case even more specialized handling is needed.

Parameters:
node - Activated node.
parent - Parent of activated node.
Throws:
info.magnolia.cms.exchange.ExchangeException
javax.jcr.RepositoryException


Copyright © 2003-2013 Magnolia International Ltd.. All Rights Reserved.