001 //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.3_testing/src/org/deegree/portal/context/XMLFactory.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 037 package org.deegree.portal.context; 038 039 import java.awt.Rectangle; 040 import java.net.MalformedURLException; 041 import java.net.URI; 042 import java.net.URL; 043 044 import javax.xml.parsers.ParserConfigurationException; 045 046 import org.deegree.framework.util.Parameter; 047 import org.deegree.framework.util.ParameterList; 048 import org.deegree.framework.xml.XMLFragment; 049 import org.deegree.framework.xml.XMLTools; 050 import org.deegree.model.metadata.iso19115.CitedResponsibleParty; 051 import org.deegree.model.metadata.iso19115.ContactInfo; 052 import org.deegree.model.spatialschema.Point; 053 import org.deegree.ogcbase.BaseURL; 054 import org.deegree.ogcbase.CommonNamespaces; 055 import org.deegree.ogcbase.ImageURL; 056 import org.deegree.ogcwebservices.OWSUtils; 057 import org.w3c.dom.Attr; 058 import org.w3c.dom.Document; 059 import org.w3c.dom.Element; 060 import org.w3c.dom.Node; 061 import org.w3c.dom.Text; 062 063 /** 064 * This is a factory class to export a <code>ViewContext</code> and a 065 * <code>ViewContextCollection</code> as an xml <code>org.w3c.dom.Document</code>. 066 * 067 * 068 * @version $Revision: 18195 $ 069 * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a> 070 * @author last edited by: $Author: mschneider $ 071 * 072 * @version $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18. Jun 2009) $ 073 */ 074 public class XMLFactory { 075 076 // Import and define constants 077 private static URI OGC_CONTEXT_NS = CommonNamespaces.CNTXTNS; 078 079 private static URI D_CONTEXT_NS = CommonNamespaces.DGCNTXTNS; 080 081 private static URI SLD_NS = CommonNamespaces.SLDNS; 082 083 private static URI XSI_NS = CommonNamespaces.buildNSURI( "http://www.w3.org/2001/XMLSchema-instance" ); 084 085 private static URI XLINK_NS = CommonNamespaces.buildNSURI( "http://www.w3.org/1999/xlink" ); 086 087 // Common objects 088 protected static javax.xml.parsers.DocumentBuilderFactory factory = null; 089 090 protected static javax.xml.parsers.DocumentBuilder builder = null; 091 092 protected static Document document = null; 093 094 private XMLFactory() { 095 // Forbid instantiation 096 } 097 098 /** 099 * Convenience method for creating a common document builder. Implementation copied from 100 * XmlDocument (by tf and ap). 101 * 102 * @throws ParserConfigurationException 103 */ 104 protected static void initDocBuilder() 105 throws ParserConfigurationException { 106 107 if ( builder == null ) { 108 if ( factory == null ) { 109 factory = javax.xml.parsers.DocumentBuilderFactory.newInstance(); 110 factory.setIgnoringElementContentWhitespace( true ); 111 factory.setNamespaceAware( false ); 112 factory.setExpandEntityReferences( false ); 113 } 114 builder = factory.newDocumentBuilder(); 115 } 116 117 } 118 119 /** 120 * Creates a new <code>org.w3c.dom.Document</code> using the internal document builder. 121 * 122 * @return new <code>Document</code> instance 123 * @throws ParserConfigurationException 124 */ 125 protected static Document createDocument() 126 throws ParserConfigurationException { 127 128 initDocBuilder(); 129 130 return builder.newDocument(); 131 } 132 133 /** 134 * Creates a new <code>org.w3c.dom.Element</code>. 135 * 136 * @param namespace 137 * the element namespace 138 * @param elemName 139 * the element name 140 * @return new <code>Element</code> instance 141 */ 142 private static Element createElement( URI namespace, String elemName ) { 143 144 return document.createElementNS( namespace == null ? null : namespace.toString(), elemName ); 145 } 146 147 /** 148 * Creates a new <code>org.w3c.dom.Attr</code>. 149 * 150 * @param attName 151 * the attribute name 152 * @param value 153 * the attribute value 154 * @return new <code>Attr</code> instance 155 */ 156 private static Attr createAttribute( String attName, String value ) { 157 158 Attr attr = document.createAttribute( attName ); 159 attr.setValue( value ); 160 161 return attr; 162 } 163 164 /** 165 * Creates a new <code>org.w3c.dom.Text</code>. This is the textual content of an element. 166 * 167 * @param text 168 * the attribute name (if <code>null</code>, then context stays empty) 169 * @return new <code>Text</code> instance 170 */ 171 private static Text createTextNode( String text ) { 172 173 String t = ""; 174 if ( text != null ) { 175 t = text; 176 } 177 178 return document.createTextNode( t ); 179 } 180 181 /** 182 * Creates a new <code>org.w3c.dom.Document</code> describing a <code>ViewContext</code>. 183 * 184 * @param viewContext 185 * the <code>ViewContext</code> to be exported 186 * @return the xml dom-representation of the given viewContext. 187 * @throws ParserConfigurationException 188 * if an XML parser couldn't be found 189 */ 190 public static XMLFragment export( ViewContext viewContext ) 191 throws ParserConfigurationException { 192 193 document = createDocument(); 194 // start appending nodes... 195 appendViewContext( document, viewContext ); 196 197 XMLFragment xml = null; 198 try { 199 xml = new XMLFragment( document, XMLFragment.DEFAULT_URL ); 200 } catch ( MalformedURLException neverHappens ) { 201 neverHappens.printStackTrace(); 202 } 203 204 return xml; 205 } 206 207 /** 208 * Creates a new <code>org.w3c.dom.Document</code> describing a 209 * <code>ViewContextCollection</code>. 210 * 211 * @param viewContCollec 212 * the <code>ViewContextCollection</code> to be exported 213 * @return the xml dom-representation of the given viewContextCollection. 214 * @throws ParserConfigurationException 215 * if an XML parser couldn't be found 216 * 217 */ 218 public static Document export( ViewContextCollection viewContCollec ) 219 throws ParserConfigurationException { 220 221 document = createDocument(); 222 // start appending nodes... 223 appendViewContextCollection( document, viewContCollec ); 224 225 return document; 226 } 227 228 /** 229 * Appends the XML representation of a <code>ViewContext</code> to a <code>Node</code> using 230 * the <code>namespace</code>. 231 * 232 * @param toNode 233 * the <code>Node</code> to append the new element to 234 * @param viewContxt 235 * the <code>ViewContext</code> to be appended as new element 236 * 237 * 238 */ 239 protected static void appendViewContext( Node toNode, ViewContext viewContxt ) { 240 241 if ( viewContxt != null ) { 242 Element e = createElement( OGC_CONTEXT_NS, "ViewContext" ); 243 Element rootNode = (Element) toNode.appendChild( e ); 244 XMLTools.appendNSBinding( rootNode, "sld", SLD_NS ); 245 XMLTools.appendNSBinding( rootNode, "xlink", XLINK_NS ); 246 XMLTools.appendNSBinding( rootNode, "deegree", D_CONTEXT_NS ); 247 XMLTools.appendNSBinding( rootNode, "xsi", XSI_NS ); 248 // XMLTools.appendNSBinding( rootNode, "", OGC_CONTEXT_NS ); 249 XMLTools.appendNSDefaultBinding( rootNode, OGC_CONTEXT_NS ); 250 251 // e.setAttributeNode( createAttribute( "xmlns", OGC_CONTEXT_NS.toString() ) ); 252 // e.setAttributeNode( createAttribute( "xmlns:sld", ) ); 253 // e.setAttributeNode( createAttribute( "xmlns:xlink", .toString() ) ); 254 // e.setAttributeNode( createAttribute( "xmlns:deegree", D_CONTEXT_NS.toString() ) ); 255 // e.setAttributeNode( createAttribute( "xmlns:", XSI_NS.toString() ) ); 256 rootNode.setAttribute( "version", "1.0.0" ); 257 rootNode.setAttribute( "id", "viewContext_id" ); 258 259 appendGeneral( rootNode, viewContxt.getGeneral() ); 260 appendLayerList( rootNode, viewContxt.getLayerList() ); 261 262 // toNode.appendChild( e ); 263 } 264 265 } 266 267 /** 268 * Appends the XML representation of a <code>General</code> to a <code>Node</code> using the 269 * <code>namespace</code>. 270 * 271 * @param toNode 272 * the <code>Node</code> to append the new element to 273 * @param gen 274 * the <code>General</code> to be appended as new element 275 * 276 * contains illegal characters 277 */ 278 protected static void appendGeneral( Node toNode, General gen ) { 279 280 if ( gen != null ) { 281 Element e = createElement( OGC_CONTEXT_NS, "General" ); 282 appendWindow( e, gen.getWindow() ); 283 appendBoundingBox( e, gen.getBoundingBox() ); 284 appendTitle( e, gen.getTitle() ); 285 appendAbstract( e, gen.getAbstract() ); 286 appendKeywords( e, gen.getKeywords() ); 287 appendDescriptionURL( e, gen.getDescriptionURL() ); 288 appendLogoURL( e, gen.getLogoURL() ); 289 appendContactInformation( e, gen.getContactInformation() ); 290 // append deegree-specific extension 291 appendGeneralExtension( e, gen.getExtension() ); 292 293 toNode.appendChild( e ); 294 } 295 296 } 297 298 /** 299 * Appends the XML representation of a <code>Rectangle</code> to a <code>Node</code> using 300 * the <code>namespace</code>. <p/> Note that the XML representation of a 301 * <code>Rectangle</code> is given by a <code><Window></code> element. 302 * 303 * @param toNode 304 * the <code>Node</code> to append the new element to 305 * @param r 306 * the <code>Rectangle</code> to be appended as new element 307 * 308 * contains illegal characters 309 */ 310 protected static void appendWindow( Node toNode, Rectangle r ) { 311 312 if ( r != null ) { 313 Element window = createElement( OGC_CONTEXT_NS, "Window" ); 314 315 window.setAttribute( "width", String.valueOf( r.width ) ); 316 window.setAttribute( "height", String.valueOf( r.height ) ); 317 318 toNode.appendChild( window ); 319 } 320 321 } 322 323 /** 324 * Appends the XML representation of a <code>GM_Point[]</code> to a <code>Node</code> using 325 * the <code>namespace</code>. <p/> Note that the XML representation of a 326 * <code>GM_Point[]</code> is given by a <code><BoundingBox></code> element. 327 * 328 * @param toNode 329 * the <code>Node</code> to append the new element to 330 * @param points 331 * the <code>GM_Point[]</code> to be appended as new element 332 * 333 * contains illegal characters 334 */ 335 protected static void appendBoundingBox( Node toNode, Point[] points ) { 336 337 if ( points != null && points.length == 2 ) { 338 Element bbox = createElement( OGC_CONTEXT_NS, "BoundingBox" ); 339 String srs = "UNKNOWN_SRS"; 340 try { 341 srs = points[0].getCoordinateSystem().getIdentifier(); 342 } catch ( Exception e ) { 343 e.printStackTrace(); 344 } 345 346 bbox.setAttributeNode( createAttribute( "SRS", srs ) ); 347 348 bbox.setAttribute( "minx", String.valueOf( points[0].getX() ) ); 349 bbox.setAttribute( "miny", String.valueOf( points[0].getY() ) ); 350 bbox.setAttribute( "maxx", String.valueOf( points[1].getX() ) ); 351 bbox.setAttribute( "maxy", String.valueOf( points[1].getY() ) ); 352 353 toNode.appendChild( bbox ); 354 355 } 356 357 } 358 359 /** 360 * Appends the XML representation of a <code>Title</code> to a <code>Node</code> using the 361 * <code>namespace</code>. 362 * 363 * @param toNode 364 * the <code>Node</code> to append the new element to 365 * @param title 366 * the <code>String</code> to be appended as new element 367 * 368 * contains illegal characters 369 */ 370 protected static void appendTitle( Node toNode, String title ) { 371 372 String t = ""; 373 if ( title != null ) { 374 t = title; 375 } 376 Element te = createElement( OGC_CONTEXT_NS, "Title" ); 377 te.appendChild( createTextNode( t ) ); 378 toNode.appendChild( te ); 379 380 } 381 382 /** 383 * Appends the XML representation of an <code>Abstract</code> to a <code>Node</code> using 384 * the <code>namespace</code>. 385 * 386 * @param toNode 387 * the <code>Node</code> to append the new element to 388 * @param abstr 389 * the <code>String</code> to be appended as new element 390 * 391 */ 392 protected static void appendAbstract( Node toNode, String abstr ) { 393 394 if ( abstr != null ) { 395 Element te = createElement( OGC_CONTEXT_NS, "Abstract" ); 396 te.appendChild( createTextNode( abstr ) ); 397 toNode.appendChild( te ); 398 } 399 400 } 401 402 /** 403 * Appends the XML representation of an <code>ImageURL</code> to a <code>Node</code> using 404 * the <code>namespace</code>. 405 * 406 * @param toNode 407 * the <code>Node</code> to append the new element to 408 * @param logoURL 409 * the <code>ImageURL</code> to be appended as new element 410 * 411 * contains illegal characters 412 */ 413 protected static void appendLogoURL( Node toNode, ImageURL logoURL ) { 414 415 if ( logoURL != null && logoURL.getOnlineResource() != null ) { 416 Element e = createElement( OGC_CONTEXT_NS, "LogoURL" ); 417 appendOnlineResource( e, logoURL.getOnlineResource() ); 418 toNode.appendChild( e ); 419 } 420 421 } 422 423 /** 424 * Appends the XML representation of a keyword list as a <code>String[]</code> to a 425 * <code>Node</code> using the <code>namespace</code>. <p/> Note that the keywords are 426 * appended to a <code><KeywordList></code> element. 427 * 428 * @param toNode 429 * the <code>Node</code> to append the new element to 430 * @param keywords 431 * the <code>ImageURL</code> to be appended as new element 432 * 433 * contains illegal characters 434 */ 435 protected static void appendKeywords( Node toNode, String[] keywords ) { 436 437 if ( keywords != null ) { 438 Element kWordList = createElement( OGC_CONTEXT_NS, "KeywordList" ); 439 for ( int i = 0; i < keywords.length; i++ ) { 440 Element kw = createElement( OGC_CONTEXT_NS, "Keyword" ); 441 kw.appendChild( createTextNode( keywords[i] ) ); 442 kWordList.appendChild( kw ); 443 } 444 toNode.appendChild( kWordList ); 445 } 446 447 } 448 449 /** 450 * Appends the XML representation of a <code>BaseURL</code>, the <code>DescriptionURL</code>, 451 * to a <code>Node</code> using the <code>namespace</code>. 452 * 453 * @param toNode 454 * the <code>Node</code> to append the new element to 455 * @param bURL 456 * the <code>BaseURL</code> to be appended as new element 457 * 458 * contains illegal characters 459 */ 460 protected static void appendDescriptionURL( Node toNode, BaseURL bURL ) { 461 462 if ( bURL != null ) { 463 Element du = createElement( OGC_CONTEXT_NS, "DescriptionURL" ); 464 String f = bURL.getFormat(); 465 if ( f != null ) { 466 du.setAttribute( "format", f ); 467 } 468 469 URL onlineRes = bURL.getOnlineResource(); 470 appendOnlineResource( du, onlineRes ); 471 472 toNode.appendChild( du ); 473 } 474 475 } 476 477 /** 478 * Appends the XML representation of a <code>URL</code> to a <code>Node</code> as a 479 * <code><OnlineResource></code> using the <code>namespace</code>. 480 * 481 * @param toNode 482 * the <code>Node</code> to append the new element to 483 * @param onlineRes 484 * the <code>URL</code> to be appended as new element 485 * 486 * contains illegal characters 487 */ 488 protected static void appendOnlineResource( Node toNode, URL onlineRes ) { 489 490 if ( onlineRes != null ) { 491 Element or = createElement( OGC_CONTEXT_NS, "OnlineResource" ); 492 or.setAttributeNS( XLINK_NS.toASCIIString(), "xlink:type", "simple" ); 493 494 String href = onlineRes.toExternalForm(); 495 if ( href != null ) { 496 // according to OGC WMS 1.3 Testsuite a URL to a service operation 497 // via HTTPGet must end with '?' or '&' 498 if ( href.indexOf( '.' ) < 0 ) { 499 href = OWSUtils.validateHTTPGetBaseURL( href ); 500 } 501 or.setAttributeNS( XLINK_NS.toASCIIString(), "xlink:href", href ); 502 } 503 toNode.appendChild( or ); 504 } 505 506 } 507 508 /** 509 * Appends the XML representation of a <code>ContactInformation</code> to a <code>Node</code> 510 * using the <code>namespace</code>. 511 * 512 * @param toNode 513 * the <code>Node</code> to append the new element to 514 * @param respParty 515 */ 516 protected static void appendContactInformation( Node toNode, CitedResponsibleParty respParty ) { 517 518 if ( respParty != null ) { 519 Element ci = createElement( OGC_CONTEXT_NS, "ContactInformation" ); 520 521 appendContactPersonPrimary( ci, respParty ); 522 523 Element pos = createElement( OGC_CONTEXT_NS, "ContactPosition" ); 524 pos.appendChild( createTextNode( respParty.getPositionName()[0] ) ); 525 ci.appendChild( pos ); 526 ContactInfo[] conInf = respParty.getContactInfo(); 527 528 if ( conInf != null && conInf.length > 0 ) { 529 appendContactAddress( ci, conInf[0] ); 530 if ( conInf[0].getPhone().getVoice() != null && conInf[0].getPhone().getVoice().length > 0 ) { 531 Element e = createElement( OGC_CONTEXT_NS, "ContactVoiceTelephone" ); 532 e.appendChild( createTextNode( conInf[0].getPhone().getVoice()[0] ) ); 533 ci.appendChild( e ); 534 } 535 if ( conInf[0].getAddress().getElectronicMailAddress() != null 536 && conInf[0].getAddress().getElectronicMailAddress().length > 0 ) { 537 Element e = createElement( OGC_CONTEXT_NS, "ContactElectronicMailAddress" ); 538 e.appendChild( createTextNode( conInf[0].getAddress().getElectronicMailAddress()[0] ) ); 539 ci.appendChild( e ); 540 } 541 } 542 543 toNode.appendChild( ci ); 544 } 545 546 } 547 548 /** 549 * Appends the XML representation of a <code>ContactPersonPrimary</code> to a 550 * <code>Node</code> using the <code>namespace</code>. 551 * 552 * @param toNode 553 * the <code>Node</code> to append the new element to 554 * @param respParty 555 */ 556 protected static void appendContactPersonPrimary( Node toNode, CitedResponsibleParty respParty ) { 557 558 if ( respParty.getIndividualName() != null && respParty.getIndividualName().length > 0 ) { 559 Element cpp = createElement( OGC_CONTEXT_NS, "ContactPersonPrimary" ); 560 561 Element p = createElement( OGC_CONTEXT_NS, "ContactPerson" ); 562 563 p.appendChild( createTextNode( respParty.getIndividualName()[0] ) ); 564 cpp.appendChild( p ); 565 566 Element org = createElement( OGC_CONTEXT_NS, "ContactOrganization" ); 567 org.appendChild( createTextNode( respParty.getOrganisationName()[0] ) ); 568 cpp.appendChild( org ); 569 570 toNode.appendChild( cpp ); 571 } 572 573 } 574 575 /** 576 * Appends the XML representation of a <code>ContactAddress</code> to a <code>Node</code> 577 * using the <code>namespace</code>. 578 * 579 * @param toNode 580 * the <code>Node</code> to append the new element to 581 * @param ci 582 * the <code>ContactAddress</code> to be appended as new element 583 * 584 */ 585 protected static void appendContactAddress( Node toNode, ContactInfo ci ) { 586 587 if ( ci != null ) { 588 Element ca = createElement( OGC_CONTEXT_NS, "ContactAddress" ); 589 590 Element e = createElement( OGC_CONTEXT_NS, "AddressType" ); 591 e.appendChild( createTextNode( "postal" ) ); 592 ca.appendChild( e ); 593 594 e = createElement( OGC_CONTEXT_NS, "Address" ); 595 e.appendChild( createTextNode( ci.getAddress().getDeliveryPoint()[0] ) ); 596 ca.appendChild( e ); 597 598 e = createElement( OGC_CONTEXT_NS, "City" ); 599 e.appendChild( createTextNode( ci.getAddress().getCity() ) ); 600 ca.appendChild( e ); 601 602 e = createElement( OGC_CONTEXT_NS, "StateOrProvince" ); 603 e.appendChild( createTextNode( ci.getAddress().getAdministrativeArea() ) ); 604 ca.appendChild( e ); 605 606 e = createElement( OGC_CONTEXT_NS, "PostCode" ); 607 e.appendChild( createTextNode( ci.getAddress().getPostalCode() ) ); 608 ca.appendChild( e ); 609 610 e = createElement( OGC_CONTEXT_NS, "Country" ); 611 e.appendChild( createTextNode( ci.getAddress().getCountry() ) ); 612 ca.appendChild( e ); 613 614 toNode.appendChild( ca ); 615 } 616 617 } 618 619 /** 620 * Appends the XML representation of a <code>LayerList</code> to a <code>Node</code> using 621 * the <code>namespace</code>. 622 * 623 * @param toNode 624 * the <code>Node</code> to append the new element to 625 * @param lList 626 * the <code>LayerList</code> to be appended as new element 627 * 628 */ 629 protected static void appendLayerList( Node toNode, LayerList lList ) { 630 631 if ( lList != null ) { 632 Element list = createElement( OGC_CONTEXT_NS, "LayerList" ); 633 634 Layer[] ls = lList.getLayers(); 635 if ( ls != null ) { 636 for ( int i = 0; i < ls.length; i++ ) { 637 appendLayer( list, ls[i] ); 638 } 639 } 640 toNode.appendChild( list ); 641 } 642 643 } 644 645 /** 646 * Appends the XML representation of a <code>Layer</code> to a <code>Node</code> using the 647 * <code>namespace</code>. 648 * 649 * @param toNode 650 * the <code>Node</code> to append the new element to 651 * @param layer 652 * the <code>Layer</code> to be appended as new element 653 * 654 */ 655 protected static void appendLayer( Node toNode, Layer layer ) { 656 657 if ( layer != null ) { 658 Element le = createElement( OGC_CONTEXT_NS, "Layer" ); 659 660 le.setAttribute( "queryable", stringValue01( layer.isQueryable() ) ); 661 le.setAttribute( "hidden", stringValue01( layer.isHidden() ) ); 662 663 appendServer( le, layer.getServer() ); 664 665 Element n = createElement( OGC_CONTEXT_NS, "Name" ); 666 n.appendChild( createTextNode( layer.getName() ) ); 667 le.appendChild( n ); 668 669 if ( layer.getAbstract() != null ) { 670 n = createElement( OGC_CONTEXT_NS, "Abstract" ); 671 n.appendChild( createTextNode( layer.getAbstract() ) ); 672 le.appendChild( n ); 673 } 674 675 n = createElement( OGC_CONTEXT_NS, "Title" ); 676 n.appendChild( createTextNode( layer.getTitle() ) ); 677 le.appendChild( n ); 678 679 if ( layer.getMetadataURL() != null ) { 680 n = createElement( OGC_CONTEXT_NS, "MetadataURL" ); 681 le.appendChild( n ); 682 appendOnlineResource( n, layer.getMetadataURL().getOnlineResource() ); 683 } 684 685 appendSrs( le, layer.getSrs() ); 686 appendFormatList( le, layer.getFormatList() ); 687 appendStyleList( le, layer.getStyleList() ); 688 689 appendLayerExtension( le, layer.getExtension() ); 690 691 toNode.appendChild( le ); 692 } 693 694 } 695 696 /** 697 * Appends the XML representation of a <code>Server</code> to a <code>Node</code> using the 698 * <code>namespace</code>. 699 * 700 * @param toNode 701 * the <code>Node</code> to append the new element to 702 * @param server 703 * the <code>Server</code> to be appended as new element 704 * 705 */ 706 protected static void appendServer( Node toNode, Server server ) { 707 708 if ( server != null ) { 709 Element serv = createElement( OGC_CONTEXT_NS, "Server" ); 710 711 if ( server.getService() != null ) { 712 serv.setAttribute( "service", server.getService() ); 713 } 714 if ( server.getService() != null ) { 715 serv.setAttribute( "version", server.getVersion() ); 716 } 717 if ( server.getService() != null ) { 718 serv.setAttribute( "title", server.getTitle() ); 719 } 720 721 appendOnlineResource( serv, server.getOnlineResource() ); 722 723 toNode.appendChild( serv ); 724 } 725 726 } 727 728 /** 729 * Appends the XML representation of a list of SRSs as a <code>String[]</code> to a 730 * <code>Node</code> using the <code>namespace</code>. 731 * 732 * @param toNode 733 * the <code>Node</code> to append the new element to 734 * @param srsList 735 * the <code>String[]</code> to be appended as new element 736 * 737 */ 738 protected static void appendSrs( Node toNode, String[] srsList ) { 739 740 if ( srsList != null ) { 741 StringBuffer sBuf = new StringBuffer( 100 ); 742 for ( int i = 0; i < srsList.length; i++ ) { 743 sBuf.append( srsList[i] ); 744 if ( i < srsList.length - 1 ) 745 sBuf.append( ";" ); 746 747 } 748 Element e = createElement( OGC_CONTEXT_NS, "SRS" ); 749 e.appendChild( createTextNode( sBuf.toString() ) ); 750 toNode.appendChild( e ); 751 } 752 753 } 754 755 /** 756 * Appends the XML representation of a list of a <code>FormatList</code> to a 757 * <code>Node</code> using the <code>namespace</code>. 758 * 759 * @param toNode 760 * the <code>Node</code> to append the new element to 761 * @param formatList 762 * the <code>FormatList</code> to be appended as new element 763 * 764 * contains illegal characters 765 */ 766 protected static void appendFormatList( Node toNode, FormatList formatList ) { 767 768 if ( formatList != null ) { 769 770 Format[] formats = formatList.getFormats(); 771 if ( formats != null ) { 772 Element e = createElement( OGC_CONTEXT_NS, "FormatList" ); 773 774 for ( int i = 0; i < formats.length; i++ ) { 775 if ( formats[i] != null ) { 776 Element f = createElement( OGC_CONTEXT_NS, "Format" ); 777 f.setAttribute( "current", stringValue01( formats[i].isCurrent() ) ); 778 if ( formats[i].getName() != null ) 779 f.appendChild( createTextNode( formats[i].getName() ) ); 780 e.appendChild( f ); 781 } 782 } 783 toNode.appendChild( e ); 784 } 785 } 786 787 } 788 789 /** 790 * Appends the XML representation of a list of a <code>StyleList</code> to a <code>Node</code> 791 * using the <code>namespace</code>. 792 * 793 * @param toNode 794 * the <code>Node</code> to append the new element to 795 * @param styleList 796 * the <code>StyleList</code> to be appended as new element 797 * 798 */ 799 protected static void appendStyleList( Node toNode, StyleList styleList ) { 800 801 if ( styleList != null ) { 802 803 Style[] styles = styleList.getStyles(); 804 if ( styles != null ) { 805 Element e = createElement( OGC_CONTEXT_NS, "StyleList" ); 806 807 for ( int i = 0; i < styles.length; i++ ) { 808 if ( styles[i] != null ) { 809 Element s = createElement( OGC_CONTEXT_NS, "Style" ); 810 s.setAttribute( "current", stringValue01( styles[i].isCurrent() ) ); 811 812 if ( styles[i].getName() != null ) { 813 Element ne = createElement( OGC_CONTEXT_NS, "Name" ); 814 ne.appendChild( createTextNode( styles[i].getName() ) ); 815 s.appendChild( ne ); 816 } 817 if ( styles[i].getTitle() != null ) { 818 Element ne = createElement( OGC_CONTEXT_NS, "Title" ); 819 ne.appendChild( createTextNode( styles[i].getTitle() ) ); 820 s.appendChild( ne ); 821 } 822 if ( styles[i].getAbstract() != null ) { 823 Element ne = createElement( OGC_CONTEXT_NS, "Abstract" ); 824 ne.appendChild( createTextNode( styles[i].getAbstract() ) ); 825 s.appendChild( ne ); 826 } 827 if ( styles[i].getLegendURL() != null && styles[i].getLegendURL().getOnlineResource() != null ) { 828 Element ne = createElement( OGC_CONTEXT_NS, "LegendURL" ); 829 ne.setAttribute( "width", String.valueOf( styles[i].getLegendURL().getWidth() ) ); 830 ne.setAttribute( "height", String.valueOf( styles[i].getLegendURL().getHeight() ) ); 831 ne.setAttribute( "width", String.valueOf( styles[i].getLegendURL().getWidth() ) ); 832 appendOnlineResource( ne, styles[i].getLegendURL().getOnlineResource() ); 833 s.appendChild( ne ); 834 } 835 e.appendChild( s ); 836 837 } 838 } 839 toNode.appendChild( e ); 840 } 841 } 842 843 } 844 845 /** 846 * Appends the XML representation of a list of a <code>ViewContextCollection</code> to a 847 * <code>Node</code> using the <code>namespace</code>. 848 * 849 * @param toNode 850 * the <code>Node</code> to append the new element to 851 * @param vcc 852 * the <code>ViewContextCollection</code> to be appended as new element 853 * 854 */ 855 protected static void appendViewContextCollection( Node toNode, ViewContextCollection vcc ) { 856 857 if ( vcc != null ) { 858 Element e = createElement( OGC_CONTEXT_NS, "ViewContextCollection" ); 859 e.setAttributeNode( createAttribute( "xmlns", OGC_CONTEXT_NS.toString() ) ); 860 e.setAttributeNode( createAttribute( "xmlns:sld", SLD_NS.toString() ) ); 861 e.setAttributeNode( createAttribute( "xmlns:xlink", XLINK_NS.toString() ) ); 862 e.setAttributeNode( createAttribute( "xmlns:deegree", D_CONTEXT_NS.toString() ) ); 863 e.setAttributeNode( createAttribute( "xmlns:xsi", XSI_NS.toString() ) ); 864 e.setAttributeNode( createAttribute( "version", "1.0.0" ) ); 865 866 ViewContextReference[] vcrs = vcc.getViewContextReferences(); 867 if ( vcrs != null && vcrs.length > 0 ) { 868 for ( int i = 0; i < vcrs.length; i++ ) { 869 if ( vcrs[i] != null ) { 870 appendContextReference( e, vcrs[i] ); 871 } 872 } 873 } 874 toNode.appendChild( e ); 875 } 876 877 } 878 879 /** 880 * Appends the XML representation of a list of a <code>ViewContextReference</code> to a 881 * <code>Node</code> using the <code>namespace</code>. <p/> // TODO implement ID in VCR 882 * 883 * @param toNode 884 * the <code>Node</code> to append the new element to 885 * @param vcr 886 * the <code>ViewContextReference</code> to be appended as new element 887 */ 888 protected static void appendContextReference( Node toNode, ViewContextReference vcr ) { 889 890 if ( vcr != null ) { 891 Element e = createElement( OGC_CONTEXT_NS, "ViewContextReference" ); 892 893 e.setAttributeNode( createAttribute( "version", "1.0.0" ) ); 894 895 String id = vcr.getTitle().replace( ' ', '_' ).toLowerCase(); 896 e.setAttributeNode( createAttribute( "id", id ) ); 897 898 Element t = createElement( OGC_CONTEXT_NS, "Title" ); 899 t.appendChild( createTextNode( vcr.getTitle() ) ); 900 e.appendChild( t ); 901 902 if ( vcr.getContextURL() != null ) { 903 Element c = createElement( OGC_CONTEXT_NS, "ViewContextURL" ); 904 appendOnlineResource( c, vcr.getContextURL() ); 905 e.appendChild( c ); 906 } 907 toNode.appendChild( e ); 908 } 909 910 } 911 912 /** 913 * Creates a String representation ("0" or "1") of a boolean value. 914 * 915 * @param value 916 * the input value 917 * @return "0" or "1" if value is true or false, respectively 918 */ 919 private static final String stringValue01( boolean value ) { 920 return value ? "1" : "0"; 921 } 922 923 // *********************************************************************** 924 // BEGIN Deegree specific methods 925 // *********************************************************************** 926 927 /** 928 * Appends the XML representation of a list of a <code>GeneralExtension</code> to a 929 * <code>Node</code> using the <code>namespace</code>. 930 * 931 * @param toNode 932 * the <code>Node</code> to append the new element to 933 * @param genExt 934 * the <code>GeneralExtension</code> to be appended as new element 935 * 936 */ 937 protected static void appendGeneralExtension( Node toNode, GeneralExtension genExt ) { 938 939 if ( genExt != null ) { 940 Element e = createElement( OGC_CONTEXT_NS, "Extension" ); 941 Element a = createElement( D_CONTEXT_NS, "deegree:Mode" ); 942 a.appendChild( createTextNode( genExt.getMode() ) ); 943 e.appendChild( a ); 944 945 appendAuthentificationSettings( e, genExt.getAuthentificationSettings() ); 946 appendIOSettings( e, genExt.getIOSettings() ); 947 appendFrontend( e, genExt.getFrontend() ); 948 appendMapParameter( e, genExt.getMapParameter() ); 949 950 appendLayerTree( e, genExt.getLayerTreeRoot() ); 951 952 toNode.appendChild( e ); 953 } 954 955 } 956 957 /** 958 * Appends the XML representation of a <code>LayerTree</code>. 959 * 960 * @param e 961 * the <code>Element</code> to append the new element to 962 * @param layerTreeRoot 963 * the root <code>Node</code> of the LayerTree 964 * 965 */ 966 protected static void appendLayerTree( Element e, org.deegree.portal.context.Node layerTreeRoot ) { 967 Element layerTree = createElement( D_CONTEXT_NS, "deegree:LayerTree" ); 968 layerTree.appendChild( getLayerTreeNode( layerTreeRoot ) ); 969 e.appendChild( layerTree ); 970 } 971 972 // create LayerTree elements 973 private static Element getLayerTreeNode( org.deegree.portal.context.Node node ) { 974 Element n = createElement( D_CONTEXT_NS, "deegree:Node" ); 975 n.setAttributeNode( createAttribute( "id", String.valueOf( node.getId() ) ) ); 976 n.setAttributeNode( createAttribute( "title", node.getTitle() ) ); 977 978 org.deegree.portal.context.Node[] nodes = node.getNodes(); 979 for ( org.deegree.portal.context.Node childNode : nodes ) { 980 // ( tree -> recursion ) 981 n.appendChild( getLayerTreeNode( childNode ) ); 982 } 983 return n; 984 } 985 986 /** 987 * @param toNode 988 * @param settings 989 */ 990 protected static void appendAuthentificationSettings( Node toNode, AuthentificationSettings settings ) { 991 992 if ( settings != null ) { 993 Element e = createElement( D_CONTEXT_NS, "deegree:AuthentificationSettings" ); 994 Element ee = createElement( D_CONTEXT_NS, "deegree:AuthentificationService" ); 995 appendOnlineResource( ee, settings.getAuthentificationURL().getOnlineResource() ); 996 e.appendChild( ee ); 997 toNode.appendChild( e ); 998 } 999 1000 } 1001 1002 /** 1003 * Appends the XML representation of a list of a <code>IOSettings</code> to a 1004 * <code>Node</code> using the <code>namespace</code>. 1005 * 1006 * @param toNode 1007 * the <code>Node</code> to append the new element to 1008 * @param ioSetts 1009 * the <code>IOSettings</code> to be appended as new element 1010 */ 1011 protected static void appendIOSettings( Node toNode, IOSettings ioSetts ) { 1012 1013 if ( ioSetts != null ) { 1014 Element e = createElement( D_CONTEXT_NS, "deegree:IOSettings" ); 1015 1016 // TODO: ioSetts.getTempDirectory() , inexistent till now 1017 /* 1018 * if(ioSetts.getRootDirectory() != null ){ Element rd = 1019 * createElement(namespace,"deegree:TempDirectory"); rd.appendChild( createTextNode( 1020 * ioSetts.getRootDirectory() + "temp")); e.appendChild(rd); } 1021 */ 1022 1023 appendDirectoryAccess( e, ioSetts.getTempDirectory(), "deegree:TempDirectory" ); 1024 // appendDirectoryAccess( e, ioSetts.getDownloadDirectory(), "deegree:TempDirectory" ); 1025 appendDirectoryAccess( e, ioSetts.getDownloadDirectory(), "deegree:DownloadDirectory" ); 1026 appendDirectoryAccess( e, ioSetts.getSLDDirectory(), "deegree:SLDDirectory" ); 1027 appendDirectoryAccess( e, ioSetts.getPrintDirectory(), "deegree:PrintDirectory" ); 1028 1029 toNode.appendChild( e ); 1030 } 1031 1032 } 1033 1034 /** 1035 * Appends the XML representation of a list of a <code>DirectoryAccess</code> to a 1036 * <code>Node</code> using the <code>namespace</code>. 1037 * 1038 * @param toNode 1039 * the <code>Node</code> to append the new element to 1040 * @param dirAcc 1041 * the <code>DirectoryAccess</code> to be appended as new element 1042 * @param dirName 1043 * 1044 */ 1045 protected static void appendDirectoryAccess( Node toNode, DirectoryAccess dirAcc, String dirName ) { 1046 1047 if ( dirAcc != null ) { 1048 Element d = createElement( D_CONTEXT_NS, dirName ); 1049 if ( dirAcc.getDirectoryName() != null ) { 1050 Element a = createElement( D_CONTEXT_NS, "deegree:Name" ); 1051 a.appendChild( createTextNode( dirAcc.getDirectoryName() ) ); 1052 d.appendChild( a ); 1053 1054 } 1055 if ( dirAcc.getOnlineResource() != null ) { 1056 Element a = createElement( D_CONTEXT_NS, "deegree:Access" ); 1057 appendOnlineResource( a, dirAcc.getOnlineResource() ); 1058 d.appendChild( a ); 1059 } 1060 toNode.appendChild( d ); 1061 } 1062 1063 } 1064 1065 /** 1066 * Appends the XML representation of a list of a <code>Frontend</code> to a <code>Node</code> 1067 * using the <code>namespace</code>. 1068 * 1069 * @param toNode 1070 * the <code>Node</code> to append the new element to 1071 * @param fEnd 1072 * the <code>Frontend</code> to be appended as new element 1073 * 1074 */ 1075 protected static void appendFrontend( Node toNode, Frontend fEnd ) { 1076 1077 if ( fEnd != null ) { 1078 Element e = createElement( D_CONTEXT_NS, "deegree:Frontend" ); 1079 1080 e.setAttribute( "scope", "JSP" ); 1081 if ( fEnd.getController() != null ) { 1082 Element c = createElement( D_CONTEXT_NS, "deegree:Controller" ); 1083 c.appendChild( createTextNode( fEnd.getController() ) ); 1084 e.appendChild( c ); 1085 } 1086 if ( ( (JSPFrontend) fEnd ).getStyle() != null ) { 1087 Element c = createElement( D_CONTEXT_NS, "deegree:Style" ); 1088 c.appendChild( createTextNode( ( (JSPFrontend) fEnd ).getStyle() ) ); 1089 e.appendChild( c ); 1090 } 1091 if ( ( (JSPFrontend) fEnd ).getHeader() != null ) { 1092 Element c = createElement( D_CONTEXT_NS, "deegree:Header" ); 1093 c.appendChild( createTextNode( ( (JSPFrontend) fEnd ).getHeader() ) ); 1094 e.appendChild( c ); 1095 } 1096 if ( ( (JSPFrontend) fEnd ).getFooter() != null ) { 1097 Element c = createElement( D_CONTEXT_NS, "deegree:Footer" ); 1098 c.appendChild( createTextNode( ( (JSPFrontend) fEnd ).getFooter() ) ); 1099 e.appendChild( c ); 1100 } 1101 1102 appendCommonJS( e, ( (JSPFrontend) fEnd ).getCommonJS() ); 1103 1104 appendButtons( e, ( (JSPFrontend) fEnd ).getButtons() ); 1105 1106 appendGUIArea( e, fEnd.getNorth(), "deegree:North" ); 1107 appendGUIArea( e, fEnd.getWest(), "deegree:West" ); 1108 appendGUIArea( e, fEnd.getCenter(), "deegree:Center" ); 1109 appendGUIArea( e, fEnd.getEast(), "deegree:East" ); 1110 appendGUIArea( e, fEnd.getSouth(), "deegree:South" ); 1111 1112 toNode.appendChild( e ); 1113 } 1114 1115 } 1116 1117 /** 1118 * Appends the XML representation of a list of a <code>String[]</code> to a <code>Node</code> 1119 * using the <code>namespace</code>. 1120 * 1121 * @param toNode 1122 * the <code>Node</code> to append the new element to 1123 * @param commonJS 1124 * the <code>String[]</code> to be appended as new element 1125 * 1126 */ 1127 protected static void appendCommonJS( Node toNode, String[] commonJS ) { 1128 1129 if ( commonJS != null ) { 1130 Element c = createElement( D_CONTEXT_NS, "deegree:CommonJS" ); 1131 1132 for ( int i = 0; i < commonJS.length; i++ ) { 1133 if ( commonJS[i] != null ) { 1134 Element n = createElement( D_CONTEXT_NS, "deegree:Name" ); 1135 n.appendChild( createTextNode( commonJS[i] ) ); 1136 c.appendChild( n ); 1137 } 1138 } 1139 toNode.appendChild( c ); 1140 } 1141 1142 } 1143 1144 /** 1145 * Appends the XML representation of a list of a <code>String</code> to a <code>Node</code> 1146 * using the <code>namespace</code>. // TODO 1147 * 1148 * @param toNode 1149 * the <code>Node</code> to append the new element to 1150 * @param buttons 1151 * the <code>String</code> to be appended as new element 1152 * 1153 */ 1154 protected static void appendButtons( Node toNode, String buttons ) { 1155 1156 if ( buttons != null ) { 1157 Element b = createElement( D_CONTEXT_NS, "deegree:Buttons" ); 1158 b.appendChild( createTextNode( buttons ) ); 1159 1160 toNode.appendChild( b ); 1161 } 1162 1163 } 1164 1165 /** 1166 * Appends the XML representation of a list of a <code>GUIArea</code> to a <code>Node</code> 1167 * using the <code>namespace</code>. 1168 * 1169 * @param toNode 1170 * the <code>Node</code> to append the new element to 1171 * @param guiArea 1172 * the <code>GUIArea</code> to be appended as new element 1173 * @param name 1174 * 1175 */ 1176 protected static void appendGUIArea( Node toNode, GUIArea guiArea, String name ) { 1177 1178 if ( guiArea != null ) { 1179 Element e = createElement( D_CONTEXT_NS, name ); 1180 e.setAttribute( "hidden", String.valueOf( guiArea.isHidden() ) ); 1181 if ( guiArea.getWidth() > 0 ) { 1182 e.setAttribute( "width", String.valueOf( guiArea.getWidth() ) ); 1183 } 1184 if ( guiArea.getHeight() > 0 ) { 1185 e.setAttribute( "height", String.valueOf( guiArea.getHeight() ) ); 1186 } 1187 if ( guiArea.getTop() > -1 ) { 1188 e.setAttribute( "top", String.valueOf( guiArea.getTop() ) ); 1189 } 1190 if ( guiArea.getRight() > 0 ) { 1191 e.setAttribute( "right", String.valueOf( guiArea.getRight() ) ); 1192 } 1193 if ( guiArea.getLeft() > -1 ) { 1194 e.setAttribute( "left", String.valueOf( guiArea.getLeft() ) ); 1195 } 1196 if ( guiArea.getBottom() > 0 ) { 1197 e.setAttribute( "bottom", String.valueOf( guiArea.getBottom() ) ); 1198 } 1199 e.setAttribute( "closable", String.valueOf( guiArea.isClosable() ).toLowerCase() ); 1200 e.setAttribute( "header", String.valueOf( guiArea.hasHeader() ).toLowerCase() ); 1201 e.setAttribute( "overlay", String.valueOf( guiArea.isOverlay() ).toLowerCase() ); 1202 1203 Module[] mods = guiArea.getModules(); 1204 if ( mods != null ) { 1205 for ( int i = 0; i < mods.length; i++ ) { 1206 if ( mods[i] != null ) { 1207 appendModule( e, mods[i] ); 1208 } 1209 } 1210 } 1211 1212 toNode.appendChild( e ); 1213 } 1214 1215 } 1216 1217 /** 1218 * Appends the XML representation of a list of a <code>GUIArea</code> to a <code>Node</code> 1219 * using the <code>namespace</code>. 1220 * 1221 * @param toNode 1222 * the <code>Node</code> to append the new element to 1223 * @param mod 1224 * 1225 */ 1226 protected static void appendModule( Node toNode, Module mod ) { 1227 1228 if ( mod != null ) { 1229 Element m = createElement( D_CONTEXT_NS, "deegree:Module" ); 1230 m.setAttribute( "hidden", String.valueOf( mod.isHidden() ) ); 1231 1232 m.setAttribute( "type", mod.getType() ); 1233 m.setAttribute( "scrolling", String.valueOf( mod.getScrolling() ) ); 1234 if ( mod.getWidth() > 0 ) { 1235 m.setAttribute( "width", String.valueOf( mod.getWidth() ) ); 1236 } 1237 if ( mod.getHeight() > 0 ) { 1238 m.setAttribute( "height", String.valueOf( mod.getHeight() ) ); 1239 } 1240 if ( mod.getTop() > -1 ) { 1241 m.setAttribute( "top", String.valueOf( mod.getTop() ) ); 1242 } 1243 if ( mod.getRight() > 0 ) { 1244 m.setAttribute( "right", String.valueOf( mod.getRight() ) ); 1245 } 1246 if ( mod.getLeft() > -1 ) { 1247 m.setAttribute( "left", String.valueOf( mod.getLeft() ) ); 1248 } 1249 if ( mod.getBottom() > 0 ) { 1250 m.setAttribute( "bottom", String.valueOf( mod.getBottom() ) ); 1251 } 1252 m.setAttribute( "closeable", String.valueOf( mod.isClosable() ).toLowerCase() ); 1253 m.setAttribute( "header", String.valueOf( mod.hasHeader() ).toLowerCase() ); 1254 m.setAttribute( "overlay", String.valueOf( mod.isOverlay() ).toLowerCase() ); 1255 1256 Element n = createElement( D_CONTEXT_NS, "deegree:Name" ); 1257 n.appendChild( createTextNode( mod.getName() ) ); 1258 m.appendChild( n ); 1259 1260 n = createElement( D_CONTEXT_NS, "deegree:Content" ); 1261 n.appendChild( createTextNode( mod.getContent() ) ); 1262 m.appendChild( n ); 1263 1264 appendModuleJSList( m, mod.getModuleJSList() ); 1265 appendModuleConfiguration( m, mod.getModuleConfiguration() ); 1266 appendParameterList( m, mod.getParameter() ); 1267 1268 toNode.appendChild( m ); 1269 } 1270 1271 } 1272 1273 /** 1274 * Appends the XML representation of a list of a <code>ModuleConfiguration</code> to a 1275 * <code>Node</code> using the <code>namespace</code>. 1276 * 1277 * @param toNode 1278 * the <code>Node</code> to append the new element to 1279 * @param modConf 1280 * the <code>ModuleConfiguration</code> to be appended as new element 1281 * 1282 */ 1283 protected static void appendModuleConfiguration( Node toNode, ModuleConfiguration modConf ) { 1284 1285 if ( modConf != null && modConf.getOnlineResource() != null ) { 1286 Element e = createElement( D_CONTEXT_NS, "deegree:ModuleConfiguration" ); 1287 appendOnlineResource( e, modConf.getOnlineResource() ); 1288 toNode.appendChild( e ); 1289 } 1290 1291 } 1292 1293 /** 1294 * Appends the XML representation of a list of a <code>ParameterList</code> to a 1295 * <code>Node</code> using the <code>namespace</code>. 1296 * 1297 * @param toNode 1298 * the <code>Node</code> to append the new element to 1299 * @param parList 1300 * the <code>ParameterList</code> to be appended as new element 1301 * 1302 */ 1303 protected static void appendParameterList( Node toNode, ParameterList parList ) { 1304 1305 if ( parList != null && parList.getParameters().length > 0 ) { 1306 1307 Element e = createElement( D_CONTEXT_NS, "deegree:ParameterList" ); 1308 1309 Parameter[] pars = parList.getParameters(); 1310 for ( int i = 0; i < pars.length; i++ ) { 1311 if ( pars[i] != null ) { 1312 Element p = createElement( D_CONTEXT_NS, "deegree:Parameter" ); 1313 1314 Element n = createElement( D_CONTEXT_NS, "deegree:Name" ); 1315 String name = pars[i].getName(); 1316 // name = name.substring(0,name.indexOf(':')); 1317 n.appendChild( createTextNode( name ) ); 1318 p.appendChild( n ); 1319 1320 n = createElement( D_CONTEXT_NS, "deegree:Value" ); 1321 n.appendChild( createTextNode( pars[i].getValue().toString() ) ); 1322 p.appendChild( n ); 1323 1324 e.appendChild( p ); 1325 } 1326 } 1327 toNode.appendChild( e ); 1328 } 1329 1330 } 1331 1332 /** 1333 * Appends the XML representation of a list of a <code>MapParameter</code> to a 1334 * <code>Node</code> using the <code>namespace</code>. 1335 * 1336 * @param toNode 1337 * the <code>Node</code> to append the new element to 1338 * @param mapPar 1339 * the <code>MapParameter</code> to be appended as new element 1340 * 1341 */ 1342 protected static void appendMapParameter( Node toNode, MapParameter mapPar ) { 1343 1344 if ( mapPar != null ) { 1345 Element e = createElement( D_CONTEXT_NS, "deegree:MapParameter" ); 1346 1347 Element f = createElement( D_CONTEXT_NS, "deegree:OfferedInfoFormats" ); 1348 appendFormats( f, mapPar.getOfferedInfoFormats() ); 1349 e.appendChild( f ); 1350 1351 appendMapOperationFactors( e, mapPar.getOfferedZoomFactors(), "deegree:OfferedZoomFactor" ); 1352 appendMapOperationFactors( e, mapPar.getOfferedPanFactors(), "deegree:OfferedPanFactor" ); 1353 1354 Element minScale = createElement( D_CONTEXT_NS, "deegree:MinScale" ); 1355 minScale.appendChild( createTextNode( String.valueOf( mapPar.getMinScale() ) ) ); 1356 e.appendChild( minScale ); 1357 1358 Element maxScale = createElement( D_CONTEXT_NS, "deegree:MaxScale" ); 1359 maxScale.appendChild( createTextNode( String.valueOf( mapPar.getMaxScale() ) ) ); 1360 e.appendChild( maxScale ); 1361 1362 toNode.appendChild( e ); 1363 } 1364 1365 } 1366 1367 /** 1368 * Appends the XML representation of a list of a <code>Format[]</code> to a <code>Node</code> 1369 * using the <code>namespace</code>. 1370 * 1371 * @param toNode 1372 * the <code>Node</code> to append the new element to 1373 * @param formats 1374 * the <code>Format[]</code> to be appended as new element 1375 * 1376 */ 1377 protected static void appendFormats( Node toNode, Format[] formats ) { 1378 1379 if ( formats != null ) { 1380 for ( int i = 0; i < formats.length; i++ ) { 1381 if ( formats[i] != null ) { 1382 Element f = createElement( D_CONTEXT_NS, "deegree:Format" ); 1383 1384 // TODO is current or selected? 1385 if ( formats[i].isCurrent() ) { 1386 f.setAttribute( "selected", String.valueOf( formats[i].isCurrent() ) ); 1387 } 1388 1389 f.appendChild( createTextNode( formats[i].getName() ) ); 1390 toNode.appendChild( f ); 1391 } 1392 } 1393 } 1394 1395 } 1396 1397 /** 1398 * Appends the XML representation of a list of a <code>MapOperationFactor</code> to a 1399 * <code>Node</code> using the <code>namespace</code>. 1400 * 1401 * @param toNode 1402 * the <code>Node</code> to append the new element to 1403 * @param mapOpFac 1404 * the <code>MapOperationFactor</code> to be appended as new element 1405 * @param opName 1406 * 1407 */ 1408 protected static void appendMapOperationFactors( Node toNode, MapOperationFactor[] mapOpFac, String opName ) { 1409 1410 if ( mapOpFac != null ) { 1411 for ( int i = 0; i < mapOpFac.length; i++ ) { 1412 if ( mapOpFac[i] != null ) { 1413 1414 Element mof = createElement( D_CONTEXT_NS, opName ); 1415 Element f = createElement( D_CONTEXT_NS, "deegree:Factor" ); 1416 f.appendChild( createTextNode( String.valueOf( mapOpFac[i].getFactor() ) ) ); 1417 1418 if ( mapOpFac[i].isSelected() ) { 1419 f.setAttribute( "selected", String.valueOf( mapOpFac[i].isSelected() ) ); 1420 } 1421 1422 // TODO isFree ??? 1423 1424 mof.appendChild( f ); 1425 toNode.appendChild( mof ); 1426 } 1427 } 1428 } 1429 1430 } 1431 1432 /** 1433 * Appends the XML representation of a list of a <code>LayerExtension</code> to a 1434 * <code>Node</code> using the <code>namespace</code>. 1435 * 1436 * @param toNode 1437 * the <code>Node</code> to append the new element to 1438 * @param layExt 1439 * the <code>LayerExtension</code> to be appended as new element 1440 * 1441 */ 1442 protected static void appendLayerExtension( Node toNode, LayerExtension layExt ) { 1443 1444 if ( layExt != null ) { 1445 Element e = createElement( OGC_CONTEXT_NS, "Extension" ); 1446 1447 appendDataService( e, layExt.getDataService() ); 1448 1449 Element g = createElement( D_CONTEXT_NS, "deegree:MasterLayer" ); 1450 g.appendChild( createTextNode( String.valueOf( layExt.isMasterLayer() ) ) ); 1451 e.appendChild( g ); 1452 1453 g = createElement( D_CONTEXT_NS, "deegree:ScaleHint" ); 1454 g.setAttribute( "min", "" + layExt.getMinScaleHint() ); 1455 g.setAttribute( "max", "" + layExt.getMaxScaleHint() ); 1456 e.appendChild( g ); 1457 1458 g = createElement( D_CONTEXT_NS, "deegree:parentNodeId" ); 1459 g.appendChild( createTextNode( String.valueOf( layExt.getParentNodeId() ) ) ); 1460 e.appendChild( g ); 1461 1462 g = createElement( D_CONTEXT_NS, "deegree:SelectedForQuery" ); 1463 g.appendChild( createTextNode( String.valueOf( layExt.isSelectedForQuery() ) ) ); 1464 e.appendChild( g ); 1465 1466 g = createElement( D_CONTEXT_NS, "deegree:UseAuthentication" ); 1467 // System.out.println(layExt.getAuthentication()); 1468 if ( layExt.getAuthentication() == LayerExtension.SESSIONID ) { 1469 g.appendChild( createTextNode( "sessionID" ) ); 1470 } else if ( layExt.getAuthentication() == LayerExtension.USERPASSWORD ) { 1471 g.appendChild( createTextNode( "user/password" ) ); 1472 } else if ( layExt.getAuthentication() == LayerExtension.NONE ) { 1473 g.appendChild( createTextNode( "none" ) ); 1474 } 1475 e.appendChild( g ); 1476 1477 toNode.appendChild( e ); 1478 } 1479 1480 } 1481 1482 /** 1483 * Appends the XML representation of a list of a <code>DataService</code> to a 1484 * <code>Node</code> using the <code>namespace</code>. 1485 * 1486 * @param toNode 1487 * the <code>Node</code> to append the new element to 1488 * @param dataServ 1489 * the <code>DataService</code> to be appended as new element 1490 * 1491 */ 1492 protected static void appendDataService( Node toNode, DataService dataServ ) { 1493 1494 if ( dataServ != null ) { 1495 Element e = createElement( D_CONTEXT_NS, "deegree:DataService" ); 1496 1497 if ( dataServ.getServer() != null ) { 1498 appendServer( e, dataServ.getServer() ); 1499 } 1500 String geoType = dataServ.getGeometryType(); 1501 if ( geoType != null ) { 1502 Element g = createElement( D_CONTEXT_NS, "deegree:GeometryType" ); 1503 g.appendChild( createTextNode( dataServ.getGeometryType() ) ); 1504 e.appendChild( g ); 1505 } 1506 String featType = dataServ.getFeatureType(); 1507 if ( featType != null ) { 1508 Element g = createElement( D_CONTEXT_NS, "deegree:FeatureType" ); 1509 g.appendChild( createTextNode( featType ) ); 1510 e.appendChild( g ); 1511 } 1512 1513 toNode.appendChild( e ); 1514 } 1515 1516 } 1517 1518 /** 1519 * Appends the XML representation of a list of a <code>ParameterList</code> to a 1520 * <code>Node</code> using the <code>namespace</code>. 1521 * 1522 * @param toNode 1523 * the <code>Node</code> to append the new element to 1524 * @param modJSList 1525 * the <code>modJSList</code> to be appended as new element 1526 * 1527 */ 1528 protected static void appendModuleJSList( Node toNode, String[] modJSList ) { 1529 1530 if ( modJSList != null && modJSList.length > 0 ) { 1531 1532 for ( int i = 0; i < modJSList.length; i++ ) { 1533 if ( modJSList[i] != null ) { 1534 Element p = createElement( D_CONTEXT_NS, "deegree:ModuleJS" ); 1535 p.appendChild( createTextNode( modJSList[i] ) ); 1536 1537 toNode.appendChild( p ); 1538 } 1539 } 1540 } 1541 1542 } 1543 1544 }