Source Code Cross Referenced for Upload.java in  » GIS » geonetwork » org » fao » geonet » services » thesaurus » 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.services.thesaurus 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        //=============================================================================
002:        //===	Copyright (C) 2001-2005 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019:        //===
020:        //===	Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2,
021:        //===	Rome - Italy. email: GeoNetwork@fao.org
022:        //==============================================================================
023:
024:        package org.fao.geonet.services.thesaurus;
025:
026:        import java.io.File;
027:        import java.io.FileOutputStream;
028:
029:        import jeeves.interfaces.Service;
030:        import jeeves.server.ServiceConfig;
031:        import jeeves.server.context.ServiceContext;
032:        import jeeves.utils.Util;
033:        import jeeves.utils.Xml;
034:        import jeeves.utils.Log;
035:
036:        import org.fao.geonet.GeonetContext;
037:        import org.fao.geonet.constants.Geonet;
038:        import org.fao.geonet.constants.Params;
039:        import org.fao.geonet.kernel.Thesaurus;
040:        import org.fao.geonet.kernel.ThesaurusManager;
041:        import org.jdom.Document;
042:        import org.jdom.Element;
043:
044:        //=============================================================================
045:
046:        /** 
047:         *  
048:         *  Upload one thesaurus file
049:         */
050:
051:        public class Upload implements  Service {
052:            static String FS = System.getProperty("file.separator", "/");
053:            static int inc = 0;
054:
055:            // XSL - IMPORT NOMENCLATURE - FR
056:            public static final String STYLESHEET_SKOS_FR = "lang-fr.xsl";
057:            private String stylePath;
058:
059:            //--------------------------------------------------------------------------
060:            //---
061:            //--- Init
062:            //---
063:            //--------------------------------------------------------------------------
064:
065:            public void init(String appPath, ServiceConfig params)
066:                    throws Exception {
067:                this .stylePath = appPath + FS + Geonet.Path.STYLESHEETS + FS;
068:            }
069:
070:            //--------------------------------------------------------------------------
071:            //---
072:            //--- API
073:            //---
074:            //--------------------------------------------------------------------------
075:
076:            public Element exec(Element params, ServiceContext context)
077:                    throws Exception {
078:                long start = System.currentTimeMillis();
079:                Element uploadResult;
080:
081:                uploadResult = upload(params, context);
082:
083:                long end = System.currentTimeMillis();
084:                long duration = (end - start) / 1000;
085:
086:                Log.debug("Thesaurus", "Uploaded in " + duration + " s.");
087:
088:                Element response = new Element("response");
089:                if (uploadResult != null)
090:                    response.addContent(uploadResult);
091:                return response;
092:
093:                // 		chaîner sur le service d'update/view de la nomenclature ?
094:                //		return update.exec(params, context);
095:            }
096:
097:            /**
098:             * 
099:             * @param params
100:             * @param context
101:             * @return
102:             * @throws Exception
103:             */
104:            private Element upload(Element params, ServiceContext context)
105:                    throws Exception {
106:                String uploadDir = context.getUploadDir();
107:                Element uploadResult = null;
108:
109:                // Le fichier particulier format rdf
110:                String fname = null;
111:                Element param = params.getChild(Params.FNAME);
112:                if (!(param == null || param.getTextTrim().length() == 0)) {
113:                    fname = param.getTextTrim();
114:                }
115:
116:                // Type de thesaurus (local, external)
117:                String type = Util.getParam(params, Params.TYPE, "external");
118:
119:                // Répertoire de thesaurus (Discipline, Place, Stratum, Temporal, Theme)
120:                String dir = Util.getParam(params, Params.DIR);
121:
122:                // Le schéma cible par rapport auquel effectuer la validation éventuelle
123:                String style = Util.getParam(params, Params.STYLESHEET,
124:                        "_none_");
125:
126:                // ?
127:                // String siteId   = Util.getParam(params, Params.SITE_ID,  gc.getSiteId());
128:
129:                // Valider par rapport au schéma cible ?
130:                boolean validate = Util
131:                        .getParam(params, Params.VALIDATE, "off").equals("on");
132:
133:                if ((fname != null) && !fname.equals("")) {
134:
135:                    Element eTSResult;
136:
137:                    File oldFile = new File(uploadDir, fname);
138:                    String extension = fname.substring(fname.lastIndexOf('.'))
139:                            .toLowerCase();
140:
141:                    // -> UN FICHIER XML
142:                    if (extension.equals(".rdf")) {
143:
144:                        Log.debug("Thesaurus", "Uploading thesaurus: " + fname);
145:                        eTSResult = UploadThesaurus(oldFile, style, context,
146:                                validate, fname, type, dir);
147:                    } else {
148:                        Log.debug("Thesaurus",
149:                                "Incorrect extension for thesaurus file name : "
150:                                        + fname);
151:                        throw new Exception(
152:                                "Incorrect extension for thesaurus file name : "
153:                                        + fname);
154:                    }
155:
156:                    uploadResult = new Element("record")
157:                            .setText("Thesaurus uploaded");
158:                    uploadResult.addContent(eTSResult);
159:                }
160:
161:                return uploadResult;
162:            }
163:
164:            /**
165:             * Upload one Thesaurus
166:             * @param oldFile
167:             * @param style
168:             * @param context
169:             * @param validate
170:             * @param siteId
171:             * @param fname
172:             * @param type
173:             * @param dir
174:             * @return Element thesaurus uploaded
175:             * @throws Exception
176:             */
177:            private Element UploadThesaurus(File oldFile, String style,
178:                    ServiceContext context, boolean validate, String fname,
179:                    String type, String dir) throws Exception {
180:
181:                Element TS_xml = null;
182:                Element xml = Xml.loadFile(oldFile);
183:                xml.detach();
184:
185:                if (!style.equals("_none_")) {
186:                    TS_xml = Xml.transform(xml, stylePath + "/" + style);
187:                    TS_xml.detach();
188:                } else
189:                    TS_xml = xml;
190:
191:                // Analyse du fichier
192:                if (TS_xml.getNamespacePrefix().equals("rdf")
193:                        && TS_xml.getName().equals("RDF")) {
194:
195:                    GeonetContext gc = (GeonetContext) context
196:                            .getHandlerContext(Geonet.CONTEXT_NAME);
197:                    ThesaurusManager thesaurusMan = gc.getThesaurusManager();
198:
199:                    // Copie du fichier dans l'espace adéquat			
200:                    // Position dans l'arborescence déterminée par la categorie
201:                    String path = thesaurusMan.buildThesaurusFilePath(fname,
202:                            type, dir);
203:                    File newFile = new File(path);
204:                    Xml.writeResponse(new Document(TS_xml),
205:                            new FileOutputStream(newFile));
206:
207:                    Thesaurus gst = new Thesaurus(fname, type, dir, newFile);
208:                    thesaurusMan.addThesaurus(gst);
209:                } else {
210:                    oldFile.delete();
211:
212:                    // CE N'EST PAS UN FICHIER SKOS !
213:                    throw new Exception("Format de fichier inconnu");
214:
215:                }
216:
217:                return new Element("Thesaurus").setText(oldFile.getName());
218:            }
219:
220:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.