Package net.sourceforge.pebble.domain

Examples of net.sourceforge.pebble.domain.Blog


   * @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 {
    Blog blog = (Blog)getModel().get(Constants.BLOG_KEY);

    String type = getType();
    String path = "";
    String[] filenames = new String[10];

    FileManager fileManager = new FileManager(blog, type);

    try {
      boolean isMultipart = FileUpload.isMultipartContent(request);

      if (isMultipart) {
        DiskFileUpload upload = new DiskFileUpload();
        long sizeInBytes = PebbleContext.getInstance().getConfiguration().getFileUploadSize() * 1024; // convert to bytes
        upload.setSizeMax(sizeInBytes);
        upload.setSizeThreshold((int)sizeInBytes/4);
        upload.setRepositoryPath(System.getProperty("java.io.tmpdir"));

        List items;
        try {
          items = upload.parseRequest(request);
        } catch (FileUploadBase.SizeLimitExceededException e) {
          return new FileTooLargeView();
        }

        // find the form fields first
        Iterator it = items.iterator();
        while (it.hasNext()) {
          FileItem item = (FileItem)it.next();
          if (item.isFormField() && item.getFieldName().startsWith("filename")) {
            int index = Integer.parseInt(item.getFieldName().substring(item.getFieldName().length()-1));
            filenames[index] = item.getString();
            log.debug("index is " + index + ", filename is " + filenames[index]);
          } else if (item.isFormField() && item.getFieldName().equals("path")) {
            path = item.getString();
          }
        }

        // now the actual files
        it = items.iterator();
        while (it.hasNext()) {
          FileItem item = (FileItem)it.next();

          if (!item.isFormField() && item.getSize() > 0 && item.getFieldName().startsWith("file")) {
            int index = Integer.parseInt(item.getFieldName().substring(item.getFieldName().length()-1));

            // if the filename hasn't been specified, use that from the file
            // being uploaded
            if (filenames[index] == null || filenames[index].length() == 0) {
              filenames[index] = item.getName();
            }

            File destinationDirectory = fileManager.getFile(path);
            File file = new File(destinationDirectory, filenames[index]);
            if (!fileManager.isUnderneathRootDirectory(file)) {
              response.setStatus(HttpServletResponse.SC_FORBIDDEN);
              return null;
            }

            long itemSize = item.getSize()/1024;
            if (FileManager.hasEnoughSpace(blog, itemSize)) {
              log.debug("Writing file " + filenames[index] + ", size is " + item.getSize());
              writeFile(fileManager, path, filenames[index], item);

              // if it's a theme file, also create a copy in blog.dir/theme
              if (type.equals(FileMetaData.THEME_FILE)) {
                writeFile(new FileManager(blog, FileMetaData.BLOG_DATA), "/theme" + path, filenames[index], item);
              }
            } else {
              return new NotEnoughSpaceView();
            }
          }
        }
      }

      blog.info("Files uploaded.");
    } catch (Exception e) {
      throw new ServletException(e);
    }

    FileMetaData directory = fileManager.getFileMetaData(path);

    return new RedirectView(blog.getUrl() + directory.getUrl());
  }
View Full Code Here


   * Gets the URI that this view represents.
   *
   * @return the URI as a String
   */
  public String getUri() {
    Blog blog = (Blog)getModel().get(Constants.BLOG_KEY);
    TrackBackConfirmationStrategy strategy = blog.getTrackBackConfirmationStrategy();
    return strategy.getUri();
  }
View Full Code Here

    if (flavor != null && flavor.equalsIgnoreCase("zip")) {
      return new ForwardView("/zipDirectory.secureaction?type=blogData");
    }

    Blog blog = (Blog)getModel().get(Constants.BLOG_KEY);

    response.setContentType("application/xml; charset=" + blog.getCharacterEncoding());

    List<BlogEntry> blogEntries = blog.getBlogEntries();
    Collections.sort(blogEntries, new BlogEntryComparator());
    getModel().put(Constants.BLOG_ENTRIES, blogEntries);

    // set the locale of this feed request to be English
    javax.servlet.jsp.jstl.core.Config.set(
View Full Code Here

* @author    Simon Brown
*/
public abstract class AbstractLogAction extends SecureAction {

  protected Log getLog(HttpServletRequest request, HttpServletResponse response) throws ServletException {
    Blog blog = (Blog)getModel().get(Constants.BLOG_KEY);

    String yearAsString = request.getParameter("year");
    String monthAsString = request.getParameter("month");
    String dayAsString = request.getParameter("day");

    Calendar cal = blog.getCalendar();
    Log log = null;
    String logPeriod = "";

    if (yearAsString != null && yearAsString.length() > 0 &&
        monthAsString != null && monthAsString.length() > 0 &&
        dayAsString != null && dayAsString.length() > 0) {
      int year = Integer.parseInt(yearAsString);
      int month = Integer.parseInt(monthAsString);
      int day = Integer.parseInt(dayAsString);
      cal.set(Calendar.YEAR, year);
      cal.set(Calendar.MONTH, month-1);
      cal.set(Calendar.DAY_OF_MONTH, day);
      log = blog.getLogger().getLog(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH)+1, cal.get(Calendar.DAY_OF_MONTH));
      SimpleDateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy", blog.getLocale());
      dateFormat.setTimeZone(blog.getTimeZone());
      registerObjectsForNavigation(blog, blog.getBlogForDay(year, month, day));
      logPeriod = dateFormat.format(cal.getTime());
    } else if (yearAsString != null && yearAsString.length() > 0 &&
          monthAsString != null && monthAsString.length() > 0) {
      int year = Integer.parseInt(yearAsString);
      int month = Integer.parseInt(monthAsString);
      cal.set(Calendar.YEAR, year);
      cal.set(Calendar.MONTH, month-1);
      log = blog.getLogger().getLog(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH)+1);
      SimpleDateFormat dateFormat = new SimpleDateFormat("MMMM yyyy", blog.getLocale());
      dateFormat.setTimeZone(blog.getTimeZone());
      registerObjectsForNavigation(blog, blog.getBlogForMonth(year, month));
      logPeriod = dateFormat.format(cal.getTime());
    } else {
      // get the log for today
      log = blog.getLogger().getLog();
      SimpleDateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy", blog.getLocale());
      dateFormat.setTimeZone(blog.getTimeZone());
      registerObjectsForNavigation(blog, blog.getBlogForToday());
      logPeriod = dateFormat.format(cal.getTime());
    }

    getModel().put("logPeriod", logPeriod);

View Full Code Here

   * Gets the content type of this view.
   *
   * @return the content type as a String
   */
  public String getContentType() {
    Blog blog = (Blog)getModel().get(Constants.BLOG_KEY);
    return "application/xml; charset=" + blog.getCharacterEncoding();
  }
View Full Code Here

    return log;
  }

  protected String getLogFile(HttpServletRequest request, HttpServletResponse response) throws ServletException {
    Blog blog = (Blog)getModel().get(Constants.BLOG_KEY);

    String yearAsString = request.getParameter("year");
    String monthAsString = request.getParameter("month");
    String dayAsString = request.getParameter("day");

    Calendar cal = blog.getCalendar();
    String log = null;
    String logPeriod = "";

    if (yearAsString != null && yearAsString.length() > 0 &&
        monthAsString != null && monthAsString.length() > 0 &&
        dayAsString != null && dayAsString.length() > 0) {
      int year = Integer.parseInt(yearAsString);
      int month = Integer.parseInt(monthAsString);
      int day = Integer.parseInt(dayAsString);
      cal.set(Calendar.YEAR, year);
      cal.set(Calendar.MONTH, month-1);
      cal.set(Calendar.DAY_OF_MONTH, day);
      log = blog.getLogger().getLogFile(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH)+1, cal.get(Calendar.DAY_OF_MONTH));
      SimpleDateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy", blog.getLocale());
      dateFormat.setTimeZone(blog.getTimeZone());
      registerObjectsForNavigation(blog, blog.getBlogForDay(year, month, day));
      logPeriod = dateFormat.format(cal.getTime());
    } else if (yearAsString != null && yearAsString.length() > 0 &&
          monthAsString != null && monthAsString.length() > 0) {
      int year = Integer.parseInt(yearAsString);
      int month = Integer.parseInt(monthAsString);
      cal.set(Calendar.YEAR, year);
      cal.set(Calendar.MONTH, month-1);
      log = blog.getLogger().getLogFile(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH)+1);
      SimpleDateFormat dateFormat = new SimpleDateFormat("MMMM yyyy", blog.getLocale());
      dateFormat.setTimeZone(blog.getTimeZone());
      registerObjectsForNavigation(blog, blog.getBlogForMonth(year, month));
      logPeriod = dateFormat.format(cal.getTime());
    } else {
      // get the log for today
      log = blog.getLogger().getLogFile();
      SimpleDateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy", blog.getLocale());
      dateFormat.setTimeZone(blog.getTimeZone());
      registerObjectsForNavigation(blog, blog.getBlogForToday());
      logPeriod = dateFormat.format(cal.getTime());
    }

    getModel().put("logPeriod", logPeriod);
View Full Code Here

    if (s == null) {
      throw new XmlRpcException(0, "Blog with ID of " + null + " not found.");
    }

    String blogId = null;
    Blog blog;

    int index = s.lastIndexOf(BLOG_ID_SEPARATOR);
    if (index > -1) {
      blogId = s.substring(0, index);
    }
View Full Code Here

   *
   * @param blogId   the String containing the post ID
   * @return  the blog ID
   */
  protected Blog getBlogWithBlogId(String blogId) throws XmlRpcException {
    Blog blog = BlogManager.getInstance().getBlog(blogId);
    if (blog == null) {
      throw new XmlRpcException(0, "Blog with ID of " + blogId + " not found.");
    } else {
      return blog;
    }
View Full Code Here

   * @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 {
    Blog blog = (Blog)getModel().get(Constants.BLOG_KEY);
    Utilities.resetTheme(blog);
    return new ForwardView("/reloadBlog.secureaction");
  }
View Full Code Here

   * Sends the notification.
   *
   * @param blogEntry   the BlogEntry instance
   */
  private void sendNotification(BlogEntry blogEntry) {
    Blog blog = blogEntry.getBlog();
    String urlList = blog.getPluginProperties().getProperty(URL_LIST_KEY);
    String urls[] = new String[0];
    if (urlList != null) {
      urls = urlList.split(",");
    }
    UpdateNotificationPingsClient client = new UpdateNotificationPingsClient();
View Full Code Here

TOP

Related Classes of net.sourceforge.pebble.domain.Blog

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.