001/* 002 * Copyright (c) 2006-2011 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 * 009 * Contributors: 010 */ 011 012package org.nuxeo.ecm.automation.jsf.operations; 013 014import org.jboss.seam.contexts.Contexts; 015import org.nuxeo.ecm.automation.OperationContext; 016import org.nuxeo.ecm.automation.core.Constants; 017import org.nuxeo.ecm.automation.core.annotations.Context; 018import org.nuxeo.ecm.automation.core.annotations.Operation; 019import org.nuxeo.ecm.automation.core.annotations.OperationMethod; 020import org.nuxeo.ecm.automation.core.annotations.Param; 021import org.nuxeo.ecm.core.api.DocumentModel; 022 023/** 024 * @author <a href="mailto:td@nuxeo.com">Thierry Delprat</a> 025 */ 026@Operation(id = PushToSeamContext.ID, category = Constants.CAT_UI, requires = Constants.SEAM_CONTEXT, label = "Push to Seam Context", description = "Push the current input document into Seam context. Returns back the document.", aliases = { "Seam.PushDocument" }) 027public class PushToSeamContext { 028 029 public static final String ID = "WebUI.PushDocumentToSeamContext"; 030 031 @Context 032 protected OperationContext ctx; 033 034 @Param(name = "name") 035 protected String name; 036 037 @Param(name = "scope", widget = Constants.W_OPTION, values = { "session", "conversation", "page", "event" }) 038 protected String scope; 039 040 @OperationMethod 041 public DocumentModel push(DocumentModel value) { 042 if ("session".equalsIgnoreCase(scope)) { 043 Contexts.getSessionContext().set(name, value); 044 } else if ("conversation".equalsIgnoreCase(scope)) { 045 Contexts.getConversationContext().set(name, value); 046 } else if ("page".equalsIgnoreCase(scope)) { 047 Contexts.getPageContext().set(name, value); 048 } else if ("event".equalsIgnoreCase(scope)) { 049 Contexts.getEventContext().set(name, value); 050 } 051 052 return value; 053 } 054 055}