001: //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/trunk/src/org/deegree/ogcwebservices/wpvs/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: Aennchenstraße 19
030: 53177 Bonn
031: Germany
032: E-Mail: poth@lat-lon.de
033:
034: Prof. Dr. Klaus Greve
035: Department of Geography
036: University of Bonn
037: Meckenheimer Allee 166
038: 53115 Bonn
039: Germany
040: E-Mail: greve@giub.uni-bonn.de
041:
042: ---------------------------------------------------------------------------*/
043:
044: package org.deegree.ogcwebservices.wpvs;
045:
046: import java.io.IOException;
047: import java.net.URI;
048: import java.net.URL;
049:
050: import org.deegree.datatypes.values.TypedLiteral;
051: import org.deegree.datatypes.values.ValueRange;
052: import org.deegree.framework.xml.XMLTools;
053: import org.deegree.model.crs.CoordinateSystem;
054: import org.deegree.model.spatialschema.Envelope;
055: import org.deegree.ogcbase.BaseURL;
056: import org.deegree.ogcbase.CommonNamespaces;
057: import org.deegree.ogcbase.ImageURL;
058: import org.deegree.ogcwebservices.getcapabilities.DCPType;
059: import org.deegree.ogcwebservices.getcapabilities.OperationsMetadata;
060: import org.deegree.ogcwebservices.getcapabilities.ServiceIdentification;
061: import org.deegree.ogcwebservices.getcapabilities.ServiceProvider;
062: import org.deegree.ogcwebservices.wpvs.capabilities.DataProvider;
063: import org.deegree.ogcwebservices.wpvs.capabilities.Dataset;
064: import org.deegree.ogcwebservices.wpvs.capabilities.Dimension;
065: import org.deegree.ogcwebservices.wpvs.capabilities.Identifier;
066: import org.deegree.ogcwebservices.wpvs.capabilities.MetaData;
067: import org.deegree.ogcwebservices.wpvs.capabilities.Style;
068: import org.deegree.ogcwebservices.wpvs.capabilities.WPVSCapabilities;
069: import org.deegree.ogcwebservices.wpvs.capabilities.WPVSCapabilitiesDocument;
070: import org.deegree.ogcwebservices.wpvs.capabilities.WPVSOperationsMetadata;
071: import org.deegree.owscommon.OWSMetadata;
072: import org.deegree.owscommon.com110.HTTP110;
073: import org.deegree.owscommon.com110.OWSAllowedValues;
074: import org.deegree.owscommon.com110.OWSDomainType110;
075: import org.deegree.owscommon.com110.OWSRequestMethod;
076: import org.deegree.owscommon.com110.Operation110;
077: import org.w3c.dom.Element;
078: import org.w3c.dom.Text;
079: import org.xml.sax.SAXException;
080:
081: /**
082: * TODO class description
083: *
084: * @author <a href="mailto:mays@lat-lon.de">Judit Mays</a>
085: * @author last edited by: $Author: rbezema $
086: *
087: * $Revision: 10559 $, $Date: 2008-03-12 01:35:07 -0700 (Wed, 12 Mar 2008) $
088: */
089: public class XMLFactory extends org.deegree.owscommon.XMLFactory {
090:
091: private static final URI WPVSNS = CommonNamespaces.WPVSNS;
092:
093: private static final String PRE_OWS = CommonNamespaces.OWS_PREFIX + ':';
094:
095: private static final String PRE_WPVS = CommonNamespaces.WPVS_PREFIX + ':';
096:
097: private XMLFactory() {
098: // not instantiable.
099: }
100:
101: /**
102: * This method exporst a wpvs capabilitiesDocument with following information taken from the
103: * given WPVSCapabilities
104: * <ul>
105: * <li>ServiceIdentification</li>
106: * <li>ServiceProvide</li>
107: * <li>operationMetadata</li>
108: * <li>the root dataset</li>
109: * </ul>
110: *
111: * @param wpvsCapabilities
112: * @return the WPVSCapabilitiesDocument of this wpvs
113: * @throws IOException
114: * if wpvsCapabilitiesDocument cannot be instantiated
115: */
116: public static WPVSCapabilitiesDocument export(
117: WPVSCapabilities wpvsCapabilities) throws IOException {
118: XMLFactory factory = new XMLFactory();
119: return factory.createCapabilitiesDocument(wpvsCapabilities);
120: }
121:
122: private WPVSCapabilitiesDocument createCapabilitiesDocument(
123: WPVSCapabilities wpvsCapabilities) throws IOException {
124: WPVSCapabilitiesDocument wpvsCapabilitiesDocument = new WPVSCapabilitiesDocument();
125: try {
126: wpvsCapabilitiesDocument.createEmptyDocument();
127: Element root = wpvsCapabilitiesDocument.getRootElement();
128:
129: ServiceIdentification serviceIdentification = wpvsCapabilities
130: .getServiceIdentification();
131: if (serviceIdentification != null) {
132: appendServiceIdentification(root, serviceIdentification);
133: }
134:
135: ServiceProvider serviceProvider = wpvsCapabilities
136: .getServiceProvider();
137: if (serviceProvider != null) {
138: appendServiceProvider(root, serviceProvider);
139: }
140:
141: OperationsMetadata operationMetadata = wpvsCapabilities
142: .getOperationsMetadata();
143: if (operationMetadata != null
144: && operationMetadata instanceof WPVSOperationsMetadata) {
145: appendWPVSOperationsMetadata(root,
146: (WPVSOperationsMetadata) operationMetadata);
147: }
148:
149: Dataset dataset = wpvsCapabilities.getDataset();
150: if (dataset != null) {
151: appendDataset(root, dataset);
152: }
153:
154: } catch (SAXException e) {
155: e.printStackTrace();
156: LOG.logError(e.getMessage(), e);
157: }
158:
159: return wpvsCapabilitiesDocument;
160: }
161:
162: /**
163: * Appends the DOM representation of an <code>WPVSOperationsMetadata</code> to the passed
164: * <code>Element</code>.
165: *
166: * @param root
167: * @param operationsMetadata
168: */
169: private void appendWPVSOperationsMetadata(Element root,
170: WPVSOperationsMetadata operationsMetadata) {
171: // 'ows:OperationsMetadata'-element
172: Element operationsMetadataNode = XMLTools.appendElement(root,
173: OWSNS, PRE_OWS + "OperationsMetadata");
174:
175: // append all Operations
176: Operation110[] operations = (Operation110[]) operationsMetadata
177: .getAllOperations();
178: for (int i = 0; i < operations.length; i++) {
179: Operation110 operation = operations[i];
180:
181: // 'ows:Operation' - element
182: Element operationElement = XMLTools.appendElement(
183: operationsMetadataNode, OWSNS, PRE_OWS
184: + "Operation");
185: operationElement.setAttribute("name", operation.getName());
186:
187: // 'ows:DCP' - elements
188: DCPType[] dcps = operation.getDCPs();
189: for (int j = 0; j < dcps.length; j++) {
190: appendDCPValue(operationElement, dcps[j]);
191: }
192:
193: // 'ows:Parameter' - elements
194: OWSDomainType110[] parameters = operation
195: .getParameters110();
196: for (int j = 0; j < parameters.length; j++) {
197: appendDomainType(operationElement, parameters[j],
198: PRE_OWS + "Parameter");
199: }
200:
201: // 'ows:Constraint' - elements
202: OWSDomainType110[] constraints = operation
203: .getConstraints110();
204: for (int j = 0; j < constraints.length; j++) {
205: appendDomainType(operationElement, constraints[j],
206: PRE_OWS + "Constraint");
207: }
208:
209: // 'ows:Metadata' - elements
210: OWSMetadata[] metadata = operation.getMetadata110();
211: for (int j = 0; j < metadata.length; j++) {
212: appendOWSMetadata(operationElement, metadata[j],
213: PRE_OWS + "Metadata");
214: }
215: }
216:
217: // append general parameters
218: OWSDomainType110[] parameters = operationsMetadata
219: .getParameters110();
220: for (int i = 0; i < parameters.length; i++) {
221: appendDomainType(operationsMetadataNode, parameters[i],
222: PRE_OWS + "Parameter");
223: }
224:
225: // append general constraints
226: OWSDomainType110[] constraints = operationsMetadata
227: .getConstraints110();
228: for (int i = 0; i < constraints.length; i++) {
229: appendDomainType(operationsMetadataNode, constraints[i],
230: PRE_OWS + "Constraint");
231: }
232:
233: // append 'ows:ExtendedCapabilities'
234: // TODO when needed.
235:
236: }
237:
238: /**
239: * Appends the DOM representation of an <code>OWSMetadata</code> to the passed
240: * <code>Element</code>. The given <code>String</code> is used to distinguish between the
241: * different Metadata types.
242: *
243: * @param element
244: * @param metadata
245: * @param tagName
246: */
247: private void appendOWSMetadata(Element element,
248: OWSMetadata metadata, String tagName) {
249:
250: if (metadata != null) {
251:
252: Element metadataElement = XMLTools.appendElement(element,
253: OWSNS, tagName);
254:
255: appendSimpleLinkAttributes(metadataElement, metadata
256: .getLink());
257:
258: Element nameElement = XMLTools.appendElement(
259: metadataElement, OWSNS, CommonNamespaces.OWS_PREFIX
260: + ":Name");
261: metadataElement.appendChild(nameElement);
262: nameElement.setNodeValue(metadata.getName());
263: }
264:
265: }
266:
267: /**
268: * Appends the DOM representation of an <code>OWSDomainType</code> to the passed
269: * <code>Element</code>. The given <code>String</code> is used to distinguish between
270: * <code>Parameter</code> and <code>Constraint</code>.
271: *
272: * @param element
273: * @param domainType
274: * @param tagName
275: */
276: private void appendDomainType(Element element,
277: OWSDomainType110 domainType, String tagName) {
278:
279: Element domainElement = XMLTools.appendElement(element, OWSNS,
280: tagName);
281:
282: // attribute
283: domainElement.setAttribute("name", domainType.getName());
284:
285: // elements
286: OWSAllowedValues allowedValues = domainType.getAllowedValues();
287: OWSMetadata valuesListReference = domainType
288: .getValuesListReference();
289: if (allowedValues != null) {
290: appendAllowedValues(domainElement, allowedValues);
291: }
292: // else if ( domainType.isAnyValue() ) {
293: // Element anyElement = XMLTools.appendElement( domainElement, OWSNS,
294: // CommonNamespaces.OWS_PREFIX+":AnyValue" );
295: // // TODO content of this tag!
296: // } else if ( domainType.hasNoValues() ) {
297: // Element noValuesElement = XMLTools.appendElement( domainElement, OWSNS,
298: // CommonNamespaces.OWS_PREFIX+":NoValues" );
299: // // TODO content of this tag!
300: // }
301: else if (valuesListReference != null) {
302: appendOWSMetadata(domainElement, valuesListReference,
303: CommonNamespaces.OWS_PREFIX
304: + ":ValuesListReference");
305: } else {
306: // TODO "domainType object is invalid!"
307: }
308:
309: appendTypedLiteral(domainElement, domainType.getDefaultValue(),
310: PRE_OWS + "DefaultValue", OWSNS);
311:
312: appendOWSMetadata(domainElement, domainType.getMeaning(),
313: PRE_OWS + "Meaning");
314:
315: appendOWSMetadata(domainElement, domainType.getOwsDataType(),
316: PRE_OWS + "DataType");
317:
318: String measurement = domainType.getMeasurementType();
319: if (OWSDomainType110.REFERENCE_SYSTEM.equals(measurement)) {
320: appendOWSMetadata(domainElement, domainType
321: .getMeasurement(), PRE_OWS + "ReferenceSystem");
322: } else if (OWSDomainType110.UOM.equals(measurement)) {
323: appendOWSMetadata(domainElement, domainType
324: .getMeasurement(), PRE_OWS + "UOM");
325: }
326:
327: OWSMetadata[] metadata = domainType.getMetadata();
328: for (int i = 0; i < metadata.length; i++) {
329: appendOWSMetadata(domainElement, metadata[i], PRE_OWS
330: + "Metadata");
331: }
332:
333: }
334:
335: /**
336: * Appends the DOM representation of an <code>OWSAllowedValues</code> object to the passed
337: * <code>Element</code>.
338: *
339: * @param element
340: * @param allowedValues
341: */
342: private void appendAllowedValues(Element element,
343: OWSAllowedValues allowedValues) {
344:
345: Element allowedElement = XMLTools.appendElement(element, OWSNS,
346: PRE_OWS + "AllowedValues");
347:
348: TypedLiteral[] literals = allowedValues.getOwsValues();
349: for (int i = 0; i < literals.length; i++) {
350: appendTypedLiteral(allowedElement, literals[i], PRE_OWS
351: + "Value", OWSNS);
352: }
353:
354: ValueRange[] range = allowedValues.getValueRanges();
355: for (int i = 0; i < range.length; i++) {
356: Element rangeElement = XMLTools.appendElement(
357: allowedElement, OWSNS, PRE_OWS + "Range");
358:
359: appendTypedLiteral(rangeElement, range[i].getMin(), PRE_OWS
360: + "MinimumValue", OWSNS);
361: appendTypedLiteral(rangeElement, range[i].getMax(), PRE_OWS
362: + "MaximumValue", OWSNS);
363: appendTypedLiteral(rangeElement, range[i].getSpacing(),
364: PRE_OWS + "Spacing", OWSNS);
365: }
366:
367: }
368:
369: /*
370: * (non-Javadoc)
371: *
372: * @see org.deegree.owscommon.XMLFactory#appendDCP(org.w3c.dom.Element,
373: * org.deegree.ogcwebservices.getcapabilities.DCPType)
374: */
375: private void appendDCPValue(Element operationElement, DCPType dcp) {
376:
377: // 'ows:DCP'-element
378: Element dcpNode = XMLTools.appendElement(operationElement,
379: OWSNS, PRE_OWS + "DCP");
380:
381: // currently, the only supported DCP are HTTP and HTTP110!
382: if (dcp.getProtocol() instanceof HTTP110) {
383: HTTP110 http = (HTTP110) dcp.getProtocol();
384:
385: // 'ows:HTTP'-element
386: Element httpNode = XMLTools.appendElement(dcpNode, OWSNS,
387: PRE_OWS + "HTTP");
388:
389: // 'ows:Get'-elements
390: OWSRequestMethod[] getRequest = http.getGetRequests();
391: for (int i = 0; i < getRequest.length; i++) {
392: appendRequest(httpNode, PRE_OWS + "Get", getRequest[i]);
393: }
394:
395: // 'ows:Post'-elements
396: OWSRequestMethod[] postRequest = http.getPostRequests();
397: for (int i = 0; i < postRequest.length; i++) {
398: appendRequest(httpNode, PRE_OWS + "Post",
399: postRequest[i]);
400: }
401: }
402:
403: }
404:
405: /**
406: * Appends the DOM representation of an <code>OWSRequestMethod</code> to the passed
407: * <code>Element</code>. The given <code>String</code> is used to distinguish between
408: * <code>ows:Get</code> and <code>ows:Post</code> requests.
409: *
410: * @param httpNode
411: * @param type
412: * @param request
413: */
414: private void appendRequest(Element httpNode, String type,
415: OWSRequestMethod request) {
416:
417: Element owsElement = XMLTools.appendElement(httpNode, OWSNS,
418: type);
419:
420: appendSimpleLinkAttributes(owsElement, request.getLink());
421:
422: OWSDomainType110[] constraint = request.getConstraints();
423: for (int i = 0; i < constraint.length; i++) {
424: appendDomainType(owsElement, constraint[i], PRE_OWS
425: + "Constraint");
426: }
427:
428: }
429:
430: /**
431: * Appends the DOM representation of a <code>Dataset</code> to the passed <code>Element</code>.
432: *
433: * @param root
434: * @param dataset
435: */
436: private void appendDataset(Element root, Dataset dataset) {
437:
438: // 'wpvs:Dataset'-element (parent)
439: Element datasetNode = XMLTools.appendElement(root, WPVSNS,
440: PRE_WPVS + "Dataset");
441:
442: // attributes
443: datasetNode.setAttribute("queryable",
444: ((dataset.getQueryable()) ? "1" : "0"));
445: datasetNode.setAttribute("opaque", ((dataset.getOpaque()) ? "1"
446: : "0"));
447: datasetNode.setAttribute("noSubsets",
448: ((dataset.getNoSubset()) ? "1" : "0"));
449: datasetNode.setAttribute("fixedWidth", String.valueOf(dataset
450: .getFixedWidth()));
451: datasetNode.setAttribute("fixedHeight", String.valueOf(dataset
452: .getFixedHeight()));
453:
454: // optional 'wpvs:Name'-element
455: appendName(datasetNode, dataset);
456:
457: // mandatory 'wpvs:Title'-element
458: appendTitle(datasetNode, dataset);
459:
460: // optional 'wpvs:Abstract'-element
461: appendAbstract(datasetNode, dataset);
462:
463: // optional 'ows:Keywords'-elements
464: appendOWSKeywords(datasetNode, dataset.getKeywords());
465:
466: // optional 'wpvs:CRS'-elements
467: appendCRSNodes(datasetNode, dataset.getCrs());
468:
469: // optional 'wpvs:Format'-elements
470: appendFormats(datasetNode, dataset.getMimeTypeFormat());
471:
472: // mandatory 'ows:WGS84BoundingBox
473: appendBoundingBox(datasetNode, dataset.getWgs84BoundingBox(),
474: PRE_OWS + "WGS84BoundingBox",
475: "urn:ogc:def:crs:OGC:2:84", "2");
476:
477: // optional 'ows:BoundingBox'-elements
478: Envelope[] boundingBoxes = dataset.getBoundingBoxes();
479:
480: for (int i = 0; i < boundingBoxes.length; i++) {
481:
482: if (boundingBoxes[i] != null) {
483: String crsName = boundingBoxes[i].getCoordinateSystem()
484: .getIdentifier();
485:
486: appendBoundingBox(datasetNode, boundingBoxes[i],
487: PRE_OWS + "BoundingBox", crsName, "2");
488: }
489: }
490:
491: // optional 'wpvs:Dimension'-elements
492: appendDimensions(datasetNode, dataset.getDimensions());
493:
494: // optional 'wpvs:DataProvider'-element
495: appendDataProvider(datasetNode, dataset.getDataProvider());
496:
497: // mandatory 'wpvs:Identifier'-element
498: appendIdentifier(datasetNode, dataset.getIdentifier());
499:
500: // 'wpvs:MetaData'-elements
501: appendURLs(datasetNode, dataset.getMetadata(), WPVSNS, PRE_WPVS
502: + "MetaData");
503:
504: // 'wpvs:DatasetReference'-elements
505: appendURLs(datasetNode, dataset.getDatasetReferences(), WPVSNS,
506: PRE_WPVS + "DatasetReference");
507:
508: // 'wpvs:FeatureListReference'-elements
509: appendURLs(datasetNode, dataset.getFeatureListReferences(),
510: WPVSNS, PRE_WPVS + "FeatureListReference");
511:
512: // 'wpvs:Style'-elements
513: appendStyles(datasetNode, dataset.getStyles());
514:
515: // 'wpvs:MinimumScaleDenominator'-element
516: appendScaleDenominator(datasetNode, dataset
517: .getMinimumScaleDenominator(), "MIN");
518:
519: // 'wpvs:MaximumScaleDenominator'-element
520: appendScaleDenominator(datasetNode, dataset
521: .getMaximumScaleDenominator(), "MAX");
522:
523: // 'wpvs:Dataset'-elements (children)
524: Dataset[] datasets = dataset.getDatasets();
525: for (int i = 0; i < datasets.length; i++) {
526: appendDataset(datasetNode, datasets[i]);
527: }
528:
529: // 'ElevationModel'-element (the simple ogc-ElevationModel)
530: String emName = dataset.getElevationModel().getName();
531: if (emName != null) {
532: appendElevationModel(datasetNode, emName);
533: }
534: }
535:
536: /**
537: * Appends the DOM representation of an OGC <code>ElevationModel</code> to the passed
538: * <code>Element</code>.
539: *
540: * @param datasetNode
541: * @param elevationModelName
542: */
543: private void appendElevationModel(Element datasetNode,
544: String elevationModelName) {
545:
546: Element elevation = XMLTools.appendElement(datasetNode, WPVSNS,
547: PRE_WPVS + "ElevationModel");
548: Text elevationText = elevation.getOwnerDocument()
549: .createTextNode(elevationModelName);
550: elevation.appendChild(elevationText);
551:
552: elevation.appendChild(elevationText);
553:
554: }
555:
556: /**
557: * Appends the DOM representations of the given <code>ScaleDenominator</code> to the passed
558: * <code>Element</code>. The given <code>String</code> is used to distinguish between
559: * MinimumsScaleDenominator and MaximumScaleDenominator.
560: *
561: * @param datasetNode
562: * @param scaleDenominator
563: * @param extremum
564: * must be either 'MIN' or 'MAX'.
565: */
566: private void appendScaleDenominator(Element datasetNode,
567: double scaleDenominator, String extremum) {
568: Element scaleElement = null;
569:
570: if ("MIN".equalsIgnoreCase(extremum)) {
571: scaleElement = XMLTools.appendElement(datasetNode, WPVSNS,
572: PRE_WPVS + "MinimumScaleDenominator");
573: } else if ("MAX".equalsIgnoreCase(extremum)) {
574: scaleElement = XMLTools.appendElement(datasetNode, WPVSNS,
575: PRE_WPVS + "MaximumScaleDenominator");
576: } else {
577: throw new IllegalArgumentException(
578: "The extremum must be either 'MIN' or 'MAX'.");
579: }
580:
581: String value = String.valueOf(scaleDenominator);
582: Text scaleText = scaleElement.getOwnerDocument()
583: .createTextNode(value);
584: scaleElement.appendChild(scaleText);
585:
586: }
587:
588: /**
589: * Appends the DOM representations of the <code>Abstract</code> Element from the given
590: * <code>Object</code> to the passed <code>Element</code>.
591: *
592: * @param root
593: * @param obj
594: * may be of the following types: Style, Dataset.
595: */
596: private void appendAbstract(Element root, Object obj) {
597:
598: String abstractString = null;
599: if (obj instanceof Style) {
600: abstractString = ((Style) obj).getAbstract();
601: } else if (obj instanceof Dataset) {
602: abstractString = ((Dataset) obj).getAbstract();
603: }
604: if (abstractString != null) {
605: Element abstractElement = XMLTools.appendElement(root,
606: WPVSNS, PRE_WPVS + "Abstract");
607: Text abstractText = abstractElement.getOwnerDocument()
608: .createTextNode(abstractString);
609: abstractElement.appendChild(abstractText);
610: }
611:
612: }
613:
614: /**
615: * Appends the DOM representations of the <code>Title</code> Element from the given
616: * <code>Object</code> to the passed <code>Element</code>.
617: *
618: * @param root
619: * @param obj
620: * may be of the following types: Style, Dataset.
621: */
622: private void appendTitle(Element root, Object obj) {
623:
624: String title = null;
625: if (obj instanceof Style) {
626: title = ((Style) obj).getTitle();
627: } else if (obj instanceof Dataset) {
628: title = ((Dataset) obj).getTitle();
629: }
630: Element titleElement = XMLTools.appendElement(root, WPVSNS,
631: PRE_WPVS + "Title");
632: Text titleText = titleElement.getOwnerDocument()
633: .createTextNode(title);
634: titleElement.appendChild(titleText);
635: }
636:
637: /**
638: * Appends the DOM representations of the <code>Name</code> Element from the given
639: * <code>Object</code> to the passed <code>Element</code>.
640: *
641: * @param root
642: * @param obj
643: * may be of the following types: Style, Dataset.
644: */
645: private void appendName(Element root, Object obj) {
646:
647: String name = null;
648: if (obj instanceof Style) {
649: name = ((Style) obj).getName();
650: } else if (obj instanceof Dataset) {
651: name = ((Dataset) obj).getName();
652: }
653:
654: if (name != null) {
655: Element nameElement = XMLTools.appendElement(root, WPVSNS,
656: PRE_WPVS + "Name");
657: Text nameText = nameElement.getOwnerDocument()
658: .createTextNode(name);
659: nameElement.appendChild(nameText);
660: }
661:
662: }
663:
664: /**
665: * Appends the DOM representations of the given array of <code>Style</code> to the passed
666: * <code>Element</code>.
667: *
668: * @param datasetNode
669: * @param styles
670: */
671: private void appendStyles(Element datasetNode, Style[] styles) {
672:
673: if (styles != null) {
674: for (int i = 0; i < styles.length; i++) {
675:
676: Element styleElement = XMLTools.appendElement(
677: datasetNode, WPVSNS, PRE_WPVS + "Style");
678:
679: appendName(styleElement, styles[i]);
680: appendTitle(styleElement, styles[i]);
681: appendAbstract(styleElement, styles[i]);
682:
683: appendOWSKeywords(styleElement, styles[i].getKeywords());
684:
685: if (styles[i].getIdentifier() != null) {
686: appendIdentifier(styleElement, styles[i]
687: .getIdentifier());
688: }
689:
690: appendURLs(styleElement, styles[i].getLegendURLs(),
691: WPVSNS, PRE_WPVS + "LegendURL");
692:
693: Element styleSheetURLElement = XMLTools.appendElement(
694: styleElement, WPVSNS, PRE_WPVS
695: + "StyleSheetURL");
696: appendURL(styleSheetURLElement, styles[i]
697: .getStyleSheetURL(), WPVSNS);
698:
699: Element styleURLElement = XMLTools.appendElement(
700: styleElement, WPVSNS, PRE_WPVS + "StyleURL");
701: appendURL(styleURLElement, styles[i].getStyleURL(),
702: WPVSNS);
703:
704: }
705: }
706: }
707:
708: /**
709: * Appends the DOM representations of the given array of <code>BaseURL</code> under the given
710: * name to the passed <code>Element</code>.
711: *
712: * @param root
713: * @param baseURL
714: * @param uri
715: * @param newNode
716: */
717: private void appendURLs(Element root, BaseURL[] baseURL, URI uri,
718: String newNode) {
719: if (baseURL != null) {
720: for (int i = 0; i < baseURL.length; i++) {
721: Element urlElement = XMLTools.appendElement(root, uri,
722: newNode);
723: appendURL(urlElement, baseURL[i], uri);
724: }
725: }
726: }
727:
728: /**
729: * Appends the contents of the given <code>BaseURL</code> within the given <code>URI</code>
730: * as DOM representation to the passed URL <code>Element</code>.
731: *
732: * @param urlElement
733: * example: logoURLElement
734: * @param baseURL
735: * example: dataProvider.getLogoURL()
736: * @param uri
737: * example: "WPVSNS"
738: */
739: private void appendURL(Element urlElement, BaseURL baseURL, URI uri) {
740:
741: // child elements of urlElement
742: Element formatElement = XMLTools.appendElement(urlElement, uri,
743: PRE_WPVS + "Format");
744: String format = baseURL != null ? baseURL.getFormat() : "";
745: Text formatText = formatElement.getOwnerDocument()
746: .createTextNode(format);
747: formatElement.appendChild(formatText);
748:
749: Element onlineElement = XMLTools.appendElement(urlElement, uri,
750: PRE_WPVS + "OnlineResource");
751: String url = (baseURL != null && baseURL.getOnlineResource() != null) ? baseURL
752: .getOnlineResource().toString()
753: : "";
754: onlineElement.setAttribute("xlink:href", url);
755:
756: // attributes of urlElement
757: if (baseURL instanceof ImageURL) {
758: String width = String.valueOf(((ImageURL) baseURL)
759: .getWidth());
760: String height = String.valueOf(((ImageURL) baseURL)
761: .getHeight());
762: urlElement.setAttribute("width", width);
763: urlElement.setAttribute("height", height);
764:
765: } else if (baseURL instanceof MetaData) {
766:
767: urlElement.setAttribute("type", ((MetaData) baseURL)
768: .getType());
769: }
770:
771: }
772:
773: /**
774: * Appends the DOM representation of the given <code>Identifier</code> to the passed
775: * <code>Element</code>.
776: *
777: * @param root
778: * @param identifier
779: */
780: private void appendIdentifier(Element root, Identifier identifier) {
781:
782: Element idElement = XMLTools.appendElement(root, WPVSNS,
783: PRE_WPVS + "Identifier");
784:
785: if (identifier.getCodeSpace() != null) {
786: idElement.setAttribute("codeSpace", identifier
787: .getCodeSpace().toASCIIString());
788: }
789:
790: Text idText = idElement.getOwnerDocument().createTextNode(
791: identifier.getValue());
792: idElement.appendChild(idText);
793:
794: }
795:
796: /**
797: * Appends the DOM representation of the given <code>DataProvider</code> to the passed
798: * <code>Element</code>.
799: *
800: * @param datasetNode
801: * @param dataProvider
802: */
803: private void appendDataProvider(Element datasetNode,
804: DataProvider dataProvider) {
805: if (dataProvider != null) {
806: Element provider = XMLTools.appendElement(datasetNode,
807: WPVSNS, PRE_WPVS + "DataProvider");
808:
809: String provName = dataProvider.getProviderName();
810: if (provName != null) {
811: Element providerName = XMLTools.appendElement(provider,
812: WPVSNS, PRE_WPVS + "ProviderName");
813: Text providerNameText = providerName.getOwnerDocument()
814: .createTextNode(provName);
815: providerName.appendChild(providerNameText);
816:
817: }
818:
819: Element providerSite = XMLTools.appendElement(provider,
820: WPVSNS, PRE_WPVS + "ProviderSite");
821: URL siteURL = dataProvider.getProviderSite();
822: String site = "";
823: if (siteURL != null) {
824: site = siteURL.toString();
825: }
826: providerSite.setAttribute("xlink:href", site);
827:
828: Element logoURLElement = XMLTools.appendElement(provider,
829: WPVSNS, PRE_WPVS + "LogoURL");
830: appendURL(logoURLElement, dataProvider.getLogoURL(), WPVSNS);
831: }
832: }
833:
834: /**
835: * Appends the DOM representations of the given array of <code>Dimension</code> to the passed
836: * <code>Element</code>.
837: *
838: * @param datasetNode
839: * @param dimensions
840: */
841: private void appendDimensions(Element datasetNode,
842: Dimension[] dimensions) {
843: if (dimensions != null) {
844: for (Dimension dimension : dimensions) {
845: if (dimension != null) {
846: Element dimensionElement = XMLTools
847: .appendElement(datasetNode, WPVSNS,
848: PRE_WPVS + "Dimension");
849: dimensionElement.setAttribute("name", dimension
850: .getName());
851: dimensionElement.setAttribute("units", dimension
852: .getUnits());
853: dimensionElement.setAttribute("unitSymbol",
854: dimension.getUnitSymbol());
855: dimensionElement.setAttribute("default", dimension
856: .getDefault());
857: dimensionElement.setAttribute("multipleValues",
858: ((dimension.getMultipleValues()
859: .booleanValue()) ? "1" : "0"));
860: dimensionElement.setAttribute("nearestValue",
861: ((dimension.getNearestValue()
862: .booleanValue()) ? "1" : "0"));
863: dimensionElement
864: .setAttribute("current", ((dimension
865: .getCurrent().booleanValue()) ? "1"
866: : "0"));
867:
868: Text dimensionText = dimensionElement
869: .getOwnerDocument().createTextNode(
870: dimension.getValue());
871: dimensionElement.appendChild(dimensionText);
872: }
873: }
874: }
875: }
876:
877: /**
878: * Appends the DOM representations of the given array of <code>Format</code> to the passed
879: * <code>Element</code>.
880: *
881: * @param datasetNode
882: * @param mimeTypeFormat
883: */
884: private void appendFormats(Element datasetNode,
885: String[] mimeTypeFormat) {
886:
887: if (mimeTypeFormat != null) {
888:
889: for (int i = 0; i < mimeTypeFormat.length; i++) {
890: Element format = XMLTools.appendElement(datasetNode,
891: WPVSNS, PRE_WPVS + "Format");
892: Text formatText = format.getOwnerDocument()
893: .createTextNode(mimeTypeFormat[i]);
894: format.appendChild(formatText);
895: }
896: }
897: }
898:
899: /**
900: * Appends the DOM representations of the given array of <code>CRS</code> to the passed
901: * <code>Element</code>.
902: *
903: * @param datasetNode
904: * @param coordinateSystems
905: */
906: private void appendCRSNodes(Element datasetNode,
907: CoordinateSystem[] coordinateSystems) {
908:
909: if (coordinateSystems != null) {
910: for (CoordinateSystem crs : coordinateSystems) {
911: Element crsElement = XMLTools.appendElement(
912: datasetNode, WPVSNS, PRE_WPVS + "CRS");
913: Text crsText = crsElement.getOwnerDocument()
914: .createTextNode(crs.getFormattedString());
915: crsElement.appendChild(crsText);
916: }
917: }
918: }
919:
920: /**
921: * Appends the DOM representation of the given parameters <code>Envelope, elementName, crsName,
922: * dimension</code>
923: * to the passed <code>Element</code>.
924: *
925: * elementName should be of the kind ows:WGS84BoundingBox" or "ows:BoundingBox". crsName should
926: * be of the kind "urn:ogc:def:crs:OGC:2:84" or "...TODO...". dimension should be "2".
927: *
928: * @param root
929: * @param envelope
930: * @param elementName
931: * @param crsName
932: * @param dimension
933: */
934: private void appendBoundingBox(Element root, Envelope envelope,
935: String elementName, String crsName, String dimension) {
936:
937: Element boundingBoxElement = XMLTools.appendElement(root,
938: OWSNS, elementName);
939: boundingBoxElement.setAttribute("crs", crsName);
940: boundingBoxElement.setAttribute("dimensions", dimension);
941:
942: Element lowerCornerElement = XMLTools.appendElement(
943: boundingBoxElement, OWSNS, PRE_OWS + "LowerCorner");
944: Text lowerCornerText = lowerCornerElement.getOwnerDocument()
945: .createTextNode(
946: envelope.getMin().getX() + " "
947: + envelope.getMin().getY());
948: lowerCornerElement.appendChild(lowerCornerText);
949:
950: Element upperCornerElement = XMLTools.appendElement(
951: boundingBoxElement, OWSNS, PRE_OWS + "UpperCorner");
952: Text upperCornerText = upperCornerElement.getOwnerDocument()
953: .createTextNode(
954: envelope.getMax().getX() + " "
955: + envelope.getMax().getY());
956: upperCornerElement.appendChild(upperCornerText);
957:
958: }
959:
960: }
|