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.media.impl;
034:
035: import com.flexive.shared.media.FxImageMetadata;
036: import com.flexive.shared.media.FxMediaType;
037: import com.flexive.shared.FxXMLUtils;
038: import static com.flexive.shared.FxXMLUtils.writeSimpleTag;
039:
040: import javax.xml.stream.XMLStreamWriter;
041: import javax.xml.stream.XMLStreamException;
042: import java.awt.color.ICC_Profile;
043: import java.util.List;
044:
045: /**
046: * Image metadata
047: *
048: * @author Markus Plesser (markus.plesser@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
049: * @version $Rev
050: */
051: public class FxImageMetadataImpl extends FxImageMetadata {
052: private String mimeType;
053: private String filename;
054: private List<FxMetadataItem> metadata;
055: private int width;
056: private int height;
057: private String format;
058: private String formatDescription;
059: private String compressionAlgorithm;
060: private double xResolution;
061: private double yResolution;
062: private String colorType;
063: private boolean usePalette;
064: private int bpp;
065: private boolean progressive;
066: private boolean transparent;
067: private ICC_Profile icc;
068:
069: private static final double DEFAULT_RESOLUTION = 72.0d;
070:
071: public FxImageMetadataImpl(String mimeType, String filename,
072: List<FxMetadataItem> metadata, int width, int height,
073: String format, String formatDescription,
074: String compressionAlgorithm, double xResolution,
075: double yResolution, String colorType, boolean usePalette,
076: int bpp, boolean progressive, boolean transparent,
077: ICC_Profile icc) {
078: this .mimeType = mimeType;
079: this .filename = filename;
080: this .metadata = metadata;
081: this .width = width;
082: this .height = height;
083: this .format = format;
084: this .formatDescription = formatDescription;
085: if (compressionAlgorithm != null) {
086: if (compressionAlgorithm.startsWith("RLE"))
087: compressionAlgorithm = "RLE";
088: else if (compressionAlgorithm.startsWith("PNG"))
089: compressionAlgorithm = "PNG";
090: else if (compressionAlgorithm.startsWith("CCITT Group 3"))
091: compressionAlgorithm = "CCITT_GROUP_3 ";
092: else if (compressionAlgorithm.startsWith("CCITT Group 4"))
093: compressionAlgorithm = "CCITT_GROUP_3 ";
094: else if (compressionAlgorithm.equals("CCITT 1D"))
095: compressionAlgorithm = "CCITT_GROUP_1D ";
096: }
097: this .compressionAlgorithm = compressionAlgorithm;
098: if (xResolution < 0)
099: this .xResolution = DEFAULT_RESOLUTION;
100: else
101: this .xResolution = xResolution;
102: if (yResolution < 0)
103: this .yResolution = DEFAULT_RESOLUTION;
104: else
105: this .yResolution = yResolution;
106: this .colorType = colorType;
107: this .usePalette = usePalette;
108: this .bpp = bpp;
109: this .progressive = progressive;
110: this .transparent = transparent;
111: this .icc = icc;
112:
113: }
114:
115: /**
116: * {@inheritDoc}
117: */
118: public FxMediaType getMediaType() {
119: return FxMediaType.Image;
120: }
121:
122: /**
123: * {@inheritDoc}
124: */
125: public String getMimeType() {
126: return mimeType;
127: }
128:
129: /**
130: * {@inheritDoc}
131: */
132: public String getFilename() {
133: return filename;
134: }
135:
136: /**
137: * {@inheritDoc}
138: */
139: public List<FxMetadataItem> getMetadata() {
140: return metadata;
141: }
142:
143: /**
144: * {@inheritDoc}
145: */
146: public int getWidth() {
147: return width;
148: }
149:
150: /**
151: * {@inheritDoc}
152: */
153: public int getHeight() {
154: return height;
155: }
156:
157: /**
158: * {@inheritDoc}
159: */
160: public String getFormat() {
161: return format;
162: }
163:
164: /**
165: * {@inheritDoc}
166: */
167: public String getFormatDescription() {
168: return formatDescription;
169: }
170:
171: /**
172: * {@inheritDoc}
173: */
174: public String getCompressionAlgorithm() {
175: return compressionAlgorithm;
176: }
177:
178: /**
179: * {@inheritDoc}
180: */
181: public double getXResolution() {
182: return xResolution;
183: }
184:
185: /**
186: * {@inheritDoc}
187: */
188: public double getYResolution() {
189: return yResolution;
190: }
191:
192: /**
193: * {@inheritDoc}
194: */
195: public String getColorType() {
196: return colorType;
197: }
198:
199: /**
200: * {@inheritDoc}
201: */
202: public boolean usePalette() {
203: return usePalette;
204: }
205:
206: /**
207: * {@inheritDoc}
208: */
209: public int getBitsPerPixel() {
210: return bpp;
211: }
212:
213: /**
214: * {@inheritDoc}
215: */
216: public boolean isProgressive() {
217: return progressive;
218: }
219:
220: /**
221: * {@inheritDoc}
222: */
223: public boolean isTransparent() {
224: return transparent;
225: }
226:
227: /**
228: * {@inheritDoc}
229: */
230: public boolean hasICC_Profile() {
231: return icc != null;
232: }
233:
234: /**
235: * {@inheritDoc}
236: */
237: public ICC_Profile getICC_Profile() {
238: return icc;
239: }
240:
241: /**
242: * {@inheritDoc}
243: */
244: protected void writeXMLTags(XMLStreamWriter writer)
245: throws XMLStreamException {
246: writer.writeStartElement("imageData");
247: writeSimpleTag(writer, "width", getWidth(), false);
248: writeSimpleTag(writer, "height", getHeight(), false);
249: writeSimpleTag(writer, "bpp", getBitsPerPixel(), false);
250: writeSimpleTag(writer, "colorType", getColorType(), true);
251: writeSimpleTag(writer, "compressionAlgorithm",
252: getCompressionAlgorithm(), true);
253: writeSimpleTag(writer, "format", getFormat(), true);
254: writeSimpleTag(writer, "formatDescription",
255: getFormatDescription(), true);
256: writeSimpleTag(writer, "xResolution", getXResolution(), false);
257: writeSimpleTag(writer, "yResolution", getYResolution(), false);
258: writer.writeEndElement();
259: }
260: }
|