コード例 #1
0
        /**
         * Returns true if the specified file can be opened as an XML document, and calling {@link
         * #accept(org.w3c.dom.Document)} returns true.
         *
         * @param file the file in question.
         *
         * @return true if the file should be accepted; false otherwise.
         *
         * @throws ArgumentException if the file is null.
         */
        public bool accept(java.io.File file)
        {
            if (file == null)
            {
                String msg = Logging.getMessage("nullValue.FileIsNull");
                Logging.logger().severe(msg);
                throw new ArgumentException(msg);
            }

            // First check the file path, optionally returning false if the path cannot be accepted for any reason.
            if (!this.acceptFilePath(file.getPath()))
            {
                return(false);
            }

            Document doc = null;

            try
            {
                doc = WWXML.openDocumentFile(file.getPath(), this.GetType());
            }
            catch (Exception e)
            {
                // Not interested in logging the exception. We just want to return false, indicating that the File cannot
                // be opened as an XML document.
            }

            return((doc != null) && (doc.getDocumentElement() != null) && this.accept(doc));
        }
コード例 #2
0
        private void loadConfigProperties(Document doc)
        {
            try
            {
                XPath xpath = WWXML.makeXPath();

                NodeList nodes = (NodeList)xpath.evaluate("/WorldWindConfiguration/Property", doc, XPathConstants.NODESET);
                if (nodes == null || nodes.getLength() == 0)
                {
                    return;
                }

                for (int i = 0; i < nodes.getLength(); i++)
                {
                    Node   node  = nodes.item(i);
                    String prop  = xpath.evaluate("@name", node);
                    String value = xpath.evaluate("@value", node);
                    if (WWUtil.isEmpty(prop))// || WWUtil.isEmpty(value))
                    {
                        continue;
                    }

                    this.properties.setProperty(prop, value);
                }
            }
            catch (XPathExpressionException e)
            {
                Logging.logger(DEFAULT_LOGGER_NAME).log(Level.WARNING, "XML.ParserConfigurationException");
            }
        }
コード例 #3
0
        /**
         * Create the objects described in an XML element containing layer and/or layer-list descriptions. Nested layer
         * lists and included layers are created recursively.
         *
         * @param domElement an XML element describing the layers and/or layer lists.
         * @param parameters     any properties to apply when creating the included layers.
         *
         * @return a <code>Layer</code>, <code>LayerList</code> or array of <code>LayerList</code>s, as described by the
         *         specified description.
         *
         * @throws Exception if an exception occurs during creation. Exceptions occurring during creation of internal layers
         *                   or layer lists are not re-thrown but are logged. The layer or layer list associated with the
         *                   exception is not contained in the returned object.
         */
        protected override Object doCreateFromElement(Element domElement, AVList parameters)
        {
            Element[] elements = WWXML.getElements(domElement, "//LayerList", null);
            if (elements != null && elements.Length > 0)
            {
                return(createLayerLists(elements, parameters));
            }

            elements = WWXML.getElements(domElement, "./Layer", null);
            if (elements != null && elements.Length > 1)
            {
                return(createLayerList(elements, parameters));
            }

            if (elements != null && elements.Length == 1)
            {
                return(this.createFromLayerDocument(elements[0], parameters));
            }

            String localName = WWXML.getUnqualifiedName(domElement);

            if (localName != null && localName.Equals("Layer"))
            {
                return(this.createFromLayerDocument(domElement, parameters));
            }

            return(null);
        }
コード例 #4
0
        /**
         * Parses layer configuration parameters from the specified DOM document. This writes output as key-value pairs to
         * parameters. If a parameter from the XML document already exists in parameters, that parameter is ignored. Supported key
         * and parameter names are: <table> <tr><th>Parameter</th><th>Element Path</th><th>Type</th></tr> <tr><td>{@link
         * AVKey#DISPLAY_NAME}</td><td>DisplayName</td><td>string</td></tr> <tr><td>{@link
         * AVKey#OPACITY}</td><td>Opacity</td><td>Double</td></tr> <tr><td>{@link AVKey#MAX_ACTIVE_ALTITUDE}</td><td>ActiveAltitudes/@max</td><td>Double</td></tr>
         * <tr><td>{@link AVKey#MIN_ACTIVE_ALTITUDE}</td><td>ActiveAltitudes/@min</td><td>Double</td></tr> <tr><td>{@link
         * AVKey#NETWORK_RETRIEVAL_ENABLED}</td><td>NetworkRetrievalEnabled</td><td>Boolean</td></tr> <tr><td>{@link
         * AVKey#MAP_SCALE}</td><td>MapScale</td><td>Double</td></tr> <tr><td>{@link AVKey#SCREEN_CREDIT}</td><td>ScreenCredit</td><td>{@link
         * ScreenCredit}</td></tr> </table>
         *
         * @param domElement the XML document root to parse for layer configuration elements.
         * @param parameters     the output key-value pairs which recieve the layer configuration parameters. A null reference
         *                   is permitted.
         *
         * @return a reference to parameters, or a new AVList if parameters is null.
         *
         * @throws ArgumentException if the document is null.
         */
        public static AVList getLayerConfigParams(Element domElement, AVList parameters)
        {
            if (domElement == null)
            {
                string message = Logging.getMessage("nullValue.DocumentIsNull");
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }

            if (parameters == null)
            {
                parameters = new AVListImpl();
            }

            XPath xpath = WWXML.makeXPath();

            WWXML.checkAndSetStringParam(domElement, parameters, AVKey.DISPLAY_NAME, "DisplayName", xpath);
            WWXML.checkAndSetDoubleParam(domElement, parameters, AVKey.OPACITY, "Opacity", xpath);
            WWXML.checkAndSetDoubleParam(domElement, parameters, AVKey.MAX_ACTIVE_ALTITUDE, "ActiveAltitudes/@max", xpath);
            WWXML.checkAndSetDoubleParam(domElement, parameters, AVKey.MIN_ACTIVE_ALTITUDE, "ActiveAltitudes/@min", xpath);
            WWXML.checkAndSetBooleanParam(domElement, parameters, AVKey.NETWORK_RETRIEVAL_ENABLED, "NetworkRetrievalEnabled",
                                          xpath);
            WWXML.checkAndSetDoubleParam(domElement, parameters, AVKey.MAP_SCALE, "MapScale", xpath);
            WWXML.checkAndSetScreenCreditParam(domElement, parameters, AVKey.SCREEN_CREDIT, "ScreenCredit", xpath);
            WWXML.checkAndSetIntegerParam(domElement, parameters, AVKey.MAX_ABSENT_TILE_ATTEMPTS, "MaxAbsentTileAttempts",
                                          xpath);
            WWXML.checkAndSetIntegerParam(domElement, parameters, AVKey.MIN_ABSENT_TILE_CHECK_INTERVAL,
                                          "MinAbsentTileCheckInterval", xpath);
            WWXML.checkAndSetBooleanParam(domElement, parameters, AVKey.PICK_ENABLED, "PickEnabled", xpath);

            return(parameters);
        }
コード例 #5
0
 private void insertConfigDoc(String configLocation)
 {
     if (!WWUtil.isEmpty(configLocation))
     {
         Document doc = WWXML.openDocument(configLocation);
         if (doc != null)
         {
             this.configDocs.add(0, doc);
             this.loadConfigProperties(doc);
         }
     }
 }
コード例 #6
0
        //**************************************************************//
        //********************  Configuration  *************************//
        //**************************************************************//

        /**
         * Returns true if a specified DOM document is a Layer configuration document, and false otherwise.
         *
         * @param domElement the DOM document in question.
         *
         * @return true if the document is a Layer configuration document; false otherwise.
         *
         * @throws ArgumentException if document is null.
         */
        public static bool isLayerConfigDocument(Element domElement)
        {
            if (domElement == null)
            {
                string message = Logging.getMessage("nullValue.DocumentIsNull");
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }

            XPath xpath = WWXML.makeXPath();

            Element[] elements = WWXML.getElements(domElement, "//Layer", xpath);

            return(elements != null && elements.Length > 0);
        }
コード例 #7
0
        /**
         * Creates an object from a general configuration source. The source can be one of the following: <ul> <li>{@link
         * java.net.URL}</li> <li>{@link java.io.File}</li> <li>{@link java.io.InputStream}</li> <li>{@link Element}</li>
         * <li>{@link SharpEarth.ogc.OGCCapabilities}</li>
         * <li>{@link SharpEarth.ogc.wcs.wcs100.WCS100Capabilities}</li>
         * <li>{@link string} holding a file name, a name of a resource on the classpath, or a string representation of a
         * URL</li></ul>
         * <p/>
         *
         * @param configSource the configuration source. See above for supported types.
         * @param parameters       key-value parameters to override or supplement the information provided in the specified
         *                     configuration source. May be null.
         *
         * @return the new object.
         *
         * @throws ArgumentException if the configuration source is null or an empty string.
         * @throws WWUnrecognizedException  if the source type is unrecognized.
         * @throws WWRuntimeException       if object creation fails. The exception indicating the source of the failure is
         *                                  included as the {@link Exception#initCause(Throwable)}.
         */
        public object createFromConfigSource(object configSource, AVList parameters)
        {
            if (WWUtil.isEmpty(configSource))
            {
                string message = Logging.getMessage("generic.ConfigurationSourceIsInvalid", configSource);
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }

            object o = null;

            try
            {
                if (configSource is Element)
                {
                    o = this.doCreateFromElement((Element)configSource, parameters);
                }
                else if (configSource is OGCCapabilities)
                {
                    o = this.doCreateFromCapabilities((OGCCapabilities)configSource, parameters);
                }
                else if (configSource is WCS100Capabilities)
                {
                    o = this.doCreateFromCapabilities((WCS100Capabilities)configSource, parameters);
                }
                else
                {
                    Document doc = WWXML.openDocument(configSource);
                    if (doc != null)
                    {
                        o = this.doCreateFromElement(doc.getDocumentElement(), parameters);
                    }
                }
            }
            catch (Exception e)
            {
                string msg = Logging.getMessage("generic.CreationFromConfigurationFileFailed", configSource);
                throw new WWRuntimeException(msg, e);
            }

            return(o);
        }
コード例 #8
0
        /**
         * Appends layer configuration parameters as elements to the specified context. This appends elements for the
         * following parameters: <table> <tr><th>Parameter</th><th>Element Path</th><th>Type</th></tr> <tr><td>{@link
         * AVKey#DISPLAY_NAME}</td><td>DisplayName</td><td>string</td></tr> <tr><td>{@link
         * AVKey#OPACITY}</td><td>Opacity</td><td>Double</td></tr> <tr><td>{@link AVKey#MAX_ACTIVE_ALTITUDE}</td><td>ActiveAltitudes/@max</td><td>Double</td></tr>
         * <tr><td>{@link AVKey#MIN_ACTIVE_ALTITUDE}</td><td>ActiveAltitudes/@min</td><td>Double</td></tr> <tr><td>{@link
         * AVKey#NETWORK_RETRIEVAL_ENABLED}</td><td>NetworkRetrievalEnabled</td><td>Boolean</td></tr> <tr><td>{@link
         * AVKey#MAP_SCALE}</td><td>MapScale</td><td>Double</td></tr> <tr><td>{@link AVKey#SCREEN_CREDIT}</td><td>ScreenCredit</td><td>ScreenCredit</td></tr>
         * </table>
         *
         * @param parameters  the key-value pairs which define the layer configuration parameters.
         * @param context the XML document root on which to append layer configuration elements.
         *
         * @return a reference to context.
         *
         * @throws ArgumentException if either the parameters or the context are null.
         */
        public static Element createLayerConfigElements(AVList parameters, Element context)
        {
            if (parameters == null)
            {
                string message = Logging.getMessage("nullValue.ParametersIsNull");
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }

            if (context == null)
            {
                string message = Logging.getMessage("nullValue.ContextIsNull");
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }

            WWXML.checkAndAppendTextElement(parameters, AVKey.DISPLAY_NAME, context, "DisplayName");
            WWXML.checkAndAppendDoubleElement(parameters, AVKey.OPACITY, context, "Opacity");

            double?maxAlt = AVListImpl.getDoubleValue(parameters, AVKey.MAX_ACTIVE_ALTITUDE);
            double?minAlt = AVListImpl.getDoubleValue(parameters, AVKey.MIN_ACTIVE_ALTITUDE);

            if (maxAlt != null || minAlt != null)
            {
                Element el = WWXML.appendElementPath(context, "ActiveAltitudes");
                if (maxAlt != null)
                {
                    WWXML.setDoubleAttribute(el, "max", maxAlt.Value);
                }
                if (minAlt != null)
                {
                    WWXML.setDoubleAttribute(el, "min", minAlt.Value);
                }
            }

            WWXML.checkAndAppendBooleanElement(parameters, AVKey.NETWORK_RETRIEVAL_ENABLED, context, "NetworkRetrievalEnabled");
            WWXML.checkAndAppendDoubleElement(parameters, AVKey.MAP_SCALE, context, "MapScale");
            WWXML.checkAndAppendScreenCreditElement(parameters, AVKey.SCREEN_CREDIT, context, "ScreenCredit");
            WWXML.checkAndAppendBooleanElement(parameters, AVKey.PICK_ENABLED, context, "PickEnabled");

            return(context);
        }
コード例 #9
0
        /**
         * Returns a specified element of an XML configuration document.
         *
         * @param xpathExpression an XPath expression identifying the element of interest.
         *
         * @return the element of interest if the XPath expression is valid and the element exists, otherwise null.
         *
         * @throws NullPointerException if the XPath expression is null.
         */
        public static Element getElement(String xpathExpression)
        {
            XPath xpath = WWXML.makeXPath();

            foreach (Document doc in getInstance().configDocs)
            {
                try
                {
                    Node node = (Node)xpath.evaluate(xpathExpression, doc.getDocumentElement(), XPathConstants.NODE);
                    if (node != null)
                    {
                        return((Element)node);
                    }
                }
                catch (XPathExpressionException e)
                {
                    return(null);
                }
            }

            return(null);
        }
コード例 #10
0
        /**
         * Returns true if the specified {@link java.net.URL} can be opened as an XML document, and calling {@link
         * #accept(org.w3c.dom.Document)} returns true.
         *
         * @param url the URL in question.
         *
         * @return true if the URL should be accepted; false otherwise.
         *
         * @throws ArgumentException if the url is null.
         */
        public bool accept(java.net.URL url)
        {
            if (url == null)
            {
                String msg = Logging.getMessage("nullValue.URLIsNull");
                Logging.logger().severe(msg);
                throw new ArgumentException(msg);
            }

            Document doc = null;

            try
            {
                doc = WWXML.openDocumentURL(url);
            }
            catch (Exception e)
            {
                // Not interested in logging the exception. We just want to return false, indicating that the URL cannot
                // be opened as an XML document.
            }

            return((doc != null) && (doc.getDocumentElement() != null) && this.accept(doc));
        }
コード例 #11
0
        /**
         * Create a {@link TiledImageLayer} layer described by an XML layer description.
         *
         * @param domElement the XML element describing the layer to create. The element must inculde a service name
         *                   identifying the type of service to use to retrieve layer data. Recognized service types are
         *                   "Offline", "WWTileService" and "OGC:WMS".
         * @param parameters     any parameters to apply when creating the layer.
         *
         * @return a new layer
         *
         * @throws WWUnrecognizedException if the service type given in the describing element is unrecognized.
         */
        protected Layer createTiledImageLayer(Element domElement, AVList parameters)
        {
            Layer layer;

            String serviceName = WWXML.getText(domElement, "Service/@serviceName");

            if ("Offline".Equals(serviceName))
            {
                layer = new BasicTiledImageLayer(domElement, parameters);
            }
            else if ("WWTileService".Equals(serviceName))
            {
                layer = new BasicTiledImageLayer(domElement, parameters);
            }
            else if (OGCConstants.WMS_SERVICE_NAME.Equals(serviceName))
            {
                layer = new WMSTiledImageLayer(domElement, parameters);
            }
            else if (AVKey.SERVICE_NAME_LOCAL_RASTER_SERVER.Equals(serviceName))
            {
                layer = new LocalRasterServerLayer(domElement, parameters);
            }
            else
            {
                String msg = Logging.getMessage("generic.UnrecognizedServiceName", serviceName);
                throw new WWUnrecognizedException(msg);
            }
//
//        String name = layer.getStringValue(AVKey.DISPLAY_NAME);
//        System.out.println(name);

            String actuate = WWXML.getText(domElement, "@actuate");

            layer.setEnabled(actuate != null && actuate.Equals("onLoad"));

            return(layer);
        }
コード例 #12
0
            public URL getURL(Tile tile, String altImageFormat)
            {
                StringBuilder sb;

                if (this.URLTemplate == null)
                {
                    sb = new StringBuilder(WWXML.fixGetMapString(tile.getLevel().getService()));

                    if (!sb.ToString().ToLower().Contains("service=wms"))
                    {
                        sb.Append("service=WMS");
                    }
                    sb.Append("&request=GetMap");
                    sb.Append("&version=").Append(this.wmsVersion);
                    sb.Append(this.crs);
                    sb.Append("&layers=").Append(this.layerNames);
                    sb.Append("&styles=").Append(this.styleNames != null ? this.styleNames : "");
                    sb.Append("&transparent=TRUE");
                    if (this.backgroundColor != null)
                    {
                        sb.Append("&bgcolor=").Append(this.backgroundColor);
                    }

                    this.URLTemplate = sb.ToString();
                }
                else
                {
                    sb = new StringBuilder(this.URLTemplate);
                }

                String format = (altImageFormat != null) ? altImageFormat : this.imageFormat;

                if (null != format)
                {
                    sb.Append("&format=").Append(format);
                }

                sb.Append("&width=").Append(tile.getWidth());
                sb.Append("&height=").Append(tile.getHeight());

                Sector s = tile.getSector();

                sb.Append("&bbox=");
                // The order of the coordinate specification matters, and it changed with WMS 1.3.0.
                if (WWUtil.compareVersion(this.wmsVersion, "1.1.1") <= 0 || this.crs.Contains("CRS:84"))
                {
                    // 1.1.1 and earlier and CRS:84 use lon/lat order
                    sb.Append(s.getMinLongitude().getDegrees());
                    sb.Append(",");
                    sb.Append(s.getMinLatitude().getDegrees());
                    sb.Append(",");
                    sb.Append(s.getMaxLongitude().getDegrees());
                    sb.Append(",");
                    sb.Append(s.getMaxLatitude().getDegrees());
                }
                else
                {
                    // 1.3.0 uses lat/lon ordering
                    sb.Append(s.getMinLatitude().getDegrees());
                    sb.Append(",");
                    sb.Append(s.getMinLongitude().getDegrees());
                    sb.Append(",");
                    sb.Append(s.getMaxLatitude().getDegrees());
                    sb.Append(",");
                    sb.Append(s.getMaxLongitude().getDegrees());
                }

                return(new URL(sb.ToString().Replace(" ", "%20")));
            }
コード例 #13
0
        /**
         * Create a layer described by an XML layer description.
         *
         * @param domElement the XML element describing the layer to create.
         * @param parameters     any parameters to apply when creating the layer.
         *
         * @return a new layer
         *
         * @throws WWUnrecognizedException if the layer type or service type given in the describing element is
         *                                 unrecognized.
         * @see #createTiledImageLayer(org.w3c.dom.Element, SharpEarth.avlist.AVList).
         */
        protected Layer createFromLayerDocument(Element domElement, AVList parameters)
        {
            String className = WWXML.getText(domElement, "@className");

            if (className != null && className.length() > 0)
            {
                Layer  layer   = (Layer)WorldWind.createComponent(className);
                String actuate = WWXML.getText(domElement, "@actuate");
                layer.setEnabled(WWUtil.isEmpty(actuate) || actuate.Equals("onLoad"));
                WWXML.invokePropertySetters(layer, domElement);
                return(layer);
            }

            AVList props = WWXML.copyProperties(domElement, null);

            if (props != null)
            { // Copy parameters and add any properties for this layer to the copy
                if (params != null)
                {
                    props.setValues(params);
                }
                parameters = props;
            }

            Layer  layer;
            String href = WWXML.getText(domElement, "@href");

            if (href != null && href.length() > 0)
            {
                Object o = this.createFromConfigSource(href, parameters);
                if (o == null)
                {
                    return(null);
                }

                if (!(o is Layer))
                {
                    String msg = Logging.getMessage("LayerFactory.UnexpectedTypeForLayer", o.GetType().Name);
                    throw new WWRuntimeException(msg);
                }

                layer = (Layer)o;
            }
            else
            {
                String layerType = WWXML.getText(domElement, "@layerType");
                if (layerType != null && layerType.Equals("TiledImageLayer"))
                {
                    layer = this.createTiledImageLayer(domElement, parameters);
                }
                else if (layerType != null && layerType.Equals("ShapefileLayer"))
                {
                    layer = this.createShapefileLayer(domElement, parameters);
                }
                else
                {
                    String msg = Logging.getMessage("generic.UnrecognizedLayerType", layerType);
                    throw new WWUnrecognizedException(msg);
                }
            }

            if (layer != null)
            {
                String actuate = WWXML.getText(domElement, "@actuate");
                layer.setEnabled(actuate != null && actuate.Equals("onLoad"));
                WWXML.invokePropertySetters(layer, domElement);
            }

            return(layer);
        }
コード例 #14
0
        /**
         * Create a collection of layer lists and their included layers described by an array of XML layer-list description
         * elements.
         * <p/>
         * Any exceptions occurring during creation of the layer lists or their included layers are logged and not
         * re-thrown. The layers associated with the exceptions are not included in the returned layer list.
         *
         * @param elements the XML elements describing the layer lists to create.
         * @param parameters   any parameters to apply when creating the included layers.
         *
         * @return an array containing the specified layer lists.
         */
        protected LayerList[] createLayerLists(Element[] elements, AVList parameters)
        {
            List <LayerList> layerLists = new List <LayerList>();

            foreach (Element element in elements)
            {
                try
                {
                    String href = WWXML.getText(element, "@href");
                    if (href != null && href.Length > 0)
                    {
                        Object o = this.createFromConfigSource(href, parameters);
                        if (o == null)
                        {
                            continue;
                        }

                        if (o is Layer)
                        {
                            LayerList ll = new LayerList();
                            ll.add((Layer)o);
                            o = ll;
                        }

                        if (o is LayerList)
                        {
                            LayerList list = (LayerList)o;
                            if (list != null && list.size() > 0)
                            {
                                layerLists.add(list);
                            }
                        }
                        else if (o is LayerList[])
                        {
                            LayerList[] lists = (LayerList[])o;
                            if (lists != null && lists.length > 0)
                            {
                                layerLists.addAll(Arrays.asList(lists));
                            }
                        }
                        else
                        {
                            String msg = Logging.getMessage("LayerFactory.UnexpectedTypeForLayer", o.GetType().Name);
                            Logging.logger().log(java.util.logging.Level.WARNING, msg);
                        }

                        continue;
                    }

                    String    title    = WWXML.getText(element, "@title");
                    Element[] children = WWXML.getElements(element, "./Layer", null);
                    if (children != null && children.length > 0)
                    {
                        LayerList list = this.createLayerList(children, parameters);
                        if (list != null && list.size() > 0)
                        {
                            layerLists.add(list);
                            if (title != null && title.length() > 0)
                            {
                                list.setValue(AVKey.DISPLAY_NAME, title);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Logging.logger().log(java.util.logging.Level.WARNING, e.getMessage(), e);
                    // keep going to create other layers
                }
            }

            return(layerLists.toArray(new LayerList[layerLists.size()]));
        }
コード例 #15
0
 protected XMLEventReader createReader(Object docSource)
 {
     return(WWXML.openEventReader(docSource));
 }