Source Code Cross Referenced for XMLFactory.java in  » GIS » deegree » org » deegree » ogcwebservices » wms » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » GIS » deegree » org.deegree.ogcwebservices.wms 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/trunk/src/org/deegree/ogcwebservices/wms/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:        package org.deegree.ogcwebservices.wms;
044:
045:        import java.io.IOException;
046:        import java.net.URL;
047:        import java.util.List;
048:
049:        import org.deegree.datatypes.QualifiedName;
050:        import org.deegree.datatypes.values.TypedLiteral;
051:        import org.deegree.framework.log.ILogger;
052:        import org.deegree.framework.log.LoggerFactory;
053:        import org.deegree.framework.util.StringTools;
054:        import org.deegree.framework.xml.NamespaceContext;
055:        import org.deegree.framework.xml.XMLParsingException;
056:        import org.deegree.framework.xml.XMLTools;
057:        import org.deegree.model.metadata.iso19115.Address;
058:        import org.deegree.model.metadata.iso19115.Keywords;
059:        import org.deegree.model.metadata.iso19115.OnlineResource;
060:        import org.deegree.model.metadata.iso19115.Phone;
061:        import org.deegree.model.spatialschema.Envelope;
062:        import org.deegree.ogcbase.CommonNamespaces;
063:        import org.deegree.ogcwebservices.OWSUtils;
064:        import org.deegree.ogcwebservices.getcapabilities.MetadataURL;
065:        import org.deegree.ogcwebservices.wms.capabilities.Attribution;
066:        import org.deegree.ogcwebservices.wms.capabilities.AuthorityURL;
067:        import org.deegree.ogcwebservices.wms.capabilities.DataURL;
068:        import org.deegree.ogcwebservices.wms.capabilities.Dimension;
069:        import org.deegree.ogcwebservices.wms.capabilities.Extent;
070:        import org.deegree.ogcwebservices.wms.capabilities.FeatureListURL;
071:        import org.deegree.ogcwebservices.wms.capabilities.Identifier;
072:        import org.deegree.ogcwebservices.wms.capabilities.Layer;
073:        import org.deegree.ogcwebservices.wms.capabilities.LayerBoundingBox;
074:        import org.deegree.ogcwebservices.wms.capabilities.LegendURL;
075:        import org.deegree.ogcwebservices.wms.capabilities.LogoURL;
076:        import org.deegree.ogcwebservices.wms.capabilities.ScaleHint;
077:        import org.deegree.ogcwebservices.wms.capabilities.Style;
078:        import org.deegree.ogcwebservices.wms.capabilities.StyleSheetURL;
079:        import org.deegree.ogcwebservices.wms.capabilities.StyleURL;
080:        import org.deegree.ogcwebservices.wms.capabilities.UserDefinedSymbolization;
081:        import org.deegree.ogcwebservices.wms.capabilities.WMSCapabilities;
082:        import org.deegree.ogcwebservices.wms.capabilities.WMSCapabilitiesDocument;
083:        import org.deegree.ogcwebservices.wms.capabilities.WMSCapabilities_1_3_0;
084:        import org.deegree.owscommon_new.DCP;
085:        import org.deegree.owscommon_new.DomainType;
086:        import org.deegree.owscommon_new.HTTP;
087:        import org.deegree.owscommon_new.Operation;
088:        import org.deegree.owscommon_new.OperationsMetadata;
089:        import org.deegree.owscommon_new.ServiceIdentification;
090:        import org.deegree.owscommon_new.ServiceProvider;
091:        import org.w3c.dom.Element;
092:        import org.xml.sax.SAXException;
093:
094:        /**
095:         * @author <a href="mailto:mschneider@lat-lon.de">Markus Schneider </a>
096:         * @author last edited by: $Author: apoth $
097:         * 
098:         * @version $Revision: 9345 $, $Date: 2007-12-27 08:22:25 -0800 (Thu, 27 Dec 2007) $
099:         */
100:        public class XMLFactory extends org.deegree.owscommon.XMLFactory {
101:
102:            private static final ILogger LOG = LoggerFactory
103:                    .getLogger(XMLFactory.class);
104:
105:            private static NamespaceContext nsContext = CommonNamespaces
106:                    .getNamespaceContext();
107:
108:            /**
109:             * Exports a <code>WMSCapabilities</code> instance to a <code>WMSCapabilitiesDocument</code>.
110:             * 
111:             * @param capabilities
112:             * @return DOM representation of the <code>WMSCapabilities</code>
113:             * @throws IOException
114:             *             if XML template could not be loaded
115:             */
116:            public static WMSCapabilitiesDocument export(
117:                    WMSCapabilities capabilities) throws IOException {
118:
119:                // in case of a 1.3.0 capabilities, switch the method
120:                if (capabilities instanceof  WMSCapabilities_1_3_0) {
121:                    return XMLFactory_1_3_0
122:                            .export((WMSCapabilities_1_3_0) capabilities);
123:                }
124:
125:                WMSCapabilitiesDocument capabilitiesDocument = new WMSCapabilitiesDocument();
126:                try {
127:                    capabilitiesDocument.createEmptyDocument();
128:                    Element root = capabilitiesDocument.getRootElement();
129:
130:                    root.setAttribute("version", "1.1.1");
131:                    root.setAttribute("updateSequence", capabilities
132:                            .getUpdateSequence());
133:
134:                    appendService(root,
135:                            capabilities.getServiceIdentification(),
136:                            capabilities.getServiceProvider());
137:
138:                    appendCapabilityRequests(root, capabilities
139:                            .getOperationMetadata());
140:
141:                    appendUserDefinedSymbolization((Element) XMLTools.getNode(
142:                            root, "./Capability", nsContext), capabilities
143:                            .getUserDefinedSymbolization());
144:
145:                    appendCapabilityLayer((Element) XMLTools.getNode(root,
146:                            "./Capability", nsContext), capabilities.getLayer());
147:
148:                    Element exc = XMLTools.getRequiredElement(root,
149:                            "Capability/Exception", nsContext);
150:                    for (String f : capabilities.getExceptions()) {
151:                        XMLTools.appendElement(exc, null, "Format", f);
152:                    }
153:
154:                } catch (SAXException e) {
155:                    LOG.logError(e.getMessage(), e);
156:                } catch (XMLParsingException e) {
157:                    LOG.logError(e.getMessage(), e);
158:                }
159:
160:                return capabilitiesDocument;
161:            }
162:
163:            /**
164:             * This method exports a 1.3.0 capabilities document as 1.1.1, providing backward compatibility.
165:             * 
166:             * @param capabilities
167:             * @return the 1.1.1 document
168:             * @throws IOException
169:             */
170:            public static WMSCapabilitiesDocument exportAs_1_1_1(
171:                    WMSCapabilities_1_3_0 capabilities) throws IOException {
172:                WMSCapabilitiesDocument doc = new WMSCapabilitiesDocument();
173:
174:                try {
175:                    doc.createEmptyDocument();
176:
177:                    Element root = doc.getRootElement();
178:
179:                    root.setAttribute("version", "1.1.1");
180:                    root.setAttribute("updateSequence", capabilities
181:                            .getUpdateSequence());
182:
183:                    appendService(root,
184:                            capabilities.getServiceIdentification(),
185:                            capabilities.getServiceProvider());
186:
187:                    appendCapabilityRequests(root, capabilities
188:                            .getOperationMetadata());
189:
190:                    Element cap = (Element) XMLTools.getNode(root,
191:                            "Capability", nsContext);
192:                    // we don't have that one in 1.3.0 data, so just make it up since it is generally
193:                    // enabled in deegree WMS
194:                    UserDefinedSymbolization uds = new UserDefinedSymbolization(
195:                            true, true, false, true);
196:                    appendUserDefinedSymbolization(cap, uds);
197:
198:                    appendCapabilityLayer(cap, capabilities.getLayer());
199:
200:                    Element exc = XMLTools.getRequiredElement(root,
201:                            "Capability/Exception", nsContext);
202:                    for (String f : capabilities.getExceptions()) {
203:                        if (f.equalsIgnoreCase("XML")) {
204:                            f = "application/vnd.ogc.se_xml";
205:                        }
206:                        if (f.equalsIgnoreCase("INIMAGE")) {
207:                            f = "application/vnd.ogc.se_inimage";
208:                        }
209:                        if (f.equalsIgnoreCase("BLANK")) {
210:                            f = "application/vnd.ogc.se_blank";
211:                        }
212:                        XMLTools.appendElement(exc, null, "Format", f);
213:                    }
214:
215:                } catch (XMLParsingException e) {
216:                    LOG.logError(e.getMessage(), e);
217:                } catch (SAXException e) {
218:                    LOG.logError(e.getMessage(), e);
219:                }
220:
221:                return doc;
222:            }
223:
224:            /**
225:             * 
226:             * @param root
227:             * @param uds
228:             */
229:            protected static void appendUserDefinedSymbolization(Element root,
230:                    UserDefinedSymbolization uds) {
231:
232:                Element elem = XMLTools.appendElement(root, null,
233:                        "UserDefinedSymbolization");
234:                elem.setAttribute("SupportSLD", boolean2Number(uds
235:                        .isSldSupported()));
236:                elem.setAttribute("UserLayer", boolean2Number(uds
237:                        .isUserLayerSupported()));
238:                elem.setAttribute("UserStyle", boolean2Number(uds
239:                        .isUserStyleSupported()));
240:                elem.setAttribute("RemoteWFS", boolean2Number(uds
241:                        .isRemoteWFSSupported()));
242:
243:            }
244:
245:            private static String boolean2Number(boolean bool) {
246:                if (bool) {
247:                    return "1";
248:                }
249:                return "0";
250:            }
251:
252:            /**
253:             * 
254:             * @param root
255:             * @param identification
256:             * @param provider
257:             * @throws XMLParsingException
258:             */
259:            protected static void appendService(Element root,
260:                    ServiceIdentification identification,
261:                    ServiceProvider provider) throws XMLParsingException {
262:
263:                root = (Element) XMLTools.getRequiredNode(root, "./Service",
264:                        nsContext);
265:
266:                Element node = (Element) XMLTools.getRequiredNode(root,
267:                        "./Name", nsContext);
268:                // is this actually desired?
269:                node.setTextContent("OGC:WMS");
270:
271:                node = (Element) XMLTools.getRequiredNode(root, "./Title",
272:                        nsContext);
273:                node.setTextContent(identification.getTitle());
274:
275:                String serviceAbstract = identification.getAbstractString();
276:                if (serviceAbstract != null) {
277:                    XMLTools.appendElement(root, null, "Abstract",
278:                            serviceAbstract);
279:                }
280:
281:                List<Keywords> keywords = identification.getKeywords();
282:                if (keywords.size() > 0) {
283:                    String[] kw = keywords.get(0).getKeywords();
284:                    Element kwl = XMLTools.appendElement(root, null,
285:                            "KeywordList");
286:                    for (int i = 0; i < kw.length; i++) {
287:                        XMLTools.appendElement(kwl, null, "Keyword", kw[i]);
288:                    }
289:                }
290:
291:                node = root.getOwnerDocument().createElement("OnlineResource");
292:
293:                OnlineResource sLink = provider.getProviderSite();
294:                org.deegree.model.metadata.iso19115.XMLFactory
295:                        .appendOnlineResource(node, sLink);
296:
297:                root.appendChild(node);
298:
299:                appendContactInformation(root, provider);
300:
301:                String fee = null;
302:                if (identification.getAccessConstraints().size() > 0)
303:                    fee = identification.getAccessConstraints().get(0)
304:                            .getFees();
305:                if (fee != null) {
306:                    XMLTools.appendElement(root, null, "Fees", fee);
307:                } else {
308:                    XMLTools.appendElement(root, null, "Fees", "none");
309:                }
310:
311:                if (identification.getAccessConstraints().size() > 0) {
312:                    XMLTools.appendElement(root, null, "AccessConstraints",
313:                            identification.getAccessConstraints().get(0)
314:                                    .getUseLimitations().get(0));
315:                } else {
316:                    XMLTools.appendElement(root, null, "AccessConstraints",
317:                            "none");
318:                }
319:
320:            }
321:
322:            /**
323:             * 
324:             * @param root
325:             * @param provider
326:             */
327:            protected static void appendContactInformation(Element root,
328:                    ServiceProvider provider) {
329:
330:                Element ciNode = XMLTools.appendElement(root, null,
331:                        "ContactInformation");
332:                Element cppNode = XMLTools.appendElement(ciNode, null,
333:                        "ContactPersonPrimary");
334:                if (provider.getServiceContact().getIndividualName().length > 0) {
335:                    XMLTools
336:                            .appendElement(cppNode, null, "ContactPerson",
337:                                    provider.getServiceContact()
338:                                            .getIndividualName()[0]);
339:                }
340:                if (provider.getServiceContact().getOrganisationName().length > 0) {
341:                    XMLTools.appendElement(cppNode, null,
342:                            "ContactOrganization", provider.getServiceContact()
343:                                    .getOrganisationName()[0]);
344:                }
345:                if (provider.getServiceContact().getPositionName().length > 0) {
346:                    XMLTools.appendElement(ciNode, null, "ContactPosition",
347:                            provider.getServiceContact().getPositionName()[0]);
348:                }
349:                Element caNode = XMLTools.appendElement(ciNode, null,
350:                        "ContactAddress");
351:
352:                XMLTools.appendElement(caNode, null, "AddressType", "postal");
353:
354:                if (provider.getServiceContact().getContactInfo().length > 0) {
355:                    Address addr = provider.getServiceContact()
356:                            .getContactInfo()[0].getAddress();
357:                    String[] dp = addr.getDeliveryPoint();
358:                    if (dp.length > 0) {
359:                        XMLTools.appendElement(caNode, null, "Address", dp[0]);
360:                    }
361:                    if (addr.getCity() != null) {
362:                        XMLTools.appendElement(caNode, null, "City", addr
363:                                .getCity());
364:                    }
365:                    if (addr.getAdministrativeArea() != null) {
366:                        XMLTools.appendElement(caNode, null, "StateOrProvince",
367:                                addr.getAdministrativeArea());
368:                    }
369:                    if (addr.getPostalCode() != null) {
370:                        XMLTools.appendElement(caNode, null, "PostCode", addr
371:                                .getPostalCode());
372:                    }
373:                    if (addr.getCountry() != null) {
374:                        XMLTools.appendElement(caNode, null, "Country", addr
375:                                .getCountry());
376:                    }
377:
378:                    Phone phone = provider.getServiceContact().getContactInfo()[0]
379:                            .getPhone();
380:                    if (phone.getVoice().length > 0) {
381:                        XMLTools.appendElement(ciNode, null,
382:                                "ContactVoiceTelephone", phone.getVoice()[0]);
383:                    }
384:                    if (phone.getFacsimile().length > 0) {
385:                        XMLTools.appendElement(ciNode, null,
386:                                "ContactFacsimileTelephone", phone
387:                                        .getFacsimile()[0]);
388:                    }
389:                    if (addr.getElectronicMailAddress().length > 0) {
390:                        XMLTools.appendElement(ciNode, null,
391:                                "ContactElectronicMailAddress", addr
392:                                        .getElectronicMailAddress()[0]);
393:                    }
394:                }
395:
396:            }
397:
398:            /**
399:             * 
400:             * @param root
401:             * @param operationsMetadata
402:             * @throws XMLParsingException
403:             */
404:            protected static void appendCapabilityRequests(Element root,
405:                    OperationsMetadata operationsMetadata)
406:                    throws XMLParsingException {
407:
408:                root = (Element) XMLTools.getRequiredNode(root,
409:                        "./Capability/Request", nsContext);
410:
411:                operationsMetadata.getOperations();
412:
413:                // just append all operations
414:                for (Operation operation : operationsMetadata.getOperations()) {
415:                    appendOperation(root, operation);
416:                }
417:
418:            }
419:
420:            /**
421:             * 
422:             * @param root
423:             * @param operation
424:             */
425:            protected static void appendOperation(Element root,
426:                    Operation operation) {
427:
428:                String name = operation.getName().getLocalName();
429:
430:                root = XMLTools.appendElement(root, null, name);
431:
432:                DomainType odt = (DomainType) operation
433:                        .getParameter(new QualifiedName("Format"));
434:
435:                List<TypedLiteral> values = odt.getValues();
436:                for (TypedLiteral value : values)
437:                    XMLTools.appendElement(root, null, "Format", value
438:                            .getValue());
439:
440:                List<DCP> dcps = operation.getDCP();
441:                for (DCP dcp : dcps) {
442:                    Element http = XMLTools
443:                            .appendElement(root, null, "DCPType");
444:                    http = XMLTools.appendElement(http, null, "HTTP");
445:                    HTTP ht = (HTTP) dcp;
446:                    List<HTTP.Type> types = ht.getTypes();
447:                    List<OnlineResource> links = ht.getLinks();
448:                    for (int i = 0; i < types.size(); ++i) {
449:                        Element elem = null;
450:                        if (types.get(i) == HTTP.Type.Get)
451:                            elem = XMLTools.appendElement(http, null, "Get");
452:                        if (types.get(i) == HTTP.Type.Post)
453:                            elem = XMLTools.appendElement(http, null, "Post");
454:                        if (elem != null) {
455:                            elem = XMLTools.appendElement(elem, null,
456:                                    "OnlineResource");
457:                            org.deegree.model.metadata.iso19115.XMLFactory
458:                                    .appendOnlineResource(elem, links.get(i));
459:                        }
460:                    }
461:                }
462:
463:            }
464:
465:            /**
466:             * 
467:             * @param root
468:             * @param layer
469:             * @throws XMLParsingException
470:             */
471:            protected static void appendCapabilityLayer(Element root,
472:                    Layer layer) throws XMLParsingException {
473:
474:                root = XMLTools.appendElement(root, null, "Layer");
475:                root.setAttribute("queryable", boolean2Number(layer
476:                        .isQueryable()));
477:                root.setAttribute("cascaded", Integer.toString(layer
478:                        .getCascaded()));
479:                root.setAttribute("opaque", boolean2Number(layer.isOpaque()));
480:                root.setAttribute("noSubsets", boolean2Number(layer
481:                        .hasNoSubsets()));
482:                if (layer.getFixedWidth() > 0) {
483:                    root.setAttribute("fixedWidth", Integer.toString(layer
484:                            .getFixedWidth()));
485:                }
486:                if (layer.getFixedHeight() > 0) {
487:                    root.setAttribute("fixedHeight", Integer.toString(layer
488:                            .getFixedHeight()));
489:                }
490:
491:                if (layer.getName() != null) {
492:                    XMLTools.appendElement(root, null, "Name", layer.getName());
493:                }
494:                XMLTools.appendElement(root, null, "Title", layer.getTitle());
495:
496:                if (layer.getAbstract() != null) {
497:                    XMLTools.appendElement(root, null, "Abstract", layer
498:                            .getAbstract());
499:                }
500:
501:                String[] keywords = layer.getKeywordList();
502:                if (keywords.length > 0) {
503:                    Element elem = XMLTools.appendElement(root, null,
504:                            "KeywordList");
505:                    for (int i = 0; i < keywords.length; i++) {
506:                        XMLTools.appendElement(elem, null, "Keyword",
507:                                keywords[i]);
508:                    }
509:                }
510:
511:                String[] srs = layer.getSrs();
512:                for (int i = 0; i < srs.length; i++) {
513:                    XMLTools.appendElement(root, null, "SRS", srs[i]);
514:                }
515:
516:                Envelope llBox = layer.getLatLonBoundingBox();
517:                appendLatLonBoundingBox(root, llBox);
518:
519:                LayerBoundingBox[] lBoxes = layer.getBoundingBoxes();
520:                for (int i = 0; i < lBoxes.length; i++) {
521:                    appendLayerBoundingBox(root, lBoxes[i]);
522:                }
523:
524:                Dimension[] dims = layer.getDimension();
525:                for (int i = 0; i < dims.length; i++) {
526:                    appendDimension(root, dims[i]);
527:                }
528:
529:                Extent[] extents = layer.getExtent();
530:                for (int i = 0; i < extents.length; i++) {
531:                    appendExtent(root, extents[i]);
532:                }
533:
534:                Attribution attr = layer.getAttribution();
535:                if (attr != null) {
536:                    appendAttribution(root, attr);
537:                }
538:
539:                AuthorityURL[] authorityURLs = layer.getAuthorityURL();
540:                for (int i = 0; i < authorityURLs.length; i++) {
541:                    appendAuthorityURL(root, authorityURLs[i]);
542:                }
543:
544:                Identifier[] identifiers = layer.getIdentifier();
545:                for (int i = 0; i < identifiers.length; i++) {
546:                    appendIdentifier(root, identifiers[i]);
547:                }
548:
549:                MetadataURL[] metadataURLs = layer.getMetadataURL();
550:                for (int i = 0; i < metadataURLs.length; i++) {
551:                    appendMetadataURL(root, metadataURLs[i]);
552:                }
553:
554:                DataURL[] dataURLs = layer.getDataURL();
555:                for (int i = 0; i < dataURLs.length; i++) {
556:                    appendDataURL(root, dataURLs[i]);
557:                }
558:
559:                FeatureListURL[] featureListURLs = layer.getFeatureListURL();
560:                for (int i = 0; i < featureListURLs.length; i++) {
561:                    appendFeatureListURL(root, featureListURLs[i]);
562:                }
563:
564:                if (layer.getName() != null && layer.getName().length() > 0) {
565:                    Style[] styles = layer.getStyles();
566:                    for (int i = 0; i < styles.length; i++) {
567:                        appendStyle(root, styles[i]);
568:                    }
569:                }
570:
571:                ScaleHint scaleHint = layer.getScaleHint();
572:                Element elem = XMLTools.appendElement(root, null, "ScaleHint");
573:                elem.setAttribute("min", "" + scaleHint.getMin());
574:                elem.setAttribute("max", "" + scaleHint.getMax());
575:
576:                Layer[] layers = layer.getLayer();
577:                for (int i = 0; i < layers.length; i++) {
578:                    appendCapabilityLayer(root, layers[i]);
579:                }
580:
581:            }
582:
583:            /**
584:             * 
585:             * @param root
586:             * @param style
587:             */
588:            protected static void appendStyle(Element root, Style style) {
589:
590:                String nm = style.getName();
591:                String tlt = style.getTitle();
592:                if (nm.startsWith("default:")) {
593:                    nm = "default";
594:                    if (tlt != null) {
595:                        tlt = StringTools.replace(tlt, "default:", "", false)
596:                                + " (default)";
597:                    }
598:                }
599:
600:                root = XMLTools.appendElement(root, null, "Style");
601:                XMLTools.appendElement(root, null, "Name", nm);
602:                if (style.getTitle() != null) {
603:                    XMLTools.appendElement(root, null, "Title", tlt);
604:                }
605:                if (style.getAbstract() != null) {
606:                    XMLTools.appendElement(root, null, "Abstract", style
607:                            .getAbstract());
608:                }
609:                LegendURL[] legendURLs = style.getLegendURL();
610:                for (int i = 0; i < legendURLs.length; i++) {
611:                    appendLegendURL(root, legendURLs[i]);
612:                }
613:
614:                StyleSheetURL styleSheetURL = style.getStyleSheetURL();
615:                if (styleSheetURL != null) {
616:                    appendStyleSheetURL(root, styleSheetURL);
617:                }
618:
619:                StyleURL styleURL = style.getStyleURL();
620:                if (styleURL != null) {
621:                    appendStyleURL(root, styleURL);
622:                }
623:
624:            }
625:
626:            /**
627:             * @param root
628:             * @param styleURL
629:             */
630:            protected static void appendStyleURL(Element root, StyleURL styleURL) {
631:                Element elem = XMLTools.appendElement(root, null, "StyleURL");
632:                XMLTools.appendElement(elem, null, "Format", styleURL
633:                        .getFormat());
634:                appendOnlineResource(elem, styleURL.getOnlineResource(), false);
635:            }
636:
637:            /**
638:             * @param root
639:             * @param styleSheetURL
640:             */
641:            protected static void appendStyleSheetURL(Element root,
642:                    StyleSheetURL styleSheetURL) {
643:                Element elem = XMLTools.appendElement(root, null,
644:                        "StyleSheetURL");
645:                XMLTools.appendElement(elem, null, "Format", styleSheetURL
646:                        .getFormat());
647:                appendOnlineResource(elem, styleSheetURL.getOnlineResource(),
648:                        false);
649:            }
650:
651:            /**
652:             * @param root
653:             * @param legendURL
654:             */
655:            protected static void appendLegendURL(Element root,
656:                    LegendURL legendURL) {
657:                Element elem = XMLTools.appendElement(root, null, "LegendURL");
658:                elem.setAttribute("width", "" + legendURL.getWidth());
659:                elem.setAttribute("height", "" + legendURL.getWidth());
660:                XMLTools.appendElement(elem, null, "Format", legendURL
661:                        .getFormat());
662:
663:                appendOnlineResource(elem, legendURL.getOnlineResource(), false);
664:            }
665:
666:            /**
667:             * @param root
668:             * @param featureListURL
669:             */
670:            protected static void appendFeatureListURL(Element root,
671:                    FeatureListURL featureListURL) {
672:                Element elem = XMLTools.appendElement(root, null,
673:                        "FeatureListURL");
674:                XMLTools.appendElement(elem, null, "Format", featureListURL
675:                        .getFormat());
676:                appendOnlineResource(elem, featureListURL.getOnlineResource(),
677:                        false);
678:            }
679:
680:            /**
681:             * @param root
682:             * @param dataURL
683:             */
684:            protected static void appendDataURL(Element root, DataURL dataURL) {
685:                Element elem = XMLTools.appendElement(root, null, "DataURL");
686:                XMLTools.appendElement(elem, null, "Format", dataURL
687:                        .getFormat());
688:                appendOnlineResource(elem, dataURL.getOnlineResource(), false);
689:            }
690:
691:            /**
692:             * @param root
693:             * @param metadataURL
694:             */
695:            protected static void appendMetadataURL(Element root,
696:                    MetadataURL metadataURL) {
697:                Element elem = XMLTools
698:                        .appendElement(root, null, "MetadataURL");
699:                elem.setAttribute("type", metadataURL.getType());
700:                XMLTools.appendElement(elem, null, "Format", metadataURL
701:                        .getFormat());
702:                appendOnlineResource(elem, metadataURL.getOnlineResource(),
703:                        false);
704:            }
705:
706:            /**
707:             * @param root
708:             * @param identifier
709:             */
710:            protected static void appendIdentifier(Element root,
711:                    Identifier identifier) {
712:                Element elem = XMLTools.appendElement(root, null, "Identifier");
713:                elem.setAttribute("authority", identifier.getAuthority());
714:                elem.setTextContent(identifier.getValue());
715:            }
716:
717:            /**
718:             * @param root
719:             * @param authorityURL
720:             */
721:            protected static void appendAuthorityURL(Element root,
722:                    AuthorityURL authorityURL) {
723:                Element elem = XMLTools.appendElement(root, null,
724:                        "AuthorityURL");
725:                elem.setAttribute("name", authorityURL.getName());
726:                appendOnlineResource(elem, authorityURL.getOnlineResource(),
727:                        false);
728:            }
729:
730:            /**
731:             * @param root
732:             * @param attr
733:             */
734:            protected static void appendAttribution(Element root,
735:                    Attribution attr) {
736:                Element elem = XMLTools
737:                        .appendElement(root, null, "Attribution");
738:                XMLTools.appendElement(elem, null, "Title", attr.getTitle());
739:                appendOnlineResource(elem, attr.getOnlineResource(), false);
740:                LogoURL logoURL = attr.getLogoURL();
741:                if (logoURL != null) {
742:                    elem = XMLTools.appendElement(elem, null, "LogoURL");
743:                    elem.setAttribute("width", "" + logoURL.getWidth());
744:                    elem.setAttribute("height", "" + logoURL.getHeight());
745:                    XMLTools.appendElement(elem, null, "Format", logoURL
746:                            .getFormat());
747:                    appendOnlineResource(elem, logoURL.getOnlineResource(),
748:                            false);
749:                }
750:            }
751:
752:            /**
753:             * @param root
754:             * @param url
755:             * @param appendFineChar
756:             */
757:            protected static void appendOnlineResource(Element root, URL url,
758:                    boolean appendFineChar) {
759:
760:                Element olr = XMLTools.appendElement(root, null,
761:                        "OnlineResource");
762:                olr.setAttributeNS("http://www.w3.org/1999/xlink",
763:                        "xlink:type", "simple");
764:                if (appendFineChar) {
765:                    // according to OGC WMS 1.1.1 & 1.3 Testsuite a URL to a service operation
766:                    // via HTTPGet must end with '?' or '&'
767:                    String href = OWSUtils.validateHTTPGetBaseURL(url
768:                            .toExternalForm());
769:                    olr.setAttributeNS("http://www.w3.org/1999/xlink",
770:                            "xlink:href", href);
771:                } else {
772:                    olr.setAttributeNS("http://www.w3.org/1999/xlink",
773:                            "xlink:href", url.toExternalForm());
774:                }
775:            }
776:
777:            /**
778:             * @param root
779:             * @param extent
780:             */
781:            protected static void appendExtent(Element root, Extent extent) {
782:                Element exNode = XMLTools.appendElement(root, null, "Extent");
783:                exNode.setAttribute("name", extent.getName());
784:                exNode.setAttribute("default", extent.getDefault());
785:                exNode.setAttribute("nearestValue", boolean2Number(extent
786:                        .useNearestValue()));
787:                exNode.setTextContent(extent.getValue());
788:            }
789:
790:            /**
791:             * @param root
792:             * @param dim
793:             */
794:            protected static void appendDimension(Element root, Dimension dim) {
795:                Element dimNode = XMLTools.appendElement(root, null,
796:                        "Dimension");
797:                dimNode.setAttribute("name", dim.getName());
798:                dimNode.setAttribute("units", dim.getUnits());
799:                dimNode.setAttribute("unitSymbol", dim.getUnitSymbol());
800:            }
801:
802:            /**
803:             * @param root
804:             * @param lBox
805:             */
806:            protected static void appendLayerBoundingBox(Element root,
807:                    LayerBoundingBox lBox) {
808:                Element bbNode = XMLTools.appendElement(root, null,
809:                        "BoundingBox");
810:                bbNode.setAttribute("minx", "" + lBox.getMin().getX());
811:                bbNode.setAttribute("miny", "" + lBox.getMin().getY());
812:                bbNode.setAttribute("maxx", "" + lBox.getMax().getX());
813:                bbNode.setAttribute("maxy", "" + lBox.getMax().getY());
814:                bbNode.setAttribute("resx", "" + lBox.getResx());
815:                bbNode.setAttribute("resy", "" + lBox.getResy());
816:                bbNode.setAttribute("SRS", "" + lBox.getSRS());
817:            }
818:
819:            /**
820:             * @param root
821:             * @param llBox
822:             */
823:            protected static void appendLatLonBoundingBox(Element root,
824:                    Envelope llBox) {
825:                Element bbNode = XMLTools.appendElement(root, null,
826:                        "LatLonBoundingBox");
827:                bbNode.setAttribute("minx", "" + llBox.getMin().getX());
828:                bbNode.setAttribute("miny", "" + llBox.getMin().getY());
829:                bbNode.setAttribute("maxx", "" + llBox.getMax().getX());
830:                bbNode.setAttribute("maxy", "" + llBox.getMax().getY());
831:            }
832:
833:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.