Source Code Cross Referenced for APSImageReaderSpi.java in  » GIS » GeoTools-2.4.1 » it » geosolutions » imageio » plugins » jhdf » aps » 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 » GIS » GeoTools 2.4.1 » it.geosolutions.imageio.plugins.jhdf.aps 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package it.geosolutions.imageio.plugins.jhdf.aps;
002:
003:        import it.geosolutions.imageio.plugins.jhdf.BaseHDFImageReaderSpi;
004:        import it.geosolutions.imageio.stream.input.FileImageInputStreamExtImpl;
005:
006:        import java.io.File;
007:        import java.io.IOException;
008:        import java.util.Iterator;
009:        import java.util.Locale;
010:
011:        import javax.imageio.ImageReader;
012:
013:        import ncsa.hdf.object.Attribute;
014:        import ncsa.hdf.object.FileFormat;
015:        import ncsa.hdf.object.HObject;
016:
017:        public class APSImageReaderSpi extends BaseHDFImageReaderSpi {
018:
019:            /**
020:             * The list of the required attributes was built in compliance with the
021:             * information available at:
022:             * http://www7333.nrlssc.navy.mil/docs/aps_v3.4/user/aps/ch06.html
023:             * 
024:             */
025:            private final static String[] requiredAPSAttributes = { "file",
026:                    "fileClassification", "fileStatus", "fileTitle",
027:                    "fileVersion", "createAgency", "createSoftware",
028:                    "createPlatform", "createTime",
029:            /* "createUser" */}; // TODO: Add more attributes??
030:
031:            static final String[] suffixes = { "hdf" };
032:
033:            static final String[] formatNames = { "HDF", "HDF4", "HDF5" };
034:
035:            static final String[] mimeTypes = { "image/hdf" };
036:
037:            static final String version = "1.0";
038:
039:            static final String readerCN = "it.geosolutions.imageio.plugins.jhdf.aps.APSImageReader";
040:
041:            static final String vendorName = "GeoSolutions";
042:
043:            // writerSpiNames
044:            static final String[] wSN = { null };
045:
046:            // StreamMetadataFormatNames and StreamMetadataFormatClassNames
047:            static final boolean supportsStandardStreamMetadataFormat = false;
048:
049:            static final String nativeStreamMetadataFormatName = "it.geosolutions.imageio.plugins.jhdf.aps.APSHDFStreamMetadata_1.0";
050:
051:            static final String nativeStreamMetadataFormatClassName = null;
052:
053:            static final String[] extraStreamMetadataFormatNames = { null };
054:
055:            static final String[] extraStreamMetadataFormatClassNames = { null };
056:
057:            // ImageMetadataFormatNames and ImageMetadataFormatClassNames
058:            static final boolean supportsStandardImageMetadataFormat = false;
059:
060:            static final String nativeImageMetadataFormatName = "it.geosolutions.imageio.plugins.jhdf.aps.APSHDFImageMetadata_1.0";
061:
062:            static final String nativeImageMetadataFormatClassName = null;
063:
064:            static final String[] extraImageMetadataFormatNames = { null };
065:
066:            static final String[] extraImageMetadataFormatClassNames = { null };
067:
068:            public APSImageReaderSpi() {
069:                super (
070:                        vendorName,
071:                        version,
072:                        formatNames,
073:                        suffixes,
074:                        mimeTypes,
075:                        readerCN, // readerClassName
076:                        STANDARD_INPUT_TYPE,
077:                        wSN, // writer Spi Names
078:                        supportsStandardStreamMetadataFormat,
079:                        nativeStreamMetadataFormatName,
080:                        nativeStreamMetadataFormatClassName,
081:                        extraStreamMetadataFormatNames,
082:                        extraStreamMetadataFormatClassNames,
083:                        supportsStandardImageMetadataFormat,
084:                        nativeImageMetadataFormatName,
085:                        nativeImageMetadataFormatClassName,
086:                        extraImageMetadataFormatNames,
087:                        extraImageMetadataFormatClassNames);
088:            }
089:
090:            //
091:            // This version of the canDecodeInput checks if all required attributes are
092:            // present
093:            // in the APS source.
094:            //
095:            private boolean OldcanDecodeInput(Object input) throws IOException {
096:                if (input instanceof  FileImageInputStreamExtImpl) {
097:                    input = ((FileImageInputStreamExtImpl) input).getFile();
098:                }
099:
100:                if (input instanceof  File) {
101:                    final String filepath = ((File) input).getPath();
102:
103:                    // TODO: Improve to add HDF5 support.
104:                    final FileFormat fileFormat = FileFormat
105:                            .getFileFormat(FileFormat.FILE_TYPE_HDF4);
106:                    if (fileFormat != null && fileFormat.isThisType(filepath))
107:                        try {
108:                            final FileFormat testFile = fileFormat.open(
109:                                    filepath, FileFormat.READ);
110:                            if (testFile != null) {
111:                                if (testFile.open() >= 0) {
112:
113:                                    // CHECKS IF APS REQUIRED ATTRIBUTES ARE PRESENT
114:                                    final int requiredAttributes = requiredAPSAttributes.length;
115:                                    int foundAttributes = 0;
116:                                    HObject root = testFile.get("/");
117:                                    final Iterator metadataIt = root
118:                                            .getMetadata().iterator();
119:
120:                                    while (metadataIt.hasNext()) {
121:                                        // get the attribute
122:                                        final Attribute att = (Attribute) metadataIt
123:                                                .next();
124:                                        final String attName = att.getName();
125:                                        for (int i = 0; i < requiredAttributes; i++) {
126:                                            if (attName
127:                                                    .equals(requiredAPSAttributes[i])) {
128:                                                foundAttributes++;
129:                                                if (foundAttributes == requiredAttributes) {
130:                                                    // Avoid to scan the whole
131:                                                    // attributes
132:                                                    // list if I already found the
133:                                                    // required ones
134:                                                    testFile.close();
135:                                                    return true;
136:                                                }
137:                                                break;
138:                                            }
139:                                        }
140:                                    }
141:
142:                                    testFile.close();
143:                                    if (foundAttributes == requiredAttributes)
144:                                        return true;
145:                                    return false;
146:                                }
147:                            }
148:                        } catch (IOException e) {
149:                            throw e;
150:                        } catch (Exception e) {
151:                        }
152:                }
153:                return false;
154:            }
155:
156:            public boolean canDecodeInput(Object input) throws IOException {
157:                synchronized (spiMutex) {
158:
159:                    if (input instanceof  FileImageInputStreamExtImpl) {
160:                        input = ((FileImageInputStreamExtImpl) input).getFile();
161:                    }
162:
163:                    if (input instanceof  File) {
164:                        final String filepath = ((File) input).getPath();
165:
166:                        // TODO: Improve to add HDF5 support.
167:                        final FileFormat fileFormat = FileFormat
168:                                .getFileFormat(FileFormat.FILE_TYPE_HDF4);
169:                        if (fileFormat != null
170:                                && fileFormat.isThisType(filepath))
171:                            try {
172:                                final FileFormat testFile = fileFormat.open(
173:                                        filepath, FileFormat.READ);
174:                                if (testFile != null) {
175:                                    if (testFile.open() >= 0) {
176:                                        boolean found = false;
177:                                        HObject root = testFile.get("/");
178:                                        final Iterator metadataIt = root
179:                                                .getMetadata().iterator();
180:
181:                                        while (metadataIt.hasNext()) {
182:                                            // get the attribute
183:                                            final Attribute att = (Attribute) metadataIt
184:                                                    .next();
185:                                            final String attName = att
186:                                                    .getName();
187:
188:                                            if (attName
189:                                                    .equals(APSProperties.STD_FA_CREATESOFTWARE)) {
190:                                                final Object attValue = att
191:                                                        .getValue();
192:                                                final String value[] = ((String[]) attValue);
193:                                                if (value[0].startsWith("APS")) {
194:                                                    found = true;
195:                                                    break;
196:                                                }
197:                                            }
198:
199:                                        }
200:
201:                                        testFile.close();
202:                                        return found;
203:                                    }
204:                                }
205:                            } catch (IOException e) {
206:                                throw e;
207:                            } catch (Exception e) {
208:                                // TODO
209:                            }
210:                    }
211:                    return false;
212:                }
213:            }
214:
215:            /**
216:             * Returns an instance of the APSImageReader
217:             * 
218:             * @see javax.imageio.spi.ImageReaderSpi#createReaderInstance(java.lang.Object)
219:             */
220:            public ImageReader createReaderInstance(Object source)
221:                    throws IOException {
222:                return new APSImageReader(this );
223:            }
224:
225:            /**
226:             * @see javax.imageio.spi.IIOServiceProvider#getDescription(java.util.Locale)
227:             */
228:            public String getDescription(Locale locale) {
229:                return new StringBuffer(
230:                        "APS Compliant HDF Image Reader, version ").append(
231:                        version).toString();
232:            }
233:
234:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.