wwxml.java

来自「world wind java sdk 源码」· Java 代码 · 共 1,246 行 · 第 1/4 页

JAVA
1,246
字号
            Logging.logger().severe(message);            throw new IllegalArgumentException(message);        }        if (path == null)        {            String message = Logging.getMessage("nullValue.PathIsNull");            Logging.logger().severe(message);            throw new IllegalArgumentException(message);        }        String s = null;        try        {            s = getText(context, path, xpath);            if (s == null || s.length() == 0)                return null;            return Boolean.valueOf(s);        }        catch (NumberFormatException e)        {            String message = Logging.getMessage("generic.ConversionError", s);            Logging.logger().log(java.util.logging.Level.SEVERE, message, e);            return null;        }    }    /**     * Returns the {@link gov.nasa.worldwind.geom.LatLon} value of an element identified by an XPath expression.     *     * @param context the context from which to start the XPath search.     * @param path    the XPath expression. If null, indicates that the context is the LatLon element itself. If     *                non-null, the context is searched for a LatLon element using the expression.     * @param xpath   an {@link XPath} object to use for the search. This allows the caller to re-use XPath objects when     *                performing multiple searches. May be null.     *     * @return the value of an element matching the XPath expression, or null if no match is found or the match does not     *         contain a {@link gov.nasa.worldwind.geom.LatLon}.     *     * @throws IllegalArgumentException if the context is null.     */    public static LatLon getLatLon(Element context, String path, XPath xpath)    {        if (context == null)        {            String message = Logging.getMessage("nullValue.ContextIsNull");            Logging.logger().severe(message);            throw new IllegalArgumentException(message);        }        if (path == null)        {            String message = Logging.getMessage("nullValue.PathIsNull");            Logging.logger().severe(message);            throw new IllegalArgumentException(message);        }        try        {            Element el = path == null ? context : getElement(context, path, xpath);            if (el == null)                return null;            String units = getText(el, "@units", xpath);            Double lat = getDouble(el, "@latitude", xpath);            Double lon = getDouble(el, "@longitude", xpath);            if (lat == null || lon == null)                return null;            if (units == null || units.equals("degrees"))                return LatLon.fromDegrees(lat, lon);            if (units.equals("radians"))                return LatLon.fromRadians(lat, lon);            // Warn that units are not recognized            String message = Logging.getMessage("XML.UnitsUnrecognized", units);            Logging.logger().warning(message);            return null;        }        catch (NumberFormatException e)        {            String message = Logging.getMessage("generic.ConversionError", path);            Logging.logger().log(java.util.logging.Level.SEVERE, message, e);            return null;        }    }    /**     * Returns the {@link gov.nasa.worldwind.geom.Sector} value of an element identified by an XPath expression.     *     * @param context the context from which to start the XPath search.     * @param path    the XPath expression. If null, indicates that the context is the Sector element itself. If     *                non-null, the context is searched for a Sector element using the expression.     * @param xpath   an {@link XPath} object to use for the search. This allows the caller to re-use XPath objects when     *                performing multiple searches. May be null.     *     * @return the value of an element matching the XPath expression, or null if no match is found or the match does not     *         contain a {@link gov.nasa.worldwind.geom.Sector}.     *     * @throws IllegalArgumentException if the context is null.     */    public static Sector getSector(Element context, String path, XPath xpath)    {        if (context == null)        {            String message = Logging.getMessage("nullValue.ContextIsNull");            Logging.logger().severe(message);            throw new IllegalArgumentException(message);        }        Element el = path == null ? context : getElement(context, path, xpath);        if (el == null)            return null;        LatLon sw = getLatLon(el, "SouthWest/LatLon", xpath);        LatLon ne = getLatLon(el, "NorthEast/LatLon", xpath);        if (sw == null || ne == null)            return null;        return new Sector(sw.latitude, ne.latitude, sw.longitude, ne.longitude);    }    /**     * Returns the {@link gov.nasa.worldwind.util.LevelSet.SectorResolution} value of an element identified by an XPath     * expression.     *     * @param context the context from which to start the XPath search.     * @param path    the XPath expression. If null, indicates that the context is the SectorResolution element itself.     *                If non-null, the context is searched for a SectorResolution element using the expression.     * @param xpath   an {@link XPath} object to use for the search. This allows the caller to re-use XPath objects when     *                performing multiple searches. May be null.     *     * @return the value of an element matching the XPath expression, or null if no match is found or the match does not     *         contain a {@link gov.nasa.worldwind.util.LevelSet.SectorResolution}.     *     * @throws IllegalArgumentException if the context is null.     */    public static LevelSet.SectorResolution getSectorResolutionLimit(Element context, String path, XPath xpath)    {        if (context == null)        {            String message = Logging.getMessage("nullValue.ContextIsNull");            Logging.logger().severe(message);            throw new IllegalArgumentException(message);        }        Element el = path == null ? context : getElement(context, path, xpath);        if (el == null)            return null;        Integer maxLevelNum = getInteger(el, "@maxLevelNum", xpath);        Sector sector = getSector(el, "Sector", xpath);        if (maxLevelNum == null || sector == null)            return null;        return new LevelSet.SectorResolution(sector, maxLevelNum);    }    /**     * Checks a parameter list for a specified key and if not present attempts to find a value for the key from an     * element matched by an XPath expression. If found, the key and value are added to the parameter list.     *     * @param context   the context from which to start the XPath search.     * @param params    the parameter list.     * @param paramKey  the key used to identify the paramater in the parameter list.     * @param paramName the Xpath expression identifying the parameter value within the specified context.     * @param xpath     an {@link XPath} object to use for the search. This allows the caller to re-use XPath objects     *                  when performing multiple searches. May be null.     *     * @throws IllegalArgumentException if either the context, parameter list, parameter key or parameter name are     *                                  null.     */    public static void checkAndSetStringParam(Element context, AVList params, String paramKey, String paramName,        XPath xpath)    {        if (context == null)        {            String message = Logging.getMessage("nullValue.ElementIsNull");            Logging.logger().severe(message);            throw new IllegalArgumentException(message);        }        if (params == null)        {            String message = Logging.getMessage("nullValue.ParametersIsNull");            Logging.logger().severe(message);            throw new IllegalArgumentException(message);        }        if (paramKey == null)        {            String message = Logging.getMessage("nullValue.ParameterKeyIsNull");            Logging.logger().severe(message);            throw new IllegalArgumentException(message);        }        if (paramName == null)        {            String message = Logging.getMessage("nullValue.ParameterNameIsNull");            Logging.logger().severe(message);            throw new IllegalArgumentException(message);        }        String s = params.getStringValue(paramKey);        if (s == null)        {            s = getText(context, paramName, xpath);            if (s != null && s.length() > 0)                params.setValue(paramKey, s);        }    }    /**     * Checks a parameter list for a specified key and if not present attempts to find a value for the key from an     * element matched by an XPath expression. If found, the key and value are added to the parameter list.     *     * @param context   the context from which to start the XPath search.     * @param params    the parameter list.     * @param paramKey  the key used to identify the paramater in the parameter list.     * @param paramName the Xpath expression identifying the parameter value within the specified context.     * @param xpath     an {@link XPath} object to use for the search. This allows the caller to re-use XPath objects     *                  when performing multiple searches. May be null.     *     * @throws IllegalArgumentException if either the context, parameter list, parameter key or parameter name are     *                                  null.     */    public static void checkAndSetDoubleParam(Element context, AVList params, String paramKey, String paramName,        XPath xpath)    {        if (context == null)        {            String message = Logging.getMessage("nullValue.ElementIsNull");            Logging.logger().severe(message);            throw new IllegalArgumentException(message);        }        if (params == null)        {            String message = Logging.getMessage("nullValue.ParametersIsNull");            Logging.logger().severe(message);            throw new IllegalArgumentException(message);        }        if (paramKey == null)        {            String message = Logging.getMessage("nullValue.ParameterKeyIsNull");            Logging.logger().severe(message);            throw new IllegalArgumentException(message);        }        if (paramName == null)        {            String message = Logging.getMessage("nullValue.ParameterNameIsNull");            Logging.logger().severe(message);            throw new IllegalArgumentException(message);        }        Object o = params.getValue(paramKey);        if (o == null)        {            Double d = getDouble(context, paramName, xpath);            if (d != null)                params.setValue(paramKey, d);        }    }    /**     * Checks a parameter list for a specified key and if not present attempts to find a value for the key from an     * element matched by an XPath expression. If found, the key and value are added to the parameter list.     *     * @param context   the context from which to start the XPath search.     * @param params    the parameter list.     * @param paramKey  the key used to identify the paramater in the parameter list.     * @param paramName the Xpath expression identifying the parameter value within the specified context.     * @param xpath     an {@link XPath} object to use for the search. This allows the caller to re-use XPath objects     *                  when performing multiple searches. May be null.     *     * @throws IllegalArgumentException if either the context, parameter list, parameter key or parameter name are     *                                  null.     */    public static void checkAndSetIntegerParam(Element context, AVList params, String paramKey, String paramName,        XPath xpath)    {        if (context == null)        {            String message = Logging.getMessage("nullValue.ElementIsNull");            Logging.logger().severe(message);            throw new IllegalArgumentException(message);        }        if (params == null)        {            String message = Logging.getMessage("nullValue.ParametersIsNull");            Logging.logger().severe(message);            throw new IllegalArgumentException(message);        }        if (paramKey == null)        {            String message = Logging.getMessage("nullValue.ParameterKeyIsNull");            Logging.logger().severe(message);            throw new IllegalArgumentException(message);        }        if (paramName == null)

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?