Source Code Cross Referenced for BinaryDescriptor.java in  » J2EE » fleXive » com » flexive » shared » value » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » fleXive » com.flexive.shared.value 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /***************************************************************
002:         *  This file is part of the [fleXive](R) project.
003:         *
004:         *  Copyright (c) 1999-2008
005:         *  UCS - unique computing solutions gmbh (http://www.ucs.at)
006:         *  All rights reserved
007:         *
008:         *  The [fleXive](R) project is free software; you can redistribute
009:         *  it and/or modify it under the terms of the GNU General Public
010:         *  License as published by the Free Software Foundation;
011:         *  either version 2 of the License, or (at your option) any
012:         *  later version.
013:         *
014:         *  The GNU General Public License can be found at
015:         *  http://www.gnu.org/copyleft/gpl.html.
016:         *  A copy is found in the textfile GPL.txt and important notices to the
017:         *  license from the author are found in LICENSE.txt distributed with
018:         *  these libraries.
019:         *
020:         *  This library is distributed in the hope that it will be useful,
021:         *  but WITHOUT ANY WARRANTY; without even the implied warranty of
022:         *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
023:         *  GNU General Public License for more details.
024:         *
025:         *  For further information about UCS - unique computing solutions gmbh,
026:         *  please see the company website: http://www.ucs.at
027:         *
028:         *  For further information about [fleXive](R), please see the
029:         *  project website: http://www.flexive.org
030:         *
031:         *
032:         *  This copyright notice MUST APPEAR in all copies of the file!
033:         ***************************************************************/package com.flexive.shared.value;
034:
035:        import com.flexive.shared.FxSharedUtils;
036:        import com.flexive.shared.ObjectWithLabel;
037:        import com.flexive.shared.exceptions.FxStreamException;
038:        import com.flexive.shared.stream.BinaryUploadPayload;
039:        import com.flexive.shared.stream.FxStreamUtils;
040:        import com.flexive.stream.ServerLocation;
041:
042:        import java.io.*;
043:        import java.util.List;
044:
045:        /**
046:         * Descriptor for binaries
047:         *
048:         * @author Markus Plesser (markus.plesser@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
049:         */
050:        public class BinaryDescriptor implements  Serializable {
051:            private static final long serialVersionUID = -416186902840155773L;
052:
053:            public final static int SYS_UNKNOWN = -1;
054:            public final static int SYS_NOACCESS = -2;
055:            public final static int SYS_AUDIO = -3;
056:            public final static int SYS_DOC = -4;
057:            public final static int SYS_ICAL = -5;
058:            public final static int SYS_INFO = -6;
059:            public final static int SYS_PDF = -7;
060:            public final static int SYS_TXT = -8;
061:            public final static int SYS_VIDEO = -9;
062:            public final static int SYS_XLS = -10;
063:            public final static int SYS_PPT = -6; //TODO: find a fitting thumbnail!
064:            public final static int SYS_HTML = -8; //TODO: find a fitting thumbnail!
065:
066:            public final static int SYS_SELECTLIST_DEFAULT = -11;
067:
068:            public final static String EMPTY = "[EMPTY]";
069:            /**
070:             * For images: box scaled size for preview 1
071:             */
072:            public final static int PREVIEW1_BOX = 42;
073:            /**
074:             * For images: box scaled size for preview 2
075:             */
076:            public final static int PREVIEW2_BOX = 85;
077:            /**
078:             * For images: box scaled size for preview 3
079:             */
080:            public final static int PREVIEW3_BOX = 232;
081:
082:            /**
083:             * Enumeration of all available preview sizes.
084:             */
085:            public static enum PreviewSizes implements  ObjectWithLabel {
086:                PREVIEW1(1, PREVIEW1_BOX), PREVIEW2(2, PREVIEW2_BOX), PREVIEW3(
087:                        3, PREVIEW3_BOX), ORIGINAL(0, -1);
088:
089:                private final int blobIndex;
090:                private final int size;
091:
092:                PreviewSizes(int blobIndex, int size) {
093:                    this .blobIndex = blobIndex;
094:                    this .size = size;
095:                }
096:
097:                public int getSize() {
098:                    return size;
099:                }
100:
101:                public int getBlobIndex() {
102:                    return blobIndex;
103:                }
104:
105:                /** {@inheritDoc} */
106:                public FxString getLabel() {
107:                    return FxSharedUtils.getEnumLabel(this , size, size);
108:                }
109:            }
110:
111:            private String handle = null;
112:            private boolean newBinary;
113:            private List<ServerLocation> server;
114:
115:            private long id = -1;
116:            private int version;
117:            private int quality;
118:            private long creationTime;
119:            private String name;
120:            private long size;
121:            private String metadata;
122:            private String mimeType;
123:            private boolean image;
124:            private double resolution;
125:            private int width;
126:            private int height;
127:
128:            /**
129:             * Constructor (for new Binaries)
130:             *
131:             * @param handle binary_transit handle
132:             */
133:            public BinaryDescriptor(String handle) {
134:                this .handle = handle;
135:                this .newBinary = true;
136:            }
137:
138:            /**
139:             * Constructor for new Binaries in prepareSave process ..
140:             *
141:             * @param handle   handle
142:             * @param name     name of the binary
143:             * @param size     size in bytes
144:             * @param mimeType MIME type
145:             * @param metadata xml meta data
146:             */
147:            public BinaryDescriptor(String handle, String name, long size,
148:                    String mimeType, String metadata) {
149:                this .handle = handle;
150:                this .newBinary = true;
151:                this .name = name;
152:                this .size = size;
153:                this .metadata = metadata;
154:                this .mimeType = mimeType;
155:            }
156:
157:            /**
158:             * Constructor for a new empty binary
159:             */
160:            public BinaryDescriptor() {
161:                this .handle = EMPTY;
162:                this .newBinary = true;
163:            }
164:
165:            /**
166:             * Constructor (for new Binaries)
167:             *
168:             * @param name         name of the binary
169:             * @param streamLength expected size of the binary
170:             * @param stream       an open input stream for the binary to upload
171:             * @throws FxStreamException on upload errors
172:             */
173:            public BinaryDescriptor(String name, long streamLength,
174:                    InputStream stream) throws FxStreamException {
175:                this .name = name;
176:                this .size = streamLength;
177:                BinaryUploadPayload payload = FxStreamUtils.uploadBinary(
178:                        streamLength, stream);
179:                this .handle = payload.getHandle();
180:                this .newBinary = true;
181:            }
182:
183:            /**
184:             * Constructor (for new Binaries with unknown length - use with care since it will have to create a temp file to determine length!)
185:             *
186:             * @param name         name of the binary
187:             * @param stream       an open input stream for the binary to upload
188:             * @throws FxStreamException on upload errors
189:             */
190:            public BinaryDescriptor(String name, InputStream stream)
191:                    throws FxStreamException {
192:                this .name = name;
193:
194:                File tmp = null;
195:                FileOutputStream fos = null;
196:                FileInputStream fin = null;
197:                final int BUF_SIZE = 4096;
198:                try {
199:                    tmp = File.createTempFile("FxBinary", ".bin");
200:                    fos = new FileOutputStream(tmp);
201:                    byte[] buffer = new byte[BUF_SIZE];
202:                    int read;
203:                    while ((read = stream.read(buffer)) != -1) {
204:                        fos.write(buffer, 0, read);
205:                    }
206:                    fos.flush();
207:                    fos.close();
208:                    fos = null;
209:                    fin = new FileInputStream(tmp);
210:                    this .size = tmp.length();
211:                    BinaryUploadPayload payload = FxStreamUtils.uploadBinary(
212:                            tmp.length(), fin);
213:                    this .handle = payload.getHandle();
214:                } catch (IOException e) {
215:                    throw new FxStreamException(e, "ex.stream", e.getMessage());
216:                } finally {
217:                    try {
218:                        if (fos != null)
219:                            fos.close();
220:                    } catch (IOException e) {
221:                        //ignore
222:                    }
223:                    try {
224:                        if (fin != null)
225:                            fin.close();
226:                    } catch (IOException e) {
227:                        //ignore
228:                    }
229:                    if (tmp != null) {
230:                        if (!tmp.delete())
231:                            tmp.deleteOnExit();
232:                    }
233:                }
234:                this .newBinary = true;
235:            }
236:
237:            /**
238:             * Constructor - used for loading from the content engine
239:             *
240:             * @param server       server location
241:             * @param id           binary id
242:             * @param version      binary version
243:             * @param quality      quality
244:             * @param creationTime timestamp when the binary data was created in the storage
245:             * @param name         name
246:             * @param size         size
247:             * @param metadata     xml metadata
248:             * @param mimeType     mime type
249:             * @param image        binary is an image?
250:             * @param resolution   resoltion (if image and detected)
251:             * @param width        width (if image and detected)
252:             * @param height       height (if image and detected)
253:             */
254:            public BinaryDescriptor(List<ServerLocation> server, long id,
255:                    int version, int quality, long creationTime, String name,
256:                    long size, String metadata, String mimeType, boolean image,
257:                    double resolution, int width, int height) {
258:                this .server = server;
259:                this .id = id;
260:                this .version = version;
261:                this .quality = quality;
262:                this .creationTime = creationTime;
263:                this .name = name;
264:                this .size = size;
265:                this .metadata = metadata;
266:                this .mimeType = mimeType;
267:                this .image = image;
268:                this .resolution = resolution;
269:                this .width = width;
270:                this .height = height;
271:            }
272:
273:            /**
274:             * Downloads the binary to the given stream.
275:             * The stream won't be flushed or closed!
276:             *
277:             * @param stream stream used for download
278:             * @throws FxStreamException on errors
279:             */
280:            public void download(OutputStream stream) throws FxStreamException {
281:                FxStreamUtils.downloadBinary(server, stream, this );
282:            }
283:
284:            public String getHandle() {
285:                return handle;
286:            }
287:
288:            public boolean isNewBinary() {
289:                return newBinary;
290:            }
291:
292:            public long getId() {
293:                return id;
294:            }
295:
296:            public int getVersion() {
297:                return version;
298:            }
299:
300:            public int getQuality() {
301:                return quality;
302:            }
303:
304:            public long getCreationTime() {
305:                return creationTime;
306:            }
307:
308:            public String getName() {
309:                return name;
310:            }
311:
312:            public long getSize() {
313:                return size;
314:            }
315:
316:            public String getMetadata() {
317:                return metadata;
318:            }
319:
320:            public String getMimeType() {
321:                return mimeType;
322:            }
323:
324:            public boolean isImage() {
325:                return image;
326:            }
327:
328:            public double getResolution() {
329:                return resolution;
330:            }
331:
332:            public int getWidth() {
333:                return width;
334:            }
335:
336:            public int getHeight() {
337:                return height;
338:            }
339:
340:            /**
341:             * {@inheritDoc}
342:             */
343:            @Override
344:            public boolean equals(Object obj) {
345:                if (!(obj instanceof  BinaryDescriptor))
346:                    return false;
347:                BinaryDescriptor b = (BinaryDescriptor) obj;
348:                return !(b.getMetadata() != null && !b.getMetadata().equals(
349:                        this .getMetadata()))
350:                        && !(this .getMetadata() != null && !this .getMetadata()
351:                                .equals(b.getMetadata()))
352:                        && !(this .getMetadata() == null && b.getMetadata() != null)
353:                        && !(b.getMetadata() == null && this .getMetadata() != null)
354:                        && !(b.getMimeType() != null && !b.getMimeType()
355:                                .equals(this .getMimeType()))
356:                        && !(this .getMimeType() != null && !this .getMimeType()
357:                                .equals(b.getMimeType()))
358:                        && !(this .getMimeType() == null && b.getMimeType() != null)
359:                        && !(b.getMimeType() == null && this .getMimeType() != null)
360:                        && !(this .handle != null && !this .handle
361:                                .equals(b.handle))
362:                        && !(this .id != -1 && this .id != b.id);
363:            }
364:
365:            /**
366:             * {@inheritDoc}
367:             */
368:            @Override
369:            public int hashCode() {
370:                return (int) this .id
371:                        + (this .handle != null ? 31 * this .handle.hashCode()
372:                                : 0);
373:            }
374:
375:            /**
376:             * {@inheritDoc}
377:             */
378:            @Override
379:            public String toString() {
380:                return this .getName() + " " + this.mimeType;
381:            }
382:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.