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


001:        //===	Copyright (C) 2001-2005 Food and Agriculture Organization of the
002:        //===	United Nations (FAO-UN), United Nations World Food Programme (WFP)
003:        //===	and United Nations Environment Programme (UNEP)
004:        //===
005:        //===	This program is free software; you can redistribute it and/or modify
006:        //===	it under the terms of the GNU General Public License as published by
007:        //===	the Free Software Foundation; either version 2 of the License, or (at
008:        //===	your option) any later version.
009:        //===
010:        //===	This program is distributed in the hope that it will be useful, but
011:        //===	WITHOUT ANY WARRANTY; without even the implied warranty of
012:        //===	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013:        //===	General Public License for more details.
014:        //===
015:        //===	You should have received a copy of the GNU General Public License
016:        //===	along with this program; if not, write to the Free Software
017:        //===	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018:        //===
019:        //===	Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2,
020:        //===	Rome - Italy. email: GeoNetwork@fao.org
021:        //==============================================================================
022:
023:        package org.fao.geonet.kernel;
024:
025:        import java.io.File;
026:        import java.io.FilenameFilter;
027:        import java.util.Hashtable;
028:
029:        import jeeves.utils.Log;
030:
031:        import org.fao.geonet.constants.Geonet;
032:
033:        import org.openrdf.sesame.Sesame;
034:        import org.openrdf.sesame.config.ConfigurationException;
035:        import org.openrdf.sesame.config.RepositoryConfig;
036:        import org.openrdf.sesame.config.SailConfig;
037:        import org.openrdf.sesame.constants.RDFFormat;
038:        import org.openrdf.sesame.repository.local.LocalRepository;
039:        import org.openrdf.sesame.repository.local.LocalService;
040:
041:        //=============================================================================
042:
043:        public class ThesaurusManager {
044:
045:            private Hashtable<String, Thesaurus> thesauriTable = null;
046:
047:            private LocalService service = null;
048:
049:            private String thesauriDirectory = null;
050:
051:            /**
052:             * 
053:             * @param appPath
054:             * @param thesauriRepository
055:             * @throws Exception
056:             */
057:            public ThesaurusManager(String appPath, String thesauriRepository)
058:                    throws Exception {
059:                // Get Sesame interface
060:                service = Sesame.getService();
061:
062:                File thesauriDir = new File(thesauriRepository);
063:
064:                if (!thesauriDir.isAbsolute())
065:                    thesauriDir = new File(appPath + thesauriDir);
066:
067:                thesauriDirectory = thesauriDir.getAbsolutePath();
068:
069:                initThesauriTable(thesauriDir);
070:            }
071:
072:            /**
073:             * @param fname
074:             * @param type
075:             * @param dname
076:             * @return
077:             */
078:            public String buildThesaurusFilePath(String fname, String type,
079:                    String dname) {
080:                return thesauriDirectory + File.separator + type
081:                        + File.separator + Geonet.CodeList.THESAURUS
082:                        + File.separator + dname + File.separator + fname;
083:            }
084:
085:            /**
086:             * 
087:             * @param thesauriDirectory
088:             */
089:            private void initThesauriTable(File thesauriDirectory) {
090:
091:                //repositoryTable = new Hashtable<String, LocalRepository>();
092:                thesauriTable = new Hashtable<String, Thesaurus>();
093:
094:                if (thesauriDirectory.isDirectory()) {
095:                    // init of external repositories
096:                    File externalThesauriDirectory = new File(
097:                            thesauriDirectory, Geonet.CodeList.EXTERNAL
098:                                    + File.separator
099:                                    + Geonet.CodeList.THESAURUS);
100:                    if (externalThesauriDirectory.isDirectory()) {
101:                        File[] rdfDataDirectory = externalThesauriDirectory
102:                                .listFiles();
103:                        for (int i = 0; i < rdfDataDirectory.length; i++) {
104:                            if (rdfDataDirectory[i].isDirectory()) {
105:                                loadRepositories(rdfDataDirectory[i],
106:                                        Geonet.CodeList.EXTERNAL);
107:                            }
108:                        }
109:                    }
110:
111:                    // init of local repositories
112:                    File localThesauriDirectory = new File(thesauriDirectory,
113:                            Geonet.CodeList.LOCAL + File.separator
114:                                    + Geonet.CodeList.THESAURUS);
115:                    if (localThesauriDirectory.isDirectory()) {
116:                        File[] rdfDataDirectory = localThesauriDirectory
117:                                .listFiles();
118:                        for (int i = 0; i < rdfDataDirectory.length; i++) {
119:                            if (rdfDataDirectory[i].isDirectory()) {
120:                                loadRepositories(rdfDataDirectory[i],
121:                                        Geonet.CodeList.LOCAL);
122:                            }
123:                        }
124:                    }
125:                }
126:            }
127:
128:            /**
129:             * 
130:             * @param thesauriDirectory
131:             */
132:            private void loadRepositories(File thesauriDirectory, String root) {
133:
134:                FilenameFilter filter = new FilenameFilter() {
135:                    public boolean accept(File dir, String name) {
136:                        return name.endsWith(".rdf");
137:                    }
138:                };
139:
140:                String[] rdfDataFile = thesauriDirectory.list(filter);
141:
142:                for (int i = 0; i < rdfDataFile.length; i++) {
143:
144:                    Thesaurus gst = new Thesaurus(rdfDataFile[i], root,
145:                            thesauriDirectory.getName(), new File(
146:                                    thesauriDirectory, rdfDataFile[i]));
147:                    try {
148:                        addThesaurus(gst);
149:                    } catch (Exception e) {
150:                        e.printStackTrace();
151:                        // continue loading
152:                    }
153:                }
154:            }
155:
156:            /**
157:             * 
158:             * @param gst
159:             */
160:            public void addThesaurus(Thesaurus gst) throws Exception {
161:
162:                String thesaurusName = gst.getKey();
163:
164:                Log.debug(Geonet.THESAURUS_MAN, "Adding thesaurus : "
165:                        + thesaurusName);
166:
167:                if (existsThesaurus(thesaurusName)) {
168:                    throw new Exception("A thesaurus exists with code "
169:                            + thesaurusName);
170:                }
171:
172:                LocalRepository thesaurusRepository;
173:                try {
174:                    RepositoryConfig repConfig = new RepositoryConfig(gst
175:                            .getKey());
176:
177:                    SailConfig syncSail = new SailConfig(
178:                            "org.openrdf.sesame.sailimpl.sync.SyncRdfSchemaRepository");
179:                    SailConfig memSail = new org.openrdf.sesame.sailimpl.memory.RdfSchemaRepositoryConfig(
180:                            gst.getFile().getAbsolutePath(), RDFFormat.RDFXML);
181:                    repConfig.addSail(syncSail);
182:                    repConfig.addSail(memSail);
183:                    repConfig.setWorldReadable(true);
184:                    repConfig.setWorldWriteable(true);
185:
186:                    thesaurusRepository = service.createRepository(repConfig);
187:
188:                    gst.setRepository(thesaurusRepository);
189:
190:                    thesauriTable.put(thesaurusName, gst);
191:
192:                } catch (ConfigurationException e) {
193:                    e.printStackTrace();
194:                    throw e;
195:                }
196:            }
197:
198:            /**
199:             * 
200:             * @param name
201:             */
202:            public void remove(String name) {
203:                service.removeRepository(name);
204:                thesauriTable.remove(name);
205:            }
206:
207:            // =============================================================================
208:            // PUBLIC SERVICES
209:
210:            public String getThesauriDirectory() {
211:                return thesauriDirectory;
212:            }
213:
214:            public Hashtable<String, Thesaurus> getThesauriTable() {
215:                return thesauriTable;
216:            }
217:
218:            public LocalRepository getRepositoryByName(String thesaurusName) {
219:                return thesauriTable.get(thesaurusName).getRepository();
220:            }
221:
222:            public Thesaurus getThesaurusByName(String thesaurusName) {
223:                return thesauriTable.get(thesaurusName);
224:            }
225:
226:            /**
227:             * @param name
228:             * @return
229:             */
230:            public boolean existsThesaurus(String name) {
231:                return (thesauriTable.get(name) != null);
232:            }
233:
234:            // =============================================================================
235:
236:            public static void main(String[] args) throws Exception {
237:                /*	ThesaurusManager tm = new ThesaurusManager("",
238:                			"E:\\workspace3.2\\TestSesame\\res\\codelist\\");*/
239:                //	tm.getAllPrefLabel("adminstrativeAreaFrv0.1");
240:            }
241:
242:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.