Source Code Cross Referenced for WorldImageServiceExtension.java in  » GIS » udig-1.1 » net » refractions » udig » catalog » internal » worldimage » 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 » udig 1.1 » net.refractions.udig.catalog.internal.worldimage 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * uDig - User Friendly Desktop Internet GIS client http://udig.refractions.net (C) 2004,
003:         * Refractions Research Inc. This library is free software; you can redistribute it and/or modify it
004:         * under the terms of the GNU Lesser General Public License as published by the Free Software
005:         * Foundation; version 2.1 of the License. This library is distributed in the hope that it will be
006:         * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
007:         * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
008:         */
009:        package net.refractions.udig.catalog.internal.worldimage;
010:
011:        import java.io.File;
012:        import java.io.Serializable;
013:        import java.net.MalformedURLException;
014:        import java.net.URL;
015:        import java.util.HashMap;
016:        import java.util.Map;
017:
018:        import net.refractions.udig.catalog.IService;
019:        import net.refractions.udig.catalog.ServiceExtension2;
020:        import net.refractions.udig.catalog.URLUtils;
021:        import net.refractions.udig.catalog.worldimage.internal.Messages;
022:
023:        import org.geotools.gce.image.WorldImageFormat;
024:        import org.geotools.gce.image.WorldImageFormatFactory;
025:
026:        /**
027:         * Provides the interface to the catalog service extension point.
028:         * <p>
029:         * This class is responsible for ensuring that only those services that the 
030:         * WorldImage plugin is capable of processing are created.
031:         * </p>
032:         * @author mleslie
033:         * @since 0.6.0
034:         */
035:        public class WorldImageServiceExtension implements  ServiceExtension2 {
036:            /** <code>URL_PARAM</code> field */
037:            public final static String URL_PARAM = "URL"; //$NON-NLS-1$
038:
039:            private static WorldImageFormatFactory factory;
040:
041:            /**
042:             * Construct <code>WorldImageServiceExtension</code>.
043:             *
044:             */
045:            public WorldImageServiceExtension() {
046:                super ();
047:            }
048:
049:            public IService createService(URL id,
050:                    Map<String, Serializable> params) {
051:                URL id2 = id;
052:                //    	if( !canProcess(id))
053:                //    		return null;
054:
055:                if (id2 == null) {
056:                    id2 = getID(params);
057:                }
058:                if (!canProcess(id2)) {
059:                    return null;
060:                }
061:                WorldImageServiceImpl service = new WorldImageServiceImpl(id2,
062:                        getFactory());
063:                return service;
064:            }
065:
066:            private URL getID(Map<String, Serializable> params) {
067:                if (params.containsKey(URL_PARAM)) {
068:                    Object param = params.get(URL_PARAM);
069:                    if (param instanceof  String) {
070:                        try {
071:                            return new URL((String) param);
072:                        } catch (MalformedURLException ex) {
073:                            return null;
074:                        }
075:                    } else if (param instanceof  URL) {
076:                        return (URL) param;
077:                    } else {
078:                        return null;
079:                    }
080:                } else {
081:                    return null;
082:                }
083:            }
084:
085:            /**
086:             * Finds or creates a WorldImageFormatFactory.
087:             * 
088:             * @return Default instance of WorldImageFormatFactory
089:             */
090:            public static WorldImageFormatFactory getFactory() {
091:                if (factory == null) {
092:                    factory = new WorldImageFormatFactory();
093:                }
094:                return factory;
095:            }
096:
097:            private boolean canProcess(URL id) {
098:                return reasonForFailure(id) == null;
099:            }
100:
101:            public Map<String, Serializable> createParams(URL url) {
102:                if (!canProcess(url))
103:                    return null;
104:
105:                if (url != null) {
106:                    Map<String, Serializable> params = new HashMap<String, Serializable>();
107:                    params.put(URL_PARAM, url);
108:                    return params;
109:                }
110:
111:                return null;
112:            }
113:
114:            public String reasonForFailure(Map<String, Serializable> params) {
115:                return reasonForFailure(getID(params));
116:            }
117:
118:            public String reasonForFailure(URL id) {
119:                if (id == null) {
120:                    return Messages.WorldImageServiceExtension_noID;
121:                }
122:                String fileExt = id.getFile().substring(
123:                        id.getFile().indexOf('.') + 1);
124:                if (fileExt.compareToIgnoreCase("PNG") != 0 && //$NON-NLS-1$
125:                        fileExt.compareToIgnoreCase("GIF") != 0 && //$NON-NLS-1$
126:                        fileExt.compareToIgnoreCase("JPG") != 0 && //$NON-NLS-1$
127:                        fileExt.compareToIgnoreCase("JPEG") != 0 && //&& //$NON-NLS-1$
128:                        fileExt.compareToIgnoreCase("TIF") != 0 && //$NON-NLS-1$
129:                        fileExt.compareToIgnoreCase("TIFF") != 0) { //$NON-NLS-1$
130:                    return Messages.WorldImageServiceExtension_badFileExtension
131:                            + fileExt;
132:                }
133:                File file = URLUtils.urlToFile(id);
134:                String fileName = file.getAbsolutePath();
135:                int index = fileName.indexOf('.');
136:                String fileRoot = fileName.substring(0, index);
137:                File worldFile = new File(fileRoot + ".wld"); //$NON-NLS-1$
138:                if (!worldFile.exists()) {
139:                    String wldExt = WorldImageFormat.getWorldExtension(fileExt);
140:                    File otherWorldFile = new File(fileRoot + wldExt);
141:                    if (!otherWorldFile.exists()) {
142:                        return Messages.WorldImageServiceExtension_needsFile
143:                                + "\n\t-" + worldFile + "\n" + Messages.WorldImageServiceExtension_or + "\n\t-" + otherWorldFile; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ 
144:                    }
145:                }
146:
147:                if (!id.getProtocol().equals(
148:                        Messages.WorldImageServiceExtension_file)) {
149:                    return Messages.WorldImageServiceExtension_mustBeFIle;
150:                }
151:                try {
152:                    @SuppressWarnings("unused")
153:                    File fileTest = URLUtils.urlToFile(id);
154:                } catch (IllegalArgumentException ex) {
155:                    return Messages.WorldImageServiceExtension_IllegalFilePart1
156:                            + id.getFile()
157:                            + Messages.WorldImageServiceExtension_IllegalFilePart2;
158:                }
159:
160:                if (!(((WorldImageFormat) getFactory().createFormat())
161:                        .accepts(id))) {
162:                    return Messages.WorldImageServiceExtension_geotoolsDisagrees;
163:                }
164:                return null;
165:            }
166:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.