001: //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/trunk/src/org/deegree/ogcwebservices/csw/discovery/DescribeRecordDocument.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:
044: package org.deegree.ogcwebservices.csw.discovery;
045:
046: import java.io.IOException;
047: import java.net.URI;
048: import java.net.URISyntaxException;
049: import java.net.URL;
050: import java.util.List;
051: import java.util.Map;
052:
053: import org.deegree.framework.log.ILogger;
054: import org.deegree.framework.log.LoggerFactory;
055: import org.deegree.framework.util.StringTools;
056: import org.deegree.framework.xml.XMLParsingException;
057: import org.deegree.framework.xml.XMLTools;
058: import org.deegree.i18n.Messages;
059: import org.deegree.ogcbase.ExceptionCode;
060: import org.deegree.ogcwebservices.InvalidParameterValueException;
061: import org.deegree.ogcwebservices.MissingParameterValueException;
062: import org.deegree.ogcwebservices.OGCWebServiceException;
063: import org.deegree.ogcwebservices.csw.AbstractCSWRequestDocument;
064: import org.w3c.dom.Element;
065: import org.w3c.dom.Node;
066: import org.xml.sax.SAXException;
067:
068: /**
069: * Represents an XML DescribeRecord document of an OGC CSW 2.0 compliant
070: * service.
071: *
072: * @author <a href="mailto:tfr@users.sourceforge.net">Torsten Friebe </a>
073: * @author <a href="mailto:mschneider@lat-lon.de">Markus Schneider </a>
074: *
075: * @author last edited by: $Author: apoth $
076: *
077: * @version 2.0, $Revision: 9345 $, $Date: 2007-12-27 08:22:25 -0800 (Thu, 27 Dec 2007) $
078: *
079: * @since 2.0
080: */
081:
082: public class DescribeRecordDocument extends AbstractCSWRequestDocument {
083:
084: private static final long serialVersionUID = 6554937884331546780L;
085:
086: private static final ILogger LOG = LoggerFactory
087: .getLogger(DescribeRecordDocument.class);
088:
089: private static final String XML_TEMPLATE = "DescribeRecordTemplate.xml";
090:
091: /**
092: * Extracts a <code>DescribeRecord</code> representation of this object.
093: *
094: * TODO use QualifiedName for type names
095: *
096: * @param id
097: * unique ID of the request
098: * @return @throws
099: * MissingParameterValueException
100: * @throws InvalidParameterValueException
101: * @throws OGCWebServiceException
102: */
103: public DescribeRecord parse(String id)
104: throws MissingParameterValueException,
105: InvalidParameterValueException, OGCWebServiceException {
106:
107: String version;
108: Map<String, String> vendorSpecificParameter = null;
109: Map namespaceMappings = null;
110: String[] typeNames = null;
111: String outputFormat = "text/xml";
112: URI schemaLanguage = null;
113:
114: try {
115: // '<csw:DescribeRecord>'-element (required)
116: Node contextNode = XMLTools.getRequiredNode(this
117: .getRootElement(), "self::csw:DescribeRecord",
118: nsContext);
119:
120: // 'service'-attribute (required, must be CSW)
121: String service = XMLTools.getNodeAsString(contextNode,
122: "@service", nsContext, "CSW");
123: if (!service.equals("CSW")) {
124: ExceptionCode code = ExceptionCode.INVALIDPARAMETERVALUE;
125: throw new InvalidParameterValueException(
126: "DescribeRecords", "'service' must be 'CSW'",
127: code);
128: }
129:
130: // 'version'-attribute (required)
131: version = XMLTools.getNodeAsString(contextNode, "@version",
132: nsContext, "2.0.1");
133: if (!"2.0.0".equals(version) && !"2.0.1".equals(version)) {
134: throw new OGCWebServiceException(
135: "DescribeRecordDocument", Messages.getMessage(
136: "CSW_NOT_SUPPORTED_VERSION",
137: GetRecords.DEFAULT_VERSION, "2.0.2",
138: version),
139: ExceptionCode.INVALIDPARAMETERVALUE);
140: }
141:
142: // 'outputFormat'-attribute (optional, default="text/xml")
143: outputFormat = XMLTools.getNodeAsString(contextNode,
144: "@outputFormat", nsContext, outputFormat);
145:
146: // 'schemaLanguage'-attribute (optional,
147: // default="http://www.w3.org/XML/Schema")
148: String schemaLanguageString = XMLTools.getNodeAsString(
149: contextNode, "@schemaLanguage", nsContext,
150: "http://www.w3.org/XML/Schema");
151: try {
152: schemaLanguage = new URI(schemaLanguageString);
153: } catch (URISyntaxException e) {
154: throw new XMLParsingException("Value '"
155: + schemaLanguageString
156: + "' for attribute 'schemaLanguage' "
157: + "is invalid. Must denote a valid URI.");
158: }
159:
160: // 'csw:TypeName' elements
161: List nl = XMLTools.getNodes(contextNode, "csw:TypeName",
162: nsContext);
163: typeNames = new String[nl.size()];
164: for (int i = 0; i < typeNames.length; i++) {
165: typeNames[i] = parseTypeName((Element) nl.get(i));
166: }
167:
168: // vendorspecific attributes; required by deegree rights management
169: vendorSpecificParameter = parseDRMParams(this
170: .getRootElement());
171: } catch (Exception e) {
172: LOG.logError(e.getMessage(), e);
173: ExceptionCode code = ExceptionCode.INVALID_FORMAT;
174: throw new OGCWebServiceException("CatalogGetCapabilities",
175: StringTools.stackTraceToString(e), code);
176: }
177:
178: return new DescribeRecord(id, version, vendorSpecificParameter,
179: namespaceMappings, typeNames, outputFormat,
180: schemaLanguage);
181: }
182:
183: /**
184: * Parses a <code>TypeName</code> element into a <code>QualifiedName</code>.
185: *
186: * TODO respect "targetNamespace" attribute and really return a <code>QualifiedName</code>.
187: *
188: * @return
189: * @throws XMLParsingException
190: */
191: protected String parseTypeName(Element root)
192: throws XMLParsingException {
193: return XMLTools.getRequiredNodeAsString(root, "text()",
194: nsContext);
195: }
196:
197: /*
198: * (non-Javadoc)
199: *
200: * @see org.deegree.framework.xml.XMLFragment#createEmptyDocument()
201: */
202: void createEmptyDocument() throws IOException, SAXException {
203: URL url = DescribeRecordDocument.class
204: .getResource(XML_TEMPLATE);
205: if (url == null) {
206: throw new IOException("The resource '" + XML_TEMPLATE
207: + " could not be found.");
208: }
209: load(url);
210: }
211: }
|