Пример #1
0
  /**
   * Loads a blog that is a part of a larger composite blog.
   *
   * @param blogDir the blog.dir for the blog
   * @param blogId the ID for the blog
   */
  private void startBlog(String blogDir, String blogId) {
    Blog blog = new Blog(blogDir);
    blog.setId(blogId);

    File pathToLiveThemes =
        new File(PebbleContext.getInstance().getWebApplicationRoot(), THEMES_PATH);
    Theme theme = new Theme(blog, "user-" + blogId, pathToLiveThemes.getAbsolutePath());
    blog.setEditableTheme(theme);

    blog.start();
    blogs.put(blog.getId(), blog);

    // which version are we at and do we need to upgrade?
    File versionFile = new File(blogDir, "pebble.version");
    String blogVersion = null;
    String currentVersion = PebbleContext.getInstance().getBuildVersion();
    try {
      if (versionFile.exists()) {
        BufferedReader reader = new BufferedReader(new FileReader(versionFile));
        blogVersion = reader.readLine();
        reader.close();
      }
    } catch (Exception e) {
      log.error(e);
    }

    try {
      if (blogVersion == null || !blogVersion.equals(currentVersion)) {
        UpgradeUtilities.upgradeBlog(blog, blogVersion, currentVersion);

        BufferedWriter writer = new BufferedWriter(new FileWriter(versionFile));
        writer.write(currentVersion);
        writer.close();

        // now that the upgrade is complete, reload the blog
        reloadBlog(blog);
      }
    } catch (Exception e) {
      log.error(e);
    }
  }
Пример #2
0
  /**
   * Peforms the processing associated with this action.
   *
   * @param request the HttpServletRequest instance
   * @param response the HttpServletResponse instance
   * @return the name of the next view
   */
  public View process(HttpServletRequest request, HttpServletResponse response)
      throws ServletException {
    try {
      SecurityRealm realm = PebbleContext.getInstance().getConfiguration().getSecurityRealm();
      PebbleUserDetails currentUserDetails = SecurityUtils.getUserDetails();
      String password1 = request.getParameter("password1");
      String password2 = request.getParameter("password2");
      String submit = request.getParameter("submit");

      // can the user change their user details?
      if (!currentUserDetails.isDetailsUpdateable()) {
        return new ForbiddenView();
      }

      if (submit == null || submit.length() == 0) {
        return new ChangePasswordView();
      }

      ValidationContext validationContext = new ValidationContext();

      if (password1 == null || password1.length() == 0) {
        validationContext.addError("Password can not be empty");
      } else if (!password1.equals(password2)) {
        validationContext.addError("Passwords do not match");
      }

      if (!validationContext.hasErrors()) {
        realm.changePassword(currentUserDetails.getUsername(), password1);

        return new PasswordChangedView();
      }

      getModel().put("validationContext", validationContext);
      return new ChangePasswordView();
    } catch (SecurityRealmException e) {
      throw new ServletException(e);
    }
  }
Пример #3
0
 private File getBlogsDirectory() {
   return new File(PebbleContext.getInstance().getConfiguration().getDataDirectory(), "blogs");
 }
Пример #4
0
 public MultiBlog getMultiBlog() {
   return new MultiBlog(PebbleContext.getInstance().getConfiguration().getDataDirectory());
 }