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


001:        /*
002:         *    uDig - User Friendly Desktop Internet GIS client
003:         *    http://udig.refractions.net
004:         *    (C) 2004, Refractions Research Inc.
005:         *
006:         *    This library is free software; you can redistribute it and/or
007:         *    modify it under the terms of the GNU Lesser General Public
008:         *    License as published by the Free Software Foundation;
009:         *    version 2.1 of the License.
010:         *
011:         *    This library is distributed in the hope that it will be useful,
012:         *    but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         *    Lesser General Public License for more details.
015:         *
016:         */
017:        package net.refractions.udig.catalog.ui;
018:
019:        import java.io.File;
020:        import java.net.URL;
021:
022:        import net.refractions.udig.catalog.ui.internal.Messages;
023:
024:        /**
025:         * URLs are used for resolve.getId(), this class contains utility methods to help work with urls
026:         * used in this manner.
027:         * 
028:         * @author jgarnett
029:         * @since 0.9.0
030:         */
031:        public class Identifier {
032:
033:            public static final boolean isFile(URL url) {
034:                return "file".equals(url.getProtocol()); //$NON-NLS-1$
035:            }
036:
037:            public static boolean isGraphic(URL url) {
038:                // http://localhost/mapgraphic
039:                String HOST = url.getHost();
040:                String PROTOCOL = url.getProtocol();
041:                String PATH = url.getPath();
042:                if (!"http".equals(PROTOCOL))return false; //$NON-NLS-1$
043:                if (!"localhost".equals(HOST))return false; //$NON-NLS-1$
044:
045:                if (!"/mapgraphic".equals(PATH))return false; //$NON-NLS-1$
046:
047:                return true;
048:            }
049:
050:            public static boolean isMemory(URL url) {
051:                String HOST = url.getHost();
052:                String PROTOCOL = url.getProtocol();
053:                String PATH = url.getPath();
054:                if (!"http".equals(PROTOCOL))return false; //$NON-NLS-1$
055:                if (!"localhost".equals(HOST))return false; //$NON-NLS-1$
056:
057:                if (!"/scratch".equals(PATH))return false; //$NON-NLS-1$
058:
059:                return true;
060:            }
061:
062:            public static boolean isWMS(URL url) {
063:                String PATH = url.getPath();
064:                String QUERY = url.getQuery();
065:                String PROTOCOL = url.getProtocol();
066:                if (!"http".equals(PROTOCOL)) { //$NON-NLS-1$
067:                    return false;
068:                }
069:                if (QUERY != null
070:                        && QUERY.toUpperCase().indexOf("SERVICE=WMS") != -1) { //$NON-NLS-1$
071:                    return true;
072:                } else if (PATH != null
073:                        && PATH.toUpperCase().indexOf("GEOSERVER/WMS") != -1) { //$NON-NLS-1$
074:                    return true;
075:                }
076:                return false;
077:            }
078:
079:            public static final boolean isWFS(URL url) {
080:                String PATH = url.getPath();
081:                String QUERY = url.getQuery();
082:                String PROTOCOL = url.getProtocol();
083:
084:                if (!"http".equals(PROTOCOL)) { //$NON-NLS-1$
085:                    return false;
086:                }
087:                if (QUERY != null
088:                        && QUERY.toUpperCase().indexOf("SERVICE=WFS") != -1) { //$NON-NLS-1$
089:                    return true;
090:                } else if (PATH != null
091:                        && PATH.toUpperCase().indexOf("GEOSERVER/WFS") != -1) { //$NON-NLS-1$
092:                    return true;
093:                }
094:                return false;
095:            }
096:
097:            public static final boolean isJDBC(URL url) {
098:                String PROTOCOL = url.getProtocol();
099:                String HOST = url.getHost();
100:                return "http".equals(PROTOCOL) && HOST != null && HOST.indexOf(".jdbc") != -1; //$NON-NLS-1$ //$NON-NLS-2$
101:            }
102:
103:            /**
104:             * Aquire "resource " similar to "data/a.shp" from url.
105:             * <p>
106:             * According to the followng breakdown:
107:             * <ul>
108:             * <li>http path is returned
109:             * <li>last entry in the file path is returned
110:             * <li>last two elements of the file path is returned
111:             * <li>jdbc table name is returned
112:             * <li>WFS typeName is returned
113:             * </ul>
114:             * </p>
115:             * <p>
116:             * Here are some examples:
117:             * <ul>
118:             * <li>file:///C:/java/workspace/shapefiles/a.shp becomes "a.shp"
119:             * <li>http://www.refractions.net:8080/geoserver/wfs?REQUEST=GetCapabilities&SERVICE=WFS&type=topp:ROAD
120:             * becomes "topp:ROAD"
121:             * <li>http://www.refractions.net:8080/data/a.shp becomes "data/a.shp"
122:             * <li>ftp://ftp.refractions.net/data/a.shp becomes "data/a.shp"
123:             * <li>http://kraken.postgis.jdbc:5432/production.... becomes road
124:             * </ul>
125:             * <li>
126:             * 
127:             * @param url
128:             * @return label describing the URL as a resource (ie file or content)
129:             */
130:            final static public String labelResource(URL url) {
131:                if (url == null)
132:                    return Messages.ResolveLabelProvider_missingText;
133:
134:                String HOST = url.getHost();
135:                String QUERY = url.getQuery();
136:                String PATH = url.getPath();
137:                String PROTOCOL = url.getProtocol();
138:                String REF = url.getRef();
139:
140:                if (REF != null) {
141:                    return REF;
142:                }
143:                if (PROTOCOL == null) {
144:                    return ""; // we do not represent a server (local host does not cut it) //$NON-NLS-1$
145:                }
146:                StringBuffer label = new StringBuffer();
147:                if ("file".equals(PROTOCOL)) { //$NON-NLS-1$
148:                    int split = PATH.lastIndexOf('/');
149:                    if (split == -1) {
150:                        label.append(PATH);
151:                    } else {
152:                        String file = PATH.substring(split + 1);
153:                        int dot = file.lastIndexOf('.');
154:                        if (dot != -1) {
155:                            file = file.substring(0, dot);
156:                        }
157:                        label.append(file);
158:                    }
159:                } else if ("http".equals(PROTOCOL) && HOST.indexOf(".jdbc") != -1) { //$NON-NLS-1$ //$NON-NLS-2$
160:                    if (QUERY != null) {
161:                        label.append(QUERY);
162:                    } else {
163:                        label.append(PATH);
164:                    }
165:                } else if ("http".equals(PROTOCOL)) { //$NON-NLS-1$
166:                    if (QUERY != null
167:                            && QUERY.toUpperCase().indexOf("SERVICE=WFS") != -1) { //$NON-NLS-1$
168:                        for (String split : QUERY.split("&")) { //$NON-NLS-1$
169:                            if (split.toLowerCase().startsWith("type=")) { //$NON-NLS-1$
170:                                label.append(split.substring(5));
171:                            }
172:                        }
173:                    } else if (QUERY != null
174:                            && QUERY.toUpperCase().indexOf("SERVICE=WMS") != -1) { //$NON-NLS-1$
175:                        for (String split : QUERY.split("&")) { //$NON-NLS-1$
176:                            if (split.startsWith("LAYER=")) { //$NON-NLS-1$
177:                                label.append(split.substring(6));
178:                            }
179:                        }
180:                    } else {
181:                        int split = PATH.lastIndexOf('/');
182:                        if (split == -1) {
183:                            label.append(PATH);
184:                        } else {
185:                            label.append(PATH.substring(split + 1));
186:                        }
187:                    }
188:                } else {
189:                    int split = PATH.lastIndexOf('/');
190:                    if (split == -1) {
191:                        label.append(PATH);
192:                    } else {
193:                        label.append(PATH.substring(split + 1));
194:                    }
195:                }
196:                return label.toString();
197:            }
198:
199:            /**
200:             * Aquire "server" similar to "protocol://host:port" from url.
201:             * <p>
202:             * According to the followng breakdown:
203:             * <ul>
204:             * <li>Protocol http and file is ignored (or assumed)
205:             * <li>File is reduced to HOST and last path entry
206:             * <li>jdbc stuff is encoded as *majic* see, this method sorts it out
207:             * <li>default ports are not displayed
208:             * <li>service=WFS and service=WMS are *magic* as well
209:             * </ul>
210:             * </p>
211:             * <p>
212:             * Here are some examples:
213:             * <ul>
214:             * <li>file:///C:/java/workspace/shapefiles/a.shp becomes "shapefiles/a.shp"
215:             * <li>http://www.refractions.net:8080/geoserver/wfs?REQUEST=GetCapabilities&SERVICE=WFS
216:             * becomes "wfs://www.refractions.net:8080"
217:             * <li>http://www.refractions.net:8080/data/a.shp becomes "www.refractions.net:8080"
218:             * <li>ftp://ftp.refractions.net/data/a.shp becomes "ftp://ftp.refractions.net"
219:             * <li>http://kraken.postgis.jdbc:5432/production becomes postgis://kraken:5432
220:             * </ul>
221:             * <li>
222:             * 
223:             * @param server
224:             * @return label as if url points to just a server
225:             */
226:            final static public String labelServer(URL url) {
227:                if (url == null)
228:                    return Messages.ResolveLabelProvider_missingText;
229:
230:                String HOST = url.getHost();
231:                int PORT = url.getPort();
232:                String PATH = url.getPath();
233:                // String QUERY = url.getQuery();
234:                String PROTOCOL = url.getProtocol();
235:
236:                if (PROTOCOL == null) {
237:                    return ""; // we do not represent a server (local host does not cut it) //$NON-NLS-1$
238:                }
239:                StringBuffer label = new StringBuffer();
240:                if (isFile(url)) {
241:                    String split[] = PATH.split("\\/"); //$NON-NLS-1$
242:
243:                    if (split.length == 0) {
244:                        label.append(File.separatorChar);
245:                    } else {
246:                        if (split.length < 2) {
247:                            label.append(File.separatorChar);
248:                            label.append(split[0]);
249:                            label.append(File.separatorChar);
250:                        } else {
251:                            label.append(split[split.length - 2]);
252:                            label.append(File.separatorChar);
253:                        }
254:                        label.append(split[split.length - 1]);
255:                    }
256:                } else if (isJDBC(url)) {
257:                    int split2 = HOST.lastIndexOf('.');
258:                    int split1 = HOST.lastIndexOf('.', split2 - 1);
259:                    label.append(HOST.substring(split1 + 1, split2));
260:                    label.append("://"); //$NON-NLS-1$
261:                    label.append(HOST.subSequence(0, split1));
262:                } else if ("http".equals(PROTOCOL) || "https".equals(PROTOCOL)) { //$NON-NLS-1$ //$NON-NLS-2$
263:                    if (isWMS(url)) {
264:                        label.append("wms://"); //$NON-NLS-1$
265:                    } else if (isWFS(url)) {
266:                        label.append("wfs://"); //$NON-NLS-1$
267:                    }
268:                    label.append(HOST);
269:                } else {
270:                    label.append(PROTOCOL);
271:                    label.append("://"); //$NON-NLS-1$
272:                    label.append(HOST);
273:                }
274:                if (PORT != -1) {
275:                    label.append(":"); //$NON-NLS-1$
276:                    label.append(PORT);
277:                }
278:                return label.toString();
279:            }
280:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.