javax.faces.context.ExternalContext Java Examples

The following examples show how to use javax.faces.context.ExternalContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SyllabusTool.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
public String processAddAttachRedirect()
{
  try
  {
    filePickerList = EntityManager.newReferenceList();
    ToolSession currentToolSession = SessionManager.getCurrentToolSession();
    currentToolSession.setAttribute(FilePickerHelper.FILE_PICKER_ATTACHMENTS, filePickerList);
    ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
    context.redirect("sakai.filepicker.helper/tool");
    if(context.getRequestParameterMap().get("itemId") != null){
  	  currentToolSession.setAttribute(SESSION_ATTACHMENT_DATA_ID, context.getRequestParameterMap().get("itemId"));
    }
    return null;
  }
  catch(Exception e)
  {
    log.error(this + ".processAddAttachRedirect - " + e);
    return null;
  }
}
 
Example #2
Source File: CaptchaValidatorTest.java    From development with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() {
    validator = new CaptchaValidator();
    sessionMock = new HttpSessionStub(Locale.ENGLISH);
    context = new FacesContextStub(Locale.ENGLISH) {
        @Override
        public ExternalContext getExternalContext() {
            ExternalContext exContext = spy(new ExternalContextStub(
                    Locale.ENGLISH));
            doReturn(sessionMock).when(exContext).getSession(false);
            return exContext;
        }
    };

    inputField = new HtmlInputText() {
        @Override
        public String getClientId(FacesContext ctx) {
            return "";
        }
    };
}
 
Example #3
Source File: Headers.java    From softwarecave with GNU General Public License v3.0 6 votes vote down vote up
@PostConstruct
public void init() {
    entries = new ArrayList<>();
    ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
    HttpServletRequest request = (HttpServletRequest) context.getRequest();
    
    Enumeration<String> namesIt = request.getHeaderNames();
    while (namesIt.hasMoreElements()) {
        String name = namesIt.nextElement();
        Enumeration<String> valueIt = request.getHeaders(name);
        while (valueIt.hasMoreElements()) {
            String value = valueIt.nextElement();
            entries.add(new HeaderEntry(name, value));
        }
    }
}
 
Example #4
Source File: MobileRequestCustomizerFactory.java    From XPagesExtensionLibrary with Apache License 2.0 6 votes vote down vote up
private boolean isMobilePage(FacesContext context) {
    ExternalContext o = context.getExternalContext();
    HttpServletRequest r = (javax.servlet.http.HttpServletRequest) o.getRequest();
    String path = r.getServletPath();
    ApplicationEx app = ApplicationEx.getInstance(context);
    String prefix = app.getApplicationProperty(MobileConstants.XSP_THEME_MOBILE_PAGEPREFIX, null);
    if (prefix == null) {
        return false;
    }
    else if (prefix.equals("*")) { // $NON-NLS-1$
        return true;
    }
    else {
        return path.startsWith("/" + prefix); // $NON-NLS-1$
    }
}
 
Example #5
Source File: EmailBean.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
public String addAttachmentsRedirect() {
    try	{
      List filePickerList = new ArrayList();
      if (attachmentList != null){
        filePickerList = prepareReferenceList(attachmentList);
      }
      log.debug("**filePicker list="+filePickerList.size());
      ToolSession currentToolSession = SessionManager.getCurrentToolSession();
      currentToolSession.setAttribute(FilePickerHelper.FILE_PICKER_ATTACHMENTS, filePickerList);
      ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
      context.redirect("sakai.filepicker.helper/tool");
    }
    catch(Exception e){
      log.error("fail to redirect to attachment page: " + e.getMessage());
    }
    return "email";
}
 
Example #6
Source File: ServiceDetailsCtrl.java    From development with Apache License 2.0 6 votes vote down vote up
public String redirectToServiceDetails() {
    logger.logDebug("entering redirectToServiceDetails");
    FacesContext context = FacesContext.getCurrentInstance();
    ExternalContext extContext = context.getExternalContext();
    String viewId = Marketplace.MARKETPLACE_ROOT + "/serviceDetails.jsf";

    try {
        viewId = extContext.getRequestContextPath()
                + viewId
                + ui.getSelectedServiceKeyQueryPart(String.valueOf(model
                        .getSelectedServiceKey()))
                + ui.getMarketplaceIdQueryPart();
        String urlLink = context.getExternalContext().encodeActionURL(
                viewId);
        JSFUtils.redirect(extContext, urlLink);
    } catch (IOException e) {
        extContext.log(
                getClass().getName() + ".redirectToServiceDetails()", e);
    } finally {
        // reset requested key;
        model.setSelectedServiceKey(null);
    }
    return null;
}
 
Example #7
Source File: StatisticsReportingBean.java    From sailfish-core with Apache License 2.0 6 votes vote down vote up
public void getResultsInCSV() {
    logger.info("getResultsInCSV invoked {}", System.getProperty("user.name"));
    try {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        ExternalContext externalContext = facesContext.getExternalContext();
        externalContext.responseReset();
        String reportName = getExportFileName();
        externalContext.setResponseHeader("Content-Disposition", "attachment; filename=\"" + reportName + "\"");
        OutputStream output = externalContext.getResponseOutputStream();
        statisticsReportHandler.writeReport(output);
        facesContext.responseComplete();
    } catch (Exception e) {
        logger.error("Could not export report", e);
        BeanUtil.addErrorMessage("Could not export report", e.getMessage());
    }
}
 
Example #8
Source File: StudentScoresBean.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
public String addAttachmentsRedirect() {
 // 1. redirect to add attachment
 try	{
  List filePickerList = new ArrayList();
  StudentScoresBean studentScoresBean = (StudentScoresBean) ContextUtil.lookupBean("studentScores");
  Long itemGradingId = studentScoresBean.getItemGradingIdForFilePicker();
  DeliveryBean deliveryBean = (DeliveryBean) ContextUtil.lookupBean("delivery");
  ItemContentsBean itemContentsBean = (ItemContentsBean) deliveryBean.getItemContentsMap().get(itemGradingId);
  if (itemContentsBean != null && itemContentsBean.getItemGradingAttachmentList() != null){
	  AttachmentUtil attachmentUtil = new AttachmentUtil();
	  filePickerList = attachmentUtil.prepareReferenceList(itemContentsBean.getItemGradingAttachmentList());
  }
  ToolSession currentToolSession = SessionManager.getCurrentToolSession();
  currentToolSession.setAttribute(FilePickerHelper.FILE_PICKER_ATTACHMENTS, filePickerList);
  
  currentToolSession.setAttribute("itemGradingId", itemGradingId);
  ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
  context.redirect("sakai.filepicker.helper/tool");
 }
 catch(Exception e){
  log.error("fail to redirect to attachment page: " + e.getMessage());
 }
 return "studentScores";
}
 
Example #9
Source File: PostemTool.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
public String processAddAttachRedirect()
	  {
	    try
	    {
	      filePickerList = EntityManager.newReferenceList();
	      ToolSession currentToolSession = SessionManager.getCurrentToolSession();
	      currentToolSession.setAttribute("filepicker.attach_cardinality",FilePickerHelper.CARDINALITY_SINGLE);	      
	      currentToolSession.setAttribute(FilePickerHelper.FILE_PICKER_ATTACHMENTS, filePickerList);
	      ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
	      context.redirect("sakai.filepicker.helper/tool");
	      return null;
}
	    catch(Exception e)
	    {
	      log.error(this + ".processAddAttachRedirect - " + e);
	      return null;
	    }
	  }
 
Example #10
Source File: WindowScopeTest.java    From joinfaces with Apache License 2.0 6 votes vote down vote up
@BeforeEach
public void setUp() throws MalformedURLException {
	FacesContext facesContext = FacesContextMocker.mockFacesContext();
	ExternalContext externalContext = mock(ExternalContext.class);
	when(facesContext.getExternalContext()).thenReturn(externalContext);
	when(externalContext.getResource("/WEB-INF/portlet.xml")).thenReturn(null);
	Application application = mock(Application.class);
	when(facesContext.getApplication()).thenReturn(application);

	this.scopeMap = new WindowScopeManager.ScopeMap(FacesContext.getCurrentInstance());

	this.windowScope = new WindowScope() {
		@Override
		@NonNull
		WindowScopeManager.ScopeMap getScopeMap() {
			return WindowScopeTest.this.scopeMap;
		}
	};
}
 
Example #11
Source File: FacesWebRequest.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public String getDescription(boolean includeClientInfo) {
	ExternalContext externalContext = getExternalContext();
	StringBuilder sb = new StringBuilder();
	sb.append("context=").append(externalContext.getRequestContextPath());
	if (includeClientInfo) {
		Object session = externalContext.getSession(false);
		if (session != null) {
			sb.append(";session=").append(getSessionId());
		}
		String user = externalContext.getRemoteUser();
		if (StringUtils.hasLength(user)) {
			sb.append(";user=").append(user);
		}
	}
	return sb.toString();
}
 
Example #12
Source File: WebApplicationContextUtils.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public static void registerFacesDependencies(ConfigurableListableBeanFactory beanFactory) {
	beanFactory.registerResolvableDependency(FacesContext.class, new ObjectFactory<FacesContext>() {
		@Override
		public FacesContext getObject() {
			return FacesContext.getCurrentInstance();
		}
		@Override
		public String toString() {
			return "Current JSF FacesContext";
		}
	});
	beanFactory.registerResolvableDependency(ExternalContext.class, new ObjectFactory<ExternalContext>() {
		@Override
		public ExternalContext getObject() {
			return FacesContext.getCurrentInstance().getExternalContext();
		}
		@Override
		public String toString() {
			return "Current JSF ExternalContext";
		}
	});
}
 
Example #13
Source File: JsfUtils.java    From deltaspike with Apache License 2.0 6 votes vote down vote up
public static Set<RequestParameter> getViewConfigPageParameters()
{
    ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();

    Set<RequestParameter> result = new HashSet<RequestParameter>();

    if (externalContext == null || //detection of early config for different mojarra versions
            externalContext.getRequestParameterValuesMap() == null || externalContext.getRequest() == null)
    {
        return result;
    }

    NavigationParameterContext navigationParameterContext =
            BeanProvider.getContextualReference(NavigationParameterContext.class);

    for (Map.Entry<String, String> entry : navigationParameterContext.getPageParameters().entrySet())
    {
        //TODO add multi-value support
        result.add(new RequestParameter(entry.getKey(), new String[]{entry.getValue()}));
    }

    return result;
}
 
Example #14
Source File: ValidatorUtil.java    From ctsms with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static boolean skipValidation(final FacesContext context) {
	final ExternalContext externalContext = context.getExternalContext();
	final Object validate = externalContext.getRequestMap().get(GetParamNames.VALIDATE.toString());
	if (validate != null) {
		return !(Boolean) validate;
	}
	Iterator<Entry<String, String[]>> parameterValuesIt = externalContext.getRequestParameterValuesMap()
			.entrySet().iterator();
	while (parameterValuesIt.hasNext()) {
		Entry<String, String[]> parameterValues = parameterValuesIt.next();
		final String key = parameterValues.getKey();
		Iterator<String> idPrefixIt = VALIDATION_REQUIRED_COMPONENT_ID_PREFIXES.iterator();
		while (idPrefixIt.hasNext()) {
			String idPrefix = idPrefixIt.next();
			if (key.contains(idPrefix)) {
				externalContext.getRequestMap().put(GetParamNames.VALIDATE.toString(), Boolean.TRUE);
				return false;
			}
		}
	}
	externalContext.getRequestMap().put(GetParamNames.VALIDATE.toString(), Boolean.FALSE);
	return true;
}
 
Example #15
Source File: FormViewer.java    From yawl with GNU Lesser General Public License v3.0 6 votes vote down vote up
/** takes necessary action after editing a custom form */
private String postCustomForm(WorkItemRecord wir) {
    String result = "<success/>";

    // reset session timeout if previously changed
    if (_sb.isSessionTimeoutValueChanged()) {
        _sb.resetSessionTimeout();
        _sb.setSessionTimeoutValueChanged(false);
    }

    // retrieve completion flag - if any
    ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
    HttpServletRequest request = (HttpServletRequest) context.getRequest();
    String complete = request.getParameter("complete");

    // complete wir if requested
    if ((complete != null) && complete.equalsIgnoreCase("true")) {
        result = completeWorkItem(wir);
    }
    return result;
}
 
Example #16
Source File: AgentResults.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
public String addAssessmentAttachmentsRedirect() {
 // 1. redirect to add attachment
 try	{
  List<Reference> filePickerList = new ArrayList<>();
  if (assessmentGradingAttachmentList != null){
	  AttachmentUtil attachmentUtil = new AttachmentUtil();
	  filePickerList = attachmentUtil.prepareReferenceList(assessmentGradingAttachmentList);
  }
  ToolSession currentToolSession = SessionManager.getCurrentToolSession();
  currentToolSession.setAttribute(FilePickerHelper.FILE_PICKER_ATTACHMENTS, filePickerList);
  
  currentToolSession.setAttribute("assessmentGradingId", assessmentGradingId);
  ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
  context.redirect("sakai.filepicker.helper/tool");
 }
 catch(Exception e){
  log.error("fail to redirect to attachment page: " + e.getMessage());
 }
 return "sakai.filepicker.helper";
}
 
Example #17
Source File: ClientWindowHelper.java    From deltaspike with Apache License 2.0 6 votes vote down vote up
/**
 * Handles the initial redirect for the LAZY mode, if no windowId is available in the current request URL.
 *
 * @param facesContext the {@link FacesContext}
 * @param newWindowId the new windowId
 */
public static void handleInitialRedirect(FacesContext facesContext, String newWindowId)
{        
    // store the new windowId as context attribute to prevent infinite loops
    // #sendRedirect will append the windowId (from ClientWindow#getWindowId again) to the redirectUrl
    facesContext.getAttributes().put(INITIAL_REDIRECT_WINDOW_ID, newWindowId);

    ExternalContext externalContext = facesContext.getExternalContext();

    String url = constructRequestUrl(externalContext);

    // remember the initial redirect windowId till the next request - see #729
    addRequestWindowIdCookie(facesContext, newWindowId, newWindowId);

    try
    {
        externalContext.redirect(url);
    }
    catch (IOException e)
    {
        throw new FacesException("Could not send initial redirect!", e);
    }
}
 
Example #18
Source File: ProductsDAO.java    From primefaces-blueprints with The Unlicense 6 votes vote down vote up
public List<Product> getAllProducts(int first, int pageSize,
		String sortField, String sortOrderValue, Map<String, Object> filters) {
	Session session = getSession();// sessionFactory.openSession();
	session.beginTransaction();

	ExternalContext externalContext = FacesContext.getCurrentInstance()
			.getExternalContext();
	Map<String, Object> sessionMap = externalContext.getSessionMap();
	productCategory = (String) sessionMap.get("productCategory");
	String query = null;
	
	Query queryResult=null;
	if (productCategory != "") {
		query = "from Product where prodcat = :productCategory ORDER BY "+sortField+" "+sortOrderValue;
		queryResult = session.createQuery(query);
		queryResult.setParameter("productCategory", productCategory);
	} else {
		query = "from Product ORDER BY "+sortField+" "+sortOrderValue;
	    queryResult = session.createQuery(query);
	}
	List<Product> allProducts = queryResult.list();
	session.getTransaction().commit();
	return allProducts;

}
 
Example #19
Source File: SyllabusTool.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
public String processDeleteAttach() {
  ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
  String attachId = null;
  
  Map paramMap = context.getRequestParameterMap();
  Iterator itr = paramMap.keySet().iterator();
  while(itr.hasNext()) {
    Object key = itr.next();
    if( key instanceof String && "syllabus_current_attach".equals((String) key)) {
        attachId = (String) paramMap.get(key);
        break;
    }
  }

  removeAttachId = attachId;

  if (StringUtils.isNotBlank(removeAttachId)) {
    return "remove_attach_confirm";
  } else {
    return null;
  }

}
 
Example #20
Source File: StudentScoresBean.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
public String addAttachmentsRedirect() {
 // 1. redirect to add attachment
 try	{
  List filePickerList = new ArrayList();
  StudentScoresBean studentScoresBean = (StudentScoresBean) ContextUtil.lookupBean("studentScores");
  Long itemGradingId = studentScoresBean.getItemGradingIdForFilePicker();
  DeliveryBean deliveryBean = (DeliveryBean) ContextUtil.lookupBean("delivery");
  ItemContentsBean itemContentsBean = (ItemContentsBean) deliveryBean.getItemContentsMap().get(itemGradingId);
  if (itemContentsBean != null && itemContentsBean.getItemGradingAttachmentList() != null){
	  AttachmentUtil attachmentUtil = new AttachmentUtil();
	  filePickerList = attachmentUtil.prepareReferenceList(itemContentsBean.getItemGradingAttachmentList());
  }
  ToolSession currentToolSession = SessionManager.getCurrentToolSession();
  currentToolSession.setAttribute(FilePickerHelper.FILE_PICKER_ATTACHMENTS, filePickerList);
  
  currentToolSession.setAttribute("itemGradingId", itemGradingId);
  ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
  context.redirect("sakai.filepicker.helper/tool");
 }
 catch(Exception e){
  log.error("fail to redirect to attachment page: " + e.getMessage());
 }
 return "studentScores";
}
 
Example #21
Source File: SkinBeanTest.java    From development with Apache License 2.0 5 votes vote down vote up
@Before
public void before() {
    // mock the BrandService' get getMarketplaceStage() method
    brandServiceMock = mock(BrandService.class);
    when(brandServiceMock.getMarketplaceStage(anyString(), anyString()))
            .thenReturn(stageContent);

    // mock the HttpSession's getAttribute() method
    httpSessionMock = mock(HttpSession.class);
    when(httpSessionMock.getAttribute(anyString())).thenReturn(null);

    // mock the HttpServletRequest's getSession() method
    HttpServletRequest httpServletRequestMock = mock(HttpServletRequest.class);
    when(httpServletRequestMock.getSession()).thenReturn(httpSessionMock);

    // mock the ExternalContext's getRequest() method
    ExternalContext externalContextMock = mock(ExternalContext.class);
    when(externalContextMock.getRequest()).thenReturn(
            httpServletRequestMock);

    // mock the UIViewRoot's getLocale() method
    viewRootMock = mock(UIViewRoot.class);
    when(viewRootMock.getLocale()).thenReturn(Locale.FRANCE);

    // mock the FacesContext's getExternalContext() and getViewRoot()
    // methods
    final FacesContext facesContextMock = mock(FacesContext.class);
    when(facesContextMock.getExternalContext()).thenReturn(
            externalContextMock);
    when(facesContextMock.getViewRoot()).thenReturn(viewRootMock);

    // spy the SkinBean to only partial mock - overriding the methods below
    skinBean = spy(new SkinBean());
    doReturn(brandServiceMock).when(skinBean).getBrandManagementService();
    doReturn(facesContextMock).when(skinBean).getFacesContext();
    doReturn(httpServletRequestMock).when(skinBean).getRequest();
}
 
Example #22
Source File: JMeterBean.java    From kieker with Apache License 2.0 5 votes vote down vote up
@PostConstruct
public void init() {
	final ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();

	final String bin = context.getRealPath("WEB-INF/bin/");
	System.setProperty("user.dir", bin);
	final String testplan = context.getRealPath("WEB-INF/bin/Testplan.jmx");

	this.arguments = new String[] { "-n", "-t", testplan };
}
 
Example #23
Source File: FacesRequestAttributes.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
public static String[] getAttributeNames(ExternalContext externalContext) {
	Object session = externalContext.getSession(false);
	if (session instanceof PortletSession) {
		return StringUtils.toStringArray(
				((PortletSession) session).getAttributeNames(PortletSession.APPLICATION_SCOPE));
	}
	else if (session != null) {
		return StringUtils.toStringArray(externalContext.getSessionMap().keySet());
	}
	else {
		return new String[0];
	}
}
 
Example #24
Source File: FacesRequestAttributes.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
public static void removeAttribute(String name, ExternalContext externalContext) {
	Object session = externalContext.getSession(false);
	if (session instanceof PortletSession) {
		((PortletSession) session).removeAttribute(name, PortletSession.APPLICATION_SCOPE);
	}
	else if (session != null) {
		externalContext.getSessionMap().remove(name);
	}
}
 
Example #25
Source File: ServerUtil.java    From oxAuth with MIT License 5 votes vote down vote up
/**
 * Safe retrieves http request from FacesContext
 *
 * @return http
 */
public static HttpServletRequest getRequestOrNull() {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    if (facesContext == null)
        return null;

    ExternalContext externalContext = facesContext.getExternalContext();
    if (externalContext == null)
        return null;
    Object request = externalContext.getRequest();
    if (request == null || !(request instanceof HttpServletRequest))
        return null;
    return (HttpServletRequest) request;
}
 
Example #26
Source File: MessageForumsNavigationHandler.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * Handle the navigation
 * 
 * @param context
 *        The Faces context.
 * @param fromAction
 *        The action string that triggered the action.
 * @param outcome
 *        The logical outcome string, which is the new tool mode, or if null, the mode does not change.
 */
public void handleNavigation(FacesContext context, String fromAction, String outcome)
{
	m_chain.handleNavigation(context, fromAction, outcome);		
	
	ExternalContext exContext = context.getExternalContext();
   HttpSession session = (HttpSession) exContext.getSession(false);

   if (session == null){
     return;
   }
	
	// add previous navigationString (outcome) to session
	session.setAttribute("MC_PREVIOUS_NAV", outcome);
}
 
Example #27
Source File: JsfUtils.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
public static void saveFacesMessages(ExternalContext externalContext)
{
    JsfModuleConfig jsfModuleConfig = BeanProvider.getContextualReference(JsfModuleConfig.class);

    if (!jsfModuleConfig.isAlwaysKeepMessages())
    {
        return;
    }

    try
    {
        WindowMetaData windowMetaData = BeanProvider.getContextualReference(WindowMetaData.class);

        Map<String, Object> requestMap = externalContext.getRequestMap();

        @SuppressWarnings({ "unchecked" })
        List<FacesMessageEntry> facesMessageEntryList =
                (List<FacesMessageEntry>)requestMap.get(FacesMessageEntry.class.getName());

        if (facesMessageEntryList == null)
        {
            facesMessageEntryList = new CopyOnWriteArrayList<FacesMessageEntry>();
        }
        windowMetaData.setFacesMessageEntryList(facesMessageEntryList);
    }
    catch (ContextNotActiveException e)
    {
        //TODO log it in case of project-stage development
        //we can't handle it correctly -> delegate to the jsf-api (which has some restrictions esp. before v2.2)
        FacesContext.getCurrentInstance().getExternalContext().getFlash().setKeepMessages(true);
    }
}
 
Example #28
Source File: BrandBeanTest.java    From development with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    new FacesContextStub(Locale.ENGLISH) {
        @Override
        public void addMessage(String arg0, FacesMessage arg1) {
            facesMessages.add(arg1);
        }
    };

    brandBean = spy(new BrandBean());
    marketplaceBean = spy(new MarketplaceBean());
    MenuBean menuBean = new MenuBean();
    marketplaceBean.setMenuBean(menuBean);

    brandBean.setMarketplaceBean(marketplaceBean);
    brandBean.setMarketplaceId("FUJITSU");

    // Mock the faces context of the brandBean
    FacesContext fcContextMock = mock(FacesContext.class);
    doReturn(fcContextMock).when(brandBean).getFacesContext();

    // Mock the external context of the faces context
    extContextMock = mock(ExternalContext.class);
    doReturn(extContextMock).when(fcContextMock).getExternalContext();

    // Mock the path of the white label
    doReturn(WHITE_LABEL_PATH).when(extContextMock).getRequestContextPath();

    // Mock the input stream of the external context
    InputStream inMock = new ByteArrayInputStream(brandingPackageData);
    doReturn(inMock).when(extContextMock).getResourceAsStream(anyString());

    // Mock the brand service
    marketplaceServiceMock = mock(MarketplaceService.class);
    doReturn(marketplaceServiceMock).when(brandBean)
            .getMarketplaceService();
    doReturn(marketplaceServiceMock).when(marketplaceBean)
            .getMarketplaceService();
    brandBean.setMarketplaceBean(marketplaceBean);
}
 
Example #29
Source File: ApplicationBean.java    From yawl with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void redirect(String uri) {
    try {
        ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
        if (context != null) {
            context.redirect(uri);
        }
    } catch (IOException ioe) {
        // nothing to do
    }
}
 
Example #30
Source File: PrivateMessagesTool.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public String processAddAttachmentRedirect()
{
  log.debug("processAddAttachmentRedirect()");
  try
  {
    ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
    context.redirect("sakai.filepicker.helper/tool");
    return null;
  }
  catch(Exception e)
  {
    log.debug("processAddAttachmentRedirect() - Exception");
    return null;
  }
}