Пример #1
0
 public Schema() throws UtilException {
   createConnection();
   SettingBundle settings = ResourceLocator.getSettingBundle("org.silverpeas.admin.admin");
   String m_sHaveToTestConnections = settings.getString("HaveToTestConnections");
   if ("false".equalsIgnoreCase(m_sHaveToTestConnections)) {
     haveToTestConnections = false;
   }
 }
  @Override
  public String doAction(HttpServletRequest request) {
    HttpSession session = request.getSession(true);
    MainSessionController controller =
        (MainSessionController)
            session.getAttribute(MainSessionController.MAIN_SESSION_CONTROLLER_ATT);
    if (controller == null) {
      return "/Login.jsp";
    }

    SettingBundle settings =
        ResourceLocator.getSettingBundle(
            "org.silverpeas.authentication.settings.passwordExpiration");
    String passwordChangeURL =
        settings.getString("passwordChangeURL", "/defaultPasswordAboutToExpire.jsp");

    UserDetail ud = controller.getCurrentUserDetail();
    try {
      String login = ud.getLogin();
      String domainId = ud.getDomainId();
      String oldPassword = request.getParameter("oldPassword");
      String newPassword = request.getParameter("newPassword");
      AuthenticationCredential credential =
          AuthenticationCredential.newWithAsLogin(login)
              .withAsPassword(oldPassword)
              .withAsDomainId(domainId);
      AuthenticationService authenticator = AuthenticationServiceProvider.getService();
      authenticator.changePassword(credential, newPassword);

      GraphicElementFactory gef =
          (GraphicElementFactory)
              session.getAttribute(GraphicElementFactory.GE_FACTORY_SESSION_ATT);
      String favoriteFrame = gef.getLookFrame();

      return "/Main/" + favoriteFrame;
    } catch (AuthenticationException e) {
      SilverTrace.error(
          "peasCore",
          "effectiveChangePasswordHandler.doAction()",
          "peasCore.EX_USER_KEY_NOT_FOUND",
          e);
      return performUrlChangePasswordError(request, passwordChangeURL, ud);
    }
  }
  public static boolean processThumbnail(ForeignPK pk, String objectType, List<FileItem> parameters)
      throws Exception {
    boolean thumbnailChanged = false;
    String mimeType = null;
    String physicalName = null;
    FileItem uploadedFile = FileUploadUtil.getFile(parameters, "WAIMGVAR0");
    if (uploadedFile != null) {
      String logicalName = uploadedFile.getName().replace('\\', '/');
      if (StringUtil.isDefined(logicalName)) {
        logicalName = FilenameUtils.getName(logicalName);
        mimeType = FileUtil.getMimeType(logicalName);
        String type = FileRepositoryManager.getFileExtension(logicalName);
        if (FileUtil.isImage(logicalName)) {
          physicalName = String.valueOf(System.currentTimeMillis()) + '.' + type;
          SilverpeasFileDescriptor descriptor =
              new SilverpeasFileDescriptor(pk.getInstanceId())
                  .mimeType(mimeType)
                  .parentDirectory(publicationSettings.getString("imagesSubDirectory"))
                  .fileName(physicalName);
          SilverpeasFile target = SilverpeasFileProvider.newFile(descriptor);
          target.writeFrom(uploadedFile.getInputStream());
        } else {
          throw new ThumbnailRuntimeException(
              "ThumbnailController.processThumbnail()",
              SilverpeasRuntimeException.ERROR,
              "thumbnail_EX_MSG_WRONG_TYPE_ERROR");
        }
      }
    }

    // If no image have been uploaded, check if one have been picked up from a gallery
    if (physicalName == null) {
      // on a pas d'image, regarder s'il y a une provenant de la galerie
      String nameImageFromGallery = FileUploadUtil.getParameter(parameters, "valueImageGallery");
      if (StringUtil.isDefined(nameImageFromGallery)) {
        physicalName = nameImageFromGallery;
        mimeType = "image/jpeg";
      }
    }

    // If one image is defined, save it through Thumbnail service
    if (StringUtil.isDefined(physicalName)) {
      ThumbnailDetail detail =
          new ThumbnailDetail(
              pk.getInstanceId(),
              Integer.parseInt(pk.getId()),
              ThumbnailDetail.THUMBNAIL_OBJECTTYPE_PUBLICATION_VIGNETTE);
      detail.setOriginalFileName(physicalName);
      detail.setMimeType(mimeType);
      try {
        ThumbnailController.updateThumbnail(detail);
        thumbnailChanged = true;
      } catch (ThumbnailRuntimeException e) {
        SilverTrace.error(
            "thumbnail",
            "KmeliaRequestRouter.processVignette",
            "thumbnail_MSG_UPDATE_THUMBNAIL_KO",
            e);
        try {
          ThumbnailController.deleteThumbnail(detail);
        } catch (Exception exp) {

        }
      }
    }
    return thumbnailChanged;
  }
 protected static String getImageDirectory(String instanceId) {
   return FileRepositoryManager.getAbsolutePath(instanceId)
       + publicationSettings.getString("imagesSubDirectory")
       + File.separatorChar;
 }