001 // $HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.3_testing/src/org/deegree/ogcwebservices/getcapabilities/OGCCapabilitiesDocument.java $
002 /*----------------------------------------------------------------------------
003 This file is part of deegree, http://deegree.org/
004 Copyright (C) 2001-2009 by:
005 Department of Geography, University of Bonn
006 and
007 lat/lon GmbH
008
009 This library is free software; you can redistribute it and/or modify it under
010 the terms of the GNU Lesser General Public License as published by the Free
011 Software Foundation; either version 2.1 of the License, or (at your option)
012 any later version.
013 This library is distributed in the hope that it will be useful, but WITHOUT
014 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
015 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
016 details.
017 You should have received a copy of the GNU Lesser General Public License
018 along with this library; if not, write to the Free Software Foundation, Inc.,
019 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020
021 Contact information:
022
023 lat/lon GmbH
024 Aennchenstr. 19, 53177 Bonn
025 Germany
026 http://lat-lon.de/
027
028 Department of Geography, University of Bonn
029 Prof. Dr. Klaus Greve
030 Postfach 1147, 53001 Bonn
031 Germany
032 http://www.geographie.uni-bonn.de/deegree/
033
034 e-mail: info@deegree.org
035 ----------------------------------------------------------------------------*/
036 package org.deegree.ogcwebservices.getcapabilities;
037
038 import java.net.MalformedURLException;
039 import java.net.URI;
040 import java.net.URISyntaxException;
041 import java.net.URL;
042
043 import org.deegree.framework.util.StringTools;
044 import org.deegree.framework.xml.ElementList;
045 import org.deegree.framework.xml.XMLParsingException;
046 import org.deegree.framework.xml.XMLTools;
047 import org.deegree.model.metadata.iso19115.Address;
048 import org.deegree.model.metadata.iso19115.Phone;
049 import org.deegree.ogcbase.CommonNamespaces;
050 import org.deegree.ogcbase.OGCDocument;
051 import org.deegree.ogcwebservices.MetadataLink;
052 import org.deegree.ogcwebservices.MetadataType;
053 import org.w3c.dom.Element;
054
055 /**
056 * Most basic capabilities document for any OGC service instance.
057 *
058 * @author <a href="mailto:poth@lat-lon.de">Andreas Poth </a>
059 * @author <a href="mailto:mschneider@lat-lon.de">Markus Schneider </a>
060 *
061 * @author last edited by: $Author: mschneider $
062 *
063 * @version $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18. Jun 2009) $
064 */
065 public abstract class OGCCapabilitiesDocument extends OGCDocument {
066
067 private static final long serialVersionUID = -1704967654756261989L;
068 protected static final URI OGCNS = CommonNamespaces.OGCNS;
069
070 /**
071 * Returns the value of the version attribute of the capabilities document.
072 *
073 * @return the value of the version attribute of the capabilities document.
074 */
075 public String parseVersion() {
076 return getRootElement().getAttribute( "version" );
077 }
078
079 /**
080 * Returns the value of the updateSequence attribute of the capabilities document.
081 *
082 * @return the value of the updateSequence attribute of the capabilities document.
083 */
084 public String parseUpdateSequence() {
085 String s = getRootElement().getAttribute( "updateSequence" );
086 if ( s == null || s.trim().length() == 0 ) {
087 return "0";
088 }
089 return s;
090 }
091
092 /**
093 * Creates a <tt>MetadataLink</tt> instance from the passed element.
094 *
095 * @param element
096 * @return created <tt>MetadataLink</tt>
097 * @throws XMLParsingException
098 */
099 protected MetadataLink parseMetadataLink( Element element )
100 throws XMLParsingException {
101 if ( element == null )
102 return null;
103
104 try {
105 URL reference = new URL( XMLTools.getAttrValue( element, "xlink:href" ) );
106 String title = XMLTools.getAttrValue( element, "xlink:title" );
107 URI about = new URI( XMLTools.getAttrValue( element, null, "about", null ) );
108 String tmp = XMLTools.getAttrValue( element, null, "metadataType", null );
109 MetadataType metadataType = new MetadataType( tmp );
110 return new MetadataLink( reference, title, about, metadataType );
111 } catch ( MalformedURLException e ) {
112 throw new XMLParsingException( "Couldn't parse metadataLink reference\n"
113 + StringTools.stackTraceToString( e ) );
114 } catch ( URISyntaxException e ) {
115 throw new XMLParsingException( "Couldn't parse metadataLink about\n" + StringTools.stackTraceToString( e ) );
116 }
117 }
118
119 /**
120 * Creates a class representation of the document.
121 *
122 * @return class representation of the document
123 * @throws InvalidCapabilitiesException
124 */
125 public abstract OGCCapabilities parseCapabilities()
126 throws InvalidCapabilitiesException;
127
128 /**
129 * Creates an <code>Address</code> instance from the passed element.
130 *
131 * @param element
132 * Address-element
133 * @param namespaceURI
134 * namespace-prefix of all elements
135 * @return the new instance
136 */
137 protected Address parseAddress( Element element, URI namespaceURI ) {
138 ElementList el = XMLTools.getChildElements( "DeliveryPoint", namespaceURI, element );
139 String[] deliveryPoint = new String[el.getLength()];
140 for ( int i = 0; i < deliveryPoint.length; i++ ) {
141 deliveryPoint[i] = XMLTools.getStringValue( el.item( i ) );
142 }
143 String city = XMLTools.getStringValue( "City", namespaceURI, element, null );
144 String adminArea = XMLTools.getStringValue( "AdministrativeArea", namespaceURI, element, null );
145 String postalCode = XMLTools.getStringValue( "PostalCode", namespaceURI, element, null );
146 String country = XMLTools.getStringValue( "Country", namespaceURI, element, null );
147 el = XMLTools.getChildElements( "ElectronicMailAddress", namespaceURI, element );
148 String[] eMailAddresses = new String[el.getLength()];
149 for ( int i = 0; i < eMailAddresses.length; i++ ) {
150 eMailAddresses[i] = XMLTools.getStringValue( el.item( i ) );
151 }
152 return new Address( adminArea, city, country, deliveryPoint, eMailAddresses, postalCode );
153 }
154
155 /**
156 * Creates a <tt>Phone</tt> instance from the passed element.
157 *
158 * @param element
159 * Phone-element
160 * @param namespaceURI
161 * URI that all elements must have
162 * @return the new instance
163 */
164 protected Phone parsePhone( Element element, URI namespaceURI ) {
165
166 // 'Voice'-elements (optional)
167 ElementList el = XMLTools.getChildElements( "Voice", namespaceURI, element );
168 String[] voiceNumbers = new String[el.getLength()];
169 for ( int i = 0; i < voiceNumbers.length; i++ ) {
170 voiceNumbers[i] = XMLTools.getStringValue( el.item( i ) );
171 }
172
173 // 'Facsimile'-elements (optional)
174 el = XMLTools.getChildElements( "Facsimile", namespaceURI, element );
175 String[] facsimileNumbers = new String[el.getLength()];
176 for ( int i = 0; i < facsimileNumbers.length; i++ ) {
177 facsimileNumbers[i] = XMLTools.getStringValue( el.item( i ) );
178 }
179 return new Phone( facsimileNumbers, null, null, voiceNumbers );
180 }
181
182 }