Source Code Cross Referenced for XmlSerializer.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:        //=============================================================================
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;
025:
026:        import java.sql.SQLException;
027:        import java.util.List;
028:        import java.util.Vector;
029:        import jeeves.constants.Jeeves;
030:        import jeeves.resources.dbms.Dbms;
031:        import jeeves.server.UserSession;
032:        import jeeves.utils.Util;
033:        import jeeves.utils.Xml;
034:        import org.fao.geonet.util.ISODate;
035:        import org.jdom.Element;
036:
037:        //=============================================================================
038:
039:        /** This class is responsible of reading and writing xml on the database. It
040:         * works on tables like (id, data, lastChangeDate)
041:         */
042:
043:        public class XmlSerializer {
044:            //--------------------------------------------------------------------------
045:            //---
046:            //--- API
047:            //---
048:            //--------------------------------------------------------------------------
049:
050:            /** Retrieve the xml element which id matches the given one. The element is
051:             * read from 'table' and the string read is converted into xml
052:             */
053:
054:            public static Element select(Dbms dbms, String table, String id)
055:                    throws Exception {
056:                String query = "SELECT * FROM " + table + " WHERE id = ?";
057:
058:                Element rec = dbms.select(query, new Integer(id)).getChild(
059:                        Jeeves.Elem.RECORD);
060:
061:                if (rec == null)
062:                    return null;
063:
064:                String xmlData = rec.getChildText("data");
065:
066:                //		if (!xmlData.startsWith("<?xml"))
067:                //			xmlData  = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n" + xmlData;
068:
069:                rec = Xml.loadString(xmlData, false);
070:
071:                return (Element) rec.detach();
072:            }
073:
074:            //--------------------------------------------------------------------------
075:
076:            public static String insert(Dbms dbms, String schema, Element xml,
077:                    int serial, String source, String uuid, int owner,
078:                    String groupOwner) throws SQLException {
079:                return insert(dbms, schema, xml, serial, source, uuid, null,
080:                        null, "n", null, owner, groupOwner);
081:            }
082:
083:            //--------------------------------------------------------------------------
084:
085:            public static String insert(Dbms dbms, String schema, Element xml,
086:                    int serial, String source, String uuid, String isTemplate,
087:                    String title, int owner, String groupOwner)
088:                    throws SQLException {
089:                return insert(dbms, schema, xml, serial, source, uuid, null,
090:                        null, isTemplate, title, owner, groupOwner);
091:            }
092:
093:            //--------------------------------------------------------------------------
094:
095:            public static String insert(Dbms dbms, String schema, Element xml,
096:                    int serial, String source, String uuid, String createDate,
097:                    String changeDate, String isTemplate, String title,
098:                    int owner, String groupOwner) throws SQLException {
099:                String date = new ISODate().toString();
100:
101:                if (createDate == null)
102:                    createDate = date;
103:
104:                if (changeDate == null)
105:                    changeDate = date;
106:
107:                fixCR(xml);
108:
109:                StringBuffer fields = new StringBuffer(
110:                        "id, schemaId, data, createDate, changeDate, source, "
111:                                + "uuid, isTemplate, isHarvested, root, owner, groupOwner");
112:                StringBuffer values = new StringBuffer(
113:                        "?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?");
114:
115:                Vector args = new Vector();
116:                args.add(new Integer(serial));
117:                args.add(schema);
118:                args.add(Xml.getString(xml));
119:                args.add(createDate);
120:                args.add(changeDate);
121:                args.add(source);
122:                args.add(uuid.toLowerCase());
123:                args.add(isTemplate);
124:                args.add("n");
125:                args.add(xml.getQualifiedName());
126:                args.add(owner);
127:
128:                if (groupOwner != null)
129:                    args.add(new Integer(groupOwner));
130:                else
131:                    args.add(null);
132:
133:                if (title != null) {
134:                    fields.append(", title");
135:                    values.append(", ?");
136:                    args.add(title);
137:                }
138:
139:                String query = "INSERT INTO Metadata (" + fields + ") VALUES("
140:                        + values + ")";
141:                dbms.execute(query, args.toArray());
142:
143:                return Integer.toString(serial);
144:            }
145:
146:            //--------------------------------------------------------------------------
147:            /** Updates an xml element into the database. The new data replaces the old one
148:             */
149:
150:            public static void update(Dbms dbms, String id, Element xml)
151:                    throws SQLException {
152:                update(dbms, id, xml, null);
153:            }
154:
155:            //--------------------------------------------------------------------------
156:
157:            public static void update(Dbms dbms, String id, Element xml,
158:                    String changeDate) throws SQLException {
159:                String query = "UPDATE Metadata SET data=?, changeDate=?, root=? WHERE id=?";
160:
161:                Vector args = new Vector();
162:
163:                fixCR(xml);
164:                args.add(Xml.getString(xml));
165:
166:                if (changeDate == null)
167:                    args.add(new ISODate().toString());
168:                else
169:                    args.add(changeDate);
170:
171:                args.add(xml.getQualifiedName());
172:                args.add(new Integer(id));
173:
174:                dbms.execute(query, args.toArray());
175:            }
176:
177:            //--------------------------------------------------------------------------
178:            /** Deletes an xml element given its id
179:             */
180:
181:            public static void delete(Dbms dbms, String table, String id)
182:                    throws SQLException {
183:                String query = "DELETE FROM " + table + " WHERE id=" + id;
184:
185:                dbms.execute(query);
186:            }
187:
188:            //--------------------------------------------------------------------------
189:
190:            private static void fixCR(Element xml) {
191:                List list = xml.getChildren();
192:
193:                if (list.size() == 0) {
194:                    String text = xml.getText();
195:
196:                    xml.setText(Util.replaceString(text, "\r\n", "\n"));
197:                }
198:
199:                else
200:                    for (Object o : list)
201:                        fixCR((Element) o);
202:            }
203:
204:            //---------------------------------------------------------------------------
205:
206:            //	public static void dump(String name, String text)
207:            //	{
208:            //		System.out.print("name: "+name+", value:");
209:            //
210:            //		char[] chars = text.toCharArray();
211:            //
212:            //		for(char c: chars)
213:            //		{
214:            //			int i = c;
215:            //
216:            //			if (i>=32)	System.out.print(c);
217:            //				else		System.out.print("["+ i +"]");
218:            //		}
219:            //
220:            //		System.out.println("");
221:            //	}
222:        }
223:
224:        //=============================================================================
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.