001: //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/trunk/src/org/deegree/ogcwebservices/csw/manager/TransactionResultDocument.java $
002: /*---------------- FILE HEADER ------------------------------------------
003:
004: This file is part of deegree.
005: Copyright (C) 2001-2008 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.net.URI;
048: import java.util.ArrayList;
049: import java.util.List;
050:
051: import org.deegree.framework.log.ILogger;
052: import org.deegree.framework.log.LoggerFactory;
053: import org.deegree.framework.xml.NamespaceContext;
054: import org.deegree.framework.xml.XMLFragment;
055: import org.deegree.framework.xml.XMLParsingException;
056: import org.deegree.framework.xml.XMLTools;
057: import org.deegree.ogcbase.CommonNamespaces;
058: import org.w3c.dom.Document;
059: import org.w3c.dom.Element;
060: import org.w3c.dom.Node;
061: import org.xml.sax.SAXException;
062:
063: /**
064: *
065: *
066: *
067: * @version $Revision: 9549 $
068: * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
069: * @author last edited by: $Author: lbuesching $
070: *
071: * @version 1.0. $Revision: 9549 $, $Date: 2008-01-16 02:17:02 -0800 (Wed, 16 Jan 2008) $
072: *
073: * @since 2.0
074: */
075: public class TransactionResultDocument extends XMLFragment {
076:
077: private static final ILogger LOG = LoggerFactory
078: .getLogger(TransactionDocument.class);
079:
080: private NamespaceContext nsc = CommonNamespaces
081: .getNamespaceContext();
082:
083: /**
084: * initializes an empty TransactionDocument
085: *
086: */
087: public TransactionResultDocument() {
088: try {
089: setSystemId(XMLFragment.DEFAULT_URL);
090: } catch (MalformedURLException e) {
091: LOG.logError(e.getMessage(), e);
092: }
093: }
094:
095: /**
096: *
097: * @throws IOException
098: * @throws SAXException
099: */
100: public void createEmptyDocument(String version) {
101: Document doc = XMLTools.create();
102: URI namespaceURI = (version.equals("2.0.2")) ? CommonNamespaces.CSW202NS
103: : CommonNamespaces.CSWNS;
104: Element root = doc
105: .createElementNS(namespaceURI.toASCIIString(),
106: "csw:TransactionResponse");
107: setRootElement(root);
108:
109: }
110:
111: /**
112: * parses a CS-W TransactionResponse document and creates a jave class representation from it.
113: *
114: * @return
115: * @throws XMLParsingException
116: */
117: public TransactionResult parseTransactionResponse(
118: Transaction transaction) throws XMLParsingException {
119:
120: Element root = getRootElement();
121: int inserted = XMLTools.getNodeAsInt(root,
122: "./csw:TransactionSummary/csw:totalInserted", nsc, 0);
123: int deleted = XMLTools.getNodeAsInt(root,
124: "./csw:TransactionSummary/csw:totalDeleted", nsc, 0);
125: int updated = XMLTools.getNodeAsInt(root,
126: "./csw:TransactionSummary/csw:totalUpdated", nsc, 0);
127:
128: List list = XMLTools.getNodes(root,
129: "./csw:InsertResult/child::*", nsc);
130: List<Node> records = new ArrayList<Node>(list.size());
131: for (int i = 0; i < list.size(); i++) {
132: records.add((Node) list.get(i));
133: }
134: InsertResults ir = new InsertResults(records);
135:
136: return new TransactionResult(transaction, inserted, deleted,
137: updated, ir);
138:
139: }
140:
141: }
|