roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject svn commit: r828904 - in /roller/trunk/apps/weblogger: src/java/org/apache/roller/weblogger/business/jpa/ src/java/org/apache/roller/weblogger/ui/struts2/editor/ web/WEB-INF/classes/ web/WEB-INF/jsps/editor/
Date Fri, 23 Oct 2009 00:44:23 GMT
Author: snoopdave
Date: Fri Oct 23 00:44:22 2009
New Revision: 828904

URL: http://svn.apache.org/viewvc?rev=828904&view=rev
Log:
Media Blogging: allow update of file contents
https://issues.apache.org/jira/browse/ROL-1838

This commit adds an Update File Contents control on the Media File Edit page so you can upload
new content for a Media File. When you do, the Media File metadata will be updated (file size,
width, height, content type) as well as the thumbnail. The media file URL will not change.

Modified:
    roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/jpa/JPAMediaFileManagerImpl.java
    roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileAdd.java
    roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileEdit.java
    roller/trunk/apps/weblogger/web/WEB-INF/classes/ApplicationResources.properties
    roller/trunk/apps/weblogger/web/WEB-INF/jsps/editor/MediaFileEdit.jsp
    roller/trunk/apps/weblogger/web/WEB-INF/jsps/editor/MediaFileEditSuccess.jsp
    roller/trunk/apps/weblogger/web/WEB-INF/jsps/editor/MediaFileView.jsp

Modified: roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/jpa/JPAMediaFileManagerImpl.java
URL: http://svn.apache.org/viewvc/roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/jpa/JPAMediaFileManagerImpl.java?rev=828904&r1=828903&r2=828904&view=diff
==============================================================================
--- roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/jpa/JPAMediaFileManagerImpl.java
(original)
+++ roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/jpa/JPAMediaFileManagerImpl.java
Fri Oct 23 00:44:22 2009
@@ -273,37 +273,43 @@
         cmgr.saveFileContent(weblog, mediaFile.getId(), mediaFile.getInputStream());
 
         if (mediaFile.isImageFile()) {
-            FileContent fc = cmgr.getFileContent(weblog, mediaFile.getId());
-            BufferedImage img = null;
-            try {
-                img = ImageIO.read(fc.getInputStream());
+            updateThumbnail(mediaFile);
+        }
+    }
 
-                // determine and save width and height
-                mediaFile.setWidth(img.getWidth());
-                mediaFile.setHeight(img.getHeight());
-                strategy.store(mediaFile);
+    private void updateThumbnail(MediaFile mediaFile) {
+        try {
+            FileContentManager cmgr = WebloggerFactory.getWeblogger().getFileContentManager();
+            FileContent fc = cmgr.getFileContent(mediaFile.getWeblog(), mediaFile.getId());
+            BufferedImage img = null;
+            
+            img = ImageIO.read(fc.getInputStream());
 
-                int newWidth = mediaFile.getThumbnailWidth();
-                int newHeight = mediaFile.getThumbnailHeight();
-                
-                // create thumbnail image
-                Image newImage = img.getScaledInstance(
-                        newWidth, newHeight, Image.SCALE_SMOOTH);
-                BufferedImage tmp = new BufferedImage(
-                        newWidth, newHeight, BufferedImage.TYPE_INT_ARGB);
-                Graphics2D g2 = tmp.createGraphics();
-                g2.drawImage(newImage, 0, 0, newWidth, newHeight, null);
-                g2.dispose();
+            // determine and save width and height
+            mediaFile.setWidth(img.getWidth());
+            mediaFile.setHeight(img.getHeight());
+            strategy.store(mediaFile);
+
+            int newWidth = mediaFile.getThumbnailWidth();
+            int newHeight = mediaFile.getThumbnailHeight();
+
+            // create thumbnail image
+            Image newImage = img.getScaledInstance(
+                    newWidth, newHeight, Image.SCALE_SMOOTH);
+            BufferedImage tmp = new BufferedImage(
+                    newWidth, newHeight, BufferedImage.TYPE_INT_ARGB);
+            Graphics2D g2 = tmp.createGraphics();
+            g2.drawImage(newImage, 0, 0, newWidth, newHeight, null);
+            g2.dispose();
 
-                ByteArrayOutputStream baos = new ByteArrayOutputStream();
-                ImageIO.write(tmp, "png", baos);
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            ImageIO.write(tmp, "png", baos);
 
-                cmgr.saveFileContent(weblog, mediaFile.getId() + "_sm",
-                    new ByteArrayInputStream(baos.toByteArray()));
+            cmgr.saveFileContent(mediaFile.getWeblog(), mediaFile.getId() + "_sm",
+                new ByteArrayInputStream(baos.toByteArray()));
 
-            } catch (Exception e) {
-                log.debug("ERROR creating thumbnail", e);
-            }
+        } catch (Exception e) {
+            log.debug("ERROR creating thumbnail", e);
         }
     }
 
@@ -332,7 +338,11 @@
         if (!cmgr.canSave(weblog, mediaFile.getName(), mediaFile.getContentType(), mediaFile.getLength(),
msgs)) {
             throw new FileIOException(msgs.toString());
         }
-        cmgr.saveFileContent(weblog, mediaFile.getId(), mediaFile.getInputStream());
+        cmgr.saveFileContent(weblog, mediaFile.getId(), is);
+
+        if (mediaFile.isImageFile()) {
+            updateThumbnail(mediaFile);
+        }
     }
 
     /**

Modified: roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileAdd.java
URL: http://svn.apache.org/viewvc/roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileAdd.java?rev=828904&r1=828903&r2=828904&view=diff
==============================================================================
--- roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileAdd.java
(original)
+++ roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileAdd.java
Fri Oct 23 00:44:22 2009
@@ -24,7 +24,6 @@
 import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Map;
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;

Modified: roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileEdit.java
URL: http://svn.apache.org/viewvc/roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileEdit.java?rev=828904&r1=828903&r2=828904&view=diff
==============================================================================
--- roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileEdit.java
(original)
+++ roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileEdit.java
Fri Oct 23 00:44:22 2009
@@ -17,6 +17,8 @@
  */
 package org.apache.roller.weblogger.ui.struts2.editor;
 
+import java.io.File;
+import java.io.FileInputStream;
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -38,6 +40,15 @@
     private MediaFileBean bean = new MediaFileBean();
     private MediaFileDirectory directory;
 
+    // file uploaded by the user, if applicable
+    private File uploadedFile = null;
+
+    // content types for upload file
+    private String uploadedFileContentType = null;
+
+    // filename for uploaded file 
+    private String uploadedFileName = null;
+
 
     public MediaFileEdit() {
         this.actionName = "mediaFileEdit";
@@ -107,8 +118,18 @@
             try {
                 MediaFile mediaFile = manager.getMediaFile(getMediaFileId());
                 bean.copyTo(mediaFile);
-                manager.updateMediaFile(getActionWeblog(), mediaFile);
+
+                if (uploadedFile != null) {
+                    mediaFile.setLength(this.uploadedFile.length());
+                    mediaFile.setContentType(this.uploadedFileContentType);
+                    manager.updateMediaFile(getActionWeblog(),
+                        mediaFile, new FileInputStream(this.uploadedFile));
+                } else {
+                   manager.updateMediaFile(getActionWeblog(), mediaFile);
+                }
+
                 WebloggerFactory.getWeblogger().flush();
+
                 addMessage("mediaFile.update.success");
                 return SUCCESS;
 
@@ -140,4 +161,46 @@
     public void setDirectory(MediaFileDirectory directory) {
         this.directory = directory;
     }
+
+    /**
+     * @return the uploadedFile
+     */
+    public File getUploadedFile() {
+        return uploadedFile;
+    }
+
+    /**
+     * @param uploadedFile the uploadedFile to set
+     */
+    public void setUploadedFile(File uploadedFile) {
+        this.uploadedFile = uploadedFile;
+    }
+
+    /**
+     * @return the uploadedFileContentType
+     */
+    public String getUploadedFileContentType() {
+        return uploadedFileContentType;
+    }
+
+    /**
+     * @param uploadedFileContentType the uploadedFileContentType to set
+     */
+    public void setUploadedFileContentType(String uploadedFileContentType) {
+        this.uploadedFileContentType = uploadedFileContentType;
+    }
+
+    /**
+     * @return the uploadedFileName
+     */
+    public String getUploadedFileName() {
+        return uploadedFileName;
+    }
+
+    /**
+     * @param uploadedFileName the uploadedFileName to set
+     */
+    public void setUploadedFileName(String uploadedFileName) {
+        this.uploadedFileName = uploadedFileName;
+    }
 }

Modified: roller/trunk/apps/weblogger/web/WEB-INF/classes/ApplicationResources.properties
URL: http://svn.apache.org/viewvc/roller/trunk/apps/weblogger/web/WEB-INF/classes/ApplicationResources.properties?rev=828904&r1=828903&r2=828904&view=diff
==============================================================================
--- roller/trunk/apps/weblogger/web/WEB-INF/classes/ApplicationResources.properties (original)
+++ roller/trunk/apps/weblogger/web/WEB-INF/classes/ApplicationResources.properties Fri Oct
23 00:44:22 2009
@@ -1042,6 +1042,7 @@
 mediaFileEdit.includeGallery=Include in Gallery?
 mediaFileEdit.includeGalleryHelp=Check this box if you would like this media \
 file included in the new media file RSS and Atom feeds for your weblog.
+mediaFileEdit.updateFileContents=Update File Contents
 
 mediaFile.createWeblogPost=Post in weblog
 mediaFile.createPodcastPost=Post in weblog as podcast

Modified: roller/trunk/apps/weblogger/web/WEB-INF/jsps/editor/MediaFileEdit.jsp
URL: http://svn.apache.org/viewvc/roller/trunk/apps/weblogger/web/WEB-INF/jsps/editor/MediaFileEdit.jsp?rev=828904&r1=828903&r2=828904&view=diff
==============================================================================
--- roller/trunk/apps/weblogger/web/WEB-INF/jsps/editor/MediaFileEdit.jsp (original)
+++ roller/trunk/apps/weblogger/web/WEB-INF/jsps/editor/MediaFileEdit.jsp Fri Oct 23 00:44:22
2009
@@ -34,7 +34,7 @@
     <s:text name="mediaFileEdit.pagetip"  />
 </p>
 
-<s:form id="entry" action="mediaFileEdit!save" method="POST">
+<s:form id="entry" action="mediaFileEdit!save" method="POST" enctype="multipart/form-data">
     <s:hidden name="weblog" />
     <s:hidden name="mediaFileId" id="mediaFileId" />
     <s:hidden name="bean.permalink" />
@@ -119,13 +119,25 @@
             </td>
        </tr>
 
+        <tr>
+            <td class="entryEditFormLabel">
+                <label for="title"><s:text name="mediaFileEdit.updateFileContents"
/></label>
+            </td>
+            <td>
+                <div id="fileControldiv" class="miscControl">
+                    <s:file id="fileControl" name="uploadedFile" size="30" />
+                    <br />
+                </div>
+            </td>
+        </tr>
+
     </table>
 
     <div class="control">
        <input type="submit" tabindex="7"
               value="<s:text name="mediaFileEdit.save" />" name="submit" />
        <input type="button" tabindex="8"
-              value="<s:text name="mediaFileEdit.cancel" />" onClick="javascript:window.parent.onClose();"
/>
+              value="<s:text name="mediaFileEdit.cancel" />" onClick="javascript:window.parent.onEditCancelled();"
/>
     </div>
 
 </s:form>

Modified: roller/trunk/apps/weblogger/web/WEB-INF/jsps/editor/MediaFileEditSuccess.jsp
URL: http://svn.apache.org/viewvc/roller/trunk/apps/weblogger/web/WEB-INF/jsps/editor/MediaFileEditSuccess.jsp?rev=828904&r1=828903&r2=828904&view=diff
==============================================================================
--- roller/trunk/apps/weblogger/web/WEB-INF/jsps/editor/MediaFileEditSuccess.jsp (original)
+++ roller/trunk/apps/weblogger/web/WEB-INF/jsps/editor/MediaFileEditSuccess.jsp Fri Oct 23
00:44:22 2009
@@ -18,5 +18,5 @@
 <%@ include file="/WEB-INF/jsps/taglibs-struts2.jsp" %>
 
 <script type="text/javascript">
-parent.onClose();
+parent.onEditSuccess();
 </script>

Modified: roller/trunk/apps/weblogger/web/WEB-INF/jsps/editor/MediaFileView.jsp
URL: http://svn.apache.org/viewvc/roller/trunk/apps/weblogger/web/WEB-INF/jsps/editor/MediaFileView.jsp?rev=828904&r1=828903&r2=828904&view=diff
==============================================================================
--- roller/trunk/apps/weblogger/web/WEB-INF/jsps/editor/MediaFileView.jsp (original)
+++ roller/trunk/apps/weblogger/web/WEB-INF/jsps/editor/MediaFileView.jsp Fri Oct 23 00:44:22
2009
@@ -91,6 +91,8 @@
         }
     }
 
+    <%-- menu button for each image, launched from the plus sign image --%>
+
     var menuButtons = {};
 
     function setupMenuButton(id) {
@@ -118,8 +120,47 @@
         $("#createPostForm").get(0).submit();
     }
 
+
+    <%-- launch modal "lightbox" Media File Edit page --%>
+
+    function onClickEdit(mediaFileId) {
+        <s:url id="mediaFileEditURL" action="mediaFileEdit">
+            <s:param name="weblog" value="%{actionWeblog.handle}" />
+        </s:url>
+        $("#mediaFileEditor").attr('src',
+            '<s:property value="%{mediaFileEditURL}" />' + '&mediaFileId=' + mediaFileId);
+        YAHOO.mediaFileEditor.lightbox.show();
+    }
+
+    function onEditSuccess() {
+        $("#mediaFileEditor").attr('src','about:blank');
+        YAHOO.mediaFileEditor.lightbox.hide();
+        window.location.reload();
+    }
+
+    function onEditCancelled() {
+        $("#mediaFileEditor").attr('src','about:blank');
+        YAHOO.mediaFileEditor.lightbox.hide();
+    }
+
+    YAHOO.namespace("mediaFileEditor");
+    $(document).ready(function() {
+        YAHOO.mediaFileEditor.lightbox = new YAHOO.widget.Panel(
+            "mediafile_edit_lightbox", {
+                modal:    true,
+                width:   "600px",
+                height:  "600px",
+                visible: false,
+                fixedcenter: true,
+                constraintoviewport: true
+            }
+        );
+        YAHOO.mediaFileEditor.lightbox.render(document.body);
+    });
+
 </script>
 
+
 <s:form id="createPostForm" action='entryAddWithMediaFile'>
     <input type="hidden" name="weblog" value='<s:property value="actionWeblog.handle"
/>' />
     <input type="hidden" name="selectedImage" id="selectedImage" />
@@ -458,43 +499,6 @@
 </script>
 
 
-<%-- ***************************************************************** --%>
-
-<%-- code to launch Media File Edit lightbox when user clicks a media file --%>
-
-<script type="text/javascript">
-
-    function onClickEdit(mediaFileId) {
-        <s:url id="mediaFileEditURL" action="mediaFileEdit">
-            <s:param name="weblog" value="%{actionWeblog.handle}" />
-        </s:url>
-        $("#mediaFileEditor").attr('src',
-            '<s:property value="%{mediaFileEditURL}" />' + '&mediaFileId=' + mediaFileId);
-        YAHOO.mediaFileEditor.lightbox.show();
-    }
-
-    function onClose() {
-        $("#mediaFileEditor").attr('src','about:blank');
-        YAHOO.mediaFileEditor.lightbox.hide();
-    }
-
-    YAHOO.namespace("mediaFileEditor");
-    $(document).ready(function() {
-        YAHOO.mediaFileEditor.lightbox = new YAHOO.widget.Panel(
-            "mediafile_edit_lightbox", {
-                modal:    true,
-                width:   "600px",
-                height:  "600px",
-                visible: false,
-                fixedcenter: true,
-                constraintoviewport: true
-            }
-        );
-        YAHOO.mediaFileEditor.lightbox.render(document.body);
-    });
-
-</script>
-
 <div id="mediafile_edit_lightbox" style="visibility:hidden">
     <div class="hd">Media File Editor</div>
     <div class="bd">



Mime
View raw message