001 // $HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/tags/2.1/src/org/deegree/ogcwebservices/getcapabilities/OGCCapabilitiesDocument.java $ 002 /*---------------- FILE HEADER ------------------------------------------ 003 004 This file is part of deegree. 005 Copyright (C) 2001-2007 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.getcapabilities; 045 046 import java.net.MalformedURLException; 047 import java.net.URI; 048 import java.net.URISyntaxException; 049 import java.net.URL; 050 051 import org.deegree.framework.util.StringTools; 052 import org.deegree.framework.xml.ElementList; 053 import org.deegree.framework.xml.XMLParsingException; 054 import org.deegree.framework.xml.XMLTools; 055 import org.deegree.model.metadata.iso19115.Address; 056 import org.deegree.model.metadata.iso19115.Phone; 057 import org.deegree.ogcbase.CommonNamespaces; 058 import org.deegree.ogcbase.OGCDocument; 059 import org.deegree.ogcwebservices.MetadataLink; 060 import org.deegree.ogcwebservices.MetadataType; 061 import org.w3c.dom.Element; 062 063 /** 064 * Most basic capabilities document for any OGC service instance. 065 * 066 * @author <a href="mailto:poth@lat-lon.de">Andreas Poth </a> 067 * @author <a href="mailto:mschneider@lat-lon.de">Markus Schneider </a> 068 * 069 * @author last edited by: $Author: apoth $ 070 * 071 * @version 1.0. $Revision: 6845 $, $Date: 2007-05-07 11:28:14 +0200 (Mo, 07 Mai 2007) $ 072 * 073 * @since 2.0 074 */ 075 public abstract class OGCCapabilitiesDocument extends OGCDocument { 076 077 protected static final URI OGCNS = CommonNamespaces.OGCNS; 078 079 /** 080 * Returns the value of the version attribute of the capabilities document. 081 * 082 * @return the value of the version attribute of the capabilities document. 083 */ 084 public String parseVersion() { 085 return getRootElement().getAttribute( "version" ); 086 } 087 088 /** 089 * Returns the value of the updateSequence attribute of the capabilities document. 090 * 091 * @return the value of the updateSequence attribute of the capabilities document. 092 */ 093 public String parseUpdateSequence() { 094 return getRootElement().getAttribute( "updateSequence" ); 095 } 096 097 /** 098 * Creates a <tt>MetadataLink</tt> instance from the passed element. 099 * 100 * @param element 101 * @return created <tt>MetadataLink</tt> 102 * @throws XMLParsingException 103 */ 104 protected MetadataLink parseMetadataLink( Element element ) 105 throws XMLParsingException { 106 if ( element == null ) 107 return null; 108 109 try { 110 URL reference = new URL( XMLTools.getAttrValue( element, "xlink:href") ); 111 String title = XMLTools.getAttrValue( element, "xlink:title" ); 112 URI about = new URI( XMLTools.getAttrValue( element, null, "about", null ) ); 113 String tmp = XMLTools.getAttrValue( element, null, "metadataType", null ); 114 MetadataType metadataType = new MetadataType( tmp ); 115 return new MetadataLink( reference, title, about, metadataType ); 116 } catch ( MalformedURLException e ) { 117 throw new XMLParsingException( "Couldn't parse metadataLink reference\n" 118 + StringTools.stackTraceToString( e ) ); 119 } catch ( URISyntaxException e ) { 120 throw new XMLParsingException( "Couldn't parse metadataLink about\n" 121 + StringTools.stackTraceToString( e ) ); 122 } 123 } 124 125 /** 126 * Creates a class representation of the document. 127 * 128 * @return class representation of the document 129 */ 130 public abstract OGCCapabilities parseCapabilities() 131 throws InvalidCapabilitiesException; 132 133 /** 134 * Creates an <code>Address</code> instance from the passed element. 135 * 136 * @param element 137 * Address-element 138 * @param namespaceURI 139 * namespace-prefix of all elements 140 * @return 141 * @throws XMLParsingException 142 */ 143 protected Address parseAddress( Element element, URI namespaceURI ) { 144 ElementList el = XMLTools.getChildElements( "DeliveryPoint", namespaceURI, element ); 145 String[] deliveryPoint = new String[el.getLength()]; 146 for ( int i = 0; i < deliveryPoint.length; i++ ) { 147 deliveryPoint[i] = XMLTools.getStringValue( el.item( i ) ); 148 } 149 String city = XMLTools.getStringValue( "City", namespaceURI, element, null ); 150 String adminArea = XMLTools.getStringValue( "AdministrativeArea", namespaceURI, element, 151 null ); 152 String postalCode = XMLTools.getStringValue( "PostalCode", namespaceURI, element, null ); 153 String country = XMLTools.getStringValue( "Country", namespaceURI, element, null ); 154 el = XMLTools.getChildElements( "ElectronicMailAddress", namespaceURI, element ); 155 String[] eMailAddresses = new String[el.getLength()]; 156 for ( int i = 0; i < eMailAddresses.length; i++ ) { 157 eMailAddresses[i] = XMLTools.getStringValue( el.item( i ) ); 158 } 159 return new Address( adminArea, city, country, deliveryPoint, eMailAddresses, postalCode ); 160 } 161 162 /** 163 * Creates a <tt>Phone</tt> instance from the passed element. 164 * 165 * @param element 166 * Phone-element 167 * @param namespaceURI 168 * URI that all elements must have 169 * @return 170 * @throws XMLParsingException 171 */ 172 protected Phone parsePhone( Element element, URI namespaceURI ) { 173 174 // 'Voice'-elements (optional) 175 ElementList el = XMLTools.getChildElements( "Voice", namespaceURI, element ); 176 String[] voiceNumbers = new String[el.getLength()]; 177 for ( int i = 0; i < voiceNumbers.length; i++ ) { 178 voiceNumbers[i] = XMLTools.getStringValue( el.item( i ) ); 179 } 180 181 // 'Facsimile'-elements (optional) 182 el = XMLTools.getChildElements( "Facsimile", namespaceURI, element ); 183 String[] facsimileNumbers = new String[el.getLength()]; 184 for ( int i = 0; i < facsimileNumbers.length; i++ ) { 185 facsimileNumbers[i] = XMLTools.getStringValue( el.item( i ) ); 186 } 187 return new Phone( facsimileNumbers, null, null, voiceNumbers ); 188 } 189 190 }