Source Code Cross Referenced for LocalLib.java in  » GIS » geonetwork » org » fao » geonet » 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.geonet.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.geonet.lib;
025:
026:        import java.sql.SQLException;
027:        import java.util.ArrayList;
028:        import java.util.HashMap;
029:        import java.util.List;
030:        import java.util.Map;
031:        import java.util.Set;
032:        import jeeves.resources.dbms.Dbms;
033:        import org.jdom.Element;
034:
035:        //=============================================================================
036:
037:        public class LocalLib {
038:            //-----------------------------------------------------------------------------
039:            //---
040:            //--- API methods
041:            //---
042:            //-----------------------------------------------------------------------------
043:
044:            public Map<String, String> getLanguages(Dbms dbms)
045:                    throws SQLException {
046:                HashMap<String, String> hm = new HashMap<String, String>();
047:
048:                for (Object obj : dbms.select("SELECT * FROM Languages")
049:                        .getChildren()) {
050:                    Element lang = (Element) obj;
051:                    hm.put(lang.getChildText("id"), lang.getChildText("name"));
052:                }
053:
054:                return hm;
055:            }
056:
057:            //-----------------------------------------------------------------------------
058:
059:            public void insert(Dbms dbms, String baseTable, int id, String name)
060:                    throws SQLException {
061:                Set<String> langs = getLanguages(dbms).keySet();
062:
063:                String query = "INSERT INTO " + baseTable
064:                        + "Des(idDes, langId, label) VALUES (?,?,?)";
065:
066:                for (String langId : langs)
067:                    dbms.execute(query, id, langId, name);
068:            }
069:
070:            //-----------------------------------------------------------------------------
071:
072:            public void insert(Dbms dbms, String baseTable, int id,
073:                    Map<String, String> locNames, String defName)
074:                    throws SQLException {
075:                Set<String> langs = getLanguages(dbms).keySet();
076:
077:                String query = "INSERT INTO " + baseTable
078:                        + "Des(idDes, langId, label) VALUES (?,?,?)";
079:
080:                for (String langId : langs) {
081:                    String name = (locNames == null) ? null : locNames
082:                            .get(langId);
083:
084:                    //--- check if the local language does not exist in locNames
085:                    //--- this will help to align languages with remote sites
086:
087:                    if (name == null)
088:                        name = defName;
089:
090:                    dbms.execute(query, id, langId, name);
091:                }
092:            }
093:
094:            //-----------------------------------------------------------------------------
095:
096:            public void update(Dbms dbms, String baseTable, int id,
097:                    Element label) throws SQLException {
098:                List labels = label.getChildren();
099:
100:                for (Object lt : labels) {
101:                    Element locText = (Element) lt;
102:
103:                    String langId = locText.getName();
104:                    String value = locText.getText();
105:
106:                    update(dbms, baseTable, id, langId, value);
107:                }
108:            }
109:
110:            //-----------------------------------------------------------------------------
111:
112:            public void update(Dbms dbms, String baseTable, int id,
113:                    String langId, String label) throws SQLException {
114:                String query = "UPDATE " + baseTable
115:                        + "Des SET label=? WHERE idDes=? AND langId=?";
116:
117:                dbms.execute(query, label, id, langId);
118:            }
119:
120:            //-----------------------------------------------------------------------------
121:
122:            public Element retrieve(Dbms dbms, String table)
123:                    throws SQLException {
124:                return retrieve(dbms, table, null, null, null);
125:            }
126:
127:            //-----------------------------------------------------------------------------
128:
129:            public Element retrieve(Dbms dbms, String table, String where)
130:                    throws SQLException {
131:                return retrieve(dbms, table, null, where, null);
132:            }
133:
134:            //-----------------------------------------------------------------------------
135:
136:            public Element retrieve(Dbms dbms, String table, String where,
137:                    String orderBy) throws SQLException {
138:                return retrieve(dbms, table, null, where, orderBy);
139:            }
140:
141:            //-----------------------------------------------------------------------------
142:
143:            public Element retrieveById(Dbms dbms, String table, String id)
144:                    throws SQLException {
145:                return retrieve(dbms, table, id, null, null);
146:            }
147:
148:            //-----------------------------------------------------------------------------
149:            //---
150:            //--- Private methods
151:            //---
152:            //-----------------------------------------------------------------------------
153:
154:            private Element retrieve(Dbms dbms, String table, String id,
155:                    String where, String orderBy) throws SQLException {
156:                String query1 = "SELECT * FROM " + table;
157:                String query2 = "SELECT * FROM " + table + "Des";
158:
159:                if (id == null) {
160:                    if (where != null)
161:                        query1 += " WHERE " + where;
162:                } else {
163:                    query1 += " WHERE id=" + id;
164:                    query2 += " WHERE idDes=" + id;
165:                }
166:
167:                if (orderBy != null)
168:                    query1 += " ORDER BY " + orderBy;
169:
170:                Element result = dbms.select(query1);
171:
172:                List base = result.getChildren();
173:                List des = dbms.select(query2).getChildren();
174:
175:                //--- preprocess data for faster access
176:
177:                Map<String, List<String>> langData = new HashMap<String, List<String>>();
178:
179:                for (Object o : des) {
180:                    Element loc = (Element) o;
181:
182:                    String iddes = loc.getChildText("iddes");
183:                    String lang = loc.getChildText("langid");
184:                    String label = loc.getChildText("label");
185:
186:                    List<String> list = langData.get(iddes);
187:
188:                    if (list == null) {
189:                        list = new ArrayList<String>();
190:                        langData.put(iddes, list);
191:                    }
192:
193:                    list.add(lang);
194:                    list.add(label);
195:                }
196:
197:                //--- fill results
198:
199:                for (Object o : base) {
200:                    Element record = (Element) o;
201:                    Element labels = new Element("label");
202:
203:                    record.addContent(labels);
204:
205:                    id = record.getChildText("id");
206:
207:                    List<String> list = langData.get(id);
208:
209:                    for (int j = 0; j < list.size(); j += 2)
210:                        labels.addContent(new Element(list.get(j)).setText(list
211:                                .get(j + 1)));
212:                }
213:
214:                return result.setName(table.toLowerCase());
215:            }
216:        }
217:
218:        //=============================================================================
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.