Excerpt from web object code :

dealer.setProperty("dealer", "dealername", dealernameval);
dsddao.save(dealer);

...this triggers a documentModified event, which is handled by:


public class SetDealerClubNamesEventListener extends 
AbstractDocumentEventListener
{
    private static final String DOCUMENTMODIFIED = "documentModified";
    
    @Override
    protected void processEvent(Event event, DocumentModel doc, Principal p) 
throws ClientException
    {
        String type = doc.getType();

        CoreSession cs = event.getContext().getCoreSession();
        
        if (type.equals(DocumentTypesUtil.DEALER_DOC_TYPE))
        {
                    String name = (String)doc.getProperty(schemaName, 
nameField);
                    String lowercaseName = (String)doc.getProperty(schemaName, 
lowecaseNameField);
        String newLowerName = name.toLowerCase();
        if (event.getName().equals(DOCUMENTMODIFIED) && 
!newLowerName.equalsIgnoreCase(lowercaseName))
        {
            doc.setProperty(schemaName, lowecaseNameField, newLowerName);
            cs.saveDocument(doc);
        }
        }
    }
}


public abstract class AbstractDocumentEventListener implements EventListener
{
    protected static final Log LOG = 
LogFactory.getLog(AbstractDocumentEventListener.class);

    /**
     * Event handler for created image  
     * @param event - The document events as registered in 
OSGI-INF/event-listener-contrib.xml
     * @throws Exception Failed to process the transformation
     * @throws ClientException Failed to get Session data
     */
    public void handleEvent(Event event) throws ClientException
    {
        EventContext ctx = event.getContext();
        
        if(ctx instanceof DocumentEventContext)
        {
            DocumentEventContext docCtx = (DocumentEventContext)ctx;
            DocumentModel doc = docCtx.getSourceDocument();
            if(doc != null)
            {
                LOG.debug("About to execute event on document of type = " + 
doc.getType() + " in state of " + doc.getCurrentLifeCycleState() + " using 
event listener : " + getClass());
                processEvent(event, doc, ctx.getPrincipal());
            }
            else
            {
                LOG.warn("event source document not found for event:" + 
event.getName());
            }
        }
    }
    
    /**
     * Processes a DocumentContextEvent
     * 
     * @param doc - the target Document
     * @param p - the Principal who triggered the event
     * @throws Exception
     */
    protected abstract void processEvent(Event event, DocumentModel doc, 
Principal p) throws ClientException;
}
--
Posted by "mark" at Nuxeo Discussions <http://nuxeo.org/discussions>
View the complete thread: 
<http://www.nuxeo.org/discussions/thread.jspa?threadID=2809#8132>
_______________________________________________
ECM mailing list
[email protected]
http://lists.nuxeo.com/mailman/listinfo/ecm
To unsubscribe, go to http://lists.nuxeo.com/mailman/options/ecm

Reply via email to