Subversion Repositories SmartDukaan

Rev

Rev 3929 | Rev 3991 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3929 Rev 3945
Line 126... Line 126...
126
 
126
 
127
        /*
127
        /*
128
         * If the default image is not present for this entity, copy the global
128
         * If the default image is not present for this entity, copy the global
129
         * default image. TODO: This part will be moved to the Jython Script
129
         * default image. TODO: This part will be moved to the Jython Script
130
         */
130
         */
-
 
131
        File globalDefaultJPGFile = new File(globalDefaultImagePath);
131
        File f3 = new File(defaultImagePath);
132
        File f3 = new File(defaultImagePath);
132
        if (!f3.exists()) {
133
        if (!f3.exists()) {
133
            copyFile(new File(globalDefaultImagePath), new File(
134
            copyFile(globalDefaultJPGFile, new File(
134
                    defaultImagePath));
135
                    defaultImagePath));
135
        }
136
        }
136
 
137
 
137
        File staticMediaDirectory = new File(Utils.EXPORT_MEDIA_STATIC_PATH + catalogId);
138
        File staticMediaDirectory = new File(Utils.EXPORT_MEDIA_STATIC_PATH + catalogId);
138
        if (!staticMediaDirectory.exists()) {
139
        if (!staticMediaDirectory.exists()) {
Line 143... Line 144...
143
        if (!websiteMediaDirectory.exists()) {
144
        if (!websiteMediaDirectory.exists()) {
144
            websiteMediaDirectory.mkdir();
145
            websiteMediaDirectory.mkdir();
145
        }
146
        }
146
 
147
 
147
        /*
148
        /*
-
 
149
         * Creating default, thumbnails and icon files in case no 'default' labelled media is uploaded
-
 
150
         * in CMS for an entity in summary slide. It copes content form the global default location.
-
 
151
         * For incremental geenration, we check for global image file's last modified timestamp.
-
 
152
         */
-
 
153
        long defaultImageCreationTime = EntityUtils.getCreationTimeFromSummarySlide(entity, "default");
-
 
154
        File newVersionedDefaultJPGFile = new File(staticMediaDirectory,
-
 
155
                computeNewFileName(imagePrefix, DEFAULT_JPG, String.valueOf(defaultImageCreationTime)));
-
 
156
 
-
 
157
        if (defaultImageCreationTime == 0 && (!newVersionedDefaultJPGFile.exists() || 
-
 
158
            globalDefaultJPGFile.lastModified() > Long.parseLong(contentVersion)))
-
 
159
        {
-
 
160
            copyFile(globalDefaultJPGFile,
-
 
161
                     new File(websiteMediaDirectory, DEFAULT_JPG));
-
 
162
 
-
 
163
            copyFile(globalDefaultJPGFile,
-
 
164
                     newVersionedDefaultJPGFile);
-
 
165
 
-
 
166
            copyFile(new File(imageDirPath + THUMBNAIL_JPG),
-
 
167
                     new File(websiteMediaDirectory, THUMBNAIL_JPG));
-
 
168
 
-
 
169
            copyFile(new File(imageDirPath + ICON_JPG),
-
 
170
                     new File(websiteMediaDirectory, ICON_JPG));
-
 
171
 
-
 
172
            copyFile(new File(imageDirPath + THUMBNAIL_JPG),
-
 
173
                     new File(staticMediaDirectory, computeNewFileName(imagePrefix, THUMBNAIL_JPG,
-
 
174
                             String.valueOf(defaultImageCreationTime))));
-
 
175
 
-
 
176
            copyFile(new File(imageDirPath + ICON_JPG),
-
 
177
                     new File(staticMediaDirectory, computeNewFileName(imagePrefix, ICON_JPG,
-
 
178
                             String.valueOf(defaultImageCreationTime))));
-
 
179
 
-
 
180
            // FIXME This should be removed once we are ready with changes in ProductListGenerator.
-
 
181
            copyFile(new File(imageDirPath + ICON_JPG),
-
 
182
                     new File(staticMediaDirectory, ICON_JPG));
-
 
183
        }
-
 
184
 
-
 
185
        /*
148
         * Copying the generated content from db/media to export/media. This
186
         * Copying the generated content from db/media to export/media. This
149
         * will also insert a creation timestamp tag in the file names.
187
         * will also insert a creation timestamp tag in the file names.
150
         */
188
         */
151
        for (ExpandedSlide expandedSlide : entity.getExpandedSlides()) {
189
        for (ExpandedSlide expandedSlide : entity.getExpandedSlides()) {
152
            FreeformContent freeFormContent = expandedSlide.getFreeformContent();
190
            FreeformContent freeFormContent = expandedSlide.getFreeformContent();
Line 194... Line 232...
194
                                            String.valueOf(image.getCreationTime().getTime()))));
232
                                            String.valueOf(image.getCreationTime().getTime()))));
195
                            
233
                            
196
                            //FIXME This should be removed once we are ready with changes in ProductListGenerator.
234
                            //FIXME This should be removed once we are ready with changes in ProductListGenerator.
197
                            copyFile(new File(imageDirPath + ICON_JPG),
235
                            copyFile(new File(imageDirPath + ICON_JPG),
198
                                    new File(staticMediaDirectory, ICON_JPG));
236
                                    new File(staticMediaDirectory, ICON_JPG));
199
 
-
 
200
                        }
237
                        }
201
                    }
238
                    }
202
                }
239
                }
203
            }
240
            }
204
        }
241
        }
Line 210... Line 247...
210
     *
247
     *
211
     * @param staticMediaDirectory  the given directory from where file needs to be removed
248
     * @param staticMediaDirectory  the given directory from where file needs to be removed
212
     * @param fileNamePrefix    the given prefix of file name that should be removed
249
     * @param fileNamePrefix    the given prefix of file name that should be removed
213
     */
250
     */
214
    private void removeFile(File staticMediaDirectory, final String fileNamePrefix) {
251
    private void removeFile(File staticMediaDirectory, final String fileNamePrefix) {
-
 
252
        // Not removing files for now. As we can have files with same names 
-
 
253
        // and different labels.
-
 
254
        return;
215
        // Deleting the file with same name
255
//        // Deleting the file with same name
216
        File[] fileToBeDeleted = staticMediaDirectory.listFiles(new FilenameFilter() {
256
//        File[] fileToBeDeleted = staticMediaDirectory.listFiles(new FilenameFilter() {
217
            
257
//            
218
            @Override
258
//            @Override
219
            public boolean accept(File dir, String name) {
259
//            public boolean accept(File dir, String name) {
220
                if (name.startsWith(fileNamePrefix)) {
260
//                if (name.startsWith(fileNamePrefix)) {
221
                    return true;
261
//                    return true;
222
                }
262
//                }
223
 
263
//
224
                return false;
264
//                return false;
225
            }
265
//            }
226
        });
266
//        });
227
 
267
//
228
        // Deleting only one file
268
//        // Deleting only one file
229
        if (fileToBeDeleted.length != 0) {
269
//        if (fileToBeDeleted.length != 0) {
230
            fileToBeDeleted[0].delete();
270
//            fileToBeDeleted[0].delete();
231
        }
271
//        }
232
    }
272
    }
233
 
273
 
234
    /**
274
    /**
235
     * This method computes new name of a given file. It adds necessary prefix 
275
     * This method computes new name of a given file. It adds necessary prefix 
236
     * and suffix to core file name separated by hyphons keeping extension intact.
276
     * and suffix to core file name separated by hyphons keeping extension intact.
Line 263... Line 303...
263
 
303
 
264
    /**
304
    /**
265
     * Retuens true in case a given image is the default one. False, otherwise.
305
     * Retuens true in case a given image is the default one. False, otherwise.
266
     */
306
     */
267
    private boolean isDefaultImage(Media image) {
307
    private boolean isDefaultImage(Media image) {
268
        return DEFAULT_JPG.equals(image.getFileName()) || "default".equals(image.getLabel());
308
        return "default".equals(image.getLabel());
269
    }
309
    }
270
 
310
 
271
    /**
311
    /**
272
     * Copies the contents of the source file into the destination file. Creates
312
     * Copies the contents of the source file into the destination file. Creates
273
     * the destination file if it doesn't exist already.
313
     * the destination file if it doesn't exist already.