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);
  }
Пример #2
0
  /** @return */
  public static SearchContext getCurrentSearchContext() {
    final LiferayFacesContext liferayFacesContext = LiferayFacesContext.getInstance();

    final PortletRequest req =
        (PortletRequest) liferayFacesContext.getExternalContext().getRequest();

    final HttpServletRequest httpServletRequest =
        PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(req));
    final SearchContext searchContext = SearchContextFactory.getInstance(httpServletRequest);
    return searchContext;
  }
Пример #3
0
  /**
   * Upload CSV or XML file.
   *
   * @param csvXmlFile the file
   * @return the url
   * @throws Exception
   */
  public static String uploadToDocmentLibrary(UploadedFile file) throws Exception {
    LiferayFacesContext lfc = LiferayFacesContext.getInstance();
    ThemeDisplay themeDisplay = lfc.getThemeDisplay();

    // upload file to local liferay storage
    DLFileEntry fileEntry =
        FileUtils.uploadFileToFolder(file, PropsUtil.get("image.folder.id"), themeDisplay);

    return themeDisplay.getPortalURL()
        + "/c/document_library/get_file?uuid="
        + fileEntry.getUuid()
        + "&groupId="
        + themeDisplay.getScopeGroupId();
  }
Пример #4
0
  public void onSave() {
    try {
      FacesMessage message = null;
      if (!CandidateLocalServiceUtil.isEmailExisted(
          getCandidateItem().getObject().getEmailAddress())) {
        ServiceContext serviceContext = LiferayFacesContext.getInstance().getServiceContext();
        Candidate candidate =
            CandidateLocalServiceUtil.fetchCandidate(
                getCandidateItem().getObject().getCandidateId());
        final Map<Experience, Boolean> experienceMap = new LinkedHashMap<>();
        for (ExperienceObjectItem experienceObjectItem : getCandidateItem().getExperiences()) {
          experienceMap.put(
              experienceObjectItem.getExperience(), experienceObjectItem.isUIDeleted());
        }

        final Map<Certificate, Boolean> certificateMap = new LinkedHashMap<>();
        for (CertificateObjectItem item : getCandidateItem().getCertificates()) {
          // set University Id -> certificate
          item.getObject().setUniversityId(item.getUniversityId());
          certificateMap.put(item.getObject(), item.isUIDeleted());
        }

        if (candidate == null) { // create new
          candidate = getCandidateItem().getObject();
          CandidateLocalServiceUtil.addCandidate(
              candidate,
              getCandidateItem().getVacancyIndexItem().getId(),
              getCandidateItem().getPossibleDesiredVacancies(),
              getFileEntryIds(),
              experienceMap,
              certificateMap,
              serviceContext);
        } else { // update

          CandidateLocalServiceUtil.updateCandidate(
              getCandidateItem().getObject(),
              getCandidateItem().getVacancyIndexItem().getId(),
              getCandidateItem().getPossibleDesiredVacancies(),
              getFileEntryIds(),
              experienceMap,
              certificateMap,
              serviceContext);
        }

        BeanUtils.getGuestViewBean().switchOutcome(GuestNavigation.SUCCESS_ADD);

      } else {
        message = new FacesMessage("Email Existed", "This email has already existed");
        FacesContext.getCurrentInstance().addMessage(null, message);
      }

    } catch (SystemException e) {
      LOGGER.info(e);
    }
  }
Пример #5
0
  /**
   * The search redirection.
   *
   * @return an empty string.
   */
  public String search() {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    Object responseObject = facesContext.getExternalContext().getResponse();

    if (responseObject != null && responseObject instanceof ActionResponse) {
      ActionResponse actionResponse = (ActionResponse) responseObject;

      Query query = new Query();
      query.getTags().add(selectedTag);
      actionResponse.setEvent(
          new QName("http://fokus.fraunhofer.de/odplatform", "querydatasets"), query);

      String location = LiferayFacesContext.getInstance().getThemeDisplay().getPortalURL();
      Layout layout = LiferayFacesContext.getInstance().getThemeDisplay().getLayout();

      try {
        if (layout.isPublicLayout()) {
          location +=
              LiferayFacesContext.getInstance().getThemeDisplay().getPathFriendlyURLPublic();
        }

        location +=
            layout.hasScopeGroup()
                ? layout.getScopeGroup().getFriendlyURL()
                : layout.getGroup().getFriendlyURL();
        location += "/suchen";
      } catch (PortalException e) {
        e.printStackTrace();
      } catch (SystemException e) {
        e.printStackTrace();
      }

      try {
        facesContext.getExternalContext().redirect(location);
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
    return "";
  }
Пример #6
0
  /** Inits the. */
  @PostConstruct
  public void init() {
    ThemeDisplay themeDisplay = LiferayFacesContext.getInstance().getThemeDisplay();
    String currentPage = themeDisplay.getLayout().getFriendlyURL();
    if (currentPage.equals("/daten")) {
      metadataType = MetadataEnumType.DATASET.toField();
    } else if (currentPage.equals("/apps")) {
      metadataType = MetadataEnumType.APPLICATION.toField();
    } else if (currentPage.equals("/dokumente")) {
      metadataType = MetadataEnumType.DOCUMENT.toField();
    } else {
      metadataType = "metadata";
    }

    scmBuildnumber = PropsUtil.get("ogdd.buildNumber");
    scmBranch = PropsUtil.get("ogdd.scmBranch");
  }
  public boolean isPermittedToAddFolder() {

    if (permittedToAddFolder == null) {

      try {
        PermissionChecker permissionChecker = liferayFacesContext.getPermissionChecker();
        DLFolder selectedDLFolder = docLibModelBean.getSelectedFolderUserObject().getDlFolder();
        long scopeGroupId = selectedDLFolder.getGroupId();
        long folderId = selectedDLFolder.getFolderId();
        permittedToAddFolder =
            DLFolderPermission.contains(
                permissionChecker, scopeGroupId, folderId, ActionKeys.ADD_FOLDER);
      } catch (Exception e) {
        logger.error(e.getMessage(), e);
      }
    }

    return permittedToAddFolder;
  }
/** @author Neil Griffin */
@ManagedBean(name = "docLibBackingBean")
@RequestScoped
public class DocLibBackingBean {

  // Logger
  private static final Logger logger = LoggerFactory.getLogger(DocLibBackingBean.class);

  // Self-Injections
  private LiferayFacesContext liferayFacesContext = LiferayFacesContext.getInstance();

  // Injections
  @ManagedProperty(name = "docLibModelBean", value = "#{docLibModelBean}")
  private DocLibModelBean docLibModelBean;

  @ManagedProperty(name = "docLibViewBean", value = "#{docLibViewBean}")
  private DocLibViewBean docLibViewBean;

  // Private Data Members
  private String folderName;
  private String folderDescription;
  private Boolean permittedToAddDocument;
  private Boolean permittedToAddFolder;

  // Action Listeners
  private AddFolderActionListener addFolderActionListener = new AddFolderActionListener();
  private PopDownActionListener popDownActionListener = new PopDownActionListener();
  private PopUpActionListener popUpActionListener = new PopUpActionListener();

  public void treeNodeSelected(ActionEvent actionEvent) {

    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    long folderId = LongHelper.toLong(externalContext.getRequestParameterMap().get("folderId"), 0L);
    FolderTreeNode folderTreeNode =
        docLibModelBean.getFolderTreeModel().findFolderTreeNode(folderId);
    FolderUserObject folderUserObject = folderTreeNode.getFolderUserObject();
    docLibModelBean.setSelectedUserObject(folderUserObject);
    permittedToAddFolder = null;
    permittedToAddDocument = null;
  }

  public AddFolderActionListener getAddFolderActionListener() {
    return addFolderActionListener;
  }

  public void setDocLibModelBean(DocLibModelBean docLibModelBean) {

    // Injected via ManagedProperty annotation
    this.docLibModelBean = docLibModelBean;
  }

  public void setDocLibViewBean(DocLibViewBean docLibViewBean) {

    // Injected via ManagedProperty annotation.
    this.docLibViewBean = docLibViewBean;
  }

  public String getFolderDescription() {
    return folderDescription;
  }

  public void setFolderDescription(String folderDescription) {
    this.folderDescription = folderDescription;
  }

  public String getFolderName() {
    return folderName;
  }

  public void setFolderName(String folderName) {
    this.folderName = folderName;
  }

  public PopDownActionListener getPopDownActionListener() {
    return popDownActionListener;
  }

  public PopUpActionListener getPopUpActionListener() {
    return popUpActionListener;
  }

  public boolean isPermittedToAddFolder() {

    if (permittedToAddFolder == null) {

      try {
        PermissionChecker permissionChecker = liferayFacesContext.getPermissionChecker();
        DLFolder selectedDLFolder = docLibModelBean.getSelectedFolderUserObject().getDlFolder();
        long scopeGroupId = selectedDLFolder.getGroupId();
        long folderId = selectedDLFolder.getFolderId();
        permittedToAddFolder =
            DLFolderPermission.contains(
                permissionChecker, scopeGroupId, folderId, ActionKeys.ADD_FOLDER);
      } catch (Exception e) {
        logger.error(e.getMessage(), e);
      }
    }

    return permittedToAddFolder;
  }

  public boolean isPermittedToAddDocument() {

    if (permittedToAddDocument == null) {

      try {
        PermissionChecker permissionChecker = liferayFacesContext.getPermissionChecker();
        DLFolder selectedDLFolder = docLibModelBean.getSelectedFolderUserObject().getDlFolder();
        long scopeGroupId = selectedDLFolder.getGroupId();
        long folderId = selectedDLFolder.getFolderId();
        permittedToAddDocument =
            DLFolderPermission.contains(
                permissionChecker, scopeGroupId, folderId, ActionKeys.ADD_DOCUMENT);
        permittedToAddFolder =
            DLFolderPermission.contains(
                permissionChecker, scopeGroupId, folderId, ActionKeys.ADD_FOLDER);
      } catch (Exception e) {
        logger.error(e.getMessage(), e);
      }
    }

    return permittedToAddDocument;
  }

  protected class AddFolderActionListener implements ActionListener {
    public void processAction(ActionEvent actionEvent) throws AbortProcessingException {

      try {
        FolderUserObject folderUserObject = docLibModelBean.getSelectedFolderUserObject();
        DLFolder dlFolder = folderUserObject.getDlFolder();
        long groupId = dlFolder.getGroupId();
        long repositoryId = dlFolder.getRepositoryId();
        boolean mountPoint = dlFolder.getMountPoint();
        long parentFolderId = dlFolder.getFolderId();
        ServiceContext serviceContext = new ServiceContext();

        // Temporary: Make the default setting be that community members can view the file. Need to
        // develop a
        // "Viewable By" permissions Facelet composite component UI similar to
        // portal-web/docroot/html/taglib/ui/input_permissions/page.jsp
        serviceContext.setAddGroupPermissions(true);
        DLFolderServiceUtil.addFolder(
            groupId,
            repositoryId,
            mountPoint,
            parentFolderId,
            folderName,
            folderDescription,
            serviceContext);
        docLibModelBean.forceTreeRequery();
        logger.debug("Added folderName=[{0}] description=[{1}]", folderName, folderDescription);
      } catch (Exception e) {
        logger.error(e.getMessage(), e);
        liferayFacesContext.addGlobalUnexpectedErrorMessage();
      }

      docLibViewBean.setPopupRendered(false);
    }
  }

  protected class PopDownActionListener implements ActionListener {

    public void processAction(ActionEvent actionEvent) throws AbortProcessingException {
      docLibViewBean.setPopupRendered(false);
    }
  }

  protected class PopUpActionListener implements ActionListener {

    public void processAction(ActionEvent actionEvent) throws AbortProcessingException {
      docLibViewBean.setPopupRendered(true);
    }
  }
}
  @Override
  public void encodeBegin(FacesContext facesContext, UIComponent uiComponent) throws IOException {

    super.encodeBegin(facesContext, uiComponent);

    InputEditorInternal inputEditorInternal = (InputEditorInternal) uiComponent;
    ResponseWriter responseWriter = facesContext.getResponseWriter();
    ExternalContext externalContext = facesContext.getExternalContext();
    PortletRequest portletRequest = (PortletRequest) externalContext.getRequest();
    PortletResponse portletResponse = (PortletResponse) externalContext.getResponse();
    HttpServletRequest httpServletRequest = PortalUtil.getHttpServletRequest(portletRequest);
    httpServletRequest = new NonNamespacedHttpServletRequest(httpServletRequest);

    HttpServletResponse httpServletResponse = PortalUtil.getHttpServletResponse(portletResponse);
    PortletRequest liferayPortletRequest = getLiferayPortletRequest(portletRequest);
    boolean resourcePhase = (liferayPortletRequest instanceof ResourceRequest);
    Map<String, Object> attributes = inputEditorInternal.getAttributes();
    String onBlurMethod = (String) attributes.get("onBlurMethod");
    String editorImpl = (String) attributes.get("editorImpl");

    if (editorImpl == null) {
      editorImpl = CKEDITOR;
    }

    // Build up a URL that can be used to invoke the liferay-ui:input-editor JSP tag.
    String url = "/resources/liferay-ui/jsp/input-editor.jsp";
    StringBuilder queryString = new StringBuilder();
    queryString.append(StringPool.QUESTION);
    queryString.append("editorImpl");
    queryString.append(StringPool.EQUAL);
    queryString.append(editorImpl);
    queryString.append(StringPool.AMPERSAND);
    queryString.append("height");
    queryString.append(StringPool.EQUAL);
    queryString.append(attributes.get("height"));
    queryString.append(StringPool.AMPERSAND);
    queryString.append("initMethod");
    queryString.append(StringPool.EQUAL);
    queryString.append(attributes.get("initMethod"));
    queryString.append(StringPool.AMPERSAND);
    queryString.append("name");
    queryString.append(StringPool.EQUAL);

    String editorName = (String) attributes.get("name");
    queryString.append(editorName);
    queryString.append(StringPool.AMPERSAND);
    queryString.append("onChangeMethod");
    queryString.append(StringPool.EQUAL);
    queryString.append(attributes.get("onChangeMethod"));
    queryString.append(StringPool.AMPERSAND);
    queryString.append("skipEditorLoading");
    queryString.append(StringPool.EQUAL);

    if (resourcePhase) {

      // FACES-1439: Ensure that the <script src=".../ckeditor.js" /> element is not included in the
      // response by
      // specifying skipEditorLoading="true" during Ajax requests.
      queryString.append(Boolean.TRUE.toString());
    } else {
      queryString.append(Boolean.FALSE.toString());
    }

    queryString.append(StringPool.AMPERSAND);
    queryString.append("toolbarSet");
    queryString.append(StringPool.EQUAL);
    queryString.append(attributes.get("toolbarSet"));
    queryString.append(StringPool.AMPERSAND);
    queryString.append("width");
    queryString.append(StringPool.EQUAL);
    queryString.append(attributes.get("width"));
    url = url + queryString.toString();

    // Invoke the tag and capture it's output in a String, rather than having the output go directly
    // to the
    // response.
    RequestDispatcher requestDispatcher = httpServletRequest.getRequestDispatcher(url);
    JspIncludeResponse jspIncludeResponse = new JspIncludeResponse(httpServletResponse);

    try {
      requestDispatcher.include(httpServletRequest, jspIncludeResponse);
    } catch (ServletException e) {
      logger.error(e.getMessage());
      throw new IOException(e.getMessage());
    }

    String bufferedResponse = jspIncludeResponse.getBufferedResponse();

    if (bufferedResponse != null) {

      // Note: Trim the buffered response since there is typically over 100 newlines at the
      // beginning.
      bufferedResponse = bufferedResponse.trim();

      // If rendering an instance of the CKEditor, then
      String editorType = EditorUtil.getEditorValue(httpServletRequest, editorImpl);

      if (editorType.indexOf(CKEDITOR) >= 0) {

        String namespace = portletResponse.getNamespace();

        // FACES-1441: The liferay-ui:input-editor JSP tag (and associated ckeditor.jsp file) do not
        // provide a
        // way to hook-in to the "onblur" callback feature of the CKEditor. In order to overcome
        // this
        // limitation, it is necessary to append a <script>...</script> to the response that
        // provides this
        // ability.
        String onBlurScript = getOnBlurScript(editorName, onBlurMethod, namespace);

        // If running within an Ajax request, include the "onblur" callback script must be included
        // directly
        // to the response.
        if (resourcePhase) {

          StringBuilder scriptMarkup = new StringBuilder();
          scriptMarkup.append(StringPool.LESS_THAN);
          scriptMarkup.append(StringPool.SCRIPT);
          scriptMarkup.append(StringPool.GREATER_THAN);
          scriptMarkup.append(StringPool.CDATA_OPEN);
          scriptMarkup.append(onBlurScript);
          scriptMarkup.append(COMMENT_CDATA_CLOSE);
          scriptMarkup.append(StringPool.LESS_THAN);
          scriptMarkup.append(StringPool.FORWARD_SLASH);
          scriptMarkup.append(StringPool.SCRIPT);
          scriptMarkup.append(StringPool.GREATER_THAN);
          bufferedResponse = bufferedResponse.concat(scriptMarkup.toString());
        }

        // Otherwise, append the script to the "LIFERAY_SHARED_AUI_SCRIPT_DATA" request attribute,
        // which will
        // cause the script to be rendered at the bottom of the portal page.
        else {

          ScriptData scriptData =
              (ScriptData) externalContext.getRequestMap().get(WebKeys.AUI_SCRIPT_DATA);
          scriptData.append(getPortletId(portletRequest), onBlurScript, null);
        }

        // FACES-1439: If the component was rendered on the page on the previous JSF lifecycle, then
        // prevent it
        // from being re-initialized by removing all <script>...</script> elements.
        boolean scriptsRemoved = false;

        String clientId = inputEditorInternal.getClientId();

        if (resourcePhase && inputEditorInternal.isPreviouslyRendered()) {

          logger.debug("Preventing re-initialization of CKEditor for clientId=[{0}]", clientId);

          ParsedResponse parsedResponse = new ParsedResponse(bufferedResponse);
          bufferedResponse = parsedResponse.getNonScripts();
          scriptsRemoved = true;
        }

        // FACES-1422: Move the scripts to the <eval>...</eval> section of the partial-response so
        // that they
        // will execute properly. This has the added benefit of preempt a DOM-diff with ICEfaces.
        if (resourcePhase && !scriptsRemoved) {

          logger.debug(
              "Moving CKEditor scripts to <eval>...</eval> section of the partial-response for clientId=[{0}]",
              clientId);

          ParsedResponse parsedResponse = new ParsedResponse(bufferedResponse);
          bufferedResponse = parsedResponse.getNonScripts();

          String scripts = parsedResponse.getScripts();

          LiferayFacesContext liferayFacesContext = LiferayFacesContext.getInstance();
          liferayFacesContext.getJavaScriptMap().put(clientId, scripts);
          logger.trace(scripts);
        }
      }

      // Write the captured output from the JSP tag to the Faces responseWriter.
      logger.trace(bufferedResponse);
      responseWriter.write(bufferedResponse);
    }
  }
 public RegistrantModelBean() {
   registrant = new Registrant(LiferayFacesContext.getInstance().getCompanyId());
 }
Пример #11
0
 public static ServiceContext getServiceContext() {
   return LiferayFacesContext.getInstance().getServiceContext();
 }
Пример #12
0
 public void addGlobalUnexpectedErrorMessage() {
   LiferayFacesContext liferayFacesContext = LiferayFacesContext.getInstance();
   liferayFacesContext.addGlobalUnexpectedErrorMessage();
 }
Пример #13
0
 public void addGlobalSuccessInfoMessage() {
   LiferayFacesContext liferayFacesContext = LiferayFacesContext.getInstance();
   liferayFacesContext.addGlobalSuccessInfoMessage();
 }
Пример #14
0
  /**
   * Submit.
   *
   * @return the string
   */
  public void submit() {
    // Query q = new Query();
    // q.setSearchterm(query);

    ThemeDisplay themeDisplay = LiferayFacesContext.getInstance().getThemeDisplay();
    Layout layout = themeDisplay.getLayout();
    String currentPage = layout.getFriendlyURL();

    FacesContext facesContext = FacesContext.getCurrentInstance();
    Object responseObject = facesContext.getExternalContext().getResponse();
    if (responseObject != null && responseObject instanceof ActionResponse) {
      ActionResponse actionResponse = (ActionResponse) responseObject;
      // actionResponse.setEvent(new
      // QName("http://fokus.fraunhofer.de/odplatform", "querydatasets"),
      // q);

      if (query != null && !query.isEmpty()) {
        log.info("searching for '{}'", query);
        // String escapedQuery = StringEscapeUtils.escapeHtml(query);
        String escapedQuery = StringUtils.escapeColonString(query);
        // msg 8:5.2014 actionResponse.setRenderParameter("searchterm",
        // query);
        escapedQuery = StringUtils.removeBlankStrings(query);
        log.info("escapedQuery:" + escapedQuery);
        actionResponse.setRenderParameter("searchterm", escapedQuery);
      } else {
        actionResponse.removePublicRenderParameter("searchterm");
      }

      actionResponse.removePublicRenderParameter("searchcategory");
    }

    // if (currentPage.equals("/home")) {
    String location = themeDisplay.getPortalURL();
    if (layout.isPublicLayout()) {
      location += themeDisplay.getPathFriendlyURLPublic();
    }

    try {
      location +=
          layout.hasScopeGroup()
              ? layout.getScopeGroup().getFriendlyURL()
              : layout.getGroup().getFriendlyURL();
      if (currentPage.equals("/home")) {
        location += "/suchen";
      } else {
        location += layout.getFriendlyURL();
      }
    } catch (PortalException e) {
      log.error("add group to url", e);
    } catch (SystemException e) {
      log.error("add group to url", e);
    }

    try {
      facesContext.getExternalContext().redirect(location);
    } catch (IOException e) {
      log.error("redirect to result page", e);
    }
    // }

  }