Source Code Cross Referenced for MetadataLib.java in  » GIS » geonetwork » org » fao » gast » lib » 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.gast.lib 
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.gast.lib;
025:
026:        import java.io.File;
027:        import java.util.List;
028:        import jeeves.resources.dbms.Dbms;
029:        import jeeves.utils.Xml;
030:        import org.fao.geonet.constants.Geonet;
031:        import org.fao.geonet.constants.Params;
032:        import org.fao.geonet.kernel.DataManager;
033:        import org.fao.geonet.kernel.XmlSerializer;
034:        import org.fao.geonet.kernel.search.SearchManager;
035:        import org.jdom.Element;
036:
037:        //=============================================================================
038:
039:        public class MetadataLib {
040:            //---------------------------------------------------------------------------
041:            //---
042:            //--- Constructor
043:            //---
044:            //---------------------------------------------------------------------------
045:
046:            public MetadataLib(String appPath) throws Exception {
047:                this .appPath = appPath;
048:
049:                //		searchMan = new SearchManager(appPath +"/web/geonetwork/", Lib.config.getLuceneDir());
050:            }
051:
052:            //---------------------------------------------------------------------------
053:            //---
054:            //--- API methods
055:            //---
056:            //---------------------------------------------------------------------------
057:
058:            public Element getMetadata(Dbms dbms, String id) throws Exception {
059:                return XmlSerializer.select(dbms, "Metadata", id);
060:            }
061:
062:            //---------------------------------------------------------------------------
063:
064:            public boolean canConvert(String fromSchema, String toSchema) {
065:                String format = fromSchema + "-to-" + toSchema;
066:                String path = appPath + "/web/geonetwork/conversion/" + format
067:                        + "/main.xsl";
068:
069:                return new File(path).exists();
070:            }
071:
072:            //---------------------------------------------------------------------------
073:
074:            public Element convert(Element md, String fromSchema,
075:                    String toSchema) throws Exception {
076:                if (!canConvert(fromSchema, toSchema))
077:                    throw new Exception("Cannot convert to schema :" + toSchema);
078:
079:                String format = fromSchema + "-to-" + toSchema;
080:                String path = appPath + "/web/geonetwork/conversion/" + format;
081:
082:                Element result = Xml.transform(md, path + "/main.xsl");
083:                Element unmapped = Xml.transform(md, path + "/unmapped.xsl");
084:
085:                Element metadata = new Element("metadata").addContent(result);
086:
087:                return new Element("result").addContent(metadata).addContent(
088:                        unmapped);
089:            }
090:
091:            //---------------------------------------------------------------------------
092:            /** Transactional */
093:
094:            public void sync(Dbms dbms) throws Exception {
095:                try {
096:                    List list = dbms.select(
097:                            "SELECT * FROM Metadata WHERE isTemplate='n'")
098:                            .getChildren();
099:                    dbms.commit();
100:
101:                    String siteURL = Lib.site.getSiteURL(dbms);
102:
103:                    for (int i = 0; i < list.size(); i++) {
104:                        Element record = (Element) list.get(i);
105:
106:                        String id = record.getChildText("id");
107:                        String schema = record.getChildText("schemaid");
108:                        String data = record.getChildText("data");
109:                        String uuid = record.getChildText("uuid");
110:                        String date = record.getChildText("createdate");
111:
112:                        Element md = updateFixedInfo(id, Xml.loadString(data,
113:                                false), uuid, date, schema, siteURL);
114:
115:                        XmlSerializer.update(dbms, id, md, date);
116:                        dbms.commit();
117:                    }
118:                } catch (Exception e) {
119:                    dbms.abort();
120:                    throw e;
121:                }
122:            }
123:
124:            //--------------------------------------------------------------------------
125:
126:            public Element updateFixedInfo(String id, Element md, String uuid,
127:                    String date, String schema, String siteURL)
128:                    throws Exception {
129:                md.detach();
130:
131:                //--- setup environment
132:
133:                Element env = new Element("env");
134:
135:                env.addContent(new Element("id").setText(id));
136:                env.addContent(new Element("uuid").setText(uuid));
137:                env.addContent(new Element("changeDate").setText(date));
138:                env.addContent(new Element("siteURL").setText(siteURL));
139:
140:                //--- setup root element
141:
142:                Element root = new Element("root");
143:
144:                root.addContent(md);
145:                root.addContent(env);
146:
147:                //--- do an XSL  transformation
148:
149:                String styleSheet = appPath + "/web/geonetwork/xml/schemas/"
150:                        + schema + "/" + Geonet.File.UPDATE_FIXED_INFO;
151:
152:                return Xml.transform(root, styleSheet);
153:            }
154:
155:            //---------------------------------------------------------------------------
156:
157:            //	public void index(Dbms dbms, String id) throws Exception
158:            //	{
159:            //		DataManager.indexMetadata(dbms, id, searchMan);
160:            //	}
161:
162:            //---------------------------------------------------------------------------
163:
164:            public void clearIndexes() throws Exception {
165:                File dir = new File(appPath + "/web/geonetwork/"
166:                        + Lib.config.getLuceneDir());
167:                Lib.io.cleanDir(dir);
168:            }
169:
170:            //--------------------------------------------------------------------------
171:
172:            public Element getThumbnails(Dbms dbms, String schema, String id)
173:                    throws Exception {
174:                Element md = XmlSerializer.select(dbms, "Metadata", id);
175:
176:                if (md == null)
177:                    return null;
178:
179:                //--- do an XSL  transformation
180:
181:                String styleSheet = appPath + "/web/geonetwork/xml/schemas/"
182:                        + schema + "/" + Geonet.File.EXTRACT_THUMBNAILS;
183:
184:                return Xml.transform(md, styleSheet);
185:            }
186:
187:            //--------------------------------------------------------------------------
188:
189:            public String getDataDir() {
190:                String dataDir = Lib.config
191:                        .getHandlerProp(Geonet.Config.DATA_DIR);
192:
193:                if (!new File(dataDir).isAbsolute())
194:                    dataDir = appPath + "/web/geonetwork/" + dataDir;
195:
196:                return dataDir;
197:            }
198:
199:            //--------------------------------------------------------------------------
200:
201:            public String getDir(int id, String access) {
202:                String group = pad(id / 100, 3);
203:                String groupDir = group + "00-" + group + "99";
204:                String subDir = (access != null && access
205:                        .equals(Params.Access.PUBLIC)) ? Params.Access.PUBLIC
206:                        : Params.Access.PRIVATE;
207:
208:                return getDataDir() + "/" + groupDir + "/" + id + "/" + subDir
209:                        + "/";
210:            }
211:
212:            //--------------------------------------------------------------------------
213:
214:            public Element setUUID(String schema, String uuid, Element md)
215:                    throws Exception {
216:                //--- setup environment
217:
218:                Element env = new Element("env");
219:                env.addContent(new Element("uuid").setText(uuid));
220:
221:                //--- setup root element
222:
223:                Element root = new Element("root");
224:                root.addContent(md);
225:                root.addContent(env);
226:
227:                //--- do an XSL  transformation
228:
229:                String styleSheet = appPath + "/web/geonetwork/xml/schemas/"
230:                        + schema + "/" + Geonet.File.SET_UUID;
231:
232:                return Xml.transform(root, styleSheet);
233:            }
234:
235:            //-----------------------------------------------------------------------------
236:
237:            public void insertMetadata(Dbms dbms, String schema, Element md,
238:                    int id, String source, String createDate,
239:                    String changeDate, String uuid, int owner,
240:                    String groupOwner, String template, String title)
241:                    throws Exception {
242:                //--- force namespace prefix for iso19139 metadata
243:                DataManager.setNamespacePrefix(md);
244:
245:                XmlSerializer.insert(dbms, schema, md, id, source, uuid,
246:                        createDate, changeDate, template, title, owner,
247:                        groupOwner);
248:            }
249:
250:            //-----------------------------------------------------------------------------
251:            //---
252:            //--- Private methods
253:            //---
254:            //-----------------------------------------------------------------------------
255:
256:            private String pad(int group, int lenght) {
257:                String text = Integer.toString(group);
258:
259:                while (text.length() < lenght)
260:                    text = "0" + text;
261:
262:                return text;
263:            }
264:
265:            //---------------------------------------------------------------------------
266:            //---
267:            //--- Variables
268:            //---
269:            //---------------------------------------------------------------------------
270:
271:            private String appPath;
272:
273:            private SearchManager searchMan;
274:        }
275:
276:        //=============================================================================
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.