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.URI;
043: import java.net.URISyntaxException;
044: import java.net.URL;
045: import java.util.List;
046: import java.util.Map;
047:
048: import org.deegree.framework.log.ILogger;
049: import org.deegree.framework.log.LoggerFactory;
050: import org.deegree.framework.util.StringTools;
051: import org.deegree.framework.xml.XMLParsingException;
052: import org.deegree.framework.xml.XMLTools;
053: import org.deegree.i18n.Messages;
054: import org.deegree.ogcbase.ExceptionCode;
055: import org.deegree.ogcwebservices.InvalidParameterValueException;
056: import org.deegree.ogcwebservices.MissingParameterValueException;
057: import org.deegree.ogcwebservices.OGCWebServiceException;
058: import org.w3c.dom.Element;
059: import org.w3c.dom.Node;
060: import org.xml.sax.SAXException;
061:
062: /**
063: *
064: *
065: * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
066: * @author last edited by: $Author: poth $
067: *
068: * @version $Revision: 6251 $, $Date: 2007-03-19 16:59:28 +0100 (Mo, 19 Mrz 2007) $
069: */
070: public class DescribeRecordDocument_2_0_2 extends
071: DescribeRecordDocument {
072:
073: private static final ILogger LOG = LoggerFactory
074: .getLogger(DescribeRecordDocument_2_0_2.class);
075:
076: private static final String XML_TEMPLATE = "DescribeRecord2.0.2Template.xml";
077:
078: /**
079: * Extracts a <code>DescribeRecord</code> representation of this object.
080: *
081: * TODO use QualifiedName for type names
082: *
083: * @param id
084: * unique ID of the request
085: * @return @throws
086: * MissingParameterValueException
087: * @throws InvalidParameterValueException
088: * @throws OGCWebServiceException
089: */
090: public DescribeRecord parse(String id)
091: throws MissingParameterValueException,
092: InvalidParameterValueException, OGCWebServiceException {
093:
094: String version;
095: Map<String, String> vendorSpecificParameter = null;
096: Map namespaceMappings = null;
097: String[] typeNames = null;
098: String outputFormat = "application/xml";
099: URI schemaLanguage = null;
100:
101: try {
102: // '<csw202:DescribeRecord>'-element (required)
103: Node contextNode = XMLTools.getRequiredNode(this
104: .getRootElement(), "self::csw202:DescribeRecord",
105: nsContext);
106:
107: // 'service'-attribute (required, must be CSW)
108: String service = XMLTools.getRequiredNodeAsString(
109: contextNode, "@service", nsContext);
110: if (!service.equals("CSW")) {
111: ExceptionCode code = ExceptionCode.INVALIDPARAMETERVALUE;
112: throw new InvalidParameterValueException(
113: "DescribeRecords", "'service' must be 'CSW'",
114: code);
115: }
116:
117: // 'version'-attribute (required)
118: version = XMLTools.getRequiredNodeAsString(contextNode,
119: "@version", nsContext);
120: if (!"2.0.2".equals(version)) {
121: throw new OGCWebServiceException(
122: "DescribeRecordDocument_2_0_2", Messages
123: .getMessage(
124: "CSW_NOT_SUPPORTED_VERSION",
125: GetRecords.DEFAULT_VERSION,
126: "2.0.2", version),
127: ExceptionCode.INVALIDPARAMETERVALUE);
128: }
129:
130: // 'outputFormat'-attribute (optional, default="text/xml")
131: outputFormat = XMLTools.getNodeAsString(contextNode,
132: "@outputFormat", nsContext, outputFormat);
133:
134: // 'schemaLanguage'-attribute (optional,
135: // default="http://www.w3.org/XML/Schema")
136: String schemaLanguageString = XMLTools.getNodeAsString(
137: contextNode, "@schemaLanguage", nsContext,
138: "http://www.w3.org/XML/Schema");
139: try {
140: schemaLanguage = new URI(schemaLanguageString);
141: } catch (URISyntaxException e) {
142: throw new XMLParsingException("Value '"
143: + schemaLanguageString
144: + "' for attribute 'schemaLanguage' "
145: + "is invalid. Must denote a valid URI.");
146: }
147:
148: // 'csw202:TypeName' elements
149: List nl = XMLTools.getNodes(contextNode, "csw202:TypeName",
150: nsContext);
151: typeNames = new String[nl.size()];
152: for (int i = 0; i < typeNames.length; i++) {
153: typeNames[i] = parseTypeName((Element) nl.get(i));
154: }
155:
156: // vendorspecific attributes; required by deegree rights management
157: vendorSpecificParameter = parseDRMParams(this
158: .getRootElement());
159: } catch (Exception e) {
160: LOG.logError(e.getMessage(), e);
161: ExceptionCode code = ExceptionCode.INVALID_FORMAT;
162: throw new OGCWebServiceException("CatalogGetCapabilities",
163: StringTools.stackTraceToString(e), code);
164: }
165:
166: return new DescribeRecord(id, version, vendorSpecificParameter,
167: namespaceMappings, typeNames, outputFormat,
168: schemaLanguage);
169: }
170:
171: /*
172: * (non-Javadoc)
173: *
174: * @see org.deegree.framework.xml.XMLFragment#createEmptyDocument()
175: */
176: void createEmptyDocument() throws IOException, SAXException {
177: URL url = GetRecordsDocument.class.getResource(XML_TEMPLATE);
178: if (url == null) {
179: throw new IOException("The resource '" + XML_TEMPLATE
180: + " could not be found.");
181: }
182: load(url);
183: }
184:
185: }
|