0001: // $HeadURL: https://svn.wald.intevation.org/svn/deegree/base/trunk/src/org/deegree/ogcwebservices/wmps/capabilities/WMPSCapabilitiesDocument.java $
0002: /*---------------- FILE HEADER ------------------------------------------
0003:
0004: This file is part of deegree.
0005: Copyright (C) 2001-2008 by:
0006: EXSE, Department of Geography, University of Bonn
0007: http://www.giub.uni-bonn.de/deegree/
0008: lat/lon GmbH
0009: http://www.lat-lon.de
0010:
0011: This library is free software; you can redistribute it and/or
0012: modify it under the terms of the GNU Lesser General Public
0013: License as published by the Free Software Foundation; either
0014: version 2.1 of the License, or (at your option) any later version.
0015:
0016: This library is distributed in the hope that it will be useful,
0017: but WITHOUT ANY WARRANTY; without even the implied warranty of
0018: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0019: Lesser General Public License for more details.
0020:
0021: You should have received a copy of the GNU Lesser General Public
0022: License along with this library; if not, write to the Free Software
0023: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0024:
0025: Contact:
0026:
0027: Andreas Poth
0028: lat/lon GmbH
0029: Aennchenstr. 19
0030: 53115 Bonn
0031: Germany
0032: E-Mail: poth@lat-lon.de
0033:
0034: Prof. Dr. Klaus Greve
0035: Department of Geography
0036: University of Bonn
0037: Meckenheimer Allee 166
0038: 53115 Bonn
0039: Germany
0040: E-Mail: greve@giub.uni-bonn.de
0041:
0042: ---------------------------------------------------------------------------*/
0043: package org.deegree.ogcwebservices.wmps.capabilities;
0044:
0045: import java.io.IOException;
0046: import java.net.MalformedURLException;
0047: import java.net.URI;
0048: import java.net.URISyntaxException;
0049: import java.net.URL;
0050: import java.util.List;
0051:
0052: import org.deegree.datatypes.Code;
0053: import org.deegree.datatypes.xlink.SimpleLink;
0054: import org.deegree.framework.log.ILogger;
0055: import org.deegree.framework.log.LoggerFactory;
0056: import org.deegree.framework.util.StringTools;
0057: import org.deegree.framework.xml.XMLParsingException;
0058: import org.deegree.framework.xml.XMLTools;
0059: import org.deegree.model.crs.CRSFactory;
0060: import org.deegree.model.crs.CoordinateSystem;
0061: import org.deegree.model.crs.UnknownCRSException;
0062: import org.deegree.model.metadata.iso19115.Address;
0063: import org.deegree.model.metadata.iso19115.ContactInfo;
0064: import org.deegree.model.metadata.iso19115.Keywords;
0065: import org.deegree.model.metadata.iso19115.OnlineResource;
0066: import org.deegree.model.metadata.iso19115.Phone;
0067: import org.deegree.model.spatialschema.Envelope;
0068: import org.deegree.model.spatialschema.GeometryFactory;
0069: import org.deegree.model.spatialschema.Position;
0070: import org.deegree.ogcbase.CommonNamespaces;
0071: import org.deegree.ogcwebservices.getcapabilities.DCPType;
0072: import org.deegree.ogcwebservices.getcapabilities.HTTP;
0073: import org.deegree.ogcwebservices.getcapabilities.InvalidCapabilitiesException;
0074: import org.deegree.ogcwebservices.getcapabilities.MetadataURL;
0075: import org.deegree.ogcwebservices.getcapabilities.OGCCapabilities;
0076: import org.deegree.ogcwebservices.getcapabilities.Operation;
0077: import org.deegree.ogcwebservices.getcapabilities.OperationsMetadata;
0078: import org.deegree.ogcwebservices.getcapabilities.Protocol;
0079: import org.deegree.ogcwebservices.getcapabilities.ServiceIdentification;
0080: import org.deegree.ogcwebservices.getcapabilities.ServiceProvider;
0081: import org.deegree.ogcwebservices.wms.capabilities.Attribution;
0082: import org.deegree.ogcwebservices.wms.capabilities.AuthorityURL;
0083: import org.deegree.ogcwebservices.wms.capabilities.DataURL;
0084: import org.deegree.ogcwebservices.wms.capabilities.Dimension;
0085: import org.deegree.ogcwebservices.wms.capabilities.Extent;
0086: import org.deegree.ogcwebservices.wms.capabilities.FeatureListURL;
0087: import org.deegree.ogcwebservices.wms.capabilities.Identifier;
0088: import org.deegree.ogcwebservices.wms.capabilities.Layer;
0089: import org.deegree.ogcwebservices.wms.capabilities.LayerBoundingBox;
0090: import org.deegree.ogcwebservices.wms.capabilities.LegendURL;
0091: import org.deegree.ogcwebservices.wms.capabilities.LogoURL;
0092: import org.deegree.ogcwebservices.wms.capabilities.ScaleHint;
0093: import org.deegree.ogcwebservices.wms.capabilities.Style;
0094: import org.deegree.ogcwebservices.wms.capabilities.StyleSheetURL;
0095: import org.deegree.ogcwebservices.wms.capabilities.StyleURL;
0096: import org.deegree.ogcwebservices.wms.capabilities.UserDefinedSymbolization;
0097: import org.deegree.owscommon.OWSCommonCapabilitiesDocument;
0098: import org.deegree.owscommon.OWSDomainType;
0099: import org.w3c.dom.Element;
0100: import org.w3c.dom.Node;
0101: import org.xml.sax.SAXException;
0102:
0103: /**
0104: * Represents an XML capabilities document for an OGC WFS 1.1.0 compliant web service.
0105: *
0106: * @author <a href="mailto:deshmukh@lat-lon.de">Anup Deshmukh </a>
0107: *
0108: * @version 2.0
0109: */
0110: public class WMPSCapabilitiesDocument extends
0111: OWSCommonCapabilitiesDocument {
0112:
0113: private static final long serialVersionUID = -9098679671644329509L;
0114:
0115: private static final ILogger LOG = LoggerFactory
0116: .getLogger(WMPSCapabilitiesDocument.class);
0117:
0118: protected static final URI WMPSNS = CommonNamespaces.WMPSNS;
0119:
0120: private static final String XML_TEMPLATE = "WMPSCapabilitiesTemplate.xml";
0121:
0122: /**
0123: * Creates a skeleton capabilities document that contains the mandatory elements only.
0124: *
0125: * @throws IOException
0126: * @throws SAXException
0127: */
0128: public void createEmptyDocument() throws IOException, SAXException {
0129: URL url = WMPSCapabilitiesDocument.class
0130: .getResource(XML_TEMPLATE);
0131: if (url == null) {
0132: throw new IOException("The resource '" + XML_TEMPLATE
0133: + " could not be found.");
0134: }
0135: load(url);
0136: }
0137:
0138: /**
0139: * Creates a class representation of the document.
0140: *
0141: * @return OGCCapabilities class representation of the configuration document
0142: * @throws InvalidCapabilitiesException
0143: */
0144: @Override
0145: public OGCCapabilities parseCapabilities()
0146: throws InvalidCapabilitiesException {
0147:
0148: LOG.logDebug("Parsing Capabilties Request.");
0149: ServiceIdentification serviceIdentification = null;
0150: ServiceProvider serviceProvider = null;
0151: UserDefinedSymbolization uds = null;
0152: OperationsMetadata metadata = null;
0153: Layer layer = null;
0154: String version = parseVersion();
0155: try {
0156: serviceIdentification = parseServiceIdentification();
0157: serviceProvider = parseServiceProvider();
0158: LOG
0159: .logDebug("Retrieved serviceIdentification and serviceProvider information "
0160: + "from the request.");
0161: metadata = parseOperationsMetadata();
0162: LOG
0163: .logDebug("Retrieved metadData information from the request.");
0164: uds = parseUserDefinedSymbolization();
0165: Element layerElem = (Element) XMLTools.getRequiredNode(
0166: getRootElement(), "./Capability/Layer", nsContext);
0167: LOG.logDebug("Layer Element retrieved.");
0168: layer = parseLayers(layerElem, null);
0169: } catch (XMLParsingException e) {
0170: String msg = "Error parsing the capabilities request to retrieve 'serviceIdentification',"
0171: + " 'serviceProvider', 'metaData' and 'layer' "
0172: + e.getMessage();
0173: throw new InvalidCapabilitiesException(msg);
0174: } catch (UnknownCRSException e) {
0175: throw new InvalidCapabilitiesException(
0176: getClass().getName(), e.getMessage());
0177: }
0178: WMPSCapabilities wmpsCapabilities = new WMPSCapabilities(
0179: version, serviceIdentification, serviceProvider, uds,
0180: metadata, layer);
0181:
0182: return wmpsCapabilities;
0183: }
0184:
0185: /**
0186: * Parse the UserDefinedSymbolization
0187: *
0188: * @return UserDefinedSymbolization
0189: * @throws XMLParsingException
0190: */
0191: protected UserDefinedSymbolization parseUserDefinedSymbolization()
0192: throws XMLParsingException {
0193:
0194: String xPath = "./Capability/UserDefinedSymbolization/@SupportSLD";
0195: boolean supportSLD = XMLTools.getNodeAsBoolean(
0196: getRootElement(), xPath, nsContext, false);
0197:
0198: xPath = "./Capability/UserDefinedSymbolization/@UserLayer";
0199: boolean userLayer = XMLTools.getNodeAsBoolean(getRootElement(),
0200: xPath, nsContext, false);
0201:
0202: xPath = "./Capability/UserDefinedSymbolization/@UserStyle";
0203: boolean userStyle = XMLTools.getNodeAsBoolean(getRootElement(),
0204: xPath, nsContext, false);
0205:
0206: xPath = "./Capability/UserDefinedSymbolization/@RemoteWFS";
0207: boolean remoteWFS = XMLTools.getNodeAsBoolean(getRootElement(),
0208: xPath, nsContext, false);
0209:
0210: UserDefinedSymbolization uds = new UserDefinedSymbolization(
0211: supportSLD, userLayer, remoteWFS, userStyle);
0212:
0213: return uds;
0214: }
0215:
0216: /**
0217: * returns the services indentification read from the WMPS capabilities service section
0218: *
0219: * @return ServiceIdentification
0220: * @throws XMLParsingException
0221: */
0222: protected ServiceIdentification parseServiceIdentification()
0223: throws XMLParsingException {
0224:
0225: LOG.logDebug("Parsing service identification parameter.");
0226: String name = XMLTools.getNodeAsString(getRootElement(),
0227: "./Service/Name", nsContext, null);
0228: String title = XMLTools.getNodeAsString(getRootElement(),
0229: "./Service/Title", nsContext, name);
0230: String serviceAbstract = XMLTools
0231: .getNodeAsString(getRootElement(),
0232: "./Service/Abstract", nsContext, null);
0233:
0234: String[] kw = XMLTools.getNodesAsStrings(getRootElement(),
0235: "./Service/KeywordList/Keyword", nsContext);
0236:
0237: Keywords[] keywords = new Keywords[] { new Keywords(kw) };
0238:
0239: String fees = XMLTools.getNodeAsString(getRootElement(),
0240: "./Service/Fees", nsContext, null);
0241:
0242: String[] accessConstraints = XMLTools.getNodesAsStrings(
0243: getRootElement(), "./Service/AccessConstraints",
0244: nsContext);
0245:
0246: String[] acceptedVersion = new String[] { "1.0.0" };
0247: Code code = new Code("WMPS");
0248: ServiceIdentification serviceIdentification = new ServiceIdentification(
0249: code, acceptedVersion, title, serviceAbstract,
0250: keywords, fees, accessConstraints);
0251:
0252: return serviceIdentification;
0253: }
0254:
0255: /**
0256: * returns WMPS contact informaion encapsulated within a <code>ServiceProvider</code> object
0257: *
0258: * @return ServiceProvider
0259: * @throws XMLParsingException
0260: */
0261: protected ServiceProvider parseServiceProvider()
0262: throws XMLParsingException {
0263:
0264: SimpleLink sLink = retrieveOnlineResourceSimpleLink();
0265:
0266: LOG.logDebug("Parsing service provider parameter.");
0267: /**
0268: * according to WMPS (draft) specification this element is mandatory but there are several
0269: * services online which does not contain this element in its capabilities
0270: */
0271: Node contactInfo = XMLTools.getRequiredNode(getRootElement(),
0272: "./Service/ContactInformation", nsContext);
0273:
0274: String person = XMLTools.getRequiredNodeAsString(contactInfo,
0275: "./ContactPersonPrimary/ContactPerson", nsContext);
0276: String orga = XMLTools
0277: .getRequiredNodeAsString(contactInfo,
0278: "./ContactPersonPrimary/ContactOrganization",
0279: nsContext);
0280: String position = XMLTools.getRequiredNodeAsString(contactInfo,
0281: "./ContactPosition", nsContext);
0282: ContactInfo contact = parseContactInfo();
0283:
0284: ServiceProvider sp = new ServiceProvider(orga, sLink, person,
0285: position, contact, null);
0286:
0287: return sp;
0288: }
0289:
0290: /**
0291: * Returns the SimpleLink from the Online Resource node in the Service element.
0292: *
0293: * @return SimpleLink
0294: * @throws XMLParsingException
0295: */
0296: private SimpleLink retrieveOnlineResourceSimpleLink()
0297: throws XMLParsingException {
0298:
0299: String simpleLink = XMLTools
0300: .getNodeAsString(getRootElement(),
0301: "./Service/OnlineResource/@xlink:href",
0302: nsContext, null);
0303: SimpleLink sLink = null;
0304: if (simpleLink != null) {
0305: try {
0306: sLink = new SimpleLink(new URI(simpleLink));
0307: } catch (URISyntaxException e) {
0308: throw new XMLParsingException(
0309: "Error parsing service online resource", e);
0310: }
0311: } else {
0312: try {
0313: /**
0314: * use default if no online resource is contained in the capabilities (see comment
0315: * above)
0316: */
0317: sLink = new SimpleLink(new URI(
0318: "http://www.opengeospatial.org/"));
0319: } catch (URISyntaxException neverHappens) {
0320: neverHappens.printStackTrace();
0321: }
0322: }
0323:
0324: return sLink;
0325: }
0326:
0327: /**
0328: * Parse Contact Information
0329: *
0330: * @return ContactInfo
0331: * @throws XMLParsingException
0332: */
0333: protected ContactInfo parseContactInfo() throws XMLParsingException {
0334:
0335: LOG.logDebug("Parsing contact information parameter.");
0336: Node contactInfo = XMLTools.getNode(getRootElement(),
0337: "./Service/ContactInformation", nsContext);
0338: String[] addr = XMLTools.getNodesAsStrings(contactInfo,
0339: "./ContactAddress/Address", nsContext);
0340: // String addrType = XMLTools.getNodeAsString( contactInfo, "./ContactAddress/AddressType",
0341: // nsContext, null );
0342: String city = XMLTools.getNodeAsString(contactInfo,
0343: "./ContactAddress/City", nsContext, null);
0344: String state = XMLTools.getNodeAsString(contactInfo,
0345: "./ContactAddress/StateOrProvince", nsContext, null);
0346: String pc = XMLTools.getNodeAsString(contactInfo,
0347: "./ContactAddress/PostCode", nsContext, null);
0348: String country = XMLTools.getNodeAsString(contactInfo,
0349: "./ContactAddress/Country", nsContext, null);
0350: String[] mail = XMLTools.getNodesAsStrings(contactInfo,
0351: "./ContactElectronicMailAddress", nsContext);
0352: Address address = new Address(state, city, country, addr, mail,
0353: pc);
0354:
0355: String[] phone = XMLTools.getNodesAsStrings(contactInfo,
0356: "./ContactVoiceTelephone", nsContext);
0357: String[] fax = XMLTools.getNodesAsStrings(contactInfo,
0358: "./ContactFacsimileTelephone", nsContext);
0359:
0360: Phone ph = new Phone(fax, phone);
0361:
0362: ContactInfo cont = new ContactInfo(address, null, null, null,
0363: ph);
0364:
0365: return cont;
0366: }
0367:
0368: /**
0369: * returns the services capabilitiy read from the WMPS capabilities file
0370: *
0371: * @return OperationsMetadata
0372: * @throws XMLParsingException
0373: */
0374: protected OperationsMetadata parseOperationsMetadata()
0375: throws XMLParsingException {
0376:
0377: LOG.logDebug("Parsing operations metdata parameter.");
0378: Node opNode = XMLTools.getNode(getRootElement(),
0379: "./Capability/Request/GetCapabilities", nsContext);
0380:
0381: Operation getCapabilities = parseOperation(opNode);
0382: LOG
0383: .logDebug("Operation getCapabilities created for the GetCapabilities node.");
0384:
0385: opNode = XMLTools.getRequiredNode(getRootElement(),
0386: "./Capability/Request/PrintMap", nsContext);
0387:
0388: Operation printMap = parseOperation(opNode);
0389:
0390: LOG
0391: .logDebug("Operation printMap created for the PrintMap node.");
0392:
0393: WMPSOperationsMetadata metadata = new WMPSOperationsMetadata(
0394: getCapabilities, printMap);
0395:
0396: return metadata;
0397: }
0398:
0399: /**
0400: * Creates an <tt>Operation</tt>-instance according to the contents of the DOM-subtree
0401: * starting at the given <tt>Node</tt>.
0402: * <p>
0403: * Notice: operation to be parsed must be operations in sense of WMPS (draft). The method will
0404: * return an OWSCommon Operation which encapsulates parsed WMPS operation
0405: * <p>
0406: *
0407: * @param node
0408: * the <tt>Element</tt> that describes an <tt>Operation</tt>
0409: * @throws XMLParsingException
0410: * if a syntactic or semantic error in the DOM-subtree is encountered
0411: * @return the constructed <tt>Operation</tt>-instance
0412: */
0413: protected Operation parseOperation(Node node)
0414: throws XMLParsingException {
0415:
0416: LOG.logDebug("Parsing Operation.");
0417: // use node name as name of the Operation to be defined
0418: String name = node.getNodeName();
0419: String[] tmp = XMLTools.getRequiredNodesAsStrings(node,
0420: "./Format", nsContext);
0421: OWSDomainType owsDomainType = new OWSDomainType("Format", tmp,
0422: null);
0423: OWSDomainType[] odt = new OWSDomainType[] { owsDomainType };
0424:
0425: List nl = XMLTools.getRequiredNodes(node, "./DCPType",
0426: nsContext);
0427: DCPType[] dcpTypes = new DCPType[nl.size()];
0428: for (int i = 0; i < dcpTypes.length; i++) {
0429: dcpTypes[i] = getDCP((Element) nl.get(i));
0430: }
0431: LOG
0432: .logDebug("Creating operation with name, dcpTypes and OWSDomainType.");
0433:
0434: return new Operation(name, dcpTypes, odt);
0435: }
0436:
0437: /**
0438: * Creates a <code>DCPType</code> object from the passed <code>DCP</code> element.
0439: * <p>
0440: * NOTE: Currently the <code>OnlineResources</code> included in the <code>DCPType</code> are
0441: * just stored as simple <code>URLs</code> (not as <code>OnLineResource</code> instances)!
0442: * <p>
0443: * NOTE: In an <code>OGCStandardCapabilitiesDocument</code> the <code>XLinks</code> (the
0444: * <code>URLs</code>) are stored in separate elements (<code>OnlineResource</code>), in
0445: * an <code>OGCCommonCapabilitiesDocument</code> they are the
0446: * <code>Get<code>/<code>Post</code> elements themselves.
0447: *
0448: * @param element
0449: *
0450: * @return created <code>DCPType</code>
0451: * @throws XMLParsingException
0452: *
0453: * @see org.deegree.ogcwebservices.getcapabilities.OGCStandardCapabilities
0454: */
0455: @Override
0456: protected DCPType getDCP(Element element)
0457: throws XMLParsingException {
0458:
0459: DCPType dcpType = null;
0460: try {
0461: Element elem = (Element) XMLTools.getRequiredNode(element,
0462: "HTTP", nsContext);
0463: List nl = XMLTools.getNodes(elem, "Get", nsContext);
0464:
0465: URL[] get = new URL[nl.size()];
0466: for (int i = 0; i < get.length; i++) {
0467: String s = XMLTools.getNodeAsString((Node) nl.get(i),
0468: "./@xlink:href", nsContext, null);
0469: if (s == null) {
0470: s = XMLTools.getRequiredNodeAsString((Node) nl
0471: .get(i), "./OnlineResource/@xlink:href",
0472: nsContext);
0473: }
0474: get[i] = new URL(s);
0475: }
0476: nl = XMLTools.getNodes(elem, "Post", nsContext);
0477:
0478: URL[] post = new URL[nl.size()];
0479: for (int i = 0; i < post.length; i++) {
0480: String s = XMLTools.getNodeAsString((Node) nl.get(i),
0481: "./@xlink:href", nsContext, null);
0482: if (s == null) {
0483: s = XMLTools.getRequiredNodeAsString((Node) nl
0484: .get(i), "./OnlineResource/@xlink:href",
0485: nsContext);
0486: }
0487: post[i] = new URL(s);
0488: }
0489: Protocol protocol = new HTTP(get, post);
0490: dcpType = new DCPType(protocol);
0491: } catch (MalformedURLException e) {
0492: throw new XMLParsingException(
0493: "Couldn't parse DCPType onlineresource URL about: "
0494: + StringTools.stackTraceToString(e));
0495: }
0496:
0497: return dcpType;
0498: }
0499:
0500: /**
0501: * returns the layers offered by the WMPS
0502: *
0503: * @param layerElem
0504: * @param parent
0505: * @return Layer
0506: * @throws XMLParsingException
0507: * @throws UnknownCRSException
0508: */
0509: protected Layer parseLayers(Element layerElem, Layer parent)
0510: throws XMLParsingException, UnknownCRSException {
0511:
0512: boolean queryable = XMLTools.getNodeAsBoolean(layerElem,
0513: "./@queryable", nsContext, false);
0514:
0515: int cascaded = XMLTools.getNodeAsInt(layerElem, "./@cascaded",
0516: nsContext, 0);
0517: boolean opaque = XMLTools.getNodeAsBoolean(layerElem,
0518: "./@opaque", nsContext, false);
0519: boolean noSubsets = XMLTools.getNodeAsBoolean(layerElem,
0520: "./@noSubsets", nsContext, false);
0521: int fixedWidth = XMLTools.getNodeAsInt(layerElem,
0522: "./@fixedWidth", nsContext, 0);
0523: int fixedHeight = XMLTools.getNodeAsInt(layerElem,
0524: "./@fixedHeight", nsContext, 0);
0525: String name = XMLTools.getNodeAsString(layerElem, "./Name",
0526: nsContext, null);
0527: String title = XMLTools.getRequiredNodeAsString(layerElem,
0528: "./Title", nsContext);
0529: String layerAbstract = XMLTools.getNodeAsString(layerElem,
0530: "./Abstract", nsContext, null);
0531: String[] keywords = XMLTools.getNodesAsStrings(layerElem,
0532: "./KeywordList/Keyword", nsContext);
0533: String[] srs = XMLTools.getNodesAsStrings(layerElem, "./SRS",
0534: nsContext);
0535:
0536: List nl = XMLTools.getNodes(layerElem, "./BoundingBox",
0537: nsContext);
0538: // TODO substitue with Envelope
0539: LayerBoundingBox[] bboxes = null;
0540: if (nl.size() == 0 && parent != null) {
0541: // inherit BoundingBoxes from parent layer
0542: bboxes = parent.getBoundingBoxes();
0543: } else {
0544: bboxes = parseLayerBoundingBoxes(nl);
0545: }
0546:
0547: Element llBox = (Element) XMLTools.getNode(layerElem,
0548: "./LatLonBoundingBox", nsContext);
0549: Envelope llBoundingBox = null;
0550:
0551: if (llBox == null && parent != null) {
0552: // inherit LatLonBoundingBox parent layer
0553: llBoundingBox = parent.getLatLonBoundingBox();
0554: } else if (llBox != null) {
0555: llBoundingBox = parseLatLonBoundingBox(llBox);
0556: } else {
0557: /** Default crs = EPSG:4326 */
0558: CoordinateSystem crs = CRSFactory.create("EPSG:4326");
0559: llBoundingBox = GeometryFactory.createEnvelope(-180, -90,
0560: 180, 90, crs);
0561: }
0562:
0563: Dimension[] dimensions = parseDimensions(layerElem);
0564:
0565: Extent[] extents = parseExtents(layerElem);
0566:
0567: Attribution attribution = parseAttribution(layerElem);
0568:
0569: AuthorityURL[] authorityURLs = parseAuthorityURLs(layerElem);
0570:
0571: MetadataURL[] metadataURLs = parseMetadataURLs(layerElem);
0572:
0573: DataURL[] dataURLs = parseDataURL(layerElem);
0574:
0575: Identifier[] identifiers = parseIdentifiers(layerElem);
0576:
0577: FeatureListURL[] featureListURLs = parseFeatureListURL(layerElem);
0578:
0579: Style[] styles = parseStyles(layerElem);
0580:
0581: ScaleHint scaleHint = parseScaleHint(layerElem);
0582:
0583: Layer layer = new Layer(queryable, cascaded, opaque, noSubsets,
0584: fixedWidth, fixedHeight, name, title, layerAbstract,
0585: llBoundingBox, attribution, scaleHint, keywords, srs,
0586: bboxes, dimensions, extents, authorityURLs,
0587: identifiers, metadataURLs, dataURLs, featureListURLs,
0588: styles, null, null, parent);
0589:
0590: // get Child layers
0591: nl = XMLTools.getNodes(layerElem, "./Layer", nsContext);
0592: Layer[] layers = new Layer[nl.size()];
0593: for (int i = 0; i < layers.length; i++) {
0594: layers[i] = parseLayers((Element) nl.get(i), layer);
0595: }
0596:
0597: // set child layers
0598: layer.setLayer(layers);
0599:
0600: return layer;
0601: }
0602:
0603: /**
0604: * Parse Dimensions
0605: *
0606: * @param layerElem
0607: * @return Dimension[]
0608: * @throws XMLParsingException
0609: */
0610: protected Dimension[] parseDimensions(Element layerElem)
0611: throws XMLParsingException {
0612:
0613: List nl = XMLTools
0614: .getNodes(layerElem, "./Dimension", nsContext);
0615: Dimension[] dimensions = new Dimension[nl.size()];
0616: for (int i = 0; i < dimensions.length; i++) {
0617: String name = XMLTools.getNodeAsString((Node) nl.get(i),
0618: "./@name", nsContext, null);
0619: String units = XMLTools.getNodeAsString((Node) nl.get(i),
0620: "./@units", nsContext, null);
0621: String unitSymbol = XMLTools.getNodeAsString((Node) nl
0622: .get(i), "./@unitSymbol", nsContext, null);
0623: dimensions[i] = new Dimension(name, units, unitSymbol);
0624: }
0625:
0626: return dimensions;
0627: }
0628:
0629: /**
0630: * Parse Extents
0631: *
0632: * @param layerElem
0633: * @return Extent[]
0634: * @throws XMLParsingException
0635: */
0636: protected Extent[] parseExtents(Element layerElem)
0637: throws XMLParsingException {
0638:
0639: List nl = XMLTools.getNodes(layerElem, "./Extent", nsContext);
0640: Extent[] extents = new Extent[nl.size()];
0641: for (int i = 0; i < extents.length; i++) {
0642: String name = XMLTools.getNodeAsString((Node) nl.get(i),
0643: "./@name", nsContext, null);
0644: String deflt = XMLTools.getNodeAsString((Node) nl.get(i),
0645: "./@default", nsContext, null);
0646: boolean nearestValue = XMLTools.getNodeAsBoolean((Node) nl
0647: .get(i), "./@nearestValue", nsContext, false);
0648: String value = XMLTools.getNodeAsString((Node) nl.get(i),
0649: ".", nsContext, "");
0650: extents[i] = new Extent(name, deflt, nearestValue, value);
0651: }
0652:
0653: return extents;
0654: }
0655:
0656: /**
0657: * Parse Attribution
0658: *
0659: * @param layerElem
0660: * @return Attribution
0661: * @throws XMLParsingException
0662: */
0663: protected Attribution parseAttribution(Element layerElem)
0664: throws XMLParsingException {
0665:
0666: Attribution attribution = null;
0667: Node node = XMLTools.getNode(layerElem, "./Attribution",
0668: nsContext);
0669: if (node != null) {
0670: String title = XMLTools.getRequiredNodeAsString(layerElem,
0671: "./Attribution/Title", nsContext);
0672: Node onlineR = XMLTools.getRequiredNode(node,
0673: "./OnlineResource", nsContext);
0674: OnlineResource onLineResource = parseOnLineResource((Element) onlineR);
0675: node = XMLTools.getNode(node, "./LogoURL", nsContext);
0676: LogoURL logoURL = null;
0677: if (node != null) {
0678: int width = XMLTools.getRequiredNodeAsInt(node,
0679: "./@width", nsContext);
0680: int height = XMLTools.getRequiredNodeAsInt(node,
0681: "./@height", nsContext);
0682: String format = XMLTools.getRequiredNodeAsString(node,
0683: "./Format", nsContext);
0684: onlineR = XMLTools.getRequiredNode(node,
0685: "./OnlineResource", nsContext);
0686: OnlineResource logoOR = parseOnLineResource((Element) onlineR);
0687: logoURL = new LogoURL(width, height, format, logoOR
0688: .getLinkage().getHref());
0689: }
0690: attribution = new Attribution(title, onLineResource
0691: .getLinkage().getHref(), logoURL);
0692: }
0693:
0694: return attribution;
0695: }
0696:
0697: /**
0698: * Parse AuthorityURL
0699: *
0700: * @param layerElem
0701: * @return AuthorityURL[]
0702: * @throws XMLParsingException
0703: */
0704: protected AuthorityURL[] parseAuthorityURLs(Element layerElem)
0705: throws XMLParsingException {
0706:
0707: List nl = XMLTools.getNodes(layerElem, "./AuthorityURL",
0708: nsContext);
0709: AuthorityURL[] authorityURLs = new AuthorityURL[nl.size()];
0710: for (int i = 0; i < authorityURLs.length; i++) {
0711: String name = XMLTools.getRequiredNodeAsString((Node) nl
0712: .get(i), "./@name", nsContext);
0713: Element tmp = (Element) XMLTools.getRequiredNode((Node) nl
0714: .get(i), "./OnlineResource", nsContext);
0715: OnlineResource olr = parseOnLineResource(tmp);
0716: authorityURLs[i] = new AuthorityURL(name, olr.getLinkage()
0717: .getHref());
0718: }
0719:
0720: return authorityURLs;
0721: }
0722:
0723: /**
0724: * Parse MetadataURL
0725: *
0726: * @param layerElem
0727: * @return MetadataURL[]
0728: * @throws XMLParsingException
0729: */
0730: protected MetadataURL[] parseMetadataURLs(Element layerElem)
0731: throws XMLParsingException {
0732:
0733: List nl = XMLTools.getNodes(layerElem, "./MetadataURL",
0734: nsContext);
0735: MetadataURL[] metadataURL = new MetadataURL[nl.size()];
0736: for (int i = 0; i < metadataURL.length; i++) {
0737: String type = XMLTools.getRequiredNodeAsString((Node) nl
0738: .get(i), "./@type", nsContext);
0739: String format = XMLTools.getRequiredNodeAsString((Node) nl
0740: .get(i), "./Format", nsContext);
0741: Element tmp = (Element) XMLTools.getRequiredNode((Node) nl
0742: .get(i), "./OnlineResource", nsContext);
0743: OnlineResource olr = parseOnLineResource(tmp);
0744: metadataURL[i] = new MetadataURL(type, format, olr
0745: .getLinkage().getHref());
0746:
0747: }
0748:
0749: return metadataURL;
0750: }
0751:
0752: /**
0753: * Parse Data URL
0754: *
0755: * @param layerElem
0756: * @return DataURL[]
0757: * @throws XMLParsingException
0758: */
0759: protected DataURL[] parseDataURL(Element layerElem)
0760: throws XMLParsingException {
0761:
0762: List nl = XMLTools.getNodes(layerElem, "./DataURL", nsContext);
0763: DataURL[] dataURL = new DataURL[nl.size()];
0764: for (int i = 0; i < dataURL.length; i++) {
0765:
0766: String format = XMLTools.getRequiredNodeAsString((Node) nl
0767: .get(i), "./Format", nsContext);
0768: Element tmp = (Element) XMLTools.getRequiredNode((Node) nl
0769: .get(i), "./OnlineResource", nsContext);
0770: OnlineResource olr = parseOnLineResource(tmp);
0771: dataURL[i] = new DataURL(format, olr.getLinkage().getHref());
0772:
0773: }
0774:
0775: return dataURL;
0776: }
0777:
0778: /**
0779: * Parse FeatureListURL
0780: *
0781: * @param layerElem
0782: * @return FeatureListURL[]
0783: * @throws XMLParsingException
0784: */
0785: protected FeatureListURL[] parseFeatureListURL(Element layerElem)
0786: throws XMLParsingException {
0787:
0788: List nl = XMLTools.getNodes(layerElem, "./FeatureListURL",
0789: nsContext);
0790: FeatureListURL[] flURL = new FeatureListURL[nl.size()];
0791: for (int i = 0; i < flURL.length; i++) {
0792:
0793: String format = XMLTools.getRequiredNodeAsString((Node) nl
0794: .get(i), "./Format", nsContext);
0795: Element tmp = (Element) XMLTools.getRequiredNode((Node) nl
0796: .get(i), "./OnlineResource", nsContext);
0797: OnlineResource olr = parseOnLineResource(tmp);
0798: flURL[i] = new FeatureListURL(format, olr.getLinkage()
0799: .getHref());
0800:
0801: }
0802:
0803: return flURL;
0804: }
0805:
0806: /**
0807: * Parse Styles
0808: *
0809: * @param layerElem
0810: * @return Style[]
0811: * @throws XMLParsingException
0812: */
0813: protected Style[] parseStyles(Element layerElem)
0814: throws XMLParsingException {
0815:
0816: List nl = XMLTools.getNodes(layerElem, "./Style", nsContext);
0817: Style[] styles = new Style[nl.size()];
0818: for (int i = 0; i < styles.length; i++) {
0819: String name = XMLTools.getRequiredNodeAsString((Node) nl
0820: .get(i), "./Name", nsContext);
0821: String title = XMLTools.getNodeAsString((Node) nl.get(i),
0822: "./Title", nsContext, null);
0823: String styleAbstract = XMLTools.getNodeAsString((Node) nl
0824: .get(i), "./Abstract", nsContext, null);
0825: LegendURL[] legendURLs = parseLegendURL((Node) nl.get(i));
0826: StyleURL styleURL = parseStyleURL((Node) nl.get(i));
0827: StyleSheetURL styleSheetURL = parseStyleSheetURL((Node) nl
0828: .get(i));
0829:
0830: styles[i] = new Style(name, title, styleAbstract,
0831: legendURLs, styleSheetURL, styleURL, null);
0832: }
0833:
0834: return styles;
0835: }
0836:
0837: /**
0838: * Parse Legend URL
0839: *
0840: * @param node
0841: * @return LegendURL[]
0842: * @throws XMLParsingException
0843: */
0844: protected LegendURL[] parseLegendURL(Node node)
0845: throws XMLParsingException {
0846:
0847: List nl = XMLTools.getNodes(node, "./LegendURL", nsContext);
0848: LegendURL[] lURL = new LegendURL[nl.size()];
0849: for (int i = 0; i < lURL.length; i++) {
0850: int width = XMLTools.getRequiredNodeAsInt((Node) nl.get(i),
0851: "./@width", nsContext);
0852: int height = XMLTools.getRequiredNodeAsInt(
0853: (Node) nl.get(i), "./@height", nsContext);
0854: String format = XMLTools.getRequiredNodeAsString((Node) nl
0855: .get(i), "./Format", nsContext);
0856: Element tmp = (Element) XMLTools.getRequiredNode((Node) nl
0857: .get(i), "./OnlineResource", nsContext);
0858: OnlineResource olr = parseOnLineResource(tmp);
0859: lURL[i] = new LegendURL(width, height, format, olr
0860: .getLinkage().getHref());
0861:
0862: }
0863:
0864: return lURL;
0865: }
0866:
0867: /**
0868: * Parse Style URL
0869: *
0870: * @param node
0871: * @return StyleURL
0872: * @throws XMLParsingException
0873: */
0874: protected StyleURL parseStyleURL(Node node)
0875: throws XMLParsingException {
0876:
0877: StyleURL styleURL = null;
0878: Node styleNode = XMLTools
0879: .getNode(node, "./StyleURL", nsContext);
0880:
0881: if (styleNode != null) {
0882: String format = XMLTools.getRequiredNodeAsString(styleNode,
0883: "./Format", nsContext);
0884: Element tmp = (Element) XMLTools.getRequiredNode(styleNode,
0885: "./OnlineResource", nsContext);
0886: OnlineResource olr = parseOnLineResource(tmp);
0887: styleURL = new StyleURL(format, olr.getLinkage().getHref());
0888:
0889: }
0890:
0891: return styleURL;
0892: }
0893:
0894: /**
0895: * Parse Style Sheet URL
0896: *
0897: * @param node
0898: * @return StyleSheetURL
0899: * @throws XMLParsingException
0900: */
0901: protected StyleSheetURL parseStyleSheetURL(Node node)
0902: throws XMLParsingException {
0903:
0904: StyleSheetURL styleSheetURL = null;
0905: Node styleNode = XMLTools.getNode(node, "./StyleSheetURL",
0906: nsContext);
0907:
0908: if (styleNode != null) {
0909: String format = XMLTools.getRequiredNodeAsString(styleNode,
0910: "./Format", nsContext);
0911: Element tmp = (Element) XMLTools.getRequiredNode(styleNode,
0912: "./OnlineResource", nsContext);
0913: OnlineResource olr = parseOnLineResource(tmp);
0914: styleSheetURL = new StyleSheetURL(format, olr.getLinkage()
0915: .getHref());
0916:
0917: }
0918:
0919: return styleSheetURL;
0920: }
0921:
0922: /**
0923: * Parse Scale Hint
0924: *
0925: * @param layerElem
0926: * @return ScaleHint
0927: * @throws XMLParsingException
0928: */
0929: protected ScaleHint parseScaleHint(Element layerElem)
0930: throws XMLParsingException {
0931:
0932: ScaleHint scaleHint = null;
0933:
0934: Node scNode = XMLTools.getNode(layerElem, "./ScaleHint",
0935: nsContext);
0936: if (scNode != null) {
0937: double mn = XMLTools.getNodeAsDouble(scNode, "./@min",
0938: nsContext, 0);
0939: double mx = XMLTools.getNodeAsDouble(scNode, "./@max",
0940: nsContext, Double.MAX_VALUE);
0941: scaleHint = new ScaleHint(mn, mx);
0942: } else {
0943: // set default value to avoid NullPointerException
0944: // when accessing a layers scalehint
0945: scaleHint = new ScaleHint(0, Double.MAX_VALUE);
0946: }
0947:
0948: return scaleHint;
0949: }
0950:
0951: /**
0952: * Parse Identifiers
0953: *
0954: * @param layerElem
0955: * @return Identifier[]
0956: * @throws XMLParsingException
0957: */
0958: protected Identifier[] parseIdentifiers(Element layerElem)
0959: throws XMLParsingException {
0960:
0961: List nl = XMLTools.getNodes(layerElem, "./Identifier",
0962: nsContext);
0963: Identifier[] identifiers = new Identifier[nl.size()];
0964: for (int i = 0; i < identifiers.length; i++) {
0965: String value = XMLTools.getStringValue((Node) nl.get(i));
0966: String authority = XMLTools.getNodeAsString(layerElem,
0967: "./@authority", nsContext, null);
0968: identifiers[i] = new Identifier(value, authority);
0969: }
0970:
0971: return identifiers;
0972: }
0973:
0974: /**
0975: * Parse Layer Bounding Boxes
0976: *
0977: * @param nl
0978: * @return LayerBoundingBox[]
0979: * @throws XMLParsingException
0980: */
0981: protected LayerBoundingBox[] parseLayerBoundingBoxes(List nl)
0982: throws XMLParsingException {
0983:
0984: LayerBoundingBox[] llBoxes = new LayerBoundingBox[nl.size()];
0985: for (int i = 0; i < llBoxes.length; i++) {
0986: double minx = XMLTools.getRequiredNodeAsDouble((Node) nl
0987: .get(i), "./@minx", nsContext);
0988: double maxx = XMLTools.getRequiredNodeAsDouble((Node) nl
0989: .get(i), "./@maxx", nsContext);
0990: double miny = XMLTools.getRequiredNodeAsDouble((Node) nl
0991: .get(i), "./@miny", nsContext);
0992: double maxy = XMLTools.getRequiredNodeAsDouble((Node) nl
0993: .get(i), "./@maxy", nsContext);
0994: double resx = XMLTools.getNodeAsDouble((Node) nl.get(i),
0995: "./@resx", nsContext, -1);
0996: double resy = XMLTools.getNodeAsDouble((Node) nl.get(i),
0997: "./@resx", nsContext, -1);
0998: String srs = XMLTools.getRequiredNodeAsString((Node) nl
0999: .get(i), "./@SRS", nsContext);
1000: Position min = GeometryFactory.createPosition(minx, miny);
1001: Position max = GeometryFactory.createPosition(maxx, maxy);
1002: llBoxes[i] = new LayerBoundingBox(min, max, srs, resx, resy);
1003: }
1004:
1005: return llBoxes;
1006: }
1007:
1008: /**
1009: * Parse Lat Lon Bounding Box
1010: *
1011: * @param llBox
1012: * @return Envelope
1013: * @throws XMLParsingException
1014: * @throws UnknownCRSException
1015: */
1016: protected Envelope parseLatLonBoundingBox(Element llBox)
1017: throws XMLParsingException, UnknownCRSException {
1018:
1019: double minx = XMLTools.getRequiredNodeAsDouble(llBox,
1020: "./@minx", nsContext);
1021: double maxx = XMLTools.getRequiredNodeAsDouble(llBox,
1022: "./@maxx", nsContext);
1023: double miny = XMLTools.getRequiredNodeAsDouble(llBox,
1024: "./@miny", nsContext);
1025: double maxy = XMLTools.getRequiredNodeAsDouble(llBox,
1026: "./@maxy", nsContext);
1027: /** default crs = EPSG:4326 */
1028: CoordinateSystem crs = CRSFactory.create("EPSG:4326");
1029: Envelope env = GeometryFactory.createEnvelope(minx, miny, maxx,
1030: maxy, crs);
1031:
1032: return env;
1033: }
1034:
1035: }
|