001    package jmaster.jumploader.model.api.config;
002    
003    import java.util.List;
004    import java.util.MissingResourceException;
005    
006    import jmaster.jumploader.model.api.IModel;
007    import jmaster.util.lang.StringHelper;
008    import jmaster.util.property.Property;
009    import jmaster.util.property.PropertyFactory;
010    import jmaster.util.property.PropertyHelper;
011    
012    
013    /**
014     * UploaderConfig
015     * 
016     * @author timur
017     */
018    
019    public class UploaderConfig {
020            //---------------------------------------------------------------
021            //      constants
022            //---------------------------------------------------------------
023            /**
024             * property file
025             */
026            private static final String PROPERTY = "UploaderConfig.properties";
027            /**
028             * error response token
029             */
030            public static final String ERROR_RESPONSE_PREFIX = "Error:";
031            /**
032             * file id parameter name
033             */
034            public static final String PARAM_FILE_ID = "fileId";
035            /**
036             * file length parameter name
037             */
038            public static final String PARAM_FILE_LENGTH = "fileLength";
039            /**
040             * file name parameter name
041             */
042            public static final String PARAM_FILE_NAME = "fileName";
043            /**
044             * file path parameter name
045             */
046            public static final String PARAM_FILE_PATH = "filePath";
047            /**
048             * partition index parameter name
049             */
050            public static final String PARAM_PARTITION_INDEX = "partitionIndex";
051            /**
052             * partition count
053             */
054            public static final String PARAM_PARTITION_COUNT = "partitionCount";
055            /**
056             * MD5
057             */
058            public static final String PARAM_MD5 = "md5";
059            /**
060             * partition MD5
061             */
062            public static final String PARAM_PARTITION_MD5 = "partitionMd5";
063            /**
064             * zip file will be created for each file added to the queue
065             */
066            public static final String COMPRESSION_MODE_ZIP_ON_ADD = "zipOnAdd";
067            /**
068             * default http uploader class name
069             */
070            private static final String DEFAULT_HTTP_UPLOADER_CLASS_NAME = "jmaster.util.http.UrlConnectionHttpUploader";
071            //---------------------------------------------------------------
072            //      properties
073            //---------------------------------------------------------------
074            /**
075             * upload thread count
076             */
077            private int uploadThreadCount = 1;
078            /**
079             * upload url
080             */
081            private String uploadUrl = null;
082            /**
083             * max files in a list, -1 if unlimited
084             */
085            private int maxFiles = -1;
086            /**
087             * max file length allowed (per file), -1 if unlimited
088             */
089            private long maxFileLength = -1;
090            /**
091             * max files length allowed (total), -1 if unlimited 
092             */
093            private long maxLength = -1;
094            /**
095             * allowed file name (not path) regex pattern, null for all
096             */
097            private String fileNamePattern = null;
098            /**
099             * shows whether folder addition enabled (will expand and add all files)
100             */
101            private boolean directoriesEnabled = false;
102            /**
103             * duplicate files enabled
104             */
105            private boolean duplicateFileEnabled = false;
106            /**
107             * file parameter name (for POST request)
108             */
109            private String fileParameterName = "file";
110            /**
111             * partitionLength
112             */
113            private long partitionLength = -1;
114            /**
115             * user agent
116             */
117            private String userAgent = null;
118            /**
119             * cookie
120             */
121            private String cookie = null;
122            /**
123             * use MD5 hash, if true, MD5 value will be send with
124             * last partition upload request
125             */
126            private boolean useMd5 = false;
127            /**
128             * use MD5 hash for each partition, if true, MD5 value for current partition
129             * will be send with each partition upload request
130             */
131            private boolean usePartitionMd5 = false;
132            /**
133             * min files in a list, -1 if unlimited
134             */
135            private int minFiles = -1;
136            /**
137             * min file length allowed (per file), -1 if unlimited
138             */
139            private long minFileLength = -1;
140            /**
141             * shows whether scaled images should be uploaded.
142             * if true, uploaded file would be ZIP archive where entries are scaled images of original,
143             * entry count and names will match scaled instance names.
144             */
145            private boolean uploadScaledImages;
146            /**
147             * shows whether scaled images should be uploaded not zipped (multiple files on one request).
148             * in this case file parameter name will match scaled instance name 
149             */
150            private boolean uploadScaledImagesNoZip;
151            /**
152             * shows whether can resize smaller  images to bigger dimension
153             */
154            private boolean stretchImages = false;
155            /**
156             * shows whether original image should be uploaded along with scaled images,
157             * valid only if uploadScaledImages=true
158             */
159            private boolean uploadOriginalImage;
160            /**
161             * scaled instance names (comma separated, e.g. "small,medium,large")
162             */
163            private String scaledInstanceNames;
164            /**
165             * scaled instance dimensions (comma separated, for example "100x100,200x200,400x400")
166             */
167            private String scaledInstanceDimensions;
168            /**
169             * scaled instance quality factors (0-worse quality, 1000-best),
170             * (comma spearated, fo example, "900,800,700");
171             */
172            private String scaledInstanceQualityFactors;
173            /**
174             * scaled instance watermark names to apply, use null for skip
175             * (comma spearated, fo example, "null,mediumWatermark,null");
176             */
177            private String scaledInstanceWatermarkNames;
178            /**
179             * initialized watermarks
180             */
181            private List scaledInstanceWatermarks;
182            /**
183             * shows whether main file should be used
184             */
185            private boolean useMainFile = false;
186            /**
187             * shows whether images only allowed
188             */
189            private boolean addImagesOnly = false;
190            /**
191             * minimum image size allowed ({width}x{height})
192             */
193            private String minimumImageDimension;
194            /**
195             * maximum image size allowed ({width}x{height})
196             */
197            private String maximumImageDimension;
198            /**
199             * shows whether image editor is enabled
200             */
201            private boolean imageEditorEnabled = true;
202            /**
203             * resume check url
204             */
205            private String resumeCheckUrl;
206            /**
207             * shows whether filename parameters sent to server should be urlencoded
208             */
209            private boolean urlEncodeParameters;
210            /**
211             * shows whether lastModified attribute should be send for a file
212             */
213            private boolean sendFileLastModified = true;
214            /**
215             * compression mode, see constants
216             */
217            private String compressionMode = null;
218            /**
219             * add directory as zip flag
220             */
221            private boolean zipDirectoriesOnAdd = false;
222            /**
223             * send file path
224             */
225            private boolean sendFilePath = false;
226            /**
227             * maximum transfer rate (bytes/sec)
228             */
229            private long maxTransferRate = -1;
230            /**
231             * http uploader class name 
232             */
233            private String httpUploaderClassName = DEFAULT_HTTP_UPLOADER_CLASS_NAME;
234            /**
235             * shows whether upload queue reardering allowed (false by default)
236             */
237            private boolean uploadQueueReorderingAllowed = false;
238            /**
239             * request encoding to use (UTF-8 by default)
240             */
241            private String requestEncoding = "UTF-8"; 
242            /**
243             * send image exif data as xml
244             */
245            private boolean sendExif = false;
246            /**
247             * send image iptc data as xml
248             */
249            private boolean sendIptc = false;
250            /**
251             * shows whether file relative path should be preserved as "relativePath" attribute value
252             * when adding directory in explode mode (i.e. not zipping folder content, 
253             * but adding all the files in that directory recursively).
254             * For example, if adding directory c:/temp/d with files f1, f2,
255             * then file "relativePath" attribute values will be "d/f1" and ""d/f2"
256             */
257            private boolean preserveRelativePath;
258            //---------------------------------------------------------------
259            //      constructors
260            //---------------------------------------------------------------
261            /**
262             * with model 
263             */
264            public UploaderConfig( IModel model ) {
265                    super();
266                    //
267                    //      inject properties, if present
268                    try {
269                            PropertyFactory pf = PropertyFactory.getInstance();
270                            Property pr = pf.getProperty( PROPERTY );
271                            PropertyHelper ph = PropertyHelper.getInstance();
272                            ph.injectProperties( this, pr, null );
273                    } catch( MissingResourceException ignore ) {
274                    }
275            }
276            //---------------------------------------------------------------
277            //      property accessors
278            //---------------------------------------------------------------
279            /**
280             * toString
281             */
282            public String toString() {
283                    return "" +
284                            "uploadThreadCount=" + uploadThreadCount + "\r\n" +
285                            "uploadUrl=" + uploadUrl + "\r\n" +
286                            "maxFiles=" + maxFiles + "\r\n" +
287                            "maxFileLength=" + maxFileLength + "\r\n" +
288                            "maxLength=" + maxLength + "\r\n" +
289                            "fileNamePattern=" + fileNamePattern + "\r\n" +
290                            "directoriesEnabled=" + directoriesEnabled + "\r\n" +
291                            "duplicateFileEnabled=" + duplicateFileEnabled + "\r\n" +
292                            "fileParameterName=" + fileParameterName + "\r\n" +
293                            "partitionLength=" + partitionLength + "\r\n" +
294                            "userAgent=" + userAgent + "\r\n" +
295                            "cookie=" + cookie + "\r\n" +
296                            "useMd5=" + useMd5 + "\r\n" +
297                            "usePartitionMd5=" + usePartitionMd5 + "\r\n" +
298                            "minFiles=" + minFiles + "\r\n" +
299                            "minFileLength=" + minFileLength + "\r\n" +
300                            "uploadScaledImages=" + uploadScaledImages + "\r\n" +
301                            "uploadScaledImagesNoZip=" + uploadScaledImagesNoZip + "\r\n" +
302                            "stretchImages=" + stretchImages + "\r\n" +
303                            "uploadOriginalImage=" + uploadOriginalImage + "\r\n" +
304                            "scaledInstanceNames=" + scaledInstanceNames + "\r\n" +
305                            "scaledInstanceDimensions=" + scaledInstanceDimensions + "\r\n" +
306                            "scaledInstanceQualityFactors=" + scaledInstanceQualityFactors + "\r\n" +
307                            "scaledInstanceWatermarkNames=" + scaledInstanceWatermarkNames + "\r\n" +
308                            "useMainFile=" + useMainFile + "\r\n" +
309                            "addImagesOnly=" + addImagesOnly + "\r\n" +
310                            "minimumImageDimension=" + minimumImageDimension + "\r\n" +
311                            "maximumImageDimension=" + minimumImageDimension + "\r\n" +
312                            "imageEditorEnabled=" + imageEditorEnabled + "\r\n" +
313                            "resumeCheckUrl=" + resumeCheckUrl + "\r\n" +
314                            "urlEncodeParameters=" + urlEncodeParameters + "\r\n" +
315                            "sendFileLastModified=" + sendFileLastModified + "\r\n" +
316                            "compressionMode=" + compressionMode + "\r\n" +
317                            "zipDirectoriesOnAdd=" + zipDirectoriesOnAdd + "\r\n" +                 
318                            "sendFilePath=" + sendFilePath + "\r\n" +
319                            "maxTransferRate=" + maxTransferRate + "\r\n" +
320                            "httpUploaderClassName=" + httpUploaderClassName + "\r\n" +
321                            "uploadQueueReorderingAllowed=" + uploadQueueReorderingAllowed + "\r\n" +
322                            "requestEncoding=" + requestEncoding + "\r\n" +
323                            "sendExif=" + sendExif + "\r\n" +
324                            "sendIptc=" + sendIptc + "\r\n" +
325                            "preserveRelativePath=" + preserveRelativePath + "\r\n" +
326                    "";
327            }
328            public String getCompressionMode() {
329                    return compressionMode;
330            }
331            public void setCompressionMode(String compressionMode) {
332                    this.compressionMode = compressionMode;
333            }
334            public boolean isDirectoriesEnabled() {
335                    return directoriesEnabled;
336            }
337            public void setDirectoriesEnabled(boolean directoriesEnabled) {
338                    this.directoriesEnabled = directoriesEnabled;
339            }
340            public boolean isDuplicateFileEnabled() {
341                    return duplicateFileEnabled;
342            }
343            public void setDuplicateFileEnabled(boolean duplicateFileEnabled) {
344                    this.duplicateFileEnabled = duplicateFileEnabled;
345            }
346            public String getFileNamePattern() {
347                    return fileNamePattern;
348            }
349            public void setFileNamePattern(String fileNamePattern) {
350                    this.fileNamePattern = StringHelper.isEmpty( fileNamePattern ) ? 
351                                    null : fileNamePattern;
352            }
353            public long getMaxFileLength() {
354                    return maxFileLength;
355            }
356            public void setMaxFileLength(long maxFileLength) {
357                    this.maxFileLength = maxFileLength;
358            }
359            public int getMaxFiles() {
360                    return maxFiles;
361            }
362            public void setMaxFiles(int maxFiles) {
363                    this.maxFiles = maxFiles;
364            }
365            public long getMaxLength() {
366                    return maxLength;
367            }
368            public void setMaxLength(long maxLength) {
369                    this.maxLength = maxLength;
370            }
371            public int getUploadThreadCount() {
372                    return uploadThreadCount;
373            }
374            public void setUploadThreadCount(int uploadThreadCount) {
375                    this.uploadThreadCount = uploadThreadCount;
376            }
377            public String getUploadUrl() {
378                    return uploadUrl;
379            }
380            public void setUploadUrl(String uploadUrl) {
381                    this.uploadUrl = uploadUrl;
382            }
383            public String getFileParameterName() {
384                    return fileParameterName;
385            }
386            public void setFileParameterName(String fileParameterName) {
387                    this.fileParameterName = fileParameterName;
388            }
389            public long getPartitionLength() {
390                    return partitionLength;
391            }
392            public void setPartitionLength(long partitionLength) {
393                    this.partitionLength = partitionLength;
394            }
395            public String getUserAgent() {
396                    return userAgent;
397            }
398            public void setUserAgent(String userAgent) {
399                    this.userAgent = userAgent;
400            }
401            public boolean isUseMd5() {
402                    return useMd5;
403            }
404            public void setUseMd5(boolean useMd5) {
405                    this.useMd5 = useMd5;
406            }
407            public int getMinFiles() {
408                    return minFiles;
409            }
410            public void setMinFiles(int minFiles) {
411                    this.minFiles = minFiles;
412            }
413            public String getScaledInstanceDimensions() {
414                    return scaledInstanceDimensions;
415            }
416            public void setScaledInstanceDimensions(String scaledInstanceDimensions) {
417                    this.scaledInstanceDimensions = scaledInstanceDimensions;
418            }
419            public String getScaledInstanceNames() {
420                    return scaledInstanceNames;
421            }
422            public void setScaledInstanceNames(String scaledInstanceNames) {
423                    this.scaledInstanceNames = scaledInstanceNames;
424            }
425            public String getScaledInstanceQualityFactors() {
426                    return scaledInstanceQualityFactors;
427            }
428            public void setScaledInstanceQualityFactors(String scaledInstanceQualityFactors) {
429                    this.scaledInstanceQualityFactors = scaledInstanceQualityFactors;
430            }
431            public boolean isUploadScaledImages() {
432                    return uploadScaledImages;
433            }
434            public void setUploadScaledImages(boolean uploadScaledImages) {
435                    this.uploadScaledImages = uploadScaledImages;
436            }
437            public long getMinFileLength() {
438                    return minFileLength;
439            }
440            public void setMinFileLength(long minFileLength) {
441                    this.minFileLength = minFileLength;
442            }
443            public boolean isUseMainFile() {
444                    return useMainFile;
445            }
446            public void setUseMainFile(boolean useMainFile) {
447                    this.useMainFile = useMainFile;
448            }
449            public boolean isAddImagesOnly() {
450                    return addImagesOnly;
451            }
452            public void setAddImagesOnly(boolean addImagesOnly) {
453                    this.addImagesOnly = addImagesOnly;
454            }
455            public String getMinimumImageDimension() {
456                    return minimumImageDimension;
457            }
458            public void setMinimumImageDimension(String minimumImageDimension) {
459                    this.minimumImageDimension = minimumImageDimension;
460            }
461            public String getMaximumImageDimension() {
462                    return maximumImageDimension;
463            }
464            public void setMaximumImageDimension(String maximumImageDimension) {
465                    this.maximumImageDimension = maximumImageDimension;
466            }
467            public boolean isImageEditorEnabled() {
468                    return imageEditorEnabled;
469            }
470            public void setImageEditorEnabled(boolean imageEditorEnabled) {
471                    this.imageEditorEnabled = imageEditorEnabled;
472            }
473            public String getResumeCheckUrl() {
474                    return resumeCheckUrl;
475            }
476            public void setResumeCheckUrl(String resumeCheckUrl) {
477                    this.resumeCheckUrl = resumeCheckUrl;
478            }
479            public boolean isUsePartitionMd5() {
480                    return usePartitionMd5;
481            }
482            public void setUsePartitionMd5(boolean usePartitionMd5) {
483                    this.usePartitionMd5 = usePartitionMd5;
484            }
485            public boolean isUploadOriginalImage() {
486                    return uploadOriginalImage;
487            }
488            public void setUploadOriginalImage(boolean uploadOriginalImage) {
489                    this.uploadOriginalImage = uploadOriginalImage;
490            }
491            public boolean isStretchImages() {
492                    return stretchImages;
493            }
494            public void setStretchImages(boolean stretchImages) {
495                    this.stretchImages = stretchImages;
496            }
497            public boolean isUrlEncodeParameters() {
498                    return urlEncodeParameters;
499            }
500            public void setUrlEncodeParameters(boolean urlEncodeParameters) {
501                    this.urlEncodeParameters = urlEncodeParameters;
502            }
503            public boolean isSendFileLastModified() {
504                    return sendFileLastModified;
505            }
506            public void setSendFileLastModified(boolean sendFileLastModified) {
507                    this.sendFileLastModified = sendFileLastModified;
508            }
509            public boolean isZipDirectoriesOnAdd() {
510                    return zipDirectoriesOnAdd;
511            }
512            public void setZipDirectoriesOnAdd(boolean zipDirectoriesOnAdd) {
513                    this.zipDirectoriesOnAdd = zipDirectoriesOnAdd;
514            }
515            public boolean isSendFilePath() {
516                    return sendFilePath;
517            }
518            public void setSendFilePath(boolean sendFilePath) {
519                    this.sendFilePath = sendFilePath;
520            }
521            public long getMaxTransferRate() {
522                    return maxTransferRate;
523            }
524            public void setMaxTransferRate(long maxTransferRate) {
525                    this.maxTransferRate = maxTransferRate;
526            }
527            public String getCookie() {
528                    return cookie;
529            }
530            public void setCookie(String cookie) {
531                    this.cookie = cookie;
532            }
533            public String getHttpUploaderClassName() {
534                    return httpUploaderClassName;
535            }
536            public void setHttpUploaderClassName(String httpUploaderClassName) {
537                    this.httpUploaderClassName = httpUploaderClassName;
538            }
539            public boolean isUploadQueueReorderingAllowed() {
540                    return uploadQueueReorderingAllowed;
541            }
542            public void setUploadQueueReorderingAllowed(boolean uploadQueueReorderingAllowed) {
543                    this.uploadQueueReorderingAllowed = uploadQueueReorderingAllowed;
544            }
545            public String getRequestEncoding() {
546                    return requestEncoding;
547            }
548            public void setRequestEncoding(String requestEncoding) {
549                    this.requestEncoding = requestEncoding;
550            }
551            public boolean isSendExif() {
552                    return sendExif;
553            }
554            public void setSendExif(boolean sendExif) {
555                    this.sendExif = sendExif;
556            }
557            public String getScaledInstanceWatermarkNames() {
558                    return scaledInstanceWatermarkNames;
559            }
560            public void setScaledInstanceWatermarkNames(String scaledInstanceWatermarkNames) {
561                    this.scaledInstanceWatermarkNames = scaledInstanceWatermarkNames;
562            }
563            public List getScaledInstanceWatermarks() {
564                    return scaledInstanceWatermarks;
565            }
566            public void setScaledInstanceWatermarks(List scaledInstanceWatermarks) {
567                    this.scaledInstanceWatermarks = scaledInstanceWatermarks;
568            }
569            public boolean isPreserveRelativePath() {
570                    return preserveRelativePath;
571            }
572            public void setPreserveRelativePath(boolean preserveRelativePath) {
573                    this.preserveRelativePath = preserveRelativePath;
574            }
575            public boolean isUploadScaledImagesNoZip() {
576                    return uploadScaledImagesNoZip;
577            }
578            public void setUploadScaledImagesNoZip(boolean uploadScaledImagesNoZip) {
579                    this.uploadScaledImagesNoZip = uploadScaledImagesNoZip;
580            }
581            public boolean isSendIptc() {
582                    return sendIptc;
583            }
584            public void setSendIptc(boolean sendIptc) {
585                    this.sendIptc = sendIptc;
586            }
587    }