001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/tags/2.1/src/org/deegree/ogcwebservices/csw/manager/TransactionResultDocument.java $
002 /*---------------- FILE HEADER ------------------------------------------
003
004 This file is part of deegree.
005 Copyright (C) 2001-2006 by:
006 EXSE, Department of Geography, University of Bonn
007 http://www.giub.uni-bonn.de/deegree/
008 lat/lon GmbH
009 http://www.lat-lon.de
010
011 This library is free software; you can redistribute it and/or
012 modify it under the terms of the GNU Lesser General Public
013 License as published by the Free Software Foundation; either
014 version 2.1 of the License, or (at your option) any later version.
015
016 This library is distributed in the hope that it will be useful,
017 but WITHOUT ANY WARRANTY; without even the implied warranty of
018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019 Lesser General Public License for more details.
020
021 You should have received a copy of the GNU Lesser General Public
022 License along with this library; if not, write to the Free Software
023 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
024
025 Contact:
026
027 Andreas Poth
028 lat/lon GmbH
029 Aennchenstr. 19
030 53115 Bonn
031 Germany
032 E-Mail: poth@lat-lon.de
033
034 Prof. Dr. Klaus Greve
035 Department of Geography
036 University of Bonn
037 Meckenheimer Allee 166
038 53115 Bonn
039 Germany
040 E-Mail: greve@giub.uni-bonn.de
041
042 ---------------------------------------------------------------------------*/
043 package org.deegree.ogcwebservices.csw.manager;
044
045 import java.io.IOException;
046 import java.net.MalformedURLException;
047 import java.util.ArrayList;
048 import java.util.List;
049
050 import org.deegree.framework.log.ILogger;
051 import org.deegree.framework.log.LoggerFactory;
052 import org.deegree.framework.xml.NamespaceContext;
053 import org.deegree.framework.xml.XMLFragment;
054 import org.deegree.framework.xml.XMLParsingException;
055 import org.deegree.framework.xml.XMLTools;
056 import org.deegree.ogcbase.CommonNamespaces;
057 import org.w3c.dom.Document;
058 import org.w3c.dom.Element;
059 import org.w3c.dom.Node;
060 import org.xml.sax.SAXException;
061
062 /**
063 *
064 *
065 *
066 * @version $Revision: 6259 $
067 * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
068 * @author last edited by: $Author: bezema $
069 *
070 * @version 1.0. $Revision: 6259 $, $Date: 2007-03-20 10:15:15 +0100 (Di, 20 Mär 2007) $
071 *
072 * @since 2.0
073 */
074 public class TransactionResultDocument extends XMLFragment {
075
076 private static final ILogger LOG = LoggerFactory.getLogger( TransactionDocument.class );
077
078 private NamespaceContext nsc = CommonNamespaces.getNamespaceContext();
079
080 /**
081 * initializes an empty TransactionDocument
082 *
083 */
084 public TransactionResultDocument() {
085 try {
086 setSystemId( XMLFragment.DEFAULT_URL );
087 } catch ( MalformedURLException e ) {
088 LOG.logError( e.getMessage(), e );
089 }
090 }
091
092 /**
093 *
094 * @throws IOException
095 * @throws SAXException
096 */
097 public void createEmptyDocument() {
098 Document doc = XMLTools.create();
099 Element root = doc.createElementNS( CommonNamespaces.CSWNS.toASCIIString(),
100 "csw:TransactionResponse" );
101 setRootElement( root );
102
103 }
104
105 /**
106 * parses a CS-W TransactionResponse document and creates a jave class representation from it.
107 *
108 * @return
109 * @throws XMLParsingException
110 */
111 public TransactionResult parseTransactionResponse( Transaction transaction )
112 throws XMLParsingException {
113
114 Element root = getRootElement();
115 int inserted = XMLTools.getNodeAsInt( root, "./csw:TransactionSummary/csw:totalInserted",
116 nsc, 0 );
117 int deleted = XMLTools.getNodeAsInt( root, "./csw:TransactionSummary/csw:totalDeleted",
118 nsc, 0 );
119 int updated = XMLTools.getNodeAsInt( root, "./csw:TransactionSummary/csw:totalUpdated",
120 nsc, 0 );
121
122 List list = XMLTools.getNodes( root, "./csw:InsertResult/child::*", nsc );
123 List<Node> records = new ArrayList<Node>( list.size() );
124 for ( int i = 0; i < list.size(); i++ ) {
125 records.add( (Node) list.get( i ) );
126 }
127 InsertResults ir = new InsertResults( records );
128
129 return new TransactionResult( transaction, inserted, deleted, updated, ir );
130
131 }
132
133 }
134
135 /***************************************************************************************************
136 * Changes to this class. What the people have been up to:
137 * $Log$
138 * Revision 1.8 2006/10/13 14:22:08 poth
139 * changes required because of extending TransactionResult from DefaultOGCWebServiceResponse
140 *
141 * Revision 1.7 2006/08/08 09:24:54 poth
142 * log statement added / footer corrected
143 *
144 * Revision 1.6 2006/04/06 20:25:27 poth
145 * *** empty log message ***
146 * Changes to this class. What the people have been up to:
147 * Revision 1.5 2006/04/04 20:39:43 poth
148 * *** empty log message ***
149 * Changes to this class. What the people have been up to:
150 * Revision 1.4 2006/04/04 10:22:02 poth ** empty log message ***
151 *
152 * Revision 1.3 2006/03/30 21:20:26 poth ** empty log message ***
153 *
154 * Revision 1.2 2006/03/27 20:16:03 poth ** empty log message ***
155 *
156 * Revision 1.1 2006/03/25 15:58:36 poth ** empty log message ***
157 *
158 * Revision 1.3 2006/02/21 19:47:49 poth ** empty log message ***
159 *
160 * Revision 1.2 2006/02/20 14:14:00 poth ** empty log message ***
161 *
162 * Revision 1.1 2006/02/20 12:40:02 poth ** empty log message ***
163 *
164 * Revision 1.1 2006/01/09 07:47:09 ap ** empty log message ***
165 *
166 *
167 **************************************************************************************************/