@SuppressWarnings("deprecation")
  public void uploadAttachments(ActionEvent actionEvent) {

    List<UploadedFile> uploadedFiles = applicantModelBean.getUploadedFiles();

    UploadedFile uploadedFile1 = attachment1.getUploadedFile();

    if (uploadedFile1 != null) {
      uploadedFiles.add(uploadedFile1);
      logger.debug("uploadedFile1=[{0}]", uploadedFile1.getName());
    }

    UploadedFile uploadedFile2 = attachment2.getUploadedFile();

    if (uploadedFile2 != null) {
      uploadedFiles.add(uploadedFile2);
      logger.debug("uploadedFile2=[{0}]", uploadedFile2.getName());
    }

    UploadedFile uploadedFile3 = attachment3.getUploadedFile();

    if (uploadedFile3 != null) {
      uploadedFiles.add(uploadedFile3);
      logger.debug("uploadedFile3=[{0}]", uploadedFile3.getName());
    }

    applicantViewBean.setFileUploaderRendered(false);
  }
  public void deleteUploadedFile(ActionEvent actionEvent) {

    try {
      List<UploadedFile> uploadedFiles = applicantModelBean.getUploadedFiles();

      String uploadedFileId = applicantViewBean.getUploadedFileId();

      UploadedFile uploadedFileToDelete = null;

      for (UploadedFile uploadedFile : uploadedFiles) {

        if (uploadedFile.getId().equals(uploadedFileId)) {
          uploadedFileToDelete = uploadedFile;

          break;
        }
      }

      if (uploadedFileToDelete != null) {
        uploadedFileToDelete.delete();
        uploadedFiles.remove(uploadedFileToDelete);
        logger.debug("Deleted file=[{0}]", uploadedFileToDelete.getName());
      }
    } catch (Exception e) {
      logger.error(e);
    }
  }
  @Override
  public void endElement(String name) throws IOException {

    try {
      ElementWriter elementWriter = elementWriterStack.pop();
      Element element = elementWriter.getElement();
      String nodeName = element.getNodeName();
      logger.trace("POPPED element name=[{0}]", nodeName);

      if (!StringPool.HEAD.equals(nodeName)) {

        // NOTE: The Portlet 2.0 Javadocs for the addProperty method indicate that if the key
        // already exists,
        // then the element will be added to any existing elements under that key name. There is a
        // risk that
        // multiple portlet instances on the same portal page could cause multiple <script />
        // elements to be
        // added to the <head>...</head> section of the rendered portal page. See:
        // http://portals.apache.org/pluto/portlet-2.0-apidocs/javax/portlet/PortletResponse.html#addProperty(java.lang.String,
        // org.w3c.dom.Element)
        portletResponse.addProperty(MimeResponse.MARKUP_HEAD_ELEMENT, element);
        logger.debug(
            "Added resource to portal's <head>...</head> section nodeName=[{0}]", nodeName);
      }
    } catch (EmptyStackException e) {
      throw new IOException(EmptyStackException.class.getSimpleName());
    }
  }
  @Override
  public void execute() throws BridgeException {

    logger.debug(Logger.SEPARATOR);
    logger.debug(
        "execute(RenderRequest, RenderResponse) portletName=[{0}] portletMode=[{1}]",
        portletName, renderRequest.getPortletMode());

    Object renderPartAttribute = renderRequest.getAttribute(RenderRequest.RENDER_PART);

    if ((renderPartAttribute != null) && renderPartAttribute.equals(RenderRequest.RENDER_HEADERS)) {
      doFacesHeaders(renderRequest, renderResponse);
    } else {

      try {
        execute(null);
      } catch (BridgeException e) {
        throw e;
      } catch (Throwable t) {
        throw new BridgeException(t);
      } finally {
        cleanup(renderRequest);
      }

      logger.debug(Logger.SEPARATOR);
    }
  }
  public void deleteUploadedFile(ActionEvent actionEvent) {

    String fileId =
        (String)
            FacesContext.getCurrentInstance()
                .getExternalContext()
                .getRequestParameterMap()
                .get("fileId");

    try {
      List<UploadedFile> uploadedFiles = applicantModelBean.getUploadedFiles();

      UploadedFile uploadedFileToDelete = null;

      for (UploadedFile uploadedFile : uploadedFiles) {

        if (uploadedFile.getId().equals(fileId)) {
          uploadedFileToDelete = uploadedFile;

          break;
        }
      }

      if (uploadedFileToDelete != null) {
        File file = new File(uploadedFileToDelete.getAbsolutePath());
        file.delete();
        uploadedFiles.remove(uploadedFileToDelete);
        logger.debug("Deleted file=[{0}]", file);
      }
    } catch (Exception e) {
      logger.error(e);
    }
  }
  public void handleFileUpload(FileUploadEvent fileUploadEvent) {

    List<UploadedFile> uploadedFiles = bridgeInputFileModelBean.getUploadedFiles();
    UploadedFile uploadedFile = fileUploadEvent.getUploadedFile();

    if (uploadedFile.getStatus() == UploadedFile.Status.FILE_SAVED) {

      FacesContext facesContext = FacesContext.getCurrentInstance();
      FacesMessage facesMessage =
          new FacesMessage(
              "Received fileUploadEvent for file named '"
                  + uploadedFile.getName()
                  + "' in the "
                  + fileUploadEvent.getPhaseId().toString()
                  + " phase.");
      facesContext.addMessage(null, facesMessage);
      uploadedFiles.add(uploadedFile);
      logger.debug(
          "Received fileName=[{0}] absolutePath=[{1}]",
          uploadedFile.getName(), uploadedFile.getAbsolutePath());
    } else {
      logger.error(
          "Failed to receive uploaded file due to error status=[{0}] message=[{1}]",
          uploadedFile.getStatus(), uploadedFile.getMessage());
    }
  }
  public WebConfig scan() throws IOException {

    // Parse the Servlet 3.0 META-INF/web-fragment.xml descriptor files found in the classpath.
    Enumeration<URL> webFragmentURLs = classLoader.getResources(WEB_FRAGMENT_META_INF_PATH);

    WebConfig webConfig = new WebConfigImpl();

    InputStream inputStream = null;

    if (webFragmentURLs != null) {

      while (webFragmentURLs.hasMoreElements()) {
        URL webFragmentURL = webFragmentURLs.nextElement();
        inputStream = webFragmentURL.openStream();

        WebConfigParser webConfigParser = newWebConfigParser();

        try {
          webConfig = webConfigParser.parse(inputStream, webConfig);
          inputStream.close();
        } catch (Exception e) {
          logger.error(e.getMessage());
        }
      }
    }

    // Parse the WEB-INF/web.xml descriptor.
    inputStream = resourceReader.getResourceAsStream(WEB_XML_PATH);

    if (inputStream != null) {
      logger.debug("Processing web-app: [{0}]", WEB_XML_PATH);

      WebConfigParser webConfigParser = newWebConfigParser();

      try {
        webConfig = webConfigParser.parse(inputStream, webConfig);
      } catch (IOException e) {
        logger.error(e);
        throw new IOException(e.getMessage());
      }
    }

    // Parse the WEB-INF/liferay-web.xml descriptor.
    inputStream = resourceReader.getResourceAsStream(WEB_XML_LIFERAY_PATH);

    if (inputStream != null) {
      logger.debug("Processing web-app: [{0}]", WEB_XML_LIFERAY_PATH);

      WebConfigParser webConfigParser = newWebConfigParser();

      try {
        webConfigParser.parse(inputStream, webConfig);
      } catch (IOException e) {
        logger.error(e);
        throw new IOException(e.getMessage());
      }
    }

    return webConfig;
  }
  @Override
  protected Object resolveVariable(ELContext elContext, String varName) {

    Object value = null;

    try {

      if (varName.equals(VAR_NAME_I18N)) {

        if (i18n == null) {
          i18n = new I18N();
        }

        value = i18n;
      }
    } catch (Exception e) {
      throw new ELException("Failed to resolve variable [" + varName + "]", e);
    }

    if (value == null) {

      if (logger.isDebugEnabled()) {
        logger.debug("Unable to resolve variable [" + varName + "] value=" + value);
      }
    } else {

      if (logger.isDebugEnabled()) {
        logger.debug("Resolved variable [" + varName + "] value=" + value);
      }
    }

    return value;
  }
  public void deleteUploadedFile(ActionEvent actionEvent) {

    UICommand uiCommand = (UICommand) actionEvent.getComponent();
    String fileId = (String) uiCommand.getValue();

    try {
      List<UploadedFile> uploadedFiles = htmlInputFileModelBean.getUploadedFiles();

      UploadedFile uploadedFileToDelete = null;

      for (UploadedFile uploadedFile : uploadedFiles) {

        if (uploadedFile.getId().equals(fileId)) {
          uploadedFileToDelete = uploadedFile;

          break;
        }
      }

      if (uploadedFileToDelete != null) {
        uploadedFileToDelete.delete();
        uploadedFiles.remove(uploadedFileToDelete);
        logger.debug("Deleted file=[{0}]", uploadedFileToDelete.getName());
      }
    } catch (Exception e) {
      logger.error(e);
    }
  }
  /**
   * This method is called after an attribute is added to the ServletRequest. Note that this should
   * only get called for remote WSRP portlets. For more info, see:
   * http://issues.liferay.com/browse/FACES-146
   */
  public void attributeAdded(ServletRequestAttributeEvent servletRequestAttributeEvent) {

    // NOTE: We only care about phases prior to the RENDER_PHASE because we're concerned here about
    // managed beans
    // that get added to the request scope when the BridgeRequestScope begins. We're trying to
    // provide those managed
    // beans with an opportunity to prepare for an unexpected invocation of their methods annotated
    // with
    // @PreDestroy.
    ServletRequest servletRequest = servletRequestAttributeEvent.getServletRequest();
    PortletPhase phase = (PortletPhase) servletRequest.getAttribute(Bridge.PORTLET_LIFECYCLE_PHASE);

    // If this is taking place within a PortletRequest handled by the bridge in any phase prior to
    // the
    // RENDER_PHASE, then
    if ((phase != null) && (phase != PortletPhase.RENDER_PHASE)) {

      // If the attribute being added is not excluded, then invoke all methods on the attribute
      // value (class
      // instance) that are annotated with the BridgeRequestScopeAttributeAdded annotation.
      String attributeName = servletRequestAttributeEvent.getName();
      BridgeContext bridgeContext = BridgeContext.getCurrentInstance();
      BridgeConfig bridgeConfig = bridgeContext.getBridgeConfig();
      Set<String> excludedRequestScopeAttributes = bridgeConfig.getExcludedRequestAttributes();

      if (!excludedRequestScopeAttributes.contains(attributeName)) {

        Object attributeValue = servletRequestAttributeEvent.getValue();
        logger.trace("Attribute added name=[{0}] value=[{1}]", attributeName, attributeValue);

        if (attributeValue != null) {
          Method[] methods = attributeValue.getClass().getMethods();

          if (methods != null) {

            for (Method method : methods) {

              if (method != null) {

                if (method.isAnnotationPresent(BridgeRequestScopeAttributeAdded.class)) {

                  try {
                    method.invoke(attributeValue, new Object[] {});
                  } catch (Exception e) {
                    logger.error(e);
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  public void afterPhase(PhaseEvent phaseEvent) {

    // This method just does some logging. It's useful to the developer to determine if a
    // navigation-rule
    // fired, causing new JSF view to be restored after the INVOKE_APPLICATION phase finished.
    if (logger.isDebugEnabled() && (phaseEvent.getPhaseId() == PhaseId.INVOKE_APPLICATION)) {
      FacesContext facesContext = phaseEvent.getFacesContext();
      String viewId = facesContext.getViewRoot().getViewId();
      logger.debug("After INVOKE_APPLICATION: viewId=[{0}]", viewId);
    }
  }
  static {

    // Set the value of the LIFERAY_ATTRIBUTE_NAMES constant. Need to use reflection in order to
    // determine all of
    // the public constants because different versions of the portal source have different sets of
    // constants. This
    // approach minimizes diffs in the different source branches for the bridge.
    List<String> fieldList = new ArrayList<String>();
    Field[] fields = JavaConstants.class.getFields();

    for (Field field : fields) {

      String fieldName = field.getName();

      if ((fieldName != null) && fieldName.startsWith("JAVAX")) {

        try {
          Object value = field.get(null);

          if ((value != null) && (value instanceof String)) {
            fieldList.add((String) value);
          }
        } catch (Exception e) {
          logger.error(e);
        }
      }
    }

    LIFERAY_ATTRIBUTE_NAMES = fieldList.toArray(new String[fieldList.size()]);
  }
  /**
   * @see {@link ExternalContext#getResponseOutputStream()}
   * @since JSF 2.0
   */
  @Override
  public OutputStream getResponseOutputStream() throws IOException {

    if (portletResponse instanceof MimeResponse) {

      if (facesImplementationServletResponse != null) {
        logger.debug(
            "Delegating to AFTER_VIEW_CONTENT servletResponse=[{0}]",
            facesImplementationServletResponse);

        return facesImplementationServletResponse.getOutputStream();
      } else {
        MimeResponse mimeResponse = (MimeResponse) portletResponse;

        return mimeResponse.getPortletOutputStream();
      }
    } else {

      if (manageIncongruities) {
        return incongruityContext.getResponseOutputStream();
      } else {
        throw new IllegalStateException();
      }
    }
  }
  protected void indicateNamespacingToConsumers(
      UIViewRoot uiViewRoot, PortletResponse portletResponse) {

    if (uiViewRoot != null) {

      // This method helps satisfy the namespacing requirements of Section 6.6 of the specification.
      // It might be
      // the case that the consumer (portal engine / portlet container) needs to know if all of the
      // form fields
      // have been namespaced properly. If that's the case, then it can check for the existence of
      // the
      // "X-JAVAX-PORTLET-FACES-NAMESPACED-RESPONSE" property on the response, which will be set to
      // "true" if the
      // UIViewRoot is annotated with {@link PortletNamingContainer}.
      if (uiViewRoot.getClass().getAnnotation(PortletNamingContainer.class) != null) {
        portletResponse.addProperty(
            Bridge.PORTLET_NAMESPACED_RESPONSE_PROPERTY, Boolean.TRUE.toString());
      }
    } else {

      // http://issues.liferay.com/browse/FACES-267 Sometimes there are requests that the bridge may
      // see as valid
      // ResourceRequests (e.g. related to Ajax Push) where a ViewRoot might not be available --
      // this is not an
      // error.
      logger.debug("UIViewRoot is null -- might be push related");
    }
  }
  @Override
  public String getFirst(Object key) {

    String firstValue = null;

    if (key != null) {

      String[] values = get(key);

      if (values == null) {
        values = get(namespace + key);
      }

      if ((values != null) && (values.length > 0)) {
        firstValue = values[0];
      }

      if (firstValue == null) {
        firstValue = getSpecialParameterValue(key.toString());
      }

      if (firstValue != null) {
        firstValue = portletContainer.fixRequestParameterValue(firstValue);
      }
    }

    logger.trace("{0}=[{1}]", key, firstValue);

    return firstValue;
  }
  /**
   * This method is called before the {@link PhaseId#RENDER_RESPONSE} phase of the JSF lifecycle is
   * executed. The purpose of this timing is to pick up where the {@link
   * #beforeInvokeApplicationPhase(PhaseEvent)} method left off. It might be the case that a
   * navigation-rule has fired and a NEW JSF view has been loaded up after the {@link
   * PhaseId#APPLY_REQUEST_VALUES} phase (in the case of immediate="true") or the {@link
   * PhaseId#INVOKE_APPLICATION} phase (in the case of immediate="false") has completed. If this is
   * the case, then the list of head resourceIds in the {@link HeadManagedBean} needs to be
   * repopulated from the list found in the Flash scope.
   */
  protected void beforeAjaxifiedRenderResponsePhase(PhaseEvent phaseEvent) {
    FacesContext facesContext = phaseEvent.getFacesContext();
    Flash flash = facesContext.getExternalContext().getFlash();
    String viewId = facesContext.getViewRoot().getViewId();

    @SuppressWarnings("unchecked")
    Set<String> headResourceIdsFromFlash = (Set<String>) flash.get(HEAD_RESOURCE_IDS);

    if (headResourceIdsFromFlash != null) {

      HeadManagedBean headManagedBean = HeadManagedBean.getInstance(facesContext);

      if (headManagedBean != null) {

        Set<String> managedBeanResourceIds = headManagedBean.getHeadResourceIds();

        for (String resourceIdFromFlash : headResourceIdsFromFlash) {

          if (!managedBeanResourceIds.contains(resourceIdFromFlash)) {
            managedBeanResourceIds.add(resourceIdFromFlash);
            logger.debug(
                "Added resourceId=[{0}] from the Flash scope to the list of resourceIds in the HeadManagedBean for viewId=[{1}]",
                resourceIdFromFlash, viewId);
          }
        }
      }
    }
  }
  public void encodeCleanup(FacesContext facesContext, UIComponent uiComponent) throws IOException {

    PortletResponse portletResponse =
        (PortletResponse) facesContext.getExternalContext().getResponse();
    String namespace = portletResponse.getNamespace();

    String editorName = uiComponent.getParent().getParent().getClientId();
    StringBuilder scriptBuilder = new StringBuilder();

    // Build up a JavaScript fragment that will cleanup the DOM.
    scriptBuilder.append("var oldEditor = CKEDITOR.instances['");
    scriptBuilder.append(namespace);
    scriptBuilder.append(editorName);
    scriptBuilder.append("']; if (oldEditor) {");
    scriptBuilder.append("oldEditor.destroy(true);");
    scriptBuilder.append("delete window['");
    scriptBuilder.append(namespace);
    scriptBuilder.append(editorName);
    scriptBuilder.append("'];");
    scriptBuilder.append("}");

    String script = scriptBuilder.toString();

    LiferayFacesContext liferayFacesContext = LiferayFacesContext.getInstance();
    liferayFacesContext.getJavaScriptMap().put(editorName, script);

    logger.trace(script);
  }
Exemplo n.º 18
0
  @Override
  public String getRequestCharacterEncoding() {

    if (portletRequest instanceof ClientDataRequest) {
      ClientDataRequest clientDataRequest = (ClientDataRequest) portletRequest;
      String requestCharacterEncoding = clientDataRequest.getCharacterEncoding();

      if (manageIncongruities) {

        try {
          incongruityContext.setRequestCharacterEncoding(requestCharacterEncoding);
        } catch (Exception e) {
          logger.error(e);
        }
      }

      return requestCharacterEncoding;
    } else {

      if (manageIncongruities) {
        return incongruityContext.getRequestCharacterEncoding();
      } else {

        // The Mojarra 2.x {@link MultiViewHandler#initView(FacesContext)} method expects a null
        // value to be
        // returned, so throwing an IllegalStateException is not an option.
        return null;
      }
    }
  }
  @Override
  public void setAttribute(String name, Object value) {

    Object wrappedRequest = getRequest();

    if (wrappedRequest.getClass().getName().equals(NAMESPACE_SERVLET_REQUEST_FQCN)) {

      try {

        // Calling NameSpaceServletRequest.setAttribute(String, Object, false) instead of
        // NameSpaceServletRequest.setAttribute(String, Object) will prevent the attribute name from
        // getting
        // prefixed with the response namespace. The method must be called reflectively since the
        // NameSpaceServletRequest is packaged in portal-impl.jar and is not available at
        // compile-time.
        Method method =
            wrappedRequest
                .getClass()
                .getMethod("setAttribute", String.class, Object.class, boolean.class);
        method.invoke(wrappedRequest, name, value, false);
      } catch (Exception e) {
        logger.error(e);
      }
    } else {
      super.setAttribute(name, value);
    }
  }
Exemplo n.º 20
0
  protected void encodeAlign(ResponseWriter responseWriter, Popover popover, boolean first)
      throws IOException {

    encodeNonEscapedObject(responseWriter, ALIGN, "", first);
    responseWriter.write("{");

    String for_ = popover.getFor();
    encodeClientId(responseWriter, NODE, for_, popover, true);
    responseWriter.write("}");

    UIComponent forComponent = popover.findComponent(for_);

    if (forComponent != null) {

      if (forComponent instanceof Button) {
        Button button = (Button) forComponent;

        if ((button.getOnclick() == null) && (button.getOnmouseover() == null)) {
          logger.warn(
              "Popover [{0}] is *for* button [{1}] but the button does not have an onclick or onmouseover attribute.",
              popover.getClientKey(), for_);
        }
      }
    }
  }
Exemplo n.º 21
0
  public void submit() {

    FacesMessage globalFacesMessage = new FacesMessage("Your request processed successfully.");
    FacesContext facesContext = FacesContext.getCurrentInstance();
    facesContext.addMessage(null, globalFacesMessage);

    logger.info("submit: firstName = " + fieldModelBean.getFirstName());
  }
  /** Returns the implementation singleton instance. */
  public static LiferayFacesContext getInstance() {

    if (instance == null) {
      logger.error("Instance not initialized -- caller might be static");
    }

    return instance;
  }
  protected void maintainBridgeRequestScope(
      PortletRequest portletRequest,
      PortletResponse portletResponse,
      BridgeRequestScope.Transport bridgeRequestScopeTransport) {

    String bridgeRequestScopeId = bridgeRequestScope.getId();

    bridgeRequestScopeCache.put(bridgeRequestScopeId, bridgeRequestScope);

    String bridgeRequestScopeKey = portletName + PARAM_BRIDGE_REQUEST_SCOPE_ID;

    if (bridgeRequestScopeTransport == BridgeRequestScope.Transport.PORTLET_SESSION_ATTRIBUTE) {

      // TCK TestPage071: nonFacesResourceTest
      // TCK TestPage073: scopeAfterRedisplayResourcePPRTest
      PortletSession portletSession = portletRequest.getPortletSession(true);
      portletSession.setAttribute(bridgeRequestScopeKey, bridgeRequestScopeId);
    } else {

      if (portletResponse instanceof StateAwareResponse) {
        logger.debug(
            "Setting render parameter name=[{0}] value=[{1}]",
            bridgeRequestScopeKey, bridgeRequestScopeId);

        try {
          StateAwareResponse stateAwareResponse = (StateAwareResponse) portletResponse;
          stateAwareResponse.setRenderParameter(bridgeRequestScopeKey, bridgeRequestScopeId);
        } catch (IllegalStateException e) {

          // If a redirect occurred, then swallow/ignore the IllegalStateException
          if (bridgeRequestScope.isRedirectOccurred()) {

            // The Portlet API JavaDocs indicate that StateAwareResponse.setRenderParameter(String,
            // String)
            // must throw an IllegalStateException if ActionResponse.sendRedirect(String) was
            // previously
            // called. The JSR 329 TCK TestPage039 (requestNoScopeOnRedirectTest) and TestPage176
            // (redirectActionTest) both perform pseudo-redirects (effectively treated like
            // navigation-rules
            // from one JSF viewId to another). Since the tests don't actually call
            // ActionResponse.sendRedirect(String), this condition is never reached by the TCK.
            // However,
            // this condition is a real-world use-case and so the IllegalStateException must be
            // swallowed/ignored here so that portlet lifecycle processing is able to continue. For
            // more
            // information, see: http://issues.liferay.com/browse/FACES-1367
          }

          // Otherwise throw the IllegalStateException.
          else {
            throw e;
          }
        }
      }
    }
  }
Exemplo n.º 24
0
  public static byte[] XHTML2PDF(String xhtml) throws IOException {
    byte[] pdf = null;
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

    try {
      ITextRenderer itextRenderer = new ITextRenderer();
      itextRenderer.setDocumentFromString(xhtml);
      itextRenderer.layout();
      itextRenderer.createPDF(byteArrayOutputStream);
      pdf = byteArrayOutputStream.toByteArray();
    } catch (Exception e) {
      logger.error(e.getMessage(), e);
      logger.error("vvv--- Offending XHTML ---vvv");
      logger.error(xhtml);
      throw new IOException(e.getMessage());
    }

    return pdf;
  }
  protected Object getInjectionProvider(Map<String, Object> applicationMap) {

    try {

      Object applicationAssociate = applicationMap.get("com.sun.faces.ApplicationAssociate");

      // If the ApplicationAssociate instance is available, then return the InjectionProvider that
      // it knows about.
      if (applicationAssociate != null) {

        // Note that the ApplicationAssociate instance will be available during startup if the
        // Mojarra
        // ConfigureListener executes prior to the BridgeSessionListener. It will also be available
        // during
        // execution of the JSF lifecycle.
        Method getInjectionProviderMethod =
            applicationAssociate.getClass().getMethod("getInjectionProvider", new Class[] {});
        Object mojarraInjectionProvider =
            getInjectionProviderMethod.invoke(applicationAssociate, new Object[] {});

        logger.debug("mojarraInjectionProvider=[{0}]", mojarraInjectionProvider);

        return mojarraInjectionProvider;
      }

      // Otherwise, return null.
      else {

        // Note that the ApplicationAssociate instance will be null if this method is called during
        // startup and
        // the BridgeSessionListener executes prior to the Mojarra ConfigureListener. This can be
        // remedied by
        // explicitly specifying com.sun.faces.config.ConfigureListener as a listener in the
        // WEB-INF/web.xml
        // descriptor.
        return null;
      }
    } catch (Exception e) {
      logger.error(e);

      return null;
    }
  }
  /**
   * @see {@link ExternalContext#addResponseHeader(String, String)}
   * @since JSF 2.0
   */
  @Override
  public void addResponseHeader(String name, String value) {

    if (portletResponse instanceof ResourceResponse) {
      ResourceResponse resourceResponse = (ResourceResponse) portletResponse;
      resourceResponse.addProperty(name, value);
    } else {
      logger.warn(
          "Unable to call {0} for portletResponse=[{1}] because it is not a ResourceResponse.",
          "portletResponse.addProperty(String, String)", portletResponse.getClass().getName());
    }
  }
Exemplo n.º 27
0
  @Override
  public void setRequest(Object request) {
    this.portletRequest = (PortletRequest) request;

    try {
      boolean requestChanged = true;
      boolean responseChanged = false;
      preInitializeObjects(requestChanged, responseChanged);
    } catch (Exception e) {
      logger.error(e);
    }
  }
Exemplo n.º 28
0
 public void handleFileUpload(FileUploadEvent event) {
   List<UploadedFile> uploadedFiles = applicantModelBean.getUploadedFiles();
   ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
   PortletSession portletSession = (PortletSession) externalContext.getSession(false);
   String uniqueFolderName = portletSession.getId();
   org.primefaces.model.UploadedFile uploadedFile = event.getFile();
   UploadedFileWrapper uploadedFileWrapper =
       new UploadedFileWrapper(uploadedFile, UploadedFile.Status.FILE_SAVED, uniqueFolderName);
   uploadedFiles.add(uploadedFileWrapper);
   logger.debug(
       "Received fileName=[{0}] absolutePath=[{1}]",
       uploadedFileWrapper.getName(), uploadedFileWrapper.getAbsolutePath());
 }
  public PreDestroyInvokerMojarraImpl(Map<String, Object> applicationMap) {

    this.mojarraInjectionProvider = getInjectionProvider(applicationMap);

    try {
      this.invokePreDestroyMethod =
          mojarraInjectionProvider
              .getClass()
              .getMethod(INVOKE_PRE_DESTROY, new Class[] {Object.class});
    } catch (Exception e) {
      logger.error(e);
    }
  }
  @Override
  public void invokeAnnotatedMethods(Object managedBean, boolean preferPreDestroy) {

    if (preferPreDestroy) {

      if (invokePreDestroyMethod != null) {

        try {
          logger.debug(
              "Invoking methods annotated with @PreDestroy: mojarraInjectionProvider=[{0}] managedBean=[{1}]",
              mojarraInjectionProvider, managedBean);
          invokePreDestroyMethod.invoke(mojarraInjectionProvider, managedBean);
        } catch (Exception e) {
          logger.error(e);
        }
      } else {
        super.invokeAnnotatedMethods(managedBean, preferPreDestroy);
      }
    } else {
      super.invokeAnnotatedMethods(managedBean, preferPreDestroy);
    }
  }