001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/tags/2.1/src/org/deegree/model/metadata/iso19115/XMLFactory.java $ 002 /*---------------- FILE HEADER ------------------------------------------ 003 This file is part of deegree. 004 Copyright (C) 2001-2006 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 This library is free software; you can redistribute it and/or 010 modify it under the terms of the GNU Lesser General Public 011 License as published by the Free Software Foundation; either 012 version 2.1 of the License, or (at your option) any later version. 013 This library is distributed in the hope that it will be useful, 014 but WITHOUT ANY WARRANTY; without even the implied warranty of 015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 016 Lesser General Public License for more details. 017 You should have received a copy of the GNU Lesser General Public 018 License along with this library; if not, write to the Free Software 019 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 020 Contact: 021 Andreas Poth 022 lat/lon GmbH 023 Aennchenstraße 19 024 53177 Bonn 025 Germany 026 E-Mail: poth@lat-lon.de 027 Jens Fitzke 028 lat/lon GmbH 029 Aennchenstraße 19 030 53177 Bonn 031 Germany 032 E-Mail: jens.fitzke@uni-bonn.de 033 ---------------------------------------------------------------------------*/ 034 package org.deegree.model.metadata.iso19115; 035 036 import java.net.URI; 037 import java.net.URL; 038 import java.util.List; 039 040 import org.deegree.datatypes.Code; 041 import org.deegree.framework.xml.XMLTools; 042 import org.deegree.ogcbase.CommonNamespaces; 043 import org.w3c.dom.Element; 044 045 /** 046 * <code>XMLFactory</code> with append methods for the various ISO 19115 elements 047 * as specified in the OWS common specification 1.0.0. 048 * 049 * @author <a href="mailto:schmitz@lat-lon.de">Andreas Schmitz</a> 050 * @author last edited by: $Author: bezema $ 051 * 052 * @version 2.0, $Revision: 6259 $, $Date: 2007-03-20 10:15:15 +0100 (Di, 20 Mär 2007) $ 053 * 054 * @since 2.0 055 */ 056 057 public class XMLFactory extends org.deegree.ogcbase.XMLFactory { 058 059 private static URI OWS = CommonNamespaces.OWSNS; 060 061 private static String POWS = CommonNamespaces.OWS_PREFIX + ':'; 062 063 /** 064 * Appends the given <code>CitedResponsibleParty</code> object as XML. 065 * 066 * @param root 067 * @param party 068 */ 069 public static void appendCitedResponsibleParty( Element root, CitedResponsibleParty party ) { 070 Element elem = XMLTools.appendElement( root, OWS, POWS + "ResponsiblePartySubsetType" ); 071 072 String[] individualNames = party.getIndividualName(); 073 if( ( individualNames != null ) && ( individualNames.length != 0 ) && ( individualNames[0] != null ) ) 074 XMLTools.appendElement( elem, OWS, POWS + "IndividualName", individualNames[0] ); 075 076 String[] positionNames = party.getPositionName(); 077 if( ( positionNames != null ) && ( positionNames.length != 0 ) && ( positionNames[0] != null ) ) 078 XMLTools.appendElement( elem, OWS, POWS + "PositionName", positionNames[0] ); 079 080 RoleCode[] roles = party.getRoleCode(); 081 if( ( roles != null ) && ( roles.length != 0 ) && ( roles[0] != null ) ) 082 XMLTools.appendElement( elem, OWS, POWS + "Role", roles[0].getValue() ); 083 084 ContactInfo[] contactInfos = party.getContactInfo(); 085 if( ( contactInfos != null ) && ( contactInfos.length != 0 ) && ( contactInfos[0] != null ) ) 086 appendContactInfo( elem, contactInfos[0] ); 087 } 088 089 /** 090 * Appends the contact info. 091 * 092 * @param root 093 * @param contactInfo 094 */ 095 public static void appendContactInfo( Element root, ContactInfo contactInfo ) { 096 Element elem = XMLTools.appendElement( root, OWS, POWS + "ContactInfo" ); 097 098 appendPhone( elem, contactInfo.getPhone() ); 099 appendAddress( elem, contactInfo.getAddress() ); 100 appendOnlineResource( elem, contactInfo.getOnLineResource() ); 101 102 String hours = contactInfo.getHoursOfService(); 103 String instructions = contactInfo.getContactInstructions(); 104 105 if( hours != null ) XMLTools.appendElement( elem, OWS, POWS + "HoursOfService", hours ); 106 if( instructions != null ) XMLTools.appendElement( elem, OWS, POWS + "ContactInstructions", 107 instructions ); 108 } 109 110 /** 111 * Appends the phone data. 112 * 113 * @param root 114 * @param phone 115 */ 116 public static void appendPhone( Element root, Phone phone ) { 117 if( phone == null ) return; 118 119 Element elem = XMLTools.appendElement( root, OWS, POWS + "Phone" ); 120 121 String[] voice = phone.getVoice(); 122 for( String number : voice ) XMLTools.appendElement( elem, OWS, POWS + "Voice", number ); 123 124 String[] facsimile = phone.getFacsimile(); 125 for( String number : facsimile ) XMLTools.appendElement( elem, OWS, POWS + "Facsimile", number ); 126 } 127 128 /** 129 * Appends the address data. 130 * 131 * @param root 132 * @param address 133 */ 134 public static void appendAddress( Element root, Address address ) { 135 if( address == null ) return; 136 137 Element elem = XMLTools.appendElement( root, OWS, POWS + "Address" ); 138 139 String[] deliveryPoint = address.getDeliveryPoint(); 140 for( String point : deliveryPoint ) XMLTools.appendElement( elem, OWS, POWS + "DeliveryPoint", point ); 141 142 String city = address.getCity(); 143 if( city != null ) XMLTools.appendElement( elem, OWS, POWS + "City", city ); 144 145 String adminArea = address.getAdministrativeArea(); 146 if( adminArea != null ) XMLTools.appendElement( elem, OWS, POWS + "AdministrativeArea", adminArea ); 147 148 String postalCode = address.getPostalCode(); 149 if( postalCode != null ) XMLTools.appendElement( elem, OWS, POWS + "PostalCode", postalCode ); 150 151 String country = address.getCountry(); 152 if( country != null ) XMLTools.appendElement( elem, OWS, POWS + "Country", country ); 153 154 String[] email = address.getElectronicMailAddress(); 155 for( String mail : email ) XMLTools.appendElement( elem, OWS, POWS + "ElectronicMailAddress", mail ); 156 } 157 158 /** 159 * Appends the link. 160 * 161 * @param root 162 * @param link 163 */ 164 public static void appendOnlineResource( Element root, OnlineResource link ) { 165 if( link == null ) return; 166 appendOnlineResource( root, link.getLinkage().getHref() ); 167 } 168 169 /** 170 * Appends the link. 171 * 172 * @param root 173 * @param link 174 */ 175 public static void appendOnlineResource( Element root, URL link ) { 176 if( link == null ) return; 177 178 // fix up URL to standard form 179 String url = link.toExternalForm(); 180 if( ! url.toString().endsWith( "?") ) { 181 if( ! url.endsWith( "&" ) ) { 182 if( url.indexOf( "?" ) == -1 ) url = url + "?"; 183 else url = url + "&"; 184 } 185 } 186 187 root.setAttributeNS( "http://www.w3.org/1999/xlink", "xlink:type", "simple" ); 188 root.setAttributeNS( "http://www.w3.org/1999/xlink", "xlink:href", url ); 189 190 } 191 192 /** 193 * Appends an online resource in a newly created element in the OWS namespace. The new element 194 * will be named according to the tagName parameter. 195 * 196 * @param root 197 * @param link 198 * @param tagName 199 */ 200 public static void appendOnlineResource( Element root, OnlineResource link, String tagName ) { 201 Element newElem = XMLTools.appendElement( root, OWS, POWS + tagName ); 202 appendOnlineResource( newElem, link ); 203 } 204 205 /** 206 * Appends an online resource in a newly created element in the OWS namespace. The new element 207 * will be named according to the tagName parameter. 208 * 209 * @param root 210 * @param link 211 * @param tagName 212 */ 213 public static void appendOnlineResource( Element root, URL link, String tagName ) { 214 Element newElem = XMLTools.appendElement( root, OWS, POWS + tagName ); 215 appendOnlineResource( newElem, link ); 216 } 217 218 /** 219 * Appends the access constraint element. Please note that a lot of the information contained 220 * within will not be included in the output due to restrictions of the OWS specification. 221 * 222 * @param root 223 * @param constraints 224 */ 225 public static void appendAccessConstraint( Element root, Constraints constraints ) { 226 List<String> constrList = constraints.getUseLimitations(); 227 String constr = ""; 228 if( constrList.size() != 0 ) constr = constrList.get( 0 ); 229 230 XMLTools.appendElement( root, OWS, POWS + "AccessConstraint", constr ); 231 } 232 233 /** 234 * Appends an element of type CodeType with the given name and content. 235 * 236 * @param root 237 * @param tagName 238 * @param code 239 */ 240 public static void appendCode( Element root, String tagName, Code code ) { 241 Element elem = XMLTools.appendElement( root, OWS, POWS + tagName, code.getCode() ); 242 URI codeSpace = code.getCodeSpace(); 243 if( codeSpace != null ) elem.setAttribute( "codeSpace", codeSpace.toString() ); 244 } 245 246 /** 247 * Appends the contents of a <code>Keywords</code> object. 248 * 249 * @param root 250 * @param keywords 251 */ 252 public static void appendKeywords( Element root, Keywords keywords ) { 253 Element elem = XMLTools.appendElement( root, OWS, POWS + "Keywords" ); 254 255 String[] words = keywords.getKeywords(); 256 for( String word : words ) XMLTools.appendElement( elem, OWS, POWS + "Keyword", word ); 257 258 TypeCode code = keywords.getTypeCode(); 259 if( code != null ) appendCode( elem, "Type", code ); 260 } 261 262 } 263 /* ******************************************************************** 264 Changes to this class. What the people have been up to: 265 $Log$ 266 Revision 1.7 2007/01/04 16:53:10 poth 267 code enhancement 268 269 Revision 1.6 2006/09/12 09:24:44 schmitz 270 Corrected another xmlns:xlink error. 271 272 Revision 1.5 2006/09/12 08:39:00 schmitz 273 Added xmlns:xlink attribute to online resources. 274 275 Revision 1.4 2006/09/08 08:42:03 schmitz 276 Updated the WMS to be 1.1.1 conformant once again. 277 Cleaned up the WMS code. 278 Added cite WMS test data. 279 280 Revision 1.3 2006/08/24 06:40:27 poth 281 File header corrected 282 283 Revision 1.2 2006/08/22 10:25:01 schmitz 284 Updated the WMS to use the new OWS common package. 285 Updated the rest of deegree to use the new data classes returned 286 by the updated WMS methods/capabilities. 287 288 Revision 1.1 2006/08/08 10:21:52 schmitz 289 Parser is finished, as well as the iso XMLFactory. 290 291 ********************************************************************** */