roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ghu...@apache.org
Subject svn commit: r1465469 - in /roller/trunk: weblogger-business/src/main/java/org/apache/roller/weblogger/business/ weblogger-business/src/main/java/org/apache/roller/weblogger/business/jpa/ weblogger-business/src/main/java/org/apache/roller/weblogger/pojo...
Date Sun, 07 Apr 2013 21:28:40 GMT
Author: ghuber
Date: Sun Apr  7 21:28:40 2013
New Revision: 1465469

URL: http://svn.apache.org/r1465469
Log:
Media file tags not updating correctly.  Based on weblog entry tags logic.

Modified:
    roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/business/MediaFileManager.java
    roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/business/jpa/JPAMediaFileManagerImpl.java
    roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/pojos/MediaFile.java
    roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/pojos/MediaFileTag.java
    roller/trunk/weblogger-business/src/main/resources/org/apache/roller/weblogger/pojos/MediaFile.orm.xml
    roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileBean.java
    roller/trunk/weblogger-webapp/src/main/webapp/WEB-INF/jsps/editor/MediaFileAdd.jsp
    roller/trunk/weblogger-webapp/src/main/webapp/WEB-INF/jsps/editor/MediaFileEdit.jsp

Modified: roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/business/MediaFileManager.java
URL: http://svn.apache.org/viewvc/roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/business/MediaFileManager.java?rev=1465469&r1=1465468&r2=1465469&view=diff
==============================================================================
--- roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/business/MediaFileManager.java (original)
+++ roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/business/MediaFileManager.java Sun Apr  7 21:28:40 2013
@@ -26,6 +26,7 @@ import org.apache.roller.weblogger.pojos
 import org.apache.roller.weblogger.pojos.MediaFileDirectory;
 import org.apache.roller.weblogger.pojos.MediaFileFilter;
 import org.apache.roller.weblogger.pojos.Weblog;
+import org.apache.roller.weblogger.pojos.WeblogEntry;
 import org.apache.roller.weblogger.util.RollerMessages;
 
 /**
@@ -49,8 +50,8 @@ public interface MediaFileManager {
     /**
      * Create a media file
      */
-    public void createMediaFile(Weblog weblog, MediaFile mediaFile, RollerMessages errors)
-            throws WebloggerException;
+    public void createMediaFile(Weblog weblog, MediaFile mediaFile,
+            RollerMessages errors) throws WebloggerException;
 
     /**
      * Update metadata for a media file
@@ -61,8 +62,8 @@ public interface MediaFileManager {
     /**
      * Update metadata for a media file and content.
      */
-    public void updateMediaFile(Weblog website,
-            MediaFile mf, InputStream fis) throws WebloggerException;
+    public void updateMediaFile(Weblog website, MediaFile mf, InputStream fis)
+            throws WebloggerException;
 
     /**
      * Get media file metadata by file id
@@ -84,8 +85,8 @@ public interface MediaFileManager {
     /**
      * Search for media files based on the filter criteria
      */
-    public List<MediaFile> searchMediaFiles(Weblog weblog, MediaFileFilter filter)
-            throws WebloggerException;
+    public List<MediaFile> searchMediaFiles(Weblog weblog,
+            MediaFileFilter filter) throws WebloggerException;
 
     /**
      * Create root directory for media files in a weblog.
@@ -109,8 +110,8 @@ public interface MediaFileManager {
     /**
      * Create a media file directory given its path
      */
-    public MediaFileDirectory createMediaFileDirectoryByPath(
-            Weblog weblog, String path) throws WebloggerException;
+    public MediaFileDirectory createMediaFileDirectoryByPath(Weblog weblog,
+            String path) throws WebloggerException;
 
     /**
      * Get media file directory by id
@@ -121,8 +122,8 @@ public interface MediaFileManager {
     /**
      * Get media file directory by its path
      */
-    public MediaFileDirectory getMediaFileDirectoryByPath(
-            Weblog weblog, String path) throws WebloggerException;
+    public MediaFileDirectory getMediaFileDirectoryByPath(Weblog weblog,
+            String path) throws WebloggerException;
 
     /**
      * Get media file by path.
@@ -131,9 +132,8 @@ public interface MediaFileManager {
             throws WebloggerException;
 
     /**
-     * Get media file by the original path by which it was stored.
-     * Required for support of old upload file URLs and for theme resources.
-     * {@inheritDoc}
+     * Get media file by the original path by which it was stored. Required for
+     * support of old upload file URLs and for theme resources. {@inheritDoc}
      */
     public MediaFile getMediaFileByOriginalPath(Weblog weblog, String origpath)
             throws WebloggerException;
@@ -153,49 +153,57 @@ public interface MediaFileManager {
     /**
      * Move a set of media files to a new directory.
      */
-    public void moveMediaFiles(
-            Collection<MediaFile> mediaFiles, MediaFileDirectory directory)
-            throws WebloggerException;
+    public void moveMediaFiles(Collection<MediaFile> mediaFiles,
+            MediaFileDirectory directory) throws WebloggerException;
 
     /**
      * Move one media file to a new directory.
      */
-    public void moveMediaFile(
-            MediaFile mediaFile, MediaFileDirectory directory)
+    public void moveMediaFile(MediaFile mediaFile, MediaFileDirectory directory)
             throws WebloggerException;
 
     /**
      * Move a set of media files to a new directory.
      */
     public void moveMediaFileDirectories(
-            Collection<MediaFileDirectory> mediaFilesDir, MediaFileDirectory directory)
-            throws WebloggerException;
+            Collection<MediaFileDirectory> mediaFilesDir,
+            MediaFileDirectory directory) throws WebloggerException;
 
     /**
      * Move one media file to a new directory.
      */
-    public void moveMediaFileDirectory(
-            MediaFileDirectory mediaFileDir, MediaFileDirectory directory)
-            throws WebloggerException;
+    public void moveMediaFileDirectory(MediaFileDirectory mediaFileDir,
+            MediaFileDirectory directory) throws WebloggerException;
 
     /**
      * Return recently added media files that are public.
      */
     public List<MediaFile> fetchRecentPublicMediaFiles(int length)
             throws WebloggerException;
-    
+
     /**
      * Remove all media files associated with a weblog.
+     * 
      * @param website
      */
     public void removeAllFiles(Weblog website) throws WebloggerException;
 
     /**
      * Remove media file directory
+     * 
      * @param weblog
      * @param mediaFileDir
      */
     public void removeMediaFileDirectory(MediaFileDirectory mediaFileDir)
             throws WebloggerException;
 
+    /**
+     * Remove tag with given name from given MediaFile
+     * 
+     * @param name
+     *            Name of tag to be removed
+     */
+    public void removeMediaFileTag(String name, MediaFile entry)
+            throws WebloggerException;
+
 }

Modified: roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/business/jpa/JPAMediaFileManagerImpl.java
URL: http://svn.apache.org/viewvc/roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/business/jpa/JPAMediaFileManagerImpl.java?rev=1465469&r1=1465468&r2=1465469&view=diff
==============================================================================
--- roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/business/jpa/JPAMediaFileManagerImpl.java (original)
+++ roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/business/jpa/JPAMediaFileManagerImpl.java Sun Apr  7 21:28:40 2013
@@ -32,6 +32,7 @@ import java.sql.Timestamp;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.Iterator;
 import java.util.List;
 
 import java.util.Properties;
@@ -50,9 +51,12 @@ import org.apache.roller.weblogger.pojos
 import org.apache.roller.weblogger.pojos.MediaFile;
 import org.apache.roller.weblogger.pojos.MediaFileDirectory;
 import org.apache.roller.weblogger.pojos.MediaFileFilter;
+import org.apache.roller.weblogger.pojos.MediaFileTag;
 import org.apache.roller.weblogger.pojos.MediaFileType;
 import org.apache.roller.weblogger.pojos.User;
 import org.apache.roller.weblogger.pojos.Weblog;
+import org.apache.roller.weblogger.pojos.WeblogEntry;
+import org.apache.roller.weblogger.pojos.WeblogEntryTag;
 import org.apache.roller.weblogger.util.RollerMessages;
 import org.apache.roller.weblogger.util.Utilities;
 
@@ -61,24 +65,27 @@ public class JPAMediaFileManagerImpl imp
 
     private final Weblogger roller;
     private final JPAPersistenceStrategy strategy;
-    private static Log log =
-            LogFactory.getFactory().getInstance(JPAMediaFileManagerImpl.class);
+    private static Log log = LogFactory.getFactory().getInstance(
+            JPAMediaFileManagerImpl.class);
     public static final String MIGRATION_STATUS_FILENAME = "migration-status.properties";
 
     /**
      * Creates a new instance of MediaFileManagerImpl
      */
     @com.google.inject.Inject
-    protected JPAMediaFileManagerImpl(Weblogger roller, JPAPersistenceStrategy persistenceStrategy) {
+    protected JPAMediaFileManagerImpl(Weblogger roller,
+            JPAPersistenceStrategy persistenceStrategy) {
         this.roller = roller;
         this.strategy = persistenceStrategy;
     }
 
     /**
-     * Initialize manager; deal with upgrade/migration if 'uploads.migrate.auto' is true.
+     * Initialize manager; deal with upgrade/migration if 'uploads.migrate.auto'
+     * is true.
      */
     public void initialize() {
-        boolean autoUpgrade = WebloggerConfig.getBooleanProperty("uploads.migrate.auto");
+        boolean autoUpgrade = WebloggerConfig
+                .getBooleanProperty("uploads.migrate.auto");
         if (autoUpgrade && this.isFileStorageUpgradeRequired()) {
             this.upgradeFileStorage();
         }
@@ -93,26 +100,27 @@ public class JPAMediaFileManagerImpl imp
     /**
      * {@inheritDoc}
      */
-    public void moveMediaFileDirectories(Collection<MediaFileDirectory> mediaFileDirs, MediaFileDirectory targetDir)
-            throws WebloggerException {
+    public void moveMediaFileDirectories(
+            Collection<MediaFileDirectory> mediaFileDirs,
+            MediaFileDirectory targetDir) throws WebloggerException {
 
         for (MediaFileDirectory mediaFileDir : mediaFileDirs) {
             mediaFileDir.setParent(targetDir);
             this.strategy.store(mediaFileDir);
         }
-        // update weblog last modified date.  date updated by saveWebsite()
+        // update weblog last modified date. date updated by saveWebsite()
         roller.getWeblogManager().saveWeblog(targetDir.getWeblog());
     }
 
     /**
      * {@inheritDoc}
      */
-    public void moveMediaFiles(Collection<MediaFile> mediaFiles, MediaFileDirectory targetDirectory)
-            throws WebloggerException {
+    public void moveMediaFiles(Collection<MediaFile> mediaFiles,
+            MediaFileDirectory targetDirectory) throws WebloggerException {
 
         List<MediaFile> moved = new ArrayList<MediaFile>();
         moved.addAll(mediaFiles);
-        
+
         for (MediaFile mediaFile : moved) {
             mediaFile.getDirectory().getMediaFiles().remove(mediaFile);
 
@@ -122,39 +130,41 @@ public class JPAMediaFileManagerImpl imp
             targetDirectory.getMediaFiles().add(mediaFile);
             this.strategy.store(targetDirectory);
         }
-        // update weblog last modified date.  date updated by saveWebsite()
+        // update weblog last modified date. date updated by saveWebsite()
         roller.getWeblogManager().saveWeblog(targetDirectory.getWeblog());
     }
 
     /**
      * {@inheritDoc}
      */
-    public void moveMediaFile(MediaFile mediaFile, MediaFileDirectory targetDirectory)
-            throws WebloggerException {
+    public void moveMediaFile(MediaFile mediaFile,
+            MediaFileDirectory targetDirectory) throws WebloggerException {
         moveMediaFiles(Arrays.asList(mediaFile), targetDirectory);
     }
 
     /**
      * {@inheritDoc}
      */
-    public void moveMediaFileDirectory(MediaFileDirectory mediaFileDir, MediaFileDirectory targetDirectory)
-            throws WebloggerException {
+    public void moveMediaFileDirectory(MediaFileDirectory mediaFileDir,
+            MediaFileDirectory targetDirectory) throws WebloggerException {
         moveMediaFileDirectories(Arrays.asList(mediaFileDir), targetDirectory);
     }
 
     /**
      * {@inheritDoc}
      */
-    public MediaFileDirectory createMediaFileDirectory(MediaFileDirectory parentDirectory, String newDirName)
+    public MediaFileDirectory createMediaFileDirectory(
+            MediaFileDirectory parentDirectory, String newDirName)
             throws WebloggerException {
 
         if (parentDirectory.hasDirectory(newDirName)) {
             throw new WebloggerException("Directory exists");
         }
 
-        MediaFileDirectory newDirectory = parentDirectory.createNewDirectory(newDirName);
+        MediaFileDirectory newDirectory = parentDirectory
+                .createNewDirectory(newDirName);
 
-        // update weblog last modified date.  date updated by saveWeblog()
+        // update weblog last modified date. date updated by saveWeblog()
         roller.getWeblogManager().saveWeblog(newDirectory.getWeblog());
 
         return newDirectory;
@@ -167,15 +177,15 @@ public class JPAMediaFileManagerImpl imp
             throws WebloggerException {
         this.strategy.store(directory);
 
-        // update weblog last modified date.  date updated by saveWebsite()
+        // update weblog last modified date. date updated by saveWebsite()
         roller.getWeblogManager().saveWeblog(directory.getWeblog());
     }
 
     /**
      * {@inheritDoc}
      */
-    public MediaFileDirectory createMediaFileDirectoryByPath(Weblog weblog, String requestedPath)
-            throws WebloggerException {
+    public MediaFileDirectory createMediaFileDirectoryByPath(Weblog weblog,
+            String requestedPath) throws WebloggerException {
 
         String path = requestedPath;
         log.debug("Creating dir: " + path);
@@ -224,7 +234,8 @@ public class JPAMediaFileManagerImpl imp
                 } else {
                     pathpart += token;
                 }
-                MediaFileDirectory possibleBase = getMediaFileDirectoryByPath(weblog, pathpart);
+                MediaFileDirectory possibleBase = getMediaFileDirectoryByPath(
+                        weblog, pathpart);
                 if (possibleBase == null) {
                     base = base.createNewDirectory(token);
                     log.debug("   Created new directory: " + base.getPath());
@@ -240,7 +251,7 @@ public class JPAMediaFileManagerImpl imp
             newDirectory = base;
         }
 
-        // update weblog last modified date.  date updated by saveWeblog()
+        // update weblog last modified date. date updated by saveWeblog()
         roller.getWeblogManager().saveWeblog(weblog);
 
         return newDirectory;
@@ -251,7 +262,8 @@ public class JPAMediaFileManagerImpl imp
      */
     public MediaFileDirectory createRootMediaFileDirectory(Weblog weblog)
             throws WebloggerException {
-        MediaFileDirectory rootDirectory = new MediaFileDirectory(null, "root", "root directory", weblog);
+        MediaFileDirectory rootDirectory = new MediaFileDirectory(null, "root",
+                "root directory", weblog);
         createMediaFileDirectory(rootDirectory);
         return rootDirectory;
     }
@@ -259,18 +271,22 @@ public class JPAMediaFileManagerImpl imp
     /**
      * {@inheritDoc}
      */
-    public void createMediaFile(Weblog weblog, MediaFile mediaFile, RollerMessages errors) throws WebloggerException {
+    public void createMediaFile(Weblog weblog, MediaFile mediaFile,
+            RollerMessages errors) throws WebloggerException {
 
-        FileContentManager cmgr = WebloggerFactory.getWeblogger().getFileContentManager();
-        if (!cmgr.canSave(weblog, mediaFile.getName(), mediaFile.getContentType(), mediaFile.getLength(), errors)) {
+        FileContentManager cmgr = WebloggerFactory.getWeblogger()
+                .getFileContentManager();
+        if (!cmgr.canSave(weblog, mediaFile.getName(),
+                mediaFile.getContentType(), mediaFile.getLength(), errors)) {
             return;
         }
         strategy.store(mediaFile);
 
-        // update weblog last modified date.  date updated by saveWeblog()
+        // update weblog last modified date. date updated by saveWeblog()
         roller.getWeblogManager().saveWeblog(weblog);
 
-        cmgr.saveFileContent(weblog, mediaFile.getId(), mediaFile.getInputStream());
+        cmgr.saveFileContent(weblog, mediaFile.getId(),
+                mediaFile.getInputStream());
 
         if (mediaFile.isImageFile()) {
             updateThumbnail(mediaFile);
@@ -279,8 +295,10 @@ public class JPAMediaFileManagerImpl imp
 
     private void updateThumbnail(MediaFile mediaFile) {
         try {
-            FileContentManager cmgr = WebloggerFactory.getWeblogger().getFileContentManager();
-            FileContent fc = cmgr.getFileContent(mediaFile.getWeblog(), mediaFile.getId());
+            FileContentManager cmgr = WebloggerFactory.getWeblogger()
+                    .getFileContentManager();
+            FileContent fc = cmgr.getFileContent(mediaFile.getWeblog(),
+                    mediaFile.getId());
             BufferedImage img = null;
 
             img = ImageIO.read(fc.getInputStream());
@@ -294,10 +312,10 @@ public class JPAMediaFileManagerImpl imp
             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);
+            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();
@@ -305,8 +323,8 @@ public class JPAMediaFileManagerImpl imp
             ByteArrayOutputStream baos = new ByteArrayOutputStream();
             ImageIO.write(tmp, "png", baos);
 
-            cmgr.saveFileContent(mediaFile.getWeblog(), 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);
@@ -316,26 +334,30 @@ public class JPAMediaFileManagerImpl imp
     /**
      * {@inheritDoc}
      */
-    public void updateMediaFile(Weblog weblog, MediaFile mediaFile) throws WebloggerException {
+    public void updateMediaFile(Weblog weblog, MediaFile mediaFile)
+            throws WebloggerException {
         mediaFile.setLastUpdated(new Timestamp(System.currentTimeMillis()));
         strategy.store(mediaFile);
-        // update weblog last modified date.  date updated by saveWeblog()
+        // update weblog last modified date. date updated by saveWeblog()
         roller.getWeblogManager().saveWeblog(weblog);
     }
 
     /**
      * {@inheritDoc}
      */
-    public void updateMediaFile(Weblog weblog, MediaFile mediaFile, InputStream is) throws WebloggerException {
+    public void updateMediaFile(Weblog weblog, MediaFile mediaFile,
+            InputStream is) throws WebloggerException {
         mediaFile.setLastUpdated(new Timestamp(System.currentTimeMillis()));
         strategy.store(mediaFile);
 
-        // update weblog last modified date.  date updated by saveWeblog()
+        // update weblog last modified date. date updated by saveWeblog()
         roller.getWeblogManager().saveWeblog(weblog);
 
-        FileContentManager cmgr = WebloggerFactory.getWeblogger().getFileContentManager();
+        FileContentManager cmgr = WebloggerFactory.getWeblogger()
+                .getFileContentManager();
         RollerMessages msgs = new RollerMessages();
-        if (!cmgr.canSave(weblog, mediaFile.getName(), mediaFile.getContentType(), mediaFile.getLength(), msgs)) {
+        if (!cmgr.canSave(weblog, mediaFile.getName(),
+                mediaFile.getContentType(), mediaFile.getLength(), msgs)) {
             throw new FileIOException(msgs.toString());
         }
         cmgr.saveFileContent(weblog, mediaFile.getId(), is);
@@ -355,16 +377,21 @@ public class JPAMediaFileManagerImpl imp
     /**
      * {@inheritDoc}
      */
-    public MediaFile getMediaFile(String id, boolean includeContent) throws WebloggerException {
-        MediaFile mediaFile = (MediaFile) this.strategy.load(MediaFile.class, id);
+    public MediaFile getMediaFile(String id, boolean includeContent)
+            throws WebloggerException {
+        MediaFile mediaFile = (MediaFile) this.strategy.load(MediaFile.class,
+                id);
         if (includeContent) {
-            FileContentManager cmgr = WebloggerFactory.getWeblogger().getFileContentManager();
+            FileContentManager cmgr = WebloggerFactory.getWeblogger()
+                    .getFileContentManager();
 
-            FileContent content = cmgr.getFileContent(mediaFile.getDirectory().getWeblog(), id);
+            FileContent content = cmgr.getFileContent(mediaFile.getDirectory()
+                    .getWeblog(), id);
             mediaFile.setContent(content);
 
             try {
-                FileContent thumbnail = cmgr.getFileContent(mediaFile.getDirectory().getWeblog(), id + "_sm");
+                FileContent thumbnail = cmgr.getFileContent(mediaFile
+                        .getDirectory().getWeblog(), id + "_sm");
                 mediaFile.setThumbnailContent(thumbnail);
 
             } catch (Exception e) {
@@ -381,15 +408,15 @@ public class JPAMediaFileManagerImpl imp
     /**
      * {@inheritDoc}
      */
-    public MediaFileDirectory getMediaFileDirectoryByPath(Weblog weblog, String path)
-            throws WebloggerException {
+    public MediaFileDirectory getMediaFileDirectoryByPath(Weblog weblog,
+            String path) throws WebloggerException {
 
         path = !path.startsWith("/") ? "/" + path : path;
 
         log.debug("Looking up weblog|path: " + weblog.getHandle() + "|" + path);
 
-        Query q = this.strategy.getNamedQuery(
-                "MediaFileDirectory.getByWeblogAndPath");
+        Query q = this.strategy
+                .getNamedQuery("MediaFileDirectory.getByWeblogAndPath");
         q.setParameter(1, weblog);
         q.setParameter(2, path);
         try {
@@ -425,15 +452,16 @@ public class JPAMediaFileManagerImpl imp
      */
     public MediaFile getMediaFileByOriginalPath(Weblog weblog, String origpath)
             throws WebloggerException {
-                
-        if (null == origpath) return null;
+
+        if (null == origpath)
+            return null;
 
         if (!origpath.startsWith("/")) {
             origpath = "/" + origpath;
         }
 
-        Query q = this.strategy.getNamedQuery(
-                "MediaFile.getByWeblogAndOrigpath");
+        Query q = this.strategy
+                .getNamedQuery("MediaFile.getByWeblogAndOrigpath");
         q.setParameter(1, weblog);
         q.setParameter(2, origpath);
         MediaFile mf = null;
@@ -442,8 +470,10 @@ public class JPAMediaFileManagerImpl imp
         } catch (NoResultException e) {
             return null;
         }
-        FileContentManager cmgr = WebloggerFactory.getWeblogger().getFileContentManager();
-        FileContent content = cmgr.getFileContent(mf.getDirectory().getWeblog(), mf.getId());
+        FileContentManager cmgr = WebloggerFactory.getWeblogger()
+                .getFileContentManager();
+        FileContent content = cmgr.getFileContent(
+                mf.getDirectory().getWeblog(), mf.getId());
         mf.setContent(content);
         return mf;
     }
@@ -453,7 +483,8 @@ public class JPAMediaFileManagerImpl imp
      */
     public MediaFileDirectory getMediaFileDirectory(String id)
             throws WebloggerException {
-        return (MediaFileDirectory) this.strategy.load(MediaFileDirectory.class, id);
+        return (MediaFileDirectory) this.strategy.load(
+                MediaFileDirectory.class, id);
     }
 
     /**
@@ -461,7 +492,8 @@ public class JPAMediaFileManagerImpl imp
      */
     public MediaFileDirectory getMediaFileRootDirectory(Weblog weblog)
             throws WebloggerException {
-        Query q = this.strategy.getNamedQuery("MediaFileDirectory.getByWeblogAndNoParent");
+        Query q = this.strategy
+                .getNamedQuery("MediaFileDirectory.getByWeblogAndNoParent");
         q.setParameter(1, weblog);
         try {
             return (MediaFileDirectory) q.getSingleResult();
@@ -486,10 +518,11 @@ public class JPAMediaFileManagerImpl imp
      */
     public void removeMediaFile(Weblog weblog, MediaFile mediaFile)
             throws WebloggerException {
-        FileContentManager cmgr = WebloggerFactory.getWeblogger().getFileContentManager();
+        FileContentManager cmgr = WebloggerFactory.getWeblogger()
+                .getFileContentManager();
 
         this.strategy.remove(mediaFile);
-        // update weblog last modified date.  date updated by saveWeblog()
+        // update weblog last modified date. date updated by saveWeblog()
         roller.getWeblogManager().saveWeblog(weblog);
 
         try {
@@ -511,7 +544,8 @@ public class JPAMediaFileManagerImpl imp
         int size = 0;
         StringBuilder queryString = new StringBuilder();
 
-        queryString.append("SELECT m FROM MediaFile m WHERE m.sharedForGallery = true");
+        queryString
+                .append("SELECT m FROM MediaFile m WHERE m.sharedForGallery = true");
         queryString.append(" order by m.dateUploaded");
         Query query = strategy.getDynamicQuery(queryString.toString());
         query.setFirstResult(0);
@@ -522,8 +556,8 @@ public class JPAMediaFileManagerImpl imp
     /**
      * {@inheritDoc}
      */
-    public List<MediaFile> searchMediaFiles(Weblog weblog, MediaFileFilter filter)
-            throws WebloggerException {
+    public List<MediaFile> searchMediaFiles(Weblog weblog,
+            MediaFileFilter filter) throws WebloggerException {
 
         List<Object> params = new ArrayList<Object>();
         int size = 0;
@@ -550,30 +584,31 @@ public class JPAMediaFileManagerImpl imp
             params.add(size++, filter.getSize());
             whereClause.append(" AND m.length ");
             switch (filter.getSizeFilterType()) {
-                case GT:
-                    whereClause.append(">");
-                    break;
-                case GTE:
-                    whereClause.append(">=");
-                    break;
-                case EQ:
-                    whereClause.append("=");
-                    break;
-                case LT:
-                    whereClause.append("<");
-                    break;
-                case LTE:
-                    whereClause.append("<=");
-                    break;
-                default:
-                    whereClause.append("=");
-                    break;
+            case GT:
+                whereClause.append(">");
+                break;
+            case GTE:
+                whereClause.append(">=");
+                break;
+            case EQ:
+                whereClause.append("=");
+                break;
+            case LT:
+                whereClause.append("<");
+                break;
+            case LTE:
+                whereClause.append("<=");
+                break;
+            default:
+                whereClause.append("=");
+                break;
             }
             whereClause.append(" ?").append(size);
         }
 
         if (filter.getTags() != null && filter.getTags().size() > 1) {
-            whereClause.append(" AND EXISTS (SELECT t FROM MediaFileTag t WHERE t.mediaFile = m and t.name IN (");
+            whereClause
+                    .append(" AND EXISTS (SELECT t FROM MediaFileTag t WHERE t.mediaFile = m and t.name IN (");
             for (String tag : filter.getTags()) {
                 params.add(size++, tag);
                 whereClause.append("?").append(size).append(",");
@@ -582,7 +617,9 @@ public class JPAMediaFileManagerImpl imp
             whereClause.append("))");
         } else if (filter.getTags() != null && filter.getTags().size() == 1) {
             params.add(size++, filter.getTags().get(0));
-            whereClause.append(" AND EXISTS (SELECT t FROM MediaFileTag t WHERE t.mediaFile = m and t.name = ?").append(size).append(")");
+            whereClause
+                    .append(" AND EXISTS (SELECT t FROM MediaFileTag t WHERE t.mediaFile = m and t.name = ?")
+                    .append(size).append(")");
         }
 
         if (filter.getType() != null) {
@@ -590,33 +627,36 @@ public class JPAMediaFileManagerImpl imp
                 for (MediaFileType type : MediaFileType.values()) {
                     if (type != MediaFileType.OTHERS) {
                         params.add(size++, type.getContentTypePrefix() + "%");
-                        whereClause.append(" AND m.contentType not like ?").append(size);
+                        whereClause.append(" AND m.contentType not like ?")
+                                .append(size);
                     }
                 }
             } else {
-                params.add(size++, filter.getType().getContentTypePrefix() + "%");
+                params.add(size++, filter.getType().getContentTypePrefix()
+                        + "%");
                 whereClause.append(" AND m.contentType like ?").append(size);
             }
         }
 
         if (filter.getOrder() != null) {
             switch (filter.getOrder()) {
-                case NAME:
-                    orderBy.append(" order by m.name");
-                    break;
-                case DATE_UPLOADED:
-                    orderBy.append(" order by m.dateUploaded");
-                    break;
-                case TYPE:
-                    orderBy.append(" order by m.contentType");
-                    break;
-                default:
+            case NAME:
+                orderBy.append(" order by m.name");
+                break;
+            case DATE_UPLOADED:
+                orderBy.append(" order by m.dateUploaded");
+                break;
+            case TYPE:
+                orderBy.append(" order by m.contentType");
+                break;
+            default:
             }
         } else {
             orderBy.append(" order by m.name");
         }
 
-        Query query = strategy.getDynamicQuery(queryString.toString() + whereClause.toString() + orderBy.toString());
+        Query query = strategy.getDynamicQuery(queryString.toString()
+                + whereClause.toString() + orderBy.toString());
         for (int i = 0; i < params.size(); i++) {
             query.setParameter(i + 1, params.get(i));
         }
@@ -629,8 +669,8 @@ public class JPAMediaFileManagerImpl imp
     }
 
     /**
-     * Does mediafile storage require any upgrading;
-     * checks for existence of migration status file.
+     * Does mediafile storage require any upgrading; checks for existence of
+     * migration status file.
      */
     public boolean isFileStorageUpgradeRequired() {
         String uploadsDirName = WebloggerConfig.getProperty("uploads.dir");
@@ -673,13 +713,16 @@ public class JPAMediaFileManagerImpl imp
 
                         if (dirs[i].isDirectory()) {
                             WeblogManager wmgr = this.roller.getWeblogManager();
-                            Weblog weblog = wmgr.getWeblogByHandle(dirs[i].getName(), null);
+                            Weblog weblog = wmgr.getWeblogByHandle(
+                                    dirs[i].getName(), null);
                             if (weblog != null) {
 
-                                log.info("Migrating weblog: " + weblog.getHandle());
+                                log.info("Migrating weblog: "
+                                        + weblog.getHandle());
 
                                 // use 1st admin user found as file creator
-                                List<User> users = wmgr.getWeblogUsers(weblog, true);
+                                List<User> users = wmgr.getWeblogUsers(weblog,
+                                        true);
                                 User chosenUser = users.get(0);
                                 for (User user : users) {
                                     chosenUser = user;
@@ -689,18 +732,22 @@ public class JPAMediaFileManagerImpl imp
                                 }
 
                                 try {
-                                    // create weblog's mediafile directory if needed
-                                    MediaFileDirectory root =
-                                            this.getMediaFileRootDirectory(weblog);
+                                    // create weblog's mediafile directory if
+                                    // needed
+                                    MediaFileDirectory root = this
+                                            .getMediaFileRootDirectory(weblog);
                                     if (root == null) {
-                                        root = this.createRootMediaFileDirectory(weblog);
+                                        root = this
+                                                .createRootMediaFileDirectory(weblog);
                                         roller.flush();
                                     }
 
                                     // upgrade!
-                                    upgradeUploadsDir(weblog, chosenUser,
-                                            new File(oldDirName + FS + dirs[i].getName()),
-                                            root);
+                                    upgradeUploadsDir(
+                                            weblog,
+                                            chosenUser,
+                                            new File(oldDirName + FS
+                                                    + dirs[i].getName()), root);
 
                                 } catch (Throwable t) {
                                     log.error("ERROR upgading weblog", t);
@@ -712,9 +759,8 @@ public class JPAMediaFileManagerImpl imp
 
                 Properties props = new Properties();
                 props.setProperty("complete", "true");
-                props.store(new FileOutputStream(oldDirName
-                        + File.separator + MIGRATION_STATUS_FILENAME),
-                        "Migration is complete!");
+                props.store(new FileOutputStream(oldDirName + File.separator
+                        + MIGRATION_STATUS_FILENAME), "Migration is complete!");
 
             } catch (Exception ioex) {
                 log.error("ERROR upgrading", ioex);
@@ -724,7 +770,8 @@ public class JPAMediaFileManagerImpl imp
         return msgs;
     }
 
-    private void upgradeUploadsDir(Weblog weblog, User user, File oldDir, MediaFileDirectory newDir) {
+    private void upgradeUploadsDir(Weblog weblog, User user, File oldDir,
+            MediaFileDirectory newDir) {
         RollerMessages messages = new RollerMessages();
 
         log.debug("Upgrading dir: " + oldDir.getAbsolutePath());
@@ -752,7 +799,8 @@ public class JPAMediaFileManagerImpl imp
                     MediaFileDirectory subDir = null;
                     try {
                         subDir = newDir.createNewDirectory(files[i].getName());
-                        roller.getMediaFileManager().createMediaFileDirectory(subDir);
+                        roller.getMediaFileManager().createMediaFileDirectory(
+                                subDir);
                         newDir.getChildDirectories().add(subDir);
                         roller.flush();
                         dirCount++;
@@ -773,16 +821,18 @@ public class JPAMediaFileManagerImpl imp
 
                 } else {
 
-                    String originalPath =
-                            ("/".equals(newDir.getPath()) ? "" : newDir.getPath()) + "/" + files[i].getName();
-                    log.debug("    Upgrade file with original path: " + originalPath);
+                    String originalPath = ("/".equals(newDir.getPath()) ? ""
+                            : newDir.getPath()) + "/" + files[i].getName();
+                    log.debug("    Upgrade file with original path: "
+                            + originalPath);
                     MediaFile mf = new MediaFile();
                     try {
                         mf.setName(files[i].getName());
                         mf.setDescription(files[i].getName());
                         mf.setOriginalPath(originalPath);
 
-                        mf.setDateUploaded(new Timestamp(files[i].lastModified()));
+                        mf.setDateUploaded(new Timestamp(files[i]
+                                .lastModified()));
                         mf.setLastUpdated(new Timestamp(files[i].lastModified()));
 
                         mf.setDirectory(newDir);
@@ -792,10 +842,12 @@ public class JPAMediaFileManagerImpl imp
 
                         mf.setLength(files[i].length());
                         mf.setInputStream(new FileInputStream(files[i]));
-                        mf.setContentType(Utilities.getContentTypeFromFileName(files[i].getName()));
+                        mf.setContentType(Utilities
+                                .getContentTypeFromFileName(files[i].getName()));
                         newDir.getMediaFiles().add(mf);
 
-                        this.roller.getMediaFileManager().createMediaFile(weblog, mf, messages);
+                        this.roller.getMediaFileManager().createMediaFile(
+                                weblog, mf, messages);
                         log.info(messages.toString());
 
                         fileCount++;
@@ -805,14 +857,15 @@ public class JPAMediaFileManagerImpl imp
                                 + files[i].getAbsolutePath(), ex);
 
                     } catch (java.io.FileNotFoundException ex) {
-                        log.error("ERROR reading file from old storage system: "
-                                + files[i].getAbsolutePath(), ex);
+                        log.error(
+                                "ERROR reading file from old storage system: "
+                                        + files[i].getAbsolutePath(), ex);
                     }
                 }
             }
         }
 
-        try { // flush changes to this directory 
+        try { // flush changes to this directory
             roller.flush();
 
             log.debug("Count of dirs  created: " + dirCount);
@@ -832,7 +885,8 @@ public class JPAMediaFileManagerImpl imp
         if (dir == null) {
             return;
         }
-        FileContentManager cmgr = WebloggerFactory.getWeblogger().getFileContentManager();
+        FileContentManager cmgr = WebloggerFactory.getWeblogger()
+                .getFileContentManager();
         Set<MediaFile> files = dir.getMediaFiles();
         for (MediaFile mf : files) {
             try {
@@ -848,4 +902,23 @@ public class JPAMediaFileManagerImpl imp
         }
         this.strategy.remove(dir);
     }
+
+    public void removeMediaFileTag(String name, MediaFile entry)
+            throws WebloggerException {
+
+        for (Iterator it = entry.getTags().iterator(); it.hasNext();) {
+            MediaFileTag tag = (MediaFileTag) it.next();
+            if (tag.getName().equals(name)) {
+
+                // Call back the entity to adjust its internal state
+                entry.onRemoveTag(name);
+
+                // Remove it from database
+                this.strategy.remove(tag);
+
+                // Remove it from the collection
+                it.remove();
+            }
+        }
+    }
 }

Modified: roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/pojos/MediaFile.java
URL: http://svn.apache.org/viewvc/roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/pojos/MediaFile.java?rev=1465469&r1=1465468&r2=1465469&view=diff
==============================================================================
--- roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/pojos/MediaFile.java (original)
+++ roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/pojos/MediaFile.java Sun Apr  7 21:28:40 2013
@@ -18,62 +18,90 @@
 package org.apache.roller.weblogger.pojos;
 
 import java.io.InputStream;
+import java.io.Serializable;
 import java.sql.Timestamp;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
 import java.util.Set;
 
+import org.apache.commons.lang.builder.EqualsBuilder;
+import org.apache.commons.lang.builder.HashCodeBuilder;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.roller.util.UUIDGenerator;
+import org.apache.roller.weblogger.WebloggerException;
 import org.apache.roller.weblogger.business.MediaFileManager;
 import org.apache.roller.weblogger.business.WebloggerFactory;
+import org.apache.roller.weblogger.util.Utilities;
 
 /**
  * Represents a media file
- *
+ * 
  */
-public class MediaFile {
+public class MediaFile implements Serializable {
 
-    private static Log log =
-            LogFactory.getFactory().getInstance(MediaFile.class);
+    private static final long serialVersionUID = -6704258422169734004L;
 
-    private String id;
+    private static Log log = LogFactory.getFactory().getInstance(
+            MediaFile.class);
 
-    private String      name;
-    private String      description;
-    private String      copyrightText;
-    private Boolean     isSharedForGallery = Boolean.FALSE;
-    private long        length;
-    private int         width = -1;
-    private int         height = -1;
-    private int         thumbnailHeight = -1;
-    private int         thumbnailWidth = -1;
-    private String      contentType;
-    private String      originalPath;
-    private Timestamp   dateUploaded = new Timestamp(System.currentTimeMillis());
-    private Timestamp   lastUpdated = new Timestamp(System.currentTimeMillis());
-    private String      creatorUserName;
-    private Weblog      weblog;
+    private String id = UUIDGenerator.generateUUID();
+
+    private String name;
+    private String description;
+    private String copyrightText;
+    private Boolean isSharedForGallery = Boolean.FALSE;
+    private long length;
+    private int width = -1;
+    private int height = -1;
+    private int thumbnailHeight = -1;
+    private int thumbnailWidth = -1;
+    private String contentType;
+    private String originalPath;
+    private Timestamp dateUploaded = new Timestamp(System.currentTimeMillis());
+    private Timestamp lastUpdated = new Timestamp(System.currentTimeMillis());
+    private String creatorUserName;
+    private Weblog weblog;
 
     private InputStream is;
 
     private MediaFileDirectory directory;
-    private Set<MediaFileTag>  tags;
 
     private FileContent content;
     private FileContent thumbnail;
 
-    
     // TODO: anchor to be populated
-    private String      anchor;
+    // private String anchor;
 
+    private Set<MediaFileTag> tagSet = new HashSet<MediaFileTag>();
+    private Set<String> removedTags = new HashSet<String>();
+    private Set<String> addedTags = new HashSet<String>();
 
     public MediaFile() {
-        this.id = UUIDGenerator.generateUUID();
+    }
+
+    /**
+     * Database surrogate key.
+     * 
+     * @roller.wrapPojoMethod type="simple"
+     */
+    public String getId() {
+        return id;
+    }
+
+    /**
+     * @param id
+     *            the id to set
+     */
+    public void setId(String id) {
+        this.id = id;
     }
 
     /**
      * Name for the media file
-     *
+     * 
      */
     public String getName() {
         return name;
@@ -85,7 +113,7 @@ public class MediaFile {
 
     /**
      * Description for media file
-     *
+     * 
      */
     public String getDescription() {
         return description;
@@ -97,7 +125,7 @@ public class MediaFile {
 
     /**
      * Copyright text for media file
-     *
+     * 
      */
     public String getCopyrightText() {
         return copyrightText;
@@ -109,7 +137,7 @@ public class MediaFile {
 
     /**
      * Is media file shared for gallery
-     *
+     * 
      */
     public Boolean isSharedForGallery() {
         return isSharedForGallery;
@@ -121,7 +149,7 @@ public class MediaFile {
 
     /**
      * Size of the media file
-     *
+     * 
      */
     public long getLength() {
         return length;
@@ -149,7 +177,7 @@ public class MediaFile {
 
     /**
      * Last updated timestamp
-     *
+     * 
      */
     public Timestamp getLastUpdated() {
         return lastUpdated;
@@ -169,19 +197,120 @@ public class MediaFile {
 
     /**
      * Set of tags for this media file
-     *
      */
     public Set<MediaFileTag> getTags() {
-        return tags;
+        return tagSet;
     }
 
-    public void setTags(Set<MediaFileTag> tags) {
-        this.tags = tags;
+    private void setTags(Set<MediaFileTag> tagSet) throws WebloggerException {
+        this.tagSet = tagSet;
+        this.removedTags = new HashSet<String>();
+        this.addedTags = new HashSet<String>();
+    }
+
+    /**
+     * Roller lowercases all tags based on locale because there's not a 1:1
+     * mapping between uppercase/lowercase characters across all languages.
+     * 
+     * @param name
+     * @throws WebloggerException
+     */
+    public void addTag(String name) throws WebloggerException {
+        Locale localeObject = getWeblog() != null ? getWeblog()
+                .getLocaleInstance() : Locale.getDefault();
+        name = Utilities.normalizeTag(name, localeObject);
+        if (name.length() == 0)
+            return;
+
+        for (Iterator it = getTags().iterator(); it.hasNext();) {
+            MediaFileTag tag = (MediaFileTag) it.next();
+            if (tag.getName().equals(name))
+                return;
+        }
+
+        MediaFileTag tag = new MediaFileTag();
+        tag.setName(name);
+        tag.setMediaFile(this);
+
+        tagSet.add(tag);
+
+        addedTags.add(name);
+    }
+
+    public void onRemoveTag(String name) throws WebloggerException {
+        removedTags.add(name);
+    }
+
+    public Set getAddedTags() {
+        return addedTags;
+    }
+
+    public Set getRemovedTags() {
+        return removedTags;
+    }
+
+    public void updateTags(List<String> updatedTags) throws WebloggerException {
+
+        if (updatedTags == null) {
+            return;
+        }
+
+        HashSet newTags = new HashSet(updatedTags.size());
+        Locale localeObject = getWeblog() != null ? getWeblog()
+                .getLocaleInstance() : Locale.getDefault();
+
+        for (Iterator<String> it = updatedTags.iterator(); it.hasNext();) {
+            String name = it.next();
+            newTags.add(Utilities.normalizeTag(name, localeObject));
+        }
+
+        HashSet removeTags = new HashSet();
+
+        // remove old ones no longer passed.
+        for (Iterator it = getTags().iterator(); it.hasNext();) {
+            MediaFileTag tag = (MediaFileTag) it.next();
+            if (!newTags.contains(tag.getName())) {
+                removeTags.add(tag.getName());
+            } else {
+                newTags.remove(tag.getName());
+            }
+        }
+
+        MediaFileManager mediaManager = WebloggerFactory.getWeblogger()
+                .getMediaFileManager();
+        for (Iterator it = removeTags.iterator(); it.hasNext();) {
+            mediaManager.removeMediaFileTag((String) it.next(), this);
+        }
+
+        for (Iterator it = newTags.iterator(); it.hasNext();) {
+            addTag((String) it.next());
+        }
+    }
+
+    public String getTagsAsString() {
+        StringBuffer sb = new StringBuffer();
+        for (Iterator it = getTags().iterator(); it.hasNext();) {
+            sb.append(((MediaFileTag) it.next()).getName()).append(" ");
+        }
+        if (sb.length() > 0) {
+            sb.deleteCharAt(sb.length() - 1);
+        }
+
+        return sb.toString();
+    }
+
+    public void setTagsAsString(String tags) throws WebloggerException {
+        if (tags == null) {
+            tagSet.clear();
+            return;
+        }
+
+        updateTags(Utilities.splitStringAsTags(tags));
     }
 
     /**
      * Content type of the media file
-     *
+     * 
      */
     public String getContentType() {
         return contentType;
@@ -191,21 +320,13 @@ public class MediaFile {
         this.contentType = contentType;
     }
 
-    /**
-     * Database surrogate key.
-     *
-     * @roller.wrapPojoMethod type="simple"
-     */
-    public String getId() {
-        return id;
-    }
-
     public String getPath() {
         return directory.getPath();
     }
 
     /**
      * Returns input stream for the underlying file in the file system.
+     * 
      * @return
      */
     public InputStream getInputStream() {
@@ -227,31 +348,31 @@ public class MediaFile {
 
     /**
      * Indicates whether this is an image file.
-     *
+     * 
      */
     public boolean isImageFile() {
         if (this.contentType == null) {
             return false;
         }
-        return (this.contentType.toLowerCase().startsWith(
-                MediaFileType.IMAGE.getContentTypePrefix().toLowerCase()));
+        return (this.contentType.toLowerCase().startsWith(MediaFileType.IMAGE
+                .getContentTypePrefix().toLowerCase()));
     }
 
     /**
      * Returns permalink URL for this media file resource.
      */
     public String getPermalink() {
-        return WebloggerFactory.getWeblogger().getUrlStrategy().getMediaFileURL(
-                this.weblog, this.getId(), true);
+        return WebloggerFactory.getWeblogger().getUrlStrategy()
+                .getMediaFileURL(this.weblog, this.getId(), true);
     }
 
     /**
-     * Returns thumbnail URL for this media file resource.
-     * Resulting URL will be a 404 if media file is not an image.
+     * Returns thumbnail URL for this media file resource. Resulting URL will be
+     * a 404 if media file is not an image.
      */
     public String getThumbnailURL() {
-        return WebloggerFactory.getWeblogger().getUrlStrategy().getMediaFileThumbnailURL(
-                this.weblog, this.getId(), true);
+        return WebloggerFactory.getWeblogger().getUrlStrategy()
+                .getMediaFileThumbnailURL(this.weblog, this.getId(), true);
     }
 
     public String getCreatorUserName() {
@@ -264,15 +385,19 @@ public class MediaFile {
 
     public User getCreator() {
         try {
-            return WebloggerFactory.getWeblogger().getUserManager().getUserByUserName(getCreatorUserName());
+            return WebloggerFactory.getWeblogger().getUserManager()
+                    .getUserByUserName(getCreatorUserName());
         } catch (Exception e) {
-            log.error("ERROR fetching user object for username: " + getCreatorUserName(), e);
+            log.error("ERROR fetching user object for username: "
+                    + getCreatorUserName(), e);
         }
         return null;
     }
 
     /**
-     * For old migrated files and theme resource files, orignal path of file can never change.
+     * For old migrated files and theme resource files, orignal path of file can
+     * never change.
+     * 
      * @return the originalPath
      */
     public String getOriginalPath() {
@@ -280,8 +405,11 @@ public class MediaFile {
     }
 
     /**
-     * For old migrated files and theme resource files, orignal path of file can never change.
-     * @param originalPath the originalPath to set
+     * For old migrated files and theme resource files, orignal path of file can
+     * never change.
+     * 
+     * @param originalPath
+     *            the originalPath to set
      */
     public void setOriginalPath(String originalPath) {
         this.originalPath = originalPath;
@@ -295,7 +423,8 @@ public class MediaFile {
     }
 
     /**
-     * @param weblog the weblog to set
+     * @param weblog
+     *            the weblog to set
      */
     public void setWeblog(Weblog weblog) {
         this.weblog = weblog;
@@ -309,7 +438,8 @@ public class MediaFile {
     }
 
     /**
-     * @param width the width to set
+     * @param width
+     *            the width to set
      */
     public void setWidth(int width) {
         this.width = width;
@@ -323,14 +453,17 @@ public class MediaFile {
     }
 
     /**
-     * @param height the height to set
+     * @param height
+     *            the height to set
      */
     public void setHeight(int height) {
         this.height = height;
     }
 
     /**
-     * Returns input stream for the underlying thumbnail file in the file system.
+     * Returns input stream for the underlying thumbnail file in the file
+     * system.
+     * 
      * @return
      */
     public InputStream getThumbnailInputStream() {
@@ -371,13 +504,13 @@ public class MediaFile {
 
         if (getWidth() > getHeight()) {
             if (getWidth() > MediaFileManager.MAX_WIDTH) {
-                newHeight = (int)((float)getHeight() * ((float)MediaFileManager.MAX_WIDTH / (float)getWidth()));
+                newHeight = (int) ((float) getHeight() * ((float) MediaFileManager.MAX_WIDTH / (float) getWidth()));
                 newWidth = MediaFileManager.MAX_WIDTH;
             }
 
         } else {
             if (getHeight() > MediaFileManager.MAX_HEIGHT) {
-                newWidth = (int)((float)getWidth() * ((float)MediaFileManager.MAX_HEIGHT / (float)getHeight()));
+                newWidth = (int) ((float) getWidth() * ((float) MediaFileManager.MAX_HEIGHT / (float) getHeight()));
                 newHeight = MediaFileManager.MAX_HEIGHT;
             }
         }
@@ -385,10 +518,27 @@ public class MediaFile {
         thumbnailWidth = newWidth;
     }
 
-    /**
-     * @param id the id to set
-     */
-    public void setId(String id) {
-        this.id = id;
+    // ------------------------------------------------------- Good citizenship
+
+    public String toString() {
+        return "MediaFile [name=" + name + ", directory=" + directory
+                + ", weblog=" + weblog + "]";
+    }
+
+    public boolean equals(Object other) {
+        if (other == this)
+            return true;
+        if (other instanceof MediaFile != true)
+            return false;
+        MediaFile o = (MediaFile) other;
+        return new EqualsBuilder().append(getName(), o.getName())
+                .append(getDirectory(), o.getDirectory())
+                .append(getWeblog(), o.getWeblog()).isEquals();
     }
+
+    public int hashCode() {
+        return new HashCodeBuilder().append(getName()).append(getDirectory())
+                .append(getWeblog()).toHashCode();
+    }
+
 }

Modified: roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/pojos/MediaFileTag.java
URL: http://svn.apache.org/viewvc/roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/pojos/MediaFileTag.java?rev=1465469&r1=1465468&r2=1465469&view=diff
==============================================================================
--- roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/pojos/MediaFileTag.java (original)
+++ roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/pojos/MediaFileTag.java Sun Apr  7 21:28:40 2013
@@ -18,47 +18,76 @@
 
 package org.apache.roller.weblogger.pojos;
 
+import java.io.Serializable;
+
+import org.apache.commons.lang.builder.EqualsBuilder;
+import org.apache.commons.lang.builder.HashCodeBuilder;
 import org.apache.roller.util.UUIDGenerator;
 
 /**
  * Represents the tag for media files.
- *
+ * 
  */
-public class MediaFileTag {
-	
-	private String id = UUIDGenerator.generateUUID();
-	String name;
-	MediaFile mediaFile;
-	
-	public MediaFileTag() {
-	}
-
-	public MediaFileTag(String name, MediaFile mediaFile) {
-		this.name = name;
-		this.mediaFile = mediaFile;
-	}
-
-	public String getId() {
-		return id;
-	}
-
-	public void setId(String id) {
-		this.id = id;
-	}
-
-	public String getName() {
-		return name;
-	}
-	
-	public void setName(String name) {
-		this.name = name;
-	}
-
-	public MediaFile getMediaFile() {
-		return mediaFile;
-	}
-
-	public void setMediaFile(MediaFile mediaFile) {
-		this.mediaFile = mediaFile;
-	}
+public class MediaFileTag implements Serializable {
+
+    private static final long serialVersionUID = -1349427373511141841L;
+
+    private String id = UUIDGenerator.generateUUID();
+    private String name;
+    private MediaFile mediaFile;
+
+    public MediaFileTag() {
+    }
+
+    public MediaFileTag(String name, MediaFile mediaFile) {
+        this.name = name;
+        this.mediaFile = mediaFile;
+    }
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public MediaFile getMediaFile() {
+        return mediaFile;
+    }
+
+    public void setMediaFile(MediaFile mediaFile) {
+        this.mediaFile = mediaFile;
+    }
+
+    // ------------------------------------------------------- Good citizenship
+
+    public String toString() {
+        return "MediaFileTag [id=" + id + ", name=" + name + ", mediaFile="
+                + mediaFile + "]";
+    }
+
+    public boolean equals(Object other) {
+        if (other == this)
+            return true;
+        if (other instanceof MediaFileTag != true)
+            return false;
+        MediaFileTag o = (MediaFileTag) other;
+        return new EqualsBuilder().append(getName(), o.getName())
+                .append(getMediaFile(), o.getMediaFile()).isEquals();
+    }
+
+    public int hashCode() {
+        return new HashCodeBuilder().append(getName()).append(getMediaFile())
+                .toHashCode();
+    }
+
 }

Modified: roller/trunk/weblogger-business/src/main/resources/org/apache/roller/weblogger/pojos/MediaFile.orm.xml
URL: http://svn.apache.org/viewvc/roller/trunk/weblogger-business/src/main/resources/org/apache/roller/weblogger/pojos/MediaFile.orm.xml?rev=1465469&r1=1465468&r2=1465469&view=diff
==============================================================================
--- roller/trunk/weblogger-business/src/main/resources/org/apache/roller/weblogger/pojos/MediaFile.orm.xml (original)
+++ roller/trunk/weblogger-business/src/main/resources/org/apache/roller/weblogger/pojos/MediaFile.orm.xml Sun Apr  7 21:28:40 2013
@@ -61,7 +61,7 @@
             <many-to-one name="weblog" target-entity="org.apache.roller.weblogger.pojos.Weblog">
                 <join-column name="weblogid" insertable="true" updatable="true" nullable="false"/>
             </many-to-one>
-            <one-to-many name="tags" mapped-by="mediaFile" target-entity="org.apache.roller.weblogger.pojos.MediaFileTag">
+            <one-to-many name="tags" mapped-by="mediaFile" target-entity="org.apache.roller.weblogger.pojos.MediaFileTag" fetch="LAZY">
                 <cascade>
                     <cascade-persist /> <!-- Added so entry added by addTag() gets persisted -->
                     <cascade-remove />
@@ -72,6 +72,7 @@
             <transient name="lastModified"/>
             <transient name="path"/>
             <transient name="creator"/>
+            <transient name="tagsAsString"/>
             <transient name="imageFile"/>
             <transient name="inputStream"/>
             <transient name="thumbnailInputStream"/>

Modified: roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileBean.java
URL: http://svn.apache.org/viewvc/roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileBean.java?rev=1465469&r1=1465468&r2=1465469&view=diff
==============================================================================
--- roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileBean.java (original)
+++ roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileBean.java Sun Apr  7 21:28:40 2013
@@ -17,34 +17,29 @@
  */
 package org.apache.roller.weblogger.ui.struts2.editor;
 
-import java.util.HashSet;
-import java.util.Set;
-
-import org.apache.commons.lang.StringUtils;
 import org.apache.roller.weblogger.WebloggerException;
 import org.apache.roller.weblogger.pojos.MediaFile;
-import org.apache.roller.weblogger.pojos.MediaFileTag;
 
 /**
  * Bean for managing media file.
  */
 public class MediaFileBean {
 
-    private String  id;
-    private String  name;
-    private String  description;
-    private String  contentType;
-    private String  copyrightText;
-    private String  tags;
-    private String  directoryId;
+    private String id;
+    private String name;
+    private String description;
+    private String contentType;
+    private String copyrightText;
+    private String tagsAsString;
+    private String directoryId;
     private boolean isSharedForGallery;
-    private String  permalink;
-    private String  thumbnailURL;
+    private String permalink;
+    private String thumbnailURL;
     private boolean isImage;
-    private int     width;
-    private int     height;
-    private long    length;
-    private String  originalPath;
+    private int width;
+    private int height;
+    private long length;
+    private String originalPath;
 
     public String getName() {
         return name;
@@ -70,12 +65,12 @@ public class MediaFileBean {
         this.copyrightText = copyrightText;
     }
 
-    public String getTags() {
-        return tags;
+    public String getTagsAsString() {
+        return this.tagsAsString;
     }
 
-    public void setTags(String tags) {
-        this.tags = tags;
+    public void setTagsAsString(String tagsAsString) {
+        this.tagsAsString = tagsAsString;
     }
 
     public String getDirectoryId() {
@@ -111,22 +106,13 @@ public class MediaFileBean {
         dataHolder.setName(this.name);
         dataHolder.setDescription(this.description);
         dataHolder.setCopyrightText(this.copyrightText);
-
-		if (StringUtils.isNotEmpty(tags)) {
-			Set<MediaFileTag> tagsSet = new HashSet<MediaFileTag>();
-			for (String tag : this.tags.split(" ")) {
-				tagsSet.add(new MediaFileTag(tag, dataHolder));
-			}
-			dataHolder.setTags(tagsSet);
-		} else {
-			dataHolder.setTags(null);
-		}
+        dataHolder.setTagsAsString(this.tagsAsString);
         dataHolder.setSharedForGallery(this.isSharedForGallery);
         dataHolder.setOriginalPath(this.originalPath);
     }
 
     /**
-     * Populates this bean from a media file object. 
+     * Populates this bean from a media file object.
      * 
      */
     public void copyFrom(MediaFile dataHolder) {
@@ -134,22 +120,7 @@ public class MediaFileBean {
         this.setName(dataHolder.getName());
         this.setDescription(dataHolder.getDescription());
         this.setCopyrightText(dataHolder.getCopyrightText());
-
-        Set<MediaFileTag> tags = dataHolder.getTags();
-        if (tags != null && !tags.isEmpty()) {
-            StringBuilder tagDisplayBuilder = new StringBuilder();
-            for (MediaFileTag tag : dataHolder.getTags()) {
-            	if (StringUtils.isNotEmpty(tag.getName())) {
-            		tagDisplayBuilder.append(tag.getName());
-                    tagDisplayBuilder.append(" ");
-				}
-            }
-			if (tagDisplayBuilder.length() > 0) {
-				tagDisplayBuilder.deleteCharAt(tagDisplayBuilder.length() - 1);
-			}
-            this.setTags(tagDisplayBuilder.toString());
-        }
-
+        this.setTagsAsString(dataHolder.getTagsAsString());
         this.setSharedForGallery(dataHolder.isSharedForGallery());
         this.setDirectoryId(dataHolder.getDirectory().getId());
         this.setPermalink(dataHolder.getPermalink());
@@ -170,7 +141,8 @@ public class MediaFileBean {
     }
 
     /**
-     * @param permalink the permalink to set
+     * @param permalink
+     *            the permalink to set
      */
     public void setPermalink(String permalink) {
         this.permalink = permalink;
@@ -184,7 +156,8 @@ public class MediaFileBean {
     }
 
     /**
-     * @param isImage the isImage to set
+     * @param isImage
+     *            the isImage to set
      */
     public void setIsImage(boolean isImage) {
         this.isImage = isImage;
@@ -198,7 +171,8 @@ public class MediaFileBean {
     }
 
     /**
-     * @param thumbnailURL the thumbnailURL to set
+     * @param thumbnailURL
+     *            the thumbnailURL to set
      */
     public void setThumbnailURL(String thumbnailURL) {
         this.thumbnailURL = thumbnailURL;
@@ -212,7 +186,8 @@ public class MediaFileBean {
     }
 
     /**
-     * @param width the width to set
+     * @param width
+     *            the width to set
      */
     public void setWidth(int width) {
         this.width = width;
@@ -226,7 +201,8 @@ public class MediaFileBean {
     }
 
     /**
-     * @param height the height to set
+     * @param height
+     *            the height to set
      */
     public void setHeight(int height) {
         this.height = height;
@@ -240,7 +216,8 @@ public class MediaFileBean {
     }
 
     /**
-     * @param length the length to set
+     * @param length
+     *            the length to set
      */
     public void setLength(long length) {
         this.length = length;
@@ -254,7 +231,8 @@ public class MediaFileBean {
     }
 
     /**
-     * @param contentType the contentType to set
+     * @param contentType
+     *            the contentType to set
      */
     public void setContentType(String contentType) {
         this.contentType = contentType;
@@ -268,7 +246,8 @@ public class MediaFileBean {
     }
 
     /**
-     * @param originalPath the originalPath to set
+     * @param originalPath
+     *            the originalPath to set
      */
     public void setOriginalPath(String originalPath) {
         this.originalPath = originalPath;

Modified: roller/trunk/weblogger-webapp/src/main/webapp/WEB-INF/jsps/editor/MediaFileAdd.jsp
URL: http://svn.apache.org/viewvc/roller/trunk/weblogger-webapp/src/main/webapp/WEB-INF/jsps/editor/MediaFileAdd.jsp?rev=1465469&r1=1465468&r2=1465469&view=diff
==============================================================================
--- roller/trunk/weblogger-webapp/src/main/webapp/WEB-INF/jsps/editor/MediaFileAdd.jsp (original)
+++ roller/trunk/weblogger-webapp/src/main/webapp/WEB-INF/jsps/editor/MediaFileAdd.jsp Sun Apr  7 21:28:40 2013
@@ -108,7 +108,7 @@
                 <label for="status"><s:text name="mediaFileAdd.tags" /></label>
             </td>
             <td>
-                <s:textfield name="bean.tags" size="50" maxlength="255" />
+                <s:textfield name="bean.tagsAsString" size="50" maxlength="255" />
             </td>
        </tr>
 

Modified: roller/trunk/weblogger-webapp/src/main/webapp/WEB-INF/jsps/editor/MediaFileEdit.jsp
URL: http://svn.apache.org/viewvc/roller/trunk/weblogger-webapp/src/main/webapp/WEB-INF/jsps/editor/MediaFileEdit.jsp?rev=1465469&r1=1465468&r2=1465469&view=diff
==============================================================================
--- roller/trunk/weblogger-webapp/src/main/webapp/WEB-INF/jsps/editor/MediaFileEdit.jsp (original)
+++ roller/trunk/weblogger-webapp/src/main/webapp/WEB-INF/jsps/editor/MediaFileEdit.jsp Sun Apr  7 21:28:40 2013
@@ -147,7 +147,7 @@ $("#d_clip_button").ready(function() {
                 <label for="tags"><s:text name="mediaFileEdit.tags" /></label>
             </td>
             <td>
-                <s:textfield name="bean.tags" size="30" maxlength="100" tabindex="3" />
+                <s:textfield name="bean.tagsAsString" size="30" maxlength="100" tabindex="3" />
             </td>
        </tr>
 



Mime
View raw message