Source Code Cross Referenced for WebDavRetriever.java in  » GIS » geonetwork » org » fao » geonet » kernel » harvest » harvester » webdav » 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 » geonetwork » org.fao.geonet.kernel.harvest.harvester.webdav 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        //=============================================================================
002:        //===	Copyright (C) 2001-2007 Food and Agriculture Organization of the
003:        //===	United Nations (FAO-UN), United Nations World Food Programme (WFP)
004:        //===	and United Nations Environment Programme (UNEP)
005:        //===
006:        //===	This program is free software; you can redistribute it and/or modify
007:        //===	it under the terms of the GNU General Public License as published by
008:        //===	the Free Software Foundation; either version 2 of the License, or (at
009:        //===	your option) any later version.
010:        //===
011:        //===	This program is distributed in the hope that it will be useful, but
012:        //===	WITHOUT ANY WARRANTY; without even the implied warranty of
013:        //===	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014:        //===	General Public License for more details.
015:        //===
016:        //===	You should have received a copy of the GNU General Public License
017:        //===	along with this program; if not, write to the Free Software
018:        //===	Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
019:        //===
020:        //===	Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2,
021:        //===	Rome - Italy. email: geonetwork@osgeo.org
022:        //==============================================================================
023:
024:        package org.fao.geonet.kernel.harvest.harvester.webdav;
025:
026:        import java.io.IOException;
027:        import java.util.ArrayList;
028:        import java.util.List;
029:        import jeeves.interfaces.Logger;
030:        import jeeves.server.context.ServiceContext;
031:        import org.apache.commons.httpclient.HttpException;
032:        import org.apache.commons.httpclient.HttpStatus;
033:        import org.apache.commons.httpclient.HttpURL;
034:        import org.apache.commons.httpclient.HttpsURL;
035:        import org.apache.webdav.lib.WebdavResource;
036:        import org.fao.geonet.GeonetContext;
037:        import org.fao.geonet.constants.Geonet;
038:        import org.fao.geonet.kernel.setting.SettingManager;
039:        import org.fao.geonet.lib.Lib;
040:
041:        //=============================================================================
042:
043:        class WebDavRetriever implements  RemoteRetriever {
044:            //--------------------------------------------------------------------------
045:            //---
046:            //--- RemoteRetriever interface
047:            //---
048:            //--------------------------------------------------------------------------
049:
050:            public void init(Logger log, ServiceContext context,
051:                    WebDavParams params) {
052:                this .log = log;
053:                this .context = context;
054:                this .params = params;
055:            }
056:
057:            //---------------------------------------------------------------------------
058:
059:            public List<RemoteFile> retrieve() throws Exception {
060:                davRes = open(params.url);
061:
062:                files.clear();
063:                retrieveFiles(davRes);
064:
065:                return files;
066:            }
067:
068:            //---------------------------------------------------------------------------
069:
070:            public void destroy() {
071:                try {
072:                    davRes.close();
073:                } catch (Exception e) {
074:                    log.warning("Cannot close resource : " + e.getMessage());
075:                }
076:            }
077:
078:            //---------------------------------------------------------------------------
079:            //---
080:            //--- Private methods
081:            //---
082:            //---------------------------------------------------------------------------
083:
084:            private WebdavResource open(String url) throws Exception {
085:                if (!url.endsWith("/"))
086:                    url += "/";
087:
088:                try {
089:                    log.info("Connecting to webdav url for node : "
090:                            + params.name);
091:
092:                    WebdavResource wr = createResource(params.url);
093:
094:                    log.info("Connected to webdav resource at : " + url);
095:
096:                    //--- we are interested only in folders
097:                    if (!wr.isCollection()) {
098:                        log.error("Resource url is not a collection : " + url);
099:                        wr.close();
100:
101:                        throw new Exception(
102:                                "Resource url is not a collection : " + url);
103:                    }
104:
105:                    log.info("Resource path is : " + wr.getPath());
106:
107:                    return wr;
108:                }
109:
110:                catch (HttpException e) {
111:                    int code = e.getReasonCode();
112:
113:                    if (code == HttpStatus.SC_METHOD_NOT_ALLOWED)
114:                        throw new Exception("Server does not support WebDAV");
115:
116:                    if (code == HttpStatus.SC_UNAUTHORIZED)
117:                        throw new Exception("Unauthorized to access resource");
118:
119:                    throw new Exception(
120:                            "Received unknown response from server : "
121:                                    + e.getReason());
122:                }
123:            }
124:
125:            //---------------------------------------------------------------------------
126:
127:            private WebdavResource createResource(String url) throws Exception {
128:                HttpURL http = url.startsWith("https") ? new HttpsURL(url)
129:                        : new HttpURL(url);
130:
131:                if (params.useAccount)
132:                    http.setUserinfo(params.username, params.password);
133:
134:                //--- setup proxy, if the case
135:
136:                GeonetContext gc = (GeonetContext) context
137:                        .getHandlerContext(Geonet.CONTEXT_NAME);
138:                SettingManager sm = gc.getSettingManager();
139:
140:                boolean enabled = sm.getValueAsBool("system/proxy/use", false);
141:                String host = sm.getValue("system/proxy/host");
142:                String port = sm.getValue("system/proxy/port");
143:
144:                if (!enabled)
145:                    return new WebdavResource(http);
146:
147:                if (!Lib.type.isInteger(port))
148:                    throw new Exception("Proxy port is not an integer : "
149:                            + port);
150:
151:                return new WebdavResource(http, host, Integer.parseInt(port));
152:            }
153:
154:            //---------------------------------------------------------------------------
155:
156:            private void retrieveFiles(WebdavResource wr) throws HttpException,
157:                    IOException {
158:                String path = wr.getPath();
159:
160:                log.debug("Scanning resource : " + path);
161:
162:                String[] children = wr.list();
163:
164:                if (children == null)
165:                    log.warning("Cannot scan resource. Error is : "
166:                            + wr.getStatusMessage());
167:                else {
168:                    int startSize = files.size();
169:
170:                    for (String name : children) {
171:                        wr.setPath(path + "/" + name);
172:
173:                        if (wr.exists()) {
174:                            if (wr.isCollection()) {
175:                                //--- this test is needed to fix a slide bug
176:
177:                                if (!wr.getPath().equals(path))
178:                                    if (params.recurse)
179:                                        retrieveFiles(wr);
180:                            }
181:
182:                            else if (wr.getName().toLowerCase()
183:                                    .endsWith(".xml"))
184:                                files.add(new WebDavRemoteFile(wr));
185:                        }
186:                    }
187:
188:                    int endSize = files.size();
189:                    int added = endSize - startSize;
190:
191:                    if (added == 0)
192:                        log.debug("No xml files found in path : " + path);
193:                    else
194:                        log.debug("Found " + added + " xml file(s) in path : "
195:                                + path);
196:                }
197:            }
198:
199:            //---------------------------------------------------------------------------
200:            //---
201:            //--- Variables
202:            //---
203:            //---------------------------------------------------------------------------
204:
205:            private Logger log;
206:            private ServiceContext context;
207:            private WebDavParams params;
208:            private WebdavResource davRes;
209:
210:            private List<RemoteFile> files = new ArrayList<RemoteFile>();
211:        }
212:
213:        //=============================================================================
w__ww_.___j___a__v__a__2__s._c_o_m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.