001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/branches/2.2_testing/src/org/deegree/model/metadata/iso19115/XMLFactory.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.model.metadata.iso19115; 045 046 import java.net.URI; 047 import java.net.URL; 048 import java.util.List; 049 050 import org.deegree.datatypes.Code; 051 import org.deegree.framework.xml.XMLTools; 052 import org.deegree.ogcbase.CommonNamespaces; 053 import org.w3c.dom.Element; 054 055 /** 056 * <code>XMLFactory</code> with append methods for the various ISO 19115 elements as specified in 057 * the OWS common specification 1.0.0. 058 * 059 * @author <a href="mailto:schmitz@lat-lon.de">Andreas Schmitz</a> 060 * @author last edited by: $Author: apoth $ 061 * 062 * @version 2.0, $Revision: 9343 $, $Date: 2007-12-27 14:30:32 +0100 (Do, 27 Dez 2007) $ 063 * 064 * @since 2.0 065 */ 066 067 public class XMLFactory extends org.deegree.ogcbase.XMLFactory { 068 069 private static URI OWS = CommonNamespaces.OWSNS; 070 071 private static String POWS = CommonNamespaces.OWS_PREFIX + ':'; 072 073 /** 074 * Appends the given <code>CitedResponsibleParty</code> object as XML. 075 * 076 * @param root 077 * @param party 078 */ 079 public static void appendCitedResponsibleParty( Element root, CitedResponsibleParty party ) { 080 Element elem = XMLTools.appendElement( root, OWS, POWS + "ResponsiblePartySubsetType" ); 081 082 String[] individualNames = party.getIndividualName(); 083 if ( ( individualNames != null ) && ( individualNames.length != 0 ) && ( individualNames[0] != null ) ) 084 XMLTools.appendElement( elem, OWS, POWS + "IndividualName", individualNames[0] ); 085 086 String[] positionNames = party.getPositionName(); 087 if ( ( positionNames != null ) && ( positionNames.length != 0 ) && ( positionNames[0] != null ) ) 088 XMLTools.appendElement( elem, OWS, POWS + "PositionName", positionNames[0] ); 089 090 RoleCode[] roles = party.getRoleCode(); 091 if ( ( roles != null ) && ( roles.length != 0 ) && ( roles[0] != null ) ) 092 XMLTools.appendElement( elem, OWS, POWS + "Role", roles[0].getValue() ); 093 094 ContactInfo[] contactInfos = party.getContactInfo(); 095 if ( ( contactInfos != null ) && ( contactInfos.length != 0 ) && ( contactInfos[0] != null ) ) 096 appendContactInfo( elem, contactInfos[0] ); 097 } 098 099 /** 100 * Appends the contact info. 101 * 102 * @param root 103 * @param contactInfo 104 */ 105 public static void appendContactInfo( Element root, ContactInfo contactInfo ) { 106 Element elem = XMLTools.appendElement( root, OWS, POWS + "ContactInfo" ); 107 108 appendPhone( elem, contactInfo.getPhone() ); 109 appendAddress( elem, contactInfo.getAddress() ); 110 appendOnlineResource( elem, contactInfo.getOnLineResource() ); 111 112 String hours = contactInfo.getHoursOfService(); 113 String instructions = contactInfo.getContactInstructions(); 114 115 if ( hours != null ) 116 XMLTools.appendElement( elem, OWS, POWS + "HoursOfService", hours ); 117 if ( instructions != null ) 118 XMLTools.appendElement( elem, OWS, POWS + "ContactInstructions", instructions ); 119 } 120 121 /** 122 * Appends the phone data. 123 * 124 * @param root 125 * @param phone 126 */ 127 public static void appendPhone( Element root, Phone phone ) { 128 if ( phone == null ) 129 return; 130 131 Element elem = XMLTools.appendElement( root, OWS, POWS + "Phone" ); 132 133 String[] voice = phone.getVoice(); 134 for ( String number : voice ) 135 XMLTools.appendElement( elem, OWS, POWS + "Voice", number ); 136 137 String[] facsimile = phone.getFacsimile(); 138 for ( String number : facsimile ) 139 XMLTools.appendElement( elem, OWS, POWS + "Facsimile", number ); 140 } 141 142 /** 143 * Appends the address data. 144 * 145 * @param root 146 * @param address 147 */ 148 public static void appendAddress( Element root, Address address ) { 149 if ( address == null ) 150 return; 151 152 Element elem = XMLTools.appendElement( root, OWS, POWS + "Address" ); 153 154 String[] deliveryPoint = address.getDeliveryPoint(); 155 for ( String point : deliveryPoint ) 156 XMLTools.appendElement( elem, OWS, POWS + "DeliveryPoint", point ); 157 158 String city = address.getCity(); 159 if ( city != null ) 160 XMLTools.appendElement( elem, OWS, POWS + "City", city ); 161 162 String adminArea = address.getAdministrativeArea(); 163 if ( adminArea != null ) 164 XMLTools.appendElement( elem, OWS, POWS + "AdministrativeArea", adminArea ); 165 166 String postalCode = address.getPostalCode(); 167 if ( postalCode != null ) 168 XMLTools.appendElement( elem, OWS, POWS + "PostalCode", postalCode ); 169 170 String country = address.getCountry(); 171 if ( country != null ) 172 XMLTools.appendElement( elem, OWS, POWS + "Country", country ); 173 174 String[] email = address.getElectronicMailAddress(); 175 for ( String mail : email ) 176 XMLTools.appendElement( elem, OWS, POWS + "ElectronicMailAddress", mail ); 177 } 178 179 /** 180 * Appends the link. 181 * 182 * @param root 183 * @param link 184 */ 185 public static void appendOnlineResource( Element root, OnlineResource link ) { 186 if ( link == null ) 187 return; 188 appendOnlineResource( root, link.getLinkage().getHref() ); 189 } 190 191 /** 192 * Appends the link. 193 * 194 * @param root 195 * @param link 196 */ 197 public static void appendOnlineResource( Element root, URL link ) { 198 if ( link == null ) 199 return; 200 201 // fix up URL to standard form 202 String url = link.toExternalForm(); 203 if ( !url.toString().endsWith( "?" ) ) { 204 if ( !url.endsWith( "&" ) ) { 205 if ( url.indexOf( "?" ) == -1 ) 206 url = url + "?"; 207 else 208 url = url + "&"; 209 } 210 } 211 212 root.setAttributeNS( "http://www.w3.org/1999/xlink", "xlink:type", "simple" ); 213 root.setAttributeNS( "http://www.w3.org/1999/xlink", "xlink:href", url ); 214 215 } 216 217 /** 218 * Appends an online resource in a newly created element in the OWS namespace. The new element 219 * will be named according to the tagName parameter. 220 * 221 * @param root 222 * @param link 223 * @param tagName 224 */ 225 public static void appendOnlineResource( Element root, OnlineResource link, String tagName ) { 226 Element newElem = XMLTools.appendElement( root, OWS, POWS + tagName ); 227 appendOnlineResource( newElem, link ); 228 } 229 230 /** 231 * Appends an online resource in a newly created element in the OWS namespace. The new element 232 * will be named according to the tagName parameter. 233 * 234 * @param root 235 * @param link 236 * @param tagName 237 */ 238 public static void appendOnlineResource( Element root, URL link, String tagName ) { 239 Element newElem = XMLTools.appendElement( root, OWS, POWS + tagName ); 240 appendOnlineResource( newElem, link ); 241 } 242 243 /** 244 * Appends the access constraint element. Please note that a lot of the information contained 245 * within will not be included in the output due to restrictions of the OWS specification. 246 * 247 * @param root 248 * @param constraints 249 */ 250 public static void appendAccessConstraint( Element root, Constraints constraints ) { 251 List<String> constrList = constraints.getUseLimitations(); 252 String constr = ""; 253 if ( constrList.size() != 0 ) 254 constr = constrList.get( 0 ); 255 256 XMLTools.appendElement( root, OWS, POWS + "AccessConstraint", constr ); 257 } 258 259 /** 260 * Appends an element of type CodeType with the given name and content. 261 * 262 * @param root 263 * @param tagName 264 * @param code 265 */ 266 public static void appendCode( Element root, String tagName, Code code ) { 267 Element elem = XMLTools.appendElement( root, OWS, POWS + tagName, code.getCode() ); 268 URI codeSpace = code.getCodeSpace(); 269 if ( codeSpace != null ) 270 elem.setAttribute( "codeSpace", codeSpace.toString() ); 271 } 272 273 /** 274 * Appends the contents of a <code>Keywords</code> object. 275 * 276 * @param root 277 * @param keywords 278 */ 279 public static void appendKeywords( Element root, Keywords keywords ) { 280 Element elem = XMLTools.appendElement( root, OWS, POWS + "Keywords" ); 281 282 String[] words = keywords.getKeywords(); 283 for ( String word : words ) 284 XMLTools.appendElement( elem, OWS, POWS + "Keyword", word ); 285 286 TypeCode code = keywords.getTypeCode(); 287 if ( code != null ) 288 appendCode( elem, "Type", code ); 289 } 290 291 }