001: //$HeadURL$
002: /*---------------- FILE HEADER ------------------------------------------
003: This file is part of deegree.
004: Copyright (C) 2001-2008 by:
005: Department of Geography, University of Bonn
006: http://www.giub.uni-bonn.de/deegree/
007: lat/lon GmbH
008: http://www.lat-lon.de
009:
010: This library is free software; you can redistribute it and/or
011: modify it under the terms of the GNU Lesser General Public
012: License as published by the Free Software Foundation; either
013: version 2.1 of the License, or (at your option) any later version.
014: This library is distributed in the hope that it will be useful,
015: but WITHOUT ANY WARRANTY; without even the implied warranty of
016: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: Lesser General Public License for more details.
018: You should have received a copy of the GNU Lesser General Public
019: License along with this library; if not, write to the Free Software
020: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
021: Contact:
022:
023: Andreas Poth
024: lat/lon GmbH
025: Aennchenstr. 19
026: 53177 Bonn
027: Germany
028: E-Mail: poth@lat-lon.de
029:
030: Prof. Dr. Klaus Greve
031: Department of Geography
032: University of Bonn
033: Meckenheimer Allee 166
034: 53115 Bonn
035: Germany
036: E-Mail: greve@giub.uni-bonn.de
037: ---------------------------------------------------------------------------*/
038:
039: package org.deegree.ogcwebservices.csw.discovery;
040:
041: import java.io.IOException;
042: import java.net.URL;
043: import java.util.Map;
044:
045: import org.deegree.framework.util.StringTools;
046: import org.deegree.framework.xml.XMLTools;
047: import org.deegree.i18n.Messages;
048: import org.deegree.ogcbase.ExceptionCode;
049: import org.deegree.ogcwebservices.InvalidParameterValueException;
050: import org.deegree.ogcwebservices.OGCWebServiceException;
051: import org.w3c.dom.Node;
052: import org.xml.sax.SAXException;
053:
054: /**
055: *
056: *
057: * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
058: * @author last edited by: $Author: poth $
059: *
060: * @version $Revision: 6251 $, $Date: 2007-03-19 16:59:28 +0100 (Mo, 19 Mrz 2007) $
061: */
062: public class GetRecordByIdDocument_2_0_2 extends GetRecordByIdDocument {
063:
064: private static final String XML_TEMPLATE = "GetRecordByIdTemplate2.0.2.xml";
065:
066: /**
067: *
068: * @param id
069: * @return
070: */
071: GetRecordById parse(String id) throws OGCWebServiceException {
072:
073: String version = null;
074: Map<String, String> vendorSpecificParameters = null;
075: String[] ids = null;
076: String elementSetName = null;
077:
078: try {
079: // '<csw202:GetRecords>'-element (required)
080: Node contextNode = XMLTools.getRequiredNode(this
081: .getRootElement(), "self::csw202:GetRecordById",
082: nsContext);
083:
084: // 'service'-attribute (required, must be CSW)
085: String service = XMLTools.getRequiredNodeAsString(
086: contextNode, "@service", nsContext);
087: if (!service.equals("CSW")) {
088: ExceptionCode code = ExceptionCode.INVALIDPARAMETERVALUE;
089: throw new InvalidParameterValueException(
090: "GetRecordById", "'service' must be 'CSW'",
091: code);
092: }
093:
094: // 'version'-attribute (required)
095: version = XMLTools.getRequiredNodeAsString(contextNode,
096: "@version", nsContext);
097: if (!"2.0.2".equals(version)) {
098: throw new OGCWebServiceException(
099: "GetRecordByIdDocument_2_0_2", Messages
100: .getMessage(
101: "CSW_NOT_SUPPORTED_VERSION",
102: GetRecords.DEFAULT_VERSION,
103: "2.0.2", version),
104: ExceptionCode.INVALIDPARAMETERVALUE);
105: }
106:
107: // '<csw:ResponseHandler>'-elements (optional)
108: ids = XMLTools.getNodesAsStrings(contextNode, "csw202:Id",
109: nsContext);
110:
111: // '<csw:ElementSetName>'-element (optional)
112: Node elementSetNameElement = XMLTools.getNode(contextNode,
113: "csw202:ElementSetName", nsContext);
114:
115: if (elementSetNameElement != null) {
116: // must contain one of the values 'brief', 'summary' or
117: // 'full'
118: elementSetName = XMLTools.getRequiredNodeAsString(
119: elementSetNameElement, "text()", nsContext,
120: new String[] { "brief", "summary", "full" });
121:
122: } else {
123: elementSetName = "summary";
124: }
125: // in the future the vendorSpecificParameters
126: vendorSpecificParameters = parseDRMParams(this
127: .getRootElement());
128: } catch (Exception e) {
129: ExceptionCode code = ExceptionCode.INVALIDPARAMETERVALUE;
130: throw new OGCWebServiceException(
131: "GetRecordByIdDocument_2_0_2", StringTools
132: .stackTraceToString(e), code);
133: }
134:
135: return new GetRecordById(id, version, vendorSpecificParameters,
136: ids, elementSetName);
137: }
138:
139: /*
140: * (non-Javadoc)
141: *
142: * @see org.deegree.framework.xml.XMLFragment#createEmptyDocument()
143: */
144: void createEmptyDocument() throws IOException, SAXException {
145: URL url = GetRecordByIdDocument.class.getResource(XML_TEMPLATE);
146: if (url == null) {
147: throw new IOException("The resource '" + XML_TEMPLATE
148: + " could not be found.");
149: }
150: load(url);
151: }
152:
153: }
|