/**
   * add a new content. It is registered to contentManager service
   *
   * @param con a Connection
   * @param pubDetail the content to register
   * @param userId the creator of the content
   * @return the unique silverObjectId which identified the new content
   */
  public int createSilverContent(
      Connection con, PublicationDetail pubDetail, String userId, boolean isVisible)
      throws ContentManagerException {

    SilverContentVisibility scv =
        new SilverContentVisibility(pubDetail.getBeginDate(), pubDetail.getEndDate(), isVisible);
    return getContentManager()
        .addSilverContent(
            con, pubDetail.getPK().getId(), pubDetail.getPK().getComponentName(), userId, scv);
  }
 /**
  * return a list of silverContent according to a list of publicationPK
  *
  * @param pubPKs a list of publicationPK
  * @return a list of publicationDetail
  */
 private List getHeaders(List<PublicationPK> pubPKs) {
   List<PublicationDetail> publicationDetails =
       new ArrayList<>(getPublicationService().getPublications(pubPKs));
   List<PublicationDetail> headers = new ArrayList<>(publicationDetails.size());
   for (PublicationDetail pubDetail : publicationDetails) {
     pubDetail.setIconUrl(CONTENT_ICON);
     headers.add(pubDetail);
   }
   return headers;
 }
 @Override
 public List<PublicationDetail> getLatestPublications(String spaceId, int nbPublis) {
   List<PublicationDetail> publications = super.getLatestPublications(spaceId, nbPublis * 2);
   List<PublicationDetail> result = new ArrayList<PublicationDetail>();
   for (PublicationDetail publication : publications) {
     if (!isComponentForNews(publication.getPK().getInstanceId())) {
       result.add(publication);
     }
     if (result.size() == nbPublis) {
       return result;
     }
   }
   return result;
 }
Пример #4
0
  @Override
  public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
      throws IOException, ServletException {

    Boolean mob = (Boolean) ((HttpServletRequest) req).getSession().getAttribute("isMobile");
    if (mob != null && !mob) {
      chain.doFilter(req, res);
      return;
    }

    String userAgent = ((HttpServletRequest) req).getHeader("User-Agent");
    if (userAgent != null) {
      boolean isMobile = userAgent.contains("Android") || userAgent.contains("iPhone");
      ((HttpServletRequest) req).getSession().setAttribute("isMobile", new Boolean(isMobile));

      if (isMobile) {
        String url = ((HttpServletRequest) req).getRequestURL().toString();
        String params = "";
        if (url.contains("Publication")) {
          String id = url.substring(url.lastIndexOf("/") + 1);
          PublicationDetail pub = getPubBm().getDetail(new PublicationPK(id));
          String appId = pub.getInstanceId();
          params =
              "?shortcutContentType=Publication&shortcutContentId="
                  + id
                  + "&shortcutAppId="
                  + appId;
        } else if (url.contains("Media")) {
          String id = url.substring(url.lastIndexOf("/") + 1);
          Media media = getGalleryService().getMedia(new MediaPK(id));
          String appId = media.getInstanceId();
          params = "?shortcutContentType=Media&shortcutContentId=" + id + "&shortcutAppId=" + appId;
        } else {
          chain.doFilter(req, res);
          return;
        }
        ((HttpServletResponse) res).sendRedirect("/silverpeas/spmobile/" + params);
        return;
      } else {
        chain.doFilter(req, res);
        return;
      }
    } else {
      chain.doFilter(req, res);
      return;
    }
  }
  /**
   * update the visibility attributes of the content. Here, the type of content is a
   * PublicationDetail
   *
   * @param pubDetail the content
   */
  public void updateSilverContentVisibility(PublicationDetail pubDetail, boolean isVisible)
      throws ContentManagerException {
    int silverContentId =
        getContentManager()
            .getSilverContentId(pubDetail.getPK().getId(), pubDetail.getPK().getComponentName());
    if (silverContentId != -1) {
      SilverContentVisibility scv =
          new SilverContentVisibility(pubDetail.getBeginDate(), pubDetail.getEndDate(), isVisible);

      getContentManager()
          .updateSilverContentVisibilityAttributes(
              scv, pubDetail.getPK().getComponentName(), silverContentId);
      ClassifyEngine.clearCache();
    } else {
      createSilverContent(null, pubDetail, pubDetail.getCreatorId(), isVisible);
    }
  }